@@ -1934,28 +1934,10 @@ private void createDraftEntries(
19341934 String newObjectId = attachmentMetadata .get ("cmis:objectId" );
19351935 logger .debug ("Processing draft entry for objectId: {}, fileName: {}" , newObjectId , fileName );
19361936
1937- // Read status and scannedAt from the source attachment so copies preserve the original
1938- // values.
1939- String resolvedStatus = "Clean" ;
1940- Instant resolvedScannedAt = Instant .now ();
1941- List <String > sourceObjectIds = request .getSourceObjectIds ();
1942- if (targetEntity != null && sourceObjectIds != null && i < sourceObjectIds .size ()) {
1943- String sourceObjectId = sourceObjectIds .get (i );
1944- Optional <Row > sourceRow =
1945- persistenceService
1946- .run (
1947- Select .from (targetEntity )
1948- .columns ("status" , "scannedAt" )
1949- .where (doc -> doc .get ("objectId" ).eq (sourceObjectId ))
1950- .limit (1 ))
1951- .first ();
1952- if (sourceRow .isPresent ()) {
1953- Object statusVal = sourceRow .get ().get ("status" );
1954- Object scannedAtVal = sourceRow .get ().get ("scannedAt" );
1955- if (statusVal != null ) resolvedStatus = statusVal .toString ();
1956- if (scannedAtVal instanceof Instant ) resolvedScannedAt = (Instant ) scannedAtVal ;
1957- }
1958- }
1937+ SourceScanState scanState =
1938+ resolveSourceScanState (targetEntity , request .getSourceObjectIds (), i );
1939+ String resolvedStatus = scanState .status ;
1940+ Instant resolvedScannedAt = scanState .scannedAt ;
19591941 logger .debug (
19601942 "Resolved status={}, scannedAt={} for source attachment at index {}" ,
19611943 resolvedStatus ,
@@ -2059,6 +2041,40 @@ private void createDraftEntries(
20592041 logger .debug ("Completed creating draft entries for copied attachments" );
20602042 }
20612043
2044+ private SourceScanState resolveSourceScanState (
2045+ CdsEntity targetEntity , List <String > sourceObjectIds , int index ) {
2046+ if (targetEntity == null || sourceObjectIds == null || index >= sourceObjectIds .size ()) {
2047+ return new SourceScanState ("Clean" , Instant .now ());
2048+ }
2049+ String sourceObjectId = sourceObjectIds .get (index );
2050+ Optional <Row > sourceRow =
2051+ persistenceService
2052+ .run (
2053+ Select .from (targetEntity )
2054+ .columns ("status" , "scannedAt" )
2055+ .where (doc -> doc .get ("objectId" ).eq (sourceObjectId ))
2056+ .limit (1 ))
2057+ .first ();
2058+ if (sourceRow .isEmpty ()) {
2059+ return new SourceScanState ("Clean" , Instant .now ());
2060+ }
2061+ Object statusVal = sourceRow .get ().get ("status" );
2062+ Object scannedAtVal = sourceRow .get ().get ("scannedAt" );
2063+ String status = statusVal != null ? statusVal .toString () : "Clean" ;
2064+ Instant scannedAt = scannedAtVal instanceof Instant inst ? inst : Instant .now ();
2065+ return new SourceScanState (status , scannedAt );
2066+ }
2067+
2068+ private static final class SourceScanState {
2069+ final String status ;
2070+ final Instant scannedAt ;
2071+
2072+ SourceScanState (String status , Instant scannedAt ) {
2073+ this .status = status ;
2074+ this .scannedAt = scannedAt ;
2075+ }
2076+ }
2077+
20622078 /**
20632079 * Rolls back successfully moved attachments when database update fails. Moves attachments back to
20642080 * their original source folder in parallel. Continues with remaining rollbacks even if individual
0 commit comments