diff --git a/CHANGELOG.md b/CHANGELOG.md index ef6e276a16..4589418f9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). _**For better traceability add the corresponding GitHub issue number in each changelog entry, please.**_ ## [UNRELEASED - DD.MM.YYYY] +### Removed +- #547 Removed classification check on alert / investigation update callback methods ## [10.8.1 - 04.04.2024] diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/mapper/NotificationMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/mapper/NotificationMapper.java index 381417b75c..c02f000e1a 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/mapper/NotificationMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/mapper/NotificationMapper.java @@ -34,6 +34,8 @@ import java.util.ArrayList; import java.util.List; +import static org.apache.commons.collections4.ListUtils.emptyIfNull; + @RequiredArgsConstructor @Component public class NotificationMapper { @@ -49,7 +51,7 @@ public class NotificationMapper { public Notification toNotification(BPN bpn, String description, NotificationMessage notification, NotificationType notificationType) { List assetIds = new ArrayList<>(); - notification.getAffectedParts().stream() + emptyIfNull(notification.getAffectedParts()).stream() .map(NotificationAffectedPart::assetId) .forEach(assetIds::add); return Notification.builder() diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/mapper/NotificationMessageMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/mapper/NotificationMessageMapper.java index abda31df0b..cd1c942eca 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/mapper/NotificationMessageMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/mapper/NotificationMessageMapper.java @@ -31,6 +31,8 @@ import java.time.LocalDateTime; import java.util.UUID; +import static org.apache.commons.collections4.ListUtils.emptyIfNull; + @Component @RequiredArgsConstructor public class NotificationMessageMapper { @@ -56,7 +58,7 @@ public NotificationMessage toNotification(EDCNotification edcNotification, Notif .sendToName(getManufacturerName(edcNotification.getRecipientBPN())) .description(edcNotification.getInformation()) .notificationStatus(edcNotification.convertNotificationStatus()) - .affectedParts(edcNotification.getListOfAffectedItems()) + .affectedParts(emptyIfNull(edcNotification.getListOfAffectedItems())) .targetDate(edcNotification.getTargetDate()) .severity(NotificationSeverity.fromString(edcNotification.getSeverity())) .edcNotificationId(edcNotification.getNotificationId()) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/model/Notification.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/model/Notification.java index 8c84c78fb3..0eacd4892f 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/model/Notification.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/model/Notification.java @@ -33,6 +33,8 @@ import java.util.List; import java.util.Optional; +import static org.apache.commons.collections4.ListUtils.emptyIfNull; + @Data @Builder(toBuilder = true) @Slf4j @@ -135,7 +137,7 @@ public void addNotificationMessage(NotificationMessage notification) { notifications = Collections.unmodifiableList(updatedNotifications); List newAssetIds = new ArrayList<>(assetIds); // create a mutable copy of assetIds - notification.getAffectedParts().stream() + emptyIfNull(notification.getAffectedParts()).stream() .map(NotificationAffectedPart::assetId) .forEach(newAssetIds::add); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/model/NotificationMessage.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/model/NotificationMessage.java index ac1faf0a0c..084e545443 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/model/NotificationMessage.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/model/NotificationMessage.java @@ -43,7 +43,7 @@ public class NotificationMessage { private final String createdByName; private final String sendToName; @Builder.Default - private final List affectedParts = new ArrayList<>(); + private List affectedParts = new ArrayList<>(); private String notificationReferenceId; private String createdBy; private String sendTo; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/AbstractNotificationReceiverService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/AbstractNotificationReceiverService.java index 72dd7affe6..80b6e99109 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/AbstractNotificationReceiverService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/AbstractNotificationReceiverService.java @@ -29,6 +29,8 @@ import org.eclipse.tractusx.traceability.notification.domain.notification.repository.NotificationRepository; import org.eclipse.tractusx.traceability.notification.infrastructure.edc.model.EDCNotification; +import static org.apache.commons.collections4.ListUtils.emptyIfNull; + @Slf4j public abstract class AbstractNotificationReceiverService implements NotificationReceiverService { @@ -53,9 +55,11 @@ public void handleReceive(EDCNotification edcNotification, NotificationType noti @Override public void handleUpdate(EDCNotification edcNotification, NotificationType notificationType) { - NotificationMessage notificationMessage = getNotificationMessageMapper().toNotification(edcNotification, notificationType); + Notification notification = getRepository().findByEdcNotificationId(edcNotification.getNotificationId()) .orElseThrow(() -> getNotFoundException(edcNotification.getNotificationId())); + NotificationMessage notificationMessage = getNotificationMessageMapper().toNotification(edcNotification, notificationType); + emptyIfNull(notification.getNotifications()).stream().findFirst().ifPresent(notificationMessage1 -> notificationMessage.setAffectedParts(notificationMessage1.getAffectedParts())); switch (edcNotification.convertNotificationStatus()) { case ACKNOWLEDGED -> notification.acknowledge(); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/edc/EdcController.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/edc/EdcController.java index 876452d8f9..4b4e2ecdac 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/edc/EdcController.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/edc/EdcController.java @@ -168,7 +168,6 @@ public void investigationNotificationReceive(final @ValidEDCNotification @Valid public void investigationNotificationUpdate(final @ValidEDCNotification @Valid @RequestBody EDCNotification edcNotification) { EDCNotification cleanEdcNotification = sanitize(edcNotification); log.info("EdcController [investigationNotificationUpdate] notificationId:{}", cleanEdcNotification); - validateIsInvestigation(cleanEdcNotification); notificationReceiverService.handleUpdate(cleanEdcNotification, NotificationType.INVESTIGATION); } @@ -288,7 +287,6 @@ public void alertNotificationReceive(final @ValidEDCNotification @Valid @Request public void alertNotificationUpdate(final @ValidEDCNotification @Valid @RequestBody EDCNotification edcNotification) { EDCNotification cleanEdcNotification = sanitize(edcNotification); log.info("EdcController [alertNotificationUpdate] notificationId:{}", cleanEdcNotification); - validateIsAlert(cleanEdcNotification); notificationReceiverService.handleUpdate(cleanEdcNotification, NotificationType.ALERT); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/edc/model/EDCNotificationFactory.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/edc/model/EDCNotificationFactory.java index e159dbd99e..a2a488201d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/edc/model/EDCNotificationFactory.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/edc/model/EDCNotificationFactory.java @@ -26,6 +26,8 @@ import java.util.List; +import static org.apache.commons.collections4.ListUtils.emptyIfNull; + public class EDCNotificationFactory { private EDCNotificationFactory() { @@ -60,7 +62,7 @@ public static EDCNotification createEdcNotification(String senderEDC, Notificati private static List extractAssetIds(NotificationMessage notification) { - return notification.getAffectedParts().stream() + return emptyIfNull(notification.getAffectedParts()).stream() .map(NotificationAffectedPart::assetId).toList(); } } diff --git a/tx-backend/src/test/resources/testdata/edc_notification_okay_update.json b/tx-backend/src/test/resources/testdata/edc_notification_okay_update.json index ef512623d8..6cc50b1195 100644 --- a/tx-backend/src/test/resources/testdata/edc_notification_okay_update.json +++ b/tx-backend/src/test/resources/testdata/edc_notification_okay_update.json @@ -4,16 +4,12 @@ "senderBPN" : "BPNL00000003AXS3", "senderAddress" : "https://some-url.com", "recipientBPN" : "BPNL00000003AXS3", - "classification" : "QM-Investigation", "severity" : "CRITICAL", "relatedNotificationId" : "REPLACE_ME", "status" : "ACKNOWLEDGED", "targetDate" : "2099-03-11T22:44:06.333826952Z" }, "content" : { - "information" : "Some long description", - "listOfAffectedItems" : [ - "urn:uuid:d387fa8e-603c-42bd-98c3-4d87fef8d2bb" - ] + "information" : "Some long description" } }