From cd6de7d557ca72b10e39441d07c7ddb6b835f203 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Thu, 25 Jan 2024 15:58:37 +0100 Subject: [PATCH 01/55] feature(irs-edc-client): #412 irs-lib-extension for asset management capabilities draft v1 --- .../irs/connector/job/JobOrchestrator.java | 2 +- .../irs/edc/client/asset/EdcAssetService.java | 152 ++++++++++++++++++ .../irs/edc/client/asset/model/EdcAsset.java | 40 +++++ .../asset/model/EdcAssetProperties.java | 42 +++++ .../edc/client/asset/model/EdcContext.java | 42 +++++ .../model/EdcCreateDataAssetRequest.java | 39 +++++ .../client/asset/model/EdcDataAddress.java | 44 +++++ .../asset/model/EdcDataAddressProperties.java | 43 +++++ .../asset/model/NotificationMethod.java | 36 +++++ .../client/asset/model/NotificationType.java | 36 +++++ .../edc/client/asset/model/OdrlContext.java | 30 ++++ .../exception/CreateEdcAssetException.java | 30 ++++ .../client/contract/model/EDRAuthCode.java | 35 ++++ .../model/EdcContractDefinitionCriteria.java | 43 +++++ .../EdcCreateContractDefinitionRequest.java | 48 ++++++ .../client/contract/model/EdcOperator.java | 33 ++++ .../CreateEdcContractDefinitionException.java | 30 ++++ .../service/EdcContractDefinitionService.java | 98 +++++++++++ .../EdcCreatePolicyDefinitionRequest.java | 44 +++++ .../edc/client/policy/model/EdcPolicy.java | 35 ++++ .../policy/model/EdcPolicyPermission.java | 35 ++++ .../model/EdcPolicyPermissionConstraint.java | 37 +++++ ...cPolicyPermissionConstraintExpression.java | 45 ++++++ .../CreateEdcPolicyDefinitionException.java | 30 ++++ .../service/EdcPolicyDefinitionService.java | 131 +++++++++++++++ 25 files changed, 1179 insertions(+), 1 deletion(-) create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAsset.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAssetProperties.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcContext.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcCreateDataAssetRequest.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddress.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddressProperties.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationMethod.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationType.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/OdrlContext.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EDRAuthCode.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractDefinitionCriteria.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcCreatePolicyDefinitionRequest.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicy.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermission.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraint.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraintExpression.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/connector/job/JobOrchestrator.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/connector/job/JobOrchestrator.java index d07a12d581..7991aa6144 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/connector/job/JobOrchestrator.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/connector/job/JobOrchestrator.java @@ -119,7 +119,7 @@ public JobInitiateResponse startJob(final String globalAssetId, final JobParamet final Stream requests; try { - requests = handler.initiate(multiJob); + requests = z.initiate(multiJob); } catch (RuntimeException e) { markJobInError(multiJob, e, JOB_EXECUTION_FAILED); meterService.incrementJobFailed(); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java new file mode 100644 index 0000000000..730d5cd0d5 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -0,0 +1,152 @@ +/******************************************************************************** + * Copyright (c) 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.asset; + +import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.NAMESPACE_EDC; + +import java.util.UUID; + +import lombok.extern.slf4j.Slf4j; +import org.eclipse.edc.spi.types.domain.asset.Asset; +import org.eclipse.tractusx.irs.edc.client.asset.model.EdcAsset; +import org.eclipse.tractusx.irs.edc.client.asset.model.EdcAssetProperties; +import org.eclipse.tractusx.irs.edc.client.asset.model.EdcContext; +import org.eclipse.tractusx.irs.edc.client.asset.model.EdcCreateDataAssetRequest; +import org.eclipse.tractusx.irs.edc.client.asset.model.EdcDataAddress; +import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationMethod; +import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationType; +import org.eclipse.tractusx.irs.edc.client.asset.model.exception.CreateEdcAssetException; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +@Slf4j +public class EdcAssetService { + + private static final String DEFAULT_CONTENT_TYPE = "application/json"; + private static final String DEFAULT_POLICY_ID = "use-eu"; + private static final String DEFAULT_METHOD = "POST"; + private static final String DEFAULT_DATA_ADDRESS_PROPERTY_TYPE = "HttpData"; + // TODO: move to config ? + private static final String ASSETS_PATH = "/management/v2/assets"; + + public String createNotificationAsset(String baseUrl, String assetName, NotificationMethod notificationMethod, + NotificationType notificationType, RestTemplate restTemplate) { + EdcCreateDataAssetRequest request = createNotificationAssetRequest(assetName, baseUrl, notificationMethod, + notificationType); + return sendRequest(request, restTemplate); + } + + private static String sendRequest( final EdcCreateDataAssetRequest request, final RestTemplate restTemplate) { + final String assetId = request.getAsset().getAssetId(); + final String assetName = request.getAsset().getEdcAssetProperties().getAssetName(); + final ResponseEntity createEdcDataAssetResponse; + try { + createEdcDataAssetResponse = restTemplate.postForEntity(ASSETS_PATH, request, String.class); + HttpStatusCode responseCode = createEdcDataAssetResponse.getStatusCode(); + + if (responseCode.value() == 409) { + log.info("{} asset already exists in the EDC", assetId); + return assetId; + } + + if (responseCode.value() == 200) { + return assetId; + } + } catch (RestClientException e) { + throw new CreateEdcAssetException(e); + } + throw new CreateEdcAssetException("Failed to create asset %s".formatted(assetName)); + } + + public String createDtrAsset() { + return ""; + } + + public void deleteAsset(String notificationAssetId, RestTemplate restTemplate) { + String deleteUri = UriComponentsBuilder.fromPath(ASSETS_PATH) + .pathSegment("{notificationAssetId}") + .buildAndExpand(notificationAssetId) + .toUriString(); + + try { + restTemplate.delete(deleteUri); + } catch (RestClientException e) { + log.error("Failed to delete EDC notification asset {}. Reason: ", notificationAssetId, e); + } + } + + private EdcCreateDataAssetRequest createNotificationAssetRequest(String assetName, String baseUrl, + NotificationMethod notificationMethod, NotificationType notificationType) { + + String assetId = UUID.randomUUID().toString(); + EdcDataAddress dataAddress = EdcDataAddress.builder() + .type(DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) + .baseUrl(baseUrl) + .method(DEFAULT_METHOD) + .proxyBody("true") + .proxyMethod("true") + .build(); + + EdcAssetProperties assetProperties = EdcAssetProperties.builder() + .assetName(assetName) + .policyId(DEFAULT_POLICY_ID) + .contentType(DEFAULT_CONTENT_TYPE) + .type(notificationType.getValue()) + .notificationType(notificationType.getValue()) + .notificationMethod(notificationMethod.getValue()) + .build(); + + EdcAsset asset = EdcAsset.builder().assetId(assetId).type("Asset").edcAssetProperties(assetProperties).build(); + + EdcContext edcContext = EdcContext.builder().edc(NAMESPACE_EDC).build(); + + return EdcCreateDataAssetRequest.builder().asset(asset).dataAddress(dataAddress).context(edcContext).build(); + } + + // TODO check edc edc for corresponding asset class + private EdcCreateDataAssetRequest createDtrAssetRequest(String assetName, String baseUrl, + NotificationMethod notificationMethod, NotificationType notificationType) { + String assetId = UUID.randomUUID().toString(); + EdcDataAddress dataAddress = EdcDataAddress.builder() + .type(DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) + .baseUrl(baseUrl) + .method(DEFAULT_METHOD) + .proxyBody("true") + .proxyMethod("true") + .build(); + + EdcAssetProperties assetProperties = EdcAssetProperties.builder() + .assetName(assetName) + .policyId(DEFAULT_POLICY_ID) + .contentType(DEFAULT_CONTENT_TYPE) + .type(notificationType.getValue()) + .notificationType(notificationType.getValue()) + .notificationMethod(notificationMethod.getValue()) + .build(); + + EdcAsset asset = EdcAsset.builder().assetId(assetId).type("Asset").edcAssetProperties(assetProperties).build(); + + EdcContext edcContext = EdcContext.builder().edc(NAMESPACE_EDC).build(); + + return EdcCreateDataAssetRequest.builder().asset(asset).dataAddress(dataAddress).context(edcContext).build(); + } +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAsset.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAsset.java new file mode 100644 index 0000000000..eeb0e02513 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAsset.java @@ -0,0 +1,40 @@ +/******************************************************************************** + * Copyright (c) 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.asset.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@ToString +@Getter +@Builder +public class EdcAsset { + + @JsonProperty("@id") + private String assetId; + + @JsonProperty("@type") + private String type; + + @JsonProperty("properties") + private EdcAssetProperties edcAssetProperties; + +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAssetProperties.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAssetProperties.java new file mode 100644 index 0000000000..5a4f0cf7e8 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAssetProperties.java @@ -0,0 +1,42 @@ +/******************************************************************************** + * Copyright (c) 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.asset.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@ToString +@Getter +@Builder +public class EdcAssetProperties { + @JsonProperty("description") + String assetName; + @JsonProperty("contenttype") + String contentType; + @JsonProperty("policy-id") + String policyId; + @JsonProperty("type") + String type; + @JsonProperty("notificationtype") + String notificationType; + @JsonProperty("notificationmethod") + String notificationMethod; +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcContext.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcContext.java new file mode 100644 index 0000000000..44b2acb6f6 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcContext.java @@ -0,0 +1,42 @@ +/******************************************************************************** + * Copyright (c) 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.asset.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.ToString; + +@ToString +@Builder +public class EdcContext { + + /** + * For dtr asset currently following context is created by python script + * + * "dct": "https://purl.org/dc/terms/", + * "tx": "https://w3id.org/tractusx/v0.0.1/ns/", + * "edc": "https://w3id.org/edc/v0.0.1/ns/", + * "odrl": "http://www.w3.org/ns/odrl/2/", + * "dcat": "https://www.w3.org/ns/dcat/", + * "dspace": "https://w3id.org/dspace/v0.8/" + */ + + @JsonProperty("edc") + String edc; +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcCreateDataAssetRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcCreateDataAssetRequest.java new file mode 100644 index 0000000000..66a021510c --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcCreateDataAssetRequest.java @@ -0,0 +1,39 @@ +/******************************************************************************** + * Copyright (c) 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.asset.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@ToString +@Getter +@Builder +public class EdcCreateDataAssetRequest { + + @JsonProperty("@context") + private EdcContext context; + + @JsonProperty("asset") + private EdcAsset asset; + + @JsonProperty("dataAddress") + private EdcDataAddress dataAddress; +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddress.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddress.java new file mode 100644 index 0000000000..2ae31d6d27 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddress.java @@ -0,0 +1,44 @@ +/******************************************************************************** + * Copyright (c) 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.asset.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.ToString; + +@ToString +@Builder +public class EdcDataAddress { + + @JsonProperty("type") + private String type; + + @JsonProperty("baseUrl") + private String baseUrl; + + @JsonProperty("proxyMethod") + private String proxyMethod; + + @JsonProperty("proxyBody") + private String proxyBody; + + @JsonProperty("method") + private String method; + +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddressProperties.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddressProperties.java new file mode 100644 index 0000000000..2ded52c1ec --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddressProperties.java @@ -0,0 +1,43 @@ +/******************************************************************************** + * Copyright (c) 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.asset.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.ToString; + +@ToString +@Builder +public class EdcDataAddressProperties { + + @JsonProperty("baseUrl") + private final String baseUrl; + + @JsonProperty("proxyMethod") + private final String proxyMethod; + + @JsonProperty("method") + private final String method; + + @JsonProperty("proxyBody") + private final String proxyBody; + + @JsonProperty("type") + private final String type; +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationMethod.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationMethod.java new file mode 100644 index 0000000000..08ebe34d12 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationMethod.java @@ -0,0 +1,36 @@ +/******************************************************************************** + * Copyright (c) 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.asset.model; + +public enum NotificationMethod { + RECEIVE("receive"), + UPDATE("update"), + RESOLVE("resolve"); + + private final String value; + + NotificationMethod(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} + diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationType.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationType.java new file mode 100644 index 0000000000..4c6a3c8fe2 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationType.java @@ -0,0 +1,36 @@ +/******************************************************************************** + * 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.asset.model; + +public enum NotificationType { + QUALITY_INVESTIGATION("qualityinvestigation"), + QUALITY_ALERT("qualityalert"); + + private final String value; + + NotificationType(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/OdrlContext.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/OdrlContext.java new file mode 100644 index 0000000000..af4c1ec2b6 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/OdrlContext.java @@ -0,0 +1,30 @@ +/******************************************************************************** + * Copyright (c) 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.asset.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.ToString; + +@ToString +@Builder +public class OdrlContext { + @JsonProperty("odrl") + String odrl; +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java new file mode 100644 index 0000000000..d2592c691a --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java @@ -0,0 +1,30 @@ +/******************************************************************************** + * Copyright (c) 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.asset.model.exception; + +public class CreateEdcAssetException extends RuntimeException { + + public CreateEdcAssetException(String message) { + super(message); + } + + public CreateEdcAssetException(Throwable cause) { + super(cause); + } +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EDRAuthCode.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EDRAuthCode.java new file mode 100644 index 0000000000..264be9348a --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EDRAuthCode.java @@ -0,0 +1,35 @@ +/******************************************************************************** + * Copyright (c) 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.contract.model; + +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +/** + * The decoded Auth code JWT. + */ +@Builder +@Data +@Jacksonized +public class EDRAuthCode { + private final long exp; + private final String dad; + private final String cid; +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractDefinitionCriteria.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractDefinitionCriteria.java new file mode 100644 index 0000000000..98edc3c8c2 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractDefinitionCriteria.java @@ -0,0 +1,43 @@ +/******************************************************************************** + * Copyright (c) 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.contract.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@ToString +@Getter +@Builder +public class EdcContractDefinitionCriteria { + + @JsonProperty("@type") + private String type; + + @JsonProperty("operandLeft") + private String operandLeft; + + @JsonProperty("operator") + private String operator; + + @JsonProperty("operandRight") + private String operandRight; + +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java new file mode 100644 index 0000000000..1c0f1c405f --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java @@ -0,0 +1,48 @@ +/******************************************************************************** + * Copyright (c) 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.contract.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.ToString; +import org.eclipse.tractusx.irs.edc.client.asset.model.EdcContext; + +@ToString +@Builder +public class EdcCreateContractDefinitionRequest { + + @JsonProperty("@context") + private EdcContext edcContext; + + @JsonProperty("@type") + private String type; + + @JsonProperty("@id") + private String id; + + @JsonProperty("accessPolicyId") + private String accessPolicyId; + + @JsonProperty("contractPolicyId") + private String contractPolicyId; + + @JsonProperty("assetsSelector") + private EdcContractDefinitionCriteria assetsSelector; + +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java new file mode 100644 index 0000000000..6f9dc4bffd --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java @@ -0,0 +1,33 @@ +/******************************************************************************** + * Copyright (c) 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.contract.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.ToString; + +@ToString +@Builder +@AllArgsConstructor +public class EdcOperator { + @JsonProperty("@id") + String id; + +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java new file mode 100644 index 0000000000..2205c4f1e9 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java @@ -0,0 +1,30 @@ +/******************************************************************************** + * Copyright (c) 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.contract.model.exception; + +public class CreateEdcContractDefinitionException extends RuntimeException { + + public CreateEdcContractDefinitionException(String message) { + super(message); + } + + public CreateEdcContractDefinitionException(Throwable cause) { + super(cause); + } +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java new file mode 100644 index 0000000000..b7e805ca4e --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java @@ -0,0 +1,98 @@ +/******************************************************************************** + * Copyright (c) 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.contract.service; + +import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.NAMESPACE_EDC; + +import lombok.extern.slf4j.Slf4j; +import org.eclipse.edc.spi.types.domain.asset.Asset; +import org.eclipse.tractusx.irs.edc.client.asset.model.EdcContext; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractDefinitionCriteria; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcCreateContractDefinitionRequest; +import org.eclipse.tractusx.irs.edc.client.contract.model.exception.CreateEdcContractDefinitionException; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; + +@Slf4j +public class EdcContractDefinitionService { + + private static final String ASSET_SELECTOR_ID = "https://w3id.org/edc/v0.0.1/ns/id"; + private static final String ASSET_SELECTOR_EQUALITY_OPERATOR = "="; + private static final String ASSET_SELECTOR_TYPE = "CriterionDto"; + private static final String CONTRACT_DEFINITION_TYPE = "ContractDefinition"; + + private static final String CONTRACT_DEFINITION_PATH = "/management/v2/contractdefinitions"; + + public String createContractDefinition(String assetId, String policyId, RestTemplate restTemplate) { + EdcCreateContractDefinitionRequest createContractDefinitionRequest = createContractDefinitionRequest(assetId, + policyId); + final ResponseEntity createContractDefinitionResponse; + try { + createContractDefinitionResponse = restTemplate.postForEntity(CONTRACT_DEFINITION_PATH, + createContractDefinitionRequest, String.class); + + HttpStatusCode responseCode = createContractDefinitionResponse.getStatusCode(); + + if (responseCode.value() == 409) { + log.info("{} asset contract definition already exists in the EDC", assetId); + + throw new CreateEdcContractDefinitionException("Asset contract definition already exists in the EDC"); + } + + if (responseCode.value() == 200) { + return policyId; + } + + throw new CreateEdcContractDefinitionException( + "Failed to create EDC contract definition for %s notification asset id".formatted(assetId)); + } catch (RestClientException e) { + log.error( + "Failed to create edc contract definition for {} notification asset and {} policy definition id. Reason: ", + assetId, policyId, e); + + throw new CreateEdcContractDefinitionException(e); + } + + } + + private static EdcCreateContractDefinitionRequest createContractDefinitionRequest(final String notificationAssetId, + final String accessPolicyId) { + EdcContractDefinitionCriteria edcContractDefinitionCriteria = EdcContractDefinitionCriteria.builder() + .type(ASSET_SELECTOR_TYPE) + .operandLeft( + ASSET_SELECTOR_ID) + .operandRight( + notificationAssetId) + .operator( + ASSET_SELECTOR_EQUALITY_OPERATOR) + .build(); + + EdcContext edcContext = EdcContext.builder().edc(NAMESPACE_EDC).build(); + return EdcCreateContractDefinitionRequest.builder() + .contractPolicyId(accessPolicyId) + .edcContext(edcContext) + .type(CONTRACT_DEFINITION_TYPE) + .accessPolicyId(accessPolicyId) + .id(accessPolicyId) + .assetsSelector(edcContractDefinitionCriteria) + .build(); + } +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcCreatePolicyDefinitionRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcCreatePolicyDefinitionRequest.java new file mode 100644 index 0000000000..fd3cf0ba51 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcCreatePolicyDefinitionRequest.java @@ -0,0 +1,44 @@ +/******************************************************************************** + * Copyright (c) 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.policy.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; +import org.eclipse.tractusx.irs.edc.client.asset.model.OdrlContext; + +@ToString +@Getter +@Builder +public class EdcCreatePolicyDefinitionRequest { + + @JsonProperty("@context") + private OdrlContext odrlContext; + + @JsonProperty("@id") + private String policyDefinitionId; + + @JsonProperty("@type") + private String type; + + @JsonProperty("policy") + private EdcPolicy policy; + +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicy.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicy.java new file mode 100644 index 0000000000..953dee724c --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicy.java @@ -0,0 +1,35 @@ +/******************************************************************************** + * Copyright (c) 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.policy.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.ToString; + +@ToString +@Builder +public class EdcPolicy { + @JsonProperty("@type") + private String type; + @JsonProperty("odrl:permission") + private List odrlPermissions; + +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermission.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermission.java new file mode 100644 index 0000000000..681d1f9e5c --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermission.java @@ -0,0 +1,35 @@ +/******************************************************************************** + * Copyright (c) 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.policy.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.ToString; + +@ToString +@Builder +public class EdcPolicyPermission { + + @JsonProperty("odrl:action") + private String action; + + @JsonProperty("odrl:constraint") + private EdcPolicyPermissionConstraint edcPolicyPermissionConstraints; + +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraint.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraint.java new file mode 100644 index 0000000000..7f680c7874 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraint.java @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (c) 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.policy.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.ToString; + +@ToString +@Builder +public class EdcPolicyPermissionConstraint { + + @JsonProperty("@type") + private String type; + + @JsonProperty("odrl:or") + private List orExpressions; + +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraintExpression.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraintExpression.java new file mode 100644 index 0000000000..ca4090bea7 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraintExpression.java @@ -0,0 +1,45 @@ +/******************************************************************************** + * Copyright (c) 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.policy.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcOperator; + +@ToString +@Getter +@Builder +public class EdcPolicyPermissionConstraintExpression { + + // Constraint + @JsonProperty("@type") + private final String type; + + @JsonProperty("odrl:leftOperand") + private final String leftOperand; + + @JsonProperty("odrl:rightOperand") + private final String rightOperand; + + @JsonProperty("odrl:operator") + private final EdcOperator operator; + +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java new file mode 100644 index 0000000000..a915b07906 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java @@ -0,0 +1,30 @@ +/******************************************************************************** + * Copyright (c) 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.policy.model.exception; + +public class CreateEdcPolicyDefinitionException extends RuntimeException { + + public CreateEdcPolicyDefinitionException(String message) { + super(message); + } + + public CreateEdcPolicyDefinitionException(Throwable cause) { + super(cause); + } +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java new file mode 100644 index 0000000000..8080ab354b --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -0,0 +1,131 @@ +/******************************************************************************** + * Copyright (c) 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.policy.service; + +import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.NAMESPACE_ODRL; + +import java.util.List; +import java.util.UUID; + +import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.irs.edc.client.asset.model.OdrlContext; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcOperator; +import org.eclipse.tractusx.irs.edc.client.policy.model.EdcCreatePolicyDefinitionRequest; +import org.eclipse.tractusx.irs.edc.client.policy.model.EdcPolicy; +import org.eclipse.tractusx.irs.edc.client.policy.model.EdcPolicyPermission; +import org.eclipse.tractusx.irs.edc.client.policy.model.EdcPolicyPermissionConstraint; +import org.eclipse.tractusx.irs.edc.client.policy.model.EdcPolicyPermissionConstraintExpression; +import org.eclipse.tractusx.irs.edc.client.policy.model.exception.CreateEdcPolicyDefinitionException; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +@Slf4j +public class EdcPolicyDefinitionService { + + private static final String USE_ACTION = "USE"; + private static final String POLICY_TYPE = "Policy"; + private static final String POLICY_DEFINITION_TYPE = "PolicyDefinitionRequestDto"; + private static final String ATOMIC_CONSTRAINT = "AtomicConstraint"; + private static final String CONSTRAINT = "Constraint"; + private static final String OPERATOR_PREFIX = "odrl:"; + + private static final String POLICY_DEFINITION_PATH = "/management/v2/policydefinitions"; + + public String createAccessPolicy(RestTemplate restTemplate) { + + final EdcCreatePolicyDefinitionRequest request = createPolicyDefinition(); + + final ResponseEntity createPolicyDefinitionResponse; + try { + createPolicyDefinitionResponse = restTemplate.postForEntity(POLICY_DEFINITION_PATH, request, String.class); + } catch (RestClientException e) { + log.error("Failed to create EDC notification asset policy. Reason: ", e); + + throw new CreateEdcPolicyDefinitionException(e); + } + + HttpStatusCode responseCode = createPolicyDefinitionResponse.getStatusCode(); + + if (responseCode.value() == 409) { + log.info("Notification asset policy definition already exists in the EDC"); + + throw new CreateEdcPolicyDefinitionException("Asset policy definition already exists in the EDC"); + } + + if (responseCode.value() == 200) { + return request.getPolicyDefinitionId(); + } + + throw new CreateEdcPolicyDefinitionException("Failed to create EDC policy definition for asset"); + } + + private EdcCreatePolicyDefinitionRequest createPolicyDefinition() { + EdcPolicyPermissionConstraintExpression constraint = EdcPolicyPermissionConstraintExpression.builder() + .leftOperand( + "PURPOSE") // configurable ? parameter ? + .rightOperand( + "ID 3.0 Trace") // parameter + .operator( + new EdcOperator( + OPERATOR_PREFIX + + "eq")) + .type(CONSTRAINT) + .build(); + + EdcPolicyPermissionConstraint edcPolicyPermissionConstraint = EdcPolicyPermissionConstraint.builder() + .orExpressions( + List.of(constraint)) + .type(ATOMIC_CONSTRAINT) + .build(); + + EdcPolicyPermission odrlPermissions = EdcPolicyPermission.builder() + .action(USE_ACTION) + .edcPolicyPermissionConstraints( + edcPolicyPermissionConstraint) + .build(); + + EdcPolicy edcPolicy = EdcPolicy.builder().odrlPermissions(List.of(odrlPermissions)).type(POLICY_TYPE).build(); + + String accessPolicyId = UUID.randomUUID().toString(); + OdrlContext odrlContext = OdrlContext.builder().odrl(NAMESPACE_ODRL).build(); + + return EdcCreatePolicyDefinitionRequest.builder() + .policyDefinitionId(accessPolicyId) + .policy(edcPolicy) + .odrlContext(odrlContext) + .type(POLICY_DEFINITION_TYPE) + .build(); + } + + public void deleteAccessPolicy(String accessPolicyId, RestTemplate restTemplate) { + String deleteUri = UriComponentsBuilder.fromPath(POLICY_DEFINITION_PATH) + .pathSegment("{accessPolicyId}") + .buildAndExpand(accessPolicyId) + .toUriString(); + + try { + restTemplate.delete(deleteUri); + } catch (RestClientException e) { + log.error("Failed to delete EDC notification asset policy {}. Reason: ", accessPolicyId, e); + } + } +} From 4dd365dccc76ef5a748b92ccd392681fc92532a3 Mon Sep 17 00:00:00 2001 From: mk Date: Fri, 26 Jan 2024 16:15:04 +0100 Subject: [PATCH 02/55] chore(concept):[#367] add concept for industry core --- .../#367-adapt-to-changes-industry-core.md | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md diff --git a/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md b/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md new file mode 100644 index 0000000000..05780c5e00 --- /dev/null +++ b/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md @@ -0,0 +1,139 @@ +# IndustryCore Changes #367 + +| Key | Value | +|---------------|-------------------| +| Autor | @ds-mkanal | +| Creation date | 26.01.2024 | +| Ticket Id | https://github.com/eclipse-tractusx/item-relationship-service/issues/367 | +| State | WIP | + +# Table of Contents +1. [Overview](#overview) +2. [Summary](#summary) +3. [Problem Statement](#problem-statement) +4. [Requirements](#requirements) +5. [NFR](#nfr) +6. [Out of scope](#out-of-scope) +7. [Assumptions](#assumptions) +8. [Definition of the Industry Core](#definition-of-the-industry-core) +9. [Glossary](#glossary) +10. [References](#references) +11. [Additional Details](#additional-details) + +# TODO +- TODO: globalAssetId of the twins being referenced MUST be equal to the unique ID being used in Catena-X. +- [ ] AAS manufacturerId is mandatory [Add AC to PBI] +- [ ] manufacturerPartId is mandatory [Add AC to PBI] +- [ ] customerPartId is optional [Add AC to PBI] +- [ ] assetLifecyclePhase optional for asBuilt and mandatory for asPlanned [Add AC to PBI] +- [ ] digitalTwinType mandatory > filter for digitalTwinType="PartType" or "PartInstance" [Add AC to PBI] +- [ ] SerialParts: Add optional van number for [Add AC to PBI] +- [ ] SerialParts: partInstanceId is mandatory [Add AC to PBI] + +# Overview + +The "Industry Core" is a fundamental element in the C-X network or system architecture. +It provides essential functions for identification, traversal, data flow, configuration, and communication in a modular and +interconnected environment. +The goal is to make components identifiable and discoverable at type and instance levels. +Enable seamless traversal across different tier levels. +Facilitate the creation of data chains. +Crucial role in configuring enablement services for component-based data exchange +Notification base message exchange. + +1. Identifiability and findability +2. Traversing Across multiple tier levels +3. Facilitate Data Chains +4. Configuration for Enablement Services +5. Components-Based Data Exchange +The core enables the sending of notifications, indicating that there's a mechanism for alerting or informing relevant parties about specific events or changes within the system. + +# Summary + +# Problem Statement + +# Requirements + + +# NFR + +# Out of scope + +# Assumptions + +# Definition of the Industry Core + +- [CX-0127-IndustryCorePartInstance#1.0.0](https://github.com/catenax-eV/product-standardization-prod/tree/CX-0127-IndustryCorePartInstance-v1.0.0/standards/CX-0127-IndustryCorePartInstance) + +## Standards to be complied with + +| Fullfilled | Standard | Description | +|------------|--------------------------------------------------|---------------------------------------------------------------------------------| +| [x] | CX-0002 Digital Twins in Catena-X 2.2.0 | Trace-Xs notification process and consumption of assets is bases on DT standards | +| [x] | CX-0018 Eclipse Data Space Connector (EDC) 2.1.0 | Data consumption and data provision as well as the sending and receiving of messages takes place exclusively via the EDC | + + +- [x] +CX-0018 Eclipse Data Space Connector (EDC) 2.1.0 + +## Describe Part at type and instance level + +| Level | Name | Description | Standard | +|----------------|---------------|----------------------------------------------------------------------------------|----------------------| +| Type Level | CatalogueType | Type Level (part number, material number, catalog part) | | +| Instance Level | SerialPart | Instance Level (vehicle, ECUs, serialized parts, batches, etc) | CX-0019 Aspect Model | +| Instance Level | Batch | Instance Level (vehicle, ECUs, serialized parts, batches, etc) | CX-0021 Aspect Model | +| Instance Level | JiS / JustInSequencePart | Instance Level (vehicle, ECUs, serialized parts, batches, etc) | | +|Instance Level | SingleLevelBomAsBuilt| RBuilts relationsship between parts in downwards direction (customer > supplier) | CX-0020 Aspect Model | +| Instance Level | PartSiteInformationAsBuilt | (shared aspect) | | + +# Changes in AAS +| Key | Availability | Description | +|------------|------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| manufacturerId | Mandatory | The Business Partner Number (BPNL) of the manufacturer of the part. | +|manufacturerPartId | Mandatory | | +|customerPartId | Optional | | +|assetLifecyclePhase | asPlanned(Mandatory) / asBuilt(Optional) | @Deprecated For serialized parts, batches, and JIS parts, use the value AsBuilt. For catalog parts in a Digital Twin As-Planned lifecycle phase, use the value AsPlanned. | +|digitalTwinType | Mandatory | digitalTwinType="PartType" OR digitalTwinType="PartInstance" For parts on an instance level (e.g. serialized parts, batches, and JIS parts), use the value PartInstance. For parts on a part type level (e.g. catalog parts), use the value PartType. | | | + +# Changes in SerialPart +| Key | Availability | Description | +|------------|------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| partInstanceId | Mandatory | | +| van | Optioonal | | + + +## Discoverable in the network + +- [ ] re-definition if the "specific asset ids" + +## Enable traversing across serveral tier levels +- Industry Core aspect models +- DataChain KIT + +## Configure the necessary enablement services +- EDC Setup (BPN-S/BPN-L, Policy Handling of the Core) + +## Sending of notifications +- Header +- EDC-Assets + +## Core Elements +- [CX-0002-DigitalTwinsInCatenaX](https://github.com/catenax-eV/product-standardization-prod/tree/CX-0127-IndustryCorePartInstance-v1.0.0/standards/CX-0002-DigitalTwinsInCatenaX) + + +# Glossary + +| Abbreviation | Name | Description | +|--------------|-------------------------|----------------------------------------------------------| +| ECU | Electronic Control Unit | An ECU's main job is to keep the engine working smoothly | +| JIS | Just In Sequence | Just-in-sequence is a delivery concept where parts are delivered to the production plant at a requested time in the exact order of installation, typically for a 1:1 dependency on the manufactured product. A just-in-sequence-part is a part for which this concept and order of delivery applies and which does not have a dedicated serial number (then it would be considered a serialized part). Examples for JIS-parts are seats and bumpers. | +| BPN | Business Partner Number | A BPN is the unique identifier of a partner within Catena-x. | +| |Part Instance|A part instance is a physically produced instance (e.g. serialized part, batch, just-in-sequence-part) of a part type. | +| |Part Type| A part type is a generic (not physically produced) part on material- or catalog-level as a representation for a designed part.| +| VAN | Vehicle Anonymised Number | A number mapped 1:1 to VIN, but pseudonomised.| + +# References + +# Additional Details +Given the dynamic nature of ongoing development, there might be variations between the conceptualization and the current implementation. For the latest status, refer to the documentation. From 4d7ff61cfb2e255ae1d46ab2130df6981b0706ab Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Wed, 31 Jan 2024 09:09:20 +0100 Subject: [PATCH 03/55] feature(irs-edc-client): #412 refactor code to use transformer and edc classes for asset creation --- .../irs/edc/client/asset/EdcAssetService.java | 144 +++++++++--------- .../{EdcAsset.java => AssetRequest.java} | 31 ++-- .../asset/model/EdcAssetProperties.java | 42 ----- .../model/EdcCreateDataAssetRequest.java | 39 ----- .../client/asset/model/EdcDataAddress.java | 44 ------ .../asset/model/EdcDataAddressProperties.java | 43 ------ ...JsonObjectFromAssetRequestTransformer.java | 50 ++++++ .../EdcCreateContractDefinitionRequest.java | 2 + .../client/transformer/EdcTransformer.java | 29 +++- .../edc/client/asset/EdcAssetServiceTest.java | 102 +++++++++++++ 10 files changed, 270 insertions(+), 256 deletions(-) rename irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/{EdcAsset.java => AssetRequest.java} (67%) delete mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAssetProperties.java delete mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcCreateDataAssetRequest.java delete mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddress.java delete mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddressProperties.java create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java create mode 100644 irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java index 730d5cd0d5..02c9e4e13f 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -18,27 +18,28 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.asset; -import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.NAMESPACE_EDC; - +import java.util.Map; import java.util.UUID; +import jakarta.json.JsonObject; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; -import org.eclipse.tractusx.irs.edc.client.asset.model.EdcAsset; -import org.eclipse.tractusx.irs.edc.client.asset.model.EdcAssetProperties; -import org.eclipse.tractusx.irs.edc.client.asset.model.EdcContext; -import org.eclipse.tractusx.irs.edc.client.asset.model.EdcCreateDataAssetRequest; -import org.eclipse.tractusx.irs.edc.client.asset.model.EdcDataAddress; import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationMethod; import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationType; import org.eclipse.tractusx.irs.edc.client.asset.model.exception.CreateEdcAssetException; +import org.eclipse.tractusx.irs.edc.client.transformer.EdcTransformer; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @Slf4j +@Service +@RequiredArgsConstructor public class EdcAssetService { private static final String DEFAULT_CONTENT_TYPE = "application/json"; @@ -48,37 +49,37 @@ public class EdcAssetService { // TODO: move to config ? private static final String ASSETS_PATH = "/management/v2/assets"; + EdcTransformer edcTransformer; + public String createNotificationAsset(String baseUrl, String assetName, NotificationMethod notificationMethod, NotificationType notificationType, RestTemplate restTemplate) { - EdcCreateDataAssetRequest request = createNotificationAssetRequest(assetName, baseUrl, notificationMethod, - notificationType); + JsonObject request = createNotificationAssetRequest(assetName, baseUrl, notificationMethod, notificationType); + return sendRequest(request, restTemplate); + } + + public String createDtrAsset(String baseUrl, String assetName, RestTemplate restTemplate) { + JsonObject request = createDtrAssetRequest(assetName, baseUrl); return sendRequest(request, restTemplate); } - private static String sendRequest( final EdcCreateDataAssetRequest request, final RestTemplate restTemplate) { - final String assetId = request.getAsset().getAssetId(); - final String assetName = request.getAsset().getEdcAssetProperties().getAssetName(); + private String sendRequest(final JsonObject request, final RestTemplate restTemplate) { final ResponseEntity createEdcDataAssetResponse; try { createEdcDataAssetResponse = restTemplate.postForEntity(ASSETS_PATH, request, String.class); HttpStatusCode responseCode = createEdcDataAssetResponse.getStatusCode(); if (responseCode.value() == 409) { - log.info("{} asset already exists in the EDC", assetId); - return assetId; + log.info("{} asset already exists in the EDC", getAssetId(request)); + return getAssetId(request); } if (responseCode.value() == 200) { - return assetId; + return getAssetId(request); } } catch (RestClientException e) { throw new CreateEdcAssetException(e); } - throw new CreateEdcAssetException("Failed to create asset %s".formatted(assetName)); - } - - public String createDtrAsset() { - return ""; + throw new CreateEdcAssetException("Failed to create asset %s".formatted(getAssetId(request))); } public void deleteAsset(String notificationAssetId, RestTemplate restTemplate) { @@ -94,59 +95,64 @@ public void deleteAsset(String notificationAssetId, RestTemplate restTemplate) { } } - private EdcCreateDataAssetRequest createNotificationAssetRequest(String assetName, String baseUrl, + private JsonObject createNotificationAssetRequest(String assetName, String baseUrl, NotificationMethod notificationMethod, NotificationType notificationType) { - String assetId = UUID.randomUUID().toString(); - EdcDataAddress dataAddress = EdcDataAddress.builder() - .type(DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) - .baseUrl(baseUrl) - .method(DEFAULT_METHOD) - .proxyBody("true") - .proxyMethod("true") - .build(); - - EdcAssetProperties assetProperties = EdcAssetProperties.builder() - .assetName(assetName) - .policyId(DEFAULT_POLICY_ID) - .contentType(DEFAULT_CONTENT_TYPE) - .type(notificationType.getValue()) - .notificationType(notificationType.getValue()) - .notificationMethod(notificationMethod.getValue()) - .build(); - - EdcAsset asset = EdcAsset.builder().assetId(assetId).type("Asset").edcAssetProperties(assetProperties).build(); - - EdcContext edcContext = EdcContext.builder().edc(NAMESPACE_EDC).build(); - - return EdcCreateDataAssetRequest.builder().asset(asset).dataAddress(dataAddress).context(edcContext).build(); + Map properties = Map.of( + "description", assetName, + "contenttype", DEFAULT_CONTENT_TYPE, + "policy-id", DEFAULT_POLICY_ID, + "type", notificationType.getValue(), + "notificationtype", notificationType.getValue(), + "notificationmethod", notificationMethod.getValue() + ); + + DataAddress dataAddress = DataAddress.Builder.newInstance() + .type(DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", baseUrl) + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", "true") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", "true") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/method", DEFAULT_METHOD) + .build(); + + Asset asset = Asset.Builder.newInstance() + .id(assetId) + .contentType("Asset") + .properties(properties) + .dataAddress(dataAddress) + .build(); + return edcTransformer.transformAssetToJson(asset); } - // TODO check edc edc for corresponding asset class - private EdcCreateDataAssetRequest createDtrAssetRequest(String assetName, String baseUrl, - NotificationMethod notificationMethod, NotificationType notificationType) { + private JsonObject createDtrAssetRequest(String assetName, String baseUrl){ String assetId = UUID.randomUUID().toString(); - EdcDataAddress dataAddress = EdcDataAddress.builder() - .type(DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) - .baseUrl(baseUrl) - .method(DEFAULT_METHOD) - .proxyBody("true") - .proxyMethod("true") - .build(); - - EdcAssetProperties assetProperties = EdcAssetProperties.builder() - .assetName(assetName) - .policyId(DEFAULT_POLICY_ID) - .contentType(DEFAULT_CONTENT_TYPE) - .type(notificationType.getValue()) - .notificationType(notificationType.getValue()) - .notificationMethod(notificationMethod.getValue()) - .build(); - - EdcAsset asset = EdcAsset.builder().assetId(assetId).type("Asset").edcAssetProperties(assetProperties).build(); - - EdcContext edcContext = EdcContext.builder().edc(NAMESPACE_EDC).build(); - - return EdcCreateDataAssetRequest.builder().asset(asset).dataAddress(dataAddress).context(edcContext).build(); + Map properties = Map.of( + "description", assetName, + "type", "data.core.digitalTwinRegistry" + ); + + DataAddress dataAddress = DataAddress.Builder.newInstance() + .type("DataAddress") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", baseUrl) + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", "true") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", "true") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyPath", "true") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams", "true") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/method", DEFAULT_METHOD) + .build(); + + Asset asset = Asset.Builder.newInstance() + .id(assetId) + .contentType("Asset") + .properties(properties) + .dataAddress(dataAddress) + .build(); + return edcTransformer.transformAssetToJson(asset); + } + + private static String getAssetId(JsonObject jsonObject) { + return jsonObject.get("asset").asJsonObject().get("@id").toString(); } } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAsset.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java similarity index 67% rename from irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAsset.java rename to irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java index eeb0e02513..14194fc38a 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAsset.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -16,25 +17,19 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ + package org.eclipse.tractusx.irs.edc.client.asset.model; -import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; -import lombok.Getter; -import lombok.ToString; - -@ToString -@Getter -@Builder -public class EdcAsset { - - @JsonProperty("@id") - private String assetId; - - @JsonProperty("@type") - private String type; - - @JsonProperty("properties") - private EdcAssetProperties edcAssetProperties; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; +import org.eclipse.edc.spi.types.domain.DataAddress; +import org.eclipse.edc.spi.types.domain.asset.Asset; +@Value +@Builder(toBuilder = true) +@Jacksonized +public class AssetRequest { + Asset asset; + DataAddress dataAddress; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAssetProperties.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAssetProperties.java deleted file mode 100644 index 5a4f0cf7e8..0000000000 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcAssetProperties.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************** - * Copyright (c) 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.asset.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Getter; -import lombok.ToString; - -@ToString -@Getter -@Builder -public class EdcAssetProperties { - @JsonProperty("description") - String assetName; - @JsonProperty("contenttype") - String contentType; - @JsonProperty("policy-id") - String policyId; - @JsonProperty("type") - String type; - @JsonProperty("notificationtype") - String notificationType; - @JsonProperty("notificationmethod") - String notificationMethod; -} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcCreateDataAssetRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcCreateDataAssetRequest.java deleted file mode 100644 index 66a021510c..0000000000 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcCreateDataAssetRequest.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************** - * Copyright (c) 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.asset.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Getter; -import lombok.ToString; - -@ToString -@Getter -@Builder -public class EdcCreateDataAssetRequest { - - @JsonProperty("@context") - private EdcContext context; - - @JsonProperty("asset") - private EdcAsset asset; - - @JsonProperty("dataAddress") - private EdcDataAddress dataAddress; -} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddress.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddress.java deleted file mode 100644 index 2ae31d6d27..0000000000 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddress.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************** - * Copyright (c) 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.asset.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.ToString; - -@ToString -@Builder -public class EdcDataAddress { - - @JsonProperty("type") - private String type; - - @JsonProperty("baseUrl") - private String baseUrl; - - @JsonProperty("proxyMethod") - private String proxyMethod; - - @JsonProperty("proxyBody") - private String proxyBody; - - @JsonProperty("method") - private String method; - -} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddressProperties.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddressProperties.java deleted file mode 100644 index 2ded52c1ec..0000000000 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcDataAddressProperties.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************** - * Copyright (c) 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.asset.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.ToString; - -@ToString -@Builder -public class EdcDataAddressProperties { - - @JsonProperty("baseUrl") - private final String baseUrl; - - @JsonProperty("proxyMethod") - private final String proxyMethod; - - @JsonProperty("method") - private final String method; - - @JsonProperty("proxyBody") - private final String proxyBody; - - @JsonProperty("type") - private final String type; -} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java new file mode 100644 index 0000000000..88026282c8 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java @@ -0,0 +1,50 @@ +/******************************************************************************** + * 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.asset.transformer; + +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import jakarta.json.JsonObjectBuilder; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; +import org.jetbrains.annotations.NotNull; + +public class JsonObjectFromAssetRequestTransformer extends AbstractJsonLdTransformer { + + private final JsonBuilderFactory jsonFactory; + + public JsonObjectFromAssetRequestTransformer(final JsonBuilderFactory jsonFactory, ObjectMapper jsonLdMapper) { + super(AssetRequest.class, JsonObject.class); + this.jsonFactory = jsonFactory; + } + + @Override + public JsonObject transform(@NotNull final AssetRequest assetRequest, @NotNull final TransformerContext context) { + final JsonObjectBuilder builder = this.jsonFactory.createObjectBuilder(); + builder.add("https://w3id.org/edc/v0.0.1/ns/asset", + context.transform(assetRequest.getAsset(), JsonObject.class)); + builder.add("https://w3id.org/edc/v0.0.1/ns/dataAddress", + context.transform(assetRequest.getDataAddress(), JsonObject.class)); + return builder.build(); + } +} \ No newline at end of file diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java index 1c0f1c405f..64d707a2e7 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java @@ -21,6 +21,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; import lombok.ToString; +import org.eclipse.edc.connector.contract.spi.event.contractdefinition.ContractDefinitionCreated; +import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition; import org.eclipse.tractusx.irs.edc.client.asset.model.EdcContext; @ToString diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java index 8e25830fe0..bcaafd3c8a 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java @@ -63,7 +63,10 @@ import org.eclipse.edc.core.transform.transformer.to.JsonValueToGenericTypeTransformer; import org.eclipse.edc.jsonld.TitaniumJsonLd; import org.eclipse.edc.spi.result.Result; +import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; +import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; +import org.eclipse.tractusx.irs.edc.client.asset.transformer.JsonObjectFromAssetRequestTransformer; import org.eclipse.tractusx.irs.edc.client.model.ContractOfferDescription; import org.eclipse.tractusx.irs.edc.client.model.NegotiationRequest; import org.eclipse.tractusx.irs.edc.client.model.TransferProcessRequest; @@ -81,12 +84,23 @@ public class EdcTransformer { private final JsonObjectFromTransferProcessRequestTransformer jsonObjectFromTransferProcessRequestTransformer; private final JsonObjectFromContractOfferDescriptionTransformer jsonObjectFromContractOfferDescriptionTransformer; private final JsonObjectFromCatalogRequestTransformer jsonObjectFromCatalogRequestTransformer; + private final JsonObjectFromAssetTransformer jsonObjectFromAssetTransformer; private final TitaniumJsonLd titaniumJsonLd; private final TransformerContextImpl transformerContext; + private final JsonObjectFromAssetRequestTransformer jsonObjectFromAssetRequestTransformer; public EdcTransformer(@Qualifier("jsonLdObjectMapper") final ObjectMapper objectMapper, final TitaniumJsonLd titaniumJsonLd) { this.titaniumJsonLd = titaniumJsonLd; + this.titaniumJsonLd.registerNamespace("type", "https://w3id.org/edc/v0.0.1/ns/dataAddress/type"); + this.titaniumJsonLd.registerNamespace("baseUrl", "https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl"); + this.titaniumJsonLd.registerNamespace("proxyMethod", "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod"); + this.titaniumJsonLd.registerNamespace("proxyBody", "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody"); + this.titaniumJsonLd.registerNamespace("method", "https://w3id.org/edc/v0.0.1/ns/dataAddress/method"); + this.titaniumJsonLd.registerNamespace("asset", "https://w3id.org/edc/v0.0.1/ns/asset"); + this.titaniumJsonLd.registerNamespace("dataAddress", "https://w3id.org/edc/v0.0.1/ns/dataAddress"); + this.titaniumJsonLd.registerNamespace("proxyPath", "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyPath"); + this.titaniumJsonLd.registerNamespace("proxyQueryParams", "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams"); final JsonBuilderFactory jsonBuilderFactory = Json.createBuilderFactory(Map.of()); jsonObjectFromNegotiationInitiateDtoTransformer = new JsonObjectFromNegotiationInitiateDtoTransformer( @@ -97,6 +111,8 @@ public EdcTransformer(@Qualifier("jsonLdObjectMapper") final ObjectMapper object jsonObjectFromContractOfferDescriptionTransformer = new JsonObjectFromContractOfferDescriptionTransformer( jsonBuilderFactory); jsonObjectFromCatalogRequestTransformer = new JsonObjectFromCatalogRequestTransformer(jsonBuilderFactory); + jsonObjectFromAssetTransformer = new JsonObjectFromAssetTransformer(jsonBuilderFactory, objectMapper); + jsonObjectFromAssetRequestTransformer = new JsonObjectFromAssetRequestTransformer(jsonBuilderFactory, objectMapper); final TypeTransformerRegistry typeTransformerRegistry = new TypeTransformerRegistryImpl(); transformerContext = new TransformerContextImpl(typeTransformerRegistry); @@ -128,9 +144,10 @@ public EdcTransformer(@Qualifier("jsonLdObjectMapper") final ObjectMapper object typeTransformerRegistry.register(new JsonObjectFromPolicyTransformer(jsonBuilderFactory)); typeTransformerRegistry.register(new JsonObjectFromDistributionTransformer(jsonBuilderFactory)); typeTransformerRegistry.register(new JsonObjectFromDataServiceTransformer(jsonBuilderFactory)); - typeTransformerRegistry.register(new JsonObjectFromAssetTransformer(jsonBuilderFactory, objectMapper)); + typeTransformerRegistry.register(jsonObjectFromAssetTransformer); typeTransformerRegistry.register(new JsonObjectFromCriterionTransformer(jsonBuilderFactory, objectMapper)); typeTransformerRegistry.register(new JsonObjectFromDataAddressTransformer(jsonBuilderFactory)); + typeTransformerRegistry.register(jsonObjectFromAssetRequestTransformer); } public Catalog transformCatalog(final String jsonString, final Charset charset) { @@ -167,4 +184,14 @@ public JsonObject transformCatalogRequestToJson(final CatalogRequest catalogRequ transformerContext); return titaniumJsonLd.compact(transform).asOptional().orElseThrow(); } + + public JsonObject transformAssetToJson(Asset asset) { + final JsonObject transform = jsonObjectFromAssetTransformer.transform(asset, transformerContext); + return titaniumJsonLd.compact(transform).asOptional().orElseThrow(); + } + + public JsonObject transformAssetRequestToJson(AssetRequest assetRequest) { + final JsonObject transform = jsonObjectFromAssetRequestTransformer.transform(assetRequest, transformerContext); + return titaniumJsonLd.compact(transform).asOptional().orElseThrow(); + } } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java new file mode 100644 index 0000000000..7c306b2b25 --- /dev/null +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java @@ -0,0 +1,102 @@ +/******************************************************************************** + * 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.asset; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Map; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.fasterxml.jackson.datatype.jsonp.JSONPModule; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import jakarta.json.JsonObject; +import org.eclipse.edc.jsonld.TitaniumJsonLd; +import org.eclipse.edc.policy.model.AtomicConstraint; +import org.eclipse.edc.policy.model.LiteralExpression; +import org.eclipse.edc.spi.monitor.ConsoleMonitor; +import org.eclipse.edc.spi.types.domain.DataAddress; +import org.eclipse.edc.spi.types.domain.asset.Asset; +import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; +import org.eclipse.tractusx.irs.edc.client.transformer.EdcTransformer; +import org.junit.jupiter.api.Test; + +class EdcAssetServiceTest { + + @Test + void test() { + TitaniumJsonLd jsonLd = new TitaniumJsonLd(new ConsoleMonitor()); + jsonLd.registerNamespace("odrl", "http://www.w3.org/ns/odrl/2/"); + jsonLd.registerNamespace("dct", "https://purl.org/dc/terms/"); + jsonLd.registerNamespace("tx", "https://w3id.org/tractusx/v0.0.1/ns/"); + jsonLd.registerNamespace("edc", "https://w3id.org/edc/v0.0.1/ns/"); + jsonLd.registerNamespace("dcat", "https://www.w3.org/ns/dcat/"); + jsonLd.registerNamespace("dspace", "https://w3id.org/dspace/v0.8/"); + + // jsonLd.registerNamespace("type", "https://w3id.org/edc/v0.0.1/ns/dataAddress/type"); + // jsonLd.registerNamespace("baseUrl", "https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl"); + // jsonLd.registerNamespace("proxyMethod", "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod"); + // jsonLd.registerNamespace("proxyBody", "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody"); + // jsonLd.registerNamespace("method", "https://w3id.org/edc/v0.0.1/ns/dataAddress/method"); + // jsonLd.registerNamespace("asset", "https://w3id.org/edc/v0.0.1/ns/asset"); + // jsonLd.registerNamespace("dataAddress", "https://w3id.org/edc/v0.0.1/ns/dataAddress"); + + EdcTransformer edcTransformer = new EdcTransformer(objectMapper(), jsonLd); + + Map properties = Map.of("description", "endpoint to qualityinvestigation receive", + "contenttype", "application/json", "policy-id", "use-eu", "type", "receive", "notificationtype", + "qualityinvestigation", "notificationmethod", "receive"); + + DataAddress dataAddress = DataAddress.Builder.newInstance() + .type("DEFAULT_DATA_ADDRESS_PROPERTY_TYPE") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", + "HttpData") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", + "https://traceability.dev.demo.catena-x.net/api/qualitynotifications/receive") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", + "true") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", + "true") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/method", + "POST") + .build(); + + Asset asset = Asset.Builder.newInstance().id("Asset1").contentType("Asset").properties(properties).build(); + + JsonObject jsonObject = edcTransformer.transformAssetRequestToJson( + AssetRequest.builder().asset(asset).dataAddress(dataAddress).build()); + + assertThat(jsonObject).isNotNull(); + } + + ObjectMapper objectMapper() { + final ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); + objectMapper.registerModule(new Jdk8Module()); + objectMapper.registerModule(new JSONPModule()); + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.registerSubtypes(AtomicConstraint.class, LiteralExpression.class); + return objectMapper; + } + +} \ No newline at end of file From bd622a7819d6aac43ffc977cb84ecd9a46ac61f2 Mon Sep 17 00:00:00 2001 From: mk Date: Wed, 31 Jan 2024 20:22:14 +0100 Subject: [PATCH 04/55] chore(concept):[#367] adjust irs to industry core standard --- CHANGELOG.md | 1 + .../#367-adapt-to-changes-industry-core.md | 186 ++++++++++++------ 2 files changed, 132 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 458cdcad76..213b5d8008 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added helper script for building documentation locally. +- Added concept to conform with IndustryCore Changes CX-0126 and CX-127 ### Changed - Updated license header to "Copyright (c) 2021,2024 Contributors to the Eclipse Foundation" diff --git a/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md b/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md index 05780c5e00..912cce9ef7 100644 --- a/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md +++ b/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md @@ -9,26 +9,11 @@ # Table of Contents 1. [Overview](#overview) -2. [Summary](#summary) -3. [Problem Statement](#problem-statement) -4. [Requirements](#requirements) -5. [NFR](#nfr) -6. [Out of scope](#out-of-scope) -7. [Assumptions](#assumptions) -8. [Definition of the Industry Core](#definition-of-the-industry-core) -9. [Glossary](#glossary) -10. [References](#references) -11. [Additional Details](#additional-details) - -# TODO -- TODO: globalAssetId of the twins being referenced MUST be equal to the unique ID being used in Catena-X. -- [ ] AAS manufacturerId is mandatory [Add AC to PBI] -- [ ] manufacturerPartId is mandatory [Add AC to PBI] -- [ ] customerPartId is optional [Add AC to PBI] -- [ ] assetLifecyclePhase optional for asBuilt and mandatory for asPlanned [Add AC to PBI] -- [ ] digitalTwinType mandatory > filter for digitalTwinType="PartType" or "PartInstance" [Add AC to PBI] -- [ ] SerialParts: Add optional van number for [Add AC to PBI] -- [ ] SerialParts: partInstanceId is mandatory [Add AC to PBI] +2. [Problem Statement](#problem-statement) +3. [Concept](#concept) +4. [Definition of the Industry Core](#definition-of-the-industry-core) +5. [Glossary](#glossary) +6. [References](#references) # Overview @@ -46,20 +31,90 @@ Notification base message exchange. 3. Facilitate Data Chains 4. Configuration for Enablement Services 5. Components-Based Data Exchange -The core enables the sending of notifications, indicating that there's a mechanism for alerting or informing relevant parties about specific events or changes within the system. - -# Summary + The core enables the sending of notifications, indicating that there's a mechanism for alerting or informing relevant parties about specific events or changes within the system. # Problem Statement +The product IRS MUST align with the Industry Code Standard CX-126 and CX-127. + +# Concept + +## Version matrix + +|Artefact| Version | Availability | link | +|---|---------|-----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------| +| AAS | | | | +| PartAsPlanned | 1.0.1 | Mandatory | [PartAsPlanned 1.0.1](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.part_as_planned/1.0.1) | +|PartAsPlanned | 2.0.0 | Optional (Mandatory for next version of CX-0126) | [PartAsPlanned 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.part_as_planned/2.0.0) | +| SingleLevelBomAsPlanned| 1.1.0 | Mandatory | [SingleLevelBomAsPlanned 1.1.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_planned/1.1.0)] | +| SingleLevelBomAsPlanned| 2.0.0 | Optional (Mandatory for next version of CX-0126) | [SingleLevelBomAsPlanned 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_planned/2.2.0)] | +| SerialPart| 1.0.1 | Mandatory | [SerialPart 1.0.1](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.serial_part/1.0.1) | +| SerialPart| 2.0.0 | Optional | [SerialPart 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.serial_part/2.0.0) | +| Batch| 2.0.0 | Mandatory | [Batch 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.batch/2.0.0) | +| Batch| 2.0.1 | Optional | [Batch 2.0.1](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.batch/2.0.1) | +| JustInSequencePart| 2.0.0 | Optional | [JustInSequencePart 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.just_in_sequence_part/2.0.0) | +| SingleLevelBomAsBuilt| 2.0.0 | Mandatory | [SingleLevelBomAsBuilt 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_built/2.0.0) | +| PartSiteInformationAsBuilt| 1.0.0 | Integrated in Aspects JustInSequencePart / Batch / SerialPart | https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.shared.part_site_information_as_built/1.0.0 | + + +- JustInSequencePart: https://github.com/eclipse-tractusx/sldt-semantic-models/pull/563 +- Batch : https://github.com/eclipse-tractusx/sldt-semantic-models/pull/562 +- SerialPart: https://github.com/eclipse-tractusx/sldt-semantic-models/pull/557 + +## Changes in AAS handling + +### AAS Parameter + +|Parameter | Availability version aas 3.0.0 / 3.1.0 | Availability version aas 3.x.x | +|----|---|--| +|manufacturerId | Mandatory | Mandatory | +|manufacturerPartId | Mandatory | Mandatory | +|customerPartId | Optional | Optional | + + +### Descope @Deprecated assetLifecyclePhase +For serialized parts, batches, and JIS parts this will be deprecated with new version 3.x.x of AAS. +ASS parameter assetLifecyclePhase will not be used anymore to detect BOMLifecycle. Parameter 'digitalTwinType' is used instead. -# Requirements +### Use parameter 'digitalTwinType' to detect BOMLifecycle +**Parameter 'digitalTwinType'** -# NFR +| Key |Value| Description | +|--------------|---|-------------------------------------------------------------------------------------------------------| +| Name | digitalTwinType | Name of paramter in AAS | +| Availability | Mandatory | Parameter is mandatory - adjust required checks - Add exception handling in case parameter is not set | +| Values | PartType / PartInstance | PartType= asPlanned parts / PartInstance == parts on an instance level (e.g. serialized parts, batches, and JIS parts) | -# Out of scope +#### Configuration of parameter 'digitalTwinType' +Parameter is configurable for dDTR instance and has to be configured for integration test. -# Assumptions +https://github.com/eclipse-tractusx/sldt-digital-twin-registry/blob/f438fe96a7ae1f1b920e8e4fb4114fb7af32643d/charts/registry/values.yaml#L51 +https://github.com/eclipse-tractusx/sldt-digital-twin-registry/blob/f438fe96a7ae1f1b920e8e4fb4114fb7af32643d/charts/registry/README.md#:~:text=externalSubjectIdWildcardAllowedTypes + +### Visbility of Specific Asset IDs in the DTR +* Usage of parameter 'externalSubjectIds' which contains 'specificAssetIds'. Parameter 'externalSubjectIds' restricts visibility exclusively to manufacturer. + +## Semantic Models + +### SerialPart +|Parameter | Availability | +|----|------------------| +|partInstanceId | Mandatory | +|van | Optional | + +### Batch +|Parameter | Availability | +|----|------------------| +|partInstanceId | Mandatory | +|batchId | Optional | + +### JiS +|Parameter | Availability | +|----|------------------| +|jisNumber | Mandatory | +|parentOrderNumber | Optional | +|jisCallDate | Optional | +|partInstanceId | Mandatory | # Definition of the Industry Core @@ -67,14 +122,16 @@ The core enables the sending of notifications, indicating that there's a mechani ## Standards to be complied with -| Fullfilled | Standard | Description | -|------------|--------------------------------------------------|---------------------------------------------------------------------------------| -| [x] | CX-0002 Digital Twins in Catena-X 2.2.0 | Trace-Xs notification process and consumption of assets is bases on DT standards | -| [x] | CX-0018 Eclipse Data Space Connector (EDC) 2.1.0 | Data consumption and data provision as well as the sending and receiving of messages takes place exclusively via the EDC | - - -- [x] -CX-0018 Eclipse Data Space Connector (EDC) 2.1.0 +| Fulfilled | Standard | Description | +|-----------|-------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [x] | CX-0001 EDC DISCOVERY API 1.0.2 | IRS uses irs_edc_client library for EDC communication this uses the EDC discovery service for EDC resolution | | +| [x] | CX-0002 Digital Twins in Catena-X 2.2.0 | IRS notification process and consumption of assets is bases on DT standards | +| [x] | CX-0003 SAMM Aspect Meta Model 1.1.0 | IRS using Semantic Models using SAMM standard | | +| [x] | CX-0018 Eclipse Data Space Connector (EDC) 2.1.0 | Data consumption and data provision as well as the sending and receiving of messages takes place exclusively via the EDC | +| [x] | CX-0019 Aspect Model SerialPart | The semantic model SerialPart describes a submodel for a digital twin of a serialised part providing essential information about this part | +| [x] | CX-0020 Aspect Model SingleLevelBomAsBuilt | The Industry Core: Part Instance aims on building product genealogy information throughout the supply chain. Therefore it is required to link a produced part with its predecessor items. | +| [x] | CX-0021 Aspect Model: Batch | A batch is a quantity of (semi-) finished products or (raw) material product that have been produced under the same circumstances (e.g., same production location), as specified groups or amounts, within a certain time frame. | +| [x] | CX-0060 Triangle Traceability - Digital Twin As-Built | Digital Twin As-Built | ## Describe Part at type and instance level @@ -87,27 +144,46 @@ CX-0018 Eclipse Data Space Connector (EDC) 2.1.0 |Instance Level | SingleLevelBomAsBuilt| RBuilts relationsship between parts in downwards direction (customer > supplier) | CX-0020 Aspect Model | | Instance Level | PartSiteInformationAsBuilt | (shared aspect) | | -# Changes in AAS -| Key | Availability | Description | -|------------|------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| manufacturerId | Mandatory | The Business Partner Number (BPNL) of the manufacturer of the part. | -|manufacturerPartId | Mandatory | | -|customerPartId | Optional | | -|assetLifecyclePhase | asPlanned(Mandatory) / asBuilt(Optional) | @Deprecated For serialized parts, batches, and JIS parts, use the value AsBuilt. For catalog parts in a Digital Twin As-Planned lifecycle phase, use the value AsPlanned. | -|digitalTwinType | Mandatory | digitalTwinType="PartType" OR digitalTwinType="PartInstance" For parts on an instance level (e.g. serialized parts, batches, and JIS parts), use the value PartInstance. For parts on a part type level (e.g. catalog parts), use the value PartType. | | | - -# Changes in SerialPart -| Key | Availability | Description | -|------------|------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| partInstanceId | Mandatory | | -| van | Optioonal | | +# Changes in AAS +| Key | Availability | Description | +|------------|------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +|manufacturerId | Mandatory | The Business Partner Number (BPNL) of the manufacturer of the part. | +|manufacturerPartId | Mandatory | | +|customerPartId | Optional | | +|assetLifecyclePhase | asPlanned(Mandatory) / asBuilt(Optional) | @Deprecated For serialized parts, batches, and JIS parts, use the value AsBuilt. For catalog parts in a Digital Twin As-Planned lifecycle phase, use the value AsPlanned. | +|digitalTwinType | Mandatory | digitalTwinType="PartType" OR digitalTwinType="PartInstance" For parts on an instance level (e.g. serialized parts, batches, and JIS parts), use the value PartInstance. For parts on a part type level (e.g. catalog parts), use the value PartType. | | | + +# PartAsPlanned + +- No changes +- Version 1.0.1 Mandatory + +# SerialPart +| Key | Availability | Description | +|------------|-----------------------------------------|------------------------------------------------------| +| partInstanceId | Mandatory | The serial number of the part from the manufacturer. | +| van | Optional | Only for vehicles: The pseudonymized vehicle identification number (VIN) of the vehicle. | + +# Batch +| Key | Availability | Description | +|------------|-----------------------------------------|-----------------------------------------------------| +| batchId | Optional | The number of the batch from the manufacturer. | +| partInstanceId | Mandatory | Also the number of the batch from the manufacturer. For the time being we also use the batch number as partInstanceId. This makes looking up digital twins for serialized parts and batches easier as a data consumer only has to specify the partInstanceId no matter if they are looking up a serialized part or a batch. Otherwise, the data consumer would need to know for what type of digital twin it is looking for or it would have to look for both until a match is found. | + +### JiS +|Parameter | Availability |Description | +|----|------------------|----------------------------------------------------| +|jisNumber | Mandatory | A number that is used to identify the call-off that can be assumed unique within the specific just-in-sequence process. This is typically not the sequence number, but the call-off number.| +|parentOrderNumber | Optional |A number identifying the just-in-sequence- part's destination parent part. The parent part is typically known upfront to the supplier for just-in-sequence parts.| +|jisCallDate | Optional |The date of the just-in-sequence call-off as stated on the call-off document itself.The value must be compliant to ISO 8601: YYYY-MM-DD or YYYY-MM-DDThh:mm:ss or YYYY-MM-DDThh:mm:ss±hh:mm| +|partInstanceId | Mandatory |A composition of jisNumber, parentOrderNumber (if available), jisCallDate (ifavailable). This information is typically known upfront to the supplier jisNumber, partOrderNumber and jisCallDate for just-in-sequence parts.| ## Discoverable in the network - [ ] re-definition if the "specific asset ids" -## Enable traversing across serveral tier levels +## Enable traversing across several tier levels - Industry Core aspect models - DataChain KIT @@ -129,11 +205,11 @@ CX-0018 Eclipse Data Space Connector (EDC) 2.1.0 | ECU | Electronic Control Unit | An ECU's main job is to keep the engine working smoothly | | JIS | Just In Sequence | Just-in-sequence is a delivery concept where parts are delivered to the production plant at a requested time in the exact order of installation, typically for a 1:1 dependency on the manufactured product. A just-in-sequence-part is a part for which this concept and order of delivery applies and which does not have a dedicated serial number (then it would be considered a serialized part). Examples for JIS-parts are seats and bumpers. | | BPN | Business Partner Number | A BPN is the unique identifier of a partner within Catena-x. | -| |Part Instance|A part instance is a physically produced instance (e.g. serialized part, batch, just-in-sequence-part) of a part type. | -| |Part Type| A part type is a generic (not physically produced) part on material- or catalog-level as a representation for a designed part.| -| VAN | Vehicle Anonymised Number | A number mapped 1:1 to VIN, but pseudonomised.| +| Part Instance|A part instance is a physically produced instance (e.g. serialized part, batch, just-in-sequence-part) of a part type. | +| Part Type| A part type is a generic (not physically produced) part on material- or catalog-level as a representation for a designed part.| +| VAN | Vehicle Anonymised Number | A number mapped 1:1 to VIN, but pseudonomised.| # References +- [CX-0126 Industry Core Part Type Standard 1.0.0](https://github.com/catenax-eV/product-standardization-prod/blob/CX-0126-IndustryCorePartType-v1.0.0/standards/CX-0126-IndustryCorePartType/1.0.0/CX-0126-Industry-Core-Part-Type.pdf) +- [CX-0126 Industry Core Part Instance Standard 1.0.0](https://github.com/catenax-eV/product-standardization-prod/blob/CX-0127-IndustryCorePartInstance-v1.0.0/standards/CX-0127-IndustryCorePartInstance/1.0.0/CX%20-%200127%20Industry%20Core%20Part%20Instance%201.0.0.pdf) -# Additional Details -Given the dynamic nature of ongoing development, there might be variations between the conceptualization and the current implementation. For the latest status, refer to the documentation. From 33733c1d272dad160e2c95a77e0e88daeb23a591 Mon Sep 17 00:00:00 2001 From: mk Date: Thu, 1 Feb 2024 08:14:13 +0100 Subject: [PATCH 05/55] chore(concept):[#367] add Detect Lifecycle in AAS --- .../#367-adapt-to-changes-industry-core.md | 66 ++++++++++++++----- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md b/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md index 912cce9ef7..e599cda964 100644 --- a/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md +++ b/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md @@ -40,20 +40,20 @@ The product IRS MUST align with the Industry Code Standard CX-126 and CX-127. ## Version matrix -|Artefact| Version | Availability | link | -|---|---------|-----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------| -| AAS | | | | -| PartAsPlanned | 1.0.1 | Mandatory | [PartAsPlanned 1.0.1](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.part_as_planned/1.0.1) | -|PartAsPlanned | 2.0.0 | Optional (Mandatory for next version of CX-0126) | [PartAsPlanned 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.part_as_planned/2.0.0) | -| SingleLevelBomAsPlanned| 1.1.0 | Mandatory | [SingleLevelBomAsPlanned 1.1.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_planned/1.1.0)] | -| SingleLevelBomAsPlanned| 2.0.0 | Optional (Mandatory for next version of CX-0126) | [SingleLevelBomAsPlanned 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_planned/2.2.0)] | -| SerialPart| 1.0.1 | Mandatory | [SerialPart 1.0.1](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.serial_part/1.0.1) | -| SerialPart| 2.0.0 | Optional | [SerialPart 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.serial_part/2.0.0) | -| Batch| 2.0.0 | Mandatory | [Batch 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.batch/2.0.0) | -| Batch| 2.0.1 | Optional | [Batch 2.0.1](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.batch/2.0.1) | -| JustInSequencePart| 2.0.0 | Optional | [JustInSequencePart 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.just_in_sequence_part/2.0.0) | -| SingleLevelBomAsBuilt| 2.0.0 | Mandatory | [SingleLevelBomAsBuilt 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_built/2.0.0) | -| PartSiteInformationAsBuilt| 1.0.0 | Integrated in Aspects JustInSequencePart / Batch / SerialPart | https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.shared.part_site_information_as_built/1.0.0 | +| Artefact | Version | Availability | link | +|----------------------------|---------|-----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------| +| AAS | | | | +| PartAsPlanned | 1.0.1 | Mandatory | [PartAsPlanned 1.0.1](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.part_as_planned/1.0.1) | +| PartAsPlanned | 2.0.0 | Optional (Mandatory for next version of CX-0126) | [PartAsPlanned 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.part_as_planned/2.0.0) | +| SingleLevelBomAsPlanned | 1.1.0 | Mandatory | [SingleLevelBomAsPlanned 1.1.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_planned/1.1.0)] | +| SingleLevelBomAsPlanned | 2.0.0 | Optional (Mandatory for next version of CX-0126) | [SingleLevelBomAsPlanned 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_planned/2.2.0)] | +| SerialPart | 1.0.1 | Mandatory | [SerialPart 1.0.1](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.serial_part/1.0.1) | +| SerialPart | 2.0.0 | Optional | [SerialPart 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.serial_part/2.0.0) | +| Batch | 2.0.0 | Mandatory | [Batch 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.batch/2.0.0) | +| Batch | 2.0.1 | Optional | [Batch 2.0.1](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.batch/2.0.1) | +| JustInSequencePart | 2.0.0 | Optional | [JustInSequencePart 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.just_in_sequence_part/2.0.0) | +| SingleLevelBomAsBuilt | 2.0.0 | Mandatory | [SingleLevelBomAsBuilt 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_built/2.0.0) | +| PartSiteInformationAsBuilt | 1.0.0 | Integrated in Aspects JustInSequencePart / Batch / SerialPart | https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.shared.part_site_information_as_built/1.0.0 | - JustInSequencePart: https://github.com/eclipse-tractusx/sldt-semantic-models/pull/563 @@ -85,13 +85,45 @@ ASS parameter assetLifecyclePhase will not be used anymore to detect BOMLifecycl | Availability | Mandatory | Parameter is mandatory - adjust required checks - Add exception handling in case parameter is not set | | Values | PartType / PartInstance | PartType= asPlanned parts / PartInstance == parts on an instance level (e.g. serialized parts, batches, and JIS parts) | + +#### Detect Lifecycle in AAS + +````mermaid + +sequenceDiagram + %%{init: {'theme': 'dark', 'themeVariables': { 'fontSize': '15px'}}}%% + autonumber + IRS ->> BOMLifecycleDetector : detectBOMLifecycleInAASBOMLifecycleDetector ->> BOMLifecycleDetector : digitalTwinType +alt aas contains 'digitalTwinType' + alt digitalTwinType="PartType" + BOMLifecycleDetector -->> IRS : return asPlanned + else digitalTwinType="PartInstance" + BOMLifecycleDetector -->> IRS : return asBuilt + else digitalTwinType any other value or null + BOMLifecycleDetector -->> IRS : throw Exception + end +else aas contains 'assetLifecyclePhase' + alt assetLifecyclePhase="AsBuilt" + BOMLifecycleDetector -->> IRS : return asBuilt + else assetLifecyclePhase="AsPlanned" + BOMLifecycleDetector -->> IRS : return asPlanned + else assetLifecyclePhase any other value or null + BOMLifecycleDetector -->> IRS : throw Exception + end +else + IRS -->> BOMLifecycleDetector : throw Exception (BOMLifecylce could not be detected) + BOMLifecycleDetector -->> IRS : retrun BOMLifecyle +end + +```` + #### Configuration of parameter 'digitalTwinType' Parameter is configurable for dDTR instance and has to be configured for integration test. -https://github.com/eclipse-tractusx/sldt-digital-twin-registry/blob/f438fe96a7ae1f1b920e8e4fb4114fb7af32643d/charts/registry/values.yaml#L51 -https://github.com/eclipse-tractusx/sldt-digital-twin-registry/blob/f438fe96a7ae1f1b920e8e4fb4114fb7af32643d/charts/registry/README.md#:~:text=externalSubjectIdWildcardAllowedTypes +- [Values.yaml](https://github.com/eclipse-tractusx/sldt-digital-twin-registry/blob/f438fe96a7ae1f1b920e8e4fb4114fb7af32643d/charts/registry/values.yaml#L51) +- [README.md](https://github.com/eclipse-tractusx/sldt-digital-twin-registry/blob/f438fe96a7ae1f1b920e8e4fb4114fb7af32643d/charts/registry/README.md#:~:text=externalSubjectIdWildcardAllowedTypes) -### Visbility of Specific Asset IDs in the DTR +### Visibility of Specific Asset IDs in the DTR * Usage of parameter 'externalSubjectIds' which contains 'specificAssetIds'. Parameter 'externalSubjectIds' restricts visibility exclusively to manufacturer. ## Semantic Models From d167cac3c4ae47f1fe3ec7dfa177b8863cbe9bd3 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Thu, 1 Feb 2024 13:48:44 +0100 Subject: [PATCH 06/55] feature(irs-edc-client): #412 check policy and contract required configs and adjust code add tests --- irs-edc-client/pom.xml | 6 ++ .../irs/edc/client/asset/EdcAssetService.java | 5 +- .../service/EdcContractDefinitionService.java | 7 +- .../service/EdcPolicyDefinitionService.java | 13 ++- .../edc/client/asset/EdcAssetServiceTest.java | 56 ++++++++++--- .../EdcContractDefinitionServiceTest.java | 77 +++++++++++++++++ .../EdcPolicyDefinitionServiceTest.java | 83 +++++++++++++++++++ pom.xml | 1 + 8 files changed, 225 insertions(+), 23 deletions(-) create mode 100644 irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java create mode 100644 irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java diff --git a/irs-edc-client/pom.xml b/irs-edc-client/pom.xml index 10d3049c1e..6455b8efbf 100644 --- a/irs-edc-client/pom.xml +++ b/irs-edc-client/pom.xml @@ -225,6 +225,12 @@ ${awaitility.version} test + + org.skyscreamer + jsonassert + ${jsonassert.version} + test + diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java index 02c9e4e13f..eb2f3b08a7 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -46,7 +46,6 @@ public class EdcAssetService { private static final String DEFAULT_POLICY_ID = "use-eu"; private static final String DEFAULT_METHOD = "POST"; private static final String DEFAULT_DATA_ADDRESS_PROPERTY_TYPE = "HttpData"; - // TODO: move to config ? private static final String ASSETS_PATH = "/management/v2/assets"; EdcTransformer edcTransformer; @@ -153,6 +152,8 @@ private JsonObject createDtrAssetRequest(String assetName, String baseUrl){ } private static String getAssetId(JsonObject jsonObject) { - return jsonObject.get("asset").asJsonObject().get("@id").toString(); + return jsonObject.get("asset") + .asJsonObject() + .get("@id").toString(); } } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java index b7e805ca4e..84d6ecb68d 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java @@ -20,8 +20,9 @@ import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.NAMESPACE_EDC; +import java.util.UUID; + import lombok.extern.slf4j.Slf4j; -import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.tractusx.irs.edc.client.asset.model.EdcContext; import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractDefinitionCriteria; import org.eclipse.tractusx.irs.edc.client.contract.model.EdcCreateContractDefinitionRequest; @@ -73,14 +74,14 @@ public String createContractDefinition(String assetId, String policyId, RestTemp } - private static EdcCreateContractDefinitionRequest createContractDefinitionRequest(final String notificationAssetId, + public EdcCreateContractDefinitionRequest createContractDefinitionRequest(final String assetId, final String accessPolicyId) { EdcContractDefinitionCriteria edcContractDefinitionCriteria = EdcContractDefinitionCriteria.builder() .type(ASSET_SELECTOR_TYPE) .operandLeft( ASSET_SELECTOR_ID) .operandRight( - notificationAssetId) + assetId) .operator( ASSET_SELECTOR_EQUALITY_OPERATOR) .build(); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index 8080ab354b..b86c909151 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -50,9 +50,9 @@ public class EdcPolicyDefinitionService { private static final String POLICY_DEFINITION_PATH = "/management/v2/policydefinitions"; - public String createAccessPolicy(RestTemplate restTemplate) { - - final EdcCreatePolicyDefinitionRequest request = createPolicyDefinition(); + public String createAccessPolicy(String policyName, RestTemplate restTemplate) { + String accessPolicyId = UUID.randomUUID().toString(); + final EdcCreatePolicyDefinitionRequest request = createPolicyDefinition(policyName, accessPolicyId); final ResponseEntity createPolicyDefinitionResponse; try { @@ -78,12 +78,12 @@ public String createAccessPolicy(RestTemplate restTemplate) { throw new CreateEdcPolicyDefinitionException("Failed to create EDC policy definition for asset"); } - private EdcCreatePolicyDefinitionRequest createPolicyDefinition() { + public EdcCreatePolicyDefinitionRequest createPolicyDefinition(String policyName, String accessPolicyId) { EdcPolicyPermissionConstraintExpression constraint = EdcPolicyPermissionConstraintExpression.builder() .leftOperand( - "PURPOSE") // configurable ? parameter ? + "PURPOSE") .rightOperand( - "ID 3.0 Trace") // parameter + policyName) .operator( new EdcOperator( OPERATOR_PREFIX @@ -105,7 +105,6 @@ private EdcCreatePolicyDefinitionRequest createPolicyDefinition() { EdcPolicy edcPolicy = EdcPolicy.builder().odrlPermissions(List.of(odrlPermissions)).type(POLICY_TYPE).build(); - String accessPolicyId = UUID.randomUUID().toString(); OdrlContext odrlContext = OdrlContext.builder().odrl(NAMESPACE_ODRL).build(); return EdcCreatePolicyDefinitionRequest.builder() diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java index 7c306b2b25..83a2e783c6 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java @@ -19,7 +19,6 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.asset; -import static org.assertj.core.api.Assertions.assertThat; import java.util.Map; @@ -38,12 +37,14 @@ import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; import org.eclipse.tractusx.irs.edc.client.transformer.EdcTransformer; +import org.json.JSONException; import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; class EdcAssetServiceTest { @Test - void test() { + void testAssetCreateRequestStructure() throws JSONException { TitaniumJsonLd jsonLd = new TitaniumJsonLd(new ConsoleMonitor()); jsonLd.registerNamespace("odrl", "http://www.w3.org/ns/odrl/2/"); jsonLd.registerNamespace("dct", "https://purl.org/dc/terms/"); @@ -52,14 +53,6 @@ void test() { jsonLd.registerNamespace("dcat", "https://www.w3.org/ns/dcat/"); jsonLd.registerNamespace("dspace", "https://w3id.org/dspace/v0.8/"); - // jsonLd.registerNamespace("type", "https://w3id.org/edc/v0.0.1/ns/dataAddress/type"); - // jsonLd.registerNamespace("baseUrl", "https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl"); - // jsonLd.registerNamespace("proxyMethod", "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod"); - // jsonLd.registerNamespace("proxyBody", "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody"); - // jsonLd.registerNamespace("method", "https://w3id.org/edc/v0.0.1/ns/dataAddress/method"); - // jsonLd.registerNamespace("asset", "https://w3id.org/edc/v0.0.1/ns/asset"); - // jsonLd.registerNamespace("dataAddress", "https://w3id.org/edc/v0.0.1/ns/dataAddress"); - EdcTransformer edcTransformer = new EdcTransformer(objectMapper(), jsonLd); Map properties = Map.of("description", "endpoint to qualityinvestigation receive", @@ -85,7 +78,48 @@ void test() { JsonObject jsonObject = edcTransformer.transformAssetRequestToJson( AssetRequest.builder().asset(asset).dataAddress(dataAddress).build()); - assertThat(jsonObject).isNotNull(); + JSONAssert.assertEquals( + jsonObject.toString(), + """ + { + "asset": { + "@id": "Asset1", + "@type": "edc:Asset", + "edc:properties": { + "edc:id": "Asset1", + "edc:contenttype": "Asset" + } + }, + "dataAddress": { + "@type": "edc:DataAddress", + "type": "HttpData", + "proxyBody": "true", + "edc:type": "DEFAULT_DATA_ADDRESS_PROPERTY_TYPE", + "baseUrl": "https://traceability.dev.demo.catena-x.net/api/qualitynotifications/receive", + "method": "POST", + "proxyMethod": "true" + }, + "@context": { + "tx": "https://w3id.org/tractusx/v0.0.1/ns/", + "method": "https://w3id.org/edc/v0.0.1/ns/dataAddress/method", + "dataAddress": "https://w3id.org/edc/v0.0.1/ns/dataAddress", + "edc": "https://w3id.org/edc/v0.0.1/ns/", + "proxyQueryParams": "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams", + "proxyBody": "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", + "type": "https://w3id.org/edc/v0.0.1/ns/dataAddress/type", + "proxyPath": "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyPath", + "dspace": "https://w3id.org/dspace/v0.8/", + "baseUrl": "https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", + "dct": "https://purl.org/dc/terms/", + "proxyMethod": "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", + "odrl": "http://www.w3.org/ns/odrl/2/", + "dcat": "https://www.w3.org/ns/dcat/", + "asset": "https://w3id.org/edc/v0.0.1/ns/asset" + } + } + """, + false + ); } ObjectMapper objectMapper() { diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java new file mode 100644 index 0000000000..27d21cd856 --- /dev/null +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java @@ -0,0 +1,77 @@ +/******************************************************************************** + * 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.contract.service; + +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcCreateContractDefinitionRequest; +import org.json.JSONException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.skyscreamer.jsonassert.JSONAssert; +import org.springframework.web.client.RestTemplate; +import org.testcontainers.shaded.com.fasterxml.jackson.core.JsonProcessingException; +import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; + +@ExtendWith(MockitoExtension.class) +class EdcContractDefinitionServiceTest { + + @Mock + private RestTemplate restTemplate; + private ObjectMapper objectMapper; + private EdcContractDefinitionService service; + + @BeforeEach + void setUp() { + this.objectMapper = new ObjectMapper(); + this.service = new EdcContractDefinitionService(); + } + + @Test + void testCreateContractDefinition() throws JsonProcessingException, JSONException { + // given + String assetId = "Asset1"; + String policyId = "Policy1"; + + // when + EdcCreateContractDefinitionRequest request = service.createContractDefinitionRequest(assetId, policyId); + + // then + JSONAssert.assertEquals(""" + { + "@context": { + "edc": "https://w3id.org/edc/v0.0.1/ns/" + }, + "@type": "ContractDefinition", + "@id": "Policy1", + "accessPolicyId": "Policy1", + "contractPolicyId": "Policy1", + "assetsSelector": { + "@type": "CriterionDto", + "operandLeft": "https://w3id.org/edc/v0.0.1/ns/id", + "operator": "=", + "operandRight": "Asset1" + } + } + """, objectMapper.writeValueAsString(request), false); + } + +} \ No newline at end of file diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java new file mode 100644 index 0000000000..4c20b9d9cd --- /dev/null +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java @@ -0,0 +1,83 @@ +/******************************************************************************** + * 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.policy.service; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.tractusx.irs.edc.client.policy.model.EdcCreatePolicyDefinitionRequest; +import org.json.JSONException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +class EdcPolicyDefinitionServiceTest { + + private ObjectMapper objectMapper; + private EdcPolicyDefinitionService service; + + @BeforeEach + void setUp() { + this.objectMapper = new ObjectMapper(); + this.service = new EdcPolicyDefinitionService(); + } + + @Test + void testCreatePolicyDefinitionRequest() throws JsonProcessingException, JSONException { + // given + String policyName = "ID 3.0 Trace"; + String policyId = "4cc0bb57-2d64-4cfb-a13b-aceef3477b7e"; + + // when + EdcCreatePolicyDefinitionRequest request = service.createPolicyDefinition(policyName, policyId); + + // then + JSONAssert.assertEquals(objectMapper.writeValueAsString(request), """ + { + "@context": { + "odrl": "http://www.w3.org/ns/odrl/2/" + }, + "@id": "4cc0bb57-2d64-4cfb-a13b-aceef3477b7e", + "@type": "PolicyDefinitionRequestDto", + "policy": { + "@type": "Policy", + "odrl:permission": [ + { + "odrl:action": "USE", + "odrl:constraint": { + "@type": "AtomicConstraint", + "odrl:or": [ + { + "@type": "Constraint", + "odrl:leftOperand": "PURPOSE", + "odrl:rightOperand": "ID 3.0 Trace", + "odrl:operator": { + "@id": "odrl:eq" + } + } + ] + } + } + ] + } + } + """, false); + } + +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 14d22c7d14..0a836fbf02 100644 --- a/pom.xml +++ b/pom.xml @@ -86,6 +86,7 @@ 8.5.6 5.4.0 4.2.0 + 1.5.1 5.9.2 7.11.1 2.0 From e1f9fbb547023e202627aaee7ef25e21c7addeab Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Thu, 1 Feb 2024 14:43:42 +0100 Subject: [PATCH 07/55] feature(irs-edc-client): #412 add headers and javadocs --- .../irs/edc/client/asset/EdcAssetService.java | 7 ++++++- .../edc/client/asset/model/AssetRequest.java | 5 ++++- .../edc/client/asset/model/EdcContext.java | 19 ++++++------------- .../asset/model/NotificationMethod.java | 7 ++++++- .../client/asset/model/NotificationType.java | 5 ++++- .../edc/client/asset/model/OdrlContext.java | 7 ++++++- .../exception/CreateEdcAssetException.java | 7 ++++++- .../client/contract/model/EDRAuthCode.java | 4 +++- .../model/EdcContractDefinitionCriteria.java | 7 ++++++- .../EdcCreateContractDefinitionRequest.java | 7 ++++++- .../client/contract/model/EdcOperator.java | 7 ++++++- .../CreateEdcContractDefinitionException.java | 7 ++++++- .../service/EdcContractDefinitionService.java | 7 ++++++- .../EdcCreatePolicyDefinitionRequest.java | 7 ++++++- .../edc/client/policy/model/EdcPolicy.java | 7 ++++++- .../policy/model/EdcPolicyPermission.java | 7 ++++++- .../model/EdcPolicyPermissionConstraint.java | 7 ++++++- ...cPolicyPermissionConstraintExpression.java | 8 ++++++-- .../CreateEdcPolicyDefinitionException.java | 7 ++++++- .../service/EdcPolicyDefinitionService.java | 7 ++++++- 20 files changed, 113 insertions(+), 33 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java index eb2f3b08a7..966babd60a 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -37,6 +38,10 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; +/** + * EdcAssetService used for creating edc assets for notifications dtr and to delete assets from edc + */ + @Slf4j @Service @RequiredArgsConstructor diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java index 14194fc38a..7d3615dc43 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java @@ -17,7 +17,6 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ - package org.eclipse.tractusx.irs.edc.client.asset.model; import lombok.Builder; @@ -26,6 +25,10 @@ import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; +/** + * AssetRequest used for creating edc notification asset + */ + @Value @Builder(toBuilder = true) @Jacksonized diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcContext.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcContext.java index 44b2acb6f6..d20c1bc2ab 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcContext.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcContext.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -22,21 +23,13 @@ import lombok.Builder; import lombok.ToString; +/** + * EdcContext used for creating edc notification asset + */ + @ToString @Builder public class EdcContext { - - /** - * For dtr asset currently following context is created by python script - * - * "dct": "https://purl.org/dc/terms/", - * "tx": "https://w3id.org/tractusx/v0.0.1/ns/", - * "edc": "https://w3id.org/edc/v0.0.1/ns/", - * "odrl": "http://www.w3.org/ns/odrl/2/", - * "dcat": "https://www.w3.org/ns/dcat/", - * "dspace": "https://w3id.org/dspace/v0.8/" - */ - @JsonProperty("edc") String edc; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationMethod.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationMethod.java index 08ebe34d12..0f666dcc75 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationMethod.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationMethod.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -18,6 +19,10 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.asset.model; +/** + * NotificationMethod used for creating edc notification asset + */ + public enum NotificationMethod { RECEIVE("receive"), UPDATE("update"), diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationType.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationType.java index 4c6a3c8fe2..66e9e1e5c9 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationType.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationType.java @@ -17,9 +17,12 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ - package org.eclipse.tractusx.irs.edc.client.asset.model; +/** + * NotificationType used for creating edc notification asset + */ + public enum NotificationType { QUALITY_INVESTIGATION("qualityinvestigation"), QUALITY_ALERT("qualityalert"); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/OdrlContext.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/OdrlContext.java index af4c1ec2b6..bf5916e470 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/OdrlContext.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/OdrlContext.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -22,6 +23,10 @@ import lombok.Builder; import lombok.ToString; +/** + * OdrlContext used for creating edc assets + */ + @ToString @Builder public class OdrlContext { diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java index d2592c691a..59eb9bcada 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -18,6 +19,10 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.asset.model.exception; +/** + * CreateEdcAssetException used for create asset failure + */ + public class CreateEdcAssetException extends RuntimeException { public CreateEdcAssetException(String message) { diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EDRAuthCode.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EDRAuthCode.java index 264be9348a..edf3ce33ec 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EDRAuthCode.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EDRAuthCode.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -25,6 +26,7 @@ /** * The decoded Auth code JWT. */ + @Builder @Data @Jacksonized diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractDefinitionCriteria.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractDefinitionCriteria.java index 98edc3c8c2..e8376de8ee 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractDefinitionCriteria.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractDefinitionCriteria.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -23,6 +24,10 @@ import lombok.Getter; import lombok.ToString; +/** + * EdcContractDefinitionCriteria used for creation of contract + */ + @ToString @Getter @Builder diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java index 64d707a2e7..fd3a87a3b2 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -25,6 +26,10 @@ import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition; import org.eclipse.tractusx.irs.edc.client.asset.model.EdcContext; +/** + * EdcCreateContractDefinitionRequest used for creation of contract + */ + @ToString @Builder public class EdcCreateContractDefinitionRequest { diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java index 6f9dc4bffd..556ad80172 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -23,6 +24,10 @@ import lombok.Builder; import lombok.ToString; +/** + * EdcOperator + */ + @ToString @Builder @AllArgsConstructor diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java index 2205c4f1e9..070df46c65 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -18,6 +19,10 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.contract.model.exception; +/** + * EdcContractDefinitionCriteria used for create contract failure + */ + public class CreateEdcContractDefinitionException extends RuntimeException { public CreateEdcContractDefinitionException(String message) { diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java index 84d6ecb68d..275b0102f0 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -32,6 +33,10 @@ import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; +/** + * EdcContractDefinitionService used for contract creation + */ + @Slf4j public class EdcContractDefinitionService { diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcCreatePolicyDefinitionRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcCreatePolicyDefinitionRequest.java index fd3cf0ba51..448320d8d0 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcCreatePolicyDefinitionRequest.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcCreatePolicyDefinitionRequest.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -24,6 +25,10 @@ import lombok.ToString; import org.eclipse.tractusx.irs.edc.client.asset.model.OdrlContext; +/** + * EdcCreatePolicyDefinitionRequest used for policy create request + */ + @ToString @Getter @Builder diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicy.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicy.java index 953dee724c..b5c1a08809 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicy.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicy.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -24,6 +25,10 @@ import lombok.Builder; import lombok.ToString; +/** + * EdcPolicy used for policy create request + */ + @ToString @Builder public class EdcPolicy { diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermission.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermission.java index 681d1f9e5c..2d4befa3ec 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermission.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermission.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -22,6 +23,10 @@ import lombok.Builder; import lombok.ToString; +/** + * EdcPolicyPermission used for policy create request + */ + @ToString @Builder public class EdcPolicyPermission { diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraint.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraint.java index 7f680c7874..d1626a8c9b 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraint.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraint.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -24,6 +25,10 @@ import lombok.Builder; import lombok.ToString; +/** + * EdcPolicyPermissionConstraint used for policy create request + */ + @ToString @Builder public class EdcPolicyPermissionConstraint { diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraintExpression.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraintExpression.java index ca4090bea7..6f5cb9118b 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraintExpression.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/EdcPolicyPermissionConstraintExpression.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -24,12 +25,15 @@ import lombok.ToString; import org.eclipse.tractusx.irs.edc.client.contract.model.EdcOperator; +/** + * EdcPolicyPermissionConstraintExpression used for policy create request + */ + @ToString @Getter @Builder public class EdcPolicyPermissionConstraintExpression { - // Constraint @JsonProperty("@type") private final String type; diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java index a915b07906..001a268bc4 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -18,6 +19,10 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.policy.model.exception; +/** + * CreateEdcPolicyDefinitionException used policy creation failed case + */ + public class CreateEdcPolicyDefinitionException extends RuntimeException { public CreateEdcPolicyDefinitionException(String message) { diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index b86c909151..530b5cbd82 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -1,5 +1,6 @@ /******************************************************************************** - * Copyright (c) 2024 Contributors to the Eclipse Foundation + * 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. @@ -38,6 +39,10 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; +/** + * Service providing Edc Policies creation + */ + @Slf4j public class EdcPolicyDefinitionService { From 37084ef9e965ef1a7443771aac2cf6a2f305c360 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Thu, 1 Feb 2024 14:52:23 +0100 Subject: [PATCH 08/55] feature(irs-edc-client): #412 add headers and javadocs --- .../irs/edc/client/asset/EdcAssetService.java | 68 ++++++++++--------- ...JsonObjectFromAssetRequestTransformer.java | 6 +- .../service/EdcContractDefinitionService.java | 7 +- .../service/EdcPolicyDefinitionService.java | 5 +- 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java index 966babd60a..c11f6b1682 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -31,6 +31,7 @@ import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationType; import org.eclipse.tractusx.irs.edc.client.asset.model.exception.CreateEdcAssetException; import org.eclipse.tractusx.irs.edc.client.transformer.EdcTransformer; +import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -72,12 +73,12 @@ private String sendRequest(final JsonObject request, final RestTemplate restTemp createEdcDataAssetResponse = restTemplate.postForEntity(ASSETS_PATH, request, String.class); HttpStatusCode responseCode = createEdcDataAssetResponse.getStatusCode(); - if (responseCode.value() == 409) { + if (responseCode.value() == HttpStatus.CONFLICT.value()) { log.info("{} asset already exists in the EDC", getAssetId(request)); return getAssetId(request); } - if (responseCode.value() == 200) { + if (responseCode.value() == HttpStatus.OK.value()) { return getAssetId(request); } } catch (RestClientException e) { @@ -102,23 +103,23 @@ public void deleteAsset(String notificationAssetId, RestTemplate restTemplate) { private JsonObject createNotificationAssetRequest(String assetName, String baseUrl, NotificationMethod notificationMethod, NotificationType notificationType) { String assetId = UUID.randomUUID().toString(); - Map properties = Map.of( - "description", assetName, - "contenttype", DEFAULT_CONTENT_TYPE, - "policy-id", DEFAULT_POLICY_ID, - "type", notificationType.getValue(), - "notificationtype", notificationType.getValue(), - "notificationmethod", notificationMethod.getValue() - ); + Map properties = Map.of("description", assetName, "contenttype", DEFAULT_CONTENT_TYPE, + "policy-id", DEFAULT_POLICY_ID, "type", notificationType.getValue(), "notificationtype", + notificationType.getValue(), "notificationmethod", notificationMethod.getValue()); DataAddress dataAddress = DataAddress.Builder.newInstance() - .type(DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", baseUrl) - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", "true") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", "true") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/method", DEFAULT_METHOD) - .build(); + .type(DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", + DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", + baseUrl) + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", + "true") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", + "true") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/method", + DEFAULT_METHOD) + .build(); Asset asset = Asset.Builder.newInstance() .id(assetId) @@ -129,22 +130,27 @@ private JsonObject createNotificationAssetRequest(String assetName, String baseU return edcTransformer.transformAssetToJson(asset); } - private JsonObject createDtrAssetRequest(String assetName, String baseUrl){ + private JsonObject createDtrAssetRequest(String assetName, String baseUrl) { String assetId = UUID.randomUUID().toString(); - Map properties = Map.of( - "description", assetName, - "type", "data.core.digitalTwinRegistry" - ); + Map properties = Map.of("description", assetName, "type", "data.core.digitalTwinRegistry"); DataAddress dataAddress = DataAddress.Builder.newInstance() .type("DataAddress") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", baseUrl) - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", "true") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", "true") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyPath", "true") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams", "true") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/method", DEFAULT_METHOD) + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", + DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", + baseUrl) + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", + "true") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", + "true") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyPath", + "true") + .property( + "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams", + "true") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/method", + DEFAULT_METHOD) .build(); Asset asset = Asset.Builder.newInstance() @@ -157,8 +163,6 @@ private JsonObject createDtrAssetRequest(String assetName, String baseUrl){ } private static String getAssetId(JsonObject jsonObject) { - return jsonObject.get("asset") - .asJsonObject() - .get("@id").toString(); + return jsonObject.get("asset").asJsonObject().get("@id").toString(); } } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java index 88026282c8..02a2412984 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java @@ -29,6 +29,10 @@ import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; import org.jetbrains.annotations.NotNull; +/** + * Transformer to convert AssetRequest to JSON-LD. + */ + public class JsonObjectFromAssetRequestTransformer extends AbstractJsonLdTransformer { private final JsonBuilderFactory jsonFactory; @@ -47,4 +51,4 @@ public JsonObject transform(@NotNull final AssetRequest assetRequest, @NotNull f context.transform(assetRequest.getDataAddress(), JsonObject.class)); return builder.build(); } -} \ No newline at end of file +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java index 275b0102f0..fe9cf7508b 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java @@ -21,13 +21,12 @@ import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.NAMESPACE_EDC; -import java.util.UUID; - import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.edc.client.asset.model.EdcContext; import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractDefinitionCriteria; import org.eclipse.tractusx.irs.edc.client.contract.model.EdcCreateContractDefinitionRequest; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.CreateEdcContractDefinitionException; +import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestClientException; @@ -57,13 +56,13 @@ public String createContractDefinition(String assetId, String policyId, RestTemp HttpStatusCode responseCode = createContractDefinitionResponse.getStatusCode(); - if (responseCode.value() == 409) { + if (responseCode.value() == HttpStatus.CONFLICT.value()) { log.info("{} asset contract definition already exists in the EDC", assetId); throw new CreateEdcContractDefinitionException("Asset contract definition already exists in the EDC"); } - if (responseCode.value() == 200) { + if (responseCode.value() == HttpStatus.OK.value()) { return policyId; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index 530b5cbd82..e2042f7759 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -33,6 +33,7 @@ import org.eclipse.tractusx.irs.edc.client.policy.model.EdcPolicyPermissionConstraint; import org.eclipse.tractusx.irs.edc.client.policy.model.EdcPolicyPermissionConstraintExpression; import org.eclipse.tractusx.irs.edc.client.policy.model.exception.CreateEdcPolicyDefinitionException; +import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestClientException; @@ -70,13 +71,13 @@ public String createAccessPolicy(String policyName, RestTemplate restTemplate) { HttpStatusCode responseCode = createPolicyDefinitionResponse.getStatusCode(); - if (responseCode.value() == 409) { + if (responseCode.value() == HttpStatus.CONFLICT.value()) { log.info("Notification asset policy definition already exists in the EDC"); throw new CreateEdcPolicyDefinitionException("Asset policy definition already exists in the EDC"); } - if (responseCode.value() == 200) { + if (responseCode.value() == HttpStatus.OK.value()) { return request.getPolicyDefinitionId(); } From 5fc7799a55547b446e4d38edc02a7828b92a027d Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Thu, 1 Feb 2024 14:56:31 +0100 Subject: [PATCH 09/55] feature(irs-edc-client): #412 findings --- .../contract/model/EdcCreateContractDefinitionRequest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java index fd3a87a3b2..5d8a457853 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java @@ -22,8 +22,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; import lombok.ToString; -import org.eclipse.edc.connector.contract.spi.event.contractdefinition.ContractDefinitionCreated; -import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition; import org.eclipse.tractusx.irs.edc.client.asset.model.EdcContext; /** From b039eeb0ca55a6fb906b69381aff7d754a633976 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Thu, 1 Feb 2024 15:11:17 +0100 Subject: [PATCH 10/55] feature(irs-edc-client): #412 compilation issue --- .../org/eclipse/tractusx/irs/connector/job/JobOrchestrator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/connector/job/JobOrchestrator.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/connector/job/JobOrchestrator.java index 7991aa6144..d07a12d581 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/connector/job/JobOrchestrator.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/connector/job/JobOrchestrator.java @@ -119,7 +119,7 @@ public JobInitiateResponse startJob(final String globalAssetId, final JobParamet final Stream requests; try { - requests = z.initiate(multiJob); + requests = handler.initiate(multiJob); } catch (RuntimeException e) { markJobInError(multiJob, e, JOB_EXECUTION_FAILED); meterService.incrementJobFailed(); From feaac440e84a46406ea6bec17add6e8305b287c7 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Thu, 1 Feb 2024 15:13:50 +0100 Subject: [PATCH 11/55] feature(irs-edc-client): #412 empty spaces end files --- .../tractusx/irs/edc/client/asset/EdcAssetServiceTest.java | 2 +- .../contract/service/EdcContractDefinitionServiceTest.java | 2 +- .../client/policy/service/EdcPolicyDefinitionServiceTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java index 81ce3effb8..0d26b803d3 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java @@ -134,4 +134,4 @@ ObjectMapper objectMapper() { return objectMapper; } -} \ No newline at end of file +} diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java index 27d21cd856..2eaf7eadcd 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java @@ -74,4 +74,4 @@ void testCreateContractDefinition() throws JsonProcessingException, JSONExceptio """, objectMapper.writeValueAsString(request), false); } -} \ No newline at end of file +} diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java index 4c20b9d9cd..d2bc64a526 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java @@ -80,4 +80,4 @@ void testCreatePolicyDefinitionRequest() throws JsonProcessingException, JSONExc """, false); } -} \ No newline at end of file +} From e4051aa70db47c5c9a80d70b137181e77e27b84d Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Thu, 1 Feb 2024 15:57:32 +0100 Subject: [PATCH 12/55] feature(irs-edc-client): #412 added tests for policy and contract services --- .../DeleteEdcPolicyDefinitionException.java | 32 +++++++ .../service/EdcPolicyDefinitionService.java | 2 + .../EdcContractDefinitionServiceTest.java | 58 ++++++++++++ .../EdcPolicyDefinitionServiceTest.java | 91 +++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/DeleteEdcPolicyDefinitionException.java diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/DeleteEdcPolicyDefinitionException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/DeleteEdcPolicyDefinitionException.java new file mode 100644 index 0000000000..ee89ad4970 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/DeleteEdcPolicyDefinitionException.java @@ -0,0 +1,32 @@ +/******************************************************************************** + * 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.policy.model.exception; + +/** + * DeleteEdcPolicyDefinitionException used policy delete failed case + */ + +public class DeleteEdcPolicyDefinitionException extends RuntimeException { + + public DeleteEdcPolicyDefinitionException(Throwable cause) { + super(cause); + } +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index e2042f7759..18a48014d1 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -33,6 +33,7 @@ import org.eclipse.tractusx.irs.edc.client.policy.model.EdcPolicyPermissionConstraint; import org.eclipse.tractusx.irs.edc.client.policy.model.EdcPolicyPermissionConstraintExpression; import org.eclipse.tractusx.irs.edc.client.policy.model.exception.CreateEdcPolicyDefinitionException; +import org.eclipse.tractusx.irs.edc.client.policy.model.exception.DeleteEdcPolicyDefinitionException; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; @@ -131,6 +132,7 @@ public void deleteAccessPolicy(String accessPolicyId, RestTemplate restTemplate) restTemplate.delete(deleteUri); } catch (RestClientException e) { log.error("Failed to delete EDC notification asset policy {}. Reason: ", accessPolicyId, e); + throw new DeleteEdcPolicyDefinitionException(e); } } } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java index 2eaf7eadcd..27b3fc947b 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java @@ -19,7 +19,13 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.contract.service; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + import org.eclipse.tractusx.irs.edc.client.contract.model.EdcCreateContractDefinitionRequest; +import org.eclipse.tractusx.irs.edc.client.contract.model.exception.CreateEdcContractDefinitionException; import org.json.JSONException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -27,6 +33,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.skyscreamer.jsonassert.JSONAssert; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.testcontainers.shaded.com.fasterxml.jackson.core.JsonProcessingException; import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; @@ -74,4 +83,53 @@ void testCreateContractDefinition() throws JsonProcessingException, JSONExceptio """, objectMapper.writeValueAsString(request), false); } + @Test + void givenCreateContractDefinition_whenOK_thenReturnPolicyId() { + // given + String assetId = "Asset1"; + String policyId = "Policy1"; + when(restTemplate.postForEntity(any(String.class), any(EdcCreateContractDefinitionRequest.class), + any())).thenReturn(ResponseEntity.ok("test")); + + String result = service.createContractDefinition(assetId, policyId, restTemplate); + + assertThat(result).isEqualTo(policyId); + } + + @Test + void givenCreateContractDefinition_whenConflict_thenThrowException() { + // given + String assetId = "Asset1"; + String policyId = "Policy1"; + when(restTemplate.postForEntity(any(String.class), any(EdcCreateContractDefinitionRequest.class), + any())).thenReturn(ResponseEntity.status(HttpStatus.CONFLICT.value()).build()); + + assertThrows(CreateEdcContractDefinitionException.class, + () -> service.createContractDefinition(assetId, policyId, restTemplate)); + } + + @Test + void givenCreateContractDefinition_whenBadRequest_thenThrowException() { + // given + String assetId = "Asset1"; + String policyId = "Policy1"; + when(restTemplate.postForEntity(any(String.class), any(EdcCreateContractDefinitionRequest.class), + any())).thenReturn(ResponseEntity.status(HttpStatus.BAD_REQUEST.value()).build()); + + assertThrows(CreateEdcContractDefinitionException.class, + () -> service.createContractDefinition(assetId, policyId, restTemplate)); + } + + @Test + void givenCreateContractDefinition_whenRestClientException_thenThrowException() { + // given + String assetId = "Asset1"; + String policyId = "Policy1"; + when(restTemplate.postForEntity(any(String.class), any(EdcCreateContractDefinitionRequest.class), + any())).thenThrow(new RestClientException("Surprise")); + + assertThrows(CreateEdcContractDefinitionException.class, + () -> service.createContractDefinition(assetId, policyId, restTemplate)); + } + } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java index d2bc64a526..155bfb2232 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java @@ -19,16 +19,37 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.policy.service; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.tractusx.irs.edc.client.policy.model.EdcCreatePolicyDefinitionRequest; +import org.eclipse.tractusx.irs.edc.client.policy.model.exception.CreateEdcPolicyDefinitionException; +import org.eclipse.tractusx.irs.edc.client.policy.model.exception.DeleteEdcPolicyDefinitionException; import org.json.JSONException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.skyscreamer.jsonassert.JSONAssert; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; +@ExtendWith(MockitoExtension.class) class EdcPolicyDefinitionServiceTest { + @Mock + private RestTemplate restTemplate; + private ObjectMapper objectMapper; private EdcPolicyDefinitionService service; @@ -80,4 +101,74 @@ void testCreatePolicyDefinitionRequest() throws JsonProcessingException, JSONExc """, false); } + @Test + void givenPolicy_WhenCreateAccessPolicy_ThenCreateIt() { + // given + String policyName = "policyName"; + when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class), + any())).thenReturn(ResponseEntity.ok("test")); + + // when + String result = service.createAccessPolicy(policyName, restTemplate); + + // then + assertThat(result).isNotBlank(); + } + + @Test + void givenCreatePolicy_whenConflict_thenThrowException() { + // given + String policyName = "policyName"; + when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class), + any())).thenReturn(ResponseEntity.status(HttpStatus.CONFLICT.value()).build()); + + assertThrows(CreateEdcPolicyDefinitionException.class, + () -> service.createAccessPolicy(policyName, restTemplate)); + } + + @Test + void givenCreatePolicy_whenBadRequest_thenThrowException() { + // given + String policyName = "policyName"; + when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class), + any())).thenReturn(ResponseEntity.status(HttpStatus.BAD_REQUEST.value()).build()); + + assertThrows(CreateEdcPolicyDefinitionException.class, + () -> service.createAccessPolicy(policyName, restTemplate)); + } + + @Test + void givenCreatePolicy_whenRestClientException_thenThrowException() { + // given + String policyName = "policyName"; + when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class), + any())).thenThrow(new RestClientException("Surprise")); + + assertThrows(CreateEdcPolicyDefinitionException.class, + () -> service.createAccessPolicy(policyName, restTemplate)); + } + + @Test + void givenDeletePolicy_whenRestClientException_thenThrowException() { + // given + String policyName = "policyName"; + doThrow(new RestClientException("Surprise")).when(restTemplate).delete(any(String.class)); + + // when/then + assertThrows(DeleteEdcPolicyDefinitionException.class, + () -> service.deleteAccessPolicy(policyName, restTemplate)); + } + + @Test + void givenDeletePolicy_whenOk_thenCallRestTemplate() { + // given + String policyName = "policyName"; + + // when + service.deleteAccessPolicy(policyName, restTemplate); + + // then + verify(restTemplate, times(1)).delete(any(String.class)); + } + } From 33049eb506aea426a8c784ba653a0c0e0890a48e Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Thu, 1 Feb 2024 16:55:59 +0100 Subject: [PATCH 13/55] feature(irs-edc-client): #412 added tests for AssetService --- .../irs/edc/client/asset/EdcAssetService.java | 17 ++- .../exception/DeleteEdcAssetException.java | 32 +++++ .../client/transformer/EdcTransformer.java | 5 - .../edc/client/asset/EdcAssetServiceTest.java | 112 ++++++++++++++++-- 4 files changed, 146 insertions(+), 20 deletions(-) create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/DeleteEdcAssetException.java diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java index c11f6b1682..8557199075 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -27,9 +27,11 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; +import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationMethod; import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationType; import org.eclipse.tractusx.irs.edc.client.asset.model.exception.CreateEdcAssetException; +import org.eclipse.tractusx.irs.edc.client.asset.model.exception.DeleteEdcAssetException; import org.eclipse.tractusx.irs.edc.client.transformer.EdcTransformer; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; @@ -54,7 +56,7 @@ public class EdcAssetService { private static final String DEFAULT_DATA_ADDRESS_PROPERTY_TYPE = "HttpData"; private static final String ASSETS_PATH = "/management/v2/assets"; - EdcTransformer edcTransformer; + private final EdcTransformer edcTransformer; public String createNotificationAsset(String baseUrl, String assetName, NotificationMethod notificationMethod, NotificationType notificationType, RestTemplate restTemplate) { @@ -87,16 +89,17 @@ private String sendRequest(final JsonObject request, final RestTemplate restTemp throw new CreateEdcAssetException("Failed to create asset %s".formatted(getAssetId(request))); } - public void deleteAsset(String notificationAssetId, RestTemplate restTemplate) { + public void deleteAsset(String assetId, RestTemplate restTemplate) { String deleteUri = UriComponentsBuilder.fromPath(ASSETS_PATH) .pathSegment("{notificationAssetId}") - .buildAndExpand(notificationAssetId) + .buildAndExpand(assetId) .toUriString(); try { restTemplate.delete(deleteUri); } catch (RestClientException e) { - log.error("Failed to delete EDC notification asset {}. Reason: ", notificationAssetId, e); + log.error("Failed to delete EDC notification asset {}. Reason: ", assetId, e); + throw new DeleteEdcAssetException(e); } } @@ -127,7 +130,8 @@ private JsonObject createNotificationAssetRequest(String assetName, String baseU .properties(properties) .dataAddress(dataAddress) .build(); - return edcTransformer.transformAssetToJson(asset); + return edcTransformer.transformAssetRequestToJson( + AssetRequest.builder().asset(asset).dataAddress(dataAddress).build()); } private JsonObject createDtrAssetRequest(String assetName, String baseUrl) { @@ -159,7 +163,8 @@ private JsonObject createDtrAssetRequest(String assetName, String baseUrl) { .properties(properties) .dataAddress(dataAddress) .build(); - return edcTransformer.transformAssetToJson(asset); + return edcTransformer.transformAssetRequestToJson( + AssetRequest.builder().asset(asset).dataAddress(dataAddress).build()); } private static String getAssetId(JsonObject jsonObject) { diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/DeleteEdcAssetException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/DeleteEdcAssetException.java new file mode 100644 index 0000000000..e52ec7b0d2 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/DeleteEdcAssetException.java @@ -0,0 +1,32 @@ +/******************************************************************************** + * 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.asset.model.exception; + +/** + * DeleteEdcAssetException used for delete asset failure + */ + +public class DeleteEdcAssetException extends RuntimeException { + public DeleteEdcAssetException(Throwable cause) { + super(cause); + } + +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java index cffa22c0da..109c7baabc 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java @@ -186,11 +186,6 @@ public JsonObject transformCatalogRequestToJson(final CatalogRequest catalogRequ return titaniumJsonLd.compact(transform).asOptional().orElseThrow(); } - public JsonObject transformAssetToJson(Asset asset) { - final JsonObject transform = jsonObjectFromAssetTransformer.transform(asset, transformerContext); - return titaniumJsonLd.compact(transform).asOptional().orElseThrow(); - } - public JsonObject transformAssetRequestToJson(AssetRequest assetRequest) { final JsonObject transform = jsonObjectFromAssetRequestTransformer.transform(assetRequest, transformerContext); return titaniumJsonLd.compact(transform).asOptional().orElseThrow(); diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java index 0d26b803d3..9f7bfbc9d4 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java @@ -19,6 +19,12 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.asset; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.Map; @@ -37,15 +43,35 @@ import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; +import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationMethod; +import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationType; +import org.eclipse.tractusx.irs.edc.client.asset.model.exception.CreateEdcAssetException; +import org.eclipse.tractusx.irs.edc.client.asset.model.exception.DeleteEdcAssetException; import org.eclipse.tractusx.irs.edc.client.transformer.EdcTransformer; import org.json.JSONException; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.skyscreamer.jsonassert.JSONAssert; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; +@ExtendWith(MockitoExtension.class) class EdcAssetServiceTest { - @Test - void testAssetCreateRequestStructure() throws JSONException { + @Mock + private RestTemplate restTemplate; + private org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper objectMapper; + + private EdcTransformer edcTransformer; + private EdcAssetService service; + + @BeforeEach + void setUp() { + this.objectMapper = new org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper(); TitaniumJsonLd jsonLd = new TitaniumJsonLd(new ConsoleMonitor()); jsonLd.registerNamespace("odrl", "http://www.w3.org/ns/odrl/2/"); jsonLd.registerNamespace("dct", "https://purl.org/dc/terms/"); @@ -54,7 +80,12 @@ void testAssetCreateRequestStructure() throws JSONException { jsonLd.registerNamespace("dcat", "https://www.w3.org/ns/dcat/"); jsonLd.registerNamespace("dspace", "https://w3id.org/dspace/v0.8/"); - EdcTransformer edcTransformer = new EdcTransformer(objectMapper(), jsonLd, new TypeTransformerRegistryImpl()); + this.edcTransformer = new EdcTransformer(objectMapper(), jsonLd, new TypeTransformerRegistryImpl()); + this.service = new EdcAssetService(edcTransformer); + } + + @Test + void testAssetCreateRequestStructure() throws JSONException { Map properties = Map.of("description", "endpoint to qualityinvestigation receive", "contenttype", "application/json", "policy-id", "use-eu", "type", "receive", "notificationtype", @@ -79,9 +110,7 @@ void testAssetCreateRequestStructure() throws JSONException { JsonObject jsonObject = edcTransformer.transformAssetRequestToJson( AssetRequest.builder().asset(asset).dataAddress(dataAddress).build()); - JSONAssert.assertEquals( - jsonObject.toString(), - """ + JSONAssert.assertEquals(jsonObject.toString(), """ { "asset": { "@id": "Asset1", @@ -118,9 +147,74 @@ void testAssetCreateRequestStructure() throws JSONException { "asset": "https://w3id.org/edc/v0.0.1/ns/asset" } } - """, - false - ); + """, false); + } + + @Test + void givenCreateNotificationAsset_whenOk_ThenReturnCreatedAssetId() { + // given + String baseUrl = "http://test.test"; + String assetName = "asset1"; + NotificationMethod notificationMethod = NotificationMethod.RECEIVE; + NotificationType notificationType = NotificationType.QUALITY_ALERT; + when(restTemplate.postForEntity(any(String.class), any(JsonObject.class), any())).thenReturn( + ResponseEntity.ok("test")); + + // when + String assetId = service.createNotificationAsset(baseUrl, assetName, notificationMethod, notificationType, + restTemplate); + + // then + assertThat(assetId).isNotBlank(); + } + + @Test + void givenCreateDtrAsset_whenOk_ThenReturnCreatedAssetId() { + // given + String baseUrl = "http://test.test"; + String assetName = "asset1"; + when(restTemplate.postForEntity(any(String.class), any(JsonObject.class), any())).thenReturn( + ResponseEntity.ok("test")); + + // when + String assetId = service.createDtrAsset(baseUrl, assetName, restTemplate); + + // then + assertThat(assetId).isNotBlank(); + } + + @Test + void givenDeleteAsset_whenOk_ThenReturnCreatedAssetId() { + // given + String assetId = "id"; + + // when + service.deleteAsset(assetId, restTemplate); + + // then + verify(restTemplate).delete(any(String.class)); + } + + @Test + void givenCreateDtrAsset_whenTemplateException_ThenThrowException() { + // given + String baseUrl = "http://test.test"; + String assetName = "asset1"; + doThrow(new RestClientException("Surprise")).when(restTemplate) + .postForEntity(any(String.class), any(JsonObject.class), any()); + + // when/then + assertThrows(CreateEdcAssetException.class, () -> service.createDtrAsset(baseUrl, assetName, restTemplate)); + } + + @Test + void givenDeleteAsset_whenTemplateException_ThenThrowException() { + // given + String assetId = "id"; + doThrow(new RestClientException("Surprise")).when(restTemplate).delete(any(String.class)); + + // when/then + assertThrows(DeleteEdcAssetException.class, () -> service.deleteAsset(assetId, restTemplate)); } ObjectMapper objectMapper() { From 3eb09ead59d55f5f26fbdc21d1bc96cd27feb7d5 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Thu, 1 Feb 2024 19:45:36 +0100 Subject: [PATCH 14/55] feature(irs-edc-client): #412 sonar issus --- .../JsonObjectFromAssetRequestTransformer.java | 3 +-- .../irs/edc/client/transformer/EdcTransformer.java | 9 +++++---- .../irs/edc/client/asset/EdcAssetServiceTest.java | 12 ++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java index 02a2412984..9a1e206090 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java @@ -20,7 +20,6 @@ package org.eclipse.tractusx.irs.edc.client.asset.transformer; -import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.json.JsonBuilderFactory; import jakarta.json.JsonObject; import jakarta.json.JsonObjectBuilder; @@ -37,7 +36,7 @@ public class JsonObjectFromAssetRequestTransformer extends AbstractJsonLdTransfo private final JsonBuilderFactory jsonFactory; - public JsonObjectFromAssetRequestTransformer(final JsonBuilderFactory jsonFactory, ObjectMapper jsonLdMapper) { + public JsonObjectFromAssetRequestTransformer(final JsonBuilderFactory jsonFactory) { super(AssetRequest.class, JsonObject.class); this.jsonFactory = jsonFactory; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java index 109c7baabc..240087d3f3 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java @@ -62,7 +62,6 @@ import org.eclipse.edc.core.transform.transformer.to.JsonValueToGenericTypeTransformer; import org.eclipse.edc.jsonld.TitaniumJsonLd; import org.eclipse.edc.spi.result.Result; -import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; import org.eclipse.tractusx.irs.edc.client.asset.transformer.JsonObjectFromAssetRequestTransformer; @@ -101,7 +100,8 @@ public EdcTransformer(@Qualifier("jsonLdObjectMapper") final ObjectMapper object this.titaniumJsonLd.registerNamespace("asset", "https://w3id.org/edc/v0.0.1/ns/asset"); this.titaniumJsonLd.registerNamespace("dataAddress", "https://w3id.org/edc/v0.0.1/ns/dataAddress"); this.titaniumJsonLd.registerNamespace("proxyPath", "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyPath"); - this.titaniumJsonLd.registerNamespace("proxyQueryParams", "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams"); + this.titaniumJsonLd.registerNamespace("proxyQueryParams", + "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams"); final JsonBuilderFactory jsonBuilderFactory = Json.createBuilderFactory(Map.of()); jsonObjectFromNegotiationInitiateDtoTransformer = new JsonObjectFromNegotiationInitiateDtoTransformer( @@ -113,8 +113,9 @@ public EdcTransformer(@Qualifier("jsonLdObjectMapper") final ObjectMapper object jsonBuilderFactory); jsonObjectFromCatalogRequestTransformer = new JsonObjectFromCatalogRequestTransformer(jsonBuilderFactory); jsonObjectFromAssetTransformer = new JsonObjectFromAssetTransformer(jsonBuilderFactory, objectMapper); - jsonObjectFromAssetRequestTransformer = new JsonObjectFromAssetRequestTransformer(jsonBuilderFactory, objectMapper); - jsonObjectToPolicyTransformer = new org.eclipse.tractusx.irs.edc.client.transformer.JsonObjectToPolicyTransformer(objectMapper); + jsonObjectFromAssetRequestTransformer = new JsonObjectFromAssetRequestTransformer(jsonBuilderFactory); + jsonObjectToPolicyTransformer = new org.eclipse.tractusx.irs.edc.client.transformer.JsonObjectToPolicyTransformer( + objectMapper); transformerContext = new TransformerContextImpl(typeTransformerRegistry); diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java index 9f7bfbc9d4..9574652614 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java @@ -195,6 +195,18 @@ void givenDeleteAsset_whenOk_ThenReturnCreatedAssetId() { verify(restTemplate).delete(any(String.class)); } + @Test + void givenCreateDtrAsset_whenOK_ThenThrowException() { + // given + String baseUrl = "http://test.test"; + String assetName = "asset1"; + doThrow(new RestClientException("Surprise")).when(restTemplate) + .postForEntity(any(String.class), any(JsonObject.class), any()); + + // when/then + assertThrows(CreateEdcAssetException.class, () -> service.createDtrAsset(baseUrl, assetName, restTemplate)); + } + @Test void givenCreateDtrAsset_whenTemplateException_ThenThrowException() { // given From 32ea0baeb37c414e345ab22f267659613d76dcfd Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Thu, 1 Feb 2024 19:49:44 +0100 Subject: [PATCH 15/55] feature(irs-edc-client): #412 sonar issus --- .../eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java index 8557199075..4287463477 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -49,7 +49,6 @@ @Service @RequiredArgsConstructor public class EdcAssetService { - private static final String DEFAULT_CONTENT_TYPE = "application/json"; private static final String DEFAULT_POLICY_ID = "use-eu"; private static final String DEFAULT_METHOD = "POST"; From 191e362783fc1a82930ccd3c420138fcbc8efd7d Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Fri, 2 Feb 2024 10:01:54 +0100 Subject: [PATCH 16/55] feature(irs-edc-client): #412 pmd validation issues --- .../irs/edc/client/asset/EdcAssetService.java | 142 ++++++++++-------- .../edc/client/asset/model/AssetRequest.java | 6 +- .../edc/client/asset/model/EdcContext.java | 4 +- .../asset/model/NotificationMethod.java | 9 +- .../client/asset/model/NotificationType.java | 8 +- .../edc/client/asset/model/OdrlContext.java | 2 +- .../exception/CreateEdcAssetException.java | 4 +- .../exception/DeleteEdcAssetException.java | 2 +- .../EdcCreateContractDefinitionRequest.java | 2 +- .../client/contract/model/EdcOperator.java | 2 +- .../CreateEdcContractDefinitionException.java | 4 +- .../service/EdcContractDefinitionService.java | 33 ++-- .../CreateEdcPolicyDefinitionException.java | 4 +- .../service/EdcPolicyDefinitionService.java | 22 +-- .../client/transformer/EdcTransformer.java | 7 +- 15 files changed, 133 insertions(+), 118 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java index 4287463477..f78d845ad6 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -57,14 +57,16 @@ public class EdcAssetService { private final EdcTransformer edcTransformer; - public String createNotificationAsset(String baseUrl, String assetName, NotificationMethod notificationMethod, - NotificationType notificationType, RestTemplate restTemplate) { - JsonObject request = createNotificationAssetRequest(assetName, baseUrl, notificationMethod, notificationType); + public String createNotificationAsset(final String baseUrl, final String assetName, + final NotificationMethod notificationMethod, final NotificationType notificationType, + final RestTemplate restTemplate) { + final JsonObject request = createNotificationAssetRequest(assetName, baseUrl, notificationMethod, + notificationType); return sendRequest(request, restTemplate); } - public String createDtrAsset(String baseUrl, String assetName, RestTemplate restTemplate) { - JsonObject request = createDtrAssetRequest(assetName, baseUrl); + public String createDtrAsset(final String baseUrl, final String assetName, final RestTemplate restTemplate) { + final JsonObject request = createDtrAssetRequest(assetName, baseUrl); return sendRequest(request, restTemplate); } @@ -72,7 +74,7 @@ private String sendRequest(final JsonObject request, final RestTemplate restTemp final ResponseEntity createEdcDataAssetResponse; try { createEdcDataAssetResponse = restTemplate.postForEntity(ASSETS_PATH, request, String.class); - HttpStatusCode responseCode = createEdcDataAssetResponse.getStatusCode(); + final HttpStatusCode responseCode = createEdcDataAssetResponse.getStatusCode(); if (responseCode.value() == HttpStatus.CONFLICT.value()) { log.info("{} asset already exists in the EDC", getAssetId(request)); @@ -88,11 +90,11 @@ private String sendRequest(final JsonObject request, final RestTemplate restTemp throw new CreateEdcAssetException("Failed to create asset %s".formatted(getAssetId(request))); } - public void deleteAsset(String assetId, RestTemplate restTemplate) { - String deleteUri = UriComponentsBuilder.fromPath(ASSETS_PATH) - .pathSegment("{notificationAssetId}") - .buildAndExpand(assetId) - .toUriString(); + public void deleteAsset(final String assetId, final RestTemplate restTemplate) { + final String deleteUri = UriComponentsBuilder.fromPath(ASSETS_PATH) + .pathSegment("{notificationAssetId}") + .buildAndExpand(assetId) + .toUriString(); try { restTemplate.delete(deleteUri); @@ -102,71 +104,81 @@ public void deleteAsset(String assetId, RestTemplate restTemplate) { } } - private JsonObject createNotificationAssetRequest(String assetName, String baseUrl, - NotificationMethod notificationMethod, NotificationType notificationType) { - String assetId = UUID.randomUUID().toString(); - Map properties = Map.of("description", assetName, "contenttype", DEFAULT_CONTENT_TYPE, + private JsonObject createNotificationAssetRequest(final String assetName, final String baseUrl, + final NotificationMethod notificationMethod, final NotificationType notificationType) { + final String assetId = UUID.randomUUID().toString(); + final Map properties = Map.of("description", assetName, "contenttype", DEFAULT_CONTENT_TYPE, "policy-id", DEFAULT_POLICY_ID, "type", notificationType.getValue(), "notificationtype", notificationType.getValue(), "notificationmethod", notificationMethod.getValue()); - DataAddress dataAddress = DataAddress.Builder.newInstance() - .type(DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", - DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", - baseUrl) - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", - "true") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", - "true") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/method", - DEFAULT_METHOD) - .build(); - - Asset asset = Asset.Builder.newInstance() - .id(assetId) - .contentType("Asset") - .properties(properties) - .dataAddress(dataAddress) - .build(); + final DataAddress dataAddress = DataAddress.Builder.newInstance() + .type(DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", + DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) + .property( + "https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", + baseUrl) + .property( + "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", + Boolean.TRUE.toString()) + .property( + "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", + Boolean.TRUE.toString()) + .property( + "https://w3id.org/edc/v0.0.1/ns/dataAddress/method", + DEFAULT_METHOD) + .build(); + + final Asset asset = Asset.Builder.newInstance() + .id(assetId) + .contentType("Asset") + .properties(properties) + .dataAddress(dataAddress) + .build(); return edcTransformer.transformAssetRequestToJson( AssetRequest.builder().asset(asset).dataAddress(dataAddress).build()); } - private JsonObject createDtrAssetRequest(String assetName, String baseUrl) { - String assetId = UUID.randomUUID().toString(); - Map properties = Map.of("description", assetName, "type", "data.core.digitalTwinRegistry"); - - DataAddress dataAddress = DataAddress.Builder.newInstance() - .type("DataAddress") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", - DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", - baseUrl) - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", - "true") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", - "true") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyPath", - "true") - .property( - "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams", - "true") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/method", - DEFAULT_METHOD) - .build(); - - Asset asset = Asset.Builder.newInstance() - .id(assetId) - .contentType("Asset") - .properties(properties) - .dataAddress(dataAddress) - .build(); + private JsonObject createDtrAssetRequest(final String assetName, final String baseUrl) { + final String assetId = UUID.randomUUID().toString(); + final Map properties = Map.of("description", assetName, "type", + "data.core.digitalTwinRegistry"); + + final DataAddress dataAddress = DataAddress.Builder.newInstance() + .type("DataAddress") + .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", + DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) + .property( + "https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", + baseUrl) + .property( + "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", + Boolean.TRUE.toString()) + .property( + "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", + Boolean.TRUE.toString()) + .property( + "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyPath", + Boolean.TRUE.toString()) + .property( + "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams", + Boolean.TRUE.toString()) + .property( + "https://w3id.org/edc/v0.0.1/ns/dataAddress/method", + DEFAULT_METHOD) + .build(); + + final Asset asset = Asset.Builder.newInstance() + .id(assetId) + .contentType("Asset") + .properties(properties) + .dataAddress(dataAddress) + .build(); return edcTransformer.transformAssetRequestToJson( AssetRequest.builder().asset(asset).dataAddress(dataAddress).build()); } - private static String getAssetId(JsonObject jsonObject) { + private static String getAssetId(final JsonObject jsonObject) { return jsonObject.get("asset").asJsonObject().get("@id").toString(); } } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java index 7d3615dc43..abe1478c46 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java @@ -20,6 +20,7 @@ package org.eclipse.tractusx.irs.edc.client.asset.model; import lombok.Builder; +import lombok.Data; import lombok.Value; import lombok.extern.jackson.Jacksonized; import org.eclipse.edc.spi.types.domain.DataAddress; @@ -30,9 +31,10 @@ */ @Value +@Data @Builder(toBuilder = true) @Jacksonized public class AssetRequest { - Asset asset; - DataAddress dataAddress; + private Asset asset; + private DataAddress dataAddress; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcContext.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcContext.java index d20c1bc2ab..119678c256 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcContext.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/EdcContext.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; import lombok.ToString; +import lombok.extern.jackson.Jacksonized; /** * EdcContext used for creating edc notification asset @@ -29,7 +30,8 @@ @ToString @Builder +@Jacksonized public class EdcContext { @JsonProperty("edc") - String edc; + private String edc; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationMethod.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationMethod.java index 0f666dcc75..39f2ebe02c 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationMethod.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationMethod.java @@ -19,10 +19,13 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.asset.model; +import lombok.Getter; + /** * NotificationMethod used for creating edc notification asset */ +@Getter public enum NotificationMethod { RECEIVE("receive"), UPDATE("update"), @@ -30,12 +33,8 @@ public enum NotificationMethod { private final String value; - NotificationMethod(String value) { + NotificationMethod(final String value) { this.value = value; } - public String getValue() { - return value; - } } - diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationType.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationType.java index 66e9e1e5c9..5bc188c740 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationType.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/NotificationType.java @@ -19,21 +19,21 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.asset.model; +import lombok.Getter; + /** * NotificationType used for creating edc notification asset */ +@Getter public enum NotificationType { QUALITY_INVESTIGATION("qualityinvestigation"), QUALITY_ALERT("qualityalert"); private final String value; - NotificationType(String value) { + NotificationType(final String value) { this.value = value; } - public String getValue() { - return value; - } } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/OdrlContext.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/OdrlContext.java index bf5916e470..ef07fc3759 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/OdrlContext.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/OdrlContext.java @@ -31,5 +31,5 @@ @Builder public class OdrlContext { @JsonProperty("odrl") - String odrl; + private String odrl; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java index 59eb9bcada..a39b2d0edc 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java @@ -25,11 +25,11 @@ public class CreateEdcAssetException extends RuntimeException { - public CreateEdcAssetException(String message) { + public CreateEdcAssetException(final String message) { super(message); } - public CreateEdcAssetException(Throwable cause) { + public CreateEdcAssetException(final Throwable cause) { super(cause); } } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/DeleteEdcAssetException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/DeleteEdcAssetException.java index e52ec7b0d2..bf0426c1f3 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/DeleteEdcAssetException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/DeleteEdcAssetException.java @@ -25,7 +25,7 @@ */ public class DeleteEdcAssetException extends RuntimeException { - public DeleteEdcAssetException(Throwable cause) { + public DeleteEdcAssetException(final Throwable cause) { super(cause); } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java index 5d8a457853..646105cf56 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcCreateContractDefinitionRequest.java @@ -39,7 +39,7 @@ public class EdcCreateContractDefinitionRequest { private String type; @JsonProperty("@id") - private String id; + private String contractDefinitionId; @JsonProperty("accessPolicyId") private String accessPolicyId; diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java index 556ad80172..fe9f70b25d 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java @@ -33,6 +33,6 @@ @AllArgsConstructor public class EdcOperator { @JsonProperty("@id") - String id; + final String operatorId; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java index 070df46c65..9684ade715 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java @@ -25,11 +25,11 @@ public class CreateEdcContractDefinitionException extends RuntimeException { - public CreateEdcContractDefinitionException(String message) { + public CreateEdcContractDefinitionException(final String message) { super(message); } - public CreateEdcContractDefinitionException(Throwable cause) { + public CreateEdcContractDefinitionException(final Throwable cause) { super(cause); } } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java index fe9cf7508b..b259157ce4 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java @@ -46,15 +46,16 @@ public class EdcContractDefinitionService { private static final String CONTRACT_DEFINITION_PATH = "/management/v2/contractdefinitions"; - public String createContractDefinition(String assetId, String policyId, RestTemplate restTemplate) { - EdcCreateContractDefinitionRequest createContractDefinitionRequest = createContractDefinitionRequest(assetId, - policyId); + public String createContractDefinition(final String assetId, final String policyId, + final RestTemplate restTemplate) { + final EdcCreateContractDefinitionRequest createContractDefinitionRequest = createContractDefinitionRequest( + assetId, policyId); final ResponseEntity createContractDefinitionResponse; try { createContractDefinitionResponse = restTemplate.postForEntity(CONTRACT_DEFINITION_PATH, createContractDefinitionRequest, String.class); - HttpStatusCode responseCode = createContractDefinitionResponse.getStatusCode(); + final HttpStatusCode responseCode = createContractDefinitionResponse.getStatusCode(); if (responseCode.value() == HttpStatus.CONFLICT.value()) { log.info("{} asset contract definition already exists in the EDC", assetId); @@ -80,23 +81,23 @@ public String createContractDefinition(String assetId, String policyId, RestTemp public EdcCreateContractDefinitionRequest createContractDefinitionRequest(final String assetId, final String accessPolicyId) { - EdcContractDefinitionCriteria edcContractDefinitionCriteria = EdcContractDefinitionCriteria.builder() - .type(ASSET_SELECTOR_TYPE) - .operandLeft( - ASSET_SELECTOR_ID) - .operandRight( - assetId) - .operator( - ASSET_SELECTOR_EQUALITY_OPERATOR) - .build(); - - EdcContext edcContext = EdcContext.builder().edc(NAMESPACE_EDC).build(); + final EdcContractDefinitionCriteria edcContractDefinitionCriteria = EdcContractDefinitionCriteria.builder() + .type(ASSET_SELECTOR_TYPE) + .operandLeft( + ASSET_SELECTOR_ID) + .operandRight( + assetId) + .operator( + ASSET_SELECTOR_EQUALITY_OPERATOR) + .build(); + + final EdcContext edcContext = EdcContext.builder().edc(NAMESPACE_EDC).build(); return EdcCreateContractDefinitionRequest.builder() .contractPolicyId(accessPolicyId) .edcContext(edcContext) .type(CONTRACT_DEFINITION_TYPE) .accessPolicyId(accessPolicyId) - .id(accessPolicyId) + .contractDefinitionId(accessPolicyId) .assetsSelector(edcContractDefinitionCriteria) .build(); } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java index 001a268bc4..8ca78c1389 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java @@ -25,11 +25,11 @@ public class CreateEdcPolicyDefinitionException extends RuntimeException { - public CreateEdcPolicyDefinitionException(String message) { + public CreateEdcPolicyDefinitionException(final String message) { super(message); } - public CreateEdcPolicyDefinitionException(Throwable cause) { + public CreateEdcPolicyDefinitionException(final Throwable cause) { super(cause); } } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index 18a48014d1..568ba99a53 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -57,8 +57,8 @@ public class EdcPolicyDefinitionService { private static final String POLICY_DEFINITION_PATH = "/management/v2/policydefinitions"; - public String createAccessPolicy(String policyName, RestTemplate restTemplate) { - String accessPolicyId = UUID.randomUUID().toString(); + public String createAccessPolicy(final String policyName,final RestTemplate restTemplate) { + final String accessPolicyId = UUID.randomUUID().toString(); final EdcCreatePolicyDefinitionRequest request = createPolicyDefinition(policyName, accessPolicyId); final ResponseEntity createPolicyDefinitionResponse; @@ -70,7 +70,7 @@ public String createAccessPolicy(String policyName, RestTemplate restTemplate) { throw new CreateEdcPolicyDefinitionException(e); } - HttpStatusCode responseCode = createPolicyDefinitionResponse.getStatusCode(); + final HttpStatusCode responseCode = createPolicyDefinitionResponse.getStatusCode(); if (responseCode.value() == HttpStatus.CONFLICT.value()) { log.info("Notification asset policy definition already exists in the EDC"); @@ -85,8 +85,8 @@ public String createAccessPolicy(String policyName, RestTemplate restTemplate) { throw new CreateEdcPolicyDefinitionException("Failed to create EDC policy definition for asset"); } - public EdcCreatePolicyDefinitionRequest createPolicyDefinition(String policyName, String accessPolicyId) { - EdcPolicyPermissionConstraintExpression constraint = EdcPolicyPermissionConstraintExpression.builder() + public EdcCreatePolicyDefinitionRequest createPolicyDefinition(final String policyName,final String accessPolicyId) { + final EdcPolicyPermissionConstraintExpression constraint = EdcPolicyPermissionConstraintExpression.builder() .leftOperand( "PURPOSE") .rightOperand( @@ -98,21 +98,21 @@ public EdcCreatePolicyDefinitionRequest createPolicyDefinition(String policyName .type(CONSTRAINT) .build(); - EdcPolicyPermissionConstraint edcPolicyPermissionConstraint = EdcPolicyPermissionConstraint.builder() + final EdcPolicyPermissionConstraint edcPolicyPermissionConstraint = EdcPolicyPermissionConstraint.builder() .orExpressions( List.of(constraint)) .type(ATOMIC_CONSTRAINT) .build(); - EdcPolicyPermission odrlPermissions = EdcPolicyPermission.builder() + final EdcPolicyPermission odrlPermissions = EdcPolicyPermission.builder() .action(USE_ACTION) .edcPolicyPermissionConstraints( edcPolicyPermissionConstraint) .build(); - EdcPolicy edcPolicy = EdcPolicy.builder().odrlPermissions(List.of(odrlPermissions)).type(POLICY_TYPE).build(); + final EdcPolicy edcPolicy = EdcPolicy.builder().odrlPermissions(List.of(odrlPermissions)).type(POLICY_TYPE).build(); - OdrlContext odrlContext = OdrlContext.builder().odrl(NAMESPACE_ODRL).build(); + final OdrlContext odrlContext = OdrlContext.builder().odrl(NAMESPACE_ODRL).build(); return EdcCreatePolicyDefinitionRequest.builder() .policyDefinitionId(accessPolicyId) @@ -122,8 +122,8 @@ public EdcCreatePolicyDefinitionRequest createPolicyDefinition(String policyName .build(); } - public void deleteAccessPolicy(String accessPolicyId, RestTemplate restTemplate) { - String deleteUri = UriComponentsBuilder.fromPath(POLICY_DEFINITION_PATH) + public void deleteAccessPolicy(final String accessPolicyId,final RestTemplate restTemplate) { + final String deleteUri = UriComponentsBuilder.fromPath(POLICY_DEFINITION_PATH) .pathSegment("{accessPolicyId}") .buildAndExpand(accessPolicyId) .toUriString(); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java index 240087d3f3..a929575ec3 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java @@ -83,7 +83,6 @@ public class EdcTransformer { private final JsonObjectFromTransferProcessRequestTransformer jsonObjectFromTransferProcessRequestTransformer; private final JsonObjectFromContractOfferDescriptionTransformer jsonObjectFromContractOfferDescriptionTransformer; private final JsonObjectFromCatalogRequestTransformer jsonObjectFromCatalogRequestTransformer; - private final JsonObjectFromAssetTransformer jsonObjectFromAssetTransformer; private final org.eclipse.tractusx.irs.edc.client.transformer.JsonObjectToPolicyTransformer jsonObjectToPolicyTransformer; private final TitaniumJsonLd titaniumJsonLd; private final TransformerContextImpl transformerContext; @@ -112,7 +111,7 @@ public EdcTransformer(@Qualifier("jsonLdObjectMapper") final ObjectMapper object jsonObjectFromContractOfferDescriptionTransformer = new JsonObjectFromContractOfferDescriptionTransformer( jsonBuilderFactory); jsonObjectFromCatalogRequestTransformer = new JsonObjectFromCatalogRequestTransformer(jsonBuilderFactory); - jsonObjectFromAssetTransformer = new JsonObjectFromAssetTransformer(jsonBuilderFactory, objectMapper); + jsonObjectFromAssetRequestTransformer = new JsonObjectFromAssetRequestTransformer(jsonBuilderFactory); jsonObjectToPolicyTransformer = new org.eclipse.tractusx.irs.edc.client.transformer.JsonObjectToPolicyTransformer( objectMapper); @@ -146,7 +145,7 @@ public EdcTransformer(@Qualifier("jsonLdObjectMapper") final ObjectMapper object typeTransformerRegistry.register(new JsonObjectFromPolicyTransformer(jsonBuilderFactory)); typeTransformerRegistry.register(new JsonObjectFromDistributionTransformer(jsonBuilderFactory)); typeTransformerRegistry.register(new JsonObjectFromDataServiceTransformer(jsonBuilderFactory)); - typeTransformerRegistry.register(jsonObjectFromAssetTransformer); + typeTransformerRegistry.register(new JsonObjectFromAssetTransformer(jsonBuilderFactory, objectMapper)); typeTransformerRegistry.register(new JsonObjectFromCriterionTransformer(jsonBuilderFactory, objectMapper)); typeTransformerRegistry.register(new JsonObjectFromDataAddressTransformer(jsonBuilderFactory)); typeTransformerRegistry.register(jsonObjectFromAssetRequestTransformer); @@ -187,7 +186,7 @@ public JsonObject transformCatalogRequestToJson(final CatalogRequest catalogRequ return titaniumJsonLd.compact(transform).asOptional().orElseThrow(); } - public JsonObject transformAssetRequestToJson(AssetRequest assetRequest) { + public JsonObject transformAssetRequestToJson(final AssetRequest assetRequest) { final JsonObject transform = jsonObjectFromAssetRequestTransformer.transform(assetRequest, transformerContext); return titaniumJsonLd.compact(transform).asOptional().orElseThrow(); } From c18d47816576dc03ac66a341853af592152e96fd Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Fri, 2 Feb 2024 10:05:19 +0100 Subject: [PATCH 17/55] feature(irs-edc-client): #412 pmd validation issues --- .../service/EdcPolicyDefinitionService.java | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index 568ba99a53..c725587fbb 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -57,7 +57,7 @@ public class EdcPolicyDefinitionService { private static final String POLICY_DEFINITION_PATH = "/management/v2/policydefinitions"; - public String createAccessPolicy(final String policyName,final RestTemplate restTemplate) { + public String createAccessPolicy(final String policyName, final RestTemplate restTemplate) { final String accessPolicyId = UUID.randomUUID().toString(); final EdcCreatePolicyDefinitionRequest request = createPolicyDefinition(policyName, accessPolicyId); @@ -85,32 +85,36 @@ public String createAccessPolicy(final String policyName,final RestTemplate res throw new CreateEdcPolicyDefinitionException("Failed to create EDC policy definition for asset"); } - public EdcCreatePolicyDefinitionRequest createPolicyDefinition(final String policyName,final String accessPolicyId) { + public EdcCreatePolicyDefinitionRequest createPolicyDefinition(final String policyName, + final String accessPolicyId) { final EdcPolicyPermissionConstraintExpression constraint = EdcPolicyPermissionConstraintExpression.builder() - .leftOperand( - "PURPOSE") - .rightOperand( - policyName) - .operator( - new EdcOperator( - OPERATOR_PREFIX - + "eq")) - .type(CONSTRAINT) - .build(); + .leftOperand( + "PURPOSE") + .rightOperand( + policyName) + .operator( + new EdcOperator( + OPERATOR_PREFIX + + "eq")) + .type(CONSTRAINT) + .build(); final EdcPolicyPermissionConstraint edcPolicyPermissionConstraint = EdcPolicyPermissionConstraint.builder() - .orExpressions( - List.of(constraint)) - .type(ATOMIC_CONSTRAINT) - .build(); + .orExpressions( + List.of(constraint)) + .type(ATOMIC_CONSTRAINT) + .build(); final EdcPolicyPermission odrlPermissions = EdcPolicyPermission.builder() - .action(USE_ACTION) - .edcPolicyPermissionConstraints( - edcPolicyPermissionConstraint) - .build(); + .action(USE_ACTION) + .edcPolicyPermissionConstraints( + edcPolicyPermissionConstraint) + .build(); - final EdcPolicy edcPolicy = EdcPolicy.builder().odrlPermissions(List.of(odrlPermissions)).type(POLICY_TYPE).build(); + final EdcPolicy edcPolicy = EdcPolicy.builder() + .odrlPermissions(List.of(odrlPermissions)) + .type(POLICY_TYPE) + .build(); final OdrlContext odrlContext = OdrlContext.builder().odrl(NAMESPACE_ODRL).build(); @@ -122,11 +126,11 @@ public EdcCreatePolicyDefinitionRequest createPolicyDefinition(final String poli .build(); } - public void deleteAccessPolicy(final String accessPolicyId,final RestTemplate restTemplate) { + public void deleteAccessPolicy(final String accessPolicyId, final RestTemplate restTemplate) { final String deleteUri = UriComponentsBuilder.fromPath(POLICY_DEFINITION_PATH) - .pathSegment("{accessPolicyId}") - .buildAndExpand(accessPolicyId) - .toUriString(); + .pathSegment("{accessPolicyId}") + .buildAndExpand(accessPolicyId) + .toUriString(); try { restTemplate.delete(deleteUri); From 1618b7c789e9b7b3d79333fff83d500f822fafb5 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Fri, 2 Feb 2024 10:23:38 +0100 Subject: [PATCH 18/55] feature(irs-edc-client): #412 pmd validation issues --- .../tractusx/irs/edc/client/contract/model/EdcOperator.java | 2 +- .../model/exception/DeleteEdcPolicyDefinitionException.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java index fe9f70b25d..a344646593 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java @@ -32,7 +32,7 @@ @Builder @AllArgsConstructor public class EdcOperator { + @JsonProperty("@id") final String operatorId; - } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/DeleteEdcPolicyDefinitionException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/DeleteEdcPolicyDefinitionException.java index ee89ad4970..d83bcef4fb 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/DeleteEdcPolicyDefinitionException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/DeleteEdcPolicyDefinitionException.java @@ -26,7 +26,7 @@ public class DeleteEdcPolicyDefinitionException extends RuntimeException { - public DeleteEdcPolicyDefinitionException(Throwable cause) { + public DeleteEdcPolicyDefinitionException(final Throwable cause) { super(cause); } } From a7114734de22810ee53421e174c947bc29d7b64b Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Fri, 2 Feb 2024 10:26:39 +0100 Subject: [PATCH 19/55] feature(irs-edc-client): #412 pmd validation issues --- .../tractusx/irs/edc/client/contract/model/EdcOperator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java index a344646593..cd9754978f 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcOperator.java @@ -34,5 +34,5 @@ public class EdcOperator { @JsonProperty("@id") - final String operatorId; + private String operatorId; } From 09ce8240c8f96ff1dd3c06da1c9246837c702bdf Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 5 Feb 2024 14:32:54 +0100 Subject: [PATCH 20/55] feature(irs-edc-client): #412 after review --- .../irs/edc/client/EdcConfiguration.java | 3 ++ .../irs/edc/client/asset/EdcAssetService.java | 20 ++++++---- .../edc/client/asset/model/AssetRequest.java | 14 +++---- .../exception/CreateEdcAssetException.java | 2 +- .../exception/DeleteEdcAssetException.java | 2 +- ...JsonObjectFromAssetRequestTransformer.java | 11 ++++-- .../client/contract/model/EDRAuthCode.java | 37 ------------------- .../CreateEdcContractDefinitionException.java | 2 +- .../service/EdcContractDefinitionService.java | 11 ++++-- .../CreateEdcPolicyDefinitionException.java | 2 +- .../DeleteEdcPolicyDefinitionException.java | 2 +- .../service/EdcPolicyDefinitionService.java | 20 +++++++--- .../edc/client/asset/EdcAssetServiceTest.java | 33 +++++++++++++++-- .../EdcContractDefinitionServiceTest.java | 24 ++++++++++-- .../EdcPolicyDefinitionServiceTest.java | 31 ++++++++++++++-- 15 files changed, 134 insertions(+), 80 deletions(-) delete mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EDRAuthCode.java diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcConfiguration.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcConfiguration.java index c4951cc1a9..3eebea2e4a 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcConfiguration.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcConfiguration.java @@ -67,6 +67,9 @@ public static class EndpointConfig { private String data; private String catalog; private String contractNegotiation; + private String asset; + private String contractDefinition; + private String policyDefinition; private String transferProcess; private String stateSuffix; diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java index f78d845ad6..0857018c6e 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -27,6 +27,7 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; +import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationMethod; import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationType; @@ -53,27 +54,32 @@ public class EdcAssetService { private static final String DEFAULT_POLICY_ID = "use-eu"; private static final String DEFAULT_METHOD = "POST"; private static final String DEFAULT_DATA_ADDRESS_PROPERTY_TYPE = "HttpData"; - private static final String ASSETS_PATH = "/management/v2/assets"; private final EdcTransformer edcTransformer; + private final EdcConfiguration config; public String createNotificationAsset(final String baseUrl, final String assetName, final NotificationMethod notificationMethod, final NotificationType notificationType, - final RestTemplate restTemplate) { + final RestTemplate restTemplate) throws CreateEdcAssetException { final JsonObject request = createNotificationAssetRequest(assetName, baseUrl, notificationMethod, notificationType); return sendRequest(request, restTemplate); } - public String createDtrAsset(final String baseUrl, final String assetName, final RestTemplate restTemplate) { + public String createDtrAsset(final String baseUrl, final String assetName, final RestTemplate restTemplate) + throws CreateEdcAssetException { final JsonObject request = createDtrAssetRequest(assetName, baseUrl); return sendRequest(request, restTemplate); } - private String sendRequest(final JsonObject request, final RestTemplate restTemplate) { + private String sendRequest(final JsonObject request, final RestTemplate restTemplate) + throws CreateEdcAssetException { final ResponseEntity createEdcDataAssetResponse; try { - createEdcDataAssetResponse = restTemplate.postForEntity(ASSETS_PATH, request, String.class); + createEdcDataAssetResponse = restTemplate.postForEntity( + config.getControlplane().getEndpoint().getAsset(), + request, + String.class); final HttpStatusCode responseCode = createEdcDataAssetResponse.getStatusCode(); if (responseCode.value() == HttpStatus.CONFLICT.value()) { @@ -90,8 +96,8 @@ private String sendRequest(final JsonObject request, final RestTemplate restTemp throw new CreateEdcAssetException("Failed to create asset %s".formatted(getAssetId(request))); } - public void deleteAsset(final String assetId, final RestTemplate restTemplate) { - final String deleteUri = UriComponentsBuilder.fromPath(ASSETS_PATH) + public void deleteAsset(final String assetId, final RestTemplate restTemplate) throws DeleteEdcAssetException { + final String deleteUri = UriComponentsBuilder.fromPath(config.getControlplane().getEndpoint().getAsset()) .pathSegment("{notificationAssetId}") .buildAndExpand(assetId) .toUriString(); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java index abe1478c46..7e3995c9ec 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java @@ -20,9 +20,6 @@ package org.eclipse.tractusx.irs.edc.client.asset.model; import lombok.Builder; -import lombok.Data; -import lombok.Value; -import lombok.extern.jackson.Jacksonized; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; @@ -30,11 +27,10 @@ * AssetRequest used for creating edc notification asset */ -@Value -@Data @Builder(toBuilder = true) -@Jacksonized -public class AssetRequest { - private Asset asset; - private DataAddress dataAddress; +public record AssetRequest( + Asset asset, + DataAddress dataAddress) { + public static final String ASSET_CREATION_ASSET = "https://w3id.org/edc/v0.0.1/ns/asset"; + public static final String ASSET_CREATION_DATA_ADDRESS = "https://w3id.org/edc/v0.0.1/ns/dataAddress"; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java index a39b2d0edc..646fd23aec 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/CreateEdcAssetException.java @@ -23,7 +23,7 @@ * CreateEdcAssetException used for create asset failure */ -public class CreateEdcAssetException extends RuntimeException { +public class CreateEdcAssetException extends Exception { public CreateEdcAssetException(final String message) { super(message); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/DeleteEdcAssetException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/DeleteEdcAssetException.java index bf0426c1f3..9a883b7635 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/DeleteEdcAssetException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/exception/DeleteEdcAssetException.java @@ -24,7 +24,7 @@ * DeleteEdcAssetException used for delete asset failure */ -public class DeleteEdcAssetException extends RuntimeException { +public class DeleteEdcAssetException extends Exception { public DeleteEdcAssetException(final Throwable cause) { super(cause); } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java index 9a1e206090..4b9bb550ef 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java @@ -20,6 +20,9 @@ package org.eclipse.tractusx.irs.edc.client.asset.transformer; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_ASSET; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS; + import jakarta.json.JsonBuilderFactory; import jakarta.json.JsonObject; import jakarta.json.JsonObjectBuilder; @@ -44,10 +47,10 @@ public JsonObjectFromAssetRequestTransformer(final JsonBuilderFactory jsonFactor @Override public JsonObject transform(@NotNull final AssetRequest assetRequest, @NotNull final TransformerContext context) { final JsonObjectBuilder builder = this.jsonFactory.createObjectBuilder(); - builder.add("https://w3id.org/edc/v0.0.1/ns/asset", - context.transform(assetRequest.getAsset(), JsonObject.class)); - builder.add("https://w3id.org/edc/v0.0.1/ns/dataAddress", - context.transform(assetRequest.getDataAddress(), JsonObject.class)); + builder.add(ASSET_CREATION_ASSET, + context.transform(assetRequest.asset(), JsonObject.class)); + builder.add(ASSET_CREATION_DATA_ADDRESS, + context.transform(assetRequest.dataAddress(), JsonObject.class)); return builder.build(); } } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EDRAuthCode.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EDRAuthCode.java deleted file mode 100644 index edf3ce33ec..0000000000 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EDRAuthCode.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************** - * 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.contract.model; - -import lombok.Builder; -import lombok.Data; -import lombok.extern.jackson.Jacksonized; - -/** - * The decoded Auth code JWT. - */ - -@Builder -@Data -@Jacksonized -public class EDRAuthCode { - private final long exp; - private final String dad; - private final String cid; -} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java index 9684ade715..82a042f406 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/CreateEdcContractDefinitionException.java @@ -23,7 +23,7 @@ * EdcContractDefinitionCriteria used for create contract failure */ -public class CreateEdcContractDefinitionException extends RuntimeException { +public class CreateEdcContractDefinitionException extends Exception { public CreateEdcContractDefinitionException(final String message) { super(message); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java index b259157ce4..28af70c55b 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java @@ -21,7 +21,9 @@ import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.NAMESPACE_EDC; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; import org.eclipse.tractusx.irs.edc.client.asset.model.EdcContext; import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractDefinitionCriteria; import org.eclipse.tractusx.irs.edc.client.contract.model.EdcCreateContractDefinitionRequest; @@ -29,6 +31,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; @@ -37,6 +40,8 @@ */ @Slf4j +@Service +@RequiredArgsConstructor public class EdcContractDefinitionService { private static final String ASSET_SELECTOR_ID = "https://w3id.org/edc/v0.0.1/ns/id"; @@ -44,15 +49,15 @@ public class EdcContractDefinitionService { private static final String ASSET_SELECTOR_TYPE = "CriterionDto"; private static final String CONTRACT_DEFINITION_TYPE = "ContractDefinition"; - private static final String CONTRACT_DEFINITION_PATH = "/management/v2/contractdefinitions"; + private final EdcConfiguration config; public String createContractDefinition(final String assetId, final String policyId, - final RestTemplate restTemplate) { + final RestTemplate restTemplate) throws CreateEdcContractDefinitionException { final EdcCreateContractDefinitionRequest createContractDefinitionRequest = createContractDefinitionRequest( assetId, policyId); final ResponseEntity createContractDefinitionResponse; try { - createContractDefinitionResponse = restTemplate.postForEntity(CONTRACT_DEFINITION_PATH, + createContractDefinitionResponse = restTemplate.postForEntity(config.getControlplane().getEndpoint().getContractDefinition(), createContractDefinitionRequest, String.class); final HttpStatusCode responseCode = createContractDefinitionResponse.getStatusCode(); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java index 8ca78c1389..fd0e11ab0b 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/CreateEdcPolicyDefinitionException.java @@ -23,7 +23,7 @@ * CreateEdcPolicyDefinitionException used policy creation failed case */ -public class CreateEdcPolicyDefinitionException extends RuntimeException { +public class CreateEdcPolicyDefinitionException extends Exception { public CreateEdcPolicyDefinitionException(final String message) { super(message); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/DeleteEdcPolicyDefinitionException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/DeleteEdcPolicyDefinitionException.java index d83bcef4fb..4b6c303d96 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/DeleteEdcPolicyDefinitionException.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/DeleteEdcPolicyDefinitionException.java @@ -24,7 +24,7 @@ * DeleteEdcPolicyDefinitionException used policy delete failed case */ -public class DeleteEdcPolicyDefinitionException extends RuntimeException { +public class DeleteEdcPolicyDefinitionException extends Exception { public DeleteEdcPolicyDefinitionException(final Throwable cause) { super(cause); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index c725587fbb..9a50e0c858 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -24,7 +24,9 @@ import java.util.List; import java.util.UUID; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; import org.eclipse.tractusx.irs.edc.client.asset.model.OdrlContext; import org.eclipse.tractusx.irs.edc.client.contract.model.EdcOperator; import org.eclipse.tractusx.irs.edc.client.policy.model.EdcCreatePolicyDefinitionRequest; @@ -37,6 +39,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -46,6 +49,8 @@ */ @Slf4j +@Service +@RequiredArgsConstructor public class EdcPolicyDefinitionService { private static final String USE_ACTION = "USE"; @@ -55,15 +60,19 @@ public class EdcPolicyDefinitionService { private static final String CONSTRAINT = "Constraint"; private static final String OPERATOR_PREFIX = "odrl:"; - private static final String POLICY_DEFINITION_PATH = "/management/v2/policydefinitions"; + private final EdcConfiguration config; - public String createAccessPolicy(final String policyName, final RestTemplate restTemplate) { + public String createAccessPolicy(final String policyName, final RestTemplate restTemplate) + throws CreateEdcPolicyDefinitionException { final String accessPolicyId = UUID.randomUUID().toString(); final EdcCreatePolicyDefinitionRequest request = createPolicyDefinition(policyName, accessPolicyId); final ResponseEntity createPolicyDefinitionResponse; try { - createPolicyDefinitionResponse = restTemplate.postForEntity(POLICY_DEFINITION_PATH, request, String.class); + createPolicyDefinitionResponse = restTemplate.postForEntity( + config.getControlplane().getEndpoint().getPolicyDefinition(), + request, + String.class); } catch (RestClientException e) { log.error("Failed to create EDC notification asset policy. Reason: ", e); @@ -126,8 +135,9 @@ public EdcCreatePolicyDefinitionRequest createPolicyDefinition(final String poli .build(); } - public void deleteAccessPolicy(final String accessPolicyId, final RestTemplate restTemplate) { - final String deleteUri = UriComponentsBuilder.fromPath(POLICY_DEFINITION_PATH) + public void deleteAccessPolicy(final String accessPolicyId, final RestTemplate restTemplate) + throws DeleteEdcPolicyDefinitionException { + final String deleteUri = UriComponentsBuilder.fromPath(config.getControlplane().getEndpoint().getPolicyDefinition()) .pathSegment("{accessPolicyId}") .buildAndExpand(accessPolicyId) .toUriString(); diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java index 9574652614..78b1cadffb 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java @@ -42,6 +42,7 @@ import org.eclipse.edc.spi.monitor.ConsoleMonitor; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; +import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationMethod; import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationType; @@ -62,6 +63,12 @@ @ExtendWith(MockitoExtension.class) class EdcAssetServiceTest { + @Mock + EdcConfiguration edcConfiguration; + @Mock + EdcConfiguration.ControlplaneConfig controlplaneConfig; + @Mock + EdcConfiguration.ControlplaneConfig.EndpointConfig endpointConfig; @Mock private RestTemplate restTemplate; private org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper objectMapper; @@ -81,7 +88,7 @@ void setUp() { jsonLd.registerNamespace("dspace", "https://w3id.org/dspace/v0.8/"); this.edcTransformer = new EdcTransformer(objectMapper(), jsonLd, new TypeTransformerRegistryImpl()); - this.service = new EdcAssetService(edcTransformer); + this.service = new EdcAssetService(edcTransformer, edcConfiguration); } @Test @@ -151,8 +158,11 @@ void testAssetCreateRequestStructure() throws JSONException { } @Test - void givenCreateNotificationAsset_whenOk_ThenReturnCreatedAssetId() { + void givenCreateNotificationAsset_whenOk_ThenReturnCreatedAssetId() throws CreateEdcAssetException { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getAsset()).thenReturn("/management/v2/assets"); String baseUrl = "http://test.test"; String assetName = "asset1"; NotificationMethod notificationMethod = NotificationMethod.RECEIVE; @@ -169,8 +179,11 @@ void givenCreateNotificationAsset_whenOk_ThenReturnCreatedAssetId() { } @Test - void givenCreateDtrAsset_whenOk_ThenReturnCreatedAssetId() { + void givenCreateDtrAsset_whenOk_ThenReturnCreatedAssetId() throws CreateEdcAssetException { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getAsset()).thenReturn("/management/v2/assets"); String baseUrl = "http://test.test"; String assetName = "asset1"; when(restTemplate.postForEntity(any(String.class), any(JsonObject.class), any())).thenReturn( @@ -184,8 +197,11 @@ void givenCreateDtrAsset_whenOk_ThenReturnCreatedAssetId() { } @Test - void givenDeleteAsset_whenOk_ThenReturnCreatedAssetId() { + void givenDeleteAsset_whenOk_ThenReturnCreatedAssetId() throws DeleteEdcAssetException { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getAsset()).thenReturn("/management/v2/assets"); String assetId = "id"; // when @@ -198,6 +214,9 @@ void givenDeleteAsset_whenOk_ThenReturnCreatedAssetId() { @Test void givenCreateDtrAsset_whenOK_ThenThrowException() { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getAsset()).thenReturn("/management/v2/assets"); String baseUrl = "http://test.test"; String assetName = "asset1"; doThrow(new RestClientException("Surprise")).when(restTemplate) @@ -210,6 +229,9 @@ void givenCreateDtrAsset_whenOK_ThenThrowException() { @Test void givenCreateDtrAsset_whenTemplateException_ThenThrowException() { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getAsset()).thenReturn("/management/v2/assets"); String baseUrl = "http://test.test"; String assetName = "asset1"; doThrow(new RestClientException("Surprise")).when(restTemplate) @@ -222,6 +244,9 @@ void givenCreateDtrAsset_whenTemplateException_ThenThrowException() { @Test void givenDeleteAsset_whenTemplateException_ThenThrowException() { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getAsset()).thenReturn("/management/v2/assets"); String assetId = "id"; doThrow(new RestClientException("Surprise")).when(restTemplate).delete(any(String.class)); diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java index 27b3fc947b..6ed1aa4954 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java @@ -24,6 +24,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; import org.eclipse.tractusx.irs.edc.client.contract.model.EdcCreateContractDefinitionRequest; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.CreateEdcContractDefinitionException; import org.json.JSONException; @@ -45,13 +46,19 @@ class EdcContractDefinitionServiceTest { @Mock private RestTemplate restTemplate; + @Mock + EdcConfiguration edcConfiguration; + @Mock + EdcConfiguration.ControlplaneConfig controlplaneConfig; + @Mock + EdcConfiguration.ControlplaneConfig.EndpointConfig endpointConfig; private ObjectMapper objectMapper; private EdcContractDefinitionService service; @BeforeEach void setUp() { this.objectMapper = new ObjectMapper(); - this.service = new EdcContractDefinitionService(); + this.service = new EdcContractDefinitionService(edcConfiguration); } @Test @@ -84,8 +91,11 @@ void testCreateContractDefinition() throws JsonProcessingException, JSONExceptio } @Test - void givenCreateContractDefinition_whenOK_thenReturnPolicyId() { + void givenCreateContractDefinition_whenOK_thenReturnPolicyId() throws CreateEdcContractDefinitionException { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getContractDefinition()).thenReturn("/management/v2/contractdefinitions"); String assetId = "Asset1"; String policyId = "Policy1"; when(restTemplate.postForEntity(any(String.class), any(EdcCreateContractDefinitionRequest.class), @@ -99,6 +109,9 @@ void givenCreateContractDefinition_whenOK_thenReturnPolicyId() { @Test void givenCreateContractDefinition_whenConflict_thenThrowException() { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getContractDefinition()).thenReturn("/management/v2/contractdefinitions"); String assetId = "Asset1"; String policyId = "Policy1"; when(restTemplate.postForEntity(any(String.class), any(EdcCreateContractDefinitionRequest.class), @@ -110,7 +123,9 @@ void givenCreateContractDefinition_whenConflict_thenThrowException() { @Test void givenCreateContractDefinition_whenBadRequest_thenThrowException() { - // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getContractDefinition()).thenReturn("/management/v2/contractdefinitions"); String assetId = "Asset1"; String policyId = "Policy1"; when(restTemplate.postForEntity(any(String.class), any(EdcCreateContractDefinitionRequest.class), @@ -123,6 +138,9 @@ void givenCreateContractDefinition_whenBadRequest_thenThrowException() { @Test void givenCreateContractDefinition_whenRestClientException_thenThrowException() { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getContractDefinition()).thenReturn("/management/v2/contractdefinitions"); String assetId = "Asset1"; String policyId = "Policy1"; when(restTemplate.postForEntity(any(String.class), any(EdcCreateContractDefinitionRequest.class), diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java index 155bfb2232..a6a258e186 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; import org.eclipse.tractusx.irs.edc.client.policy.model.EdcCreatePolicyDefinitionRequest; import org.eclipse.tractusx.irs.edc.client.policy.model.exception.CreateEdcPolicyDefinitionException; import org.eclipse.tractusx.irs.edc.client.policy.model.exception.DeleteEdcPolicyDefinitionException; @@ -47,6 +48,12 @@ @ExtendWith(MockitoExtension.class) class EdcPolicyDefinitionServiceTest { + @Mock + EdcConfiguration edcConfiguration; + @Mock + EdcConfiguration.ControlplaneConfig controlplaneConfig; + @Mock + EdcConfiguration.ControlplaneConfig.EndpointConfig endpointConfig; @Mock private RestTemplate restTemplate; @@ -56,7 +63,7 @@ class EdcPolicyDefinitionServiceTest { @BeforeEach void setUp() { this.objectMapper = new ObjectMapper(); - this.service = new EdcPolicyDefinitionService(); + this.service = new EdcPolicyDefinitionService(edcConfiguration); } @Test @@ -102,8 +109,11 @@ void testCreatePolicyDefinitionRequest() throws JsonProcessingException, JSONExc } @Test - void givenPolicy_WhenCreateAccessPolicy_ThenCreateIt() { + void givenPolicy_WhenCreateAccessPolicy_ThenCreateIt() throws CreateEdcPolicyDefinitionException { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getPolicyDefinition()).thenReturn("/management/v2/policydefinitions"); String policyName = "policyName"; when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class), any())).thenReturn(ResponseEntity.ok("test")); @@ -118,6 +128,9 @@ void givenPolicy_WhenCreateAccessPolicy_ThenCreateIt() { @Test void givenCreatePolicy_whenConflict_thenThrowException() { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getPolicyDefinition()).thenReturn("/management/v2/policydefinitions"); String policyName = "policyName"; when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class), any())).thenReturn(ResponseEntity.status(HttpStatus.CONFLICT.value()).build()); @@ -129,6 +142,9 @@ void givenCreatePolicy_whenConflict_thenThrowException() { @Test void givenCreatePolicy_whenBadRequest_thenThrowException() { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getPolicyDefinition()).thenReturn("/management/v2/policydefinitions"); String policyName = "policyName"; when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class), any())).thenReturn(ResponseEntity.status(HttpStatus.BAD_REQUEST.value()).build()); @@ -140,6 +156,9 @@ void givenCreatePolicy_whenBadRequest_thenThrowException() { @Test void givenCreatePolicy_whenRestClientException_thenThrowException() { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getPolicyDefinition()).thenReturn("/management/v2/policydefinitions"); String policyName = "policyName"; when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class), any())).thenThrow(new RestClientException("Surprise")); @@ -151,6 +170,9 @@ void givenCreatePolicy_whenRestClientException_thenThrowException() { @Test void givenDeletePolicy_whenRestClientException_thenThrowException() { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getPolicyDefinition()).thenReturn("/management/v2/policydefinitions"); String policyName = "policyName"; doThrow(new RestClientException("Surprise")).when(restTemplate).delete(any(String.class)); @@ -160,8 +182,11 @@ void givenDeletePolicy_whenRestClientException_thenThrowException() { } @Test - void givenDeletePolicy_whenOk_thenCallRestTemplate() { + void givenDeletePolicy_whenOk_thenCallRestTemplate() throws DeleteEdcPolicyDefinitionException { // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + when(endpointConfig.getPolicyDefinition()).thenReturn("/management/v2/policydefinitions"); String policyName = "policyName"; // when From a12a1a3ecae1f6fa20ae2ec05d80bef991072539 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 6 Feb 2024 10:54:28 +0100 Subject: [PATCH 21/55] feature(irs-edc-client): #412 change approach for using services. now need to create beans from services with preconfigured rest templates :) --- .../irs/edc/client/asset/EdcAssetService.java | 23 ++++++++----------- .../service/EdcContractDefinitionService.java | 12 +++++----- .../service/EdcPolicyDefinitionService.java | 12 ++++------ .../edc/client/asset/EdcAssetServiceTest.java | 11 ++++----- .../EdcContractDefinitionServiceTest.java | 10 ++++---- .../EdcPolicyDefinitionServiceTest.java | 13 ++++------- 6 files changed, 35 insertions(+), 46 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java index 0857018c6e..38f033de90 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -37,7 +37,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -47,7 +46,6 @@ */ @Slf4j -@Service @RequiredArgsConstructor public class EdcAssetService { private static final String DEFAULT_CONTENT_TYPE = "application/json"; @@ -57,29 +55,26 @@ public class EdcAssetService { private final EdcTransformer edcTransformer; private final EdcConfiguration config; + private final RestTemplate restTemplate; public String createNotificationAsset(final String baseUrl, final String assetName, - final NotificationMethod notificationMethod, final NotificationType notificationType, - final RestTemplate restTemplate) throws CreateEdcAssetException { + final NotificationMethod notificationMethod, final NotificationType notificationType) + throws CreateEdcAssetException { final JsonObject request = createNotificationAssetRequest(assetName, baseUrl, notificationMethod, notificationType); - return sendRequest(request, restTemplate); + return sendRequest(request); } - public String createDtrAsset(final String baseUrl, final String assetName, final RestTemplate restTemplate) - throws CreateEdcAssetException { + public String createDtrAsset(final String baseUrl, final String assetName) throws CreateEdcAssetException { final JsonObject request = createDtrAssetRequest(assetName, baseUrl); - return sendRequest(request, restTemplate); + return sendRequest(request); } - private String sendRequest(final JsonObject request, final RestTemplate restTemplate) - throws CreateEdcAssetException { + private String sendRequest(final JsonObject request) throws CreateEdcAssetException { final ResponseEntity createEdcDataAssetResponse; try { - createEdcDataAssetResponse = restTemplate.postForEntity( - config.getControlplane().getEndpoint().getAsset(), - request, - String.class); + createEdcDataAssetResponse = restTemplate.postForEntity(config.getControlplane().getEndpoint().getAsset(), + request, String.class); final HttpStatusCode responseCode = createEdcDataAssetResponse.getStatusCode(); if (responseCode.value() == HttpStatus.CONFLICT.value()) { diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java index 28af70c55b..790299d1d7 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionService.java @@ -31,7 +31,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; @@ -40,7 +39,6 @@ */ @Slf4j -@Service @RequiredArgsConstructor public class EdcContractDefinitionService { @@ -50,15 +48,17 @@ public class EdcContractDefinitionService { private static final String CONTRACT_DEFINITION_TYPE = "ContractDefinition"; private final EdcConfiguration config; + private final RestTemplate restTemplate; - public String createContractDefinition(final String assetId, final String policyId, - final RestTemplate restTemplate) throws CreateEdcContractDefinitionException { + public String createContractDefinition(final String assetId, final String policyId) + throws CreateEdcContractDefinitionException { final EdcCreateContractDefinitionRequest createContractDefinitionRequest = createContractDefinitionRequest( assetId, policyId); final ResponseEntity createContractDefinitionResponse; try { - createContractDefinitionResponse = restTemplate.postForEntity(config.getControlplane().getEndpoint().getContractDefinition(), - createContractDefinitionRequest, String.class); + createContractDefinitionResponse = restTemplate.postForEntity( + config.getControlplane().getEndpoint().getContractDefinition(), createContractDefinitionRequest, + String.class); final HttpStatusCode responseCode = createContractDefinitionResponse.getStatusCode(); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index 9a50e0c858..f06b3605af 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -49,7 +49,6 @@ */ @Slf4j -@Service @RequiredArgsConstructor public class EdcPolicyDefinitionService { @@ -61,18 +60,16 @@ public class EdcPolicyDefinitionService { private static final String OPERATOR_PREFIX = "odrl:"; private final EdcConfiguration config; + private final RestTemplate restTemplate; - public String createAccessPolicy(final String policyName, final RestTemplate restTemplate) - throws CreateEdcPolicyDefinitionException { + public String createAccessPolicy(final String policyName) throws CreateEdcPolicyDefinitionException { final String accessPolicyId = UUID.randomUUID().toString(); final EdcCreatePolicyDefinitionRequest request = createPolicyDefinition(policyName, accessPolicyId); final ResponseEntity createPolicyDefinitionResponse; try { createPolicyDefinitionResponse = restTemplate.postForEntity( - config.getControlplane().getEndpoint().getPolicyDefinition(), - request, - String.class); + config.getControlplane().getEndpoint().getPolicyDefinition(), request, String.class); } catch (RestClientException e) { log.error("Failed to create EDC notification asset policy. Reason: ", e); @@ -137,7 +134,8 @@ public EdcCreatePolicyDefinitionRequest createPolicyDefinition(final String poli public void deleteAccessPolicy(final String accessPolicyId, final RestTemplate restTemplate) throws DeleteEdcPolicyDefinitionException { - final String deleteUri = UriComponentsBuilder.fromPath(config.getControlplane().getEndpoint().getPolicyDefinition()) + final String deleteUri = UriComponentsBuilder.fromPath( + config.getControlplane().getEndpoint().getPolicyDefinition()) .pathSegment("{accessPolicyId}") .buildAndExpand(accessPolicyId) .toUriString(); diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java index 78b1cadffb..6e4463e073 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java @@ -88,7 +88,7 @@ void setUp() { jsonLd.registerNamespace("dspace", "https://w3id.org/dspace/v0.8/"); this.edcTransformer = new EdcTransformer(objectMapper(), jsonLd, new TypeTransformerRegistryImpl()); - this.service = new EdcAssetService(edcTransformer, edcConfiguration); + this.service = new EdcAssetService(edcTransformer, edcConfiguration, restTemplate); } @Test @@ -171,8 +171,7 @@ void givenCreateNotificationAsset_whenOk_ThenReturnCreatedAssetId() throws Creat ResponseEntity.ok("test")); // when - String assetId = service.createNotificationAsset(baseUrl, assetName, notificationMethod, notificationType, - restTemplate); + String assetId = service.createNotificationAsset(baseUrl, assetName, notificationMethod, notificationType); // then assertThat(assetId).isNotBlank(); @@ -190,7 +189,7 @@ void givenCreateDtrAsset_whenOk_ThenReturnCreatedAssetId() throws CreateEdcAsset ResponseEntity.ok("test")); // when - String assetId = service.createDtrAsset(baseUrl, assetName, restTemplate); + String assetId = service.createDtrAsset(baseUrl, assetName); // then assertThat(assetId).isNotBlank(); @@ -223,7 +222,7 @@ void givenCreateDtrAsset_whenOK_ThenThrowException() { .postForEntity(any(String.class), any(JsonObject.class), any()); // when/then - assertThrows(CreateEdcAssetException.class, () -> service.createDtrAsset(baseUrl, assetName, restTemplate)); + assertThrows(CreateEdcAssetException.class, () -> service.createDtrAsset(baseUrl, assetName)); } @Test @@ -238,7 +237,7 @@ void givenCreateDtrAsset_whenTemplateException_ThenThrowException() { .postForEntity(any(String.class), any(JsonObject.class), any()); // when/then - assertThrows(CreateEdcAssetException.class, () -> service.createDtrAsset(baseUrl, assetName, restTemplate)); + assertThrows(CreateEdcAssetException.class, () -> service.createDtrAsset(baseUrl, assetName)); } @Test diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java index 6ed1aa4954..5e6ec5e280 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractDefinitionServiceTest.java @@ -58,7 +58,7 @@ class EdcContractDefinitionServiceTest { @BeforeEach void setUp() { this.objectMapper = new ObjectMapper(); - this.service = new EdcContractDefinitionService(edcConfiguration); + this.service = new EdcContractDefinitionService(edcConfiguration, restTemplate); } @Test @@ -101,7 +101,7 @@ void givenCreateContractDefinition_whenOK_thenReturnPolicyId() throws CreateEdcC when(restTemplate.postForEntity(any(String.class), any(EdcCreateContractDefinitionRequest.class), any())).thenReturn(ResponseEntity.ok("test")); - String result = service.createContractDefinition(assetId, policyId, restTemplate); + String result = service.createContractDefinition(assetId, policyId); assertThat(result).isEqualTo(policyId); } @@ -118,7 +118,7 @@ void givenCreateContractDefinition_whenConflict_thenThrowException() { any())).thenReturn(ResponseEntity.status(HttpStatus.CONFLICT.value()).build()); assertThrows(CreateEdcContractDefinitionException.class, - () -> service.createContractDefinition(assetId, policyId, restTemplate)); + () -> service.createContractDefinition(assetId, policyId)); } @Test @@ -132,7 +132,7 @@ void givenCreateContractDefinition_whenBadRequest_thenThrowException() { any())).thenReturn(ResponseEntity.status(HttpStatus.BAD_REQUEST.value()).build()); assertThrows(CreateEdcContractDefinitionException.class, - () -> service.createContractDefinition(assetId, policyId, restTemplate)); + () -> service.createContractDefinition(assetId, policyId)); } @Test @@ -147,7 +147,7 @@ void givenCreateContractDefinition_whenRestClientException_thenThrowException() any())).thenThrow(new RestClientException("Surprise")); assertThrows(CreateEdcContractDefinitionException.class, - () -> service.createContractDefinition(assetId, policyId, restTemplate)); + () -> service.createContractDefinition(assetId, policyId)); } } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java index a6a258e186..60f471e5c5 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java @@ -63,7 +63,7 @@ class EdcPolicyDefinitionServiceTest { @BeforeEach void setUp() { this.objectMapper = new ObjectMapper(); - this.service = new EdcPolicyDefinitionService(edcConfiguration); + this.service = new EdcPolicyDefinitionService(edcConfiguration, restTemplate); } @Test @@ -119,7 +119,7 @@ void givenPolicy_WhenCreateAccessPolicy_ThenCreateIt() throws CreateEdcPolicyDef any())).thenReturn(ResponseEntity.ok("test")); // when - String result = service.createAccessPolicy(policyName, restTemplate); + String result = service.createAccessPolicy(policyName); // then assertThat(result).isNotBlank(); @@ -135,8 +135,7 @@ void givenCreatePolicy_whenConflict_thenThrowException() { when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class), any())).thenReturn(ResponseEntity.status(HttpStatus.CONFLICT.value()).build()); - assertThrows(CreateEdcPolicyDefinitionException.class, - () -> service.createAccessPolicy(policyName, restTemplate)); + assertThrows(CreateEdcPolicyDefinitionException.class, () -> service.createAccessPolicy(policyName)); } @Test @@ -149,8 +148,7 @@ void givenCreatePolicy_whenBadRequest_thenThrowException() { when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class), any())).thenReturn(ResponseEntity.status(HttpStatus.BAD_REQUEST.value()).build()); - assertThrows(CreateEdcPolicyDefinitionException.class, - () -> service.createAccessPolicy(policyName, restTemplate)); + assertThrows(CreateEdcPolicyDefinitionException.class, () -> service.createAccessPolicy(policyName)); } @Test @@ -163,8 +161,7 @@ void givenCreatePolicy_whenRestClientException_thenThrowException() { when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class), any())).thenThrow(new RestClientException("Surprise")); - assertThrows(CreateEdcPolicyDefinitionException.class, - () -> service.createAccessPolicy(policyName, restTemplate)); + assertThrows(CreateEdcPolicyDefinitionException.class, () -> service.createAccessPolicy(policyName)); } @Test From f2552af0e12d56742c3b49f82700f8df47680947 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 6 Feb 2024 10:59:11 +0100 Subject: [PATCH 22/55] feature(irs-edc-client): #412 remove unused import --- .../edc/client/policy/service/EdcPolicyDefinitionService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index f06b3605af..2c5942a155 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -39,7 +39,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; From 32ab6218e6e4fb6b877a063ae5f7ef96bf7f9faa Mon Sep 17 00:00:00 2001 From: "Krzysztof Massalski (Extern)" Date: Thu, 8 Feb 2024 10:24:56 +0100 Subject: [PATCH 23/55] feat(impl):[#396] fix log4j config --- irs-api/src/main/resources/application.yml | 8 +------- irs-api/src/main/resources/log4j2.xml | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/irs-api/src/main/resources/application.yml b/irs-api/src/main/resources/application.yml index cfa958d815..54715476c1 100644 --- a/irs-api/src/main/resources/application.yml +++ b/irs-api/src/main/resources/application.yml @@ -59,13 +59,7 @@ management: # Spring management API config, see https://spring.io/guides/gs/cent server: port: 4004 -logging: - pattern: - console: "%d %-5level %logger : %msg%n" - level: - root: WARN - org.springframework: INFO - org.eclipse.tractusx.irs: INFO +logging.config: "classpath:log4j2.xml" springdoc: # API docs configuration api-docs: diff --git a/irs-api/src/main/resources/log4j2.xml b/irs-api/src/main/resources/log4j2.xml index 4c2ec2ff00..b4d0162ce7 100644 --- a/irs-api/src/main/resources/log4j2.xml +++ b/irs-api/src/main/resources/log4j2.xml @@ -8,7 +8,7 @@ - + From eaa84ca067562f3e8f4a3484a38c88f15d0b0fde Mon Sep 17 00:00:00 2001 From: ds-alexander-bulgakov Date: Fri, 9 Feb 2024 13:30:10 +0100 Subject: [PATCH 24/55] feat(testing):[416] fixed test method for TRI-912 --- local/testing/api-tests/tavern_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/local/testing/api-tests/tavern_helpers.py b/local/testing/api-tests/tavern_helpers.py index 50a0a0164e..160feefec9 100644 --- a/local/testing/api-tests/tavern_helpers.py +++ b/local/testing/api-tests/tavern_helpers.py @@ -135,7 +135,7 @@ def submodelDescriptors_in_shells_are_empty(response): shells = response.json().get("shells") print("shells ", shells) for i in shells: - assert len(i.get("submodelDescriptors")) == 0 + assert len(i.get("payload").get("submodelDescriptors")) == 0 def aspects_in_job_parameter_are_empty(response): From 5a77150b43b50987de8cb7e6b3063d480fb76dd9 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Mon, 12 Feb 2024 14:10:11 +0100 Subject: [PATCH 25/55] chore(logging):[#xxx] Reduce log level to TRACE in MeterRegistryService the method setStateSnapShot is called every 10 seconds via scheduler, therefore reduced log level to TRACE here --- .../eclipse/tractusx/irs/services/MeterRegistryService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/services/MeterRegistryService.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/services/MeterRegistryService.java index 7f2013f32c..8b5cd0b963 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/services/MeterRegistryService.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/services/MeterRegistryService.java @@ -186,7 +186,7 @@ public void setMeasuredMethodExecutionTime(final String tag, final long duration } public void setStateSnapShot(final JobState state, final long value) { - log.debug("Update State {} snapshot to {} ", state, value); + log.trace("Update State {} snapshot to {} ", state, value); switch (state) { case COMPLETED: snapshotCompletedValue.set(value); @@ -201,7 +201,7 @@ public void setStateSnapShot(final JobState state, final long value) { snapshotFailedValue.set(value); break; default: - log.debug("Unused State {} value {} ", state, value); + log.trace("Unused State {} value {} ", state, value); break; } } From 42469b0cbff3fd91cb29d4a504838ae49d606006 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 12 Feb 2024 16:45:53 +0100 Subject: [PATCH 26/55] feature(irs-edc-client): #412 temp changes shared --- .../configuration/RegistryConfiguration.java | 5 +- .../ProtocolInformation.java | 4 + .../registryclient/DefaultConfiguration.java | 4 +- .../DigitalTwinRegistryService.java | 9 +++ .../DecentralDigitalTwinRegistryClient.java | 11 +++ .../DecentralDigitalTwinRegistryService.java | 29 ++++--- ...ecentralDigitalTwinRegistryClientTest.java | 80 ++++++++++++++++++- ...igitalTwinRegistryServiceWiremockTest.java | 3 +- .../testing/wiremock/DtrWiremockSupport.java | 2 + 9 files changed, 130 insertions(+), 17 deletions(-) diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java index db7de31bb7..73a532687a 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java @@ -70,6 +70,7 @@ public DigitalTwinRegistryClient digitalTwinRegistryClientImpl( public DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService( @Qualifier(RestTemplateConfig.EDC_REST_TEMPLATE) final RestTemplate edcRestTemplate, final ConnectorEndpointsService connectorEndpointsService, final EdcSubmodelFacade facade, + @Value("${digitalTwinRegistry.createShellDescriptorTemplate:}") final String createShellDescriptorTemplate, @Value("${digitalTwinRegistry.shellDescriptorTemplate:}") final String shellDescriptorTemplate, @Value("${digitalTwinRegistry.lookupShellsTemplate:}") final String lookupShellsTemplate) { return new DecentralDigitalTwinRegistryService(connectorEndpointsService, @@ -79,8 +80,8 @@ public DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService( } catch (EdcClientException e) { throw new EdcRetrieverException(e); } - }), - new DecentralDigitalTwinRegistryClient(edcRestTemplate, shellDescriptorTemplate, lookupShellsTemplate)); + }), new DecentralDigitalTwinRegistryClient(edcRestTemplate, createShellDescriptorTemplate, + shellDescriptorTemplate, lookupShellsTemplate)); } @Bean diff --git a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/ProtocolInformation.java b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/ProtocolInformation.java index e1c204c142..2885265ef4 100644 --- a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/ProtocolInformation.java +++ b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/ProtocolInformation.java @@ -66,5 +66,9 @@ public class ProtocolInformation { * subprotocolBodyEncoding */ private String subprotocolBodyEncoding; + /** + * securityAttributes + */ + private List securityAttributes; } diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java index 613c12db3c..37256fcb1d 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java @@ -146,9 +146,11 @@ public EdcSubmodelClient edcSubmodelClient(final EdcConfiguration edcConfigurati @ConditionalOnProperty(prefix = CONFIG_PREFIX, name = CONFIG_FIELD_TYPE, havingValue = CONFIG_VALUE_DECENTRAL) public DecentralDigitalTwinRegistryClient decentralDigitalTwinRegistryClient( @Qualifier(EDC_REST_TEMPLATE) final RestTemplate edcRestTemplate, + @Value("${digitalTwinRegistryClient.createShellDescriptorTemplate:}") final String createShellDescriptorTemplate, @Value("${digitalTwinRegistryClient.shellDescriptorTemplate:}") final String shellDescriptorTemplate, @Value("${digitalTwinRegistryClient.lookupShellsTemplate:}") final String lookupShellsTemplate) { - return new DecentralDigitalTwinRegistryClient(edcRestTemplate, shellDescriptorTemplate, lookupShellsTemplate); + return new DecentralDigitalTwinRegistryClient(edcRestTemplate, createShellDescriptorTemplate, + shellDescriptorTemplate, lookupShellsTemplate); } @Bean diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DigitalTwinRegistryService.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DigitalTwinRegistryService.java index 153acd3140..4e71b5d5e2 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DigitalTwinRegistryService.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DigitalTwinRegistryService.java @@ -26,6 +26,7 @@ import java.util.Collection; import org.eclipse.tractusx.irs.component.Shell; +import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; /** @@ -71,4 +72,12 @@ default Collection lookupShells(final String bpn) throws */ Collection fetchShells(Collection identifiers) throws RegistryServiceException; + + /** + * Created Shell. + * + * @param assetAdministrationShellDescriptor the shell to create + * @return the shell descriptors + */ + AssetAdministrationShellDescriptor createShell(final AssetAdministrationShellDescriptor assetAdministrationShellDescriptor); } diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClient.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClient.java index 1c7a7ed5b3..78a49d31e3 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClient.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClient.java @@ -23,6 +23,7 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.registryclient.decentral; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.List; @@ -54,6 +55,7 @@ public class DecentralDigitalTwinRegistryClient { private final String lookupShellsTemplate; public DecentralDigitalTwinRegistryClient(final RestTemplate edcRestTemplate, + @Value("${digitalTwinRegistry.createShellDescriptorTemplate:}") final String createShellDescriptorTemplate, @Value("${digitalTwinRegistry.shellDescriptorTemplate:}") final String shellDescriptorTemplate, @Value("${digitalTwinRegistry.lookupShellsTemplate:}") final String lookupShellsTemplate) { this.edcRestTemplate = edcRestTemplate; @@ -65,6 +67,15 @@ private static String encodeWithBase64(final String aasIdentifier) { return Base64.getEncoder().encodeToString(aasIdentifier.getBytes(StandardCharsets.UTF_8)); } + public AssetAdministrationShellDescriptor createShell( + AssetAdministrationShellDescriptor assetAdministrationShellDescriptor, + EndpointDataReference endpointDataReference) { + final String descriptorEndpoint = endpointDataReference.getEndpoint() + shellDescriptorTemplate; + return edcRestTemplate.exchange(URI.create(descriptorEndpoint), HttpMethod.POST, + new HttpEntity<>(assetAdministrationShellDescriptor, headers(endpointDataReference)), + AssetAdministrationShellDescriptor.class).getBody(); + } + @Retry(name = "registry") public AssetAdministrationShellDescriptor getAssetAdministrationShellDescriptor( final EndpointDataReference endpointDataReference, final String aasIdentifier) { diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryService.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryService.java index 9fb4065879..3e5f7aea3e 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryService.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryService.java @@ -121,8 +121,14 @@ public Collection fetchShells(final Collection ke } } - private Stream fetchShellDescriptors( - final Map.Entry> entry, final Set calledEndpoints) { + @Override + public AssetAdministrationShellDescriptor createShell( + final AssetAdministrationShellDescriptor assetAdministrationShellDescriptor) { + + } + + private Stream fetchShellDescriptors(final Map.Entry> entry, + final Set calledEndpoints) { try { @@ -140,8 +146,8 @@ private Stream fetchShellDescriptors( } } - private CompletableFuture> fetchShellDescriptors( - final Set calledEndpoints, final String bpn, final List keys) { + private CompletableFuture> fetchShellDescriptors(final Set calledEndpoints, final String bpn, + final List keys) { final var watch = new StopWatch(); final String msg = "Fetching %s shells for bpn '%s'".formatted(keys.size(), bpn); @@ -177,8 +183,8 @@ private CompletableFuture> fetchShellDescriptorsForConnectorEndpoint return resultFinder.getFastestResult(futures); } - private List fetchShellDescriptorsForKey( - final List keys, final EndpointDataReference endpointDataReference) { + private List fetchShellDescriptorsForKey(final List keys, + final EndpointDataReference endpointDataReference) { final var watch = new StopWatch(); final String msg = "Fetching shell descriptors for keys %s from endpoint '%s'".formatted(keys, @@ -186,8 +192,10 @@ private List fetchShellDescriptorsForKey( watch.start(msg); log.info(msg); try { - return keys.stream().map(key -> new Shell(contractNegotiationId(endpointDataReference.getAuthCode()), - fetchShellDescriptor(endpointDataReference, key))).toList(); + return keys.stream() + .map(key -> new Shell(contractNegotiationId(endpointDataReference.getAuthCode()), + fetchShellDescriptor(endpointDataReference, key))) + .toList(); } finally { watch.stop(); log.info(TOOK_MS, watch.getLastTaskName(), watch.getLastTaskTimeMillis()); @@ -212,10 +220,7 @@ private AssetAdministrationShellDescriptor fetchShellDescriptor(final EndpointDa } private String contractNegotiationId(final String token) { - return Optional.ofNullable(token) - .map(EDRAuthCode::fromAuthCodeToken) - .map(EDRAuthCode::getCid) - .orElse(""); + return Optional.ofNullable(token).map(EDRAuthCode::fromAuthCodeToken).map(EDRAuthCode::getCid).orElse(""); } /** diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClientTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClientTest.java index 823fa5a175..aa7115c138 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClientTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClientTest.java @@ -1,5 +1,6 @@ package org.eclipse.tractusx.irs.registryclient.decentral; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -9,18 +10,29 @@ import java.net.URI; import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.Optional; import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference; import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; +import org.eclipse.tractusx.irs.component.assetadministrationshell.Endpoint; +import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; +import org.eclipse.tractusx.irs.component.assetadministrationshell.ProtocolInformation; +import org.eclipse.tractusx.irs.component.assetadministrationshell.Reference; +import org.eclipse.tractusx.irs.component.assetadministrationshell.SecurityAttribute; +import org.eclipse.tractusx.irs.component.assetadministrationshell.SemanticId; +import org.eclipse.tractusx.irs.component.assetadministrationshell.SubmodelDescriptor; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; +import org.testcontainers.shaded.com.fasterxml.jackson.core.JsonProcessingException; +import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; class DecentralDigitalTwinRegistryClientTest { + public static final String CREATE_SHELL_DESCRIPTORS = "/shell-descriptors"; public static final String SHELL_DESCRIPTORS = "/shell-descriptors/{aasIdentifier}"; public static final String LOOKUP_SHELLS = "/lookup/shells"; RestTemplate restTemplate = mock(RestTemplate.class); @@ -28,7 +40,7 @@ class DecentralDigitalTwinRegistryClientTest { @BeforeEach void setUp() { - client = new DecentralDigitalTwinRegistryClient(restTemplate, SHELL_DESCRIPTORS, LOOKUP_SHELLS); + client = new DecentralDigitalTwinRegistryClient(restTemplate, CREATE_SHELL_DESCRIPTORS, SHELL_DESCRIPTORS, LOOKUP_SHELLS); } @Test @@ -65,4 +77,70 @@ void shouldCallForAllAssetAdministrationShellIdsByAssetLink() { verify(restTemplate).exchange(any(), eq(HttpMethod.GET), any(), eq(LookupShellsResponse.class)); } + @Test + void test() throws JsonProcessingException { + AssetAdministrationShellDescriptor test = AssetAdministrationShellDescriptor.builder() + .globalAssetId( + "urn:uuid:254604ab-2153-45fb-8cad-54ef09f4080f") + .idShort("test") + .id("urn:uuid:25300562-aa66-4840-8952-5cef4ed667c2") + .specificAssetIds( + List.of(IdentifierKeyValuePair.builder() + .name("manufacturerId") + .value("BPNL00000003CNKC") + .subjectId( + Reference.builder() + .keys(List.of( + SemanticId.builder() + .type("GlobalReference") + .value("PUBLIC_READABLE") + .build())) + .build()) + .build())) + .submodelDescriptors( + List.of(SubmodelDescriptor.builder() + .idShort( + "SingleLevelUsageAsBuilt") + .id("urn:uuid:e401ccb7-a8f5-499a-9340-93746822d775") + .semanticId( + Reference.builder() + .type("ExternalReference") + .keys(List.of( + SemanticId.builder() + .type("GlobalReference") + .value("urn:bamm:io.catenax.single_level_usage_as_built:2.0.0#SingleLevelUsageAsBuilt") + .build())) + .build() + + ) + .endpoints( + List.of(Endpoint.builder() + .interfaceInformation( + "SUBMODEL-3.0") + .protocolInformation( + ProtocolInformation.builder() + .href("https://trace-x-edc-dataplane.dev.demo.catena-x.net/api/public/data/urn:uuid:e401ccb7-a8f5-499a-9340-93746822d775") + .endpointProtocol( + "HTTP") + .endpointProtocolVersion( + List.of("1.1")) + .subprotocol( + "DSP") + .subprotocolBody( + "id=urn:uuid:cb6d86b5-b8ea-4fc0-b10b-ff2dd62f793d;dspEndpoint=https://trace-x-edc.dev.demo.catena-x.net") + .subprotocolBodyEncoding( + "plain") + .securityAttributes( + List.of(SecurityAttribute.none())) + + .build()) + .build())) + .build())) + .build(); + + ObjectMapper m = new ObjectMapper(); + + assertThat(m.writeValueAsString(test)).isNotBlank(); + } + } \ No newline at end of file diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java index 36ce0ff1b6..9b4ca73f74 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java @@ -36,6 +36,7 @@ import static org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport.postDiscoveryFinder404; import static org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport.postEdcDiscovery200; import static org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport.postEdcDiscovery404; +import static org.eclipse.tractusx.irs.testing.wiremock.DtrWiremockSupport.CREATE_SHELL_DESCRIPTOR_PATH; import static org.eclipse.tractusx.irs.testing.wiremock.DtrWiremockSupport.DATAPLANE_URL; import static org.eclipse.tractusx.irs.testing.wiremock.DtrWiremockSupport.LOOKUP_SHELLS_PATH; import static org.eclipse.tractusx.irs.testing.wiremock.DtrWiremockSupport.LOOKUP_SHELLS_TEMPLATE; @@ -87,7 +88,7 @@ void setUp(WireMockRuntimeInfo wireMockRuntimeInfo) throws EdcRetrieverException final var connectorEndpointsService = new ConnectorEndpointsService(discoveryFinderClient); final var endpointDataForConnectorsService = new EndpointDataForConnectorsService(edcSubmodelFacadeMock); final var decentralDigitalTwinRegistryClient = new DecentralDigitalTwinRegistryClient(restTemplate, - SHELL_DESCRIPTORS_TEMPLATE, LOOKUP_SHELLS_TEMPLATE); + CREATE_SHELL_DESCRIPTOR_PATH, SHELL_DESCRIPTORS_TEMPLATE, LOOKUP_SHELLS_TEMPLATE); decentralDigitalTwinRegistryService = new DecentralDigitalTwinRegistryService(connectorEndpointsService, endpointDataForConnectorsService, decentralDigitalTwinRegistryClient); final var endpointDataReference = endpointDataReference("assetId"); diff --git a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockSupport.java b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockSupport.java index f269e1713b..2b340e813e 100644 --- a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockSupport.java +++ b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockSupport.java @@ -35,6 +35,8 @@ public final class DtrWiremockSupport { public static final String DATAPLANE_URL = "http://dataplane.test"; public static final String DATAPLANE_PUBLIC_PATH = "/api/public"; public static final String DATAPLANE_PUBLIC_URL = DATAPLANE_URL + DATAPLANE_PUBLIC_PATH; + + public static final String CREATE_SHELL_DESCRIPTOR_PATH = "/shell-descriptors"; public static final String SHELL_DESCRIPTORS_PATH = "/shell-descriptors/"; public static final String PUBLIC_SHELL_DESCRIPTORS_PATH = DATAPLANE_PUBLIC_PATH + SHELL_DESCRIPTORS_PATH; public static final String SHELL_DESCRIPTORS_TEMPLATE = SHELL_DESCRIPTORS_PATH + "{aasIdentifier}"; From 476fb0847cb70febd8b03bdea88ee883d28ec0c9 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 12 Feb 2024 16:52:48 +0100 Subject: [PATCH 27/55] feature(irs-edc-client): #412 temp changes shared --- .../SecurityAttribute.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/SecurityAttribute.java diff --git a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/SecurityAttribute.java b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/SecurityAttribute.java new file mode 100644 index 0000000000..40dd0726c8 --- /dev/null +++ b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/SecurityAttribute.java @@ -0,0 +1,48 @@ +/******************************************************************************** + * 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.component.assetadministrationshell; + +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +@Builder +@Jacksonized +public class SecurityAttribute { + + /** + * type + */ + private String type; + /** + * key + */ + private String key; + /** + * value + */ + private String value; + + public static SecurityAttribute none() { + return SecurityAttribute.builder().type("NONE").key("NONE").value("NONE").build(); + } +} From c8cbab35c17c28bd6d9b2ea7b815157f74af4797 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 12 Feb 2024 21:50:51 +0100 Subject: [PATCH 28/55] feature(irs-edc-client): #412 refactor a bit for better usability --- .../configuration/RegistryConfiguration.java | 5 +- .../registryclient/DefaultConfiguration.java | 4 +- .../DigitalTwinRegistryService.java | 12 +- .../DecentralDigitalTwinRegistryClient.java | 10 -- .../DecentralDigitalTwinRegistryService.java | 6 - .../decentral/DigitalTwinRegistryService.java | 68 +++++++ .../exception/CreateDtrShellException.java | 34 ++++ ...ecentralDigitalTwinRegistryClientTest.java | 69 +------ ...igitalTwinRegistryServiceWiremockTest.java | 3 +- .../DigitalTwinRegistryServiceTest.java | 169 ++++++++++++++++++ .../testing/wiremock/DtrWiremockSupport.java | 23 +-- 11 files changed, 290 insertions(+), 113 deletions(-) create mode 100644 irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryService.java create mode 100644 irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/exception/CreateDtrShellException.java create mode 100644 irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryServiceTest.java diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java index 73a532687a..db7de31bb7 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/RegistryConfiguration.java @@ -70,7 +70,6 @@ public DigitalTwinRegistryClient digitalTwinRegistryClientImpl( public DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService( @Qualifier(RestTemplateConfig.EDC_REST_TEMPLATE) final RestTemplate edcRestTemplate, final ConnectorEndpointsService connectorEndpointsService, final EdcSubmodelFacade facade, - @Value("${digitalTwinRegistry.createShellDescriptorTemplate:}") final String createShellDescriptorTemplate, @Value("${digitalTwinRegistry.shellDescriptorTemplate:}") final String shellDescriptorTemplate, @Value("${digitalTwinRegistry.lookupShellsTemplate:}") final String lookupShellsTemplate) { return new DecentralDigitalTwinRegistryService(connectorEndpointsService, @@ -80,8 +79,8 @@ public DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService( } catch (EdcClientException e) { throw new EdcRetrieverException(e); } - }), new DecentralDigitalTwinRegistryClient(edcRestTemplate, createShellDescriptorTemplate, - shellDescriptorTemplate, lookupShellsTemplate)); + }), + new DecentralDigitalTwinRegistryClient(edcRestTemplate, shellDescriptorTemplate, lookupShellsTemplate)); } @Bean diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java index 37256fcb1d..613c12db3c 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DefaultConfiguration.java @@ -146,11 +146,9 @@ public EdcSubmodelClient edcSubmodelClient(final EdcConfiguration edcConfigurati @ConditionalOnProperty(prefix = CONFIG_PREFIX, name = CONFIG_FIELD_TYPE, havingValue = CONFIG_VALUE_DECENTRAL) public DecentralDigitalTwinRegistryClient decentralDigitalTwinRegistryClient( @Qualifier(EDC_REST_TEMPLATE) final RestTemplate edcRestTemplate, - @Value("${digitalTwinRegistryClient.createShellDescriptorTemplate:}") final String createShellDescriptorTemplate, @Value("${digitalTwinRegistryClient.shellDescriptorTemplate:}") final String shellDescriptorTemplate, @Value("${digitalTwinRegistryClient.lookupShellsTemplate:}") final String lookupShellsTemplate) { - return new DecentralDigitalTwinRegistryClient(edcRestTemplate, createShellDescriptorTemplate, - shellDescriptorTemplate, lookupShellsTemplate); + return new DecentralDigitalTwinRegistryClient(edcRestTemplate, shellDescriptorTemplate, lookupShellsTemplate); } @Bean diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DigitalTwinRegistryService.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DigitalTwinRegistryService.java index 4e71b5d5e2..2c844c4029 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DigitalTwinRegistryService.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DigitalTwinRegistryService.java @@ -26,7 +26,6 @@ import java.util.Collection; import org.eclipse.tractusx.irs.component.Shell; -import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; /** @@ -70,14 +69,5 @@ default Collection lookupShells(final String bpn) throws * @param identifiers the shell identifiers * @return the shell descriptors */ - Collection fetchShells(Collection identifiers) - throws RegistryServiceException; - - /** - * Created Shell. - * - * @param assetAdministrationShellDescriptor the shell to create - * @return the shell descriptors - */ - AssetAdministrationShellDescriptor createShell(final AssetAdministrationShellDescriptor assetAdministrationShellDescriptor); + Collection fetchShells(Collection identifiers) throws RegistryServiceException; } diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClient.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClient.java index 78a49d31e3..fe976aa72e 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClient.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClient.java @@ -55,7 +55,6 @@ public class DecentralDigitalTwinRegistryClient { private final String lookupShellsTemplate; public DecentralDigitalTwinRegistryClient(final RestTemplate edcRestTemplate, - @Value("${digitalTwinRegistry.createShellDescriptorTemplate:}") final String createShellDescriptorTemplate, @Value("${digitalTwinRegistry.shellDescriptorTemplate:}") final String shellDescriptorTemplate, @Value("${digitalTwinRegistry.lookupShellsTemplate:}") final String lookupShellsTemplate) { this.edcRestTemplate = edcRestTemplate; @@ -67,15 +66,6 @@ private static String encodeWithBase64(final String aasIdentifier) { return Base64.getEncoder().encodeToString(aasIdentifier.getBytes(StandardCharsets.UTF_8)); } - public AssetAdministrationShellDescriptor createShell( - AssetAdministrationShellDescriptor assetAdministrationShellDescriptor, - EndpointDataReference endpointDataReference) { - final String descriptorEndpoint = endpointDataReference.getEndpoint() + shellDescriptorTemplate; - return edcRestTemplate.exchange(URI.create(descriptorEndpoint), HttpMethod.POST, - new HttpEntity<>(assetAdministrationShellDescriptor, headers(endpointDataReference)), - AssetAdministrationShellDescriptor.class).getBody(); - } - @Retry(name = "registry") public AssetAdministrationShellDescriptor getAssetAdministrationShellDescriptor( final EndpointDataReference endpointDataReference, final String aasIdentifier) { diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryService.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryService.java index 3e5f7aea3e..c7258869eb 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryService.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryService.java @@ -121,12 +121,6 @@ public Collection fetchShells(final Collection ke } } - @Override - public AssetAdministrationShellDescriptor createShell( - final AssetAdministrationShellDescriptor assetAdministrationShellDescriptor) { - - } - private Stream fetchShellDescriptors(final Map.Entry> entry, final Set calledEndpoints) { diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryService.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryService.java new file mode 100644 index 0000000000..333129298e --- /dev/null +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryService.java @@ -0,0 +1,68 @@ +/******************************************************************************** + * 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.registryclient.decentral; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; +import org.eclipse.tractusx.irs.registryclient.decentral.exception.CreateDtrShellException; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; + +@Slf4j +@RequiredArgsConstructor +public class DigitalTwinRegistryService { + + private final RestTemplate restTemplate; + private final String createShellUrl; + + public AssetAdministrationShellDescriptor createShell( + final AssetAdministrationShellDescriptor assetAdministrationShellDescriptor) + throws CreateDtrShellException { + final ResponseEntity createdShellResponse; + try { + createdShellResponse = restTemplate.postForEntity(createShellUrl, + new HttpEntity<>(assetAdministrationShellDescriptor, headers()), + AssetAdministrationShellDescriptor.class); + final HttpStatusCode responseCode = createdShellResponse.getStatusCode(); + + if (responseCode.value() == HttpStatus.CREATED.value()) { + return createdShellResponse.getBody(); + } + } catch (RestClientException e) { + throw new CreateDtrShellException(e); + } + throw new CreateDtrShellException( + "Failed to create shell %s".formatted(assetAdministrationShellDescriptor.getGlobalAssetId())); + } + + private HttpHeaders headers() { + final HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + return headers; + } +} diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/exception/CreateDtrShellException.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/exception/CreateDtrShellException.java new file mode 100644 index 0000000000..15862e15fc --- /dev/null +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/exception/CreateDtrShellException.java @@ -0,0 +1,34 @@ +/******************************************************************************** + * 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.registryclient.decentral.exception; + +/** + * CreateDtrShellException used for create asset failure + */ +public class CreateDtrShellException extends Exception { + public CreateDtrShellException(final String message) { + super(message); + } + + public CreateDtrShellException(final Throwable cause) { + super(cause); + } +} diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClientTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClientTest.java index aa7115c138..70d905e572 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClientTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClientTest.java @@ -32,7 +32,6 @@ class DecentralDigitalTwinRegistryClientTest { - public static final String CREATE_SHELL_DESCRIPTORS = "/shell-descriptors"; public static final String SHELL_DESCRIPTORS = "/shell-descriptors/{aasIdentifier}"; public static final String LOOKUP_SHELLS = "/lookup/shells"; RestTemplate restTemplate = mock(RestTemplate.class); @@ -40,7 +39,7 @@ class DecentralDigitalTwinRegistryClientTest { @BeforeEach void setUp() { - client = new DecentralDigitalTwinRegistryClient(restTemplate, CREATE_SHELL_DESCRIPTORS, SHELL_DESCRIPTORS, LOOKUP_SHELLS); + client = new DecentralDigitalTwinRegistryClient(restTemplate, SHELL_DESCRIPTORS, LOOKUP_SHELLS); } @Test @@ -77,70 +76,4 @@ void shouldCallForAllAssetAdministrationShellIdsByAssetLink() { verify(restTemplate).exchange(any(), eq(HttpMethod.GET), any(), eq(LookupShellsResponse.class)); } - @Test - void test() throws JsonProcessingException { - AssetAdministrationShellDescriptor test = AssetAdministrationShellDescriptor.builder() - .globalAssetId( - "urn:uuid:254604ab-2153-45fb-8cad-54ef09f4080f") - .idShort("test") - .id("urn:uuid:25300562-aa66-4840-8952-5cef4ed667c2") - .specificAssetIds( - List.of(IdentifierKeyValuePair.builder() - .name("manufacturerId") - .value("BPNL00000003CNKC") - .subjectId( - Reference.builder() - .keys(List.of( - SemanticId.builder() - .type("GlobalReference") - .value("PUBLIC_READABLE") - .build())) - .build()) - .build())) - .submodelDescriptors( - List.of(SubmodelDescriptor.builder() - .idShort( - "SingleLevelUsageAsBuilt") - .id("urn:uuid:e401ccb7-a8f5-499a-9340-93746822d775") - .semanticId( - Reference.builder() - .type("ExternalReference") - .keys(List.of( - SemanticId.builder() - .type("GlobalReference") - .value("urn:bamm:io.catenax.single_level_usage_as_built:2.0.0#SingleLevelUsageAsBuilt") - .build())) - .build() - - ) - .endpoints( - List.of(Endpoint.builder() - .interfaceInformation( - "SUBMODEL-3.0") - .protocolInformation( - ProtocolInformation.builder() - .href("https://trace-x-edc-dataplane.dev.demo.catena-x.net/api/public/data/urn:uuid:e401ccb7-a8f5-499a-9340-93746822d775") - .endpointProtocol( - "HTTP") - .endpointProtocolVersion( - List.of("1.1")) - .subprotocol( - "DSP") - .subprotocolBody( - "id=urn:uuid:cb6d86b5-b8ea-4fc0-b10b-ff2dd62f793d;dspEndpoint=https://trace-x-edc.dev.demo.catena-x.net") - .subprotocolBodyEncoding( - "plain") - .securityAttributes( - List.of(SecurityAttribute.none())) - - .build()) - .build())) - .build())) - .build(); - - ObjectMapper m = new ObjectMapper(); - - assertThat(m.writeValueAsString(test)).isNotBlank(); - } - } \ No newline at end of file diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java index 9b4ca73f74..36ce0ff1b6 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java @@ -36,7 +36,6 @@ import static org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport.postDiscoveryFinder404; import static org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport.postEdcDiscovery200; import static org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport.postEdcDiscovery404; -import static org.eclipse.tractusx.irs.testing.wiremock.DtrWiremockSupport.CREATE_SHELL_DESCRIPTOR_PATH; import static org.eclipse.tractusx.irs.testing.wiremock.DtrWiremockSupport.DATAPLANE_URL; import static org.eclipse.tractusx.irs.testing.wiremock.DtrWiremockSupport.LOOKUP_SHELLS_PATH; import static org.eclipse.tractusx.irs.testing.wiremock.DtrWiremockSupport.LOOKUP_SHELLS_TEMPLATE; @@ -88,7 +87,7 @@ void setUp(WireMockRuntimeInfo wireMockRuntimeInfo) throws EdcRetrieverException final var connectorEndpointsService = new ConnectorEndpointsService(discoveryFinderClient); final var endpointDataForConnectorsService = new EndpointDataForConnectorsService(edcSubmodelFacadeMock); final var decentralDigitalTwinRegistryClient = new DecentralDigitalTwinRegistryClient(restTemplate, - CREATE_SHELL_DESCRIPTOR_PATH, SHELL_DESCRIPTORS_TEMPLATE, LOOKUP_SHELLS_TEMPLATE); + SHELL_DESCRIPTORS_TEMPLATE, LOOKUP_SHELLS_TEMPLATE); decentralDigitalTwinRegistryService = new DecentralDigitalTwinRegistryService(connectorEndpointsService, endpointDataForConnectorsService, decentralDigitalTwinRegistryClient); final var endpointDataReference = endpointDataReference("assetId"); diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryServiceTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryServiceTest.java new file mode 100644 index 0000000000..4c413edf4d --- /dev/null +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryServiceTest.java @@ -0,0 +1,169 @@ +/******************************************************************************** + * 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.registryclient.decentral; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.when; + +import java.util.List; + +import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; +import org.eclipse.tractusx.irs.component.assetadministrationshell.Endpoint; +import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; +import org.eclipse.tractusx.irs.component.assetadministrationshell.ProtocolInformation; +import org.eclipse.tractusx.irs.component.assetadministrationshell.Reference; +import org.eclipse.tractusx.irs.component.assetadministrationshell.SecurityAttribute; +import org.eclipse.tractusx.irs.component.assetadministrationshell.SemanticId; +import org.eclipse.tractusx.irs.component.assetadministrationshell.SubmodelDescriptor; +import org.eclipse.tractusx.irs.registryclient.decentral.exception.CreateDtrShellException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; + +@ExtendWith(MockitoExtension.class) +class DigitalTwinRegistryServiceTest { + + private static final String CREATE_SHELL_URL = "/shell-descriptors"; + @Mock + private RestTemplate restTemplate; + private DigitalTwinRegistryService service; + + @BeforeEach + void setUp() { + service = new DigitalTwinRegistryService(restTemplate, CREATE_SHELL_URL); + } + + @Test + void givenShell_whenCreateShell_thenCreteIt() throws CreateDtrShellException { + // given + AssetAdministrationShellDescriptor shell = testShell(); + when(restTemplate.postForEntity(any(String.class), any(HttpEntity.class), any())).thenReturn( + ResponseEntity.status(HttpStatus.CREATED).body(shell)); + + // when + AssetAdministrationShellDescriptor result = service.createShell(shell); + + // then + assertThat(result).isNotNull(); + } + + @Test + void givenShell_whenTemplateException_thenThrowException() { + // given + AssetAdministrationShellDescriptor shell = testShell(); + doThrow(new RestClientException("Surprise")).when(restTemplate) + .postForEntity(any(String.class), any(HttpEntity.class), any()); + + // when/then + assertThrows(CreateDtrShellException.class, () -> service.createShell(shell)); + } + + @Test + void givenShell_whenConflict_thenThrowException() { + // given + AssetAdministrationShellDescriptor shell = testShell(); + when(restTemplate.postForEntity(any(String.class), any(HttpEntity.class), any())).thenReturn( + ResponseEntity.status(HttpStatus.CONFLICT).body(shell)); + + // when/then + assertThrows(CreateDtrShellException.class, () -> service.createShell(shell)); + } + + @Test + void testCreateShell() throws CreateDtrShellException { + AssetAdministrationShellDescriptor shell = testShell(); + when(restTemplate.postForEntity(any(String.class), any(HttpEntity.class), any())).thenReturn( + ResponseEntity.status(HttpStatus.CREATED).body(shell)); + + // when + AssetAdministrationShellDescriptor result = service.createShell(shell); + + // then + assertThat(result).isNotNull(); + } + + private AssetAdministrationShellDescriptor testShell() { + return AssetAdministrationShellDescriptor.builder() + .globalAssetId("urn:uuid:254604ab-2153-45fb-8cad-54ef09f4080f") + .idShort("test") + .id("urn:uuid:25300562-aa66-4840-8952-5cef4ed667c2") + .specificAssetIds(List.of(IdentifierKeyValuePair.builder() + .name("manufacturerId") + .value("BPNL00000003CNKC") + .subjectId( + Reference.builder() + .keys(List.of( + SemanticId.builder() + .type("GlobalReference") + .value("PUBLIC_READABLE") + .build())) + .build()) + .build())) + .submodelDescriptors(List.of(SubmodelDescriptor.builder() + .idShort( + "SingleLevelUsageAsBuilt") + .id("urn:uuid:e401ccb7-a8f5-499a-9340-93746822d775") + .semanticId( + Reference.builder() + .type("ExternalReference") + .keys(List.of( + SemanticId.builder() + .type("GlobalReference") + .value("urn:bamm:io.catenax.single_level_usage_as_built:2.0.0#SingleLevelUsageAsBuilt") + .build())) + .build() + + ) + .endpoints( + List.of(Endpoint.builder() + .interfaceInformation( + "SUBMODEL-3.0") + .protocolInformation( + ProtocolInformation.builder() + .href("https://trace-x-edc-dataplane.dev.demo.catena-x.net/api/public/data/urn:uuid:e401ccb7-a8f5-499a-9340-93746822d775") + .endpointProtocol( + "HTTP") + .endpointProtocolVersion( + List.of("1.1")) + .subprotocol( + "DSP") + .subprotocolBody( + "id=urn:uuid:cb6d86b5-b8ea-4fc0-b10b-ff2dd62f793d;dspEndpoint=https://trace-x-edc.dev.demo.catena-x.net") + .subprotocolBodyEncoding( + "plain") + .securityAttributes( + List.of(SecurityAttribute.none())) + + .build()) + .build())) + .build())) + .build(); + } +} \ No newline at end of file diff --git a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockSupport.java b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockSupport.java index 2b340e813e..3212d33cb1 100644 --- a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockSupport.java +++ b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockSupport.java @@ -36,7 +36,6 @@ public final class DtrWiremockSupport { public static final String DATAPLANE_PUBLIC_PATH = "/api/public"; public static final String DATAPLANE_PUBLIC_URL = DATAPLANE_URL + DATAPLANE_PUBLIC_PATH; - public static final String CREATE_SHELL_DESCRIPTOR_PATH = "/shell-descriptors"; public static final String SHELL_DESCRIPTORS_PATH = "/shell-descriptors/"; public static final String PUBLIC_SHELL_DESCRIPTORS_PATH = DATAPLANE_PUBLIC_PATH + SHELL_DESCRIPTORS_PATH; public static final String SHELL_DESCRIPTORS_TEMPLATE = SHELL_DESCRIPTORS_PATH + "{aasIdentifier}"; @@ -55,8 +54,9 @@ public static MappingBuilder getShellDescriptor200() { public static MappingBuilder getShellDescriptor200(final String urlRegex) { final String materialForRecycling = submodelDescriptor(DATAPLANE_PUBLIC_URL, - "urn:uuid:19b0338f-6d03-4198-b3b8-5c43f8958d60", DiscoveryServiceWiremockSupport.CONTROLPLANE_PUBLIC_URL, - "MaterialForRecycling", "urn:uuid:cf06d5d5-e3f8-4bd4-bfcf-81815310701f", + "urn:uuid:19b0338f-6d03-4198-b3b8-5c43f8958d60", + DiscoveryServiceWiremockSupport.CONTROLPLANE_PUBLIC_URL, "MaterialForRecycling", + "urn:uuid:cf06d5d5-e3f8-4bd4-bfcf-81815310701f", "urn:bamm:io.catenax.material_for_recycling:1.1.0#MaterialForRecycling"); final String batch = submodelDescriptor(DATAPLANE_PUBLIC_URL, "urn:uuid:234edd2f-0223-47c7-9fe4-3984ab14c4f9", @@ -64,8 +64,9 @@ public static MappingBuilder getShellDescriptor200(final String urlRegex) { "urn:uuid:f53db6ef-7a58-4326-9169-0ae198b85dbf", "urn:samm:io.catenax.batch:2.0.0#Batch"); final String singleLevelBomAsBuilt = submodelDescriptor(DATAPLANE_PUBLIC_URL, - "urn:uuid:234edd2f-0223-47c7-9fe4-3984ab14c4f9", DiscoveryServiceWiremockSupport.CONTROLPLANE_PUBLIC_URL, - "SingleLevelBomAsBuilt", "urn:uuid:0e413809-966b-4107-aae5-aeb28bcdaadf", + "urn:uuid:234edd2f-0223-47c7-9fe4-3984ab14c4f9", + DiscoveryServiceWiremockSupport.CONTROLPLANE_PUBLIC_URL, "SingleLevelBomAsBuilt", + "urn:uuid:0e413809-966b-4107-aae5-aeb28bcdaadf", "urn:bamm:io.catenax.single_level_bom_as_built:2.0.0#SingleLevelBomAsBuilt"); final List submodelDescriptors = List.of(batch, singleLevelBomAsBuilt, materialForRecycling); @@ -77,11 +78,13 @@ public static MappingBuilder getShellDescriptor200(final String urlRegex) { } @SuppressWarnings("PMD.UseObjectForClearerAPI") // used only for testing - public static MappingBuilder getShellDescriptor200(final String urlRegex, final String bpn, final List submodelDescriptors, - final String globalAssetId, final String shellId, final String idShort) { + public static MappingBuilder getShellDescriptor200(final String urlRegex, final String bpn, + final List submodelDescriptors, final String globalAssetId, final String shellId, + final String idShort) { final List specificAssetIds = List.of(specificAssetId("manufacturerId", bpn)); return get(urlPathMatching(urlRegex)).willReturn(responseWithStatus(STATUS_CODE_OK).withBody( - assetAdministrationShellResponse(submodelDescriptors, globalAssetId, idShort, shellId, specificAssetIds))); + assetAdministrationShellResponse(submodelDescriptors, globalAssetId, idShort, shellId, + specificAssetIds))); } public static String assetAdministrationShellResponse(final List submodelDescriptors, @@ -180,8 +183,8 @@ public static MappingBuilder getLookupShells200(final String lookupShellsPath) { } public static MappingBuilder getLookupShells200(final String lookupShellsPath, final List shellIds) { - return get(urlPathEqualTo(lookupShellsPath)).willReturn(responseWithStatus(STATUS_CODE_OK).withBody( - lookupShellsResponse(shellIds))); + return get(urlPathEqualTo(lookupShellsPath)).willReturn( + responseWithStatus(STATUS_CODE_OK).withBody(lookupShellsResponse(shellIds))); } public static MappingBuilder getLookupShells200Empty() { From 87acaf767946d6ce533dc6a0a7a13064863d8493 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 12 Feb 2024 22:09:49 +0100 Subject: [PATCH 29/55] feature(irs-edc-client): #412 refactor a bit for better usability --- .../component/assetadministrationshell/SecurityAttribute.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/SecurityAttribute.java b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/SecurityAttribute.java index 40dd0726c8..4065b514a6 100644 --- a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/SecurityAttribute.java +++ b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/SecurityAttribute.java @@ -24,6 +24,9 @@ import lombok.Data; import lombok.extern.jackson.Jacksonized; +/** + * SecurityAttribute + */ @Data @Builder @Jacksonized From b455ce9ee4b4af349e05783685ff56f3732be8cf Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 12 Feb 2024 22:16:16 +0100 Subject: [PATCH 30/55] feature(irs-edc-client): #412 refactor a bit for better usability --- .../decentral/DecentralDigitalTwinRegistryClient.java | 1 - .../registryclient/decentral/DigitalTwinRegistryService.java | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClient.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClient.java index fe976aa72e..1c7a7ed5b3 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClient.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClient.java @@ -23,7 +23,6 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.registryclient.decentral; -import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.List; diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryService.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryService.java index 333129298e..195f557d1c 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryService.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryService.java @@ -33,6 +33,9 @@ import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; +/** + * implementation of DigitalTwinRegistryService used to create shells in DTR + */ @Slf4j @RequiredArgsConstructor public class DigitalTwinRegistryService { From 3bc2481e0f8fab90bd3e54062b026935f6da1b9b Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 12 Feb 2024 22:33:50 +0100 Subject: [PATCH 31/55] feature(irs-edc-client): #412 refactor a bit for better usability --- .../DigitalTwinRegistryService.java | 3 ++- .../DecentralDigitalTwinRegistryService.java | 23 ++++++++++--------- ...ecentralDigitalTwinRegistryClientTest.java | 11 --------- .../testing/wiremock/DtrWiremockSupport.java | 23 ++++++++----------- 4 files changed, 23 insertions(+), 37 deletions(-) diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DigitalTwinRegistryService.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DigitalTwinRegistryService.java index 2c844c4029..153acd3140 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DigitalTwinRegistryService.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/DigitalTwinRegistryService.java @@ -69,5 +69,6 @@ default Collection lookupShells(final String bpn) throws * @param identifiers the shell identifiers * @return the shell descriptors */ - Collection fetchShells(Collection identifiers) throws RegistryServiceException; + Collection fetchShells(Collection identifiers) + throws RegistryServiceException; } diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryService.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryService.java index c7258869eb..9fb4065879 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryService.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryService.java @@ -121,8 +121,8 @@ public Collection fetchShells(final Collection ke } } - private Stream fetchShellDescriptors(final Map.Entry> entry, - final Set calledEndpoints) { + private Stream fetchShellDescriptors( + final Map.Entry> entry, final Set calledEndpoints) { try { @@ -140,8 +140,8 @@ private Stream fetchShellDescriptors(final Map.Entry> fetchShellDescriptors(final Set calledEndpoints, final String bpn, - final List keys) { + private CompletableFuture> fetchShellDescriptors( + final Set calledEndpoints, final String bpn, final List keys) { final var watch = new StopWatch(); final String msg = "Fetching %s shells for bpn '%s'".formatted(keys.size(), bpn); @@ -177,8 +177,8 @@ private CompletableFuture> fetchShellDescriptorsForConnectorEndpoint return resultFinder.getFastestResult(futures); } - private List fetchShellDescriptorsForKey(final List keys, - final EndpointDataReference endpointDataReference) { + private List fetchShellDescriptorsForKey( + final List keys, final EndpointDataReference endpointDataReference) { final var watch = new StopWatch(); final String msg = "Fetching shell descriptors for keys %s from endpoint '%s'".formatted(keys, @@ -186,10 +186,8 @@ private List fetchShellDescriptorsForKey(final List new Shell(contractNegotiationId(endpointDataReference.getAuthCode()), - fetchShellDescriptor(endpointDataReference, key))) - .toList(); + return keys.stream().map(key -> new Shell(contractNegotiationId(endpointDataReference.getAuthCode()), + fetchShellDescriptor(endpointDataReference, key))).toList(); } finally { watch.stop(); log.info(TOOK_MS, watch.getLastTaskName(), watch.getLastTaskTimeMillis()); @@ -214,7 +212,10 @@ private AssetAdministrationShellDescriptor fetchShellDescriptor(final EndpointDa } private String contractNegotiationId(final String token) { - return Optional.ofNullable(token).map(EDRAuthCode::fromAuthCodeToken).map(EDRAuthCode::getCid).orElse(""); + return Optional.ofNullable(token) + .map(EDRAuthCode::fromAuthCodeToken) + .map(EDRAuthCode::getCid) + .orElse(""); } /** diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClientTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClientTest.java index 70d905e572..823fa5a175 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClientTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryClientTest.java @@ -1,6 +1,5 @@ package org.eclipse.tractusx.irs.registryclient.decentral; -import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -10,25 +9,15 @@ import java.net.URI; import java.util.ArrayList; import java.util.Collections; -import java.util.List; import java.util.Optional; import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference; import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor; -import org.eclipse.tractusx.irs.component.assetadministrationshell.Endpoint; -import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; -import org.eclipse.tractusx.irs.component.assetadministrationshell.ProtocolInformation; -import org.eclipse.tractusx.irs.component.assetadministrationshell.Reference; -import org.eclipse.tractusx.irs.component.assetadministrationshell.SecurityAttribute; -import org.eclipse.tractusx.irs.component.assetadministrationshell.SemanticId; -import org.eclipse.tractusx.irs.component.assetadministrationshell.SubmodelDescriptor; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; -import org.testcontainers.shaded.com.fasterxml.jackson.core.JsonProcessingException; -import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; class DecentralDigitalTwinRegistryClientTest { diff --git a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockSupport.java b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockSupport.java index 3212d33cb1..f269e1713b 100644 --- a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockSupport.java +++ b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockSupport.java @@ -35,7 +35,6 @@ public final class DtrWiremockSupport { public static final String DATAPLANE_URL = "http://dataplane.test"; public static final String DATAPLANE_PUBLIC_PATH = "/api/public"; public static final String DATAPLANE_PUBLIC_URL = DATAPLANE_URL + DATAPLANE_PUBLIC_PATH; - public static final String SHELL_DESCRIPTORS_PATH = "/shell-descriptors/"; public static final String PUBLIC_SHELL_DESCRIPTORS_PATH = DATAPLANE_PUBLIC_PATH + SHELL_DESCRIPTORS_PATH; public static final String SHELL_DESCRIPTORS_TEMPLATE = SHELL_DESCRIPTORS_PATH + "{aasIdentifier}"; @@ -54,9 +53,8 @@ public static MappingBuilder getShellDescriptor200() { public static MappingBuilder getShellDescriptor200(final String urlRegex) { final String materialForRecycling = submodelDescriptor(DATAPLANE_PUBLIC_URL, - "urn:uuid:19b0338f-6d03-4198-b3b8-5c43f8958d60", - DiscoveryServiceWiremockSupport.CONTROLPLANE_PUBLIC_URL, "MaterialForRecycling", - "urn:uuid:cf06d5d5-e3f8-4bd4-bfcf-81815310701f", + "urn:uuid:19b0338f-6d03-4198-b3b8-5c43f8958d60", DiscoveryServiceWiremockSupport.CONTROLPLANE_PUBLIC_URL, + "MaterialForRecycling", "urn:uuid:cf06d5d5-e3f8-4bd4-bfcf-81815310701f", "urn:bamm:io.catenax.material_for_recycling:1.1.0#MaterialForRecycling"); final String batch = submodelDescriptor(DATAPLANE_PUBLIC_URL, "urn:uuid:234edd2f-0223-47c7-9fe4-3984ab14c4f9", @@ -64,9 +62,8 @@ public static MappingBuilder getShellDescriptor200(final String urlRegex) { "urn:uuid:f53db6ef-7a58-4326-9169-0ae198b85dbf", "urn:samm:io.catenax.batch:2.0.0#Batch"); final String singleLevelBomAsBuilt = submodelDescriptor(DATAPLANE_PUBLIC_URL, - "urn:uuid:234edd2f-0223-47c7-9fe4-3984ab14c4f9", - DiscoveryServiceWiremockSupport.CONTROLPLANE_PUBLIC_URL, "SingleLevelBomAsBuilt", - "urn:uuid:0e413809-966b-4107-aae5-aeb28bcdaadf", + "urn:uuid:234edd2f-0223-47c7-9fe4-3984ab14c4f9", DiscoveryServiceWiremockSupport.CONTROLPLANE_PUBLIC_URL, + "SingleLevelBomAsBuilt", "urn:uuid:0e413809-966b-4107-aae5-aeb28bcdaadf", "urn:bamm:io.catenax.single_level_bom_as_built:2.0.0#SingleLevelBomAsBuilt"); final List submodelDescriptors = List.of(batch, singleLevelBomAsBuilt, materialForRecycling); @@ -78,13 +75,11 @@ public static MappingBuilder getShellDescriptor200(final String urlRegex) { } @SuppressWarnings("PMD.UseObjectForClearerAPI") // used only for testing - public static MappingBuilder getShellDescriptor200(final String urlRegex, final String bpn, - final List submodelDescriptors, final String globalAssetId, final String shellId, - final String idShort) { + public static MappingBuilder getShellDescriptor200(final String urlRegex, final String bpn, final List submodelDescriptors, + final String globalAssetId, final String shellId, final String idShort) { final List specificAssetIds = List.of(specificAssetId("manufacturerId", bpn)); return get(urlPathMatching(urlRegex)).willReturn(responseWithStatus(STATUS_CODE_OK).withBody( - assetAdministrationShellResponse(submodelDescriptors, globalAssetId, idShort, shellId, - specificAssetIds))); + assetAdministrationShellResponse(submodelDescriptors, globalAssetId, idShort, shellId, specificAssetIds))); } public static String assetAdministrationShellResponse(final List submodelDescriptors, @@ -183,8 +178,8 @@ public static MappingBuilder getLookupShells200(final String lookupShellsPath) { } public static MappingBuilder getLookupShells200(final String lookupShellsPath, final List shellIds) { - return get(urlPathEqualTo(lookupShellsPath)).willReturn( - responseWithStatus(STATUS_CODE_OK).withBody(lookupShellsResponse(shellIds))); + return get(urlPathEqualTo(lookupShellsPath)).willReturn(responseWithStatus(STATUS_CODE_OK).withBody( + lookupShellsResponse(shellIds))); } public static MappingBuilder getLookupShells200Empty() { From 42812805b99d12e6d592b68c85c2eb962b0ebbab Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 13 Feb 2024 12:36:20 +0100 Subject: [PATCH 32/55] feature(irs-edc-client): #412 fix test --- docs/src/api/irs-api.yaml | 15 +++++++++++++++ .../ProtocolInformation.java | 1 + 2 files changed, 16 insertions(+) diff --git a/docs/src/api/irs-api.yaml b/docs/src/api/irs-api.yaml index f7c25939dc..76f8a18765 100644 --- a/docs/src/api/irs-api.yaml +++ b/docs/src/api/irs-api.yaml @@ -2326,6 +2326,11 @@ components: type: string subprotocolBodyEncoding: type: string + securityAttributes: + type: array + items: + $ref: '#/components/schemas/SecurityAttribute' + maxItems: 2147483647 Quantity: type: object additionalProperties: false @@ -2622,6 +2627,16 @@ components: value: type: string example: Submodel + SecurityAttribute: + type: object + additionalProperties: false + properties: + type: + type: string + key: + type: string + value: + type: string Shell: type: object additionalProperties: false diff --git a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/ProtocolInformation.java b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/ProtocolInformation.java index 2885265ef4..93e0650d87 100644 --- a/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/ProtocolInformation.java +++ b/irs-models/src/main/java/org/eclipse/tractusx/irs/component/assetadministrationshell/ProtocolInformation.java @@ -69,6 +69,7 @@ public class ProtocolInformation { /** * securityAttributes */ + @ArraySchema(arraySchema = @Schema(implementation = SecurityAttribute.class), maxItems = Integer.MAX_VALUE) private List securityAttributes; } From 7d7f3b309c7be8644a5a54764bca6e8b754cd6a2 Mon Sep 17 00:00:00 2001 From: ds-alexander-bulgakov Date: Wed, 14 Feb 2024 07:47:23 +0100 Subject: [PATCH 33/55] feat(testing):[416] changed tested Batch id for TRI-959 --- local/testing/api-tests/irs-api-tests.tavern.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/local/testing/api-tests/irs-api-tests.tavern.yaml b/local/testing/api-tests/irs-api-tests.tavern.yaml index e76a085bfd..e077008680 100644 --- a/local/testing/api-tests/irs-api-tests.tavern.yaml +++ b/local/testing/api-tests/irs-api-tests.tavern.yaml @@ -1569,13 +1569,13 @@ stages: url: "{tavern.env_vars.IRS_HOST}/irs/jobs" json: key: - globalAssetId: "urn:uuid:334cce52-1f52-4bc9-9dd1-410bbe497bbc" - bpn: "BPNL00000003B2OM" + globalAssetId: "urn:uuid:397b63ae-89d7-4131-b45a-575e840dc5c5" + bpn: "BPNL00000003AVTH" aspects: - Batch collectAspects: true bomLifecycle: "asBuilt" - depth: 2 + depth: 10 method: POST headers: content-type: application/json From 431d06d7f17cfe10db11c0471fa9dfeab407d4c9 Mon Sep 17 00:00:00 2001 From: ds-alexander-bulgakov Date: Wed, 14 Feb 2024 08:20:25 +0100 Subject: [PATCH 34/55] feat(testing):[416] changed expected submodels for TRI-1647 TractionBatteryCode --- .../TRI-1647-expected-submodels.json | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/irs-cucumber-tests/src/test/resources/expected-files/TRI-1647-expected-submodels.json b/irs-cucumber-tests/src/test/resources/expected-files/TRI-1647-expected-submodels.json index 4d887537a6..5528d8a886 100644 --- a/irs-cucumber-tests/src/test/resources/expected-files/TRI-1647-expected-submodels.json +++ b/irs-cucumber-tests/src/test/resources/expected-files/TRI-1647-expected-submodels.json @@ -1,8 +1,9 @@ { "submodels": [ { - "identification": "urn:uuid:06564726-8032-417f-9583-5385632c980e", + "identification": "urn:uuid:662f3a1b-de56-4cbb-8fb4-51779643126d", "aspectType": "urn:bamm:io.catenax.traction_battery_code:1.0.0#TractionBatteryCode", + "contractAgreementId": null, "payload": { "tractionBatteryCode": "X12MCPM27KLPCLX2M2382320", "subcomponents": [ @@ -15,8 +16,9 @@ } }, { - "identification": "urn:uuid:2dc2f65e-e2e5-4939-9624-3d2be4c76884", + "identification": "urn:uuid:73068d1b-e846-4a22-a0ae-b6310f5b0a36", "aspectType": "urn:bamm:io.catenax.traction_battery_code:1.0.0#TractionBatteryCode", + "contractAgreementId": null, "payload": { "tractionBatteryCode": "X12MCPM27KLPCLX2M2382320", "subcomponents": [ @@ -29,8 +31,9 @@ } }, { - "identification": "urn:uuid:76fe719c-cfc9-4247-9882-4460fe0166f0", + "identification": "urn:uuid:b5933d6b-f005-4a9a-996e-a55501b2d651", "aspectType": "urn:bamm:io.catenax.traction_battery_code:1.0.0#TractionBatteryCode", + "contractAgreementId": null, "payload": { "tractionBatteryCode": "X12MCPM27KLPCLX2M2382320", "subcomponents": [ @@ -43,8 +46,9 @@ } }, { - "identification": "urn:uuid:edb31207-09b1-4570-b5d4-f753d8463915", + "identification": "urn:uuid:ab703fb6-7869-439b-aedf-43c3f21f8060", "aspectType": "urn:bamm:io.catenax.traction_battery_code:1.0.0#TractionBatteryCode", + "contractAgreementId": null, "payload": { "tractionBatteryCode": "X12MCPM27KLPCLX2M2382320", "subcomponents": [ @@ -57,8 +61,9 @@ } }, { - "identification": "urn:uuid:987c584b-afa7-4ace-9a00-d63867a781e9", + "identification": "urn:uuid:26aa986b-a443-4b8d-aec5-bc0da9757cbe", "aspectType": "urn:bamm:io.catenax.traction_battery_code:1.0.0#TractionBatteryCode", + "contractAgreementId": null, "payload": { "tractionBatteryCode": "X12MCPM27KLPCLX2M2382320", "subcomponents": [ @@ -71,8 +76,24 @@ } }, { - "identification": "urn:uuid:003c7b24-5860-4b47-87f9-bb5366c237c0", + "identification": "urn:uuid:1753b174-8212-429d-9f37-cfa2e0d6a07c", "aspectType": "urn:bamm:io.catenax.traction_battery_code:1.0.0#TractionBatteryCode", + "contractAgreementId": null, + "payload": { + "tractionBatteryCode": "X12MCPM27KLPCLX2M2382320", + "subcomponents": [ + { + "tractionBatteryCode": "X12MCPM27KLPCLX2M2382320", + "productType": "module" + } + ], + "productType": "module" + } + }, + { + "identification": "urn:uuid:6e6f7237-982e-4359-accf-e3b9c0fb4f0e", + "aspectType": "urn:bamm:io.catenax.traction_battery_code:1.0.0#TractionBatteryCode", + "contractAgreementId": null, "payload": { "tractionBatteryCode": "X12MCPM27KLPCLX2M2382320", "subcomponents": [ From 1ed24e2c5a1571ddb715d5c00e480182822ceeb3 Mon Sep 17 00:00:00 2001 From: mk Date: Wed, 14 Feb 2024 08:25:39 +0100 Subject: [PATCH 35/55] chore(concept):[#367] add configuration for dDTR --- .../#367-adapt-to-changes-industry-core.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md b/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md index e599cda964..17bbfc62f0 100644 --- a/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md +++ b/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md @@ -123,6 +123,12 @@ Parameter is configurable for dDTR instance and has to be configured for integra - [Values.yaml](https://github.com/eclipse-tractusx/sldt-digital-twin-registry/blob/f438fe96a7ae1f1b920e8e4fb4114fb7af32643d/charts/registry/values.yaml#L51) - [README.md](https://github.com/eclipse-tractusx/sldt-digital-twin-registry/blob/f438fe96a7ae1f1b920e8e4fb4114fb7af32643d/charts/registry/README.md#:~:text=externalSubjectIdWildcardAllowedTypes) +values.yaml +````json + registry.externalSubjectIdWildcardAllowedTypes = manufacturerPartId,assetLifecyclePhase,digitalTwinType +```` + + ### Visibility of Specific Asset IDs in the DTR * Usage of parameter 'externalSubjectIds' which contains 'specificAssetIds'. Parameter 'externalSubjectIds' restricts visibility exclusively to manufacturer. From 96200eedac240d2d99ecf75e31641dc3893731c9 Mon Sep 17 00:00:00 2001 From: ds-alexander-bulgakov Date: Wed, 14 Feb 2024 08:58:41 +0100 Subject: [PATCH 36/55] feat(testing):[416] changed expected submodels and relationships for TRI-528 MaterialForRecycling --- .../TRI-528-expected-relationships.json | 19 ----- .../TRI-528-expected-submodels.json | 85 +------------------ 2 files changed, 2 insertions(+), 102 deletions(-) diff --git a/irs-cucumber-tests/src/test/resources/expected-files/TRI-528-expected-relationships.json b/irs-cucumber-tests/src/test/resources/expected-files/TRI-528-expected-relationships.json index 252a603f91..7786f58268 100644 --- a/irs-cucumber-tests/src/test/resources/expected-files/TRI-528-expected-relationships.json +++ b/irs-cucumber-tests/src/test/resources/expected-files/TRI-528-expected-relationships.json @@ -56,25 +56,6 @@ }, "aspectType": "SingleLevelBomAsBuilt", "bpn": "BPNL00000003AYRE" - }, - { - "catenaXId": "urn:uuid:d57a0374-45bc-4d9e-b44c-e6e75cfe84c0", - "linkedItem": { - "quantity": { - "quantityNumber": 0.1908, - "measurementUnit": { - "datatypeURI": null, - "lexicalValue": "unit:kilogram" - } - }, - "lifecycleContext": "asBuilt", - "assembledOn": "2022-02-03T14:48:54.709Z", - "lastModifiedOn": "2022-02-03T14:48:54.709Z", - "childCatenaXId": "urn:uuid:6cae0932-05e2-467d-98d0-7d580938a23e", - "hasAlternatives": true - }, - "aspectType": "SingleLevelBomAsBuilt", - "bpn": "BPNL00000003B0Q0" } ] } \ No newline at end of file diff --git a/irs-cucumber-tests/src/test/resources/expected-files/TRI-528-expected-submodels.json b/irs-cucumber-tests/src/test/resources/expected-files/TRI-528-expected-submodels.json index 33651a8a8f..2af3f467ef 100644 --- a/irs-cucumber-tests/src/test/resources/expected-files/TRI-528-expected-submodels.json +++ b/irs-cucumber-tests/src/test/resources/expected-files/TRI-528-expected-submodels.json @@ -1,8 +1,9 @@ { "submodels" : [ { - "identification": "urn:uuid:7a3ba22d-a6e1-4096-b34a-f2afc42fe17f", + "identification": "urn:uuid:5fbf0548-8119-4550-852e-3c58eac4a36c", "aspectType": "urn:bamm:io.catenax.material_for_recycling:1.1.0#MaterialForRecycling", + "contractAgreementId": "NDQ2MWJhZmQtOGY5My00MGI2LWEzY2ItYmFiNmExNmM1M2I0:dXJuOnV1aWQ6YjU2ZGQ0NTAtNzg2MS00MGM1LTkxNzgtNGRhYjQ1NTk4ZWQ4:ZThjZjU1YjYtYTgyNy00OWI3LTljN2YtMDhkNDJiNWJlZmM4", "payload": { "component": [ { @@ -40,88 +41,6 @@ } ] } - }, - { - "identification": "urn:uuid:8178ed3b-9c23-4dea-b252-d37338934eb4", - "aspectType": "urn:bamm:io.catenax.material_for_recycling:1.1.0#MaterialForRecycling", - "payload": { - "materialName": "Engineering Plastics", - "materialClass": "5.1", - "component": [ - { - "materialName": "PA66", - "recycledContent": 33, - "materialClass": "5.1", - "quantity": { - "unit": "unit:percent", - "value": 70 - }, - "aggregateState": "solid", - "materialAbbreviation": "PA66" - }, - { - "materialName": "GF-Faser", - "recycledContent": 20, - "materialClass": "5.1", - "quantity": { - "unit": "unit:percent", - "value": 30 - }, - "aggregateState": "solid", - "materialAbbreviation": "GF30" - } - ] - } - }, - { - "identification": "urn:uuid:b24ed803-9cf0-4b5c-bbea-5e518f2764cb", - "aspectType": "urn:bamm:io.catenax.material_for_recycling:1.1.0#MaterialForRecycling", - "payload": { - "materialName": "NTIER Product", - "materialClass": "5.5", - "component": [ - { - "materialName": "Aluminium oxide", - "recycledContent": 83, - "materialClass": "5.5.1", - "quantity": { - "unit": "unit:percent", - "value": 60 - }, - "aggregateState": "solid", - "materialAbbreviation": "" - }, - { - "materialName": "Other", - "recycledContent": 4, - "materialClass": "5.5.2", - "quantity": { - "unit": "unit:percent", - "value": 40 - }, - "aggregateState": "solid", - "materialAbbreviation": "" - } - ] - } - }, - { - "identification": "urn:uuid:07bddbb1-df63-4a25-81c0-f1d6d7a4273c", - "aspectType": "urn:bamm:io.catenax.material_for_recycling:1.1.0#MaterialForRecycling", - "payload": { - "component": [ - { - "materialName": "Glue", - "materialClass": "6.2", - "quantity": { - "unit": "unit:kilogram", - "value": 2.5 - }, - "weight": "0.2341", - "materialAbbreviation": "GL338" - } - ] - } } ] } \ No newline at end of file From def0606e6ed0e00872088dce6f67ea777249506c Mon Sep 17 00:00:00 2001 From: ds-alexander-bulgakov Date: Wed, 14 Feb 2024 10:00:08 +0100 Subject: [PATCH 37/55] feat(testing):[416] adjusted expected submodels for TRI-528 MaterialForRecycling --- .../resources/expected-files/TRI-528-expected-submodels.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irs-cucumber-tests/src/test/resources/expected-files/TRI-528-expected-submodels.json b/irs-cucumber-tests/src/test/resources/expected-files/TRI-528-expected-submodels.json index 2af3f467ef..75fe752934 100644 --- a/irs-cucumber-tests/src/test/resources/expected-files/TRI-528-expected-submodels.json +++ b/irs-cucumber-tests/src/test/resources/expected-files/TRI-528-expected-submodels.json @@ -3,7 +3,7 @@ { "identification": "urn:uuid:5fbf0548-8119-4550-852e-3c58eac4a36c", "aspectType": "urn:bamm:io.catenax.material_for_recycling:1.1.0#MaterialForRecycling", - "contractAgreementId": "NDQ2MWJhZmQtOGY5My00MGI2LWEzY2ItYmFiNmExNmM1M2I0:dXJuOnV1aWQ6YjU2ZGQ0NTAtNzg2MS00MGM1LTkxNzgtNGRhYjQ1NTk4ZWQ4:ZThjZjU1YjYtYTgyNy00OWI3LTljN2YtMDhkNDJiNWJlZmM4", + "contractAgreementId": null, "payload": { "component": [ { From 5395d31f57601564e72b0bc92813bd8793160aea Mon Sep 17 00:00:00 2001 From: ds-alexander-bulgakov Date: Thu, 15 Feb 2024 13:06:14 +0100 Subject: [PATCH 38/55] feat(testing):[416] boyscouting --- local/testing/api-tests/tavern_helpers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/local/testing/api-tests/tavern_helpers.py b/local/testing/api-tests/tavern_helpers.py index 160feefec9..5db44c9f4b 100644 --- a/local/testing/api-tests/tavern_helpers.py +++ b/local/testing/api-tests/tavern_helpers.py @@ -49,7 +49,6 @@ def ESS_job_parameter_are_as_requested(response): assert parameter.get('depth') == 1 assert parameter.get('direction') == 'downward' assert parameter.get('lookupBPNs') is False - #assert parameter.get('callbackUrl') == 'https://www.check123.com' aspects_list = parameter.get("aspects") assert 'PartSiteInformationAsPlanned' in aspects_list assert 'PartAsPlanned' in aspects_list @@ -162,7 +161,7 @@ def errors_for_unknown_globalAssetId_are_correct(response): print("RetryCounter: ", processingErrorRetryCounter) assert 'urn:uuid:cce14502-958a-42e1-8bb7-f4f41aaaaaaa' in catenaXId assert 'DigitalTwinRequest' in processingErrorStep - #assert 'Shell for identifier urn:uuid:cce14502-958a-42e1-8bb7-f4f41aaaaaaa not found' in processingErrorDetail ##commented out since this error message is not possible currently after DTR changes + #assert 'Shell for identifier urn:uuid:cce14502-958a-42e1-8bb7-f4f41aaaaaaa not found' in processingErrorDetail #commented out since this error message is not possible currently after DTR changes assert processingErrorLastAttempt is not None assert 3 is processingErrorRetryCounter From 886658aa86a469ba4014d3488a00998c851fc364 Mon Sep 17 00:00:00 2001 From: Jaro Hartmann <57985712+ds-jhartmann@users.noreply.github.com> Date: Thu, 15 Feb 2024 14:26:33 +0100 Subject: [PATCH 39/55] doc(foss): Add release instructions --- CONTRIBUTING.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d6e70985a1..8801880460 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -150,6 +150,15 @@ The plugin will be disabled by default. To enable it in the current project, go More info: https://github.com/google/google-java-format/blob/master/README.md#intellij-jre-config +### Create a release + +1. Choose a release version. Use semantic versioning! +2. Add release notes for new version in [CHANGELOG.md](CHANGELOG.md) and [charts/irs-helm/CHANGELOG.md](charts/irs-helm/CHANGELOG.md) (e.g. https://github.com/catenax-ng/tx-item-relationship-service/pull/328) +3. Create Git tag for the desired release version `git tag x.x.x` +4. Push Git tag to repository `git push origin x.x.x` +5. Wait for release workflow to complete +6. Merge the automatically opened PR by github-actions bot +7. Notify about the release in IRS Matrix Chat ## Contact From a338f7d8e7de7179a0b47a8ef913642573a98268 Mon Sep 17 00:00:00 2001 From: Jaro Hartmann <57985712+ds-jhartmann@users.noreply.github.com> Date: Thu, 15 Feb 2024 14:28:22 +0100 Subject: [PATCH 40/55] doc(foss): Add release instructions --- CONTRIBUTING.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8801880460..1c6bc91c34 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -154,11 +154,12 @@ https://github.com/google/google-java-format/blob/master/README.md#intellij-jre- 1. Choose a release version. Use semantic versioning! 2. Add release notes for new version in [CHANGELOG.md](CHANGELOG.md) and [charts/irs-helm/CHANGELOG.md](charts/irs-helm/CHANGELOG.md) (e.g. https://github.com/catenax-ng/tx-item-relationship-service/pull/328) -3. Create Git tag for the desired release version `git tag x.x.x` -4. Push Git tag to repository `git push origin x.x.x` -5. Wait for release workflow to complete -6. Merge the automatically opened PR by github-actions bot -7. Notify about the release in IRS Matrix Chat +3. Update [COMPATIBILITY_MATRIX.md](COMPATIBILITY_MATRIX.md) +4. Create Git tag for the desired release version `git tag x.x.x` +5. Push Git tag to repository `git push origin x.x.x` +6. Wait for release workflow to complete +7. Merge the automatically opened PR by github-actions bot +8. Notify about the release in IRS Matrix Chat ## Contact From 339a2638f5f71c77ca45138db5885ce88b09e3e4 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 19 Feb 2024 13:21:57 +0100 Subject: [PATCH 41/55] feature(irs-edc-client): #412 reduce duplicates --- .../irs/edc/client/asset/EdcAssetService.java | 46 ++++++++----------- .../edc/client/asset/model/AssetRequest.java | 7 +++ .../client/transformer/EdcTransformer.java | 28 +++++++---- 3 files changed, 46 insertions(+), 35 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java index 38f033de90..3f4f63e370 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -19,6 +19,14 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.asset; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_BASE_URL; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_METHOD; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_BODY; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_PATH; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_QUERY_PARAMS; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_TYPE; + import java.util.Map; import java.util.UUID; @@ -114,20 +122,14 @@ private JsonObject createNotificationAssetRequest(final String assetName, final final DataAddress dataAddress = DataAddress.Builder.newInstance() .type(DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", + .property(ASSET_CREATION_DATA_ADDRESS_TYPE, DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) - .property( - "https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", - baseUrl) - .property( - "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", + .property(ASSET_CREATION_DATA_ADDRESS_BASE_URL, baseUrl) + .property(ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD, Boolean.TRUE.toString()) - .property( - "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", + .property(ASSET_CREATION_DATA_ADDRESS_PROXY_BODY, Boolean.TRUE.toString()) - .property( - "https://w3id.org/edc/v0.0.1/ns/dataAddress/method", - DEFAULT_METHOD) + .property(ASSET_CREATION_DATA_ADDRESS_METHOD, DEFAULT_METHOD) .build(); final Asset asset = Asset.Builder.newInstance() @@ -147,26 +149,18 @@ private JsonObject createDtrAssetRequest(final String assetName, final String ba final DataAddress dataAddress = DataAddress.Builder.newInstance() .type("DataAddress") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", + .property(ASSET_CREATION_DATA_ADDRESS_TYPE, DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) - .property( - "https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", - baseUrl) - .property( - "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", + .property(ASSET_CREATION_DATA_ADDRESS_BASE_URL, baseUrl) + .property(ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD, Boolean.TRUE.toString()) - .property( - "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", + .property(ASSET_CREATION_DATA_ADDRESS_PROXY_BODY, Boolean.TRUE.toString()) - .property( - "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyPath", + .property(ASSET_CREATION_DATA_ADDRESS_PROXY_PATH, Boolean.TRUE.toString()) - .property( - "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams", + .property(ASSET_CREATION_DATA_ADDRESS_PROXY_QUERY_PARAMS, Boolean.TRUE.toString()) - .property( - "https://w3id.org/edc/v0.0.1/ns/dataAddress/method", - DEFAULT_METHOD) + .property(ASSET_CREATION_DATA_ADDRESS_METHOD, DEFAULT_METHOD) .build(); final Asset asset = Asset.Builder.newInstance() diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java index 7e3995c9ec..abb4b6be8d 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java @@ -33,4 +33,11 @@ public record AssetRequest( DataAddress dataAddress) { public static final String ASSET_CREATION_ASSET = "https://w3id.org/edc/v0.0.1/ns/asset"; public static final String ASSET_CREATION_DATA_ADDRESS = "https://w3id.org/edc/v0.0.1/ns/dataAddress"; + public static final String ASSET_CREATION_DATA_ADDRESS_TYPE = "https://w3id.org/edc/v0.0.1/ns/dataAddress/type"; + public static final String ASSET_CREATION_DATA_ADDRESS_BASE_URL = "https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl"; + public static final String ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD = "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod"; + public static final String ASSET_CREATION_DATA_ADDRESS_PROXY_BODY = "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody"; + public static final String ASSET_CREATION_DATA_ADDRESS_PROXY_PATH = "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyPath"; + public static final String ASSET_CREATION_DATA_ADDRESS_PROXY_QUERY_PARAMS = "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams"; + public static final String ASSET_CREATION_DATA_ADDRESS_METHOD = "https://w3id.org/edc/v0.0.1/ns/dataAddress/method"; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java index de0b0fd9a6..57947867f4 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java @@ -23,6 +23,16 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.transformer; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_ASSET; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_BASE_URL; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_METHOD; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_BODY; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_PATH; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_QUERY_PARAMS; +import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_TYPE; + import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.JSON_LD_OBJECT_MAPPER; import java.io.ByteArrayInputStream; @@ -93,16 +103,16 @@ public class EdcTransformer { public EdcTransformer(@Qualifier(JSON_LD_OBJECT_MAPPER) final ObjectMapper objectMapper, final TitaniumJsonLd titaniumJsonLd, final TypeTransformerRegistry typeTransformerRegistry) { this.titaniumJsonLd = titaniumJsonLd; - this.titaniumJsonLd.registerNamespace("type", "https://w3id.org/edc/v0.0.1/ns/dataAddress/type"); - this.titaniumJsonLd.registerNamespace("baseUrl", "https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl"); - this.titaniumJsonLd.registerNamespace("proxyMethod", "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod"); - this.titaniumJsonLd.registerNamespace("proxyBody", "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody"); - this.titaniumJsonLd.registerNamespace("method", "https://w3id.org/edc/v0.0.1/ns/dataAddress/method"); - this.titaniumJsonLd.registerNamespace("asset", "https://w3id.org/edc/v0.0.1/ns/asset"); - this.titaniumJsonLd.registerNamespace("dataAddress", "https://w3id.org/edc/v0.0.1/ns/dataAddress"); - this.titaniumJsonLd.registerNamespace("proxyPath", "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyPath"); + this.titaniumJsonLd.registerNamespace("type", ASSET_CREATION_DATA_ADDRESS_TYPE); + this.titaniumJsonLd.registerNamespace("baseUrl", ASSET_CREATION_DATA_ADDRESS_BASE_URL); + this.titaniumJsonLd.registerNamespace("proxyMethod", ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD); + this.titaniumJsonLd.registerNamespace("proxyBody", ASSET_CREATION_DATA_ADDRESS_PROXY_BODY); + this.titaniumJsonLd.registerNamespace("method", ASSET_CREATION_DATA_ADDRESS_METHOD); + this.titaniumJsonLd.registerNamespace("asset", ASSET_CREATION_ASSET); + this.titaniumJsonLd.registerNamespace("dataAddress", ASSET_CREATION_DATA_ADDRESS); + this.titaniumJsonLd.registerNamespace("proxyPath", ASSET_CREATION_DATA_ADDRESS_PROXY_PATH); this.titaniumJsonLd.registerNamespace("proxyQueryParams", - "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams"); + ASSET_CREATION_DATA_ADDRESS_PROXY_QUERY_PARAMS); final JsonBuilderFactory jsonBuilderFactory = Json.createBuilderFactory(Map.of()); jsonObjectFromNegotiationInitiateDtoTransformer = new JsonObjectFromNegotiationInitiateDtoTransformer( From 7c5a91f12dc457f1574c46f7c7eed42617227b07 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Mon, 19 Feb 2024 13:37:49 +0100 Subject: [PATCH 42/55] feature(irs-edc-client): #412 format --- .../tractusx/irs/edc/client/asset/model/AssetRequest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java index abb4b6be8d..7f86236a78 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java @@ -28,9 +28,7 @@ */ @Builder(toBuilder = true) -public record AssetRequest( - Asset asset, - DataAddress dataAddress) { +public record AssetRequest(Asset asset, DataAddress dataAddress) { public static final String ASSET_CREATION_ASSET = "https://w3id.org/edc/v0.0.1/ns/asset"; public static final String ASSET_CREATION_DATA_ADDRESS = "https://w3id.org/edc/v0.0.1/ns/dataAddress"; public static final String ASSET_CREATION_DATA_ADDRESS_TYPE = "https://w3id.org/edc/v0.0.1/ns/dataAddress/type"; From 6c5823ee49ec79526eb1d460161b1afb38c0bdcb Mon Sep 17 00:00:00 2001 From: mk Date: Mon, 19 Feb 2024 14:04:07 +0100 Subject: [PATCH 43/55] fix(changelog):[#367] fix Changelog --- CHANGELOG.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b34914bd7a..e37a993cc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,13 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] - - -## [4.5.0] - 2024-02-07 ### Added - Added helper script for building documentation locally. -- Added helper script for building documentation locally. - Added concept to conform with IndustryCore Changes CX-0126 and CX-127 + +## [4.5.0] - 2024-02-07 +### Added - Added new job parameter flag "auditContractNegotiation" which toggles setting contractAgreementId in Shells and Submodels - Added "contractAgreementId" field to Submodel model - Added Integration Tests for the entire IRS flow using stubbed responses of Discovery Service, Semantic Hub, EDC, Digital Twin Registry and BPDM Pool From 4e275853180177778efe840ff09e8363b2ba5a3f Mon Sep 17 00:00:00 2001 From: mk Date: Mon, 19 Feb 2024 14:07:16 +0100 Subject: [PATCH 44/55] fix(changelog):[#367] review comments --- .../#367-adapt-to-changes-industry-core.md | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md b/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md index 17bbfc62f0..8aa18a942d 100644 --- a/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md +++ b/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md @@ -17,14 +17,11 @@ # Overview -The "Industry Core" is a fundamental element in the C-X network or system architecture. -It provides essential functions for identification, traversal, data flow, configuration, and communication in a modular and -interconnected environment. -The goal is to make components identifiable and discoverable at type and instance levels. -Enable seamless traversal across different tier levels. -Facilitate the creation of data chains. -Crucial role in configuring enablement services for component-based data exchange -Notification base message exchange. +The "Industry Core" is a fundamental element in the C-X network or system architecture. It provides essential functions for identification, traversal, data flow, configuration, and communication in a modular and +interconnected environment. The goal is to make components identifiable and discoverable at type and instance levels. +Enable seamless traversal across different tier levels. Facilitate the creation of data chains. Crucial role in configuring enablement services for component-based data exchange +Notification base message exchange. + 1. Identifiability and findability 2. Traversing Across multiple tier levels @@ -238,13 +235,13 @@ values.yaml # Glossary -| Abbreviation | Name | Description | -|--------------|-------------------------|----------------------------------------------------------| -| ECU | Electronic Control Unit | An ECU's main job is to keep the engine working smoothly | -| JIS | Just In Sequence | Just-in-sequence is a delivery concept where parts are delivered to the production plant at a requested time in the exact order of installation, typically for a 1:1 dependency on the manufactured product. A just-in-sequence-part is a part for which this concept and order of delivery applies and which does not have a dedicated serial number (then it would be considered a serialized part). Examples for JIS-parts are seats and bumpers. | -| BPN | Business Partner Number | A BPN is the unique identifier of a partner within Catena-x. | -| Part Instance|A part instance is a physically produced instance (e.g. serialized part, batch, just-in-sequence-part) of a part type. | -| Part Type| A part type is a generic (not physically produced) part on material- or catalog-level as a representation for a designed part.| +| Abbreviation | Name | Description | +|--------------|---------------------------|----------------------------------------------------------| +| ECU | Electronic Control Unit | An ECU's main job is to keep the engine working smoothly | +| JIS | Just In Sequence | Just-in-sequence is a delivery concept where parts are delivered to the production plant at a requested time in the exact order of installation, typically for a 1:1 dependency on the manufactured product. A just-in-sequence-part is a part for which this concept and order of delivery applies and which does not have a dedicated serial number (then it would be considered a serialized part). Examples for JIS-parts are seats and bumpers. | +| BPN | Business Partner Number | A BPN is the unique identifier of a partner within Catena-x. | +| | Part Instance |A part instance is a physically produced instance (e.g. serialized part, batch, just-in-sequence-part) of a part type. | +| | Part Type | A part type is a generic (not physically produced) part on material- or catalog-level as a representation for a designed part. | | VAN | Vehicle Anonymised Number | A number mapped 1:1 to VIN, but pseudonomised.| # References From df9e0ad28847bed8800ca9096d04e4c00476f98a Mon Sep 17 00:00:00 2001 From: mk Date: Mon, 19 Feb 2024 14:10:20 +0100 Subject: [PATCH 45/55] fix(changelog):[#367] review comments --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e37a993cc6..80ffd77c13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- Added helper script for building documentation locally. - Added concept to conform with IndustryCore Changes CX-0126 and CX-127 ## [4.5.0] - 2024-02-07 ### Added +- Added helper script for building documentation locally. - Added new job parameter flag "auditContractNegotiation" which toggles setting contractAgreementId in Shells and Submodels - Added "contractAgreementId" field to Submodel model - Added Integration Tests for the entire IRS flow using stubbed responses of Discovery Service, Semantic Hub, EDC, Digital Twin Registry and BPDM Pool From 6dca4fba42e5f75def132ee952c132ec2334d580 Mon Sep 17 00:00:00 2001 From: Jaro Hartmann Date: Mon, 19 Feb 2024 18:32:58 +0100 Subject: [PATCH 46/55] feat(edc-client): Replace AssetRequest with Asset and corresponding Transformer --- .../irs/edc/client/asset/EdcAssetService.java | 80 ++++++++---------- .../edc/client/asset/model/AssetRequest.java | 41 ---------- ...JsonObjectFromAssetRequestTransformer.java | 56 ------------- .../client/transformer/EdcTransformer.java | 35 ++------ .../edc/client/asset/EdcAssetServiceTest.java | 82 ++++++++----------- 5 files changed, 76 insertions(+), 218 deletions(-) delete mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java delete mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java index 3f4f63e370..5ff1b8be03 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetService.java @@ -19,13 +19,8 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.asset; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_BASE_URL; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_METHOD; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_BODY; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_PATH; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_QUERY_PARAMS; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_TYPE; +import static org.eclipse.edc.spi.types.domain.DataAddress.EDC_DATA_ADDRESS_TYPE_PROPERTY; +import static org.eclipse.edc.spi.types.domain.HttpDataAddress.HTTP_DATA; import java.util.Map; import java.util.UUID; @@ -36,7 +31,6 @@ import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; -import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationMethod; import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationType; import org.eclipse.tractusx.irs.edc.client.asset.model.exception.CreateEdcAssetException; @@ -59,7 +53,12 @@ public class EdcAssetService { private static final String DEFAULT_CONTENT_TYPE = "application/json"; private static final String DEFAULT_POLICY_ID = "use-eu"; private static final String DEFAULT_METHOD = "POST"; - private static final String DEFAULT_DATA_ADDRESS_PROPERTY_TYPE = "HttpData"; + private static final String ASSET_CREATION_DATA_ADDRESS_BASE_URL = "https://w3id.org/edc/v0.0.1/ns/baseUrl"; + private static final String ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD = "https://w3id.org/edc/v0.0.1/ns/proxyMethod"; + private static final String ASSET_CREATION_DATA_ADDRESS_PROXY_BODY = "https://w3id.org/edc/v0.0.1/ns/proxyBody"; + private static final String ASSET_CREATION_DATA_ADDRESS_PROXY_PATH = "https://w3id.org/edc/v0.0.1/ns/proxyPath"; + private static final String ASSET_CREATION_DATA_ADDRESS_PROXY_QUERY_PARAMS = "https://w3id.org/edc/v0.0.1/ns/proxyQueryParams"; + private static final String ASSET_CREATION_DATA_ADDRESS_METHOD = "https://w3id.org/edc/v0.0.1/ns/method"; private final EdcTransformer edcTransformer; private final EdcConfiguration config; @@ -68,35 +67,35 @@ public class EdcAssetService { public String createNotificationAsset(final String baseUrl, final String assetName, final NotificationMethod notificationMethod, final NotificationType notificationType) throws CreateEdcAssetException { - final JsonObject request = createNotificationAssetRequest(assetName, baseUrl, notificationMethod, - notificationType); + final Asset request = createNotificationAssetRequest(assetName, baseUrl, notificationMethod, notificationType); return sendRequest(request); } public String createDtrAsset(final String baseUrl, final String assetName) throws CreateEdcAssetException { - final JsonObject request = createDtrAssetRequest(assetName, baseUrl); + final Asset request = createDtrAssetRequest(assetName, baseUrl); return sendRequest(request); } - private String sendRequest(final JsonObject request) throws CreateEdcAssetException { + private String sendRequest(final Asset request) throws CreateEdcAssetException { + final JsonObject transformedPayload = edcTransformer.transformAssetToJson(request); final ResponseEntity createEdcDataAssetResponse; try { createEdcDataAssetResponse = restTemplate.postForEntity(config.getControlplane().getEndpoint().getAsset(), - request, String.class); + transformedPayload, String.class); final HttpStatusCode responseCode = createEdcDataAssetResponse.getStatusCode(); if (responseCode.value() == HttpStatus.CONFLICT.value()) { - log.info("{} asset already exists in the EDC", getAssetId(request)); - return getAssetId(request); + log.info("{} asset already exists in the EDC", request.getId()); + return request.getId(); } if (responseCode.value() == HttpStatus.OK.value()) { - return getAssetId(request); + return request.getId(); } } catch (RestClientException e) { throw new CreateEdcAssetException(e); } - throw new CreateEdcAssetException("Failed to create asset %s".formatted(getAssetId(request))); + throw new CreateEdcAssetException("Failed to create asset %s".formatted(request.getId())); } public void deleteAsset(final String assetId, final RestTemplate restTemplate) throws DeleteEdcAssetException { @@ -113,7 +112,7 @@ public void deleteAsset(final String assetId, final RestTemplate restTemplate) t } } - private JsonObject createNotificationAssetRequest(final String assetName, final String baseUrl, + private Asset createNotificationAssetRequest(final String assetName, final String baseUrl, final NotificationMethod notificationMethod, final NotificationType notificationType) { final String assetId = UUID.randomUUID().toString(); final Map properties = Map.of("description", assetName, "contenttype", DEFAULT_CONTENT_TYPE, @@ -121,9 +120,8 @@ private JsonObject createNotificationAssetRequest(final String assetName, final notificationType.getValue(), "notificationmethod", notificationMethod.getValue()); final DataAddress dataAddress = DataAddress.Builder.newInstance() - .type(DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) - .property(ASSET_CREATION_DATA_ADDRESS_TYPE, - DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) + .type(HTTP_DATA) + .property(EDC_DATA_ADDRESS_TYPE_PROPERTY, HTTP_DATA) .property(ASSET_CREATION_DATA_ADDRESS_BASE_URL, baseUrl) .property(ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD, Boolean.TRUE.toString()) @@ -131,26 +129,22 @@ private JsonObject createNotificationAssetRequest(final String assetName, final Boolean.TRUE.toString()) .property(ASSET_CREATION_DATA_ADDRESS_METHOD, DEFAULT_METHOD) .build(); - - final Asset asset = Asset.Builder.newInstance() - .id(assetId) - .contentType("Asset") - .properties(properties) - .dataAddress(dataAddress) - .build(); - return edcTransformer.transformAssetRequestToJson( - AssetRequest.builder().asset(asset).dataAddress(dataAddress).build()); + return Asset.Builder.newInstance() + .id(assetId) + .contentType("Asset") + .properties(properties) + .dataAddress(dataAddress) + .build(); } - private JsonObject createDtrAssetRequest(final String assetName, final String baseUrl) { + private Asset createDtrAssetRequest(final String assetName, final String baseUrl) { final String assetId = UUID.randomUUID().toString(); final Map properties = Map.of("description", assetName, "type", "data.core.digitalTwinRegistry"); final DataAddress dataAddress = DataAddress.Builder.newInstance() .type("DataAddress") - .property(ASSET_CREATION_DATA_ADDRESS_TYPE, - DEFAULT_DATA_ADDRESS_PROPERTY_TYPE) + .property(EDC_DATA_ADDRESS_TYPE_PROPERTY, HTTP_DATA) .property(ASSET_CREATION_DATA_ADDRESS_BASE_URL, baseUrl) .property(ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD, Boolean.TRUE.toString()) @@ -163,17 +157,11 @@ private JsonObject createDtrAssetRequest(final String assetName, final String ba .property(ASSET_CREATION_DATA_ADDRESS_METHOD, DEFAULT_METHOD) .build(); - final Asset asset = Asset.Builder.newInstance() - .id(assetId) - .contentType("Asset") - .properties(properties) - .dataAddress(dataAddress) - .build(); - return edcTransformer.transformAssetRequestToJson( - AssetRequest.builder().asset(asset).dataAddress(dataAddress).build()); - } - - private static String getAssetId(final JsonObject jsonObject) { - return jsonObject.get("asset").asJsonObject().get("@id").toString(); + return Asset.Builder.newInstance() + .id(assetId) + .contentType("Asset") + .properties(properties) + .dataAddress(dataAddress) + .build(); } } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java deleted file mode 100644 index 7f86236a78..0000000000 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/model/AssetRequest.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************** - * 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.asset.model; - -import lombok.Builder; -import org.eclipse.edc.spi.types.domain.DataAddress; -import org.eclipse.edc.spi.types.domain.asset.Asset; - -/** - * AssetRequest used for creating edc notification asset - */ - -@Builder(toBuilder = true) -public record AssetRequest(Asset asset, DataAddress dataAddress) { - public static final String ASSET_CREATION_ASSET = "https://w3id.org/edc/v0.0.1/ns/asset"; - public static final String ASSET_CREATION_DATA_ADDRESS = "https://w3id.org/edc/v0.0.1/ns/dataAddress"; - public static final String ASSET_CREATION_DATA_ADDRESS_TYPE = "https://w3id.org/edc/v0.0.1/ns/dataAddress/type"; - public static final String ASSET_CREATION_DATA_ADDRESS_BASE_URL = "https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl"; - public static final String ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD = "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod"; - public static final String ASSET_CREATION_DATA_ADDRESS_PROXY_BODY = "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody"; - public static final String ASSET_CREATION_DATA_ADDRESS_PROXY_PATH = "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyPath"; - public static final String ASSET_CREATION_DATA_ADDRESS_PROXY_QUERY_PARAMS = "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams"; - public static final String ASSET_CREATION_DATA_ADDRESS_METHOD = "https://w3id.org/edc/v0.0.1/ns/dataAddress/method"; -} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java deleted file mode 100644 index 4b9bb550ef..0000000000 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/asset/transformer/JsonObjectFromAssetRequestTransformer.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************** - * 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.asset.transformer; - -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_ASSET; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS; - -import jakarta.json.JsonBuilderFactory; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; -import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; -import org.jetbrains.annotations.NotNull; - -/** - * Transformer to convert AssetRequest to JSON-LD. - */ - -public class JsonObjectFromAssetRequestTransformer extends AbstractJsonLdTransformer { - - private final JsonBuilderFactory jsonFactory; - - public JsonObjectFromAssetRequestTransformer(final JsonBuilderFactory jsonFactory) { - super(AssetRequest.class, JsonObject.class); - this.jsonFactory = jsonFactory; - } - - @Override - public JsonObject transform(@NotNull final AssetRequest assetRequest, @NotNull final TransformerContext context) { - final JsonObjectBuilder builder = this.jsonFactory.createObjectBuilder(); - builder.add(ASSET_CREATION_ASSET, - context.transform(assetRequest.asset(), JsonObject.class)); - builder.add(ASSET_CREATION_DATA_ADDRESS, - context.transform(assetRequest.dataAddress(), JsonObject.class)); - return builder.build(); - } -} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java index 57947867f4..ce9f63911d 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/transformer/EdcTransformer.java @@ -23,16 +23,6 @@ ********************************************************************************/ package org.eclipse.tractusx.irs.edc.client.transformer; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_ASSET; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_BASE_URL; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_METHOD; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_BODY; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_PATH; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_PROXY_QUERY_PARAMS; -import static org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest.ASSET_CREATION_DATA_ADDRESS_TYPE; - import static org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration.JSON_LD_OBJECT_MAPPER; import java.io.ByteArrayInputStream; @@ -74,9 +64,8 @@ import org.eclipse.edc.core.transform.transformer.to.JsonValueToGenericTypeTransformer; import org.eclipse.edc.jsonld.TitaniumJsonLd; import org.eclipse.edc.spi.result.Result; +import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; -import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; -import org.eclipse.tractusx.irs.edc.client.asset.transformer.JsonObjectFromAssetRequestTransformer; import org.eclipse.tractusx.irs.edc.client.model.ContractOfferDescription; import org.eclipse.tractusx.irs.edc.client.model.NegotiationRequest; import org.eclipse.tractusx.irs.edc.client.model.TransferProcessRequest; @@ -98,21 +87,11 @@ public class EdcTransformer { private final org.eclipse.tractusx.irs.edc.client.transformer.JsonObjectToPolicyTransformer jsonObjectToPolicyTransformer; private final TitaniumJsonLd titaniumJsonLd; private final TransformerContextImpl transformerContext; - private final JsonObjectFromAssetRequestTransformer jsonObjectFromAssetRequestTransformer; + private final JsonObjectFromAssetTransformer jsonObjectFromAssetTransformer; public EdcTransformer(@Qualifier(JSON_LD_OBJECT_MAPPER) final ObjectMapper objectMapper, final TitaniumJsonLd titaniumJsonLd, final TypeTransformerRegistry typeTransformerRegistry) { this.titaniumJsonLd = titaniumJsonLd; - this.titaniumJsonLd.registerNamespace("type", ASSET_CREATION_DATA_ADDRESS_TYPE); - this.titaniumJsonLd.registerNamespace("baseUrl", ASSET_CREATION_DATA_ADDRESS_BASE_URL); - this.titaniumJsonLd.registerNamespace("proxyMethod", ASSET_CREATION_DATA_ADDRESS_PROXY_METHOD); - this.titaniumJsonLd.registerNamespace("proxyBody", ASSET_CREATION_DATA_ADDRESS_PROXY_BODY); - this.titaniumJsonLd.registerNamespace("method", ASSET_CREATION_DATA_ADDRESS_METHOD); - this.titaniumJsonLd.registerNamespace("asset", ASSET_CREATION_ASSET); - this.titaniumJsonLd.registerNamespace("dataAddress", ASSET_CREATION_DATA_ADDRESS); - this.titaniumJsonLd.registerNamespace("proxyPath", ASSET_CREATION_DATA_ADDRESS_PROXY_PATH); - this.titaniumJsonLd.registerNamespace("proxyQueryParams", - ASSET_CREATION_DATA_ADDRESS_PROXY_QUERY_PARAMS); final JsonBuilderFactory jsonBuilderFactory = Json.createBuilderFactory(Map.of()); jsonObjectFromNegotiationInitiateDtoTransformer = new JsonObjectFromNegotiationInitiateDtoTransformer( @@ -123,8 +102,7 @@ public EdcTransformer(@Qualifier(JSON_LD_OBJECT_MAPPER) final ObjectMapper objec jsonObjectFromContractOfferDescriptionTransformer = new JsonObjectFromContractOfferDescriptionTransformer( jsonBuilderFactory); jsonObjectFromCatalogRequestTransformer = new JsonObjectFromCatalogRequestTransformer(jsonBuilderFactory); - - jsonObjectFromAssetRequestTransformer = new JsonObjectFromAssetRequestTransformer(jsonBuilderFactory); + jsonObjectFromAssetTransformer = new JsonObjectFromAssetTransformer(jsonBuilderFactory, objectMapper); jsonObjectToPolicyTransformer = new org.eclipse.tractusx.irs.edc.client.transformer.JsonObjectToPolicyTransformer( objectMapper); @@ -157,10 +135,9 @@ public EdcTransformer(@Qualifier(JSON_LD_OBJECT_MAPPER) final ObjectMapper objec typeTransformerRegistry.register(new JsonObjectFromPolicyTransformer(jsonBuilderFactory)); typeTransformerRegistry.register(new JsonObjectFromDistributionTransformer(jsonBuilderFactory)); typeTransformerRegistry.register(new JsonObjectFromDataServiceTransformer(jsonBuilderFactory)); - typeTransformerRegistry.register(new JsonObjectFromAssetTransformer(jsonBuilderFactory, objectMapper)); + typeTransformerRegistry.register(jsonObjectFromAssetTransformer); typeTransformerRegistry.register(new JsonObjectFromCriterionTransformer(jsonBuilderFactory, objectMapper)); typeTransformerRegistry.register(new JsonObjectFromDataAddressTransformer(jsonBuilderFactory)); - typeTransformerRegistry.register(jsonObjectFromAssetRequestTransformer); } public Catalog transformCatalog(final String jsonString, final Charset charset) { @@ -198,8 +175,8 @@ public JsonObject transformCatalogRequestToJson(final CatalogRequest catalogRequ return titaniumJsonLd.compact(transform).asOptional().orElseThrow(); } - public JsonObject transformAssetRequestToJson(final AssetRequest assetRequest) { - final JsonObject transform = jsonObjectFromAssetRequestTransformer.transform(assetRequest, transformerContext); + public JsonObject transformAssetToJson(final Asset assetRequest) { + final JsonObject transform = jsonObjectFromAssetTransformer.transform(assetRequest, transformerContext); return titaniumJsonLd.compact(transform).asOptional().orElseThrow(); } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java index 6e4463e073..be3194c004 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java @@ -20,6 +20,7 @@ package org.eclipse.tractusx.irs.edc.client.asset; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.spi.types.domain.HttpDataAddress.HTTP_DATA; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; @@ -28,6 +29,7 @@ import java.util.Map; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -43,7 +45,6 @@ import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; -import org.eclipse.tractusx.irs.edc.client.asset.model.AssetRequest; import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationMethod; import org.eclipse.tractusx.irs.edc.client.asset.model.NotificationType; import org.eclipse.tractusx.irs.edc.client.asset.model.exception.CreateEdcAssetException; @@ -71,14 +72,12 @@ class EdcAssetServiceTest { EdcConfiguration.ControlplaneConfig.EndpointConfig endpointConfig; @Mock private RestTemplate restTemplate; - private org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper objectMapper; private EdcTransformer edcTransformer; private EdcAssetService service; @BeforeEach void setUp() { - this.objectMapper = new org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper(); TitaniumJsonLd jsonLd = new TitaniumJsonLd(new ConsoleMonitor()); jsonLd.registerNamespace("odrl", "http://www.w3.org/ns/odrl/2/"); jsonLd.registerNamespace("dct", "https://purl.org/dc/terms/"); @@ -92,69 +91,60 @@ void setUp() { } @Test - void testAssetCreateRequestStructure() throws JSONException { + void testAssetCreateRequestStructure() throws JSONException, JsonProcessingException { Map properties = Map.of("description", "endpoint to qualityinvestigation receive", "contenttype", "application/json", "policy-id", "use-eu", "type", "receive", "notificationtype", "qualityinvestigation", "notificationmethod", "receive"); DataAddress dataAddress = DataAddress.Builder.newInstance() - .type("DEFAULT_DATA_ADDRESS_PROPERTY_TYPE") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/type", - "HttpData") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", + .type(HTTP_DATA) + .property("https://w3id.org/edc/v0.0.1/ns/type", "HttpData") + .property("https://w3id.org/edc/v0.0.1/ns/baseUrl", "https://traceability.dev.demo.catena-x.net/api/qualitynotifications/receive") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", - "true") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", - "true") - .property("https://w3id.org/edc/v0.0.1/ns/dataAddress/method", - "POST") + .property("https://w3id.org/edc/v0.0.1/ns/proxyMethod", "true") + .property("https://w3id.org/edc/v0.0.1/ns/proxyBody", "true") + .property("https://w3id.org/edc/v0.0.1/ns/method", "POST") .build(); - Asset asset = Asset.Builder.newInstance().id("Asset1").contentType("Asset").properties(properties).build(); + Asset asset = Asset.Builder.newInstance() + .id("Asset1") + .contentType("Asset") + .properties(properties) + .dataAddress(dataAddress) + .build(); + System.out.println(objectMapper().writeValueAsString(asset)); + System.out.println(objectMapper().writeValueAsString(dataAddress)); + System.out.println(objectMapper().writeValueAsString(properties)); + JsonObject jsonObject = edcTransformer.transformAssetToJson(asset); + System.out.println(objectMapper().writeValueAsString(jsonObject)); - JsonObject jsonObject = edcTransformer.transformAssetRequestToJson( - AssetRequest.builder().asset(asset).dataAddress(dataAddress).build()); - - JSONAssert.assertEquals(jsonObject.toString(), """ + JSONAssert.assertEquals(""" { - "asset": { - "@id": "Asset1", - "@type": "edc:Asset", - "edc:properties": { - "edc:id": "Asset1", - "edc:contenttype": "Asset" - } + "@id": "Asset1", + "@type": "edc:Asset", + "edc:properties": { + "edc:id": "Asset1", + "edc:contenttype": "Asset" }, - "dataAddress": { + "edc:dataAddress": { "@type": "edc:DataAddress", - "type": "HttpData", - "proxyBody": "true", - "edc:type": "DEFAULT_DATA_ADDRESS_PROPERTY_TYPE", - "baseUrl": "https://traceability.dev.demo.catena-x.net/api/qualitynotifications/receive", - "method": "POST", - "proxyMethod": "true" + "edc:type": "HttpData", + "edc:proxyBody": "true", + "edc:baseUrl": "https://traceability.dev.demo.catena-x.net/api/qualitynotifications/receive", + "edc:method": "POST", + "edc:proxyMethod": "true" }, "@context": { + "dct": "https://purl.org/dc/terms/", "tx": "https://w3id.org/tractusx/v0.0.1/ns/", - "method": "https://w3id.org/edc/v0.0.1/ns/dataAddress/method", - "dataAddress": "https://w3id.org/edc/v0.0.1/ns/dataAddress", "edc": "https://w3id.org/edc/v0.0.1/ns/", - "proxyQueryParams": "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyQueryParams", - "proxyBody": "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyBody", - "type": "https://w3id.org/edc/v0.0.1/ns/dataAddress/type", - "proxyPath": "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyPath", - "dspace": "https://w3id.org/dspace/v0.8/", - "baseUrl": "https://w3id.org/edc/v0.0.1/ns/dataAddress/baseUrl", - "dct": "https://purl.org/dc/terms/", - "proxyMethod": "https://w3id.org/edc/v0.0.1/ns/dataAddress/proxyMethod", - "odrl": "http://www.w3.org/ns/odrl/2/", "dcat": "https://www.w3.org/ns/dcat/", - "asset": "https://w3id.org/edc/v0.0.1/ns/asset" + "odrl": "http://www.w3.org/ns/odrl/2/", + "dspace": "https://w3id.org/dspace/v0.8/" } } - """, false); + """, jsonObject.toString(), false); } @Test From e5b6eab90d89b41b90d3d7b02e26cebe6233a28e Mon Sep 17 00:00:00 2001 From: Jaro Hartmann Date: Mon, 19 Feb 2024 18:35:01 +0100 Subject: [PATCH 47/55] feat(edc-client): Replace AssetRequest with Asset and corresponding Transformer --- .../tractusx/irs/edc/client/asset/EdcAssetServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java index be3194c004..d61bd222d9 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/asset/EdcAssetServiceTest.java @@ -122,10 +122,10 @@ void testAssetCreateRequestStructure() throws JSONException, JsonProcessingExcep JSONAssert.assertEquals(""" { "@id": "Asset1", - "@type": "edc:Asset", + "@type": "edc:Asset", "edc:properties": { "edc:id": "Asset1", - "edc:contenttype": "Asset" + "edc:contenttype": "Asset" }, "edc:dataAddress": { "@type": "edc:DataAddress", From 24d9c7e02e5b6ef4541ce6c5b654a73e7c61dcfa Mon Sep 17 00:00:00 2001 From: ds-jhartmann Date: Tue, 20 Feb 2024 09:24:09 +0000 Subject: [PATCH 48/55] chore(release): Prepare release for Helm version 6.14.1 --- charts/irs-helm/Chart.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/irs-helm/Chart.yaml b/charts/irs-helm/Chart.yaml index e2ab420f8c..caa726f415 100644 --- a/charts/irs-helm/Chart.yaml +++ b/charts/irs-helm/Chart.yaml @@ -35,12 +35,12 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 6.14.0 +version: 6.14.1 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "4.5.0" +appVersion: "4.5.1" dependencies: - name: common repository: https://charts.bitnami.com/bitnami From 58ae8e20e5ce76fb37156dc526159246373887a6 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Tue, 20 Feb 2024 11:33:59 +0100 Subject: [PATCH 49/55] feature(irs-edc-client): #412 rename service --- ...vice.java => DigitalTwinRegistryCreateShellService.java} | 2 +- ....java => DigitalTwinRegistryCreateShellServiceTest.java} | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/{DigitalTwinRegistryService.java => DigitalTwinRegistryCreateShellService.java} (98%) rename irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/{DigitalTwinRegistryServiceTest.java => DigitalTwinRegistryCreateShellServiceTest.java} (98%) diff --git a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryService.java b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryCreateShellService.java similarity index 98% rename from irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryService.java rename to irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryCreateShellService.java index 195f557d1c..88b900558d 100644 --- a/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryService.java +++ b/irs-registry-client/src/main/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryCreateShellService.java @@ -38,7 +38,7 @@ */ @Slf4j @RequiredArgsConstructor -public class DigitalTwinRegistryService { +public class DigitalTwinRegistryCreateShellService { private final RestTemplate restTemplate; private final String createShellUrl; diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryServiceTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryCreateShellServiceTest.java similarity index 98% rename from irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryServiceTest.java rename to irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryCreateShellServiceTest.java index 4c413edf4d..89ae49c5fd 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryServiceTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DigitalTwinRegistryCreateShellServiceTest.java @@ -48,16 +48,16 @@ import org.springframework.web.client.RestTemplate; @ExtendWith(MockitoExtension.class) -class DigitalTwinRegistryServiceTest { +class DigitalTwinRegistryCreateShellServiceTest { private static final String CREATE_SHELL_URL = "/shell-descriptors"; @Mock private RestTemplate restTemplate; - private DigitalTwinRegistryService service; + private DigitalTwinRegistryCreateShellService service; @BeforeEach void setUp() { - service = new DigitalTwinRegistryService(restTemplate, CREATE_SHELL_URL); + service = new DigitalTwinRegistryCreateShellService(restTemplate, CREATE_SHELL_URL); } @Test From 36be2deefc1d3dad6d216c145a3d3a26c53950be Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Tue, 20 Feb 2024 11:54:34 +0100 Subject: [PATCH 50/55] chore(release): prepare release 4.6.0 --- CHANGELOG.md | 17 ++++++++++++----- COMPATIBILITY_MATRIX.md | 16 ++++++++++++++++ CONTRIBUTING.md | 20 +++++++++++++++++--- charts/irs-helm/CHANGELOG.md | 5 ++--- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e463b78f7e..5936f952d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,18 +5,25 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + + + +## [4.6.0] - 2024-02-20 ### Added - Added concept to conform with IndustryCore Changes CX-0126 and CX-127 +- Added release instructions to CONTRIBUTING.md - EdcAssetService capable to create assets inside EDC - EdcPolicyDefinitionService capable to create polices inside EDC - EdcContractDefinitionService capable to create contracts inside EDC ### Changed - Updated AUTHORS.md +- Reduced log level in MeterRegistryService in order to avoid excessive logging +- Moved Docker notice to separate file #425 -## [4.5.1] - 2024-02-07 -### Changed -- moved Docker notice to separate file #425 +### Fixed +- Fixed Log4J configuration +- Fix tavern and cucumber tests ## [4.5.0] - 2024-02-07 ### Added @@ -524,8 +531,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Unresolved - **Select Aspects you need** You are able to select the needed aspects for which you want to collect the correct endpoint information. -[Unreleased]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.5.1...HEAD -[4.5.1]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.5.0...4.5.1 +[Unreleased]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.6.0...HEAD +[4.5.1]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.5.0...4.6.0 [4.5.0]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.4.0...4.5.0 [4.4.0]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.3.0...4.4.0 [4.3.0]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.2.0...4.3.0 diff --git a/COMPATIBILITY_MATRIX.md b/COMPATIBILITY_MATRIX.md index 9f80503b13..1d5acd4792 100644 --- a/COMPATIBILITY_MATRIX.md +++ b/COMPATIBILITY_MATRIX.md @@ -2,6 +2,22 @@ Full changelog of IRS: [changelog](CHANGELOG.md) + +## [4.6.0] - 2024-02-20 +| Dependency | Version | Helm | Comments | +|---------------------------|------------------------------|------------|-----------------| +| EDC | 0.5.3 | 0.5.3 | | +| EDC PostgresSQL | 15.1.0-debian-11-r12 | 12.1.6 | Optional | +| MIW | 0.1.0 | 0.1.0 | REST connection | +| Semantics Hub | 0.1.29 | v0.2.11-M1 | REST connection | +| DTR | 0.3.14-M1 | 0.3.22 | REST connection | +| Minio | RELEASE.2022-11-11T03-44-20Z | 5.0.1 | | +| SingleLevelBomAsBuilt | 2.0.0 | - | Model version | +| SingleLevelBomAsPlanned | 2.0.0 | - | Model version | +| SingleLevelBomAsSpecified | 1.0.0 | - | Model version | +| SingleLevelUsageAsBuilt | 2.0.0 | - | Model version | + + ## [4.2.0] - 2023-11-28 | Dependency | Version | Helm | Comments | |---------------------------|------------------------------|------------|-----------------| diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1c6bc91c34..da25c52468 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -152,14 +152,28 @@ https://github.com/google/google-java-format/blob/master/README.md#intellij-jre- ### Create a release -1. Choose a release version. Use semantic versioning! +1. Choose a release version. Use semantic versioning! Create a respective branch e.g. `chore/prepare-release-2.6.1`. 2. Add release notes for new version in [CHANGELOG.md](CHANGELOG.md) and [charts/irs-helm/CHANGELOG.md](charts/irs-helm/CHANGELOG.md) (e.g. https://github.com/catenax-ng/tx-item-relationship-service/pull/328) -3. Update [COMPATIBILITY_MATRIX.md](COMPATIBILITY_MATRIX.md) +3. Update [COMPATIBILITY_MATRIX.md](COMPATIBILITY_MATRIX.md) (see [catena-x-environments](https://github.com/catenax-ng/tx-item-relationship-service/tree/catena-x-environments/charts/irs-environments)) 4. Create Git tag for the desired release version `git tag x.x.x` + (the irs-helm tag will be created by the github workflow based on the version in the irs-helm changelog) 5. Push Git tag to repository `git push origin x.x.x` 6. Wait for release workflow to complete 7. Merge the automatically opened PR by github-actions bot -8. Notify about the release in IRS Matrix Chat +8. Notify about the release in IRS Matrix Chat. Template: + + > **IRS Release x.x.x** + > + > Hello, + > + > IRS version x.x.x is released. + > + > https://github.com/eclipse-tractusx/item-relationship-service/releases/tag/x.x.x
+ > https://github.com/eclipse-tractusx/item-relationship-service/releases/tag/irs-helm-y.y.y
+ > **Full Changelog:** https://github.com/eclipse-tractusx/item-relationship-service/compare/w.w.w...x.x.x + + _(replace x.x.x with IRS version to release, y.y.y with IRS helm version to release and w.w.w with previous IRS version)_ + ## Contact diff --git a/charts/irs-helm/CHANGELOG.md b/charts/irs-helm/CHANGELOG.md index 5905fbac62..d5cc57894e 100644 --- a/charts/irs-helm/CHANGELOG.md +++ b/charts/irs-helm/CHANGELOG.md @@ -6,10 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [6.14.1] - 2024-02-20 +## [6.15.0] - 2024-02-20 ### Changed -- Update IRS version to 4.5.1 - +- Update IRS version to 4.6.0 ## [6.14.0] - 2024-02-07 ### Added From ef03765481e4a1d444961d204115d7e02f580898 Mon Sep 17 00:00:00 2001 From: "Krzysztof Massalski (Extern)" Date: Tue, 20 Feb 2024 12:58:50 +0100 Subject: [PATCH 51/55] feat(fix):[#XXX] adjust submodel api examples --- docs/src/api/irs-api.yaml | 9 ++++++--- .../tractusx/irs/configuration/OpenApiExamples.java | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/src/api/irs-api.yaml b/docs/src/api/irs-api.yaml index f7c25939dc..085b640c8b 100644 --- a/docs/src/api/irs-api.yaml +++ b/docs/src/api/irs-api.yaml @@ -1077,7 +1077,7 @@ components: lexicalValue: piece quantityNumber: 1.0 shells: - - contractAgreementId: a787aa13-2bd7-488f-9e25-40682003901b + - contractAgreementId: f253718e-a270-4367-901b-9d50d9bd8462 payload: description: - language: en @@ -1131,6 +1131,7 @@ components: type: ModelReference submodels: - aspectType: supply_chain_impacted + contractAgreementId: f253718e-a270-4367-901b-9d50d9bd8462 identification: urn:uuid:fc784d2a-5506-4e61-8e34-21600f8cdeff payload: supplyChainImpacted: "YES" @@ -1199,7 +1200,7 @@ components: lexicalValue: piece quantityNumber: 1.0 shells: - - contractAgreementId: a787aa13-2bd7-488f-9e25-40682003901b + - contractAgreementId: f253718e-a270-4367-901b-9d50d9bd8462 payload: description: - language: en @@ -1253,6 +1254,7 @@ components: type: ModelReference submodels: - aspectType: urn:bamm:io.catenax.single_level_bom_as_built:1.0.0 + contractAgreementId: f253718e-a270-4367-901b-9d50d9bd8462 identification: urn:uuid:fc784d2a-5506-4e61-8e34-21600f8cdeff payload: catenaXId: urn:uuid:d9bec1c6-e47c-4d18-ba41-0a5fe8b7f447 @@ -1390,7 +1392,7 @@ components: lexicalValue: piece quantityNumber: 1.0 shells: - - contractAgreementId: a787aa13-2bd7-488f-9e25-40682003901b + - contractAgreementId: f253718e-a270-4367-901b-9d50d9bd8462 payload: description: - language: en @@ -1442,6 +1444,7 @@ components: value: urn:bamm:com.catenax.vehicle:0.1.1#PartDetails submodels: - aspectType: urn:bamm:io.catenax.single_level_bom_as_built:1.0.0 + contractAgreementId: f253718e-a270-4367-901b-9d50d9bd8462 identification: urn:uuid:fc784d2a-5506-4e61-8e34-21600f8cdeff payload: catenaXId: urn:uuid:d9bec1c6-e47c-4d18-ba41-0a5fe8b7f447 diff --git a/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/OpenApiExamples.java b/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/OpenApiExamples.java index 7365543464..2e04d95ba3 100644 --- a/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/OpenApiExamples.java +++ b/irs-api/src/main/java/org/eclipse/tractusx/irs/configuration/OpenApiExamples.java @@ -284,6 +284,7 @@ private Example createCompleteEssJobResult() { private Submodel createEssSubmodel() { return Submodel.builder() + .contractAgreementId(EXAMPLE_ID) .aspectType(SUPPLY_CHAIN_IMPACTED_ASPECT_TYPE) .identification(SUBMODEL_IDENTIFICATION) .payload(Map.of(SUPPLY_CHAIN_IMPACTED_KEY, SUPPLY_CHAIN_IMPACTER_RESULT)) @@ -343,6 +344,7 @@ private Example createCanceledJobResponse() { private Submodel createSubmodel() { return Submodel.builder() + .contractAgreementId(EXAMPLE_ID) .aspectType("urn:bamm:io.catenax.single_level_bom_as_built:1.0.0") .identification(SUBMODEL_IDENTIFICATION) .payload(createAssemblyPartRelationshipPayloadMap()) @@ -373,7 +375,7 @@ private Tombstone createTombstone() { } private Shell createShell() { - return new Shell("a787aa13-2bd7-488f-9e25-40682003901b", + return new Shell(EXAMPLE_ID, AssetAdministrationShellDescriptor.builder() .description(List.of(LangString.builder() .language("en") From 649ddcad6d263c3c3e0b438fb64efff891d51892 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Tue, 20 Feb 2024 14:47:14 +0100 Subject: [PATCH 52/55] chore(release): correct CHANGELOG and CONTRIBUTING.md --- CHANGELOG.md | 8 +++++++- CONTRIBUTING.md | 14 +++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5936f952d0..5f276734f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed Log4J configuration - Fix tavern and cucumber tests +## [4.5.1] - 2024-02-20 +### Changed +- Moved Docker notice to separate file #425 + ## [4.5.0] - 2024-02-07 ### Added - Added helper script for building documentation locally. @@ -532,7 +536,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Select Aspects you need** You are able to select the needed aspects for which you want to collect the correct endpoint information. [Unreleased]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.6.0...HEAD -[4.5.1]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.5.0...4.6.0 +[4.6.0]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.5.1...4.6.0 +[4.5.1]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.5.0...4.5.1 +[4.5.1]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.5.0...4.5.1 [4.5.0]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.4.0...4.5.0 [4.4.0]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.3.0...4.4.0 [4.3.0]: https://github.com/eclipse-tractusx/item-relationship-service/compare/4.2.0...4.3.0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index da25c52468..8300354d0e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -155,17 +155,17 @@ https://github.com/google/google-java-format/blob/master/README.md#intellij-jre- 1. Choose a release version. Use semantic versioning! Create a respective branch e.g. `chore/prepare-release-2.6.1`. 2. Add release notes for new version in [CHANGELOG.md](CHANGELOG.md) and [charts/irs-helm/CHANGELOG.md](charts/irs-helm/CHANGELOG.md) (e.g. https://github.com/catenax-ng/tx-item-relationship-service/pull/328) 3. Update [COMPATIBILITY_MATRIX.md](COMPATIBILITY_MATRIX.md) (see [catena-x-environments](https://github.com/catenax-ng/tx-item-relationship-service/tree/catena-x-environments/charts/irs-environments)) -4. Create Git tag for the desired release version `git tag x.x.x` +4. Create pull request and merge to main +5. Create Git tag for the desired release version `git tag x.x.x` (the irs-helm tag will be created by the github workflow based on the version in the irs-helm changelog) -5. Push Git tag to repository `git push origin x.x.x` -6. Wait for release workflow to complete -7. Merge the automatically opened PR by github-actions bot -8. Notify about the release in IRS Matrix Chat. Template: +6. Push Git tag to repository `git push origin x.x.x` +7. Wait for release workflow to complete +8. Merge the automatically opened PR by github-actions bot +9. Create pull request to eclipse-tractusx +10. Notify about the release in IRS Matrix Chat. Template: > **IRS Release x.x.x** > - > Hello, - > > IRS version x.x.x is released. > > https://github.com/eclipse-tractusx/item-relationship-service/releases/tag/x.x.x
From bf5bba0b0f46cb1ec8199ef691ce2440dbd108bd Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Tue, 20 Feb 2024 14:48:50 +0100 Subject: [PATCH 53/55] Update CHANGELOG.md Co-authored-by: Jaro Hartmann <57985712+ds-jhartmann@users.noreply.github.com> --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f276734f9..df776b7964 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Updated AUTHORS.md - Reduced log level in MeterRegistryService in order to avoid excessive logging -- Moved Docker notice to separate file #425 ### Fixed - Fixed Log4J configuration From e54fc84f3627bf10b4620ae4907aa3ff454fd31c Mon Sep 17 00:00:00 2001 From: dsmf Date: Tue, 20 Feb 2024 13:51:38 +0000 Subject: [PATCH 54/55] chore(release): Prepare release for Helm version 6.15.0 --- charts/irs-helm/Chart.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/irs-helm/Chart.yaml b/charts/irs-helm/Chart.yaml index caa726f415..2dca7bbebe 100644 --- a/charts/irs-helm/Chart.yaml +++ b/charts/irs-helm/Chart.yaml @@ -35,12 +35,12 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 6.14.1 +version: 6.15.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "4.5.1" +appVersion: "4.6.0" dependencies: - name: common repository: https://charts.bitnami.com/bitnami From 7359fc4e10609fdb718edbfdc753bd3fdd2e4122 Mon Sep 17 00:00:00 2001 From: ds-ext-sceronik Date: Wed, 21 Feb 2024 10:13:50 +0100 Subject: [PATCH 55/55] feature(irs-edc-client): #412 merge main --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c027771541..671abfac4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] - +### Added +- DigitalTwinRegistryCreateShellService in irs-registry-client for creating shells in DTR directly ## [4.6.0] - 2024-02-20 @@ -15,7 +16,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - EdcAssetService capable to create assets inside EDC - EdcPolicyDefinitionService capable to create polices inside EDC - EdcContractDefinitionService capable to create contracts inside EDC -- DigitalTwinRegistryCreateShellService in irs-registry-client for creating shells in DTR directly ### Changed - Updated AUTHORS.md