Skip to content

Commit

Permalink
Merge pull request #774 from eclipse-tractusx/bug/#639-fix-policy-exp…
Browse files Browse the repository at this point in the history
…ired-error-message

bug: eclipse-tractusx/traceability-foss#639 update policy expired err…
  • Loading branch information
ds-lcapellino authored Jul 9, 2024
2 parents 7605a01 + bd10955 commit 8422562
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ private CompletableFuture<NegotiationResponse> startNewNegotiation(final String

if (policyCheckerService.isExpired(catalogItem.getPolicy(), bpn)) {
log.warn("Policy is expired, canceling negotiation.");
throw new UsagePolicyExpiredException(catalogItem.getPolicy(),
throw new UsagePolicyExpiredException(policyCheckerService.getValidStoredPolicies(catalogItem.getConnectorId()),
catalogItem.getPolicy(),
catalogItem.getConnectorId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
********************************************************************************/
package org.eclipse.tractusx.irs.edc.client.exceptions;

import java.util.List;

import lombok.Getter;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.tractusx.irs.edc.client.policy.AcceptedPolicy;

/**
* Usage Policy Expired Exception errors in the contract negotiation.
Expand All @@ -31,9 +34,11 @@ public class UsagePolicyExpiredException extends EdcClientException {
private final transient Policy policy;
private final String businessPartnerNumber;

public UsagePolicyExpiredException(final Policy policy, final String businessPartnerNumber) {
super("Policy from " + businessPartnerNumber + " has expired.");
this.policy = policy;
public UsagePolicyExpiredException(final List<AcceptedPolicy> acceptedPolicies,
final Policy providedCatalogItemPolicy, final String businessPartnerNumber) {
super("Policy " + acceptedPolicies.stream().map(policy -> policy.policy().getPolicyId()).toList()
+ " has expired.");
this.policy = providedCatalogItemPolicy;
this.businessPartnerNumber = businessPartnerNumber;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public class UsagePolicyPermissionException extends EdcClientException {

public UsagePolicyPermissionException(final List<AcceptedPolicy> acceptedPolicies,
final Policy providedCatalogItemPolicy, final String businessPartnerNumber) {
super("Policies "
+ acceptedPolicies.stream().map(policy -> policy.policy().getPolicyId()).toList()
super("Policies " + acceptedPolicies.stream().map(policy -> policy.policy().getPolicyId()).toList()
+ " did not match with policy from " + businessPartnerNumber + ".");

this.policy = providedCatalogItemPolicy;
Expand Down

0 comments on commit 8422562

Please sign in to comment.