b0c1 commented on code in PR #2915:
URL: https://github.com/apache/fineract/pull/2915#discussion_r1089083007
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/service/DatatableReportingProcessService.java:
##########
@@ -90,13 +112,64 @@ private Response exportJSON(String reportName,
MultivaluedMap<String, String> qu
return
Response.ok().entity(json).type(MediaType.APPLICATION_JSON).build();
}
- private Response exportS3(String reportName, MultivaluedMap<String,
String> queryParams, Map<String, String> reportParams,
- boolean isSelfServiceUserReport, String parameterTypeValue) {
- throw new UnsupportedOperationException("S3 export not supported for
datatables");
+ private boolean isAwsCredentialsValid() {
+ return
StringUtils.isNotBlank(System.getenv(SdkSystemSetting.AWS_ACCESS_KEY_ID.environmentVariable()))
+ &&
StringUtils.isNotBlank(System.getenv(SdkSystemSetting.AWS_SECRET_ACCESS_KEY.environmentVariable()))
+ &&
StringUtils.isNotBlank(SdkSystemSetting.AWS_REGION.environmentVariable());
+ }
+
+ private Response exportS3(String reportName, Map<String, String>
reportParams, boolean isSelfServiceUserReport,
+ String parameterTypeValue) {
+ if (!isAwsCredentialsValid()) {
+ return Response.status(Response.Status.BAD_REQUEST).entity("AWS
credentials not set").build();
+ }
+ if (StringUtils.isBlank(System.getenv().get(AWS_S_3_BUCKET_NAME))) {
+ return Response.status(Response.Status.BAD_REQUEST).entity("AWS S3
bucket name not set").build();
+ }
+ try {
+ S3Client s3Client =
S3Client.builder().region(Region.of(System.getenv(SdkSystemSetting.AWS_REGION.environmentVariable())))
+
.credentialsProvider(EnvironmentVariableCredentialsProvider.create()).build();
+ StreamingOutput output =
this.readExtraDataAndReportingService.retrieveReportCSV(reportName,
parameterTypeValue, reportParams,
+ isSelfServiceUserReport);
+ ByteArrayOutputStream byteArrayOutputStream = new
ByteArrayOutputStream();
+ output.write(byteArrayOutputStream);
+ byteArrayOutputStream.close();
+ String finalS3Path = getS3FolderName() + "" +
exportFileNameGeneration(reportName, reportParams) + ".csv";
+ s3Client.putObject(builder ->
builder.bucket(System.getenv().get(AWS_S_3_BUCKET_NAME)).key(finalS3Path).build(),
+
RequestBody.fromBytes(byteArrayOutputStream.toByteArray()));
+ return Response.noContent().build();
+ } catch (IOException e) {
+ log.error("Error while exporting to S3", e);
+ throw new IllegalStateException("Error while exporting to S3!", e);
+ }
+ }
+
+ private String getS3FolderName() {
+ String folderName =
configurationDomainService.retrieveReportExportS3FolderName();
+ if (StringUtils.isNotBlank(folderName)) {
+ folderName = folderName + "/";
+ }
+ return folderName.trim();
+ }
+
+ private String exportFileNameGeneration(String reportName, Map<String,
String> reportParams) {
+ String timestamp = "_" + new
SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
Review Comment:
It's the generation datetime, I thin it's generation timestamp
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]