Skip to content

Commit

Permalink
Merge branch 'main' into feature/#630-extended-part-detail-view
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-mmaul committed Mar 20, 2024
2 parents 73e47bf + 8785fc0 commit a6f7380
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 43 deletions.
11 changes: 11 additions & 0 deletions frontend/cypress/integration/pages/AdminPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ export class AdminPage {
return cy.get('td').contains(contractId).parent('tr').find('td mat-checkbox').click();
}

static clickCheckBoxForFirstContractInTable() {
return cy.get('td').first().parent('tr').find('td mat-checkbox').click();
}

static getContractIdOfFirstContractInTable() {
return cy.get('[data-testid="table-component--cell-data"]').first().then(contractId => {
return contractId.text();
});
}


static clickExportContractsButton() {
return cy.get('[data-testid="export-contracts-button"]').click();
}
Expand Down
13 changes: 12 additions & 1 deletion frontend/cypress/support/step_definitions/admin-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ When('select contract with contract-id {string}', function(contractId: string) {
AdminPage.clickCheckBoxForContractId(contractId).should('have.class', 'mat-mdc-checkbox-checked');
});

When('select the first contract in the contracts table', function() {
AdminPage.getContractIdOfFirstContractInTable().then(contractId => {
currentContractId = contractId;
expect(currentContractId).not.to.be.null
});
cy.wait(1000);

AdminPage.clickCheckBoxForFirstContractInTable().should('have.class', 'mat-mdc-checkbox-checked');
})

