Search in sources :

Example 1 with ApiDocumentTagsItemResponse

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

the class DocumentTagsRequestHandler method get.

@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
    CacheService cacheService = awsservice.documentCacheService();
    ApiPagination pagination = getPagination(cacheService, event);
    int limit = pagination != null ? pagination.getLimit() : getLimit(logger, event);
    PaginationMapToken ptoken = pagination != null ? pagination.getStartkey() : null;
    String siteId = authorizer.getSiteId();
    String documentId = event.getPathParameters().get("documentId");
    PaginationResults<DocumentTag> results = awsservice.documentService().findDocumentTags(siteId, documentId, ptoken, limit);
    results.getResults().forEach(r -> r.setDocumentId(null));
    ApiPagination current = createPagination(cacheService, event, pagination, results.getToken(), limit);
    List<DocumentTag> tags = subList(results.getResults(), limit);
    List<ApiDocumentTagItemResponse> list = tags.stream().map(t -> {
        ApiDocumentTagItemResponse r = new ApiDocumentTagItemResponse();
        r.setDocumentId(t.getDocumentId());
        r.setInsertedDate(t.getInsertedDate());
        r.setKey(t.getKey());
        r.setValue(t.getValue());
        r.setValues(t.getValues());
        r.setUserId(t.getUserId());
        r.setType(t.getType() != null ? t.getType().name().toLowerCase() : null);
        return r;
    }).collect(Collectors.toList());
    ApiDocumentTagsItemResponse resp = new ApiDocumentTagsItemResponse();
    resp.setTags(list);
    resp.setPrevious(current.getPrevious());
    resp.setNext(current.hasNext() ? current.getNext() : null);
    return new ApiRequestHandlerResponse(SC_OK, resp);
}
Also used : SC_CREATED(com.formkiq.lambda.apigateway.ApiResponseStatus.SC_CREATED) Arrays(java.util.Arrays) DocumentTags(com.formkiq.stacks.dynamodb.DocumentTags) Date(java.util.Date) AwsServiceCache(com.formkiq.lambda.apigateway.AwsServiceCache) ApiAuthorizer(com.formkiq.lambda.apigateway.ApiAuthorizer) ApiResponse(com.formkiq.lambda.apigateway.ApiResponse) ApiGatewayRequestEventUtil(com.formkiq.lambda.apigateway.ApiGatewayRequestEventUtil) LambdaLogger(com.amazonaws.services.lambda.runtime.LambdaLogger) DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) SC_OK(com.formkiq.lambda.apigateway.ApiResponseStatus.SC_OK) PaginationMapToken(com.formkiq.stacks.dynamodb.PaginationMapToken) ApiDocumentTagsItemResponse(com.formkiq.stacks.api.ApiDocumentTagsItemResponse) ApiGatewayRequestHandler(com.formkiq.lambda.apigateway.ApiGatewayRequestHandler) ApiPagination(com.formkiq.lambda.apigateway.ApiPagination) ApiDocumentTagItemResponse(com.formkiq.stacks.api.ApiDocumentTagItemResponse) Collectors(java.util.stream.Collectors) BadException(com.formkiq.lambda.apigateway.exception.BadException) List(java.util.List) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) CacheService(com.formkiq.stacks.dynamodb.CacheService) ApiMessageResponse(com.formkiq.lambda.apigateway.ApiMessageResponse) Collections(java.util.Collections) DocumentTagType(com.formkiq.stacks.dynamodb.DocumentTagType) PaginationResults(com.formkiq.stacks.dynamodb.PaginationResults) ApiPagination(com.formkiq.lambda.apigateway.ApiPagination) DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) ApiDocumentTagItemResponse(com.formkiq.stacks.api.ApiDocumentTagItemResponse) ApiRequestHandlerResponse(com.formkiq.lambda.apigateway.ApiRequestHandlerResponse) PaginationMapToken(com.formkiq.stacks.dynamodb.PaginationMapToken) ApiDocumentTagsItemResponse(com.formkiq.stacks.api.ApiDocumentTagsItemResponse) CacheService(com.formkiq.stacks.dynamodb.CacheService)

Aggregations

LambdaLogger (com.amazonaws.services.lambda.runtime.LambdaLogger)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 ApiMessageResponse (com.formkiq.lambda.apigateway.ApiMessageResponse)1 ApiPagination (com.formkiq.lambda.apigateway.ApiPagination)1 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)1 ApiResponse (com.formkiq.lambda.apigateway.ApiResponse)1 SC_CREATED (com.formkiq.lambda.apigateway.ApiResponseStatus.SC_CREATED)1 SC_OK (com.formkiq.lambda.apigateway.ApiResponseStatus.SC_OK)1 AwsServiceCache (com.formkiq.lambda.apigateway.AwsServiceCache)1 BadException (com.formkiq.lambda.apigateway.exception.BadException)1 ApiDocumentTagItemResponse (com.formkiq.stacks.api.ApiDocumentTagItemResponse)1 ApiDocumentTagsItemResponse (com.formkiq.stacks.api.ApiDocumentTagsItemResponse)1 CacheService (com.formkiq.stacks.dynamodb.CacheService)1 DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)1 DocumentTagType (com.formkiq.stacks.dynamodb.DocumentTagType)1 DocumentTags (com.formkiq.stacks.dynamodb.DocumentTags)1 PaginationMapToken (com.formkiq.stacks.dynamodb.PaginationMapToken)1