use of com.formkiq.lambda.apigateway.ApiRequestHandlerResponse in project formkiq-core by formkiq.
the class PublicWebhooksRequestHandler method buildResponse.
private ApiRequestHandlerResponse buildResponse(final ApiGatewayRequestEvent event, final DynamicObject item) {
String body = item.getString("content");
String documentId = item.getString("documentId");
String contentType = item.getString("contentType");
ApiRequestHandlerResponse response = new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(Map.of("documentId", documentId)));
String redirectUri = getParameter(event, "redirect_uri");
if ("application/x-www-form-urlencoded".equals(contentType) && StringUtils.isNotBlank(redirectUri)) {
response = buildRedirect(event, redirectUri, body);
} else if (StringUtils.isNotBlank(redirectUri)) {
response = new ApiRequestHandlerResponse(MOVED_PERMANENTLY, new ApiRedirectResponse(redirectUri));
}
return response;
}
use of com.formkiq.lambda.apigateway.ApiRequestHandlerResponse in project formkiq-core by formkiq.
the class SitesRequestHandler method get.
@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
List<DynamicObject> sites = authorizer.getSiteIds().stream().map(siteId -> {
DynamicObject config = awsservice.config(siteId);
config.put("siteId", siteId != null ? siteId : DEFAULT_SITE_ID);
return config;
}).collect(Collectors.toList());
sites.forEach(ob -> {
ob.remove("PK");
ob.remove("SK");
});
updateUploadEmail(logger, awsservice, authorizer, sites);
return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(Map.of("sites", sites)));
}
use of com.formkiq.lambda.apigateway.ApiRequestHandlerResponse in project formkiq-core by formkiq.
the class VersionRequestHandler method get.
@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
String key = "/formkiq/" + awsservice.appEnvironment() + "/version";
String version = awsservice.ssmService().getParameterValue(key);
return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(Map.of("version", version, "type", awsservice.formkiqType())));
}
use of com.formkiq.lambda.apigateway.ApiRequestHandlerResponse in project formkiq-core by formkiq.
the class WebhooksIdRequestHandler method patch.
@Override
public ApiRequestHandlerResponse patch(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsServices) throws Exception {
String siteId = authorizer.getSiteId();
String id = getPathParameter(event, "webhookId");
WebhooksService webhookService = awsServices.webhookService();
if (webhookService.findWebhook(siteId, id) == null) {
throw new NotFoundException("Webhook 'id' not found");
}
DynamicObject obj = fromBodyToDynamicObject(logger, event);
Map<String, Object> map = new HashMap<>();
if (obj.containsKey("name")) {
map.put("name", obj.getString("name"));
}
if (obj.containsKey("enabled")) {
map.put("enabled", obj.getBoolean("enabled"));
}
Date ttlDate = null;
if (obj.containsKey("ttl")) {
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(Long.parseLong(obj.getString("ttl")));
ttlDate = Date.from(now.toInstant());
map.put("TimeToLive", ttlDate);
}
webhookService.updateWebhook(siteId, id, new DynamicObject(map));
if (ttlDate != null) {
webhookService.updateTimeToLive(siteId, id, ttlDate);
}
return new ApiRequestHandlerResponse(SC_OK, new ApiMessageResponse("'" + id + "' object updated"));
}
use of com.formkiq.lambda.apigateway.ApiRequestHandlerResponse in project formkiq-core by formkiq.
the class WebhooksRequestHandler 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 url = awsServices.ssmService().getParameterValue("/formkiq/" + awsServices.appEnvironment() + "/api/DocumentsPublicHttpUrl");
List<DynamicObject> list = awsServices.webhookService().findWebhooks(siteId);
List<Map<String, Object>> webhooks = list.stream().map(m -> {
String path = "private".equals(m.getString("enabled")) ? "/private" : "/public";
Map<String, Object> map = new HashMap<>();
String u = url + path + "/webhooks/" + m.getString("documentId");
if (siteId != null && !DEFAULT_SITE_ID.equals(siteId)) {
u += "?siteId=" + siteId;
}
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 map;
}).collect(Collectors.toList());
return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(Map.of("webhooks", webhooks)));
}
Aggregations