use of com.formkiq.lambda.apigateway.exception.NotFoundException in project formkiq-core by formkiq.
the class WebhooksIdRequestHandler method delete.
@Override
public ApiRequestHandlerResponse delete(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsServices) throws Exception {
String siteId = authorizer.getSiteId();
String id = getPathParameter(event, "webhookId");
if (awsServices.webhookService().findWebhook(siteId, id) == null) {
throw new NotFoundException("Webhook 'id' not found");
}
awsServices.webhookService().deleteWebhook(siteId, id);
return new ApiRequestHandlerResponse(SC_OK, new ApiMessageResponse("'" + id + "' object deleted"));
}
use of com.formkiq.lambda.apigateway.exception.NotFoundException in project formkiq-core by formkiq.
the class WebhooksIdRequestHandler method get.
@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsServices) throws Exception {
String siteId = authorizer.getSiteId();
String id = getPathParameter(event, "webhookId");
DynamicObject m = awsServices.webhookService().findWebhook(siteId, id);
if (m == null) {
throw new NotFoundException("Webhook 'id' not found");
}
String url = awsServices.ssmService().getParameterValue("/formkiq/" + awsServices.appEnvironment() + "/api/DocumentsPublicHttpUrl");
String path = "private".equals(m.getString("enabled")) ? "/private" : "/public";
String u = url + path + "/webhooks/" + m.getString("documentId");
if (siteId != null && !DEFAULT_SITE_ID.equals(siteId)) {
u += "?siteId=" + siteId;
}
Map<String, Object> map = new HashMap<>();
map.put("siteId", siteId != null ? siteId : DEFAULT_SITE_ID);
map.put("id", m.getString("documentId"));
map.put("name", m.getString("path"));
map.put("url", u);
map.put("insertedDate", m.getString("inserteddate"));
map.put("userId", m.getString("userId"));
map.put("enabled", m.getString("enabled"));
map.put("ttl", m.getString("ttl"));
return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(map));
}
use of com.formkiq.lambda.apigateway.exception.NotFoundException in project formkiq-core by formkiq.
the class WebhooksTagsRequestHandler method post.
@Override
public ApiRequestHandlerResponse post(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsServices) throws Exception {
DocumentTag tag = fromBodyToObject(logger, event, DocumentTag.class);
if (tag.getKey() == null || tag.getKey().length() == 0) {
throw new BadException("invalid json body");
}
String siteId = authorizer.getSiteId();
String id = getPathParameter(event, "webhookId");
tag.setType(DocumentTagType.USERDEFINED);
tag.setInsertedDate(new Date());
tag.setUserId(getCallingCognitoUsername(event));
DynamicObject webhook = awsServices.webhookService().findWebhook(siteId, id);
if (webhook == null) {
throw new NotFoundException("Webhook 'id' not found");
}
Date ttl = null;
String ttlString = webhook.getString("TimeToLive");
if (ttlString != null) {
long epoch = Long.parseLong(ttlString);
ttl = new Date(epoch * TO_MILLIS);
}
awsServices.webhookService().addTags(siteId, id, Arrays.asList(tag), ttl);
ApiResponse resp = new ApiMessageResponse("Created Tag '" + tag.getKey() + "'.");
return new ApiRequestHandlerResponse(SC_CREATED, resp);
}
use of com.formkiq.lambda.apigateway.exception.NotFoundException in project formkiq-core by formkiq.
the class CoreRequestHandler method findRequestHandler.
@Override
@SuppressWarnings("returncount")
public ApiGatewayRequestHandler findRequestHandler(final String method, final String resource) throws NotFoundException {
String s = "options".equals(method) ? method : resource;
if (isEnablePublicUrls && "/public/documents".equals(s)) {
return new PublicDocumentsRequestHandler();
}
if (s.startsWith("/public/webhooks")) {
return new PublicWebhooksRequestHandler();
}
if (s.startsWith("/private/webhooks")) {
return new PrivateWebhooksRequestHandler();
}
ApiGatewayRequestHandler hander = URL_MAP.get(s);
if (hander != null) {
return hander;
}
throw new NotFoundException(resource + " not found");
}
use of com.formkiq.lambda.apigateway.exception.NotFoundException in project formkiq-core by formkiq.
the class DocumentIdContentRequestHandler method get.
@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
String siteId = authorizer.getSiteId();
String documentId = event.getPathParameters().get("documentId");
String versionId = getParameter(event, "versionId");
DocumentItem item = awsservice.documentService().findDocument(siteId, documentId);
if (item == null) {
throw new NotFoundException("Document " + documentId + " not found.");
}
ApiResponse response = null;
String s3key = createS3Key(siteId, documentId);
if (MimeType.isPlainText(item.getContentType())) {
try (S3Client s3 = awsservice.s3Service().buildClient()) {
String content = awsservice.s3Service().getContentAsString(s3, awsservice.documents3bucket(), s3key, versionId);
response = new ApiMapResponse(Map.of("content", content, "contentType", item.getContentType(), "isBase64", Boolean.FALSE));
}
} else {
Duration duration = Duration.ofHours(1);
URL url = awsservice.s3Service().presignGetUrl(awsservice.documents3bucket(), s3key, duration, versionId);
response = new ApiMapResponse(Map.of("contentUrl", url.toString(), "contentType", item.getContentType() != null ? item.getContentType() : "application/octet-stream"));
}
return new ApiRequestHandlerResponse(SC_OK, response);
}
Aggregations