-
Notifications
You must be signed in to change notification settings - Fork 4
Change ActiveEntityModifier and add further checks to DraftCancelAttachmentsHandler #669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+253
−95
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
00c4f8a
Add debug statements to DraftCancelAttachmentsHandler::readAttachment…
lisajulia 85ed700
Add comment to DraftCancelAttachmentsHandler:isWhereEmpty function
lisajulia 2982ac0
Add 'isAttachmentEntity' and 'hasAttachmentAssociations' checks to
lisajulia dfee963
Change ActiveEntityModifier such that it flattens the delete requests
lisajulia e19621e
Add test to RegistrationTest.java so we reach the required jacoco cov…
lisajulia 3220975
Rename ActiveEntityModifier to ModifierToCreateFlatCQN
lisajulia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
69 changes: 0 additions & 69 deletions
69
.../main/java/com/sap/cds/feature/attachments/handler/draftservice/ActiveEntityModifier.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...in/java/com/sap/cds/feature/attachments/handler/draftservice/ModifierToCreateFlatCQN.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /* | ||
| * © 2024-2025 SAP SE or an SAP affiliate company and cds-feature-attachments contributors. | ||
| */ | ||
| package com.sap.cds.feature.attachments.handler.draftservice; | ||
|
|
||
| import com.sap.cds.ql.CQL; | ||
| import com.sap.cds.ql.RefBuilder; | ||
| import com.sap.cds.ql.RefBuilder.RefSegment; | ||
| import com.sap.cds.ql.StructuredTypeRef; | ||
| import com.sap.cds.ql.Value; | ||
| import com.sap.cds.ql.cqn.CqnComparisonPredicate.Operator; | ||
| import com.sap.cds.ql.cqn.CqnPredicate; | ||
| import com.sap.cds.ql.cqn.CqnStructuredTypeRef; | ||
| import com.sap.cds.ql.cqn.Modifier; | ||
| import com.sap.cds.services.draft.Drafts; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * A CQL modifier that transforms entity references for draft/active entity handling. | ||
| * | ||
| * <p>This modifier flattens complex entity references by removing nested references and creating a | ||
| * new CQN statement for the specified {@code fullEntityName}. It performs the following | ||
| * transformations: | ||
| * | ||
| * <ul> | ||
| * <li>Removes nested references and creates a new entity reference for {@code fullEntityName} | ||
| * <li>Preserves the filter from the last segment of the original {@link CqnStructuredTypeRef} | ||
| * <li>Adds an {@code IsActiveEntity} filter with the specified boolean value | ||
| * </ul> | ||
| * | ||
| * <p>This is primarily used in draft service scenarios to transform queries between draft entities | ||
| * (IsActiveEntity = false) and active entities (IsActiveEntity = true). | ||
| */ | ||
| class ModifierToCreateFlatCQN implements Modifier { | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(ModifierToCreateFlatCQN.class); | ||
|
|
||
| private final boolean isActiveEntity; | ||
| private final String fullEntityName; | ||
|
|
||
| ModifierToCreateFlatCQN(boolean isActiveEntity, String fullEntityName) { | ||
| this.isActiveEntity = isActiveEntity; | ||
| this.fullEntityName = fullEntityName; | ||
| } | ||
|
|
||
| @Override | ||
| public CqnStructuredTypeRef ref(CqnStructuredTypeRef original) { | ||
| RefBuilder<StructuredTypeRef> ref = CQL.copy(original); | ||
| RefSegment rootSegment = ref.rootSegment(); | ||
| logger.debug( | ||
| "Modifying ref {} with isActiveEntity: {} and fullEntityName: {}", | ||
| rootSegment, | ||
| isActiveEntity, | ||
| fullEntityName); | ||
|
|
||
| // Get the filter from the last segment: | ||
| // Get the last segment with targetSegment, then an Optional<CqnPredicate> with filter() | ||
| // which is then unwrapped to CqnPredicate or null by orElse(null). | ||
| CqnPredicate lastSegmentFilter = original.targetSegment().filter().orElse(null); | ||
|
|
||
| // Create an IsActiveEntity filter | ||
| CqnPredicate isActiveEntityFilter = CQL.get(Drafts.IS_ACTIVE_ENTITY).eq(isActiveEntity); | ||
|
|
||
| // Combine with original filter if it exists | ||
| CqnPredicate combinedFilter = | ||
| lastSegmentFilter != null | ||
| ? CQL.and(lastSegmentFilter, isActiveEntityFilter) | ||
| : isActiveEntityFilter; | ||
|
|
||
| // Apply any additional modifications (like replacing other IsActiveEntity references) | ||
| // This calls the comparison() method below for each comparison in the filter | ||
| CqnPredicate modifiedFilter = CQL.copy(combinedFilter, this); | ||
|
|
||
| // Create a new entity reference with the modified filter | ||
| return CQL.entity(fullEntityName).filter(modifiedFilter).asRef(); | ||
| } | ||
|
|
||
| @Override | ||
| public CqnPredicate comparison(Value<?> lhs, Operator op, Value<?> rhs) { | ||
| Value<?> rhsNew = rhs; | ||
| Value<?> lhsNew = lhs; | ||
| if (lhs.isRef() && Drafts.IS_ACTIVE_ENTITY.equals(lhs.asRef().lastSegment())) { | ||
| rhsNew = CQL.constant(isActiveEntity); | ||
| } | ||
| if (rhs.isRef() && Drafts.IS_ACTIVE_ENTITY.equals(rhs.asRef().lastSegment())) { | ||
| lhsNew = CQL.constant(isActiveEntity); | ||
| } | ||
| return CQL.comparison(lhsNew, op, rhsNew); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.