Skip to content

Commit

Permalink
chore(quality): [#841] correct exception hierarchy of UsagePolicy*Exc…
Browse files Browse the repository at this point in the history
…eption

Reason: These exceptions both have the same attributes. Making the PolicyException interface a base class and moving the attributes there simplifies exception handling allowing to deal with both exceptions in the same way without casting / type checking.
  • Loading branch information
dsmf committed Jul 30, 2024
1 parent ea86a63 commit 40f1f2a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@
********************************************************************************/
package org.eclipse.tractusx.irs.edc.client.exceptions;

import lombok.Getter;
import org.eclipse.edc.policy.model.Policy;

/**
* This interface provides get-methods for fine-grained policy exceptions
* Policy exception with detail information
*/
public interface PolicyException {
/**
* @return the corresponding bpn of the policy
*/
String getBusinessPartnerNumber();
@Getter
public class PolicyException extends EdcClientException {

/**
* @return the policy that caused the exception
*/
Policy getPolicy();
private final transient Policy policy;
private final String businessPartnerNumber;

public PolicyException(final String message, final Policy policy, final String businessPartnerNumber) {
super(message);
this.policy = policy;
this.businessPartnerNumber = businessPartnerNumber;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,12 @@
* Usage Policy Expired Exception errors in the contract negotiation.
*/
@Getter
public class UsagePolicyExpiredException extends EdcClientException implements PolicyException {

private final transient Policy policy;
private final String businessPartnerNumber;
public class UsagePolicyExpiredException extends PolicyException {

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;
+ " has expired.", providedCatalogItemPolicy, businessPartnerNumber);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,13 @@
* Usage Policy Permission Exception errors in the contract negotiation.
*/
@Getter
public class UsagePolicyPermissionException extends EdcClientException implements PolicyException {

private final transient Policy policy;
private final String businessPartnerNumber;
public class UsagePolicyPermissionException extends PolicyException {

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

this.policy = providedCatalogItemPolicy;
this.businessPartnerNumber = businessPartnerNumber;
+ " did not match with policy from " + businessPartnerNumber + ".", providedCatalogItemPolicy,
businessPartnerNumber);

}

Expand Down

0 comments on commit 40f1f2a

Please sign in to comment.