Skip to content

Commit

Permalink
feat(impl):[#370] catch UsagePolicyExc in RelationshipDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-ext-kmassalski committed Jan 31, 2024
1 parent e9b9c36 commit 622ea73
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -222,4 +218,8 @@ void shouldCatchRestClientExceptionAndPutTombstone() throws SchemaNotFoundExcept
ProcessStep.SCHEMA_REQUEST);
}

private static PartChainIdentificationKey createKey() {
return PartChainIdentificationKey.builder().globalAssetId("itemId").bpn("bpn123").build();
}

}

0 comments on commit 622ea73

Please sign in to comment.