use of com.formkiq.lambda.apigateway.ApiMapResponse 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.ApiMapResponse 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)));
}
use of com.formkiq.lambda.apigateway.ApiMapResponse in project formkiq-core by formkiq.
the class SearchRequestHandler method post.
@Override
public ApiRequestHandlerResponse post(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
DynamoDbCacheService cacheService = awsservice.documentCacheService();
ApiPagination pagination = getPagination(cacheService, event);
int limit = pagination != null ? pagination.getLimit() : getLimit(logger, event);
PaginationMapToken ptoken = pagination != null ? pagination.getStartkey() : null;
QueryRequest q = fromBodyToObject(logger, event, QueryRequest.class);
if (q == null || q.query() == null || q.query().tag() == null) {
throw new BadException("Invalid JSON body.");
}
Collection<String> documentIds = q.query().documentIds();
if (documentIds != null) {
if (documentIds.size() > MAX_DOCUMENT_IDS) {
throw new BadException("Maximum number of DocumentIds is " + MAX_DOCUMENT_IDS);
}
if (!getQueryParameterMap(event).containsKey("limit")) {
limit = documentIds.size();
}
}
String siteId = authorizer.getSiteId();
PaginationResults<DynamicDocumentItem> results = awsservice.documentSearchService().search(siteId, q.query(), ptoken, limit);
ApiPagination current = createPagination(cacheService, event, pagination, results.getToken(), limit);
List<DynamicDocumentItem> documents = subList(results.getResults(), limit);
Map<String, Object> map = new HashMap<>();
map.put("documents", documents);
map.put("previous", current.getPrevious());
map.put("next", current.hasNext() ? current.getNext() : null);
ApiMapResponse resp = new ApiMapResponse(map);
return new ApiRequestHandlerResponse(SC_OK, resp);
}
use of com.formkiq.lambda.apigateway.ApiMapResponse 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.ApiMapResponse in project formkiq-core by formkiq.
the class WebhooksTagsRequestHandler 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");
PaginationResults<DynamicObject> list = awsServices.webhookService().findTags(siteId, id, null);
List<Map<String, Object>> tags = list.getResults().stream().map(m -> {
Map<String, Object> map = new HashMap<>();
map.put("insertedDate", m.getString("inserteddate"));
map.put("webhookId", id);
map.put("type", m.getString("type"));
map.put("userId", m.getString("userId"));
map.put("value", m.getString("tagValue"));
map.put("key", m.getString("tagKey"));
return map;
}).collect(Collectors.toList());
return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(Map.of("tags", tags)));
}
Aggregations