Search in sources :

Example 51 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class DocumentsRestrictionsMaxContentLengthTest method testEnforced02.

/**
 * Max Content Length, no Content Length.
 */
@Test
public void testEnforced02() {
    // given
    Long contentLength = null;
    String siteId = UUID.randomUUID().toString();
    DynamicObject ob = this.awsservice.configService().get(siteId);
    ob.put(ConfigService.MAX_DOCUMENT_SIZE_BYTES, "10");
    this.awsservice.configService().save(siteId, ob);
    // when
    String value = service.getValue(this.awsservice, siteId);
    boolean result = service.enforced(this.awsservice, siteId, value, contentLength);
    // then
    assertTrue(result);
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) Test(org.junit.jupiter.api.Test)

Example 52 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class DocumentsRestrictionsMaxContentLengthTest method testEnforced05.

/**
 * Max Content Length, Content Length=0.
 */
@Test
public void testEnforced05() {
    // given
    Long contentLength = Long.valueOf(0);
    String siteId = UUID.randomUUID().toString();
    DynamicObject ob = this.awsservice.configService().get(siteId);
    ob.put(ConfigService.MAX_DOCUMENT_SIZE_BYTES, "10");
    this.awsservice.configService().save(siteId, ob);
    // when
    String value = service.getValue(this.awsservice, siteId);
    boolean result = service.enforced(this.awsservice, siteId, value, contentLength);
    // then
    assertTrue(result);
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) Test(org.junit.jupiter.api.Test)

Example 53 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class DocumentsRestrictionsMaxContentLengthTest method testEnforced03.

/**
 * Max Content Length, Content Length less than or equal.
 */
@Test
public void testEnforced03() {
    // given
    Long contentLength = Long.valueOf("10");
    String siteId = UUID.randomUUID().toString();
    DynamicObject ob = this.awsservice.configService().get(siteId);
    ob.put(ConfigService.MAX_DOCUMENT_SIZE_BYTES, "10");
    this.awsservice.configService().save(siteId, ob);
    // when
    String value = service.getValue(this.awsservice, siteId);
    boolean result = service.enforced(this.awsservice, siteId, value, contentLength);
    // then
    assertFalse(result);
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) Test(org.junit.jupiter.api.Test)

Example 54 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class StagingS3Create method createContentMap.

/**
 * Generate {@link Map} of DocumentId / Content.
 * @param doc {@link DynamicDocumentItem}
 * @return {@link Map}
 */
private Map<String, String> createContentMap(final DynamicDocumentItem doc) {
    Map<String, String> map = new HashMap<>();
    if (doc.hasString("content")) {
        if (doc.hasString("documentId")) {
            map.put(doc.getString("documentId"), doc.getString("content"));
        }
    }
    List<DynamicObject> documents = doc.getList("documents");
    for (DynamicObject document : documents) {
        if (document.hasString("content") && document.hasString("documentId")) {
            map.put(document.getString("documentId"), document.getString("content"));
        }
    }
    return map;
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) HashMap(java.util.HashMap)

Example 55 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class StagingS3CreateTest method processFkB64File.

/**
 * Test .fkb64 file.
 *
 * @param siteId {@link String}
 * @param docitem {@link DynamicDocumentItem}
 * @throws IOException IOException
 */
private void processFkB64File(final String siteId, final DynamicDocumentItem docitem) throws IOException {
    // given
    String documentId = UUID.randomUUID().toString();
    this.logger.reset();
    String key = createDatabaseKey(siteId, documentId + ".fkb64");
    Map<String, Object> map = loadFileAsMap(this, "/objectcreate-event4.json", UUID1, key);
    try (S3Client c = s3.buildClient()) {
        byte[] content = this.gson.toJson(docitem).getBytes(UTF_8);
        s3.putObject(c, STAGING_BUCKET, key, content, null, null);
        // when
        handleRequest(map);
        // then
        String destDocumentId = findDocumentIdFromLogger(siteId);
        if (destDocumentId != null) {
            assertTrue(this.logger.containsString("Removing " + key + " from bucket example-bucket."));
            assertTrue(this.logger.containsString("handling 1 record(s)."));
            assertTrue(this.logger.containsString("Inserted " + docitem.getPath() + " into bucket documentsbucket as " + createDatabaseKey(siteId, destDocumentId)));
            assertFalse(s3.getObjectMetadata(c, STAGING_BUCKET, documentId).isObjectExists());
            DocumentItem item = service.findDocument(siteId, destDocumentId);
            assertEquals("20", item.getContentLength().toString());
            assertEquals("plain/text", item.getContentType());
            assertTrue(item.getChecksum() != null && item.getInsertedDate() != null);
            assertEquals("test.txt", item.getPath());
            assertEquals("joe", item.getUserId());
            boolean hasTags = docitem.containsKey("tags");
            List<DocumentTag> tags = service.findDocumentTags(siteId, destDocumentId, null, MAX_RESULTS).getResults();
            int tagcount = hasTags ? docitem.getList("tags").size() + 2 : 2 + 1;
            assertEquals(tagcount, tags.size());
            DocumentTag ptag = findTag(tags, "path");
            assertEquals(destDocumentId, ptag.getDocumentId());
            assertEquals(docitem.getPath(), ptag.getValue());
            assertNotNull(ptag.getInsertedDate());
            assertEquals(DocumentTagType.SYSTEMDEFINED, ptag.getType());
            assertEquals(docitem.getUserId(), ptag.getUserId());
            if (hasTags) {
                for (DynamicObject tag : docitem.getList("tags")) {
                    DocumentTag dtag = findTag(tags, tag.getString("key"));
                    assertEquals(tag.getString("value"), dtag.getValue());
                }
            } else {
                ptag = findTag(tags, "untagged");
                assertEquals(destDocumentId, ptag.getDocumentId());
                assertEquals("true", ptag.getValue());
                assertNotNull(ptag.getInsertedDate());
                assertEquals(DocumentTagType.SYSTEMDEFINED, ptag.getType());
                assertEquals(docitem.getUserId(), ptag.getUserId());
            }
        }
    }
}
Also used : DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) DocumentItem(com.formkiq.stacks.dynamodb.DocumentItem) DynamicDocumentItem(com.formkiq.stacks.dynamodb.DynamicDocumentItem) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) S3Client(software.amazon.awssdk.services.s3.S3Client)

Aggregations

DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)93 Test (org.junit.jupiter.api.Test)55 Map (java.util.Map)46 ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)39 Date (java.util.Date)26 HashMap (java.util.HashMap)17 DocumentItemDynamoDb (com.formkiq.stacks.dynamodb.DocumentItemDynamoDb)12 DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)10 ZonedDateTime (java.time.ZonedDateTime)10 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)8 List (java.util.List)8 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)7 S3Client (software.amazon.awssdk.services.s3.S3Client)7 ApiMapResponse (com.formkiq.lambda.apigateway.ApiMapResponse)6 BadException (com.formkiq.lambda.apigateway.exception.BadException)6 Collectors (java.util.stream.Collectors)6 NotFoundException (com.formkiq.lambda.apigateway.exception.NotFoundException)5 FormKiqClientV1 (com.formkiq.stacks.client.FormKiqClientV1)5 LocalDate (java.time.LocalDate)5 Test (org.junit.Test)5