Search in sources :

Example 1 with ApiDocumentVersionsResponse

use of com.formkiq.stacks.api.ApiDocumentVersionsResponse 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);
    }
}
Also used : Date(java.util.Date) TimeZone(java.util.TimeZone) S3Client(software.amazon.awssdk.services.s3.S3Client) ApiGatewayRequestHandler(com.formkiq.lambda.apigateway.ApiGatewayRequestHandler) SimpleDateFormat(java.text.SimpleDateFormat) AwsServiceCache(com.formkiq.lambda.apigateway.AwsServiceCache) ApiAuthorizer(com.formkiq.lambda.apigateway.ApiAuthorizer) Collectors(java.util.stream.Collectors) SiteIdKeyGenerator.createDatabaseKey(com.formkiq.stacks.dynamodb.SiteIdKeyGenerator.createDatabaseKey) List(java.util.List) ApiGatewayRequestEventUtil(com.formkiq.lambda.apigateway.ApiGatewayRequestEventUtil) GsonUtil(com.formkiq.lambda.apigateway.util.GsonUtil) LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger) DateUtil(com.formkiq.stacks.dynamodb.DateUtil) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) ZoneOffset(java.time.ZoneOffset) SC_OK(com.formkiq.lambda.apigateway.ApiResponseStatus.SC_OK) ApiDocumentVersionsResponse(com.formkiq.stacks.api.ApiDocumentVersionsResponse) S3Service(com.formkiq.aws.s3.S3Service) ApiDocumentVersion(com.formkiq.stacks.api.ApiDocumentVersion) ListObjectVersionsResponse(software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse) ApiDocumentVersionsResponse(com.formkiq.stacks.api.ApiDocumentVersionsResponse) ApiDocumentVersion(com.formkiq.stacks.api.ApiDocumentVersion) ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) S3Client(software.amazon.awssdk.services.s3.S3Client) SimpleDateFormat(java.text.SimpleDateFormat) S3Service(com.formkiq.aws.s3.S3Service) ListObjectVersionsResponse(software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse) Date(java.util.Date) ZoneOffset(java.time.ZoneOffset)

Aggregations

LambdaLogger (com.amazonaws.services.lambda.runtime.LambdaLogger)1 S3Service (com.formkiq.aws.s3.S3Service)1 ApiAuthorizer (com.formkiq.lambda.apigateway.ApiAuthorizer)1 ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)1 ApiGatewayRequestEventUtil (com.formkiq.lambda.apigateway.ApiGatewayRequestEventUtil)1 ApiGatewayRequestHandler (com.formkiq.lambda.apigateway.ApiGatewayRequestHandler)1 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)1 SC_OK (com.formkiq.lambda.apigateway.ApiResponseStatus.SC_OK)1 AwsServiceCache (com.formkiq.lambda.apigateway.AwsServiceCache)1 GsonUtil (com.formkiq.lambda.apigateway.util.GsonUtil)1 ApiDocumentVersion (com.formkiq.stacks.api.ApiDocumentVersion)1 ApiDocumentVersionsResponse (com.formkiq.stacks.api.ApiDocumentVersionsResponse)1 DateUtil (com.formkiq.stacks.dynamodb.DateUtil)1 SiteIdKeyGenerator.createDatabaseKey (com.formkiq.stacks.dynamodb.SiteIdKeyGenerator.createDatabaseKey)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ZoneOffset (java.time.ZoneOffset)1 Date (java.util.Date)1 List (java.util.List)1 TimeZone (java.util.TimeZone)1 Collectors (java.util.stream.Collectors)1