From 4d4387da37ded183c697c0ebbf51ded9fbb449c3 Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Thu, 27 Jul 2023 18:00:44 +0530 Subject: [PATCH 01/11] Added external subject in specific asset Ids --- .../entities/common/ExternalSubjectId.java | 43 ++++++++++ .../entities/common/KeyValuePair.java | 12 ++- .../facilitator/DigitalTwinsUtility.java | 86 +++++++++++-------- 3 files changed, 103 insertions(+), 38 deletions(-) create mode 100644 modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ExternalSubjectId.java diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ExternalSubjectId.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ExternalSubjectId.java new file mode 100644 index 000000000..f9319a29b --- /dev/null +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ExternalSubjectId.java @@ -0,0 +1,43 @@ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023 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.sde.digitaltwins.entities.common; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class ExternalSubjectId { + + private String type; + + private List keys; + +} diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java index 65516a342..beed6dfde 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java @@ -21,15 +21,25 @@ package org.eclipse.tractusx.sde.digitaltwins.entities.common; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @Data -@NoArgsConstructor +@Builder @AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(Include. NON_NULL) public class KeyValuePair { private String name; private String value; + + private ExternalSubjectId externalSubjectId; } diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java index ade57a55d..c4d6ff067 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java @@ -26,6 +26,7 @@ import org.eclipse.tractusx.sde.common.constants.CommonConstants; import org.eclipse.tractusx.sde.common.utils.UUIdGenerator; import org.eclipse.tractusx.sde.digitaltwins.entities.common.Endpoint; +import org.eclipse.tractusx.sde.digitaltwins.entities.common.ExternalSubjectId; import org.eclipse.tractusx.sde.digitaltwins.entities.common.KeyValuePair; import org.eclipse.tractusx.sde.digitaltwins.entities.common.Keys; import org.eclipse.tractusx.sde.digitaltwins.entities.common.ProtocolInformation; @@ -35,6 +36,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -59,75 +61,73 @@ public ShellDescriptorRequest getShellDescriptorRequest(Map spec JsonNode jsonNode = mapper.convertValue(object, ObjectNode.class); + List bpns = getFieldFromJsonNodeArray(jsonNode, "bpn_numbers"); + return ShellDescriptorRequest.builder() .idShort(String.format("%s_%s_%s", getFieldFromJsonNode(jsonNode, "name_at_manufacturer"), manufacturerId, getFieldFromJsonNode(jsonNode, "manufacturer_part_id"))) .globalAssetId(getFieldFromJsonNode(jsonNode, "uuid")) - .specificAssetIds(getSpecificAssetIds(specificIdentifiers)) - .description(List.of()) - .id(UUIdGenerator.getUrnUuid()) - .build(); + .specificAssetIds(getSpecificAssetIds(specificIdentifiers, bpns)).description(List.of()) + .id(UUIdGenerator.getUrnUuid()).build(); } @SneakyThrows public CreateSubModelRequest getCreateSubModelRequest(String shellId, String sematicId, String idShortofModel) { String identification = UUIdGenerator.getUrnUuid(); - - SemanticId semanticId = SemanticId.builder() - .type(CommonConstants.EXTERNAL_REFERENCE) - .keys(List.of(new Keys(CommonConstants.GLOBAL_REFERENCE,sematicId))) - .build(); + + SemanticId semanticId = SemanticId.builder().type(CommonConstants.EXTERNAL_REFERENCE) + .keys(List.of(new Keys(CommonConstants.GLOBAL_REFERENCE, sematicId))).build(); List endpoints = prepareDtEndpoint(shellId, identification); - return CreateSubModelRequest.builder() - .id(identification) - .idShort(idShortofModel) - .semanticId(semanticId) - .endpoints(endpoints) - .build(); + return CreateSubModelRequest.builder().id(identification).idShort(idShortofModel).semanticId(semanticId) + .endpoints(endpoints).build(); } - + @SneakyThrows - public CreateSubModelRequest getCreateSubModelRequestForChild(String shellId, String sematicId, String idShortofModel, String identification) { - - SemanticId semanticId = SemanticId.builder() - .type(CommonConstants.EXTERNAL_REFERENCE) - .keys(List.of(new Keys(CommonConstants.GLOBAL_REFERENCE,sematicId))) - .build(); + public CreateSubModelRequest getCreateSubModelRequestForChild(String shellId, String sematicId, + String idShortofModel, String identification) { + + SemanticId semanticId = SemanticId.builder().type(CommonConstants.EXTERNAL_REFERENCE) + .keys(List.of(new Keys(CommonConstants.GLOBAL_REFERENCE, sematicId))).build(); List endpoints = prepareDtEndpoint(shellId, identification); - return CreateSubModelRequest.builder() - .idShort(idShortofModel) - .id(identification) - .semanticId(semanticId) - .endpoints(endpoints) - .build(); + return CreateSubModelRequest.builder().idShort(idShortofModel).id(identification).semanticId(semanticId) + .endpoints(endpoints).build(); } public List prepareDtEndpoint(String shellId, String submodelIdentification) { List endpoints = new ArrayList<>(); - endpoints.add(Endpoint.builder() - .endpointInterface(CommonConstants.INTERFACE) + endpoints.add(Endpoint.builder().endpointInterface(CommonConstants.INTERFACE) .protocolInformation(ProtocolInformation.builder() - .endpointAddress(edcEndpoint + "/api/public/" + encodedUrl("shells/"+shellId+ "/submodels/"+submodelIdentification) + .endpointAddress(edcEndpoint + "/api/public/" + + encodedUrl("shells/" + shellId + "/submodels/" + submodelIdentification) + CommonConstants.SUBMODEL_CONTEXT_URL) .endpointProtocol(CommonConstants.HTTP) .endpointProtocolVersion(List.of(CommonConstants.ENDPOINT_PROTOCOL_VERSION)) .subProtocol(CommonConstants.SUB_PROTOCOL) - .subprotocolBodyEncoding(CommonConstants.BODY_ENCODING) - .build()) + .subprotocolBodyEncoding(CommonConstants.BODY_ENCODING).build()) .build()); return endpoints; } - - private ArrayList getSpecificAssetIds(Map specificAssetIds) { + + private ArrayList getSpecificAssetIds(Map specificAssetIds, List bpns) { ArrayList specificIdentifiers = new ArrayList<>(); - specificAssetIds.entrySet().stream() - .forEach(entry -> specificIdentifiers.add(new KeyValuePair(entry.getKey(), entry.getValue()))); + if (!bpns.isEmpty()) { + for (String bpn : bpns) { + ExternalSubjectId externalSubjectId = ExternalSubjectId.builder().type("ExternalReference") + .keys(List.of(Keys.builder().type("Property").value(bpn).build())).build(); + + specificAssetIds.entrySet().stream().forEach(entry -> specificIdentifiers + .add(new KeyValuePair(entry.getKey(), entry.getValue(), externalSubjectId))); + } + } else { + specificAssetIds.entrySet().stream().forEach( + entry -> specificIdentifiers.add(new KeyValuePair(entry.getKey(), entry.getValue(), null))); + } return specificIdentifiers; } @@ -142,4 +142,16 @@ private String getFieldFromJsonNode(JsonNode jnode, String fieldName) { return ""; } + @SneakyThrows + private List getFieldFromJsonNodeArray(JsonNode jsonNode, String fieldName) { + ObjectMapper objectMapper = new ObjectMapper(); + + if (jsonNode.get(fieldName) != null) + return objectMapper.readValue(jsonNode.get(fieldName).asText(), new TypeReference>() { + }); + + else + return List.of(); + } + } From 8f4b45e48e72f8803a74805c4afc5e08cb373d8c Mon Sep 17 00:00:00 2001 From: ChetanT-System Date: Fri, 28 Jul 2023 12:47:18 +0530 Subject: [PATCH 02/11] A1SDS-2537 : code changes updated --- .../facilitator/DigitalTwinsUtility.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java index c4d6ff067..4693e7b8a 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java @@ -30,6 +30,7 @@ import org.eclipse.tractusx.sde.digitaltwins.entities.common.KeyValuePair; import org.eclipse.tractusx.sde.digitaltwins.entities.common.Keys; import org.eclipse.tractusx.sde.digitaltwins.entities.common.ProtocolInformation; +import org.eclipse.tractusx.sde.digitaltwins.entities.common.SecurityAttributes; import org.eclipse.tractusx.sde.digitaltwins.entities.common.SemanticId; import org.eclipse.tractusx.sde.digitaltwins.entities.request.CreateSubModelRequest; import org.eclipse.tractusx.sde.digitaltwins.entities.request.ShellDescriptorRequest; @@ -118,8 +119,13 @@ private ArrayList getSpecificAssetIds(Map specific if (!bpns.isEmpty()) { for (String bpn : bpns) { - ExternalSubjectId externalSubjectId = ExternalSubjectId.builder().type("ExternalReference") - .keys(List.of(Keys.builder().type("Property").value(bpn).build())).build(); + ExternalSubjectId externalSubjectId = ExternalSubjectId.builder() + .type("ExternalReference") + .keys(List.of(Keys.builder() + .type("Property") + .value(bpn) + .build())) + .build(); specificAssetIds.entrySet().stream().forEach(entry -> specificIdentifiers .add(new KeyValuePair(entry.getKey(), entry.getValue(), externalSubjectId))); @@ -147,7 +153,7 @@ private List getFieldFromJsonNodeArray(JsonNode jsonNode, String fieldNa ObjectMapper objectMapper = new ObjectMapper(); if (jsonNode.get(fieldName) != null) - return objectMapper.readValue(jsonNode.get(fieldName).asText(), new TypeReference>() { + return objectMapper.readValue(jsonNode.get(fieldName).toString(), new TypeReference>() { }); else From 8078a52ad37c1f70b3a994f34826f1eaeb7da52c Mon Sep 17 00:00:00 2001 From: ChetanT-System Date: Fri, 28 Jul 2023 14:26:38 +0530 Subject: [PATCH 03/11] A1SDS-2549: Update AAS submodel endpoints subprotocolBody --- .../sde/common/constants/CommonConstants.java | 8 ++-- .../entities/common/ProtocolInformation.java | 2 + .../entities/common/SecurityAttributes.java | 41 +++++++++++++++++++ .../facilitator/DigitalTwinsUtility.java | 9 ++-- 4 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/SecurityAttributes.java diff --git a/modules/sde-common/src/main/java/org/eclipse/tractusx/sde/common/constants/CommonConstants.java b/modules/sde-common/src/main/java/org/eclipse/tractusx/sde/common/constants/CommonConstants.java index 0731b07e1..f508cfd3e 100644 --- a/modules/sde-common/src/main/java/org/eclipse/tractusx/sde/common/constants/CommonConstants.java +++ b/modules/sde-common/src/main/java/org/eclipse/tractusx/sde/common/constants/CommonConstants.java @@ -37,13 +37,13 @@ private CommonConstants() { public static final String MANUFACTURER_ID = "manufacturerId"; public static final String CUSTOMER_PART_ID = "customerPartId"; public static final String ASSET_LIFECYCLE_PHASE = "assetLifecyclePhase"; - public static final String HTTP = "http"; + public static final String HTTP = "HTTP"; public static final String HTTPS = "HTTPS"; - public static final String ENDPOINT_PROTOCOL_VERSION = "0.1"; + public static final String ENDPOINT_PROTOCOL_VERSION = "1.1"; public static final String PREFIX = "urn:uuid:"; public static final String INTERFACE_EDC = "EDC"; - public static final String SUB_PROTOCOL = "IDS"; + public static final String SUB_PROTOCOL = "DSP"; public static final String SUBMODEL_CONTEXT_URL = "/submodel"; public static final String AS_PLANNED = "AsPlanned"; @@ -51,6 +51,6 @@ private CommonConstants() { public static final String EXTERNAL_REFERENCE = "ExternalReference"; public static final String GLOBAL_REFERENCE = "GlobalReference"; public static final String BODY_ENCODING = "plain"; - public static final String INTERFACE = "https://admin-shell.io/aas/API/3/0/SubmodelServiceSpecification/SSP-003"; + public static final String INTERFACE = "SUBMODEL-3.0"; } diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ProtocolInformation.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ProtocolInformation.java index f83f4b4eb..0bede9268 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ProtocolInformation.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ProtocolInformation.java @@ -45,4 +45,6 @@ public class ProtocolInformation { private String subProtocol; private String subprotocolBody; private String subprotocolBodyEncoding; + private List securityAttributes; + } diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/SecurityAttributes.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/SecurityAttributes.java new file mode 100644 index 000000000..e8b948ae2 --- /dev/null +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/SecurityAttributes.java @@ -0,0 +1,41 @@ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023 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.sde.digitaltwins.entities.common; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class SecurityAttributes { + + + private String type; + private String key; + private String value; + +} diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java index 4693e7b8a..ccbb9e4b7 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java @@ -102,13 +102,14 @@ public List prepareDtEndpoint(String shellId, String submodelIdentific List endpoints = new ArrayList<>(); endpoints.add(Endpoint.builder().endpointInterface(CommonConstants.INTERFACE) .protocolInformation(ProtocolInformation.builder() - .endpointAddress(edcEndpoint + "/api/public/" - + encodedUrl("shells/" + shellId + "/submodels/" + submodelIdentification) - + CommonConstants.SUBMODEL_CONTEXT_URL) + .endpointAddress(edcEndpoint + CommonConstants.SUBMODEL_CONTEXT_URL) .endpointProtocol(CommonConstants.HTTP) .endpointProtocolVersion(List.of(CommonConstants.ENDPOINT_PROTOCOL_VERSION)) .subProtocol(CommonConstants.SUB_PROTOCOL) - .subprotocolBodyEncoding(CommonConstants.BODY_ENCODING).build()) + .subprotocolBody(encodedUrl("id="+shellId+"-"+submodelIdentification)+";dspEndpoint="+edcEndpoint) + .subprotocolBodyEncoding(CommonConstants.BODY_ENCODING) + .securityAttributes(List.of(new SecurityAttributes("NONE","NONE","NONE"))) + .build()) .build()); return endpoints; } From 026a60807c7e808f8dfc10a089b66e954f7a93f0 Mon Sep 17 00:00:00 2001 From: ChetanT-System Date: Fri, 25 Aug 2023 12:45:33 +0530 Subject: [PATCH 04/11] - Updated code changes for DTR service API call --- .../entities/common/KeyValuePair.java | 1 - .../entities/common/LookupQuery.java | 44 +++++++++++++++++++ .../request/ShellLookupQueryRequest.java | 40 +++++++++++++++++ .../external/DigitalTwinsFeignClient.java | 4 ++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/LookupQuery.java create mode 100644 modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/request/ShellLookupQueryRequest.java diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java index beed6dfde..e571af353 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java @@ -40,6 +40,5 @@ public class KeyValuePair { private String name; private String value; - private ExternalSubjectId externalSubjectId; } diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/LookupQuery.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/LookupQuery.java new file mode 100644 index 000000000..b38c58c02 --- /dev/null +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/LookupQuery.java @@ -0,0 +1,44 @@ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023 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.sde.digitaltwins.entities.common; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class LookupQuery { + + private String type; + private List assetIds; + private List semanticIds; + + + +} diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/request/ShellLookupQueryRequest.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/request/ShellLookupQueryRequest.java new file mode 100644 index 000000000..1f86713e0 --- /dev/null +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/request/ShellLookupQueryRequest.java @@ -0,0 +1,40 @@ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023 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.sde.digitaltwins.entities.request; + +import org.eclipse.tractusx.sde.digitaltwins.entities.common.LookupQuery; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class ShellLookupQueryRequest { + + private LookupQuery query; + + + + +} diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java index 90eed3243..283bc5d10 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java @@ -25,6 +25,7 @@ import org.eclipse.tractusx.sde.common.model.KeycloakJWTTokenResponse; import org.eclipse.tractusx.sde.digitaltwins.entities.request.CreateSubModelRequest; import org.eclipse.tractusx.sde.digitaltwins.entities.request.ShellDescriptorRequest; +import org.eclipse.tractusx.sde.digitaltwins.entities.request.ShellLookupQueryRequest; import org.eclipse.tractusx.sde.digitaltwins.entities.response.ShellDescriptorResponse; import org.eclipse.tractusx.sde.digitaltwins.entities.response.ShellLookupResponse; import org.eclipse.tractusx.sde.digitaltwins.entities.response.SubModelListResponse; @@ -68,5 +69,8 @@ ResponseEntity getSubModels(URI digitalTwinsHost, @DeleteMapping(path = "/lookup/shells/{assetIds}") ResponseEntity deleteShell(URI url, @PathVariable("assetIds") String shellId); + + @PostMapping(path = "/lookup/shells/query") + ResponseEntity shellLookupByQuery(URI url, @RequestBody ShellLookupQueryRequest request); } From fbca48b1ec93ca31936b24359a45c1ab69df5f93 Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Thu, 27 Jul 2023 18:00:44 +0530 Subject: [PATCH 05/11] Added external subject in specific asset Ids --- .../entities/common/ExternalSubjectId.java | 43 ++++++++++ .../entities/common/KeyValuePair.java | 12 ++- .../facilitator/DigitalTwinsUtility.java | 86 +++++++++++-------- 3 files changed, 103 insertions(+), 38 deletions(-) create mode 100644 modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ExternalSubjectId.java diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ExternalSubjectId.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ExternalSubjectId.java new file mode 100644 index 000000000..f9319a29b --- /dev/null +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ExternalSubjectId.java @@ -0,0 +1,43 @@ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023 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.sde.digitaltwins.entities.common; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class ExternalSubjectId { + + private String type; + + private List keys; + +} diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java index 65516a342..beed6dfde 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java @@ -21,15 +21,25 @@ package org.eclipse.tractusx.sde.digitaltwins.entities.common; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @Data -@NoArgsConstructor +@Builder @AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(Include. NON_NULL) public class KeyValuePair { private String name; private String value; + + private ExternalSubjectId externalSubjectId; } diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java index ade57a55d..c4d6ff067 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java @@ -26,6 +26,7 @@ import org.eclipse.tractusx.sde.common.constants.CommonConstants; import org.eclipse.tractusx.sde.common.utils.UUIdGenerator; import org.eclipse.tractusx.sde.digitaltwins.entities.common.Endpoint; +import org.eclipse.tractusx.sde.digitaltwins.entities.common.ExternalSubjectId; import org.eclipse.tractusx.sde.digitaltwins.entities.common.KeyValuePair; import org.eclipse.tractusx.sde.digitaltwins.entities.common.Keys; import org.eclipse.tractusx.sde.digitaltwins.entities.common.ProtocolInformation; @@ -35,6 +36,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -59,75 +61,73 @@ public ShellDescriptorRequest getShellDescriptorRequest(Map spec JsonNode jsonNode = mapper.convertValue(object, ObjectNode.class); + List bpns = getFieldFromJsonNodeArray(jsonNode, "bpn_numbers"); + return ShellDescriptorRequest.builder() .idShort(String.format("%s_%s_%s", getFieldFromJsonNode(jsonNode, "name_at_manufacturer"), manufacturerId, getFieldFromJsonNode(jsonNode, "manufacturer_part_id"))) .globalAssetId(getFieldFromJsonNode(jsonNode, "uuid")) - .specificAssetIds(getSpecificAssetIds(specificIdentifiers)) - .description(List.of()) - .id(UUIdGenerator.getUrnUuid()) - .build(); + .specificAssetIds(getSpecificAssetIds(specificIdentifiers, bpns)).description(List.of()) + .id(UUIdGenerator.getUrnUuid()).build(); } @SneakyThrows public CreateSubModelRequest getCreateSubModelRequest(String shellId, String sematicId, String idShortofModel) { String identification = UUIdGenerator.getUrnUuid(); - - SemanticId semanticId = SemanticId.builder() - .type(CommonConstants.EXTERNAL_REFERENCE) - .keys(List.of(new Keys(CommonConstants.GLOBAL_REFERENCE,sematicId))) - .build(); + + SemanticId semanticId = SemanticId.builder().type(CommonConstants.EXTERNAL_REFERENCE) + .keys(List.of(new Keys(CommonConstants.GLOBAL_REFERENCE, sematicId))).build(); List endpoints = prepareDtEndpoint(shellId, identification); - return CreateSubModelRequest.builder() - .id(identification) - .idShort(idShortofModel) - .semanticId(semanticId) - .endpoints(endpoints) - .build(); + return CreateSubModelRequest.builder().id(identification).idShort(idShortofModel).semanticId(semanticId) + .endpoints(endpoints).build(); } - + @SneakyThrows - public CreateSubModelRequest getCreateSubModelRequestForChild(String shellId, String sematicId, String idShortofModel, String identification) { - - SemanticId semanticId = SemanticId.builder() - .type(CommonConstants.EXTERNAL_REFERENCE) - .keys(List.of(new Keys(CommonConstants.GLOBAL_REFERENCE,sematicId))) - .build(); + public CreateSubModelRequest getCreateSubModelRequestForChild(String shellId, String sematicId, + String idShortofModel, String identification) { + + SemanticId semanticId = SemanticId.builder().type(CommonConstants.EXTERNAL_REFERENCE) + .keys(List.of(new Keys(CommonConstants.GLOBAL_REFERENCE, sematicId))).build(); List endpoints = prepareDtEndpoint(shellId, identification); - return CreateSubModelRequest.builder() - .idShort(idShortofModel) - .id(identification) - .semanticId(semanticId) - .endpoints(endpoints) - .build(); + return CreateSubModelRequest.builder().idShort(idShortofModel).id(identification).semanticId(semanticId) + .endpoints(endpoints).build(); } public List prepareDtEndpoint(String shellId, String submodelIdentification) { List endpoints = new ArrayList<>(); - endpoints.add(Endpoint.builder() - .endpointInterface(CommonConstants.INTERFACE) + endpoints.add(Endpoint.builder().endpointInterface(CommonConstants.INTERFACE) .protocolInformation(ProtocolInformation.builder() - .endpointAddress(edcEndpoint + "/api/public/" + encodedUrl("shells/"+shellId+ "/submodels/"+submodelIdentification) + .endpointAddress(edcEndpoint + "/api/public/" + + encodedUrl("shells/" + shellId + "/submodels/" + submodelIdentification) + CommonConstants.SUBMODEL_CONTEXT_URL) .endpointProtocol(CommonConstants.HTTP) .endpointProtocolVersion(List.of(CommonConstants.ENDPOINT_PROTOCOL_VERSION)) .subProtocol(CommonConstants.SUB_PROTOCOL) - .subprotocolBodyEncoding(CommonConstants.BODY_ENCODING) - .build()) + .subprotocolBodyEncoding(CommonConstants.BODY_ENCODING).build()) .build()); return endpoints; } - - private ArrayList getSpecificAssetIds(Map specificAssetIds) { + + private ArrayList getSpecificAssetIds(Map specificAssetIds, List bpns) { ArrayList specificIdentifiers = new ArrayList<>(); - specificAssetIds.entrySet().stream() - .forEach(entry -> specificIdentifiers.add(new KeyValuePair(entry.getKey(), entry.getValue()))); + if (!bpns.isEmpty()) { + for (String bpn : bpns) { + ExternalSubjectId externalSubjectId = ExternalSubjectId.builder().type("ExternalReference") + .keys(List.of(Keys.builder().type("Property").value(bpn).build())).build(); + + specificAssetIds.entrySet().stream().forEach(entry -> specificIdentifiers + .add(new KeyValuePair(entry.getKey(), entry.getValue(), externalSubjectId))); + } + } else { + specificAssetIds.entrySet().stream().forEach( + entry -> specificIdentifiers.add(new KeyValuePair(entry.getKey(), entry.getValue(), null))); + } return specificIdentifiers; } @@ -142,4 +142,16 @@ private String getFieldFromJsonNode(JsonNode jnode, String fieldName) { return ""; } + @SneakyThrows + private List getFieldFromJsonNodeArray(JsonNode jsonNode, String fieldName) { + ObjectMapper objectMapper = new ObjectMapper(); + + if (jsonNode.get(fieldName) != null) + return objectMapper.readValue(jsonNode.get(fieldName).asText(), new TypeReference>() { + }); + + else + return List.of(); + } + } From ae97da4df92bdfa15ad031da36c1850b358d2fe7 Mon Sep 17 00:00:00 2001 From: ChetanT-System Date: Fri, 28 Jul 2023 12:47:18 +0530 Subject: [PATCH 06/11] A1SDS-2537 : code changes updated --- .../facilitator/DigitalTwinsUtility.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java index c4d6ff067..4693e7b8a 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java @@ -30,6 +30,7 @@ import org.eclipse.tractusx.sde.digitaltwins.entities.common.KeyValuePair; import org.eclipse.tractusx.sde.digitaltwins.entities.common.Keys; import org.eclipse.tractusx.sde.digitaltwins.entities.common.ProtocolInformation; +import org.eclipse.tractusx.sde.digitaltwins.entities.common.SecurityAttributes; import org.eclipse.tractusx.sde.digitaltwins.entities.common.SemanticId; import org.eclipse.tractusx.sde.digitaltwins.entities.request.CreateSubModelRequest; import org.eclipse.tractusx.sde.digitaltwins.entities.request.ShellDescriptorRequest; @@ -118,8 +119,13 @@ private ArrayList getSpecificAssetIds(Map specific if (!bpns.isEmpty()) { for (String bpn : bpns) { - ExternalSubjectId externalSubjectId = ExternalSubjectId.builder().type("ExternalReference") - .keys(List.of(Keys.builder().type("Property").value(bpn).build())).build(); + ExternalSubjectId externalSubjectId = ExternalSubjectId.builder() + .type("ExternalReference") + .keys(List.of(Keys.builder() + .type("Property") + .value(bpn) + .build())) + .build(); specificAssetIds.entrySet().stream().forEach(entry -> specificIdentifiers .add(new KeyValuePair(entry.getKey(), entry.getValue(), externalSubjectId))); @@ -147,7 +153,7 @@ private List getFieldFromJsonNodeArray(JsonNode jsonNode, String fieldNa ObjectMapper objectMapper = new ObjectMapper(); if (jsonNode.get(fieldName) != null) - return objectMapper.readValue(jsonNode.get(fieldName).asText(), new TypeReference>() { + return objectMapper.readValue(jsonNode.get(fieldName).toString(), new TypeReference>() { }); else From c5cf32bd17d7e2c3c02409c1e62d514ee178383f Mon Sep 17 00:00:00 2001 From: ChetanT-System Date: Fri, 28 Jul 2023 14:26:38 +0530 Subject: [PATCH 07/11] A1SDS-2549: Update AAS submodel endpoints subprotocolBody --- .../sde/common/constants/CommonConstants.java | 8 ++-- .../entities/common/ProtocolInformation.java | 2 + .../entities/common/SecurityAttributes.java | 41 +++++++++++++++++++ .../facilitator/DigitalTwinsUtility.java | 9 ++-- 4 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/SecurityAttributes.java diff --git a/modules/sde-common/src/main/java/org/eclipse/tractusx/sde/common/constants/CommonConstants.java b/modules/sde-common/src/main/java/org/eclipse/tractusx/sde/common/constants/CommonConstants.java index 0731b07e1..f508cfd3e 100644 --- a/modules/sde-common/src/main/java/org/eclipse/tractusx/sde/common/constants/CommonConstants.java +++ b/modules/sde-common/src/main/java/org/eclipse/tractusx/sde/common/constants/CommonConstants.java @@ -37,13 +37,13 @@ private CommonConstants() { public static final String MANUFACTURER_ID = "manufacturerId"; public static final String CUSTOMER_PART_ID = "customerPartId"; public static final String ASSET_LIFECYCLE_PHASE = "assetLifecyclePhase"; - public static final String HTTP = "http"; + public static final String HTTP = "HTTP"; public static final String HTTPS = "HTTPS"; - public static final String ENDPOINT_PROTOCOL_VERSION = "0.1"; + public static final String ENDPOINT_PROTOCOL_VERSION = "1.1"; public static final String PREFIX = "urn:uuid:"; public static final String INTERFACE_EDC = "EDC"; - public static final String SUB_PROTOCOL = "IDS"; + public static final String SUB_PROTOCOL = "DSP"; public static final String SUBMODEL_CONTEXT_URL = "/submodel"; public static final String AS_PLANNED = "AsPlanned"; @@ -51,6 +51,6 @@ private CommonConstants() { public static final String EXTERNAL_REFERENCE = "ExternalReference"; public static final String GLOBAL_REFERENCE = "GlobalReference"; public static final String BODY_ENCODING = "plain"; - public static final String INTERFACE = "https://admin-shell.io/aas/API/3/0/SubmodelServiceSpecification/SSP-003"; + public static final String INTERFACE = "SUBMODEL-3.0"; } diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ProtocolInformation.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ProtocolInformation.java index f83f4b4eb..0bede9268 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ProtocolInformation.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/ProtocolInformation.java @@ -45,4 +45,6 @@ public class ProtocolInformation { private String subProtocol; private String subprotocolBody; private String subprotocolBodyEncoding; + private List securityAttributes; + } diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/SecurityAttributes.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/SecurityAttributes.java new file mode 100644 index 000000000..e8b948ae2 --- /dev/null +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/SecurityAttributes.java @@ -0,0 +1,41 @@ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023 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.sde.digitaltwins.entities.common; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class SecurityAttributes { + + + private String type; + private String key; + private String value; + +} diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java index 4693e7b8a..ccbb9e4b7 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java @@ -102,13 +102,14 @@ public List prepareDtEndpoint(String shellId, String submodelIdentific List endpoints = new ArrayList<>(); endpoints.add(Endpoint.builder().endpointInterface(CommonConstants.INTERFACE) .protocolInformation(ProtocolInformation.builder() - .endpointAddress(edcEndpoint + "/api/public/" - + encodedUrl("shells/" + shellId + "/submodels/" + submodelIdentification) - + CommonConstants.SUBMODEL_CONTEXT_URL) + .endpointAddress(edcEndpoint + CommonConstants.SUBMODEL_CONTEXT_URL) .endpointProtocol(CommonConstants.HTTP) .endpointProtocolVersion(List.of(CommonConstants.ENDPOINT_PROTOCOL_VERSION)) .subProtocol(CommonConstants.SUB_PROTOCOL) - .subprotocolBodyEncoding(CommonConstants.BODY_ENCODING).build()) + .subprotocolBody(encodedUrl("id="+shellId+"-"+submodelIdentification)+";dspEndpoint="+edcEndpoint) + .subprotocolBodyEncoding(CommonConstants.BODY_ENCODING) + .securityAttributes(List.of(new SecurityAttributes("NONE","NONE","NONE"))) + .build()) .build()); return endpoints; } From e3bada626de160d5e14a2aba8119401ac5e0676b Mon Sep 17 00:00:00 2001 From: ChetanT-System Date: Fri, 25 Aug 2023 12:45:33 +0530 Subject: [PATCH 08/11] - Updated code changes for DTR service API call --- .../entities/common/KeyValuePair.java | 1 - .../entities/common/LookupQuery.java | 44 +++++++++++++++++++ .../request/ShellLookupQueryRequest.java | 40 +++++++++++++++++ .../external/DigitalTwinsFeignClient.java | 4 ++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/LookupQuery.java create mode 100644 modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/request/ShellLookupQueryRequest.java diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java index beed6dfde..e571af353 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java @@ -40,6 +40,5 @@ public class KeyValuePair { private String name; private String value; - private ExternalSubjectId externalSubjectId; } diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/LookupQuery.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/LookupQuery.java new file mode 100644 index 000000000..b38c58c02 --- /dev/null +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/LookupQuery.java @@ -0,0 +1,44 @@ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023 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.sde.digitaltwins.entities.common; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class LookupQuery { + + private String type; + private List assetIds; + private List semanticIds; + + + +} diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/request/ShellLookupQueryRequest.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/request/ShellLookupQueryRequest.java new file mode 100644 index 000000000..1f86713e0 --- /dev/null +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/request/ShellLookupQueryRequest.java @@ -0,0 +1,40 @@ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023 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.sde.digitaltwins.entities.request; + +import org.eclipse.tractusx.sde.digitaltwins.entities.common.LookupQuery; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class ShellLookupQueryRequest { + + private LookupQuery query; + + + + +} diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java index 90eed3243..283bc5d10 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java @@ -25,6 +25,7 @@ import org.eclipse.tractusx.sde.common.model.KeycloakJWTTokenResponse; import org.eclipse.tractusx.sde.digitaltwins.entities.request.CreateSubModelRequest; import org.eclipse.tractusx.sde.digitaltwins.entities.request.ShellDescriptorRequest; +import org.eclipse.tractusx.sde.digitaltwins.entities.request.ShellLookupQueryRequest; import org.eclipse.tractusx.sde.digitaltwins.entities.response.ShellDescriptorResponse; import org.eclipse.tractusx.sde.digitaltwins.entities.response.ShellLookupResponse; import org.eclipse.tractusx.sde.digitaltwins.entities.response.SubModelListResponse; @@ -68,5 +69,8 @@ ResponseEntity getSubModels(URI digitalTwinsHost, @DeleteMapping(path = "/lookup/shells/{assetIds}") ResponseEntity deleteShell(URI url, @PathVariable("assetIds") String shellId); + + @PostMapping(path = "/lookup/shells/query") + ResponseEntity shellLookupByQuery(URI url, @RequestBody ShellLookupQueryRequest request); } From e9259080d841d708d1cd90121884eee21e09ae1f Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Fri, 25 Aug 2023 16:48:52 +0530 Subject: [PATCH 09/11] Update DDTR use of external subject Id --- .../facilitator/DigitalTwinsUtility.java | 51 ++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java index ccbb9e4b7..8bb5e9a03 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java @@ -19,6 +19,9 @@ ********************************************************************************/ package org.eclipse.tractusx.sde.digitaltwins.facilitator; +import static org.eclipse.tractusx.sde.common.constants.CommonConstants.ASSET_LIFECYCLE_PHASE; +import static org.eclipse.tractusx.sde.common.constants.CommonConstants.MANUFACTURER_PART_ID; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -49,6 +52,8 @@ @Getter public class DigitalTwinsUtility { + private static final String PUBLIC_READABLE = "PUBLIC_READABLE"; + @Value(value = "${manufacturerId}") public String manufacturerId; @@ -57,6 +62,9 @@ public class DigitalTwinsUtility { ObjectMapper mapper = new ObjectMapper(); + private static final Map> publicReadableSpecificAssetIDs = Map.of(MANUFACTURER_PART_ID, + List.of("*"), ASSET_LIFECYCLE_PHASE, List.of("AsBuilt", "AsPlanned")); + @SneakyThrows public ShellDescriptorRequest getShellDescriptorRequest(Map specificIdentifiers, Object object) { @@ -106,10 +114,10 @@ public List prepareDtEndpoint(String shellId, String submodelIdentific .endpointProtocol(CommonConstants.HTTP) .endpointProtocolVersion(List.of(CommonConstants.ENDPOINT_PROTOCOL_VERSION)) .subProtocol(CommonConstants.SUB_PROTOCOL) - .subprotocolBody(encodedUrl("id="+shellId+"-"+submodelIdentification)+";dspEndpoint="+edcEndpoint) + .subprotocolBody(encodedUrl("id=" + shellId + "-" + submodelIdentification) + ";dspEndpoint=" + + edcEndpoint) .subprotocolBodyEncoding(CommonConstants.BODY_ENCODING) - .securityAttributes(List.of(new SecurityAttributes("NONE","NONE","NONE"))) - .build()) + .securityAttributes(List.of(new SecurityAttributes("NONE", "NONE", "NONE"))).build()) .build()); return endpoints; } @@ -118,23 +126,32 @@ private ArrayList getSpecificAssetIds(Map specific ArrayList specificIdentifiers = new ArrayList<>(); - if (!bpns.isEmpty()) { - for (String bpn : bpns) { - ExternalSubjectId externalSubjectId = ExternalSubjectId.builder() + specificAssetIds.entrySet().stream().forEach(entry -> { + + List list = publicReadableSpecificAssetIDs.get(entry.getKey()); + ExternalSubjectId externalSubjectId = null; + + if (list != null && (list.contains("*") || list.contains(entry.getValue()))) { + + externalSubjectId = ExternalSubjectId.builder() .type("ExternalReference") - .keys(List.of(Keys.builder() - .type("Property") - .value(bpn) - .build())) + .keys(List.of(Keys.builder().type("GlobalReference").value(PUBLIC_READABLE).build())) .build(); - - specificAssetIds.entrySet().stream().forEach(entry -> specificIdentifiers - .add(new KeyValuePair(entry.getKey(), entry.getValue(), externalSubjectId))); + + specificIdentifiers.add(new KeyValuePair(entry.getKey(), entry.getValue(), externalSubjectId)); } - } else { - specificAssetIds.entrySet().stream().forEach( - entry -> specificIdentifiers.add(new KeyValuePair(entry.getKey(), entry.getValue(), null))); - } + else { + for (String bpn : bpns) { + externalSubjectId = ExternalSubjectId.builder() + .type("ExternalReference") + .keys(List.of(Keys.builder().type("GlobalReference").value(bpn).build())) + .build(); + specificIdentifiers.add(new KeyValuePair(entry.getKey(), entry.getValue(), externalSubjectId)); + } + + } + }); + return specificIdentifiers; } From 3cba15815dd4239e40d48689a6842b844e444ddf Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Mon, 28 Aug 2023 10:58:14 +0530 Subject: [PATCH 10/11] DDTR update with latest version --- .../entities/common/KeyValuePair.java | 11 ++++- .../request/ShellDescriptorRequest.java | 8 +++- .../facilitator/DigitalTwinsFacilitator.java | 9 ++-- .../facilitator/DigitalTwinsUtility.java | 28 ++++++++----- .../external/DigitalTwinsFeignClient.java | 4 +- .../asset/AssetEntryRequestFactory.java | 6 +-- .../request/asset/DataAddressRequest.java | 2 +- .../PolicyConstraintBuilderService.java | 42 ++++++++++--------- .../ContractNegotiateManagementHelper.java | 41 +++++++++++++----- .../facilitator/CreateEDCAssetFacilator.java | 16 ++++--- .../edc/model/policies/PolicyDefinition.java | 4 +- .../sde/edc/util/UtilityFunctions.java | 4 +- ...nsAspectRelationShipCsvHandlerUseCase.java | 2 +- 13 files changed, 108 insertions(+), 69 deletions(-) diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java index e571af353..ed98000a3 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/common/KeyValuePair.java @@ -23,22 +23,29 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.SneakyThrows; @Data @Builder @AllArgsConstructor @NoArgsConstructor @JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(Include. NON_NULL) +@JsonInclude(JsonInclude.Include.NON_NULL) public class KeyValuePair { private String name; private String value; private ExternalSubjectId externalSubjectId; + + @SneakyThrows + public String toJsonString() { + final ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(this); + } } diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/request/ShellDescriptorRequest.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/request/ShellDescriptorRequest.java index 9d2d3c0ee..07da2f45d 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/request/ShellDescriptorRequest.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/entities/request/ShellDescriptorRequest.java @@ -23,9 +23,11 @@ import java.util.List; -import org.eclipse.tractusx.sde.digitaltwins.entities.common.KeyValuePair; import org.eclipse.tractusx.sde.digitaltwins.entities.common.MultiLanguage; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.AllArgsConstructor; @@ -38,13 +40,15 @@ @NoArgsConstructor @AllArgsConstructor @Getter +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(Include.NON_NULL) public class ShellDescriptorRequest { private String idShort; private String id; private List description; private String globalAssetId; - private List specificAssetIds; + private List specificAssetIds; @SneakyThrows public String toJsonString() { diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsFacilitator.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsFacilitator.java index b1f70bd83..09fbe627c 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsFacilitator.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsFacilitator.java @@ -54,13 +54,16 @@ public class DigitalTwinsFacilitator { @Value(value = "${digital-twins.api:/api/v3.0}") private String dtApiUri; + + @Value(value = "${manufacturerId}") + public String manufacturerId; public List shellLookup(ShellLookupRequest request) throws ServiceException { - return shellLookupFromDDTR(request, null); + return shellLookupFromDDTR(request, null, manufacturerId); } @SneakyThrows - public List shellLookupFromDDTR(ShellLookupRequest request, String ddtrUrl) throws ServiceException { + public List shellLookupFromDDTR(ShellLookupRequest request, String ddtrUrl, String edcBPN) throws ServiceException { URI dtURL = (ddtrUrl == null || ddtrUrl.length() <= 0) ? getDtURL(digitalTwinsHost) : getDtURL(ddtrUrl); @@ -68,7 +71,7 @@ public List shellLookupFromDDTR(ShellLookupRequest request, String ddtrU try { ResponseEntity response = digitalTwinsFeignClient.shellLookup(dtURL, - request.toJsonString()); + request.toJsonString(), edcBPN); ShellLookupResponse body = response.getBody(); if (response.getStatusCode() == HttpStatus.OK && body != null) { diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java index 8bb5e9a03..1b14d8459 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java @@ -23,6 +23,7 @@ import static org.eclipse.tractusx.sde.common.constants.CommonConstants.MANUFACTURER_PART_ID; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -122,10 +123,10 @@ public List prepareDtEndpoint(String shellId, String submodelIdentific return endpoints; } - private ArrayList getSpecificAssetIds(Map specificAssetIds, List bpns) { - - ArrayList specificIdentifiers = new ArrayList<>(); + @SneakyThrows + private ArrayList getSpecificAssetIds(Map specificAssetIds, List bpns) { + ArrayList specificIdentifiers = new ArrayList<>(); specificAssetIds.entrySet().stream().forEach(entry -> { List list = publicReadableSpecificAssetIDs.get(entry.getKey()); @@ -137,18 +138,23 @@ private ArrayList getSpecificAssetIds(Map specific .type("ExternalReference") .keys(List.of(Keys.builder().type("GlobalReference").value(PUBLIC_READABLE).build())) .build(); - specificIdentifiers.add(new KeyValuePair(entry.getKey(), entry.getValue(), externalSubjectId)); } else { - for (String bpn : bpns) { - externalSubjectId = ExternalSubjectId.builder() - .type("ExternalReference") - .keys(List.of(Keys.builder().type("GlobalReference").value(bpn).build())) - .build(); - specificIdentifiers.add(new KeyValuePair(entry.getKey(), entry.getValue(), externalSubjectId)); + if (bpns!=null && !bpns.isEmpty()) { + for (String bpn : bpns) { + externalSubjectId = ExternalSubjectId.builder() + .type("ExternalReference") + .keys(List.of(Keys.builder().type("GlobalReference").value(bpn).build())) + .build(); + specificIdentifiers.add(new KeyValuePair(entry.getKey(), entry.getValue(), externalSubjectId)); + } + } else { + Map map = new HashMap<>(); + map.put("name", entry.getKey()); + map.put("value", entry.getValue()); + specificIdentifiers.add(map); } - } }); diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java index 283bc5d10..a2c5c9050 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java @@ -37,6 +37,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; @FeignClient(value = "DigitalTwinsFeignClient", url = "placeholder", configuration = DigitalTwinsFeignClientConfiguration.class) @@ -65,7 +66,8 @@ ResponseEntity getSubModels(URI digitalTwinsHost, @PathVariable("aasIdentifier") String shellId); @GetMapping(path = "/lookup/shells") - ResponseEntity shellLookup(URI url, @RequestParam String assetIds); + ResponseEntity shellLookup(URI url, @RequestParam String assetIds, + @RequestHeader("Edc-Bpn") String edcBpn); @DeleteMapping(path = "/lookup/shells/{assetIds}") ResponseEntity deleteShell(URI url, @PathVariable("assetIds") String shellId); diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java index 43ede726d..de7196a2b 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java @@ -102,10 +102,10 @@ private HashMap getAssetProperties(String assetId, String assetN private HashMap getDataAddressProperties(String shellId, String subModelId, String endpoint) { HashMap dataAddressProperties = new HashMap<>(); dataAddressProperties.put("type", TYPE); - dataAddressProperties.put("baseUrl", String.format(endpoint, shellId, subModelId)); + dataAddressProperties.put("baseUrl", "https://jsonplaceholder.typicode.com/todos");//String.format(endpoint, shellId, subModelId)); dataAddressProperties.put("name", NAME); - dataAddressProperties.put("authKey", apiKeyHeader); - dataAddressProperties.put("authCode", apiKey); + // dataAddressProperties.put("authKey", apiKeyHeader); + //dataAddressProperties.put("authCode", apiKey); return dataAddressProperties; } diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/DataAddressRequest.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/DataAddressRequest.java index 8e2d762e2..207f89424 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/DataAddressRequest.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/DataAddressRequest.java @@ -38,7 +38,7 @@ public class DataAddressRequest { @Builder.Default - private String type = "HttpProxy"; + private String type = "HttpData"; private HashMap properties; diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/policies/PolicyConstraintBuilderService.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/policies/PolicyConstraintBuilderService.java index b30e416ea..b33928bc3 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/policies/PolicyConstraintBuilderService.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/policies/PolicyConstraintBuilderService.java @@ -53,41 +53,45 @@ public ActionRequest getUsagePolicyConstraints(List usagePolicies if (usagePolicies != null && !usagePolicies.isEmpty()) { usagePolicies.stream().forEach(policy -> usagePolicy(usageConstraintList, policy)); } - ActionRequest action = ActionRequest.builder().build(); - action.addProperty("@type", "LogicalConstraint"); - action.addProperty("odrl:and", usageConstraintList); - return action; + + if (!usageConstraintList.isEmpty()) { + ActionRequest action = ActionRequest.builder().build(); + action.addProperty("@type", "LogicalConstraint"); + action.addProperty("odrl:and", usageConstraintList); + return action; + } + return null; } private void usagePolicy(List usageConstraintList, UsagePolicies policy) { + ConstraintRequest request = null; + switch (policy.getType()) { case DURATION: - ConstraintRequest request = DurationPolicyDTO.fromUsagePolicy(policy).toConstraint(); - if (request != null) { - usageConstraintList.add(request); - } + request = DurationPolicyDTO.fromUsagePolicy(policy).toConstraint(); break; case PURPOSE: - ConstraintRequest purposeRequest = PurposePolicyDTO.fromUsagePolicy(policy).toConstraint(); - if (purposeRequest != null) { - usageConstraintList.add(purposeRequest); - } + request = PurposePolicyDTO.fromUsagePolicy(policy).toConstraint(); break; case ROLE: - ConstraintRequest roleRequest = RolePolicyDTO.fromUsagePolicy(policy).toConstraint(); - if (roleRequest != null) { - usageConstraintList.add(roleRequest); - } + request = RolePolicyDTO.fromUsagePolicy(policy).toConstraint(); break; default: break; } - } + if (request != null) { + usageConstraintList.add(request); + } + } + public ConstraintRequest toTraceabilityConstraint() { String operator = "odrl:eq"; - return ConstraintRequest.builder().leftOperand("FrameworkAgreement.traceability") - .operator(Operator.builder().id(operator).build()).rightOperand("active").build(); + return ConstraintRequest.builder() + .leftOperand("FrameworkAgreement.traceability") + .operator(Operator.builder().id(operator).build()) + .rightOperand("active") + .build(); } } diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/ContractNegotiateManagementHelper.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/ContractNegotiateManagementHelper.java index ea3a94839..f5a4cd80e 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/ContractNegotiateManagementHelper.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/ContractNegotiateManagementHelper.java @@ -31,6 +31,7 @@ import org.eclipse.tractusx.sde.edc.api.ContractApi; import org.eclipse.tractusx.sde.edc.entities.request.policies.ActionRequest; import org.eclipse.tractusx.sde.edc.entities.request.policies.ConstraintRequest; +import org.eclipse.tractusx.sde.edc.entities.request.policies.PermissionRequest; import org.eclipse.tractusx.sde.edc.enums.NegotiationState; import org.eclipse.tractusx.sde.edc.mapper.ContractMapper; import org.eclipse.tractusx.sde.edc.model.contractnegotiation.AcknowledgementId; @@ -84,6 +85,7 @@ public List getAllContractNegotiations(String type, Inte } + @SuppressWarnings("unchecked") @SneakyThrows public ContractAgreementResponse getAgreementBasedOnNegotiationId(String type, String negotiationId) { ContractAgreementResponse agreementResponse = null; @@ -99,18 +101,20 @@ public ContractAgreementResponse getAgreementBasedOnNegotiationId(String type, S } if (agreement != null) { List policies = new ArrayList<>(); - - Object object = agreement.getPolicy().getPermissions().getConstraint().get("odrl:and"); - if (object != null) - setContraint(objeMapper, policies, object); - else { - object = agreement.getPolicy().getPermissions().getConstraint().get("odrl:or"); - if (object != null) - setContraint(objeMapper, policies, object); + Object permissionObj = agreement.getPolicy().getPermissions(); + + if (permissionObj instanceof ArrayList) { + for (Object obj : (ArrayList) permissionObj) + formatPermissionConstraint(objeMapper, policies, obj); + } else if (permissionObj != null) { + formatPermissionConstraint(objeMapper, policies, permissionObj); } + if (policies.isEmpty()) + UtilityFunctions.getUsagePolicies(policies, List.of()); + UtilityFunctions.addCustomUsagePolicy(agreement.getPolicy().getExtensibleProperties(), policies); - + ContractAgreementInfo agreementInfo = ContractAgreementInfo.builder() .contractEndDate(agreement.getContractEndDate()) .contractSigningDate(agreement.getContractSigningDate()) @@ -126,16 +130,31 @@ public ContractAgreementResponse getAgreementBasedOnNegotiationId(String type, S return agreementResponse; } + private void formatPermissionConstraint(ObjectMapper objeMapper, List policies, + Object permissionObj) { + ObjectMapper objMapper = new ObjectMapper(); + PermissionRequest permissionRequest = objMapper.convertValue(permissionObj, PermissionRequest.class); + + Object object = permissionRequest.getConstraint().get("odrl:and"); + if (object != null) + setContraint(objeMapper, policies, object); + else { + object = permissionRequest.getConstraint().get("odrl:or"); + if (object != null) + setContraint(objeMapper, policies, object); + } + } + private void setContraint(ObjectMapper objeMapper, List policies, Object object) { if (object instanceof ArrayList) { List convertValue = objeMapper.convertValue(object, new TypeReference>() { }); - policies.addAll(UtilityFunctions.getUsagePolicies(convertValue)); + UtilityFunctions.getUsagePolicies(policies, convertValue); } else if (object !=null ){ ConstraintRequest convertValue = objeMapper.convertValue(object, ConstraintRequest.class); - policies.addAll(UtilityFunctions.getUsagePolicies(List.of(convertValue))); + UtilityFunctions.getUsagePolicies(policies, List.of(convertValue)); } } diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/CreateEDCAssetFacilator.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/CreateEDCAssetFacilator.java index de1a8d18c..7ec4f9965 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/CreateEDCAssetFacilator.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/CreateEDCAssetFacilator.java @@ -59,26 +59,24 @@ public Map createEDCAsset(AssetEntryRequest assetEntryRequest, L String assetId = assetEntryRequest.getAsset().getId(); - ActionRequest usageAction = policyConstraintBuilderService.getUsagePolicyConstraints(usagePolicies); + ActionRequest accessAction = policyConstraintBuilderService.getAccessConstraints(bpns); String customValue = getCustomValue(usagePolicies); if (StringUtils.isNotBlank(getCustomValue(usagePolicies))) { extensibleProperties.put(UsagePolicyEnum.CUSTOM.name(), customValue); } - + PolicyDefinitionRequest accessPolicyDefinitionRequest = policyFactory.getPolicy(assetId, accessAction, new HashMap<>()); edcGateway.createPolicyDefinition(accessPolicyDefinitionRequest); String accessPolicyId = accessPolicyDefinitionRequest.getId(); - String usagePolicyId = accessPolicyDefinitionRequest.getId(); - if (usageAction != null) { - PolicyDefinitionRequest usagePolicyDefinitionRequest = policyFactory.getPolicy(assetId, usageAction, - extensibleProperties); - edcGateway.createPolicyDefinition(usagePolicyDefinitionRequest); - usagePolicyId = usagePolicyDefinitionRequest.getId(); - } + ActionRequest usageAction = policyConstraintBuilderService.getUsagePolicyConstraints(usagePolicies); + PolicyDefinitionRequest usagePolicyDefinitionRequest = policyFactory.getPolicy(assetId, usageAction, + extensibleProperties); + edcGateway.createPolicyDefinition(usagePolicyDefinitionRequest); + String usagePolicyId = usagePolicyDefinitionRequest.getId(); ContractDefinitionRequest contractDefinitionRequest = contractFactory.getContractDefinitionRequest(assetId, accessPolicyId, usagePolicyId); diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/model/policies/PolicyDefinition.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/model/policies/PolicyDefinition.java index 30d53de95..bb76d6830 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/model/policies/PolicyDefinition.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/model/policies/PolicyDefinition.java @@ -23,8 +23,6 @@ import java.util.List; import java.util.Map; -import org.eclipse.tractusx.sde.edc.entities.request.policies.PermissionRequest; - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -49,7 +47,7 @@ public class PolicyDefinition { private String id; @JsonProperty("odrl:permission") - private PermissionRequest permissions; + private Object permissions; @JsonProperty("odrl:prohibition") private List prohibitions; diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/util/UtilityFunctions.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/util/UtilityFunctions.java index 1b4132b20..ca8ae15c8 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/util/UtilityFunctions.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/util/UtilityFunctions.java @@ -20,7 +20,6 @@ package org.eclipse.tractusx.sde.edc.util; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -97,8 +96,7 @@ private static UsagePolicies getResponse(String value, DurationEnum durationUnit return policyResponse; } - public static List getUsagePolicies(List constraints) { - List usagePolicies = new ArrayList<>(); + public static List getUsagePolicies(List usagePolicies, List constraints) { constraints.forEach(constraint -> { String leftExpVal = constraint.getLeftOperand(); String rightExpVal = constraint.getRightOperand().toString(); diff --git a/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DigitalTwinsAspectRelationShipCsvHandlerUseCase.java b/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DigitalTwinsAspectRelationShipCsvHandlerUseCase.java index d86357e69..fefd63157 100644 --- a/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DigitalTwinsAspectRelationShipCsvHandlerUseCase.java +++ b/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DigitalTwinsAspectRelationShipCsvHandlerUseCase.java @@ -195,7 +195,7 @@ private CreateSubModelRequest getCreateSubModelRequest(AspectRelationship aspect for (String ddtUrl : dtURls) { - List childshellIds = digitalTwinfacilitaor.shellLookupFromDDTR(shellLookupRequest, ddtUrl); + List childshellIds = digitalTwinfacilitaor.shellLookupFromDDTR(shellLookupRequest, ddtUrl, aspectRelationShip.getChildManufacturerId()); if (childshellIds.isEmpty()) { log.warn(aspectRelationShip.getRowNumber() + ", " + ddtUrl + ", No child aspect found for " From 47ca3c5112a940df82aadb81df06dde084db192f Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Mon, 28 Aug 2023 12:24:52 +0530 Subject: [PATCH 11/11] revert test commented line --- .../entities/request/asset/AssetEntryRequestFactory.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java index de7196a2b..43ede726d 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java @@ -102,10 +102,10 @@ private HashMap getAssetProperties(String assetId, String assetN private HashMap getDataAddressProperties(String shellId, String subModelId, String endpoint) { HashMap dataAddressProperties = new HashMap<>(); dataAddressProperties.put("type", TYPE); - dataAddressProperties.put("baseUrl", "https://jsonplaceholder.typicode.com/todos");//String.format(endpoint, shellId, subModelId)); + dataAddressProperties.put("baseUrl", String.format(endpoint, shellId, subModelId)); dataAddressProperties.put("name", NAME); - // dataAddressProperties.put("authKey", apiKeyHeader); - //dataAddressProperties.put("authCode", apiKey); + dataAddressProperties.put("authKey", apiKeyHeader); + dataAddressProperties.put("authCode", apiKey); return dataAddressProperties; }