Search in sources :

Example 1 with ApiEmptyResponse

use of com.formkiq.stacks.api.ApiEmptyResponse in project formkiq-core by formkiq.

the class DocumentIdUrlRequestHandler method get.

@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
    String documentId = event.getPathParameters().get("documentId");
    String versionId = getParameter(event, "versionId");
    String siteId = authorizer.getSiteId();
    DocumentItem item = awsservice.documentService().findDocument(siteId, documentId);
    if (item == null) {
        throw new NotFoundException("Document " + documentId + " not found.");
    }
    URL url = getS3Url(logger, authorizer, awsservice, event, item, documentId, versionId);
    return url != null ? new ApiRequestHandlerResponse(SC_OK, new ApiUrlResponse(url.toString(), documentId)) : new ApiRequestHandlerResponse(SC_NOT_FOUND, new ApiEmptyResponse());
}
Also used : ApiUrlResponse(com.formkiq.stacks.api.ApiUrlResponse) ApiEmptyResponse(com.formkiq.stacks.api.ApiEmptyResponse) DocumentItem(com.formkiq.stacks.dynamodb.DocumentItem) NotFoundException(com.formkiq.lambda.apigateway.exception.NotFoundException) ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) URL(java.net.URL)

Aggregations

ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)1 NotFoundException (com.formkiq.lambda.apigateway.exception.NotFoundException)1 ApiEmptyResponse (com.formkiq.stacks.api.ApiEmptyResponse)1 ApiUrlResponse (com.formkiq.stacks.api.ApiUrlResponse)1 DocumentItem (com.formkiq.stacks.dynamodb.DocumentItem)1 URL (java.net.URL)1