use of com.formkiq.stacks.dynamodb.DynamicDocumentItem in project formkiq-core by formkiq.
the class DocumentsS3UpdateTest method testHandleRequest05.
/**
* Test Processing Document with sub documents.
*
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.MILLISECONDS, value = TEST_TIMEOUT)
public void testHandleRequest05() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
this.logger.reset();
Date now = new Date();
DynamicDocumentItem doc = createSubDocuments(now);
service.saveDocumentItemWithTag(siteId, doc);
String key = createDatabaseKey(siteId, doc.getDocumentId());
final Map<String, Object> map = loadFileAsMap(this, "/objectcreate-event1.json", BUCKET_KEY, key);
addS3File(key, "pdf", false, "testdata");
// when
DocumentItem item = handleRequest(siteId, doc.getDocumentId(), map);
DocumentItem itemchild = handleRequest(siteId, doc.getDocuments().get(0).getDocumentId(), map);
// then
try (DynamoDbClient client = dbBuilder.build()) {
Map<String, AttributeValue> m = client.getItem(GetItemRequest.builder().tableName("Documents").key(keysDocument(siteId, doc.getDocumentId())).build()).item();
assertNotNull(m.get(GSI1_PK));
Map<String, AttributeValue> mchild = client.getItem(GetItemRequest.builder().tableName("Documents").key(keysDocument(siteId, itemchild.getDocumentId())).build()).item();
assertNull(mchild.get(GSI1_PK));
}
assertEquals(doc.getDocumentId(), item.getDocumentId());
PaginationResults<DocumentTag> tags = service.findDocumentTags(siteId, doc.getDocumentId(), null, MAX_RESULTS);
assertEquals(2, tags.getResults().size());
assertDocumentTagEquals(new DocumentTag().setKey("category").setValue("none").setType(DocumentTagType.USERDEFINED).setDocumentId(doc.getDocumentId()), tags.getResults().get(0));
assertDocumentTagEquals(new DocumentTag().setKey("userId").setValue(doc.getUserId()).setType(DocumentTagType.SYSTEMDEFINED).setDocumentId(doc.getDocumentId()), tags.getResults().get(1));
tags = service.findDocumentTags(siteId, itemchild.getDocumentId(), null, MAX_RESULTS);
assertEquals(1, tags.getResults().size());
assertDocumentTagEquals(new DocumentTag().setKey("category1").setValue("").setType(DocumentTagType.USERDEFINED).setDocumentId(itemchild.getDocumentId()), tags.getResults().get(0));
}
}
use of com.formkiq.stacks.dynamodb.DynamicDocumentItem in project formkiq-core by formkiq.
the class DocumentsS3UpdateTest method testHandleRequest04.
/**
* Create Document Request on child document.
*
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.MILLISECONDS, value = TEST_TIMEOUT)
public void testHandleRequest04() throws Exception {
String documentId = UUID.randomUUID().toString();
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
this.logger.reset();
String key = createDatabaseKey(siteId, documentId);
final Map<String, Object> map = loadFileAsMap(this, "/objectcreate-event1.json", BUCKET_KEY, key);
DynamicDocumentItem doc = new DynamicDocumentItem(Map.of());
doc.setInsertedDate(new Date());
doc.setDocumentId(BUCKET_KEY);
doc.setPath("test.txt");
doc.setUserId("joe");
DynamicDocumentItem child = new DynamicDocumentItem(Map.of());
child.setInsertedDate(new Date());
child.setDocumentId(documentId);
child.setUserId("joe");
doc.put("documents", Arrays.asList(child));
service.saveDocumentItemWithTag(siteId, doc);
addS3File(key, "pdf", false, "testdata");
// when
final DocumentItem item = handleRequest(siteId, child.getDocumentId(), map);
// then
assertNotNull(item.getBelongsToDocumentId());
PaginationResults<DocumentTag> tags = service.findDocumentTags(siteId, BUCKET_KEY, null, MAX_RESULTS);
try (DynamoDbClient client = dbBuilder.build()) {
Map<String, AttributeValue> m = client.getItem(GetItemRequest.builder().tableName("Documents").key(keysDocument(siteId, child.getDocumentId())).build()).item();
assertNull(m.get(GSI1_PK));
}
final int count = 3;
int i = 0;
assertEquals(count, tags.getResults().size());
assertDocumentTagEquals(new DocumentTag().setKey("path").setValue("test.txt").setDocumentId(BUCKET_KEY).setType(DocumentTagType.SYSTEMDEFINED).setUserId("joe"), tags.getResults().get(i++));
assertDocumentTagEquals(new DocumentTag().setKey("untagged").setValue("true").setDocumentId(BUCKET_KEY).setType(DocumentTagType.SYSTEMDEFINED).setUserId("joe"), tags.getResults().get(i++));
assertDocumentTagEquals(new DocumentTag().setKey("userId").setValue("joe").setDocumentId(BUCKET_KEY).setType(DocumentTagType.SYSTEMDEFINED).setUserId("joe"), tags.getResults().get(i++));
assertEquals(0, service.findDocumentFormats(siteId, BUCKET_KEY, null, MAX_RESULTS).getResults().size());
verifyDocumentSaved(siteId, item, "pdf", "8");
assertPublishSnsMessage(siteId, sqsDocumentEventUrl, "create", false, true);
tags = service.findDocumentTags(siteId, documentId, null, MAX_RESULTS);
assertEquals(0, tags.getResults().size());
}
}
use of com.formkiq.stacks.dynamodb.DynamicDocumentItem in project formkiq-core by formkiq.
the class DocumentsS3UpdateTest method testHandleRequest08.
/**
* Create Document Request with Text Content+Payload TOO LARGE.
*
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.MILLISECONDS, value = TEST_TIMEOUT)
public void testHandleRequest08() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
this.logger.reset();
String key = createDatabaseKey(siteId, BUCKET_KEY);
final Map<String, Object> map = loadFileAsMap(this, "/objectcreate-event1.json", BUCKET_KEY, key);
DynamicDocumentItem doc = new DynamicDocumentItem(Map.of());
doc.setInsertedDate(new Date());
doc.setDocumentId(BUCKET_KEY);
doc.setUserId("joe");
doc.setPath("test.txt");
service.saveDocumentItemWithTag(siteId, doc);
String content = loadFile(this, "/255kb-text.txt");
addS3File(key, "text/plain", false, content);
// when
final DocumentItem item = handleRequest(siteId, BUCKET_KEY, map);
// then
verifyDocumentSaved(siteId, item, "text/plain", "" + content.length());
assertPublishSnsMessage(siteId, sqsDocumentEventUrl, "create", false, false);
}
}
use of com.formkiq.stacks.dynamodb.DynamicDocumentItem in project formkiq-core by formkiq.
the class StagingS3CreateTest method testFkB64Extension06.
/**
* Test .fkb64 file with TTL.
*
* @throws IOException IOException
*/
@Test
public void testFkB64Extension06() throws IOException {
String timeToLive = "1612061365";
DynamicDocumentItem item = createDocumentItem();
item.put("TimeToLive", timeToLive);
item.put("tags", Arrays.asList(Map.of("documentId", item.getDocumentId(), "key", "category", "value", "person", "insertedDate", new Date(), "userId", "joe", "type", DocumentTagType.USERDEFINED.name())));
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
processFkB64File(siteId, item);
String key = createDatabaseKey(siteId, item.getDocumentId());
try (S3Client c = s3.buildClient()) {
String content = s3.getContentAsString(c, DOCUMENTS_BUCKET, key, null);
assertEquals("VGhpcyBpcyBhIHRlc3Q=", content);
}
GetItemRequest r = GetItemRequest.builder().key(keysDocument(siteId, item.getDocumentId())).tableName(dbHelper.getDocumentTable()).build();
try (DynamoDbClient db = dbBuilder.build()) {
Map<String, AttributeValue> result = db.getItem(r).item();
assertEquals(timeToLive, result.get("TimeToLive").n());
}
}
}
use of com.formkiq.stacks.dynamodb.DynamicDocumentItem in project formkiq-core by formkiq.
the class StagingS3CreateTest method testFkB64Extension01.
/**
* Test .fkb64 file with TAGS.
*
* @throws IOException IOException
*/
@Test
public void testFkB64Extension01() throws IOException {
DynamicDocumentItem item = createDocumentItem();
item.put("tags", Arrays.asList(Map.of("documentId", item.getDocumentId(), "key", "category", "value", "person", "insertedDate", new Date(), "userId", "joe", "type", DocumentTagType.USERDEFINED.name())));
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
processFkB64File(siteId, item);
}
}
Aggregations