Skip to content

Commit e3dbbe1

Browse files
committed
update
1 parent 9d59d83 commit e3dbbe1

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

dynamodb-documents/src/main/java/com/formkiq/stacks/dynamodb/DocumentServiceImpl.java

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,11 @@ public boolean deleteDocument(final String siteId, final String documentId,
442442

443443
this.versionsService.deleteAllVersionIds(this.dbClient, siteId, documentId);
444444

445-
DocumentItem item = findDocument(siteId, documentId);
445+
Map<String, AttributeValue> documentRecord = getDocumentRecord(siteId, documentId);
446446

447-
deleteFolderIndex(siteId, item);
447+
if (documentRecord.containsKey("path")) {
448+
deleteFolderIndex(siteId, documentRecord.get("path").s());
449+
}
448450

449451
Map<String, AttributeValue> keys = keysGeneric(siteId, PREFIX_DOCS + documentId, null);
450452
AttributeValue pk = keys.get(PK);
@@ -468,13 +470,27 @@ public boolean deleteDocument(final String siteId, final String documentId,
468470

469471
list.addAll(queryDocumentAttributes(pk, sk, false));
470472

471-
if (this.dbService.deleteItems(list)) {
473+
List<Map<String, AttributeValue>> listKeys = list.stream()
474+
.map(map -> map.entrySet().stream()
475+
.filter(entry -> entry.getKey().equals(PK) || entry.getKey().equals(SK))
476+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
477+
.toList();
478+
479+
if (this.dbService.deleteItems(listKeys)) {
472480
deleted = true;
473481
}
474482
}
475483

476484
if (this.interceptor != null) {
477-
this.interceptor.deleteDocument(siteId, documentId, softDelete);
485+
486+
if (documentRecord.isEmpty()) {
487+
documentRecord = list.stream().filter(l -> l.get(SK).s().startsWith("softdelete#document#"))
488+
.findAny().orElse(null);
489+
}
490+
491+
AttributeValueToMap transform = new AttributeValueToMap();
492+
Map<String, Object> apply = transform.apply(documentRecord);
493+
this.interceptor.deleteDocument(siteId, documentId, softDelete, apply);
478494
}
479495

480496
return deleted;
@@ -613,13 +629,13 @@ public void deleteDocumentTags(final String siteId, final String documentId) {
613629
* Delete Folder Index.
614630
*
615631
* @param siteId {@link String}
616-
* @param item {@link DocumentItem}
632+
* @param path {@link String}
617633
*/
618-
private void deleteFolderIndex(final String siteId, final DocumentItem item) {
619-
if (item != null) {
634+
private void deleteFolderIndex(final String siteId, final String path) {
635+
if (!isEmpty(path)) {
620636

621637
try {
622-
Map<String, String> attr = this.folderIndexProcessor.getIndex(siteId, item.getPath());
638+
Map<String, String> attr = this.folderIndexProcessor.getIndex(siteId, path);
623639

624640
if (attr.containsKey("documentId")) {
625641
deleteItem(Map.of(PK, AttributeValue.builder().s(attr.get(PK)).build(), SK,
@@ -805,6 +821,14 @@ private <T> PaginationResults<T> findAndTransform(final String pkKey, final Stri
805821
return new PaginationResults<>(list, results.getToken());
806822
}
807823

824+
private Map<String, AttributeValue> getDocumentRecord(final String siteId,
825+
final String documentId) {
826+
GetItemRequest r = GetItemRequest.builder().key(keysDocument(siteId, documentId))
827+
.tableName(this.documentTableName).consistentRead(Boolean.TRUE).build();
828+
829+
return this.dbClient.getItem(r).item();
830+
}
831+
808832
@Override
809833
public DocumentItem findDocument(final String siteId, final String documentId) {
810834
return findDocument(siteId, documentId, false, null, 0).getResult();
@@ -817,10 +841,7 @@ public PaginationResult<DocumentItem> findDocument(final String siteId, final St
817841
DocumentItem item = null;
818842
PaginationMapToken pagination = null;
819843

820-
GetItemRequest r = GetItemRequest.builder().key(keysDocument(siteId, documentId))
821-
.tableName(this.documentTableName).consistentRead(Boolean.TRUE).build();
822-
823-
Map<String, AttributeValue> result = this.dbClient.getItem(r).item();
844+
Map<String, AttributeValue> result = getDocumentRecord(siteId, documentId);
824845

825846
if (result != null && !result.isEmpty()) {
826847

@@ -1579,7 +1600,7 @@ private List<Map<String, AttributeValue>> queryDocumentAttributes(final Attribut
15791600
final int limit = 100;
15801601
Map<String, AttributeValue> startkey = null;
15811602
List<Map<String, AttributeValue>> list = new ArrayList<>();
1582-
QueryConfig config = new QueryConfig().projectionExpression(softDelete ? null : "PK,SK");
1603+
QueryConfig config = new QueryConfig();
15831604

15841605
do {
15851606

@@ -1765,7 +1786,8 @@ public boolean restoreSoftDeletedDocument(final String siteId, final String docu
17651786
new DocumentRestoreMoveAttributeFunction(siteId, documentId));
17661787

17671788
if (this.interceptor != null) {
1768-
this.interceptor.restoreSoftDeletedDocument(siteId, documentId);
1789+
Map<String, Object> apply = new AttributeValueToMap().apply(attr);
1790+
this.interceptor.restoreSoftDeletedDocument(siteId, documentId, apply);
17691791
}
17701792

17711793
String path = attr.get("path").s();

dynamodb-documents/src/main/java/com/formkiq/stacks/dynamodb/DocumentServiceInterceptor.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@ void saveDocument(String siteId, String documentId, Map<String, Object> current,
4747
* @param siteId {@link String}
4848
* @param documentId {@link String}
4949
* @param softDelete boolean
50+
* @param current {@link Map}
5051
*/
51-
void deleteDocument(String siteId, String documentId, boolean softDelete);
52+
void deleteDocument(String siteId, String documentId, boolean softDelete,
53+
Map<String, Object> current);
5254

5355
/**
5456
* Restore Soft Deleted Document Inteerceptor.
5557
*
5658
* @param siteId {@link String}
5759
* @param documentId {@link String}
60+
* @param current {@link Map}
5861
*/
59-
void restoreSoftDeletedDocument(String siteId, String documentId);
62+
void restoreSoftDeletedDocument(String siteId, String documentId, Map<String, Object> current);
6063
}

fkq-plugins/src/main/java/com/formkiq/plugins/useractivity/UserActivityPlugin.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,38 @@ public interface UserActivityPlugin {
5353
*
5454
* @param siteId {@link String}
5555
* @param documentId {@link String}
56-
* @param record {@link Map}
56+
* @param current {@link Map}
57+
* @param previous {@link Map}
5758
*/
58-
void updateDocumentActivity(String siteId, String documentId, Map<String, Object> record);
59+
void updateDocumentActivity(String siteId, String documentId, Map<String, Object> current,
60+
Map<String, Object> previous);
5961

6062
/**
6163
* Add delete Document Activity.
6264
*
6365
* @param siteId {@link String}
6466
* @param documentId {@link String}
67+
* @param record {@link Map}
6568
*/
66-
void deleteDocumentActivity(String siteId, String documentId);
69+
void deleteDocumentActivity(String siteId, String documentId, Map<String, Object> record);
6770

6871

6972
/**
7073
* Add soft delete Document Activity.
7174
*
7275
* @param siteId {@link String}
7376
* @param documentId {@link String}
77+
* @param record {@link Map}
7478
*/
75-
void deleteSoftDocumentActivity(String siteId, String documentId);
79+
void deleteSoftDocumentActivity(String siteId, String documentId, Map<String, Object> record);
7680

7781
/**
7882
* Restore Soft Delete Document Activity.
7983
*
8084
* @param siteId {@link String}
8185
* @param documentId {@link String}
86+
* @param record {@link Map}
8287
*/
83-
void restoreSoftDeletedDocumentActivity(String siteId, String documentId);
88+
void restoreSoftDeletedDocumentActivity(String siteId, String documentId,
89+
Map<String, Object> record);
8490
}

0 commit comments

Comments
 (0)