Skip to content

Commit

Permalink
chore(notifications): 547 - removed classification and type check on …
Browse files Browse the repository at this point in the history
…update methods.
  • Loading branch information
ds-mwesener committed Apr 4, 2024
1 parent 5c10016 commit 95c2c4d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -49,7 +51,7 @@ public class NotificationMapper {
public Notification toNotification(BPN bpn, String description, NotificationMessage notification, NotificationType notificationType) {

List<String> assetIds = new ArrayList<>();
notification.getAffectedParts().stream()
emptyIfNull(notification.getAffectedParts()).stream()
.map(NotificationAffectedPart::assetId)
.forEach(assetIds::add);
return Notification.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,7 +137,7 @@ public void addNotificationMessage(NotificationMessage notification) {
notifications = Collections.unmodifiableList(updatedNotifications);

List<String> newAssetIds = new ArrayList<>(assetIds); // create a mutable copy of assetIds
notification.getAffectedParts().stream()
emptyIfNull(notification.getAffectedParts()).stream()
.map(NotificationAffectedPart::assetId)
.forEach(newAssetIds::add);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class NotificationMessage {
private final String createdByName;
private final String sendToName;
@Builder.Default
private final List<NotificationAffectedPart> affectedParts = new ArrayList<>();
private List<NotificationAffectedPart> affectedParts = new ArrayList<>();
private String notificationReferenceId;
private String createdBy;
private String sendTo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import java.util.List;

import static org.apache.commons.collections4.ListUtils.emptyIfNull;

public class EDCNotificationFactory {

private EDCNotificationFactory() {
Expand Down Expand Up @@ -60,7 +62,7 @@ public static EDCNotification createEdcNotification(String senderEDC, Notificati


private static List<String> extractAssetIds(NotificationMessage notification) {
return notification.getAffectedParts().stream()
return emptyIfNull(notification.getAffectedParts()).stream()
.map(NotificationAffectedPart::assetId).toList();
}
}
Expand Down

0 comments on commit 95c2c4d

Please sign in to comment.