use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ConfigServiceImplTest method testConfig04.
/**
* Test Finding Default Config.
*/
@Test
public void testConfig04() {
// given
Map<String, Object> map = new HashMap<>();
map.put(DOCUMENT_TIME_TO_LIVE, "" + UUID.randomUUID().toString());
map.put(MAX_WEBHOOKS, "" + UUID.randomUUID().toString());
map.put(MAX_DOCUMENTS, "" + UUID.randomUUID().toString());
DynamicObject obj = new DynamicObject(map);
this.service.save(null, obj);
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString(), DEFAULT_SITE_ID)) {
// when
DynamicObject config = this.service.get(siteId);
// then
final int count = 5;
assertEquals(count, config.keySet().size());
assertEquals("configs#", config.getString("PK"));
assertEquals("default", config.getString("SK"));
assertEquals(map.get(DOCUMENT_TIME_TO_LIVE), config.getString(DOCUMENT_TIME_TO_LIVE));
assertEquals(map.get(MAX_WEBHOOKS), config.getString(MAX_WEBHOOKS));
assertEquals(map.get(MAX_DOCUMENTS), config.getString(MAX_DOCUMENTS));
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ConfigServiceImplTest method testConfig01.
/**
* Test Finding Config.
*/
@Test
public void testConfig01() {
// given
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString(), DEFAULT_SITE_ID)) {
Map<String, Object> map = new HashMap<>();
map.put(DOCUMENT_TIME_TO_LIVE, "" + UUID.randomUUID().toString());
map.put(MAX_WEBHOOKS, "" + UUID.randomUUID().toString());
map.put(MAX_DOCUMENTS, "" + UUID.randomUUID().toString());
DynamicObject obj = new DynamicObject(map);
this.service.save(siteId, obj);
// when
DynamicObject config = this.service.get(siteId);
// then
final int count = 5;
assertEquals(count, config.keySet().size());
assertEquals("configs#", config.getString("PK"));
if (siteId != null) {
assertEquals(siteId, config.getString("SK"));
} else {
assertEquals("default", config.getString("SK"));
}
assertEquals(map.get(DOCUMENT_TIME_TO_LIVE), config.getString(DOCUMENT_TIME_TO_LIVE));
assertEquals(map.get(MAX_WEBHOOKS), config.getString(MAX_WEBHOOKS));
assertEquals(map.get(MAX_DOCUMENTS), config.getString(MAX_DOCUMENTS));
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class DocumentIdRequestHandler method patch.
@Override
public ApiRequestHandlerResponse patch(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
boolean isUpdate = event.getHttpMethod().equalsIgnoreCase("patch") && event.getPathParameters().containsKey("documentId");
String siteId = authorizer.getSiteId();
String documentId = UUID.randomUUID().toString();
if (isUpdate) {
documentId = event.getPathParameters().get("documentId");
if (awsservice.documentService().findDocument(siteId, documentId) == null) {
throw new NotFoundException("Document " + documentId + " not found.");
}
}
String maxDocumentCount = null;
DynamicObject item = fromBodyToDynamicObject(logger, event);
updateContentType(event, item);
List<DynamicObject> documents = item.getList("documents");
if (!isUpdate) {
if (!item.hasString("content") && item.getList("documents").isEmpty()) {
throw new BadException("Invalid JSON body.");
}
maxDocumentCount = this.restrictionMaxDocuments.getValue(awsservice, siteId);
if (maxDocumentCount != null && this.restrictionMaxDocuments.enforced(awsservice, siteId, maxDocumentCount)) {
throw new BadException("Max Number of Documents reached");
}
}
addFieldsToObject(event, awsservice, siteId, documentId, item, documents);
item.put("documents", documents);
logger.log("setting userId: " + item.getString("userId") + " contentType: " + item.getString("contentType"));
putObjectToStaging(logger, awsservice, maxDocumentCount, siteId, item);
Map<String, String> uploadUrls = generateUploadUrls(awsservice, siteId, documentId, item, documents);
Map<String, Object> map = buildResponse(siteId, documentId, documents, uploadUrls);
ApiResponseStatus status = isUpdate ? SC_OK : SC_CREATED;
return new ApiRequestHandlerResponse(status, new ApiMapResponse(map));
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class PublicWebhooksRequestHandler method buildDynamicObject.
private DynamicObject buildDynamicObject(final AwsServiceCache awsservice, final String siteId, final String webhookId, final DynamicObject hook, final String body, final String contentType) {
DynamicObject item = new DynamicObject(new HashMap<>());
final String documentId = UUID.randomUUID().toString();
if (contentType != null) {
item.put("contentType", contentType);
}
item.put("content", body);
item.put("documentId", documentId);
item.put("userId", "webhook/" + hook.getOrDefault("path", "webhook"));
item.put("path", "webhooks/" + webhookId);
if (hook.containsKey("TimeToLive")) {
item.put("TimeToLive", hook.get("TimeToLive"));
} else {
String ttl = awsservice.configService().get(siteId).getString(DOCUMENT_TIME_TO_LIVE);
if (ttl != null) {
item.put("TimeToLive", ttl);
}
}
if (siteId != null) {
item.put("siteId", siteId);
}
return item;
}
use of com.formkiq.stacks.common.objects.DynamicObject 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)));
}
Aggregations