use of com.formkiq.stacks.dynamodb.DynamicDocumentItem in project formkiq-core by formkiq.
the class DocumentsS3UpdateTest method testHandleRequest01.
/**
* Create Document Request without existing Tags/Formats.
*
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.MILLISECONDS, value = TEST_TIMEOUT)
public void testHandleRequest01() 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);
addS3File(key, "pdf", false, "testdata");
// when
final DocumentItem item = handleRequest(siteId, BUCKET_KEY, map);
// then
PaginationResults<DocumentTag> tags = service.findDocumentTags(siteId, BUCKET_KEY, null, MAX_RESULTS);
final int count = 3;
assertEquals(count, tags.getResults().size());
int i = 0;
assertEquals("path", tags.getResults().get(i).getKey());
assertEquals("test.txt", tags.getResults().get(i).getValue());
assertEquals(BUCKET_KEY, tags.getResults().get(i).getDocumentId());
assertEquals(DocumentTagType.SYSTEMDEFINED, tags.getResults().get(i).getType());
assertEquals("joe", tags.getResults().get(i).getUserId());
assertNotNull(tags.getResults().get(i++).getInsertedDate());
assertEquals("untagged", tags.getResults().get(i).getKey());
assertEquals("true", tags.getResults().get(i).getValue());
assertEquals(BUCKET_KEY, tags.getResults().get(i).getDocumentId());
assertEquals(DocumentTagType.SYSTEMDEFINED, tags.getResults().get(i).getType());
assertEquals("joe", tags.getResults().get(i).getUserId());
assertNotNull(tags.getResults().get(i++).getInsertedDate());
assertEquals("userId", tags.getResults().get(i).getKey());
assertEquals("joe", tags.getResults().get(i).getValue());
assertEquals(BUCKET_KEY, tags.getResults().get(i).getDocumentId());
assertEquals(DocumentTagType.SYSTEMDEFINED, tags.getResults().get(i).getType());
assertEquals("joe", tags.getResults().get(i).getUserId());
assertNotNull(tags.getResults().get(i++).getInsertedDate());
assertEquals(0, service.findDocumentFormats(siteId, BUCKET_KEY, null, MAX_RESULTS).getResults().size());
verifyDocumentSaved(siteId, item, "pdf", "8");
assertPublishSnsMessage(siteId, sqsDocumentEventUrl, "create", false, false);
}
}
use of com.formkiq.stacks.dynamodb.DynamicDocumentItem in project formkiq-core by formkiq.
the class DocumentsS3UpdateTest method testHandleRequest06.
/**
* Create Document Request with Text Content.
*
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.MILLISECONDS, value = TEST_TIMEOUT)
public void testHandleRequest06() 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);
addS3File(key, "text/plain", false, "testdata");
// when
final DocumentItem item = handleRequest(siteId, BUCKET_KEY, map);
// then
verifyDocumentSaved(siteId, item, "text/plain", "8");
assertPublishSnsMessage(siteId, sqsDocumentEventUrl, "create", false, false);
}
}
use of com.formkiq.stacks.dynamodb.DynamicDocumentItem in project formkiq-core by formkiq.
the class StagingS3CreateTest method testFkB64Extension03.
/**
* Test .fkb64 file without CONTENT.
*
* @throws IOException IOException
*/
@Test
public void testFkB64Extension03() throws IOException {
DynamicDocumentItem item = createDocumentItem();
item.put("content", null);
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
processFkB64File(siteId, item);
}
assertTrue(this.logger.containsString("Skipping " + item.getPath() + " no content"));
}
use of com.formkiq.stacks.dynamodb.DynamicDocumentItem in project formkiq-core by formkiq.
the class DocumentIdRequestHandler method get.
@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
String siteId = authorizer.getSiteId();
int limit = getLimit(logger, event);
ApiPagination token = getPagination(awsservice.documentCacheService(), event);
String documentId = event.getPathParameters().get("documentId");
ApiPagination pagination = getPagination(awsservice.documentCacheService(), event);
PaginationResult<DocumentItem> presult = awsservice.documentService().findDocument(siteId, documentId, true, token != null ? token.getStartkey() : null, limit);
DocumentItem result = presult.getResult();
if (result == null) {
throw new NotFoundException("Document " + documentId + " not found.");
}
ApiPagination current = createPagination(awsservice.documentCacheService(), event, pagination, presult.getToken(), limit);
DynamicDocumentItem item = new DocumentItemToDynamicDocumentItem().apply(result);
item.put("siteId", siteId != null ? siteId : DEFAULT_SITE_ID);
item.put("previous", current.getPrevious());
item.put("next", current.hasNext() ? current.getNext() : null);
return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(item));
}
use of com.formkiq.stacks.dynamodb.DynamicDocumentItem in project formkiq-core by formkiq.
the class DocumentsRequestHandler method get.
@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
ApiPagination pagination = getPagination(awsservice.documentCacheService(), event);
final int limit = pagination != null ? pagination.getLimit() : getLimit(logger, event);
final PaginationMapToken ptoken = pagination != null ? pagination.getStartkey() : null;
String tz = getParameter(event, "tz");
String dateString = getParameter(event, "date");
if (StringUtils.isBlank(dateString)) {
if (StringUtils.isNotBlank(tz)) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
ZoneOffset offset = DateUtil.getZoneOffset(tz);
sdf.setTimeZone(TimeZone.getTimeZone(offset));
dateString = sdf.format(new Date());
} else {
dateString = this.df.format(new Date());
}
}
ZonedDateTime date = transformToDate(logger, awsservice, dateString, tz);
String siteId = authorizer.getSiteId();
final PaginationResults<DocumentItem> results = awsservice.documentService().findDocumentsByDate(siteId, date, ptoken, limit);
ApiPagination current = createPagination(awsservice.documentCacheService(), event, pagination, results.getToken(), limit);
List<DocumentItem> documents = subList(results.getResults(), limit);
List<DynamicDocumentItem> items = documents.stream().map(m -> new DocumentItemToDynamicDocumentItem().apply(m)).collect(Collectors.toList());
items.forEach(i -> i.put("siteId", siteId != null ? siteId : DEFAULT_SITE_ID));
Map<String, Object> map = new HashMap<>();
map.put("documents", items);
map.put("previous", current.getPrevious());
map.put("next", current.hasNext() ? current.getNext() : null);
return new ApiRequestHandlerResponse(SC_OK, new ApiMapResponse(map));
}
Aggregations