Skip to content

Commit

Permalink
feature(refactoring):962 update models.
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-mwesener committed Jun 17, 2024
1 parent 3bcf175 commit 65dd051
Show file tree
Hide file tree
Showing 30 changed files with 96 additions and 16,449 deletions.
8,143 changes: 1 addition & 8,142 deletions docs/api/traceability-foss-backend.json

Large diffs are not rendered by default.

8,143 changes: 1 addition & 8,142 deletions tx-backend/openapi/traceability-foss-backend.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public NotificationMessage toNotificationMessage(EDCNotification edcNotification
.message(edcNotification.getInformation())
.notificationStatus(edcNotification.convertNotificationStatus())
.affectedParts(emptyIfNull(edcNotification.getListOfAffectedItems()))
.targetDate(edcNotification.getTargetDate())
.severity(NotificationSeverity.fromString(edcNotification.getSeverity()))
.edcNotificationId(edcNotification.getNotificationId())
.messageId(edcNotification.getMessageId())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,15 @@ public static NotificationMessageResponse fromNotification(NotificationMessage n
return NotificationMessageResponse
.builder()
.id(notificationMessage.getId())
.severity(notificationMessage.getSeverity() != null ? NotificationSeverityResponse.fromString(notificationMessage.getSeverity().getRealName()) : null)
.notificationReferenceId(notificationMessage.getNotificationReferenceId())
.edcNotificationId(notificationMessage.getEdcNotificationId())
.contractAgreementId(notificationMessage.getContractAgreementId())
.notificationReferenceId(notificationMessage.getNotificationReferenceId())
.messageId(notificationMessage.getMessageId())
.updated(notificationMessage.getUpdated())
.sendToName(notificationMessage.getSendToName())
.status(fromStatus(notificationMessage.getNotificationStatus()))
.targetDate(notificationMessage.getTargetDate())
.created(notificationMessage.getCreated())
.createdBy(notificationMessage.getSentBy())
.createdByName(notificationMessage.getSentByName())
.sentBy(notificationMessage.getSentBy())
.sentByName(notificationMessage.getSentByName())
.sendTo(notificationMessage.getSentTo())
.errorMessage(notificationMessage.getErrorMessage())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
package org.eclipse.tractusx.traceability.notification.application.notification.mapper;

import lombok.experimental.UtilityClass;
import notification.response.NotificationResponse;
import notification.response.NotificationSeverityResponse;
import org.eclipse.tractusx.traceability.common.model.PageResult;
import org.eclipse.tractusx.traceability.notification.domain.base.model.Notification;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationMessage;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationSeverity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import notification.response.NotificationResponse;

import java.time.Instant;
import java.time.OffsetDateTime;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -57,8 +56,8 @@ public static NotificationResponse from(Notification notification) {
.updatedDate(OffsetDateTime.now().toString())
.sendTo(getReceiverBPN(notification.getNotifications()))
.sendToName(getReceiverName(notification.getNotifications()))
.severity(NotificationMessageMapper.from(notification.getNotifications().stream().findFirst().map(NotificationMessage::getSeverity).orElse(NotificationSeverity.MINOR)))
.targetDate(notification.getNotifications().stream().findFirst().map(NotificationMessage::getTargetDate).map(Instant::toString).orElse(null))
.severity(NotificationSeverityResponse.fromString(notification.getNotificationSeverity().getRealName()))
.targetDate(notification.getTargetDate())
.messages(fromNotifications(notification.getNotifications()))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class Notification {
@Builder.Default
private List<String> affectedPartIds = new ArrayList<>();
private NotificationSeverity notificationSeverity;
private String targetDate;

@Getter
@Builder.Default
Expand Down Expand Up @@ -132,10 +133,9 @@ public String getBpn() {
return bpn.value();
}

public void cancel(BPN applicationBpn, NotificationMessage notificationMessage) {
public void cancel(BPN applicationBpn) {
validateBPN(applicationBpn);
changeStatusTo(NotificationStatus.CANCELED);
notificationMessage.setMessage("cancelled");
}

public void close(BPN applicationBpn, String reason, NotificationMessage notificationMessage) {
Expand All @@ -149,9 +149,9 @@ public void acknowledge() {
changeStatusTo(NotificationStatus.ACKNOWLEDGED);
}

public void accept(String reason) {
public void accept(String reason, NotificationMessage message) {
changeStatusTo(NotificationStatus.ACCEPTED);
this.acceptReason = reason;
message.setMessage(reason);
}

public void decline(String reason, NotificationMessage message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void handleUpdate(EDCNotification edcNotification, NotificationType notif

switch (edcNotification.convertNotificationStatus()) {
case ACKNOWLEDGED -> notification.acknowledge();
case ACCEPTED -> notification.accept(edcNotification.getInformation());
case ACCEPTED -> notification.accept(edcNotification.getInformation(), notificationMessage);
case DECLINED -> notification.decline(edcNotification.getInformation(), notificationMessage);
case CLOSED ->
notification.close(BPN.of(notification.getBpn()), edcNotification.getInformation(), notificationMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ public void editNotification(EditNotification editNotification) {
if (editNotification.getAffectedPartIds() != null) {
notification.setAffectedPartIds(editNotification.getAffectedPartIds());
}
if (editNotification.getSeverity() != null){
notification.setNotificationSeverity(editNotification.getSeverity());
}


getNotificationRepository().updateNotificationAndMessage(notification, editNotification.getSeverity());
getNotificationRepository().updateNotificationAndMessage(notification);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ public Notification updateNotificationPublisher(Notification notification, Notif
relevantNotifications.forEach(qNotification -> {
switch (status) {
case ACKNOWLEDGED -> notification.acknowledge();
case ACCEPTED -> notification.accept(reason);
case DECLINED -> notification.decline(reason);
case ACCEPTED -> notification.accept(reason, qNotification);
case DECLINED -> notification.decline(reason, qNotification);
case CLOSED -> notification.close(reason, qNotification);
default ->
throw new NotificationIllegalUpdate("Transition from status '%s' to status '%s' is not allowed for notification with id '%s'".formatted(notification.getNotificationStatus().name(), status, notification.getNotificationId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationMessage;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationStatus;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationType;
import org.eclipse.tractusx.traceability.notification.domain.notification.exception.NotificationNotFoundException;
import org.eclipse.tractusx.traceability.notification.domain.notification.repository.NotificationRepository;
import org.eclipse.tractusx.traceability.notification.infrastructure.edc.model.EDCNotification;
import org.eclipse.tractusx.traceability.notification.infrastructure.edc.model.EDCNotificationFactory;
Expand Down Expand Up @@ -172,22 +173,30 @@ private CatalogItem getCatalogItem(final NotificationMessage notification, final

// TODO this method should be completly handled by EDCNotificationFactory.createEdcNotification which is part of this method currently
private EdcNotificationRequest toEdcNotificationRequest(
final NotificationMessage notification,
final NotificationMessage notificationMessage,
final String senderEdcUrl,
final EndpointDataReference dataReference
) throws JsonProcessingException {
EDCNotification edcNotification = EDCNotificationFactory.createEdcNotification(senderEdcUrl, notification);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String body = objectMapper.writeValueAsString(edcNotification);

HttpHeaders headers = new HttpHeaders();
headers.set(Objects.requireNonNull(dataReference.getAuthKey()), dataReference.getAuthCode());
headers.set("Content-Type", "application/json");
log.info(":::: Send notification Data body :{}, dataReferenceEndpoint :{}", body, dataReference.getEndpoint());
return EdcNotificationRequest.builder()
.url(dataReference.getEndpoint())
.body(body)
.headers(headers).build();

Optional<Notification> optionalNotificationById = notificationRepository.findByEdcNotificationId(notificationMessage.getEdcNotificationId());

if (optionalNotificationById.isPresent()) {
EDCNotification edcNotification = EDCNotificationFactory.createEdcNotification(senderEdcUrl, notificationMessage, optionalNotificationById.get());
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String body = objectMapper.writeValueAsString(edcNotification);

HttpHeaders headers = new HttpHeaders();
headers.set(Objects.requireNonNull(dataReference.getAuthKey()), dataReference.getAuthCode());
headers.set("Content-Type", "application/json");
log.info(":::: Send notificationMessage Data body :{}, dataReferenceEndpoint :{}", body, dataReference.getEndpoint());
return EdcNotificationRequest.builder()
.url(dataReference.getEndpoint())
.body(body)
.headers(headers).build();
} else {
throw new NotificationNotFoundException("Could not find notification.");
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.eclipse.tractusx.traceability.common.model.SearchCriteria;
import org.eclipse.tractusx.traceability.notification.domain.base.model.Notification;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationId;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationSeverity;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationSide;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationType;
import org.springframework.data.domain.Pageable;
Expand All @@ -46,7 +45,7 @@ public interface NotificationRepository {

void updateNotification(Notification investigation);

void updateNotificationAndMessage(Notification notification, NotificationSeverity notificationSeverity);
void updateNotificationAndMessage(Notification notification);

PageResult<Notification> getNotifications(Pageable pageable, SearchCriteria searchCriteria);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
********************************************************************************/
package org.eclipse.tractusx.traceability.notification.infrastructure.edc.model;

import org.eclipse.tractusx.traceability.notification.domain.base.model.Notification;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationAffectedPart;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationMessage;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationSeverity;

import java.util.List;

Expand All @@ -33,28 +33,24 @@ public class EDCNotificationFactory {
private EDCNotificationFactory() {
}

public static EDCNotification createEdcNotification(String senderEDC, NotificationMessage notification) {
String targetDate = null;
if (notification.getTargetDate() != null) {
targetDate = notification.getTargetDate().toString();
}
public static EDCNotification createEdcNotification(String senderEDC, NotificationMessage notificationMessage, Notification notification) {

EDCNotificationHeader header = new EDCNotificationHeader(
notification.getEdcNotificationId(),
notification.getSentBy(),
notificationMessage.getEdcNotificationId(),
notificationMessage.getSentBy(),
senderEDC,
notification.getSentTo(),
NotificationType.from(notification.getType()).getValue(),
notification.getSeverity() != null ? notification.getSeverity().getRealName() : NotificationSeverity.MINOR.getRealName(),
notification.getNotificationReferenceId(),
notification.getNotificationStatus().name(),
targetDate,
notification.getMessageId()
notificationMessage.getSentTo(),
NotificationType.from(notificationMessage.getType()).getValue(),
notification.getNotificationSeverity().getRealName(),
notificationMessage.getNotificationReferenceId(),
notificationMessage.getNotificationStatus().name(),
notification.getTargetDate(),
notificationMessage.getMessageId()
);

EDCNotificationContent content = new EDCNotificationContent(
notification.getMessage(),
extractAssetIds(notification)
notificationMessage.getMessage(),
extractAssetIds(notificationMessage)
);

return new EDCNotification(header, content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public class NotificationBaseEntity {
private Long id;
private String title;
private String bpn;
private String closeReason;
private String acceptReason;
private String declineReason;
private String description;
@Column(name = "created")
private Instant createdDate;
Expand All @@ -55,5 +52,6 @@ public class NotificationBaseEntity {
private NotificationStatusBaseEntity status;
@Enumerated(EnumType.STRING)
private NotificationSeverityBaseEntity severity;
private Instant targetDate;

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationStatus;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationType;

import java.time.Instant;
import java.util.List;

import static org.apache.commons.collections4.ListUtils.emptyIfNull;
Expand Down Expand Up @@ -95,10 +96,12 @@ public static NotificationEntity from(Notification notification, List<AssetAsBui
.title(notification.getTitle())
.assets(assetEntities)
.bpn(notification.getBpn())
.targetDate(Instant.parse(notification.getTargetDate()))
.description(notification.getDescription())
.status(NotificationStatusBaseEntity.fromStringValue(notification.getNotificationStatus().name()))
.side(NotificationSideBaseEntity.valueOf(notification.getNotificationSide().name()))
.createdDate(notification.getCreatedAt())
.severity(NotificationSeverityBaseEntity.fromString(notification.getNotificationSeverity().getRealName()))
.type(NotificationTypeEntity.from(notification.getNotificationType()))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationAffectedPart;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationId;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationMessage;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationSeverity;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationSide;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationStatus;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationType;
import org.eclipse.tractusx.traceability.notification.domain.notification.repository.NotificationRepository;
import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationEntity;
import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationMessageEntity;
import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationSeverityBaseEntity;
import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationSideBaseEntity;
import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationStatusBaseEntity;
import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationTypeEntity;
Expand Down Expand Up @@ -114,15 +114,12 @@ public void updateNotification(Notification notification) {
.orElseThrow(() -> new IllegalArgumentException(String.format("Investigation with id %s not found!", notification.getNotificationId().value())));
notificationEntity.setStatus(NotificationStatusBaseEntity.fromStringValue(notification.getNotificationStatus().name()));
notificationEntity.setUpdated(clock.instant());
notificationEntity.setCloseReason(notification.getCloseReason());
notificationEntity.setAcceptReason(notification.getAcceptReason());
notificationEntity.setDeclineReason(notification.getDeclineReason());
handleMessageUpdate(notificationEntity, notification);
jpaNotificationRepository.save(notificationEntity);
}

@Override
public void updateNotificationAndMessage(Notification notification, NotificationSeverity notificationSeverity) {
public void updateNotificationAndMessage(Notification notification) {
NotificationEntity notificationEntity = jpaNotificationRepository.findById(notification.getNotificationId().value())
.orElseThrow(() -> new IllegalArgumentException(String.format("Investigation with id %s not found!", notification.getNotificationId().value())));
notificationEntity.setTitle(notification.getTitle());
Expand All @@ -131,10 +128,8 @@ public void updateNotificationAndMessage(Notification notification, Notification
notificationEntity.setAssets(getAssetEntitiesByAssetIds(notification.getAffectedPartIds()));
notificationEntity.setStatus(NotificationStatusBaseEntity.fromStringValue(notification.getNotificationStatus().name()));
notificationEntity.setUpdated(clock.instant());
notificationEntity.setCloseReason(notification.getCloseReason());
notificationEntity.setAcceptReason(notification.getAcceptReason());
notificationEntity.setDeclineReason(notification.getDeclineReason());
handleMessageUpdate(notificationEntity, notification, notificationSeverity);
notificationEntity.setSeverity(NotificationSeverityBaseEntity.fromString(notification.getNotificationSeverity().getRealName()));
handleMessageUpdate(notificationEntity, notification);
jpaNotificationRepository.save(notificationEntity);
}

Expand Down
Loading

0 comments on commit 65dd051

Please sign in to comment.