UGC Developing

Weblibrary

Learn how to integrate Sophora's UGC add on with your apps using the Java web library.

If the following dependency is added to your web application and if it is properly configured as described below, the weblibrary provides you with Spring Beans to access UGC. The main ones are S3ResultWriter and VotingReportService.

<dependency>
 <groupId>com.subshell.sophora.ugc</groupId>
 <artifactId>ugc-weblib</artifactId>
 <version>X.X.X</version>
</dependency>

The weblibrary provides you with Spring Beans for you application.

ResultWriter

The S3ResultWriter provides you with the ability to transfer user generated data to the UGC backend without loss of data. The data is written into a folder structure of a S3 bucket where it is discovered and handled by the UGC backend. The data can be one of the following types:

  • FormResult
  • VotingResult
  • QuizResult
  • UserComment
  • ImageUpload
  • UserRating
For additional details on how to use the S3ResultWriter see its javadoc.

It needs a S3Configuration with the following fields:

S3Configuration
AttributesDescription
sophora.ugc.weblib.s3.accessKeyIdAccess key for your S3 bucket
sophora.ugc.weblib.s3.secretAccessKeySecret key, usually bundled with the previous access key
sophora.ugc.weblib.s3.hostHost for the S3 bucket, e.g. "storage.googleapis.com"
sophora.ugc.weblib.s3.bucketNameName of the bucket in which UGC submissions are stored

A typical usage to the S3ResultWriter would look like this:

public void saveForm(FormResult formResult) { 
 	try { 
 		boolean success = s3ResultWriter.writeResult(formResult); 
 		if (success) { 
 			log.info("Successfully wrote form data to S3"); 
 		} else { 
 			log.error("Failed to write form data to S3"); 
 		} 
 	} catch (Exception e) { 
 		log.error("Error while writing to S3", e); 
 	}
 }

VotingReportService

The VotingReportService can be used to access the RankingVotingReports and SimpleVotingReports of votings. For both, it needs the Sophora IDs of the corresponding votings. Caller of the methods do not need to bother about number of requests. An internal cache ensures that requests only call the UGC backend if the last retrieval is more than the cache time in the past. Call one of the following two methods based on the type of voting represented by the Sophora ID.

RankingVotingReport rankingVotingReport = votingReportService.getRankingReport("vote100");
SimpleVotingReport simpleVotingReport = votingReportService.getSimpleReport("vote102");

The URL to access UGC needs to be configured and ist available by an Spring Bean of type WeblibConfiguration. Additionally, there is an optional configuration option to specify a cache time used by the VotingReportService.

WeblibConfiguration
AttributesDescription
sophora.ugc.weblib.ugcBaseUrlURL that points to the location of UGC, including the HTTP protocol
sophora.ugc.weblib.voting.cacheTimeDuration for which a cached report is returned. After the duration is elapsed the next request will call the UGC backend to get the report. Default PT10S

Last modified on 10/21/25

The content of this page is licensed under the CC BY 4.0 License. Code samples are licensed under the MIT License.

Icon