@@ -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 ();
0 commit comments