use of com.formkiq.stacks.dynamodb.DocumentTags in project formkiq-core by formkiq.
the class DocumentTagsRequestHandler method post.
@Override
public ApiRequestHandlerResponse post(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
DocumentTag tag = fromBodyToObject(logger, event, DocumentTag.class);
DocumentTags tags = fromBodyToObject(logger, event, DocumentTags.class);
boolean tagValid = isValid(tag);
boolean tagsValid = isValid(tags);
if (!tagValid && !tagsValid) {
throw new BadException("invalid json body");
}
if (!tagsValid) {
tags = new DocumentTags();
tags.setTags(Arrays.asList(tag));
}
tags.getTags().forEach(t -> {
t.setType(DocumentTagType.USERDEFINED);
t.setInsertedDate(new Date());
t.setUserId(getCallingCognitoUsername(event));
});
String documentId = event.getPathParameters().get("documentId");
String siteId = authorizer.getSiteId();
awsservice.documentService().deleteDocumentTag(siteId, documentId, "untagged");
awsservice.documentService().addTags(siteId, documentId, tags.getTags(), null);
ApiResponse resp = tagsValid ? new ApiMessageResponse("Created Tags.") : new ApiMessageResponse("Created Tag '" + tag.getKey() + "'.");
return new ApiRequestHandlerResponse(SC_CREATED, resp);
}
Aggregations