Skip to content

Commit

Permalink
Merge pull request eclipse-tractusx#698 from ds-lcapellino/feature/63…
Browse files Browse the repository at this point in the history
…9-handle-policy-expiration

feature: eclipse-tractusx/traceability-foss#639 add catch clause
  • Loading branch information
ds-jhartmann authored Jul 10, 2024
2 parents 4f0b854 + 3a53557 commit da3bc67
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.tractusx.irs.data.JsonParseException;
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.UsagePolicyExpiredException;
import org.eclipse.tractusx.irs.edc.client.exceptions.UsagePolicyPermissionException;
import org.eclipse.tractusx.irs.edc.client.relationships.RelationshipAspect;
import org.eclipse.tractusx.irs.registryclient.discovery.ConnectorEndpointsService;
Expand Down Expand Up @@ -114,7 +115,7 @@ private void processEndpoint(final Endpoint endpoint, final RelationshipAspect r
aasTransferProcess.addIdsToProcess(idsToProcess);
itemContainerBuilder.relationships(relationships);
itemContainerBuilder.bpns(getBpnsFrom(relationships));
} catch (final UsagePolicyPermissionException e) {
} catch (final UsagePolicyPermissionException | UsagePolicyExpiredException e) {
log.info("Encountered usage policy exception: {}. Creating Tombstone.", e.getMessage());
itemContainerBuilder.tombstone(
Tombstone.from(itemId.getGlobalAssetId(), endpoint.getProtocolInformation().getHref(), e, 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.tractusx.irs.data.JsonParseException;
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.UsagePolicyExpiredException;
import org.eclipse.tractusx.irs.edc.client.exceptions.UsagePolicyPermissionException;
import org.eclipse.tractusx.irs.registryclient.discovery.ConnectorEndpointsService;
import org.eclipse.tractusx.irs.semanticshub.SemanticsHubFacade;
Expand Down Expand Up @@ -142,8 +143,8 @@ private List<Submodel> getSubmodels(final SubmodelDescriptor submodelDescriptor,
itemContainerBuilder.tombstone(Tombstone.from(itemId, endpoint.getProtocolInformation().getHref(), e, 0,
ProcessStep.SCHEMA_REQUEST));
log.info("Cannot load JSON schema for validation. Creating Tombstone.");
} catch (final UsagePolicyPermissionException e) {
log.info("Encountered usage policy exception: {}. Creating Tombstone.", e.getMessage());
} catch (final UsagePolicyPermissionException | UsagePolicyExpiredException e) {
log.info("Encountered usage policy permission exception: {}. Creating Tombstone.", e.getMessage());
itemContainerBuilder.tombstone(Tombstone.from(itemId, endpoint.getProtocolInformation().getHref(), e, 0,
ProcessStep.USAGE_POLICY_VALIDATION, e.getBusinessPartnerNumber(),
jsonUtil.asMap(e.getPolicy())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ public EdcClientException(final Throwable cause) {
public EdcClientException(final String msg) {
super(msg);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/********************************************************************************
* Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.edc.client.exceptions;

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

/**
* This interface provides get-methods for fine-grained policy exceptions
*/
public interface PolicyException {
/**
* @return the corresponding bpn of the policy
*/
String getBusinessPartnerNumber();

/**
* @return the policy that caused the exception
*/
Policy getPolicy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Usage Policy Expired Exception errors in the contract negotiation.
*/
@Getter
public class UsagePolicyExpiredException extends EdcClientException {
public class UsagePolicyExpiredException extends EdcClientException implements PolicyException {

private final transient Policy policy;
private final String businessPartnerNumber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* Usage Policy Permission Exception errors in the contract negotiation.
*/
@Getter
public class UsagePolicyPermissionException extends EdcClientException {
public class UsagePolicyPermissionException extends EdcClientException implements PolicyException {

private final transient Policy policy;
private final String businessPartnerNumber;
Expand Down

0 comments on commit da3bc67

Please sign in to comment.