Skip to content

Commit

Permalink
#175 - Strip quotes around checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriesen committed Sep 21, 2023
1 parent 0a2f1d9 commit 1b88053
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,34 @@ private List<Map<String, AttributeValue>> getSaveTagsAttributes(final String sit
return items;
}

/**
* Has current changed from previous.
*
* @param previous {@link Map}
* @param current {@link Map}
* @return boolean
*/
private boolean isChangedMatching(final Map<String, AttributeValue> previous,
final Map<String, AttributeValue> current) {

boolean changed = previous.size() != current.size();

if (!changed) {
for (Map.Entry<String, AttributeValue> e : current.entrySet()) {

if (!e.getKey().equals("inserteddate") && !e.getKey().equals("lastModifiedDate")) {
AttributeValue av = previous.get(e.getKey());
if (av == null || !e.getValue().equals(av)) {
changed = true;
break;
}
}
}
}

return changed;
}

/**
* Is {@link List} {@link DynamicObject} contain a non generated tag.
*
Expand Down Expand Up @@ -1289,15 +1317,14 @@ private void saveDocument(final Map<String, AttributeValue> keys, final String s

removeNullMetadata(document, documentValues);

boolean previousSameAsCurrent = previous.equals(current);
String documentVersionsTableName = this.versionsService.getDocumentVersionsTableName();
boolean hasDocumentChanged = documentVersionsTableName != null && !previous.isEmpty()
&& isChangedMatching(previous, current);

if (!previousSameAsCurrent) {
if (hasDocumentChanged) {
this.versionsService.addDocumentVersionAttributes(previous, documentValues);
}

Collection<Map<String, AttributeValue>> previousList =
!previous.isEmpty() ? Arrays.asList(previous) : Collections.emptyList();

List<Map<String, AttributeValue>> folderIndex =
this.folderIndexProcessor.generateIndex(siteId, document);
if (!isEmpty(document.getPath())) {
Expand All @@ -1316,9 +1343,8 @@ private void saveDocument(final Map<String, AttributeValue> keys, final String s
.append(this.documentTableName, documentValues).appends(this.documentTableName, tagValues)
.appends(this.documentTableName, folderIndex);

String documentVersionsTableName = this.versionsService.getDocumentVersionsTableName();
if (documentVersionsTableName != null) {
writeBuilder = writeBuilder.appends(documentVersionsTableName, previousList);
if (hasDocumentChanged) {
writeBuilder = writeBuilder.appends(documentVersionsTableName, Arrays.asList(previous));
}

if (writeBuilder.batchWriteItem(this.dbClient)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static com.formkiq.aws.dynamodb.SiteIdKeyGenerator.createDatabaseKey;
import static com.formkiq.aws.dynamodb.SiteIdKeyGenerator.getSiteId;
import static com.formkiq.aws.dynamodb.SiteIdKeyGenerator.resetDatabaseKey;
import static com.formkiq.aws.dynamodb.objects.Strings.removeQuotes;
import static com.formkiq.module.events.document.DocumentEventType.CREATE;
import static com.formkiq.module.events.document.DocumentEventType.DELETE;
import static com.formkiq.module.events.document.DocumentEventType.UPDATE;
Expand Down Expand Up @@ -531,7 +532,8 @@ private void processS3File(final LambdaLogger logger, final boolean create, fina
attributes.put("contentType", AttributeValue.fromS(contentType));
}

attributes.put("checksum", AttributeValue.fromS(resp.getEtag()));
String checksum = removeQuotes(resp.getEtag());
attributes.put("checksum", AttributeValue.fromS(checksum));

if (contentLength != null) {
attributes.put("contentLength", AttributeValue.fromN("" + contentLength));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static com.formkiq.testutils.aws.DynamoDbExtension.DOCUMENTS_VERSION_TABLE;
import static com.formkiq.testutils.aws.TestServices.AWS_REGION;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -481,6 +482,8 @@ public void testHandleRequest01() throws Exception {
final DocumentItem item = handleRequest(siteId, BUCKET_KEY, map);

// then
assertFalse(item.getChecksum().startsWith("\""));
assertFalse(item.getChecksum().endsWith("\""));
assertNotNull(item.getS3version());

PaginationResults<DocumentTag> tags =
Expand Down

0 comments on commit 1b88053

Please sign in to comment.