use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsSitesRequestTest method testHandleGetSites03.
/**
* Get /sites with 'read' permissions SES support.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetSites03() throws Exception {
// given
putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/maildomain", "tryformkiq.com");
removeSsmParameter(String.format("/formkiq/%s/siteid/%s/email", FORMKIQ_APP_ENVIRONMENT, "default"));
ApiGatewayRequestEvent event = toRequestEvent("/request-get-sites01.json");
setCognitoGroup(event, "default_read finance");
// 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.get("next"));
assertNull(resp.get("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"));
assertNull(getSsmParameter(String.format("/formkiq/%s/siteid/%s/email", FORMKIQ_APP_ENVIRONMENT, sites.get(0).get("siteId"))));
assertEquals("finance", sites.get(1).get("siteId"));
assertNotNull(sites.get(1).get("uploadEmail"));
String uploadEmail = sites.get(1).getString("uploadEmail");
assertTrue(uploadEmail.endsWith("@tryformkiq.com"));
assertTrue(Pattern.matches(EMAIL, uploadEmail.subSequence(0, uploadEmail.indexOf("@"))));
assertNotNull(getSsmParameter(String.format("/formkiq/%s/siteid/%s/email", FORMKIQ_APP_ENVIRONMENT, sites.get(1).get("siteId"))));
String[] strs = uploadEmail.split("@");
assertEquals("{\"siteId\":\"finance\", \"appEnvironment\":\"" + FORMKIQ_APP_ENVIRONMENT + "\"}", getSsmParameter(String.format("/formkiq/ses/%s/%s", strs[1], strs[0])));
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsSitesRequestTest method testHandleGetSites01.
/**
* Get /sites with SES support.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetSites01() throws Exception {
// given
putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/maildomain", "tryformkiq.com");
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"));
assertNotNull(sites.get(0).get("uploadEmail"));
String uploadEmail = sites.get(0).getString("uploadEmail");
assertTrue(uploadEmail.endsWith("@tryformkiq.com"));
assertTrue(Pattern.matches(EMAIL, uploadEmail.subSequence(0, uploadEmail.indexOf("@"))));
assertNotNull(getSsmParameter(String.format("/formkiq/%s/siteid/%s/email", FORMKIQ_APP_ENVIRONMENT, sites.get(0).get("siteId"))));
String[] strs = uploadEmail.split("@");
assertEquals("tryformkiq.com", strs[1]);
assertEquals("{\"siteId\":\"default\", \"appEnvironment\":\"" + FORMKIQ_APP_ENVIRONMENT + "\"}", getSsmParameter(String.format("/formkiq/ses/%s/%s", strs[1], strs[0])));
assertEquals("finance", sites.get(1).get("siteId"));
assertNotNull(sites.get(1).get("uploadEmail"));
uploadEmail = sites.get(1).getString("uploadEmail");
assertTrue(uploadEmail.endsWith("@tryformkiq.com"));
assertTrue(Pattern.matches(EMAIL, uploadEmail.subSequence(0, uploadEmail.indexOf("@"))));
assertNotNull(getSsmParameter(String.format("/formkiq/%s/siteid/%s/email", FORMKIQ_APP_ENVIRONMENT, sites.get(1).get("siteId"))));
strs = uploadEmail.split("@");
assertEquals("{\"siteId\":\"finance\", \"appEnvironment\":\"" + FORMKIQ_APP_ENVIRONMENT + "\"}", getSsmParameter(String.format("/formkiq/ses/%s/%s", strs[1], strs[0])));
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class WebhooksServiceImpl method findWebhooks.
@Override
public List<DynamicObject> findWebhooks(final String siteId) {
Map<String, AttributeValue> key = queryKeys(keysGeneric(siteId, PREFIX_WEBHOOKS, null));
String expr = GSI1_PK + " = :pk";
QueryRequest q = QueryRequest.builder().tableName(this.documentTableName).indexName(GSI1).keyConditionExpression(expr).expressionAttributeValues(key).build();
QueryResponse result = this.dynamoDB.query(q);
Collection<? extends Map<String, AttributeValue>> keys = result.items().stream().map(i -> Map.of(PK, i.get(PK), SK, i.get(SK))).collect(Collectors.toList());
List<DynamicObject> retlist = Collections.emptyList();
if (!keys.isEmpty()) {
Map<String, KeysAndAttributes> items = Map.of(this.documentTableName, KeysAndAttributes.builder().keys(keys).build());
BatchGetItemResponse batch = this.dynamoDB.batchGetItem(BatchGetItemRequest.builder().requestItems(items).build());
Map<String, List<Map<String, AttributeValue>>> responses = batch.responses();
List<Map<String, AttributeValue>> list = responses.get(this.documentTableName);
AttributeValueToDynamicObject transform = new AttributeValueToDynamicObject();
retlist = list.stream().map(m -> transform.apply(m)).collect(Collectors.toList());
retlist.forEach(ob -> updateWebhookTimeToLive(ob));
}
return retlist;
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ConfigServiceImplTest method testConfig02.
/**
* Test Finding missing Config.
*/
@Test
public void testConfig02() {
// given
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString(), DEFAULT_SITE_ID)) {
// when
DynamicObject config = this.service.get(siteId);
// then
assertEquals(0, config.size());
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ConfigServiceImplTest method testDelete01.
/**
* Test Delete Config.
*/
@Test
public void testDelete01() {
// 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 (isDefaultSiteId(siteId)) {
assertEquals("default", config.getString("SK"));
} else {
assertEquals(siteId, 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));
this.service.delete(siteId);
assertEquals(0, this.service.get(siteId).size());
}
}
Aggregations