When('export selected contracts', function() {
AdminPage.clickExportContractsButton().should('be.visible');
});
Expand All @@ -40,7 +50,8 @@ Then('exported contracts csv file is existing', function() {

Then('exported csv file has correct content', function() {
AdminPage.getExportedContractsFileData().then((data) => {
expect(data).to.equal(`contractId,counterpartyAddress,creationDate,endDate,state\n${ currentContractId },https://trace-x-edc-e2e-a.dev.demo.catena-x.net/api/v1/dsp,Thu Mar 07 2024,Thu Jan 01 1970,FINALIZED`);
let expectedData = "contractId,counterpartyAddress,creationDate,endDate,state\n" + currentContractId.trim().replace(/\n/g,'') + ",https://trace-x-edc-e2e-a.dev.demo.catena-x.net/api/v1/dsp,Mon Mar 18 2024,Thu Jan 01 1970,FINALIZED";
expect(data).to.equal(expectedData);
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Discovery getDiscoveryByBPN(String bpn) {
});
optionalDiscoveryFromDiscoveryService.ifPresent(discoveryList::add);
} catch (Exception e) {
throw new DiscoveryFinderException("DiscoverFinder not reachable.");
throw new DiscoveryFinderException("DiscoveryFinder could not determine result.");
}

Optional<Discovery> optionalDiscoveryFromBpnDatabase = getOptionalDiscoveryFromBpnDatabase(bpn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.tractusx.traceability.discovery.domain.model.Discovery;
import org.eclipse.tractusx.traceability.discovery.domain.service.DiscoveryService;
import org.eclipse.tractusx.traceability.discovery.infrastructure.exception.DiscoveryFinderException;
import org.eclipse.tractusx.traceability.qualitynotification.domain.base.AlertRepository;
import org.eclipse.tractusx.traceability.qualitynotification.domain.base.InvestigationRepository;
import org.eclipse.tractusx.traceability.qualitynotification.domain.base.exception.ContractNegotiationException;
import org.eclipse.tractusx.traceability.qualitynotification.domain.base.exception.NoCatalogItemException;
Expand Down Expand Up @@ -57,35 +58,43 @@ public class EdcNotificationServiceImpl implements EdcNotificationService {
private final InvestigationsEDCFacade edcFacade;
private final DiscoveryService discoveryService;
private final InvestigationRepository investigationRepository;
private final AlertRepository alertRepository;

@Override
@Async(value = AssetsAsyncConfig.UPDATE_NOTIFICATION_EXECUTOR)
public CompletableFuture<QualityNotificationMessage> asyncNotificationMessageExecutor(QualityNotificationMessage message) {
log.info("::asyncNotificationExecutor::message {}", message);
Discovery discovery = discoveryService.getDiscoveryByBPN(message.getSendTo());
String senderEdcUrl = discovery.getSenderUrl();
List<String> receiverUrls = emptyIfNull(discovery.getReceiverUrls());
List<Boolean> sendResults = List.of();

if (message.getType().equals(QualityNotificationType.ALERT)) {
log.info("::asyncNotificationExecutor::isQualityAlert");
sendResults = receiverUrls
.stream().map(receiverUrl -> handleSendingNotification(message, senderEdcUrl, receiverUrl)).toList();
}
try {
Discovery discovery = discoveryService.getDiscoveryByBPN(message.getSendTo());

if (message.getType().equals(QualityNotificationType.INVESTIGATION)) {
log.info("::asyncNotificationExecutor::isQualityInvestigation");
sendResults = receiverUrls
.stream().map(receiverUrl -> handleSendingNotification(message, senderEdcUrl, receiverUrl)).toList();
}
String senderEdcUrl = discovery.getSenderUrl();
List<String> receiverUrls = emptyIfNull(discovery.getReceiverUrls());
List<Boolean> sendResults = List.of();

Boolean wasSent = sendResults.stream().anyMatch(Boolean.TRUE::equals);
if (message.getType().equals(QualityNotificationType.ALERT)) {
log.info("::asyncNotificationExecutor::isQualityAlert");
sendResults = receiverUrls
.stream().map(receiverUrl -> handleSendingNotification(message, senderEdcUrl, receiverUrl)).toList();
}

if (Boolean.TRUE.equals(wasSent)) {
return CompletableFuture.completedFuture(message);
}
if (message.getType().equals(QualityNotificationType.INVESTIGATION)) {
log.info("::asyncNotificationExecutor::isQualityInvestigation");
sendResults = receiverUrls
.stream().map(receiverUrl -> handleSendingNotification(message, senderEdcUrl, receiverUrl)).toList();
}

Boolean wasSent = sendResults.stream().anyMatch(Boolean.TRUE::equals);

if (Boolean.TRUE.equals(wasSent)) {
return CompletableFuture.completedFuture(message);
}

return CompletableFuture.completedFuture(null);
return CompletableFuture.completedFuture(null);

} catch (DiscoveryFinderException discoveryFinderException) {
enrichQualityNotificationByError(discoveryFinderException, message);
return CompletableFuture.completedFuture(null);
}
}

private boolean handleSendingNotification(QualityNotificationMessage message, String senderEdcUrl, String receiverUrl) {
Expand All @@ -110,19 +119,27 @@ private boolean handleSendingNotification(QualityNotificationMessage message, St

private void enrichQualityNotificationByError(Exception e, QualityNotificationMessage message) {
log.info("Retrieving quality notification by message id {}", message.getEdcNotificationId());
Optional<QualityNotification> optionalQualityNotificationById;
if (message.getType().equals(QualityNotificationType.INVESTIGATION)) {
optionalQualityNotificationById = investigationRepository.findByEdcNotificationId(message.getEdcNotificationId());
} else {
optionalQualityNotificationById = alertRepository.findByEdcNotificationId(message.getEdcNotificationId());
}

Optional<QualityNotification> optionalQualityNotificationById = investigationRepository.findByNotificationMessageId(message.getEdcNotificationId());
log.info("Successfully executed retrieving quality notification by message id");
if (optionalQualityNotificationById.isPresent()) {
log.info("Quality Notification for error message enrichment {}", optionalQualityNotificationById.get());
optionalQualityNotificationById.get().getNotifications().forEach(message1 -> {
log.info("Message found {}", message1);
});
optionalQualityNotificationById.get().getNotifications().forEach(message1 -> log.info("Message found {}", message1));
optionalQualityNotificationById.get().secondLatestNotifications().forEach(qmMessage -> {
log.info("Message from second latest notification {}", qmMessage);
qmMessage.setErrorMessage(e.getMessage());
});
investigationRepository.updateErrorMessage(optionalQualityNotificationById.get());

if (message.getType().equals(QualityNotificationType.INVESTIGATION)) {
investigationRepository.updateErrorMessage(optionalQualityNotificationById.get());
} else {
alertRepository.updateErrorMessage(optionalQualityNotificationById.get());
}
} else {
log.warn("Quality Notification NOT FOUND for error message enrichment notification id {}", message.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public static AlertNotificationEntity from(AlertEntity alertEntity,
.assets(notificationAssets)
.notificationReferenceId(qualityNotificationMessage.getNotificationReferenceId())
.targetDate(qualityNotificationMessage.getTargetDate())
.errorMessage(qualityNotificationMessage.getErrorMessage())
.severity(qualityNotificationMessage.getSeverity())
.edcNotificationId(qualityNotificationMessage.getEdcNotificationId())
.status(NotificationStatusBaseEntity.fromStringValue(qualityNotificationMessage.getNotificationStatus().name()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ void givenNoCatalogItemException_whenHandleSendingInvestigation_thenHandleIt() {
.severity(QualityNotificationSeverity.MINOR)
.build();
doThrow(new NoCatalogItemException()).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl);
QualityNotification qualityNotification = QualityNotification.builder().build();
when(investigationRepository.findByNotificationMessageId(any())).thenReturn(Optional.of(qualityNotification));
// when
notificationsService.asyncNotificationMessageExecutor(notification);

Expand All @@ -158,8 +156,6 @@ void givenSendNotificationException_whenHandleSendingInvestigation_thenHandleIt(
.severity(QualityNotificationSeverity.MINOR)
.build();
doThrow(new SendNotificationException("message", new RuntimeException())).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl);
QualityNotification qualityNotification = QualityNotification.builder().build();
when(investigationRepository.findByNotificationMessageId(any())).thenReturn(Optional.of(qualityNotification));
// when
notificationsService.asyncNotificationMessageExecutor(notification);

Expand All @@ -183,8 +179,7 @@ void givenSendNoEndpointDataReferenceException_whenHandleSendingInvestigation_th
.severity(QualityNotificationSeverity.MINOR)
.build();
doThrow(new NoEndpointDataReferenceException("message")).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl);
QualityNotification qualityNotification = QualityNotification.builder().build();
when(investigationRepository.findByNotificationMessageId(any())).thenReturn(Optional.of(qualityNotification));

// when
notificationsService.asyncNotificationMessageExecutor(notification);

Expand All @@ -208,8 +203,7 @@ void givenContractNegotiationException_whenHandleSendingInvestigation_thenHandle
.severity(QualityNotificationSeverity.MINOR)
.build();
doThrow(new ContractNegotiationException("message")).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl);
QualityNotification qualityNotification = QualityNotification.builder().build();
when(investigationRepository.findByNotificationMessageId(any())).thenReturn(Optional.of(qualityNotification));

// when
notificationsService.asyncNotificationMessageExecutor(notification);

Expand All @@ -234,8 +228,6 @@ void givenNoCatalogItemException_whenHandleSendingAlert_thenHandleIt() {
.severity(QualityNotificationSeverity.MINOR)
.build();
doThrow(new NoCatalogItemException()).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl);
QualityNotification qualityNotification = QualityNotification.builder().build();
when(investigationRepository.findByNotificationMessageId(any())).thenReturn(Optional.of(qualityNotification));

// when
notificationsService.asyncNotificationMessageExecutor(notification);
Expand All @@ -262,8 +254,6 @@ void givenSendNotificationException_whenHandleSendingAlert_thenHandleIt() {
.build();
doThrow(new SendNotificationException("message", new RuntimeException())).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl);

QualityNotification qualityNotification = QualityNotification.builder().build();
when(investigationRepository.findByNotificationMessageId(any())).thenReturn(Optional.of(qualityNotification));

// when
notificationsService.asyncNotificationMessageExecutor(notification);
Expand All @@ -288,8 +278,7 @@ void givenSendNoEndpointDataReferenceException_whenHandleSendingAlert_thenHandle
.severity(QualityNotificationSeverity.MINOR)
.build();
doThrow(new NoEndpointDataReferenceException("message")).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl);
QualityNotification qualityNotification = QualityNotification.builder().build();
when(investigationRepository.findByNotificationMessageId(any())).thenReturn(Optional.of(qualityNotification));

// when
notificationsService.asyncNotificationMessageExecutor(notification);

Expand All @@ -313,8 +302,7 @@ void givenContractNegotiationException_whenHandleSendingAlert_thenHandleIt() {
.severity(QualityNotificationSeverity.MINOR)
.build();
doThrow(new ContractNegotiationException("message")).when(edcFacade).startEdcTransfer(notification, edcReceiverUrl, edcSenderUrl);
QualityNotification qualityNotification = QualityNotification.builder().build();
when(investigationRepository.findByNotificationMessageId(any())).thenReturn(Optional.of(qualityNotification));

// when
notificationsService.asyncNotificationMessageExecutor(notification);

Expand Down

0 comments on commit a6f7380

Please sign in to comment.