Skip to content
Open
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
5 changes: 0 additions & 5 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ jobs:
with:
maven-version: ${{ env.MAVEN_VERSION }}

- name: Set Dry Run for Pull Request
if: github.event_name == 'pull_request_target'
run: echo "DRY_RUN_PARAM=-DaltDeploymentRepository=local-repo::default::file:./local-repo" >> $GITHUB_ENV
shell: bash

- name: Get Revision
id: get-revision
run: |
Expand Down
2 changes: 1 addition & 1 deletion .pipeline/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
steps:
mavenBuild:
verbose: false
verify: true
verify: false
flatten: true
# https://www.project-piper.io/steps/mavenBuild/#dockerimage
# If empty, Docker is not used and the command is executed directly on the Jenkins system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.sap.cds.feature.attachments.handler.applicationservice.transaction.CreationChangeSetListener;
import com.sap.cds.feature.attachments.handler.applicationservice.transaction.ListenerProvider;
import com.sap.cds.feature.attachments.handler.common.AssociationCascader;
import com.sap.cds.feature.attachments.handler.common.AttachmentCountValidator;
import com.sap.cds.feature.attachments.handler.common.AttachmentsReader;
import com.sap.cds.feature.attachments.handler.draftservice.DraftActiveAttachmentsHandler;
import com.sap.cds.feature.attachments.handler.draftservice.DraftCancelAttachmentsHandler;
Expand Down Expand Up @@ -88,7 +89,8 @@ public void eventHandlers(CdsRuntimeConfigurer configurer) {
OutboxService.PERSISTENT_UNORDERED_NAME);
}

// build malware scanner client, could be null if no service binding is available
// build malware scanner client, could be null if no service binding is
// available
MalwareScanClient scanClient = buildMalwareScanClient(runtime.getEnvironment());

AttachmentMalwareScanner malwareScanner =
Expand All @@ -109,17 +111,19 @@ public void eventHandlers(CdsRuntimeConfigurer configurer) {
buildAttachmentEventFactory(attachmentService, deleteEvent, outboxedAttachmentService);
AttachmentsReader attachmentsReader =
new AttachmentsReader(new AssociationCascader(), persistenceService);
AttachmentCountValidator countValidator = new AttachmentCountValidator();
ThreadLocalDataStorage storage = new ThreadLocalDataStorage();

// register event handlers for application service, if at least one application service is
// register event handlers for application service, if at least one application
// service is
// available
boolean hasApplicationServices =
serviceCatalog.getServices(ApplicationService.class).findFirst().isPresent();
if (hasApplicationServices) {
configurer.eventHandler(new CreateAttachmentsHandler(eventFactory, storage));
configurer.eventHandler(new CreateAttachmentsHandler(eventFactory, storage, countValidator));
configurer.eventHandler(
new UpdateAttachmentsHandler(
eventFactory, attachmentsReader, outboxedAttachmentService, storage));
eventFactory, attachmentsReader, outboxedAttachmentService, storage, countValidator));
configurer.eventHandler(new DeleteAttachmentsHandler(attachmentsReader, deleteEvent));
EndTransactionMalwareScanRunner scanRunner =
new EndTransactionMalwareScanRunner(null, null, malwareScanner, runtime);
Expand All @@ -131,13 +135,14 @@ public void eventHandlers(CdsRuntimeConfigurer configurer) {
"No application service is available. Application service event handlers will not be registered.");
}

