use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class StagingS3Create method createContentTypeMap.
/**
* Generate {@link Map} of DocumentId / Content Type.
* @param doc {@link DynamicDocumentItem}
* @return {@link Map}
*/
private Map<String, String> createContentTypeMap(final DynamicDocumentItem doc) {
Map<String, String> map = new HashMap<>();
if (doc.hasString("documentId") && doc.getContentType() != null) {
map.put(doc.getString("documentId"), doc.getContentType());
}
List<DynamicObject> documents = doc.getList("documents");
for (DynamicObject document : documents) {
if (document.hasString("contentType") && document.hasString("documentId")) {
map.put(document.getString("documentId"), document.getString("contentType"));
}
}
return map;
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiWebhooksTagsRequestTest method testGetWebhooks02.
/**
* Get /webhooks/{webhookId}/tags empty.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testGetWebhooks02() throws Exception {
// given
String webhookId = getAwsServices().webhookService().saveWebhook(null, "testwebhook", "joe", null, "true");
ApiGatewayRequestEvent event = toRequestEvent("/request-post-webhooks-webhookid-tags01.json");
setPathParameter(event, "webhookId", webhookId);
// 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("201.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
assertEquals("{\"message\":\"Created Tag 'category'.\"}", m.get("body"));
// given
event = toRequestEvent("/request-get-webhooks-webhookid-tags01.json");
setPathParameter(event, "webhookId", webhookId);
// when
response = handleRequest(event);
// then
m = GsonUtil.getInstance().fromJson(response, Map.class);
assertEquals(mapsize, m.size());
assertEquals("200.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
Map<String, Object> body = fromJson(m.get("body"), Map.class);
DynamicObject obj = new DynamicObject(body);
List<DynamicObject> list = obj.getList("tags");
assertEquals(1, list.size());
assertEquals(webhookId, list.get(0).getString("webhookId"));
assertEquals("USERDEFINED", list.get(0).getString("type"));
assertEquals("8a73dfef-26d3-43d8-87aa-b3ec358e43ba@formkiq.com", list.get(0).getString("userId"));
assertEquals("category", list.get(0).getString("key"));
assertEquals("job", list.get(0).getString("value"));
assertNotNull(list.get(0).getString("insertedDate"));
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ConfigServiceImpl method get.
@Override
public DynamicObject get(final String siteId) {
Collection<Map<String, AttributeValue>> keys = new ArrayList<>();
if (isDefaultSiteId(siteId)) {
keys.add(keysGeneric(null, PREFIX_CONFIG, DEFAULT_SITE_ID));
} else {
keys.add(keysGeneric(null, PREFIX_CONFIG, siteId));
keys.add(keysGeneric(null, PREFIX_CONFIG, DEFAULT_SITE_ID));
}
Map<String, KeysAndAttributes> items = Map.of(this.documentTableName, KeysAndAttributes.builder().keys(keys).build());
BatchGetItemResponse response = this.dynamoDB.batchGetItem(BatchGetItemRequest.builder().requestItems(items).build());
AttributeValueToDynamicObject transform = new AttributeValueToDynamicObject();
Optional<Map<String, AttributeValue>> map = Optional.empty();
List<Map<String, AttributeValue>> list = response.responses().get(this.documentTableName);
if (!list.isEmpty()) {
map = list.stream().filter(s -> s.get(SK).s().equals(siteId)).findFirst();
if (map.isEmpty()) {
map = list.stream().filter(s -> s.get(SK).s().equals(DEFAULT_SITE_ID)).findFirst();
}
}
return !map.isEmpty() ? transform.apply(map.get()) : new DynamicObject(Map.of());
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class AttributeValueToDynamicObject method apply.
@Override
public DynamicObject apply(final Map<String, AttributeValue> map) {
DynamicObject o = new DynamicObject(new HashMap<>());
for (Map.Entry<String, AttributeValue> e : map.entrySet()) {
String s = e.getValue().s();
String n = e.getValue().n();
String v = s == null && n != null ? n : s;
o.put(e.getKey(), v);
}
return o;
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsPatchRequestTest method assert200Response.
/**
* Asserts 200 response.
*
* @param siteId {@link String}
* @param response {@link String}.
* @throws IOException IOException
*/
@SuppressWarnings("unchecked")
private void assert200Response(final String siteId, final String response) throws IOException {
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));
assertNotNull(resp.get("documentId"));
if (siteId != null) {
assertEquals(siteId, resp.get("siteId"));
}
assertNull(resp.get("next"));
assertNull(resp.get("previous"));
String key = siteId != null ? siteId + "/" + resp.get("documentId") + ".fkb64" : resp.get("documentId") + ".fkb64";
assertTrue(getLogger().containsString("s3 putObject " + key + " into bucket " + STAGE_BUCKET_NAME));
assertNotNull(UUID.fromString(resp.getString("documentId")));
}
Aggregations