Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public enum AttributeKeyReserved {
MALWARE_SCAN_RESULT("MalwareScanResult"),
/** Relationships. */
RELATIONSHIPS("Relationships"),
/** Artifact Status. */
ARTIFACT_STATUS("ArtifactStatus"),
/** Checkout. */
CHECKOUT("Checkout"),
/** CheckoutForLegalHold. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public DocumentRecordBuilder apply(final DocumentItem item) {
.s3version(item.getS3version()).userId(item.getUserId()).version(item.getVersion())
.width(item.getWidth()).height(item.getHeight()).timeToLive(item.getTimeToLive())
.insertedDate(item.getInsertedDate()).lastModifiedDate(item.getLastModifiedDate())
.metadata(item.getMetadata());
.metadata(item.getMetadata()).hasArtifacts(item.getHasArtifacts());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public record DocumentRecord(DynamoDbKey key, String documentId, String artifact
String belongsToDocumentId, String path, String deepLinkPath, String contentType,
Long contentLength, String checksum, String checksumType, String s3version, String userId,
String version, String width, String height, String timeToLive, Date insertedDate,
Date lastModifiedDate, Collection<DocumentMetadata> metadata) {
Date lastModifiedDate, Collection<DocumentMetadata> metadata, Boolean hasArtifacts) {

/**
* Canonical constructor to enforce non-null properties and defensive copy of Date fields.
Expand All @@ -49,6 +49,10 @@ public record DocumentRecord(DynamoDbKey key, String documentId, String artifact
Objects.requireNonNull(key, "key must not be null");
Objects.requireNonNull(documentId, "documentId must not be null");

if (artifactId != null) {
hasArtifacts = Boolean.FALSE;
}

if (insertedDate != null) {
insertedDate = new Date(insertedDate.getTime());
}
Expand Down Expand Up @@ -92,7 +96,10 @@ public static DocumentRecord fromAttributeMap(final Map<String, AttributeValue>
DynamoDbTypes.toString(attributes.get("height")),
DynamoDbTypes.toString(attributes.get("timeToLive")),
DynamoDbTypes.toDate(attributes.get("inserteddate")),
DynamoDbTypes.toDate(attributes.get("lastModifiedDate")), metadata);
DynamoDbTypes.toDate(attributes.get("lastModifiedDate")), metadata,
attributes.containsKey("hasArtifacts")
? DynamoDbTypes.toBoolean(attributes.get("hasArtifacts"))
: null);
}

/**
Expand All @@ -117,7 +124,7 @@ public Map<String, AttributeValue> getAttributes() {
.withString("userId", userId).withString("version", version).withString("width", width)
.withString("height", height).withNumber("TimeToLive", timeToLive)
.withDate("inserteddate", insertedDate).withDate("lastModifiedDate", lastModifiedDate)
.withMap(metadataAttrs);
.withMap(metadataAttrs).withBoolean("hasArtifacts", hasArtifacts);

return map.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public class DocumentRecordBuilder implements DynamoDbEntityBuilder<DocumentReco
private Date lastModifiedDate;
/** {@link DocumentMetadata}. */
private Collection<DocumentMetadata> metadata;
/** Whether this non-artifact document has artifact documents. */
private Boolean hasArtifacts;
/** Metadata Keys to Delete. */
private Collection<String> metadataDeleteKeys = Collections.emptyList();
/** Set GSI1. */
Expand Down Expand Up @@ -146,13 +148,18 @@ public DocumentRecord build(final DynamoDbKey key) {
defaultValues != null ? defaultValues.getAttributes() : Collections.emptyMap();

String cs = ps(checksum, prev, "checksum");
Boolean ha = hasArtifacts;
if (ha == null && prev.containsKey("hasArtifacts")) {
ha = DynamoDbTypes.toBoolean(prev.get("hasArtifacts"));
}
return new DocumentRecord(key, documentId, ps(artifactId, prev, "artifactId"),
ps(belongsToDocumentId, prev, "belongsToDocumentId"), ps(path, prev, "path"), deepLinkPath,
ps(contentType, prev, "contentType"), ps(contentLength, prev, "contentLength"),
cs != null ? removeQuotes(cs) : null, ps(checksumType, prev, "checksumType"),
ps(s3version, prev, "s3version"), ps(userId, prev, "userId"), ps(version, prev, "version"),
ps(width, prev, "width"), ps(height, prev, "height"), ps(timeToLive, prev, "TimeToLive"),
insertedDate, lastModifiedDate, documentMetadata);
insertedDate, lastModifiedDate, documentMetadata,
!isEmpty(ps(artifactId, prev, "artifactId")) ? Boolean.FALSE : ha);
}

