Skip to content

Commit

Permalink
feat(impl):[#404] add bpn to tombstone
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-ext-kmassalski committed Feb 27, 2024
1 parent 98d7086 commit 4951f7d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions docs/src/api/irs-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private List<Submodel> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,15 @@ 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(
singleLevelBomAsBuiltAspectName,
"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());
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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());
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private CompletableFuture<NegotiationResponse> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> 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<String, Object> policy) {
return from(catenaXId, endpointURL, exception.getMessage(), retryCount, processStep, policy);
final int retryCount, final ProcessStep processStep, final String businessPartnerNumber, final Map<String, Object> 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<String, Object> policy) {
final int retryCount, final ProcessStep processStep, final String businessPartnerNumber, final Map<String, Object> policy) {

final ProcessingError processingError = ProcessingError.builder()
.withProcessStep(processStep)
Expand All @@ -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();
}
Expand Down

0 comments on commit 4951f7d

Please sign in to comment.