use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class WebhooksRequestHandler method isOverMaxWebhooks.
private boolean isOverMaxWebhooks(final LambdaLogger logger, final AwsServiceCache awsservice, final String siteId) {
boolean over = false;
DynamicObject config = awsservice.config(siteId);
String maxString = config.getString(MAX_WEBHOOKS);
if (maxString != null) {
try {
int max = Integer.parseInt(maxString);
int numberOfWebhooks = awsservice.webhookService().findWebhooks(siteId).size();
if (awsservice.debug()) {
logger.log("found config for maximum webhooks " + maxString);
logger.log("found " + numberOfWebhooks + " webhooks");
}
if (numberOfWebhooks >= max) {
over = true;
}
} catch (NumberFormatException e) {
over = false;
e.printStackTrace();
}
}
return over;
}
use of com.formkiq.stacks.common.objects.DynamicObject 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)));
}
use of com.formkiq.stacks.common.objects.DynamicObject 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.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class AbstractRequestHandler method handleRequest.
/**
* Handle Request.
*
* @param file {@link String}
* @param siteId {@link String}
* @param username {@link String}
* @param cognitoGroups {@link String}
* @return {@link DynamicObject}
* @throws IOException IOException
*/
@SuppressWarnings("unchecked")
public DynamicObject handleRequest(final String file, final String siteId, final String username, final String cognitoGroups) throws IOException {
ApiGatewayRequestEvent event = toRequestEvent(file);
addParameter(event, "siteId", siteId);
if (username != null) {
setUsername(event, username);
}
if (cognitoGroups != null) {
setCognitoGroup(event, cognitoGroups);
}
String response = handleRequest(event);
return new DynamicObject(fromJson(response, Map.class));
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleGetDocuments10.
/**
* Test user with 'Finance' role with no siteid.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocuments10() throws Exception {
// given
String siteId = null;
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents03.json");
addParameter(event, "siteId", siteId);
setCognitoGroup(event, "Finance");
// when
String response = handleRequest(event);
// then
Map<String, String> m = fromJson(response, Map.class);
final int mapsize = 3;
assertEquals(mapsize, m.size());
assertEquals("200.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
DynamicObject resp = new DynamicObject(fromJson(m.get("body"), Map.class));
List<DynamicObject> documents = resp.getList("documents");
assertEquals(0, documents.size());
}
Aggregations