diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ceaf22984..73d138f6c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ 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] +### Changed + +- #1122 fix editing notification sendTo attribute + ## [13.0.1 - 26.07.2024] ### Added diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/application/notification/rest/NotificationController.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/application/notification/rest/NotificationController.java index 27c4f8ca1c..f32e69add5 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/application/notification/rest/NotificationController.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/application/notification/rest/NotificationController.java @@ -460,10 +460,10 @@ public void closeNotificationById( notificationService.updateStatusTransition(notificationId, NotificationStatus.from(NotificationStatusRequest.CLOSED), cleanCloseNotificationRequest.getReason()); } - @Operation(operationId = "updateNotification", - summary = "Update notification by id", + @Operation(operationId = "updateNotificationStatus", + summary = "Update notification status by id", tags = {"Notifications"}, - description = "The endpoint updates notification by their id.", + description = "The endpoint updates the notification status by their id.", security = @SecurityRequirement(name = "oAuth2", scopes = "profile email")) @ApiResponses(value = { @ApiResponse( diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/AbstractNotificationService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/AbstractNotificationService.java index acdb1960b6..7b15526965 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/AbstractNotificationService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/AbstractNotificationService.java @@ -21,9 +21,6 @@ import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.traceability.assets.domain.asbuilt.repository.AssetAsBuiltRepository; -import org.eclipse.tractusx.traceability.bpn.infrastructure.repository.BpnRepository; -import org.eclipse.tractusx.traceability.common.model.BPN; import org.eclipse.tractusx.traceability.common.model.PageResult; import org.eclipse.tractusx.traceability.common.model.SearchCriteria; import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties; @@ -54,8 +51,6 @@ public abstract class AbstractNotificationService implements NotificationService private final TraceabilityProperties traceabilityProperties; private final NotificationPublisherService notificationPublisherService; - private final AssetAsBuiltRepository assetAsBuiltRepository; - private final BpnRepository bpnRepository; private static final List SUPPORTED_ENUM_FIELDS = List.of("status", "side", "severity", "type"); @@ -115,7 +110,6 @@ public void editNotification(EditNotification editNotification) { Notification notification = loadOrNotFoundException(new NotificationId(editNotification.getId())); if (editNotification.getReceiverBpn() != null) { - notification.setBpn(BPN.of(editNotification.getReceiverBpn())); notification.setInitialReceiverBpns(List.of(editNotification.getReceiverBpn())); notification.setSendTo(editNotification.getReceiverBpn()); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/notification/service/NotificationServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/notification/service/NotificationServiceImpl.java index ec179c7948..b185aeda0c 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/notification/service/NotificationServiceImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/notification/service/NotificationServiceImpl.java @@ -19,8 +19,6 @@ package org.eclipse.tractusx.traceability.notification.domain.notification.service; -import org.eclipse.tractusx.traceability.assets.domain.asbuilt.repository.AssetAsBuiltRepository; -import org.eclipse.tractusx.traceability.bpn.infrastructure.repository.BpnRepository; import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties; import org.eclipse.tractusx.traceability.notification.domain.base.service.AbstractNotificationService; import org.eclipse.tractusx.traceability.notification.domain.base.service.NotificationPublisherService; @@ -34,9 +32,8 @@ public class NotificationServiceImpl extends AbstractNotificationService { public NotificationServiceImpl(TraceabilityProperties traceabilityProperties, NotificationRepository alertRepository, - NotificationPublisherService notificationPublisherService, - AssetAsBuiltRepository assetAsBuiltRepository, BpnRepository bpnRepository) { - super(traceabilityProperties, notificationPublisherService, assetAsBuiltRepository, bpnRepository); + NotificationPublisherService notificationPublisherService) { + super(traceabilityProperties, notificationPublisherService); this.notificationRepository = alertRepository; } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java index e294dc9761..c28247eb45 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java @@ -123,7 +123,7 @@ public void updateNotificationAndMessage(Notification notification) { .orElseThrow(() -> new IllegalArgumentException(String.format("Investigation with id %s not found!", notification.getNotificationId().value()))); notificationEntity.setTitle(notification.getTitle()); notificationEntity.setDescription(notification.getDescription()); - notificationEntity.setBpn(notification.getBpn()); + notificationEntity.setInitialReceiverBpn(notification.getSendTo()); notificationEntity.setAssets(getAssetEntitiesByAssetIds(notification.getAffectedPartIds())); notificationEntity.setStatus(NotificationStatusBaseEntity.fromStringValue(notification.getNotificationStatus().name())); notificationEntity.setUpdated(clock.instant()); diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/NotificationApiSupport.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/NotificationApiSupport.java index 2e9ec8f099..754ed04fa2 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/NotificationApiSupport.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/NotificationApiSupport.java @@ -83,6 +83,7 @@ public PageResult getNotificationsRequest(Header authHeade .when() .post("/api/notifications/filter") .then() + .log().all() .statusCode(200) .extract().response(); diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/EditNotificationIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/EditNotificationIT.java index 34de7a02fd..da20a23e70 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/EditNotificationIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/notification/EditNotificationIT.java @@ -22,7 +22,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.testcontainers.shaded.com.fasterxml.jackson.core.JsonProcessingException; import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; import java.util.Collections; @@ -145,7 +144,7 @@ void shouldThrowBadRequestWhenUpdateInvestigation_SenderAndReceiverBpnIsSame() t } @Test - void shouldUpdateInvestigationFields() throws JsonProcessingException, JoseException, com.fasterxml.jackson.core.JsonProcessingException { + void shouldUpdateInvestigationFields() throws JoseException, com.fasterxml.jackson.core.JsonProcessingException { Header authHeader = oAuth2Support.jwtAuthorization(SUPERVISOR); // given List partIds = List.of( @@ -255,6 +254,61 @@ void shouldNotUpdateInvestigationFields_whenBpnWrongFormatted() throws JoseExcep NotificationResponse notificationResponse = notificationResponsePageResult.content().get(0); assertThat(notificationResponse.getSendTo()).isEqualTo("BPNL00000003CNKC"); + } + + @Test + void shouldUpdateReceiverBpn() throws JoseException, com.fasterxml.jackson.core.JsonProcessingException { + Header authHeader = oAuth2Support.jwtAuthorization(SUPERVISOR); + + // given + List partIds = List.of( + "urn:uuid:fe99da3d-b0de-4e80-81da-882aebcca978", // BPN: BPNL00000003AYRE + "urn:uuid:d387fa8e-603c-42bd-98c3-4d87fef8d2bb", // BPN: BPNL00000003AYRE + "urn:uuid:0ce83951-bc18-4e8f-892d-48bad4eb67ef" // BPN: BPNL00000003AXS3 + ); + String description = "at least 15 characters long investigation description"; + String title = "the initial title"; + val startNotificationRequest = StartNotificationRequest.builder() + .affectedPartIds(partIds) + .description(description) + .title(title) + .type(NotificationTypeRequest.ALERT) + .severity(NotificationSeverityRequest.MINOR) + .receiverBpn("BPNL00000003AYRE") + .build(); + + int id = notificationAPISupport.createNotificationRequest_withDefaultAssetsStored(authHeader, startNotificationRequest, 201); + + String editedDescription = "at least 15 characters long investigation description which was edited"; + + String editedTitle = "changed title"; + val editNotificationRequest = EditNotificationRequest.builder() + .receiverBpn("BPNL00000003AABC") + .affectedPartIds(partIds) + .description(editedDescription) + .title(editedTitle) + .affectedPartIds(startNotificationRequest.getAffectedPartIds()) + .severity(NotificationSeverityRequest.CRITICAL) + .build(); + + // when + notificationAPISupport.editNotificationRequest(authHeader, editNotificationRequest, id, 204); + + // then + notificationMessageSupport.assertMessageSize(0); + + PageableFilterRequest pageableFilterRequest = + new PageableFilterRequest( + new OwnPageable(0, 10, Collections.emptyList()), + new SearchCriteriaRequestParam(List.of("channel,EQUAL,SENDER,AND"))); + + PageResult notificationResponsePageResult + = notificationAPISupport.getNotificationsRequest(authHeader, pageableFilterRequest); + + NotificationResponse notificationResponse = notificationResponsePageResult.content().get(0); + assertThat(notificationResponse.getId()).isEqualTo(id); + assertThat(notificationResponse.getSendTo()).isEqualTo(editNotificationRequest.getReceiverBpn()); + assertThat(notificationResponse.getCreatedBy()).isEqualTo("BPNL00000003AXS3"); } }