Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(chore):962 fixed sentToBpn. #1101

Merged
merged 5 commits into from
Jun 24, 2024
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 @@ -65,6 +65,7 @@ public Notification toNotification(BPN bpn, EDCNotification edcNotification, Not
.description(edcNotification.getInformation())
.createdAt(Instant.now())
.sendTo(applicationBPN.value())
.updatedDate(Instant.now())
.severity(NotificationSeverity.fromString(edcNotification.getSeverity()))
.targetDate(convertInstantToString(edcNotification.getTargetDate()))
.affectedPartIds(assetIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

import java.time.OffsetDateTime;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand All @@ -54,7 +53,7 @@ public static NotificationResponse from(Notification notification) {
.channel(NotificationMessageMapper.from(notification.getNotificationSide()))
.type(NotificationMessageMapper.from(notification.getNotificationType()))
.title(notification.getTitle())
.updatedDate(OffsetDateTime.now().toString())
.updatedDate(notification.getUpdatedDate() != null ? notification.getUpdatedDate().toString() : null)
.sendTo(notification.getSendTo())
.sendToName(getReceiverName(notification.getNotifications()))
.severity(notification.getSeverity() != null ?
Expand All @@ -75,7 +74,7 @@ public static PageResult<NotificationResponse> fromAsPageResult(PageResult<Notif
}

private static String getSenderBPN(Notification notification) {
return notification.getNotificationSide().equals(NotificationSide.SENDER) ? notification.getBpn() : notification.getSendTo();
return notification.getNotificationSide().equals(NotificationSide.SENDER) ? notification.getBpn() : notification.getSendTo();
}

private static String getSenderName(Collection<NotificationMessage> notifications) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,17 @@
import lombok.Data;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase;
import org.eclipse.tractusx.traceability.bpn.domain.model.BpnEdcMapping;
import org.eclipse.tractusx.traceability.common.model.BPN;
import org.eclipse.tractusx.traceability.notification.domain.notification.exception.InvestigationIllegalUpdate;
import org.eclipse.tractusx.traceability.notification.domain.notification.exception.InvestigationStatusTransitionNotAllowed;
import org.eclipse.tractusx.traceability.notification.domain.notification.model.EditNotification;

import java.time.Instant;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static java.util.stream.Collectors.groupingBy;
import static org.apache.commons.collections4.ListUtils.emptyIfNull;
import static org.eclipse.tractusx.traceability.common.date.DateUtil.convertInstantToString;

Expand Down Expand Up @@ -72,7 +66,6 @@ public class Notification {
public static Notification startNotification(String title, Instant createDate, BPN bpn, String description, NotificationType notificationType, NotificationSeverity severity, Instant targetDate, List<String> affectedPartIds, List<String> initialReceiverBpns, String receiverBpn) {



return Notification.builder()
.title(title)
.bpn(bpn)
Expand All @@ -87,6 +80,7 @@ public static Notification startNotification(String title, Instant createDate, B
.createdAt(createDate)
.affectedPartIds(affectedPartIds)
.initialReceiverBpns(initialReceiverBpns)
.updatedDate(Instant.now())
.build();
}

Expand Down Expand Up @@ -161,7 +155,7 @@ private void changeStatusTo(NotificationStatus to) {
this.notificationStatus = to;
}

public synchronized void addNotificationMessage(NotificationMessage notification) {
public synchronized void addNotificationMessage(NotificationMessage notification) {

List<NotificationMessage> updatedNotifications = new ArrayList<>(notifications);
updatedNotifications.add(notification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,10 @@ public void editNotification(EditNotification editNotification) {
validateReceiverIsNotOwnBpn(editNotification.getReceiverBpn(), editNotification.getId());
Notification notification = loadOrNotFoundException(new NotificationId(editNotification.getId()));

List<String> oldMessageIds =
notification.getNotifications().stream().map(NotificationMessage::getId).toList();

getNotificationRepository().deleteByIdIn(oldMessageIds);
notification.clearNotifications();

if (editNotification.getReceiverBpn() != null) {
notification.setBpn(BPN.of(editNotification.getReceiverBpn()));
notification.setInitialReceiverBpns(List.of(editNotification.getReceiverBpn()));
notification.setSendTo(editNotification.getReceiverBpn());
}

notification.setTitle(editNotification.getTitle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static Notification toDomain(NotificationEntity notificationEntity) {
.map(AssetAsBuiltEntity::getId)
.toList();
String initialReceiverBpn = notificationEntity.getInitialReceiverBpn();
if (initialReceiverBpn == null){
if (initialReceiverBpn == null) {
initialReceiverBpn = notificationEntity.getBpn();
}
return Notification.builder()
Expand All @@ -98,6 +98,7 @@ public static Notification toDomain(NotificationEntity notificationEntity) {
.targetDate(convertInstantToString(notificationEntity.getTargetDate()))
.severity(NotificationSeverity.fromString(notificationEntity.getSeverity() != null ? notificationEntity.getSeverity().getRealName() : null))
.notifications(messages)
.updatedDate(notificationEntity.getUpdated() != null ? notificationEntity.getUpdated() : Instant.now())
.initialReceiverBpns(List.of(initialReceiverBpn))
.build();
}
Expand All @@ -115,6 +116,7 @@ public static NotificationEntity from(Notification notification, List<AssetAsBui
.severity(NotificationSeverityBaseEntity.fromString(notification.getSeverity() != null ? notification.getSeverity().getRealName() : null))
.type(NotificationTypeEntity.from(notification.getNotificationType()))
.initialReceiverBpn(notification.getInitialReceiverBpns().stream().findFirst().orElseThrow(() -> new NotificationNotFoundException("Initial Receiver BPN not found")))
.updated(Instant.now())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import static io.restassured.RestAssured.given;
import static org.eclipse.tractusx.traceability.common.security.JwtRole.ADMIN;
import static org.eclipse.tractusx.traceability.common.security.JwtRole.USER;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasItem;

class BpnMappingControllerIT extends IntegrationTestSpecification {

Expand Down Expand Up @@ -92,9 +95,11 @@ void givenBpnMappingRequest_whenUpdate_thenUpdateIt() throws JoseException {
.get("/api/bpn-config")
.then()
.statusCode(200)
.log().all()
.body("", Matchers.hasSize(2))
.body("[1].bpn", Matchers.equalTo("BPNL00000003TEST"))
.body("[1].url", Matchers.equalTo("https://newurl.com"));
.body("", hasItem(allOf(
hasEntry("bpn", "BPNL00000003TEST"),
hasEntry("url", "https://newurl.com"))));
}
}

Expand Down
Loading