use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class DocumentServiceImpl method saveDocumentItemWithTag.
@Override
public DocumentItem saveDocumentItemWithTag(final String siteId, final DynamicDocumentItem doc) {
Date date = new Date();
String username = doc.getUserId();
String documentId = resetDatabaseKey(siteId, doc.getDocumentId());
if (isDocumentUserTagged(doc.getList("tags"))) {
deleteDocumentTag(siteId, documentId, "untagged");
}
DocumentItem item = new DocumentItemDynamoDb(documentId, date, username);
String path = doc.getPath();
item.setDocumentId(doc.getDocumentId());
item.setPath(path);
item.setContentType(doc.getContentType());
item.setChecksum(doc.getChecksum());
item.setContentLength(doc.getContentLength());
item.setUserId(doc.getUserId());
item.setInsertedDate(doc.getInsertedDate() != null ? doc.getInsertedDate() : date);
item.setBelongsToDocumentId(doc.getBelongsToDocumentId());
List<DocumentTag> tags = saveDocumentItemGenerateTags(siteId, doc, date, username);
boolean saveGsi1 = doc.getBelongsToDocumentId() == null;
Map<String, AttributeValue> keys = keysDocument(siteId, item.getDocumentId());
saveDocument(keys, siteId, item, tags, saveGsi1, doc.getString("TimeToLive"));
List<DynamicObject> documents = doc.getList("documents");
for (DynamicObject subdoc : documents) {
if (subdoc.getDate("insertedDate") == null) {
subdoc.put("insertedDate", date);
}
DocumentItem document = new DynamicDocumentItem(subdoc);
document.setBelongsToDocumentId(item.getDocumentId());
DocumentItem dockey = new DynamicDocumentItem(new HashMap<>());
dockey.setDocumentId(subdoc.getString("documentId"));
dockey.setBelongsToDocumentId(item.getDocumentId());
// save child document
keys = keysDocument(siteId, item.getDocumentId(), Optional.of(subdoc.getString("documentId")));
saveDocument(keys, siteId, dockey, null, false, doc.getString("TimeToLive"));
List<DynamicObject> doctags = subdoc.getList("tags");
tags = doctags.stream().map(t -> new DynamicObjectToDocumentTag().apply(t)).collect(Collectors.toList());
keys = keysDocument(siteId, subdoc.getString("documentId"));
saveDocument(keys, siteId, document, tags, false, doc.getString("TimeToLive"));
}
return item;
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class WebhooksServiceImpl method findTags.
@Override
public PaginationResults<DynamicObject> findTags(final String siteId, final String webhookId, final PaginationMapToken token) {
String expression = PK + " = :pk and begins_with(" + SK + ", :sk)";
Map<String, AttributeValue> values = queryKeys(keysGeneric(siteId, PREFIX_WEBHOOK + webhookId, PREFIX_TAGS));
Map<String, AttributeValue> startkey = new PaginationToAttributeValue().apply(token);
QueryRequest q = QueryRequest.builder().tableName(this.documentTableName).keyConditionExpression(expression).expressionAttributeValues(values).exclusiveStartKey(startkey).build();
QueryResponse result = this.dynamoDB.query(q);
AttributeValueToDynamicObject transform = new AttributeValueToDynamicObject();
List<DynamicObject> objs = result.items().stream().map(i -> transform.apply(i)).collect(Collectors.toList());
return new PaginationResults<>(objs, new QueryResponseToPagination().apply(result));
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class WebhooksServiceImpl method updateTimeToLive.
@Override
public void updateTimeToLive(final String siteId, final String webhookId, final Date ttl) {
Map<String, AttributeValue> key = keysGeneric(siteId, PREFIX_WEBHOOK + webhookId, "webhook");
Map<String, AttributeValueUpdate> values = new HashMap<>();
addTimeToLiveUpdate(values, ttl);
this.dynamoDB.updateItem(UpdateItemRequest.builder().tableName(this.documentTableName).key(key).attributeUpdates(values).build());
PaginationResults<DynamicObject> result = findTags(siteId, webhookId, null);
for (DynamicObject ob : result.getResults()) {
key = new HashMap<>();
key.put(PK, AttributeValue.builder().s(ob.getString(PK)).build());
key.put(SK, AttributeValue.builder().s(ob.getString(SK)).build());
this.dynamoDB.updateItem(UpdateItemRequest.builder().tableName(this.documentTableName).key(key).attributeUpdates(values).build());
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class WebhooksServiceImpl method findWebhook.
@Override
public DynamicObject findWebhook(final String siteId, final String id) {
Map<String, AttributeValue> pkvalues = keysGeneric(siteId, PREFIX_WEBHOOK + id, "webhook");
GetItemResponse response = this.dynamoDB.getItem(GetItemRequest.builder().tableName(this.documentTableName).key(pkvalues).build());
AttributeValueToDynamicObject transform = new AttributeValueToDynamicObject();
DynamicObject ob = null;
if (!response.item().isEmpty()) {
ob = transform.apply(response.item());
updateWebhookTimeToLive(ob);
}
return ob;
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class DocumentsUploadRequestTest method testGet03.
/**
* Get Request Upload Document Url, Content Length Greater than allowed.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testGet03() throws Exception {
// given
final int contentLength = 100;
getConfigService().save(SITEID0, new DynamicObject(Map.of(MAX_DOCUMENT_SIZE_BYTES, "5")));
GetDocumentUploadRequest request = new GetDocumentUploadRequest().siteId(SITEID0).contentLength(contentLength);
for (FormKiqClientV1 client : getFormKiqClients()) {
// when
HttpResponse<String> response = client.getDocumentUploadAsHttpResponse(request);
// then
assertEquals(STATUS_BAD_REQUEST, response.statusCode());
assertRequestCorsHeaders(response.headers());
assertEquals("{\"message\":\"'contentLength' cannot exceed 5 bytes\"}", response.body());
}
}
Aggregations