@Override
Expand Down Expand Up @@ -292,6 +299,11 @@ public DocumentRecordBuilder gsi1(final boolean setGsi1) {
return this;
}

public DocumentRecordBuilder hasArtifacts(final Boolean value) {
this.hasArtifacts = value;
return this;
}

public DocumentRecordBuilder height(final String h) {
this.height = h;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public DocumentRecordBuilder apply(final String parentDocumentId, final Document
.checksumType(record.checksumType()).s3version(record.s3version()).userId(record.userId())
.version(record.version()).width(record.width()).height(record.height())
.timeToLive(record.timeToLive()).insertedDate(record.insertedDate())
.lastModifiedDate(record.lastModifiedDate()).metadata(record.metadata());
.lastModifiedDate(record.lastModifiedDate()).metadata(record.metadata())
.hasArtifacts(record.hasArtifacts());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ public interface DocumentItem {
*/
List<DocumentItem> getDocuments();

/**
* Whether this non-artifact document has artifact documents.
*
* @return {@link Boolean}
*/
Boolean getHasArtifacts();

/**
* Get Height.
*
Expand Down Expand Up @@ -228,6 +235,13 @@ public interface DocumentItem {
*/
void setDocuments(List<DocumentItem> ids);

/**
* Set whether this non-artifact document has artifact documents.
*
* @param hasArtifacts {@link Boolean}
*/
void setHasArtifacts(Boolean hasArtifacts);

/**
* Set Height.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public List<DocumentItem> getDocuments() {
.collect(Collectors.toList());
}

@Override
public Boolean getHasArtifacts() {
return (Boolean) get("hasArtifacts");
}

@Override
public String getHeight() {
return getString("height");
Expand Down Expand Up @@ -169,6 +174,9 @@ public String getWidth() {
@Override
public void setArtifactId(final String artifactId) {
put("artifactId", artifactId);
if (artifactId != null) {
put("hasArtifacts", Boolean.FALSE);
}
}

@Override
Expand Down Expand Up @@ -212,6 +220,15 @@ public void setDocuments(final List<DocumentItem> list) {

}

@Override
public void setHasArtifacts(final Boolean hasArtifacts) {
if (getArtifactId() == null) {
put("hasArtifacts", hasArtifacts);
} else {
put("hasArtifacts", Boolean.FALSE);
}
}

@Override
public void setHeight(final String height) {
put("height", height);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* MIT License
*
* Copyright (c) 2018 - 2020 FormKiQ
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.aws.dynamodb.attributes;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link AttributeKeyReserved}.
*/
class AttributeKeyReservedTest {

@Test
void testFindArtifactStatus() {
assertEquals(AttributeKeyReserved.ARTIFACT_STATUS, AttributeKeyReserved.find("artifactstatus"));
assertEquals("ArtifactStatus", AttributeKeyReserved.ARTIFACT_STATUS.getKey());
assertEquals(AttributeType.STANDARD, AttributeKeyReserved.ARTIFACT_STATUS.getType());
assertEquals(AttributeDataType.STRING, AttributeKeyReserved.ARTIFACT_STATUS.getDataType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package com.formkiq.aws.dynamodb.documents;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.formkiq.aws.dynamodb.DynamoDbKey;
Expand All @@ -41,6 +42,24 @@ private void assertKeyEquals(final String siteId, final String expected, final S
assertEquals(siteId != null ? siteId + "/" + expected : expected, actual);
}

@Test
void testBuildHasArtifacts01() {
DocumentRecord record = new DocumentRecordBuilder().documentId(ID.uuid())
.hasArtifacts(Boolean.TRUE).build((String) null);

assertTrue(record.hasArtifacts());
assertTrue(record.getAttributes().get("hasArtifacts").bool());
}

@Test
void testBuildHasArtifacts02() {
DocumentRecord record = new DocumentRecordBuilder().documentId(ID.uuid()).artifactId(ID.ulid())
.hasArtifacts(Boolean.TRUE).build((String) null);

assertFalse(record.hasArtifacts());
assertFalse(record.getAttributes().get("hasArtifacts").bool());
}

@Test
void testBuildKey01() {
for (String siteId : Arrays.asList(null, ID.uuid())) {
Expand Down
Loading
Loading