// register event handlers on draft service, if at least one draft service is available
// register event handlers on draft service, if at least one draft service is
// available
boolean hasDraftServices =
serviceCatalog.getServices(DraftService.class).findFirst().isPresent();
if (hasDraftServices) {
configurer.eventHandler(new DraftPatchAttachmentsHandler(persistenceService, eventFactory));
configurer.eventHandler(new DraftCancelAttachmentsHandler(attachmentsReader, deleteEvent));
configurer.eventHandler(new DraftActiveAttachmentsHandler(storage));
configurer.eventHandler(new DraftActiveAttachmentsHandler(storage, countValidator));
} else {
logger.debug("No draft service is available. Draft event handlers will not be registered.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.sap.cds.feature.attachments.handler.applicationservice.helper.ThreadDataStorageReader;
import com.sap.cds.feature.attachments.handler.applicationservice.modifyevents.ModifyAttachmentEventFactory;
import com.sap.cds.feature.attachments.handler.common.ApplicationHandlerHelper;
import com.sap.cds.feature.attachments.handler.common.AttachmentCountValidator;
import com.sap.cds.services.EventContext;
import com.sap.cds.services.ServiceException;
import com.sap.cds.services.cds.ApplicationService;
Expand Down Expand Up @@ -40,11 +41,15 @@ public class CreateAttachmentsHandler implements EventHandler {

private final ModifyAttachmentEventFactory eventFactory;
private final ThreadDataStorageReader storageReader;
private final AttachmentCountValidator validator;

public CreateAttachmentsHandler(
ModifyAttachmentEventFactory eventFactory, ThreadDataStorageReader storageReader) {
ModifyAttachmentEventFactory eventFactory,
ThreadDataStorageReader storageReader,
AttachmentCountValidator validator) {
this.eventFactory = requireNonNull(eventFactory, "eventFactory must not be null");
this.storageReader = requireNonNull(storageReader, "storageReader must not be null");
this.validator = requireNonNull(validator, "validator must not be null");
}

@Before
Expand All @@ -60,9 +65,11 @@ void processBeforeForDraft(CdsCreateEventContext context, List<CdsData> data) {
@Before
@HandlerOrder(HandlerOrder.LATE)
void processBefore(CdsCreateEventContext context, List<CdsData> data) {
logger.debug(
"Processing before {} event for entity {}", context.getEvent(), context.getTarget());
// Validate attachment count regardless of content field presence
validator.validateForCreate(context.getTarget(), data);
if (ApplicationHandlerHelper.containsContentField(context.getTarget(), data)) {
logger.debug(
"Processing before {} event for entity {}", context.getEvent(), context.getTarget());
ModifyApplicationHandlerHelper.handleAttachmentForEntities(
context.getTarget(), data, new ArrayList<>(), eventFactory, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.sap.cds.feature.attachments.handler.applicationservice.helper.ThreadDataStorageReader;
import com.sap.cds.feature.attachments.handler.applicationservice.modifyevents.ModifyAttachmentEventFactory;
import com.sap.cds.feature.attachments.handler.common.ApplicationHandlerHelper;
import com.sap.cds.feature.attachments.handler.common.AttachmentCountValidator;
import com.sap.cds.feature.attachments.handler.common.AttachmentsReader;
import com.sap.cds.feature.attachments.service.AttachmentService;
import com.sap.cds.feature.attachments.service.model.service.MarkAsDeletedInput;
Expand Down Expand Up @@ -45,18 +46,21 @@ public class UpdateAttachmentsHandler implements EventHandler {
private final AttachmentsReader attachmentsReader;
private final AttachmentService attachmentService;
private final ThreadDataStorageReader storageReader;
private final AttachmentCountValidator validator;

public UpdateAttachmentsHandler(
ModifyAttachmentEventFactory eventFactory,
AttachmentsReader attachmentsReader,
AttachmentService attachmentService,
ThreadDataStorageReader storageReader) {
ThreadDataStorageReader storageReader,
AttachmentCountValidator validator) {
this.eventFactory = requireNonNull(eventFactory, "eventFactory must not be null");
this.attachmentsReader =
requireNonNull(attachmentsReader, "attachmentsReader must not be null");
this.attachmentService =
requireNonNull(attachmentService, "attachmentService must not be null");
this.storageReader = requireNonNull(storageReader, "storageReader must not be null");
this.validator = requireNonNull(validator, "validator must not be null");
}

@Before
Expand All @@ -79,6 +83,7 @@ void processBefore(CdsUpdateEventContext context, List<CdsData> data) {

if (containsContent || !associationsAreUnchanged) {
logger.debug("Processing before {} event for entity {}", context.getEvent(), target);
validator.validateForUpdate(target, data);

// Query database only for validation (single query for all attachments)
CqnSelect select = CqnUtils.toSelect(context.getCqn(), context.getTarget());
Expand Down
Loading