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

bug 1122 fix editing notification sendTo attribute #1327

Merged
merged 1 commit into from
Jul 30, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ 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
Expand Down
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());
ds-lcapellino marked this conversation as resolved.
Show resolved Hide resolved
}

@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 @@ -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;
Expand All @@ -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;

}
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");

}
}
Loading