Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: eclipse-tractusx/traceability-foss#639 add catch clause #698

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -26,13 +26,13 @@
* 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;

public UsagePolicyExpiredException(final String itemId, final Policy policy, final String businessPartnerNumber) {

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
PolicyException.getPolicy
; it is advisable to add an Override annotation.
super("Consumption of asset '" + itemId

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
PolicyException.getBusinessPartnerNumber
; it is advisable to add an Override annotation.
+ "' is not permitted as the required catalog offer policies are expired.");
this.policy = policy;
this.businessPartnerNumber = businessPartnerNumber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
* 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;

public UsagePolicyPermissionException(final String itemId, final Policy policy,

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
PolicyException.getPolicy
; it is advisable to add an Override annotation.
final String businessPartnerNumber) {

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
PolicyException.getBusinessPartnerNumber
; it is advisable to add an Override annotation.
super("Consumption of asset '" + itemId
+ "' is not permitted as the required catalog offer policies do not comply with defined policies.");
this.policy = policy;
Expand Down
Loading