Search in sources :

Example 16 with DynamicDocumentItem

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));
    }
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) DynamicDocumentItem(com.formkiq.stacks.dynamodb.DynamicDocumentItem) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) DynamicDocumentTag(com.formkiq.stacks.dynamodb.DynamicDocumentTag) DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) DocumentItem(com.formkiq.stacks.dynamodb.DocumentItem) DynamicDocumentItem(com.formkiq.stacks.dynamodb.DynamicDocumentItem) Date(java.util.Date) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 17 with DynamicDocumentItem

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());
    }
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) DynamicDocumentItem(com.formkiq.stacks.dynamodb.DynamicDocumentItem) DynamicDocumentTag(com.formkiq.stacks.dynamodb.DynamicDocumentTag) DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) DocumentItem(com.formkiq.stacks.dynamodb.DocumentItem) DynamicDocumentItem(com.formkiq.stacks.dynamodb.DynamicDocumentItem) Date(java.util.Date) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 18 with DynamicDocumentItem

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);
    }
}
Also used : DynamicDocumentItem(com.formkiq.stacks.dynamodb.DynamicDocumentItem) DocumentItem(com.formkiq.stacks.dynamodb.DocumentItem) DynamicDocumentItem(com.formkiq.stacks.dynamodb.DynamicDocumentItem) Date(java.util.Date) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 19 with DynamicDocumentItem

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());
        }
    }
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) DynamicDocumentItem(com.formkiq.stacks.dynamodb.DynamicDocumentItem) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) S3Client(software.amazon.awssdk.services.s3.S3Client) Date(java.util.Date) GetItemRequest(software.amazon.awssdk.services.dynamodb.model.GetItemRequest) Test(org.junit.jupiter.api.Test)

Example 20 with DynamicDocumentItem

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);
    }
}
Also used : DynamicDocumentItem(com.formkiq.stacks.dynamodb.DynamicDocumentItem) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

DynamicDocumentItem (com.formkiq.stacks.dynamodb.DynamicDocumentItem)27 Date (java.util.Date)18 Test (org.junit.jupiter.api.Test)15 DocumentItem (com.formkiq.stacks.dynamodb.DocumentItem)14 Timeout (org.junit.jupiter.api.Timeout)9 DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)7 DynamicDocumentTag (com.formkiq.stacks.dynamodb.DynamicDocumentTag)6 S3Client (software.amazon.awssdk.services.s3.S3Client)6 DocumentItemToDynamicDocumentItem (com.formkiq.stacks.dynamodb.DocumentItemToDynamicDocumentItem)5 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)4 DynamoDbClient (software.amazon.awssdk.services.dynamodb.DynamoDbClient)4 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)4 ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)3 ApiMapResponse (com.formkiq.lambda.apigateway.ApiMapResponse)3 ApiPagination (com.formkiq.lambda.apigateway.ApiPagination)3 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)3 SimpleDateFormat (java.text.SimpleDateFormat)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3