use of com.formkiq.stacks.api.ApiDocumentVersion in project formkiq-core by formkiq.
the class DocumentVersionsRequestHandler method get.
@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
SimpleDateFormat df = new SimpleDateFormat(GsonUtil.DATE_FORMAT);
String siteId = authorizer.getSiteId();
String documentId = event.getPathParameters().get("documentId");
String next = getParameter(event, "next");
String tz = getParameter(event, "tz");
ZoneOffset offset = DateUtil.getZoneOffset(tz);
df.setTimeZone(TimeZone.getTimeZone(offset));
String s3key = createDatabaseKey(siteId, documentId);
S3Service s3service = awsservice.s3Service();
try (S3Client s3 = s3service.buildClient()) {
ListObjectVersionsResponse response = s3service.getObjectVersions(s3, awsservice.documents3bucket(), s3key, next);
List<ApiDocumentVersion> list = response.versions().stream().map(v -> {
ApiDocumentVersion dv = new ApiDocumentVersion();
dv.setVersionId(v.versionId());
Date date = Date.from(v.lastModified());
dv.setLastModifiedDate(df.format(date));
return dv;
}).collect(Collectors.toList());
ApiDocumentVersionsResponse resp = new ApiDocumentVersionsResponse();
resp.setNext(response.nextKeyMarker());
resp.setVersions(list);
return new ApiRequestHandlerResponse(SC_OK, resp);
}
}
Aggregations