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 @@ -8,4 +8,4 @@ spring:
schema-locations: classpath:schema-h2.sql
data-source:
auto-config:
enabled: false
enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,15 @@ public void populateUploadableFlags(CdsReadEventContext context, List<CdsData> d
CdsModel model = context.getModel();
// Cache keyed by "facetName|parentId|isDraft" to avoid one DB query per row per facet.
Map<String, Boolean> uploadableCache = new HashMap<>();

// Non-draft entities have no IsActiveEntity; treat every row as active (isDraft=false).
boolean entityHasDraftSupport = target.findElement("IsActiveEntity").isPresent();

for (CdsData row : data) {
// Determine draft state per row — a single result set can mix active and draft records.
boolean rowIsDraft = Boolean.FALSE.equals(row.get("IsActiveEntity"));
// On a non-draft entity IsActiveEntity is absent; default to false (active).
boolean rowIsDraft =
entityHasDraftSupport && Boolean.FALSE.equals(row.get("IsActiveEntity"));
Object keyVal = row.get(keyField);
if (keyVal == null) {
logger.debug("populateUploadableFlags Path1: skipping row with null keyVal");
Expand Down
32 changes: 22 additions & 10 deletions sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ public Result getAttachmentsForUPID(
upID,
upIdKey,
attachmentEntity.getQualifiedName());
List<String> columns =
new ArrayList<>(
java.util.Arrays.asList("fileName", "ID", "folderId", "repositoryId", "mimeType"));
if (attachmentEntity.findElement("IsActiveEntity").isPresent()) {
columns.add("IsActiveEntity");
}
CqnSelect q =
Select.from(attachmentEntity)
.columns("fileName", "ID", "IsActiveEntity", "folderId", "repositoryId", "mimeType")
.columns(columns.toArray(new String[0]))
.where(doc -> doc.get(upIdKey).eq(upID));
Result result = persistenceService.run(q);
logger.debug("Found {} attachment(s) for upID: {}", result.rowCount(), upID);
Expand Down Expand Up @@ -378,9 +384,14 @@ public Result getAttachmentsForUPIDAndRepository(
upID,
SDMConstants.REPOSITORY_ID,
attachmentEntity.getQualifiedName());
List<String> columns =
new ArrayList<>(java.util.Arrays.asList("fileName", "ID", "folderId", "repositoryId"));
if (attachmentEntity.findElement("IsActiveEntity").isPresent()) {
columns.add("IsActiveEntity");
}
CqnSelect q =
Select.from(attachmentEntity)
.columns("fileName", "ID", "IsActiveEntity", "folderId", "repositoryId")
.columns(columns.toArray(new String[0]))
.where(
doc ->
doc.get(upIdKey)
Expand Down Expand Up @@ -511,16 +522,17 @@ public List<CmisDocument> getAttachmentsForFolder(
folderId,
entity);
attachmentEntity = context.getModel().findEntity(entity);
List<String> activeColumns =
new ArrayList<>(
java.util.Arrays.asList(
"fileName", "ID", "folderId", "repositoryId", "objectId", "uploadStatus"));
if (attachmentEntity.isPresent()
&& attachmentEntity.get().findElement("IsActiveEntity").isPresent()) {
activeColumns.add(1, "IsActiveEntity");
}
q =
Select.from(attachmentEntity.get())
.columns(
"fileName",
"IsActiveEntity",
"ID",
"folderId",
"repositoryId",
"objectId",
"uploadStatus")
.columns(activeColumns.toArray(new String[0]))
.where(doc -> doc.get("folderId").eq(folderId));
result = persistenceService.run(q);
for (Row row : result.list()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ void testPopulateUploadableFlags_path1_isDraft_draftEntityFound() {
when(target.getQualifiedName()).thenReturn("sap.capire.Books");
when(target.compositions()).thenAnswer(inv -> Stream.of(buildComposition("attachments", "3")));
when(target.elements()).thenAnswer(inv -> Stream.of(buildKeyElement("ID")));
// entity has draft support — IsActiveEntity element is present
when(target.findElement("IsActiveEntity")).thenReturn(Optional.of(mock(CdsElement.class)));
// isDraft=true because IsActiveEntity=false
when(model.findEntity("sap.capire.Books.attachments_drafts"))
.thenReturn(Optional.of(draftAttachmentEntity));
Expand Down Expand Up @@ -262,6 +264,8 @@ void testPopulateUploadableFlags_path1_isDraft_draftEntityNotFound_fallbackActiv
when(target.getQualifiedName()).thenReturn("sap.capire.Books");
when(target.compositions()).thenAnswer(inv -> Stream.of(buildComposition("attachments", "2")));
when(target.elements()).thenAnswer(inv -> Stream.of(buildKeyElement("ID")));
// entity has draft support — IsActiveEntity element is present
when(target.findElement("IsActiveEntity")).thenReturn(Optional.of(mock(CdsElement.class)));
when(model.findEntity("sap.capire.Books.attachments_drafts")).thenReturn(Optional.empty());
when(model.findEntity("sap.capire.Books.attachments"))
.thenReturn(Optional.of(activeAttachmentEntity));
Expand Down
Loading