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);
}
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);
}
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);
}
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;
}
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());
}
}
}
}
Aggregations