Skip to content

Commit

Permalink
bug 1122 fix editing notification sendTo attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-lcapellino committed Jul 29, 2024
1 parent a9cffce commit 93e622f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> SUPPORTED_ENUM_FIELDS = List.of("status", "side", "severity", "type");

Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public PageResult<NotificationResponse> getNotificationsRequest(Header authHeade
.when()
.post("/api/notifications/filter")
.then()
.log().all()
.statusCode(200)
.extract().response();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> partIds = List.of(
Expand Down Expand Up @@ -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<String> 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<NotificationResponse> 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");

}
}

0 comments on commit 93e622f

Please sign in to comment.