Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriesen committed Jun 15, 2024
1 parent 67fab4e commit 38d91fb
Show file tree
Hide file tree
Showing 18 changed files with 325 additions and 334 deletions.
2 changes: 1 addition & 1 deletion docs/openapi/openapi-iam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5429,7 +5429,7 @@
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/ocrObjectsLambdaApi200'
/published/documents/{documentId}:
/publications/{documentId}:
get:
operationId: GetPublishedDocumentContent
summary: Get published document's contents
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi/openapi-jwt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5429,7 +5429,7 @@
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/ocrObjectsLambdaApi200'
/published/documents/{documentId}:
/publications/{documentId}:
get:
operationId: GetPublishedDocumentContent
summary: Get published document's contents
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi/openapi-key.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5429,7 +5429,7 @@
- ApiAuthorization: []
x-amazon-apigateway-integration:
$ref: '#/components/x-amazon-apigateway-integrations/ocrObjectsLambdaApi200'
/published/documents/{documentId}:
/publications/{documentId}:
get:
operationId: GetPublishedDocumentContent
summary: Get published document's contents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import com.formkiq.stacks.dynamodb.attributes.AttributeValidation;
import com.formkiq.stacks.dynamodb.attributes.AttributeValidationAccess;
import com.formkiq.stacks.dynamodb.attributes.DocumentAttributeRecord;
import com.formkiq.stacks.dynamodb.documents.DocumentPublishRecord;
import com.formkiq.validation.ValidationException;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;

Expand Down Expand Up @@ -544,12 +543,12 @@ void publishDocument(String siteId, String documentId, String s3version, String

/**
* Get Publish Document.
*
*
* @param siteId {@link String}
* @param documentId {@link String}
* @return DocumentPublishRecord
*/
DocumentPublishRecord findPublishDocument(String siteId, String documentId);
DocumentAttributeRecord findPublishDocument(String siteId, String documentId);

/**
* Delete Publish Document.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import com.formkiq.aws.dynamodb.objects.DateUtil;
import com.formkiq.aws.dynamodb.objects.Objects;
import com.formkiq.aws.dynamodb.objects.Strings;
import com.formkiq.stacks.dynamodb.attributes.AttributeKeyReserved;
import com.formkiq.stacks.dynamodb.attributes.AttributeRecord;
import com.formkiq.stacks.dynamodb.attributes.AttributeService;
import com.formkiq.stacks.dynamodb.attributes.AttributeServiceDynamodb;
Expand All @@ -87,7 +88,7 @@
import com.formkiq.stacks.dynamodb.attributes.DocumentAttributeRecord;
import com.formkiq.stacks.dynamodb.attributes.DocumentAttributeValueType;
import com.formkiq.stacks.dynamodb.attributes.DynamicObjectToDocumentAttributeRecord;
import com.formkiq.stacks.dynamodb.documents.DocumentPublishRecord;
import com.formkiq.stacks.dynamodb.documents.DocumentAttributePublicationValue;
import com.formkiq.stacks.dynamodb.schemas.Schema;
import com.formkiq.stacks.dynamodb.schemas.SchemaAttributesCompositeKey;
import com.formkiq.stacks.dynamodb.schemas.SchemaMissingRequiredAttributes;
Expand Down Expand Up @@ -626,7 +627,9 @@ public void deletePresetTags(final String siteId, final String id) {

@Override
public boolean deletePublishDocument(final String siteId, final String documentId) {
DocumentPublishRecord r = new DocumentPublishRecord().setDocumentId(documentId);

DocumentAttributeRecord r = new DocumentAttributeRecord().setDocumentId(documentId)
.setKey(AttributeKeyReserved.PUBLICATION.getKey()).updateValueType();
Map<String, AttributeValue> attributes = r.getAttributes(siteId);
return this.dbService.deleteItem(Map.of(PK, attributes.get(PK), SK, attributes.get(SK)));
}
Expand Down Expand Up @@ -1096,8 +1099,10 @@ public PaginationResults<PresetTag> findPresetTags(final String siteId, final St
}

@Override
public DocumentPublishRecord findPublishDocument(final String siteId, final String documentId) {
DocumentPublishRecord r = new DocumentPublishRecord().setDocumentId(documentId);
public DocumentAttributeRecord findPublishDocument(final String siteId, final String documentId) {
DocumentAttributeRecord r = new DocumentAttributeRecord().setDocumentId(documentId)
.setKey(AttributeKeyReserved.PUBLICATION.getKey())
.setValueType(DocumentAttributeValueType.PUBLICATION);
Map<String, AttributeValue> a = this.dbService.get(r.fromS(r.pk(siteId)), r.fromS(r.sk()));

if (!a.isEmpty()) {
Expand Down Expand Up @@ -1481,9 +1486,12 @@ private boolean isPathChanges(final Map<String, AttributeValue> previous,
@Override
public void publishDocument(final String siteId, final String documentId, final String s3version,
final String path, final String contentType, final String userId) {
DocumentPublishRecord r =
new DocumentPublishRecord().setDocumentId(documentId).setContentType(contentType)
.setPath(path).setUserId(userId).setS3version(s3version).setInsertedDate(new Date());
DocumentAttributePublicationValue val = new DocumentAttributePublicationValue().setPath(path)
.setS3version(s3version).setContentType(contentType);
DocumentAttributeRecord r = new DocumentAttributeRecord().setDocumentId(documentId)
.setKey(AttributeKeyReserved.PUBLICATION.getKey()).setUserId(userId)
.setInsertedDate(new Date()).setPublicationValue(val);
r.updateValueType();
this.dbService.putItem(r.getAttributes(siteId));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* 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.stacks.dynamodb.attributes;

import java.util.Arrays;
import java.util.Optional;

/**
* Reserved Attribute Keys.
*/
public enum AttributeKeyReserved {
/** Publication. */
PUBLICATION("Publication"),
/** Malware Scan Result. */
MALWARE_SCAN_RESULT("MalwareScanResult");

/** Key Name. */
private final String key;

AttributeKeyReserved(final String reservedKey) {
this.key = reservedKey;
}

/**
* Find {@link AttributeKeyReserved}.
*
* @param key {@link AttributeKeyReserved}
* @return {@link AttributeKeyReserved}
*/
public static AttributeKeyReserved find(final String key) {
Optional<AttributeKeyReserved> a =
Arrays.stream(values()).filter(v -> v.getKey().equalsIgnoreCase(key)).findFirst();
return a.orElse(null);
}

/**
* Get Key Name.
*
* @return String
*/
public String getKey() {
return this.key;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ private Collection<ValidationError> validate(final String siteId, final String k
errors = Collections
.singletonList(new ValidationErrorImpl().key("key").error("'key' is required"));
} else {

AttributeKeyReserved r = AttributeKeyReserved.find(key);
if (r != null) {
errors = Collections.singletonList(new ValidationErrorImpl().key("key")
.error("'" + key + "' is a reserved attribute name"));
}
}

if (errors.isEmpty()) {
AttributeRecord attribute = getAttribute(siteId, key);
if (attribute != null) {
errors = Collections.singletonList(
Expand Down
Loading

0 comments on commit 38d91fb

Please sign in to comment.