use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsSitesRequestTest method testHandleGetSites04.
/**
* Get /sites with Config.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetSites04() throws Exception {
// given
String siteId = "finance";
ApiGatewayRequestEvent event = toRequestEvent("/request-get-sites01.json");
setCognitoGroup(event, siteId);
getAwsServices().configService().save(siteId, new DynamicObject(Map.of(MAX_DOCUMENTS, "5", MAX_WEBHOOKS, "10")));
// when
String response = handleRequest(event);
// then
Map<String, String> m = GsonUtil.getInstance().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));
assertEquals(1, resp.getList("sites").size());
assertEquals(siteId, resp.getList("sites").get(0).getString("siteId"));
assertEquals("5", resp.getList("sites").get(0).getString(MAX_DOCUMENTS));
assertEquals("10", resp.getList("sites").get(0).getString(MAX_WEBHOOKS));
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsSitesRequestTest method testHandleGetSites02.
/**
* Get /sites WITHOUT SES support.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetSites02() throws Exception {
// given
removeSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/maildomain");
ApiGatewayRequestEvent event = toRequestEvent("/request-get-sites01.json");
// when
String response = handleRequest(event);
// then
Map<String, String> m = GsonUtil.getInstance().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));
assertNull(resp.getString("next"));
assertNull(resp.getString("previous"));
List<DynamicObject> sites = resp.getList("sites");
assertEquals(2, sites.size());
assertEquals(DEFAULT_SITE_ID, sites.get(0).get("siteId"));
assertNull(sites.get(0).get("uploadEmail"));
assertEquals("finance", sites.get(1).get("siteId"));
assertNull(sites.get(1).get("uploadEmail"));
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ConfigServiceImplTest method testConfig03.
/**
* Test Finding Config.
*/
@Test
public void testConfig03() {
// given
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString(), DEFAULT_SITE_ID)) {
DynamicObject obj = new DynamicObject(Map.of());
this.service.save(siteId, obj);
// when
DynamicObject config = this.service.get(siteId);
// then
final int count = 2;
assertEquals(count, config.keySet().size());
assertEquals("configs#", config.getString("PK"));
if (siteId != null) {
assertEquals(siteId, config.getString("SK"));
} else {
assertEquals("default", config.getString("SK"));
}
assertNull(config.getString(DOCUMENT_TIME_TO_LIVE));
assertNull(config.getString(MAX_WEBHOOKS));
assertNull(config.getString(MAX_DOCUMENTS));
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class DocumentIdRequestHandler method addFieldsToObject.
/**
* Add field to object.
*
* @param event {@link ApiGatewayRequestEvent}
* @param awsservice {@link AwsServiceCache}
* @param siteId {@link String}
* @param documentId {@link String}
* @param item {@link DynamicObject}
* @param documents {@link List} {@link DynamicObject}
*/
private void addFieldsToObject(final ApiGatewayRequestEvent event, final AwsServiceCache awsservice, final String siteId, final String documentId, final DynamicObject item, final List<DynamicObject> documents) {
String userId = getCallingCognitoUsername(event);
item.put("documentId", documentId);
item.put("userId", userId);
for (DynamicObject map : documents) {
map.put("documentId", UUID.randomUUID().toString());
map.put("userId", userId);
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class DocumentIdRequestHandler method generateUploadUrls.
/**
* Add field to object.
*
* @param awsservice {@link AwsServiceCache}
* @param siteId {@link String}
* @param documentId {@link String}
* @param item {@link DynamicObject}
* @param documents {@link List} {@link DynamicObject}
* @return {@link Map}
*/
private Map<String, String> generateUploadUrls(final AwsServiceCache awsservice, final String siteId, final String documentId, final DynamicObject item, final List<DynamicObject> documents) {
Map<String, String> map = new HashMap<>();
if (!item.hasString("content")) {
map.put(documentId, generateUploadUrl(awsservice, siteId, documentId));
}
for (DynamicObject o : documents) {
if (!o.hasString("content")) {
String docid = o.getString("documentId");
map.put(docid, generateUploadUrl(awsservice, siteId, docid));
}
}
return map;
}
Aggregations