From 4951f7daaa5726b6d4f3be543267e44b5ca3fb44 Mon Sep 17 00:00:00 2001 From: "Krzysztof Massalski (Extern)" Date: Tue, 27 Feb 2024 13:01:22 +0100 Subject: [PATCH 1/5] feat(impl):[#404] add bpn to tombstone --- docs/src/api/irs-api.yaml | 2 ++ .../job/delegate/RelationshipDelegate.java | 2 +- .../aaswrapper/job/delegate/SubmodelDelegate.java | 2 +- .../job/delegate/RelationshipDelegateTest.java | 4 +++- .../job/delegate/SubmodelDelegateTest.java | 4 +++- .../irs/edc/client/ContractNegotiationService.java | 2 +- .../edc/client/exceptions/UsagePolicyException.java | 4 +++- .../eclipse/tractusx/irs/component/Tombstone.java | 12 +++++++----- 8 files changed, 21 insertions(+), 11 deletions(-) diff --git a/docs/src/api/irs-api.yaml b/docs/src/api/irs-api.yaml index 9afa2c32f3..bd6c56e6a7 100644 --- a/docs/src/api/irs-api.yaml +++ b/docs/src/api/irs-api.yaml @@ -2700,6 +2700,8 @@ components: additionalProperties: false description: Tombstone with information about request failure properties: + businessPartnerNumber: + type: string catenaXId: type: string description: CATENA-X global asset id in the format urn:uuid:uuid4. diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/RelationshipDelegate.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/RelationshipDelegate.java index 231b6d5b31..14dd51dbef 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/RelationshipDelegate.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/RelationshipDelegate.java @@ -117,7 +117,7 @@ private void processEndpoint(final Endpoint endpoint, final RelationshipAspect r log.info("Encountered usage policy exception: {}. Creating Tombstone.", e.getMessage()); itemContainerBuilder.tombstone( Tombstone.from(itemId.getGlobalAssetId(), endpoint.getProtocolInformation().getHref(), e, - 0, ProcessStep.USAGE_POLICY_VALIDATION, jsonUtil.asMap(e.getPolicy()))); + 0, ProcessStep.USAGE_POLICY_VALIDATION, e.getBusinessPartnerNumber(), jsonUtil.asMap(e.getPolicy()))); } catch (final EdcClientException e) { log.info("Submodel Endpoint could not be retrieved for Endpoint: {}. Creating Tombstone.", endpoint.getProtocolInformation().getHref()); diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/SubmodelDelegate.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/SubmodelDelegate.java index a75fcb400a..f586c3c03b 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/SubmodelDelegate.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/SubmodelDelegate.java @@ -147,7 +147,7 @@ private List getSubmodels(final SubmodelDescriptor submodelDescriptor, } catch (final UsagePolicyException e) { log.info("Encountered usage policy exception: {}. Creating Tombstone.", e.getMessage()); itemContainerBuilder.tombstone(Tombstone.from(itemId, endpoint.getProtocolInformation().getHref(), e, 0, - ProcessStep.USAGE_POLICY_VALIDATION, jsonUtil.asMap(e.getPolicy()))); + ProcessStep.USAGE_POLICY_VALIDATION, e.getBusinessPartnerNumber(), jsonUtil.asMap(e.getPolicy()))); } catch (final EdcClientException e) { log.info("Submodel Endpoint could not be retrieved for Item: {}. Creating Tombstone.", itemId); itemContainerBuilder.tombstone(Tombstone.from(itemId, endpoint.getProtocolInformation().getHref(), e, 0, diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/RelationshipDelegateTest.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/RelationshipDelegateTest.java index 3b060bd29e..7d446883d4 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/RelationshipDelegateTest.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/RelationshipDelegateTest.java @@ -191,6 +191,7 @@ void shouldCatchJsonParseExceptionAndPutTombstone() throws EdcClientException { @Test void shouldCatchUsagePolicyExceptionAndPutTombstone() throws EdcClientException { // given + final String businessPartnerNumber = "BPNL000000011111"; final ItemContainer.ItemContainerBuilder itemContainerWithShell = ItemContainer.builder() .shell(shell("", shellDescriptor( List.of(submodelDescriptorWithDspEndpoint( @@ -198,7 +199,7 @@ void shouldCatchUsagePolicyExceptionAndPutTombstone() throws EdcClientException "address"))))); // when - when(submodelFacade.getSubmodelPayload(any(), any(), any())).thenThrow(new UsagePolicyException("itemId", null)); + when(submodelFacade.getSubmodelPayload(any(), any(), any())).thenThrow(new UsagePolicyException("itemId", null, businessPartnerNumber)); when(connectorEndpointsService.fetchConnectorEndpoints(any())).thenReturn(List.of("connector.endpoint.nl")); final ItemContainer result = relationshipDelegate.process(itemContainerWithShell, jobParameter(), new AASTransferProcess(), createKey()); @@ -207,6 +208,7 @@ void shouldCatchUsagePolicyExceptionAndPutTombstone() throws EdcClientException assertThat(result).isNotNull(); assertThat(result.getTombstones()).hasSize(1); assertThat(result.getTombstones().get(0).getCatenaXId()).isEqualTo("itemId"); + assertThat(result.getTombstones().get(0).getBusinessPartnerNumber()).isEqualTo(businessPartnerNumber); assertThat(result.getTombstones().get(0).getProcessingError().getProcessStep()).isEqualTo( ProcessStep.USAGE_POLICY_VALIDATION); } diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/SubmodelDelegateTest.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/SubmodelDelegateTest.java index 312113d974..e80ecdf3b1 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/SubmodelDelegateTest.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/aaswrapper/job/delegate/SubmodelDelegateTest.java @@ -139,6 +139,7 @@ void shouldPutTombstoneForMissingBpn() { @Test void shouldCatchUsagePolicyExceptionAndPutTombstone() throws EdcClientException { // given + final String businessPartnerNumber = "BPNL000000011111"; final ItemContainer.ItemContainerBuilder itemContainerShellWithTwoSubmodels = ItemContainer.builder() .shell(shell("", shellDescriptor( List.of(submodelDescriptorWithDspEndpoint( @@ -149,7 +150,7 @@ void shouldCatchUsagePolicyExceptionAndPutTombstone() throws EdcClientException "testSingleLevelBomAsBuiltEndpoint"))))); // when - when(submodelFacade.getSubmodelPayload(any(), any(), any())).thenThrow(new UsagePolicyException("itemId", null)); + when(submodelFacade.getSubmodelPayload(any(), any(), any())).thenThrow(new UsagePolicyException("itemId", null, businessPartnerNumber)); when(connectorEndpointsService.fetchConnectorEndpoints(any())).thenReturn(List.of("connector.endpoint.nl")); final ItemContainer result = submodelDelegate.process(itemContainerShellWithTwoSubmodels, jobParameterCollectAspects(), new AASTransferProcess(), createKey()); @@ -158,6 +159,7 @@ void shouldCatchUsagePolicyExceptionAndPutTombstone() throws EdcClientException assertThat(result).isNotNull(); assertThat(result.getTombstones()).hasSize(2); assertThat(result.getTombstones().get(0).getCatenaXId()).isEqualTo("itemId"); + assertThat(result.getTombstones().get(0).getBusinessPartnerNumber()).isEqualTo(businessPartnerNumber); assertThat(result.getTombstones().get(0).getProcessingError().getProcessStep()).isEqualTo( ProcessStep.USAGE_POLICY_VALIDATION); } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationService.java index 63def1d591..ebe0689cc3 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationService.java @@ -124,7 +124,7 @@ private CompletableFuture startNewNegotiation(final String if (!policyCheckerService.isValid(catalogItem.getPolicy())) { log.info("Policy was not allowed, canceling negotiation."); - throw new UsagePolicyException(catalogItem.getItemId(), catalogItem.getPolicy()); + throw new UsagePolicyException(catalogItem.getItemId(), catalogItem.getPolicy(), catalogItem.getConnectorId()); } final NegotiationRequest negotiationRequest = createNegotiationRequestFromCatalogItem(providerConnectorUrl, diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyException.java index dcf419790b..9cf23c8ccd 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyException.java @@ -33,10 +33,12 @@ public class UsagePolicyException extends EdcClientException { private final transient Policy policy; + private final transient String businessPartnerNumber; - public UsagePolicyException(final String itemId, final Policy policy) { + public UsagePolicyException(final String itemId, final Policy policy, final String businessPartnerNumber) { super("Consumption of asset '" + itemId + "' is not permitted as the required catalog offer policies do not comply with defined IRS policies."); this.policy = policy; + this.businessPartnerNumber = businessPartnerNumber; } } diff --git a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/Tombstone.java b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/Tombstone.java index 268a33c8c4..02fb86247a 100644 --- a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/Tombstone.java +++ b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/Tombstone.java @@ -51,26 +51,27 @@ public class Tombstone { pattern = "^urn:uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$") private final String catenaXId; private final String endpointURL; + private final String businessPartnerNumber; private final ProcessingError processingError; private final Map policy; public static Tombstone from(final String catenaXId, final String endpointURL, final Exception exception, final int retryCount, final ProcessStep processStep) { - return from(catenaXId, endpointURL, exception.getMessage(), retryCount, processStep, null); + return from(catenaXId, endpointURL, exception.getMessage(), retryCount, processStep, null, null); } public static Tombstone from(final String catenaXId, final String endpointURL, final String errorDetails, final int retryCount, final ProcessStep processStep) { - return from(catenaXId, endpointURL, errorDetails, retryCount, processStep, null); + return from(catenaXId, endpointURL, errorDetails, retryCount, processStep, null, null); } public static Tombstone from(final String catenaXId, final String endpointURL, final Exception exception, - final int retryCount, final ProcessStep processStep, final Map policy) { - return from(catenaXId, endpointURL, exception.getMessage(), retryCount, processStep, policy); + final int retryCount, final ProcessStep processStep, final String businessPartnerNumber, final Map policy) { + return from(catenaXId, endpointURL, exception.getMessage(), retryCount, processStep, businessPartnerNumber, policy); } public static Tombstone from(final String catenaXId, final String endpointURL, final String errorDetails, - final int retryCount, final ProcessStep processStep, final Map policy) { + final int retryCount, final ProcessStep processStep, final String businessPartnerNumber, final Map policy) { final ProcessingError processingError = ProcessingError.builder() .withProcessStep(processStep) @@ -82,6 +83,7 @@ public static Tombstone from(final String catenaXId, final String endpointURL, f .endpointURL(endpointURL) .catenaXId(catenaXId) .processingError(processingError) + .businessPartnerNumber(businessPartnerNumber) .policy(policy) .build(); } From 7a3e6328795b214b0b20e5775e5e265e8db16d57 Mon Sep 17 00:00:00 2001 From: "Krzysztof Massalski (Extern)" Date: Tue, 27 Feb 2024 13:09:24 +0100 Subject: [PATCH 2/5] feat(impl):[#404] add bpn to tombstone --- .../irs/edc/client/exceptions/UsagePolicyException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyException.java index 9cf23c8ccd..5956b37c94 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/exceptions/UsagePolicyException.java @@ -33,7 +33,7 @@ public class UsagePolicyException extends EdcClientException { private final transient Policy policy; - private final transient String businessPartnerNumber; + private final String businessPartnerNumber; public UsagePolicyException(final String itemId, final Policy policy, final String businessPartnerNumber) { super("Consumption of asset '" + itemId From 4c0cb3bee226d8ebc284c0152049132e2ee627f3 Mon Sep 17 00:00:00 2001 From: "Krzysztof Massalski (Extern)" Date: Tue, 27 Feb 2024 13:41:56 +0100 Subject: [PATCH 3/5] feat(impl):[#404] simplify tombstone creation methods --- .../tractusx/irs/component/Tombstone.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/Tombstone.java b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/Tombstone.java index 02fb86247a..0822260099 100644 --- a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/Tombstone.java +++ b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/Tombstone.java @@ -57,35 +57,39 @@ public class Tombstone { public static Tombstone from(final String catenaXId, final String endpointURL, final Exception exception, final int retryCount, final ProcessStep processStep) { - return from(catenaXId, endpointURL, exception.getMessage(), retryCount, processStep, null, null); - } - - public static Tombstone from(final String catenaXId, final String endpointURL, final String errorDetails, - final int retryCount, final ProcessStep processStep) { - return from(catenaXId, endpointURL, errorDetails, retryCount, processStep, null, null); + return from(catenaXId, endpointURL, exception.getMessage(), retryCount, processStep); } public static Tombstone from(final String catenaXId, final String endpointURL, final Exception exception, final int retryCount, final ProcessStep processStep, final String businessPartnerNumber, final Map policy) { - return from(catenaXId, endpointURL, exception.getMessage(), retryCount, processStep, businessPartnerNumber, policy); + + return Tombstone.builder() + .endpointURL(endpointURL) + .catenaXId(catenaXId) + .processingError(withProcessingError(processStep, retryCount, exception.getMessage())) + .businessPartnerNumber(businessPartnerNumber) + .policy(policy) + .build(); } public static Tombstone from(final String catenaXId, final String endpointURL, final String errorDetails, - final int retryCount, final ProcessStep processStep, final String businessPartnerNumber, final Map policy) { + final int retryCount, final ProcessStep processStep) { - final ProcessingError processingError = ProcessingError.builder() - .withProcessStep(processStep) - .withRetryCounter(retryCount) - .withLastAttempt(ZonedDateTime.now(ZoneOffset.UTC)) - .withErrorDetail(errorDetails) - .build(); return Tombstone.builder() .endpointURL(endpointURL) .catenaXId(catenaXId) - .processingError(processingError) - .businessPartnerNumber(businessPartnerNumber) - .policy(policy) + .processingError(withProcessingError(processStep, retryCount, errorDetails)) .build(); } + private static ProcessingError withProcessingError(final ProcessStep processStep, final int retryCount, + final String exception) { + return ProcessingError.builder() + .withProcessStep(processStep) + .withRetryCounter(retryCount) + .withLastAttempt(ZonedDateTime.now(ZoneOffset.UTC)) + .withErrorDetail(exception) + .build(); + } + } From c1fc5fa9d04446ff1973ebeac58c64dbc34124fd Mon Sep 17 00:00:00 2001 From: "Krzysztof Massalski (Extern)" Date: Tue, 27 Feb 2024 14:48:22 +0100 Subject: [PATCH 4/5] feat(impl):[#404] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a747caa2e4..345fbbf45b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - DigitalTwinRegistryCreateShellService in irs-registry-client for creating shells in DTR directly +### Changed +- Added 'businessPartnerNumber' field to Tombstone model. This will be filled only when UsagePolicyValidation tombstone is being created. ## [4.6.0] - 2024-02-20 ### Added From ba1aa4dc6ca7165ae71e895333a0ffe010c1e4a0 Mon Sep 17 00:00:00 2001 From: "Krzysztof Massalski (Extern)" Date: Tue, 27 Feb 2024 14:49:23 +0100 Subject: [PATCH 5/5] feat(impl):[#404] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 345fbbf45b..f901dfd5d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Added 'businessPartnerNumber' field to Tombstone model. This will be filled only when UsagePolicyValidation tombstone is being created. +### Fixed +- Update to Spring Boot 3.1.9 to fix CVE's. + ## [4.6.0] - 2024-02-20 ### Added - Added concept to conform with IndustryCore Changes CX-0126 and CX-127