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 @@ -2,6 +2,7 @@

import com.sap.cds.Result;
import com.sap.cds.ql.Insert;
import com.sap.cds.ql.Update;
import com.sap.cds.reflect.CdsAssociationType;
import com.sap.cds.reflect.CdsElement;
import com.sap.cds.reflect.CdsEntity;
Expand Down Expand Up @@ -2000,6 +2001,21 @@ private void createDraftEntries(
throw new ServiceException(
"Failed to insert attachment entry in DB after retries: " + e.getMessage(), e);
}
// newDraft strips @readonly fields; DB DEFAULT 'Unscanned' applies for status.
// Bypass handler chain via persistenceService to persist status=Clean and scannedAt.
if (targetEntity != null) {
Map<String, Object> scanFields = new HashMap<>();
scanFields.put("status", "Clean");
scanFields.put("scannedAt", Instant.now());
String draftEntityName = targetEntity.getQualifiedName() + "_drafts";
var scanUpdate =
Update.entity(draftEntityName)
.data(scanFields)
.where(doc -> doc.get("objectId").eq(newObjectId));
persistenceService.run(scanUpdate);
logger.debug(
"Set status=Clean, scannedAt=now for copied draft attachment: {}", newObjectId);
}
} else {
logger.error("No suitable service found for entity: {}", request.getParentEntity());
throw new ServiceException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.lang.reflect.Method;
import java.util.*;
import org.ehcache.Cache;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand All @@ -48,6 +49,13 @@ public class SDMReadAttachmentsHandlerTest {

private static final String REPOSITORY_ID_KEY = "testRepoId";

@AfterEach
void tearDown() throws Exception {
java.lang.reflect.Field field = CacheConfig.class.getDeclaredField("errorMessageCache");
field.setAccessible(true);
field.set(null, null);
}

@Test
void testModifyCqnForAttachmentsEntity_Success() throws IOException {
// Arrange
Expand Down
Loading