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 68c4f32ee4..231b6d5b31 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 @@ -42,6 +42,7 @@ import org.eclipse.tractusx.irs.edc.client.EdcSubmodelFacade; import org.eclipse.tractusx.irs.edc.client.RelationshipAspect; import org.eclipse.tractusx.irs.edc.client.exceptions.EdcClientException; +import org.eclipse.tractusx.irs.edc.client.exceptions.UsagePolicyException; import org.eclipse.tractusx.irs.registryclient.discovery.ConnectorEndpointsService; import org.eclipse.tractusx.irs.util.JsonUtil; @@ -112,17 +113,22 @@ private void processEndpoint(final Endpoint endpoint, final RelationshipAspect r aasTransferProcess.addIdsToProcess(idsToProcess); itemContainerBuilder.relationships(relationships); itemContainerBuilder.bpns(getBpnsFrom(relationships)); + } catch (final UsagePolicyException e) { + 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()))); } catch (final EdcClientException e) { log.info("Submodel Endpoint could not be retrieved for Endpoint: {}. Creating Tombstone.", endpoint.getProtocolInformation().getHref()); itemContainerBuilder.tombstone( Tombstone.from(itemId.getGlobalAssetId(), endpoint.getProtocolInformation().getHref(), e, - retryCount, ProcessStep.SUBMODEL_REQUEST)); + 0, ProcessStep.SUBMODEL_REQUEST)); } catch (final JsonParseException e) { log.info("Submodel payload did not match the expected AspectType. Creating Tombstone."); itemContainerBuilder.tombstone( Tombstone.from(itemId.getGlobalAssetId(), endpoint.getProtocolInformation().getHref(), e, - retryCount, ProcessStep.SUBMODEL_REQUEST)); + 0, ProcessStep.SUBMODEL_REQUEST)); } } 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 cb49659bb2..3b060bd29e 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 @@ -25,6 +25,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.tractusx.irs.util.TestMother.jobParameter; +import static org.eclipse.tractusx.irs.util.TestMother.jobParameterCollectAspects; import static org.eclipse.tractusx.irs.util.TestMother.jobParameterUpward; import static org.eclipse.tractusx.irs.util.TestMother.shell; import static org.eclipse.tractusx.irs.util.TestMother.shellDescriptor; @@ -47,6 +48,7 @@ import org.eclipse.tractusx.irs.component.enums.ProcessStep; import org.eclipse.tractusx.irs.edc.client.EdcSubmodelFacade; import org.eclipse.tractusx.irs.edc.client.exceptions.EdcClientException; +import org.eclipse.tractusx.irs.edc.client.exceptions.UsagePolicyException; import org.eclipse.tractusx.irs.edc.client.model.SubmodelDescriptor; import org.eclipse.tractusx.irs.registryclient.discovery.ConnectorEndpointsService; import org.eclipse.tractusx.irs.util.JsonUtil; @@ -63,10 +65,6 @@ class RelationshipDelegateTest { final String singleLevelBomAsBuiltAspectName = "urn:bamm:io.catenax.single_level_bom_as_built:2.0.0#SingleLevelBomAsBuilt"; final String singleLevelUsageAsBuiltAspectName = "urn:bamm:io.catenax.single_level_usage_as_built:2.0.0#SingleLevelUsageAsBuilt"; - private static PartChainIdentificationKey createKey() { - return PartChainIdentificationKey.builder().globalAssetId("itemId").bpn("bpn123").build(); - } - @Test void shouldFillItemContainerWithRelationshipAndAddChildIdsToProcess() throws EdcClientException, URISyntaxException, IOException { @@ -190,4 +188,31 @@ void shouldCatchJsonParseExceptionAndPutTombstone() throws EdcClientException { ProcessStep.SUBMODEL_REQUEST); } + @Test + void shouldCatchUsagePolicyExceptionAndPutTombstone() throws EdcClientException { + // given + final ItemContainer.ItemContainerBuilder itemContainerWithShell = ItemContainer.builder() + .shell(shell("", shellDescriptor( + List.of(submodelDescriptorWithDspEndpoint( + singleLevelBomAsBuiltAspectName, + "address"))))); + + // when + when(submodelFacade.getSubmodelPayload(any(), any(), any())).thenThrow(new UsagePolicyException("itemId", null)); + when(connectorEndpointsService.fetchConnectorEndpoints(any())).thenReturn(List.of("connector.endpoint.nl")); + final ItemContainer result = relationshipDelegate.process(itemContainerWithShell, jobParameter(), + new AASTransferProcess(), createKey()); + + // then + assertThat(result).isNotNull(); + assertThat(result.getTombstones()).hasSize(1); + assertThat(result.getTombstones().get(0).getCatenaXId()).isEqualTo("itemId"); + assertThat(result.getTombstones().get(0).getProcessingError().getProcessStep()).isEqualTo( + ProcessStep.USAGE_POLICY_VALIDATION); + } + + private static PartChainIdentificationKey createKey() { + return PartChainIdentificationKey.builder().globalAssetId("itemId").bpn("bpn123").build(); + } + } 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 0578826baa..312113d974 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 @@ -65,10 +65,6 @@ class SubmodelDelegateTest { final SubmodelDelegate submodelDelegate = new SubmodelDelegate(submodelFacade, semanticsHubFacade, jsonValidatorService, new JsonUtil(), connectorEndpointsService); - private static PartChainIdentificationKey createKey() { - return PartChainIdentificationKey.builder().globalAssetId("itemId").bpn("bpn123").build(); - } - @Test void shouldFilterSubmodelDescriptorsByAspectTypeFilter() { // given @@ -222,4 +218,8 @@ void shouldCatchRestClientExceptionAndPutTombstone() throws SchemaNotFoundExcept ProcessStep.SCHEMA_REQUEST); } + private static PartChainIdentificationKey createKey() { + return PartChainIdentificationKey.builder().globalAssetId("itemId").bpn("bpn123").build(); + } + }