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 @@ -22,7 +22,6 @@
import com.sap.cds.feature.attachments.handler.applicationservice.processor.readhelper.stream.LazyProxyInputStream;
import com.sap.cds.feature.attachments.handler.applicationservice.processor.readhelper.validator.AttachmentStatusValidator;
import com.sap.cds.feature.attachments.handler.common.ApplicationHandlerHelper;
import com.sap.cds.feature.attachments.handler.draftservice.constants.DraftConstants;
import com.sap.cds.feature.attachments.service.AttachmentService;
import com.sap.cds.feature.attachments.service.malware.AsyncMalwareScanExecutor;
import com.sap.cds.ql.CQL;
Expand All @@ -33,6 +32,7 @@
import com.sap.cds.reflect.CdsModel;
import com.sap.cds.services.cds.ApplicationService;
import com.sap.cds.services.cds.CdsReadEventContext;
import com.sap.cds.services.draft.Drafts;
import com.sap.cds.services.handler.EventHandler;
import com.sap.cds.services.handler.annotations.After;
import com.sap.cds.services.handler.annotations.Before;
Expand Down Expand Up @@ -121,7 +121,7 @@ private List<String> getAttachmentAssociations(CdsModel model, CdsEntity entity,

for (var associatedElement : annotatedEntitiesMap.entrySet()) {
if (!associationNames.contains(associatedElement.getKey()) && !processedEntities.contains(
associatedElement.getKey()) && !DraftConstants.SIBLING_ENTITY.equals(associatedElement.getKey())) {
associatedElement.getKey()) && !Drafts.SIBLING_ENTITY.equals(associatedElement.getKey())) {
processedEntities.add(associatedElement.getKey());
var result = getAttachmentAssociations(model, associatedElement.getValue(), associatedElement.getKey(),
processedEntities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ private boolean isWhereEmpty(DraftCancelEventContext context) {
}

private CdsStructuredType getActiveEntity(DraftCancelEventContext context) {
return isDraftEntity(context) ? context.getTarget().getTargetOf(DraftConstants.SIBLING_ENTITY) : context.getTarget();
return isDraftEntity(context) ? context.getTarget().getTargetOf(Drafts.SIBLING_ENTITY) : context.getTarget();
}

private CdsStructuredType getDraftEntity(DraftCancelEventContext context) {
return isDraftEntity(context) ? context.getTarget() : context.getTarget().getTargetOf(DraftConstants.SIBLING_ENTITY);
return isDraftEntity(context) ? context.getTarget() : context.getTarget().getTargetOf(Drafts.SIBLING_ENTITY);
}

private boolean isDraftEntity(DraftCancelEventContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.sap.cds.ql.Select;
import com.sap.cds.services.draft.DraftPatchEventContext;
import com.sap.cds.services.draft.DraftService;
import com.sap.cds.services.draft.Drafts;
import com.sap.cds.services.handler.EventHandler;
import com.sap.cds.services.handler.annotations.Before;
import com.sap.cds.services.handler.annotations.HandlerOrder;
Expand Down Expand Up @@ -50,7 +51,7 @@ public void processBeforeDraftPatch(DraftPatchEventContext context, List<CdsData
Converter converter = (path, element, value) -> {
var draftElement = path.target().entity().getQualifiedName().endsWith(DraftConstants.DRAFT_TABLE_POSTFIX)
? path.target().entity()
: path.target().entity().getTargetOf(DraftConstants.SIBLING_ENTITY);
: path.target().entity().getTargetOf(Drafts.SIBLING_ENTITY);
var select = Select.from(draftElement.getQualifiedName()).matching(path.target().keys());
var result = persistence.run(select);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

public final class DraftConstants {

public static final String SIBLING_ENTITY = "SiblingEntity";
public static final String DRAFT_TABLE_POSTFIX = "_drafts";

private DraftConstants() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import com.sap.cds.Result;
import com.sap.cds.feature.attachments.generated.cds4j.sap.attachments.Attachments;
import com.sap.cds.feature.attachments.generated.cds4j.sap.attachments.StatusCode;
import com.sap.cds.feature.attachments.handler.draftservice.constants.DraftConstants;
import com.sap.cds.feature.attachments.service.AttachmentService;
import com.sap.cds.feature.attachments.service.malware.client.MalwareScanClient;
import com.sap.cds.feature.attachments.service.malware.client.model.MalwareScanResultStatus;
import com.sap.cds.ql.Select;
import com.sap.cds.ql.Update;
import com.sap.cds.reflect.CdsElementNotFoundException;
import com.sap.cds.reflect.CdsEntity;
import com.sap.cds.services.draft.Drafts;
import com.sap.cds.services.persistence.PersistenceService;

/**
Expand Down Expand Up @@ -81,7 +81,7 @@ public void scanAttachment(CdsEntity attachmentEntity, String contentId) {
private List<SelectionResult> selectData(CdsEntity attachmentEntity, String contentId) {
var result = new ArrayList<SelectionResult>();
try {
var entity = (CdsEntity) attachmentEntity.getTargetOf(DraftConstants.SIBLING_ENTITY);
var entity = (CdsEntity) attachmentEntity.getTargetOf(Drafts.SIBLING_ENTITY);
var selectionResult = readData(contentId, entity);
result.add(new SelectionResult(entity, selectionResult));
} catch (CdsElementNotFoundException ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.sap.cds.ql.cqn.CqnDelete;
import com.sap.cds.reflect.CdsEntity;
import com.sap.cds.services.draft.DraftCancelEventContext;
import com.sap.cds.services.draft.Drafts;
import com.sap.cds.services.runtime.CdsRuntime;

class DraftCancelAttachmentsHandlerTest {
Expand Down Expand Up @@ -97,7 +98,7 @@ void attachmentReaderCorrectCalled() {
assertThat(originDelete.toJson()).isEqualTo(delete.toJson());

deleteArgumentCaptor = ArgumentCaptor.forClass(CqnDelete.class);
CdsEntity siblingTarget = target.getTargetOf(DraftConstants.SIBLING_ENTITY);
CdsEntity siblingTarget = target.getTargetOf(Drafts.SIBLING_ENTITY);
verify(attachmentsReader).readAttachments(eq(runtime.getCdsModel()), eq(siblingTarget),
deleteArgumentCaptor.capture());
CqnDelete siblingDelete = deleteArgumentCaptor.getValue();
Expand All @@ -116,7 +117,7 @@ void modifierCalledWithCorrectEntitiesIfDraftIsInContext() {
CdsEntity target = eventContext.getTarget();
verify(attachmentsReader).readAttachments(eq(runtime.getCdsModel()), eq(target),
deleteArgumentCaptor.capture());
CdsEntity siblingTarget = target.getTargetOf(DraftConstants.SIBLING_ENTITY);
CdsEntity siblingTarget = target.getTargetOf(Drafts.SIBLING_ENTITY);
verify(attachmentsReader).readAttachments(eq(runtime.getCdsModel()), eq(siblingTarget),
deleteArgumentCaptor.capture());
CqnDelete siblingDelete = deleteArgumentCaptor.getValue();
Expand All @@ -129,7 +130,7 @@ void createdEntityNeedsToBeDeleted() {
CqnDelete delete = Delete.from(RootTable_.class);
when(eventContext.getCqn()).thenReturn(delete);
when(eventContext.getModel()).thenReturn(runtime.getCdsModel());
CdsEntity siblingTarget = eventContext.getTarget().getTargetOf(DraftConstants.SIBLING_ENTITY);
CdsEntity siblingTarget = eventContext.getTarget().getTargetOf(Drafts.SIBLING_ENTITY);
Attachment attachment = buildAttachmentAndReturnByReader("test", siblingTarget, false, "");

cut.processBeforeDraftCancel(eventContext);
Expand All @@ -145,7 +146,7 @@ void updatedEntityNeedsToBeDeleted() {
var delete = Delete.from(RootTable_.class);
when(eventContext.getCqn()).thenReturn(delete);
when(eventContext.getModel()).thenReturn(runtime.getCdsModel());
CdsEntity siblingTarget = eventContext.getTarget().getTargetOf(DraftConstants.SIBLING_ENTITY);
CdsEntity siblingTarget = eventContext.getTarget().getTargetOf(Drafts.SIBLING_ENTITY);
var id = UUID.randomUUID().toString();
Attachment draftAttachment = buildAttachmentAndReturnByReader("test", siblingTarget, true, id);
buildAttachmentAndReturnByReader("test origin", eventContext.getTarget(), false, id);
Expand All @@ -163,7 +164,7 @@ void entityNotUpdatedNothingToDelete() {
var delete = Delete.from(RootTable_.class);
when(eventContext.getCqn()).thenReturn(delete);
when(eventContext.getModel()).thenReturn(runtime.getCdsModel());
CdsEntity siblingTarget = eventContext.getTarget().getTargetOf(DraftConstants.SIBLING_ENTITY);
CdsEntity siblingTarget = eventContext.getTarget().getTargetOf(Drafts.SIBLING_ENTITY);
var id = UUID.randomUUID().toString();
var contentId = UUID.randomUUID().toString();
buildAttachmentAndReturnByReader(contentId, siblingTarget, true, id);
Expand Down