Skip to content

Commit

Permalink
Merged main branch on 2024-03-19
Browse files Browse the repository at this point in the history
  • Loading branch information
Update branch committed Mar 19, 2024
2 parents 820e09c + a7b17a4 commit e77bc11
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.tractusx.traceability.common.request.exception.InvalidSortException;
import org.eclipse.tractusx.traceability.common.security.TechnicalUserAuthorizationException;
import org.eclipse.tractusx.traceability.contracts.domain.exception.ContractException;
import org.eclipse.tractusx.traceability.discovery.infrastructure.exception.DiscoveryFinderException;
import org.eclipse.tractusx.traceability.qualitynotification.application.contract.model.CreateNotificationContractException;
import org.eclipse.tractusx.traceability.qualitynotification.application.validation.UpdateQualityNotificationValidationException;
import org.eclipse.tractusx.traceability.qualitynotification.domain.alert.model.exception.AlertIllegalUpdate;
Expand Down Expand Up @@ -116,6 +117,13 @@ ResponseEntity<ErrorResponse> handleAssetNotFoundException(AssetNotFoundExceptio
.body(new ErrorResponse(exception.getMessage()));
}

@ExceptionHandler(DiscoveryFinderException.class)
ResponseEntity<ErrorResponse> handleDiscoveryFinderException(DiscoveryFinderException exception) {
log.warn("handleDiscoveryFinderException", exception);
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE)
.body(new ErrorResponse(exception.getMessage()));
}

@ExceptionHandler(PublishAssetException.class)
ResponseEntity<ErrorResponse> handlePublishAssetException(PublishAssetException exception) {
log.warn("handlePublishAssetException", exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.traceability.bpn.domain.service.BpnRepository;
import org.eclipse.tractusx.traceability.common.properties.EdcProperties;
import org.eclipse.tractusx.traceability.discovery.domain.model.Discovery;
import org.eclipse.tractusx.traceability.discovery.domain.repository.DiscoveryRepository;
import org.eclipse.tractusx.traceability.common.properties.EdcProperties;
import org.eclipse.tractusx.traceability.discovery.infrastructure.exception.DiscoveryFinderException;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

Expand All @@ -50,17 +51,22 @@ public class DiscoveryServiceImpl implements DiscoveryService {
@Override
public Discovery getDiscoveryByBPN(String bpn) {
List<Discovery> discoveryList = new ArrayList<>();
Optional<Discovery> optionalDiscoveryFromDiscoveryService = getOptionalDiscoveryByBpnFromDiscoveryService(bpn);
optionalDiscoveryFromDiscoveryService.ifPresent(discovery -> {
discovery.setReceiverUrls(
discovery.getReceiverUrls().stream().map(
DiscoveryServiceImpl::removeTrailingSlash
).toList()
);
log.info("Retrieved discovery by bpn from edcDiscoveryService receiverUrls: {}, senderUrls: {}", discovery.getReceiverUrls().toString(), discovery.getSenderUrl());
discoveryList.add(discovery);
});
optionalDiscoveryFromDiscoveryService.ifPresent(discoveryList::add);
try {
Optional<Discovery> optionalDiscoveryFromDiscoveryService = getOptionalDiscoveryByBpnFromDiscoveryService(bpn);
optionalDiscoveryFromDiscoveryService.ifPresent(discovery -> {
discovery.setReceiverUrls(
discovery.getReceiverUrls().stream().map(
DiscoveryServiceImpl::removeTrailingSlash
).toList()
);
log.info("Retrieved discovery by bpn from edcDiscoveryService receiverUrls: {}, senderUrls: {}", discovery.getReceiverUrls().toString(), discovery.getSenderUrl());
discoveryList.add(discovery);
});
optionalDiscoveryFromDiscoveryService.ifPresent(discoveryList::add);
} catch (Exception e) {
throw new DiscoveryFinderException("DiscoverFinder not reachable.");
}

Optional<Discovery> optionalDiscoveryFromBpnDatabase = getOptionalDiscoveryFromBpnDatabase(bpn);
optionalDiscoveryFromBpnDatabase.ifPresent(discovery -> log.info("Retrieved discovery by bpn from BPN Mapping Table receiverUrls: {}, senderUrls: {}", discovery.getReceiverUrls().toString(), discovery.getSenderUrl()));
optionalDiscoveryFromBpnDatabase.ifPresent(discoveryList::add);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/********************************************************************************
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.traceability.discovery.infrastructure.exception;

public class DiscoveryFinderException extends RuntimeException {
public DiscoveryFinderException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.tractusx.traceability.common.config.AssetsAsyncConfig;
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.InvestigationRepository;
import org.eclipse.tractusx.traceability.qualitynotification.domain.base.exception.ContractNegotiationException;
import org.eclipse.tractusx.traceability.qualitynotification.domain.base.exception.NoCatalogItemException;
Expand All @@ -49,7 +50,7 @@
@Slf4j
@RequiredArgsConstructor
@Service
@Transactional
@Transactional(dontRollbackOn = DiscoveryFinderException.class)
@Profile(NOT_INTEGRATION_TESTS)
public class EdcNotificationServiceImpl implements EdcNotificationService {

Expand Down

0 comments on commit e77bc11

Please sign in to comment.