From 315bce98c3d22815eb67200f35c836a1947c7888 Mon Sep 17 00:00:00 2001 From: Parracho Date: Fri, 13 Oct 2023 15:03:49 +0100 Subject: [PATCH 1/3] feat: deleted central dtr search and outdated models and methods related --- .../productpass/config/DtrConfig.java | 18 - .../http/controllers/AppController.java | 17 +- .../controllers/api/ContractController.java | 63 +- .../productpass/listeners/AppListener.java | 30 +- .../productpass/managers/ProcessManager.java | 31 - .../models/dtregistry/DigitalTwin.java | 89 ++- .../models/dtregistry/DigitalTwin3.java | 171 ----- .../models/dtregistry/EndPoint.java | 110 ++- .../models/dtregistry/EndPoint3.java | 188 ----- .../models/dtregistry/SubModel.java | 115 +++- .../models/dtregistry/SubModel3.java | 198 ------ .../models/http/requests/Search.java | 11 +- .../productpass/services/AasService.java | 643 ++---------------- .../src/main/resources/application.yml | 2 - 14 files changed, 385 insertions(+), 1301 deletions(-) delete mode 100644 consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/DigitalTwin3.java delete mode 100644 consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/EndPoint3.java delete mode 100644 consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/SubModel3.java diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/DtrConfig.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/DtrConfig.java index 28eaea104..9b55a589e 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/DtrConfig.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/DtrConfig.java @@ -39,8 +39,6 @@ public class DtrConfig { /** ATTRIBUTES **/ - Boolean central; - String centralUrl; String internalDtr; Timeouts timeouts; Boolean temporaryStorage; @@ -60,9 +58,6 @@ public DecentralApis getDecentralApis() { public void setDecentralApis(DecentralApis decentralApis) { this.decentralApis = decentralApis; } - public DtrConfig(Boolean central) { - this.central = central; - } public String getInternalDtr() { return internalDtr; } @@ -93,19 +88,6 @@ public String getDspEndpointKey() { public void setDspEndpointKey(String dspEndpointKey) { this.dspEndpointKey = dspEndpointKey; } - public Boolean getCentral() { - return central; - } - public void setCentral(Boolean central) { - this.central = central; - } - public String getCentralUrl() { - return centralUrl; - } - @SuppressWarnings("Unused") - public void setCentralUrl(String centralUrl) { - this.centralUrl = centralUrl; - } public String getAssetId() { return assetId; } diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/AppController.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/AppController.java index 1a1cda7ce..5ef596357 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/AppController.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/AppController.java @@ -22,7 +22,6 @@ ********************************************************************************/ package org.eclipse.tractusx.productpass.http.controllers; -import com.fasterxml.jackson.databind.JsonNode; import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Operation; @@ -35,13 +34,11 @@ import org.eclipse.tractusx.productpass.config.DtrConfig; import org.eclipse.tractusx.productpass.config.ProcessConfig; import org.eclipse.tractusx.productpass.exceptions.ControllerException; -import org.eclipse.tractusx.productpass.exceptions.DataModelException; -import org.eclipse.tractusx.productpass.exceptions.ServiceException; import org.eclipse.tractusx.productpass.managers.ProcessManager; import org.eclipse.tractusx.productpass.models.catenax.Dtr; -import org.eclipse.tractusx.productpass.models.dtregistry.DigitalTwin3; -import org.eclipse.tractusx.productpass.models.dtregistry.EndPoint3; -import org.eclipse.tractusx.productpass.models.dtregistry.SubModel3; +import org.eclipse.tractusx.productpass.models.dtregistry.DigitalTwin; +import org.eclipse.tractusx.productpass.models.dtregistry.EndPoint; +import org.eclipse.tractusx.productpass.models.dtregistry.SubModel; import org.eclipse.tractusx.productpass.models.edc.DataPlaneEndpoint; import org.eclipse.tractusx.productpass.models.edc.Jwt; import org.eclipse.tractusx.productpass.models.http.Response; @@ -176,8 +173,8 @@ public Response getDigitalTwin(@RequestBody Object body, @PathVariable String pr Thread digitalTwinRegistryThread = ThreadUtil.runThread(digitalTwinRegistry); // Wait for digital twin query digitalTwinRegistryThread.join(); - DigitalTwin3 digitalTwin = null; - SubModel3 subModel = null; + DigitalTwin digitalTwin = null; + SubModel subModel = null; String connectorId = null; String assetId = null; String connectorAddress = null; @@ -189,7 +186,7 @@ public Response getDigitalTwin(@RequestBody Object body, @PathVariable String pr semanticId = Objects.requireNonNull(subModel.getSemanticId().getKeys().stream().filter(k -> k.getType().equalsIgnoreCase("Submodel") || k.getType().equalsIgnoreCase("GlobalReference")).findFirst().orElse(null)).getValue(); LogUtil.printMessage("SemanticId "+ semanticId); connectorId = subModel.getIdShort(); - EndPoint3 endpoint = subModel.getEndpoints().stream().filter(obj -> obj.getInterfaceName().equals(dtrConfig.getEndpointInterface())).findFirst().orElse(null); + EndPoint endpoint = subModel.getEndpoints().stream().filter(obj -> obj.getInterfaceName().equals(dtrConfig.getEndpointInterface())).findFirst().orElse(null); if (endpoint == null) { throw new ControllerException(this.getClass().getName(), "No EDC endpoint found in DTR SubModel!"); } @@ -214,7 +211,7 @@ public Response getDigitalTwin(@RequestBody Object body, @PathVariable String pr processManager.setEndpoint(processId, connectorAddress); processManager.setBpn(processId, dtr.getBpn()); processManager.setSemanticId(processId, semanticId); - processManager.saveDigitalTwin3(processId, digitalTwin, dtRequestTime); + processManager.saveDigitalTwin(processId, digitalTwin, dtRequestTime); LogUtil.printDebug("[PROCESS " + processId + "] Digital Twin [" + digitalTwin.getIdentification() + "] and Submodel [" + subModel.getIdentification() + "] with EDC endpoint [" + connectorAddress + "] retrieved from DTR"); processManager.setStatus(processId, "digital-twin-found", new History( assetId, diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ContractController.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ContractController.java index 60885df06..286fbceb9 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ContractController.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ContractController.java @@ -114,13 +114,6 @@ public class ContractController { public Response create(@Valid @RequestBody DiscoverySearch searchBody) { Response response = httpUtil.getInternalError(); try { - // In case the configuration is setting the search as central - if(dtrConfig.getCentral()){ - response.message = "The decentral Digital Twin Registry is not enabled!"; - response.status = 403; - response.statusText = "Bad Request"; - return httpUtil.buildResponse(response, httpResponse); - } if (!authService.isAuthenticated(httpRequest)) { response = httpUtil.getNotAuthorizedResponse(); return httpUtil.buildResponse(response, httpResponse); @@ -249,8 +242,8 @@ public Response search(@Valid @RequestBody Search searchBody) { return httpUtil.buildResponse(response, httpResponse); } - List versions; - /*if (searchBody.getIdShort().equalsIgnoreCase("digitalProductPass")) { + /*List versions; + if (searchBody.getIdShort().equalsIgnoreCase("digitalProductPass")) { versions = passportConfig.getDigitalProductPass().getVersions(); searchBody.setSemanticId(passportConfig.getDigitalProductPass().getFullSemanticId(versions.get(0))); LogUtil.printWarning("SEMANTID ID: " + passportConfig.getDigitalProductPass().getFullSemanticId(versions.get(0))); @@ -261,34 +254,34 @@ public Response search(@Valid @RequestBody Search searchBody) { Process process = null; AssetSearch assetSearch = null; - if(!dtrConfig.getCentral() && searchBody.getProcessId() != null) { - // Check for processId - String processId = searchBody.getProcessId(); - if(processId.isEmpty()){ - response = httpUtil.getBadRequest("Process id is required for decentral digital twin registry searches!"); - return httpUtil.buildResponse(response, httpResponse); - } - SearchStatus searchStatus = processManager.getSearchStatus(processId); - if (searchStatus == null) { - response = httpUtil.getBadRequest("The searchStatus id does not exists!"); - return httpUtil.buildResponse(response, httpResponse); - } - if(searchStatus.getDtrs().keySet().size() == 0){ - response = httpUtil.getBadRequest("No digital twins are available for this process!"); - return httpUtil.buildResponse(response, httpResponse); - } - process = processManager.createProcess(processId, httpRequest); - Status status = processManager.getStatus(processId); - if (status == null) { - response = httpUtil.getBadRequest("The status is not available!"); - return httpUtil.buildResponse(response, httpResponse); - } - assetSearch = aasService.decentralDtrSearch(process.id, searchBody); - }else { - process = processManager.createProcess(httpRequest); - assetSearch = aasService.centralDtrSearch(process.id, searchBody); + + // Check for processId + if(searchBody.getProcessId() == null){ + response = httpUtil.getBadRequest("No processId was found on the request body!"); + return httpUtil.buildResponse(response, httpResponse); } + String processId = searchBody.getProcessId(); + if(processId.isEmpty()){ + response = httpUtil.getBadRequest("Process id is required for decentral digital twin registry searches!"); + return httpUtil.buildResponse(response, httpResponse); + } + SearchStatus searchStatus = processManager.getSearchStatus(processId); + if (searchStatus == null) { + response = httpUtil.getBadRequest("The searchStatus id does not exists!"); + return httpUtil.buildResponse(response, httpResponse); + } + if(searchStatus.getDtrs().keySet().size() == 0){ + response = httpUtil.getBadRequest("No digital twins are available for this process!"); + return httpUtil.buildResponse(response, httpResponse); + } + process = processManager.createProcess(processId, httpRequest); + Status status = processManager.getStatus(processId); + if (status == null) { + response = httpUtil.getBadRequest("The status is not available!"); + return httpUtil.buildResponse(response, httpResponse); + } + assetSearch = aasService.decentralDtrSearch(process.id, searchBody); if(assetSearch == null){ response = httpUtil.getBadRequest("No digital twin was found!"); diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/listeners/AppListener.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/listeners/AppListener.java index 8d9fabe5d..27c465584 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/listeners/AppListener.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/listeners/AppListener.java @@ -152,23 +152,21 @@ public void onStartUp() { LogUtil.printMessage(serverStartUpMessage); LogUtil.printMessage("========= [ LOGGING STARTED ] ================================"); LogUtil.printMessage("Creating log file..."); - if(!dtrConfig.getCentral()) { - Discovery discovery = catenaXService.start(); // Start the CatenaX service if the central attribute is set to false (we need the bpnDiscovery and edcDiscovery addresses) - if (discovery == null) { - LogUtil.printError("\n*************************************[CRITICAL ERROR]*************************************" + - "\nIt was not possible to start the application correctly..." + - "\nPlease configure the Discovery Service Endpoint property:" + - "\n\t- [application.configuration.discovery.endpoint]" + - "\nMake sure that the Technical User Credentials are correctly configured:" + - "\n\t- [avp.helm.clientId]" + - "\n\t- [avp.helm.clientSecret]" + - "\nThis user should be able to retrieve the token from the following Keycloak Endpoint:" + - "\n\t- [application.configuration.keycloak.tokenUri]" + - "\n*****************************************************************************************\n" - ); - } + Discovery discovery = catenaXService.start(); // Start the CatenaX service (we need the bpnDiscovery and edcDiscovery addresses) + if (discovery == null) { + LogUtil.printError("\n*************************************[CRITICAL ERROR]*************************************" + + "\nIt was not possible to start the application correctly..." + + "\nPlease configure the Discovery Service Endpoint property:" + + "\n\t- [application.configuration.discovery.endpoint]" + + "\nMake sure that the Technical User Credentials are correctly configured:" + + "\n\t- [avp.helm.clientId]" + + "\n\t- [avp.helm.clientSecret]" + + "\nThis user should be able to retrieve the token from the following Keycloak Endpoint:" + + "\n\t- [application.configuration.keycloak.tokenUri]" + + "\n*****************************************************************************************\n" + ); } - } + } // Store the process manager in memory } diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/managers/ProcessManager.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/managers/ProcessManager.java index 4b6ee3947..8b576555e 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/managers/ProcessManager.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/managers/ProcessManager.java @@ -30,7 +30,6 @@ import org.eclipse.tractusx.productpass.exceptions.ManagerException; import org.eclipse.tractusx.productpass.models.catenax.Dtr; import org.eclipse.tractusx.productpass.models.dtregistry.DigitalTwin; -import org.eclipse.tractusx.productpass.models.dtregistry.DigitalTwin3; import org.eclipse.tractusx.productpass.models.edc.DataPlaneEndpoint; import org.eclipse.tractusx.productpass.models.edc.Jwt; import org.eclipse.tractusx.productpass.models.http.requests.Search; @@ -1321,36 +1320,6 @@ public String saveDigitalTwin(String processId, DigitalTwin digitalTwin, Long st } } - /** - * Saves the given {@code DigitalTwin3} object in the Process with the given processId with the given timestamp. - *

- * @param processId - * the {@code String} id of the application's process. - * @param digitalTwin - * the {@code DigitalTwin3} object to save. - * @param startedTime - * the {@code Long} timestamp when the process's event started. - * - * @return a {@code String} file path of the file where data was stored. - * - * @throws ManagerException - * if unable to save the {@code DigitalTwin3}. - */ - public String saveDigitalTwin3(String processId, DigitalTwin3 digitalTwin, Long startedTime) { - try { - return this.saveProcessPayload( - processId, - digitalTwin, - this.digitalTwinFileName, - startedTime, - digitalTwin.getIdentification(), - "READY", - "digital-twin-request"); - } catch (Exception e) { - throw new ManagerException(this.getClass().getName(), e, "It was not possible to save the digitalTwin!"); - } - } - /** * Saves the given {@code Dataset} object in the Process with the given processId with the given timestamp. *

diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/DigitalTwin.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/DigitalTwin.java index 2752193c7..6462e2313 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/DigitalTwin.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/DigitalTwin.java @@ -23,6 +23,7 @@ package org.eclipse.tractusx.productpass.models.dtregistry; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.JsonNode; @@ -30,19 +31,26 @@ import java.util.ArrayList; /** - * This class consists exclusively to define attributes related to the designed model of the Digital Twin's first version. + * This class consists exclusively to define attributes related to the designed model of the Digital Twin's improved version. **/ +@JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_NULL) public class DigitalTwin { /** ATTRIBUTES **/ @JsonProperty("description") ArrayList description; - @JsonProperty("globalAssetId") - JsonNode globalAssetId; @JsonProperty("idShort") String idShort; - @JsonProperty("identification") + @JsonProperty("assetKind") + String assetKind; + @JsonProperty("assetType") + String assetType; + @JsonProperty("globalAssetId") + String globalAssetId; + @JsonProperty("displayName") + Object displayName; + @JsonProperty("id") String identification; @JsonProperty("specificAssetIds") ArrayList specificAssetIds; @@ -54,10 +62,40 @@ public class DigitalTwin { public DigitalTwin() { } @SuppressWarnings("Unused") - public DigitalTwin(ArrayList description, JsonNode globalAssetId, String idShort, String identification, ArrayList specificAssetIds, ArrayList submodelDescriptors) { + public DigitalTwin(ArrayList description, String idShort, String identification, ArrayList specificAssetIds, ArrayList submodelDescriptors) { this.description = description; + this.idShort = idShort; + this.identification = identification; + this.specificAssetIds = specificAssetIds; + this.submodelDescriptors = submodelDescriptors; + } + @SuppressWarnings("Unused") + public DigitalTwin(ArrayList description, String idShort, Object displayName, String identification, ArrayList specificAssetIds, ArrayList submodelDescriptors) { + this.description = description; + this.idShort = idShort; + this.displayName = displayName; + this.identification = identification; + this.specificAssetIds = specificAssetIds; + this.submodelDescriptors = submodelDescriptors; + } + @SuppressWarnings("Unused") + public DigitalTwin(ArrayList description, String idShort, String globalAssetId, Object displayName, String identification, ArrayList specificAssetIds, ArrayList submodelDescriptors) { + this.description = description; + this.idShort = idShort; this.globalAssetId = globalAssetId; + this.displayName = displayName; + this.identification = identification; + this.specificAssetIds = specificAssetIds; + this.submodelDescriptors = submodelDescriptors; + } + @SuppressWarnings("Unused") + public DigitalTwin(ArrayList description, String idShort, String assetKind, String assetType, String globalAssetId, Object displayName, String identification, ArrayList specificAssetIds, ArrayList submodelDescriptors) { + this.description = description; this.idShort = idShort; + this.assetKind = assetKind; + this.assetType = assetType; + this.globalAssetId = globalAssetId; + this.displayName = displayName; this.identification = identification; this.specificAssetIds = specificAssetIds; this.submodelDescriptors = submodelDescriptors; @@ -70,14 +108,6 @@ public ArrayList getDescription() { public void setDescription(ArrayList description) { this.description = description; } - @SuppressWarnings("Unused") - public JsonNode getGlobalAssetId() { - return globalAssetId; - } - @SuppressWarnings("Unused") - public void setGlobalAssetId(JsonNode globalAssetId) { - this.globalAssetId = globalAssetId; - } public String getIdShort() { return idShort; } @@ -106,5 +136,36 @@ public ArrayList getSubmodelDescriptors() { public void setSubmodelDescriptors(ArrayList submodelDescriptors) { this.submodelDescriptors = submodelDescriptors; } + @SuppressWarnings("Unused") + public Object getDisplayName() { + return displayName; + } + @SuppressWarnings("Unused") + public void setDisplayName(Object displayName) { + this.displayName = displayName; + } + @SuppressWarnings("Unused") + public String getGlobalAssetId() { + return globalAssetId; + } + @SuppressWarnings("Unused") + public void setGlobalAssetId(String globalAssetId) { + this.globalAssetId = globalAssetId; + } + @SuppressWarnings("Unused") + public String getAssetKind() { + return assetKind; + } + @SuppressWarnings("Unused") + public void setAssetKind(String assetKind) { + this.assetKind = assetKind; + } + @SuppressWarnings("Unused") + public String getAssetType() { + return assetType; + } + @SuppressWarnings("Unused") + public void setAssetType(String assetType) { + this.assetType = assetType; + } } - diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/DigitalTwin3.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/DigitalTwin3.java deleted file mode 100644 index 576ca2b79..000000000 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/DigitalTwin3.java +++ /dev/null @@ -1,171 +0,0 @@ -/********************************************************************************* - * - * Catena-X - Product Passport Consumer Backend - * - * Copyright (c) 2022, 2023 BASF SE, BMW AG, Henkel AG & Co. KGaA - * - * 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 govern in permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.productpass.models.dtregistry; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.JsonNode; - -import java.util.ArrayList; - -/** - * This class consists exclusively to define attributes related to the designed model of the Digital Twin's improved version. - **/ -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class DigitalTwin3 { - - /** ATTRIBUTES **/ - @JsonProperty("description") - ArrayList description; - @JsonProperty("idShort") - String idShort; - @JsonProperty("assetKind") - String assetKind; - @JsonProperty("assetType") - String assetType; - @JsonProperty("globalAssetId") - String globalAssetId; - @JsonProperty("displayName") - Object displayName; - @JsonProperty("id") - String identification; - @JsonProperty("specificAssetIds") - ArrayList specificAssetIds; - @JsonProperty("submodelDescriptors") - ArrayList submodelDescriptors; - - /** CONSTRUCTOR(S) **/ - @SuppressWarnings("Unused") - public DigitalTwin3() { - } - @SuppressWarnings("Unused") - public DigitalTwin3(ArrayList description, String idShort, String identification, ArrayList specificAssetIds, ArrayList submodelDescriptors) { - this.description = description; - this.idShort = idShort; - this.identification = identification; - this.specificAssetIds = specificAssetIds; - this.submodelDescriptors = submodelDescriptors; - } - @SuppressWarnings("Unused") - public DigitalTwin3(ArrayList description, String idShort, Object displayName, String identification, ArrayList specificAssetIds, ArrayList submodelDescriptors) { - this.description = description; - this.idShort = idShort; - this.displayName = displayName; - this.identification = identification; - this.specificAssetIds = specificAssetIds; - this.submodelDescriptors = submodelDescriptors; - } - @SuppressWarnings("Unused") - public DigitalTwin3(ArrayList description, String idShort, String globalAssetId, Object displayName, String identification, ArrayList specificAssetIds, ArrayList submodelDescriptors) { - this.description = description; - this.idShort = idShort; - this.globalAssetId = globalAssetId; - this.displayName = displayName; - this.identification = identification; - this.specificAssetIds = specificAssetIds; - this.submodelDescriptors = submodelDescriptors; - } - @SuppressWarnings("Unused") - public DigitalTwin3(ArrayList description, String idShort, String assetKind, String assetType, String globalAssetId, Object displayName, String identification, ArrayList specificAssetIds, ArrayList submodelDescriptors) { - this.description = description; - this.idShort = idShort; - this.assetKind = assetKind; - this.assetType = assetType; - this.globalAssetId = globalAssetId; - this.displayName = displayName; - this.identification = identification; - this.specificAssetIds = specificAssetIds; - this.submodelDescriptors = submodelDescriptors; - } - - /** GETTERS AND SETTERS **/ - public ArrayList getDescription() { - return description; - } - public void setDescription(ArrayList description) { - this.description = description; - } - public String getIdShort() { - return idShort; - } - public void setIdShort(String idShort) { - this.idShort = idShort; - } - public String getIdentification() { - return identification; - } - @SuppressWarnings("Unused") - public void setIdentification(String identification) { - this.identification = identification; - } - @SuppressWarnings("Unused") - public ArrayList getSpecificAssetIds() { - return specificAssetIds; - } - @SuppressWarnings("Unused") - public void setSpecificAssetIds(ArrayList specificAssetIds) { - this.specificAssetIds = specificAssetIds; - } - public ArrayList getSubmodelDescriptors() { - return submodelDescriptors; - } - @SuppressWarnings("Unused") - public void setSubmodelDescriptors(ArrayList submodelDescriptors) { - this.submodelDescriptors = submodelDescriptors; - } - @SuppressWarnings("Unused") - public Object getDisplayName() { - return displayName; - } - @SuppressWarnings("Unused") - public void setDisplayName(Object displayName) { - this.displayName = displayName; - } - @SuppressWarnings("Unused") - public String getGlobalAssetId() { - return globalAssetId; - } - @SuppressWarnings("Unused") - public void setGlobalAssetId(String globalAssetId) { - this.globalAssetId = globalAssetId; - } - @SuppressWarnings("Unused") - public String getAssetKind() { - return assetKind; - } - @SuppressWarnings("Unused") - public void setAssetKind(String assetKind) { - this.assetKind = assetKind; - } - @SuppressWarnings("Unused") - public String getAssetType() { - return assetType; - } - @SuppressWarnings("Unused") - public void setAssetType(String assetType) { - this.assetType = assetType; - } -} diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/EndPoint.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/EndPoint.java index 3391000de..d31749912 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/EndPoint.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/EndPoint.java @@ -23,19 +23,27 @@ package org.eclipse.tractusx.productpass.models.dtregistry; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.Splitter; +import utils.LogUtil; + +import java.util.List; +import java.util.Map; /** - * This class consists exclusively to define attributes related to the designed model of the Endpoint's first version. + * This class consists exclusively to define attributes related to the designed model of the Endpoint's improved version. **/ +@JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_NULL) public class EndPoint { /** ATTRIBUTES **/ @JsonProperty("interface") String interfaceName; - ProtocolInformation protocolInformation = new ProtocolInformation(); + @JsonProperty("protocolInformation") + ProtocolInformation3 protocolInformation = new ProtocolInformation3(); /** GETTERS AND SETTERS **/ public String getInterfaceName() { @@ -45,38 +53,74 @@ public String getInterfaceName() { public void setInterfaceName(String interfaceName) { this.interfaceName = interfaceName; } - public ProtocolInformation getProtocolInformation() { + public ProtocolInformation3 getProtocolInformation() { return protocolInformation; } @SuppressWarnings("Unused") - public void setProtocolInformation(String endpointAddress, String endpointProtocol, String endpointProtocolVersion) { - this.protocolInformation = new ProtocolInformation(endpointAddress, endpointProtocol, endpointProtocolVersion); + public void setProtocolInformation(String endpointAddress, String endpointProtocol, List endpointProtocolVersion) { + this.protocolInformation = new ProtocolInformation3(endpointAddress, endpointProtocol, endpointProtocolVersion); } /** INNER CLASSES **/ /** - * This class consists exclusively to define attributes related to the needed protocol information for the first version. + * This class consists exclusively to define attributes related to the needed protocol information for the improved version. **/ - public static class ProtocolInformation { + public static class ProtocolInformation3 { /** ATTRIBUTES **/ - @JsonProperty("endpointAddress") + @JsonProperty("href") String endpointAddress; @JsonProperty("endpointProtocol") String endpointProtocol; + @JsonProperty("subprotocol") + String subprotocol; + @JsonProperty("subprotocolBody") + String subprotocolBody; + @JsonProperty("subprotocolBodyEncoding") + String subprotocolBodyEncoding; + @JsonProperty("securityAttributes") + Object securityAttributes; @JsonProperty("endpointProtocolVersion") - String endpointProtocolVersion; + List endpointProtocolVersion; /** CONSTRUCTOR(S) **/ - public ProtocolInformation(String endpointAddress, String endpointProtocol, String endpointProtocolVersion) { + public ProtocolInformation3(String endpointAddress, String endpointProtocol, List endpointProtocolVersion) { this.endpointAddress = endpointAddress; this.endpointProtocol = endpointProtocol; this.endpointProtocolVersion = endpointProtocolVersion; } - public ProtocolInformation() { + public ProtocolInformation3() { + } + @SuppressWarnings("Unused") + public ProtocolInformation3(String endpointAddress, String endpointProtocol, String subprotocol, String subprotocolBody, List endpointProtocolVersion) { + this.endpointAddress = endpointAddress; + this.endpointProtocol = endpointProtocol; + this.subprotocol = subprotocol; + this.subprotocolBody = subprotocolBody; + this.endpointProtocolVersion = endpointProtocolVersion; + } + @SuppressWarnings("Unused") + public ProtocolInformation3(String endpointAddress, String endpointProtocol, String subprotocol, String subprotocolBody, String subprotocolBodyEncoding, List endpointProtocolVersion) { + this.endpointAddress = endpointAddress; + this.endpointProtocol = endpointProtocol; + this.subprotocol = subprotocol; + this.subprotocolBody = subprotocolBody; + this.subprotocolBodyEncoding = subprotocolBodyEncoding; + this.endpointProtocolVersion = endpointProtocolVersion; + } + @SuppressWarnings("Unused") + public ProtocolInformation3(String endpointAddress, String endpointProtocol, String subprotocol, String subprotocolBody, String subprotocolBodyEncoding, Object securityAttributes, List endpointProtocolVersion) { + this.endpointAddress = endpointAddress; + this.endpointProtocol = endpointProtocol; + this.subprotocol = subprotocol; + this.subprotocolBody = subprotocolBody; + this.subprotocolBodyEncoding = subprotocolBodyEncoding; + this.securityAttributes = securityAttributes; + this.endpointProtocolVersion = endpointProtocolVersion; } /** GETTERS AND SETTERS **/ + @SuppressWarnings("Unused") public String getEndpointAddress() { return endpointAddress; } @@ -93,12 +137,52 @@ public void setEndpointProtocol(String endpointProtocol) { this.endpointProtocol = endpointProtocol; } @SuppressWarnings("Unused") - public String getEndpointProtocolVersion() { + public List getEndpointProtocolVersion() { return endpointProtocolVersion; } @SuppressWarnings("Unused") - public void setEndpointProtocolVersion(String endpointProtocolVersion) { + public void setEndpointProtocolVersion(List endpointProtocolVersion) { this.endpointProtocolVersion = endpointProtocolVersion; } + @SuppressWarnings("Unused") + public String getSubprotocol() { + return subprotocol; + } + @SuppressWarnings("Unused") + public void setSubprotocol(String subprotocol) { + this.subprotocol = subprotocol; + } + @SuppressWarnings("Unused") + public String getSubprotocolBody() { + return subprotocolBody; + } + public Map getParsedSubprotocolBody() { + try { + return Splitter.on(';').withKeyValueSeparator('=').split(this.subprotocolBody); + }catch (Exception e){ + LogUtil.printException(e, "Error when parsing the subprotocol body params!"); + return null; + } + } + @SuppressWarnings("Unused") + public void setSubprotocolBody(String subprotocolBody) { + this.subprotocolBody = subprotocolBody; + } + @SuppressWarnings("Unused") + public String getSubprotocolBodyEncoding() { + return subprotocolBodyEncoding; + } + @SuppressWarnings("Unused") + public void setSubprotocolBodyEncoding(String subprotocolBodyEncoding) { + this.subprotocolBodyEncoding = subprotocolBodyEncoding; + } + @SuppressWarnings("Unused") + public Object getSecurityAttributes() { + return securityAttributes; + } + @SuppressWarnings("Unused") + public void setSecurityAttributes(Object securityAttributes) { + this.securityAttributes = securityAttributes; + } } } diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/EndPoint3.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/EndPoint3.java deleted file mode 100644 index 139736579..000000000 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/EndPoint3.java +++ /dev/null @@ -1,188 +0,0 @@ -/********************************************************************************* - * - * Catena-X - Product Passport Consumer Backend - * - * Copyright (c) 2022, 2023 BASF SE, BMW AG, Henkel AG & Co. KGaA - * - * 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 govern in permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.productpass.models.dtregistry; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Splitter; -import utils.LogUtil; - -import java.util.List; -import java.util.Map; - -/** - * This class consists exclusively to define attributes related to the designed model of the Endpoint's improved version. - **/ -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class EndPoint3 { - - /** ATTRIBUTES **/ - @JsonProperty("interface") - String interfaceName; - @JsonProperty("protocolInformation") - ProtocolInformation3 protocolInformation = new ProtocolInformation3(); - - /** GETTERS AND SETTERS **/ - public String getInterfaceName() { - return interfaceName; - } - @SuppressWarnings("Unused") - public void setInterfaceName(String interfaceName) { - this.interfaceName = interfaceName; - } - public ProtocolInformation3 getProtocolInformation() { - return protocolInformation; - } - @SuppressWarnings("Unused") - public void setProtocolInformation(String endpointAddress, String endpointProtocol, List endpointProtocolVersion) { - this.protocolInformation = new ProtocolInformation3(endpointAddress, endpointProtocol, endpointProtocolVersion); - } - - /** INNER CLASSES **/ - /** - * This class consists exclusively to define attributes related to the needed protocol information for the improved version. - **/ - public static class ProtocolInformation3 { - - /** ATTRIBUTES **/ - @JsonProperty("href") - String endpointAddress; - @JsonProperty("endpointProtocol") - String endpointProtocol; - @JsonProperty("subprotocol") - String subprotocol; - @JsonProperty("subprotocolBody") - String subprotocolBody; - @JsonProperty("subprotocolBodyEncoding") - String subprotocolBodyEncoding; - @JsonProperty("securityAttributes") - Object securityAttributes; - @JsonProperty("endpointProtocolVersion") - List endpointProtocolVersion; - - /** CONSTRUCTOR(S) **/ - public ProtocolInformation3(String endpointAddress, String endpointProtocol, List endpointProtocolVersion) { - this.endpointAddress = endpointAddress; - this.endpointProtocol = endpointProtocol; - this.endpointProtocolVersion = endpointProtocolVersion; - } - public ProtocolInformation3() { - } - @SuppressWarnings("Unused") - public ProtocolInformation3(String endpointAddress, String endpointProtocol, String subprotocol, String subprotocolBody, List endpointProtocolVersion) { - this.endpointAddress = endpointAddress; - this.endpointProtocol = endpointProtocol; - this.subprotocol = subprotocol; - this.subprotocolBody = subprotocolBody; - this.endpointProtocolVersion = endpointProtocolVersion; - } - @SuppressWarnings("Unused") - public ProtocolInformation3(String endpointAddress, String endpointProtocol, String subprotocol, String subprotocolBody, String subprotocolBodyEncoding, List endpointProtocolVersion) { - this.endpointAddress = endpointAddress; - this.endpointProtocol = endpointProtocol; - this.subprotocol = subprotocol; - this.subprotocolBody = subprotocolBody; - this.subprotocolBodyEncoding = subprotocolBodyEncoding; - this.endpointProtocolVersion = endpointProtocolVersion; - } - @SuppressWarnings("Unused") - public ProtocolInformation3(String endpointAddress, String endpointProtocol, String subprotocol, String subprotocolBody, String subprotocolBodyEncoding, Object securityAttributes, List endpointProtocolVersion) { - this.endpointAddress = endpointAddress; - this.endpointProtocol = endpointProtocol; - this.subprotocol = subprotocol; - this.subprotocolBody = subprotocolBody; - this.subprotocolBodyEncoding = subprotocolBodyEncoding; - this.securityAttributes = securityAttributes; - this.endpointProtocolVersion = endpointProtocolVersion; - } - - /** GETTERS AND SETTERS **/ - @SuppressWarnings("Unused") - public String getEndpointAddress() { - return endpointAddress; - } - @SuppressWarnings("Unused") - public void setEndpointAddress(String endpointAddress) { - this.endpointAddress = endpointAddress; - } - @SuppressWarnings("Unused") - public String getEndpointProtocol() { - return endpointProtocol; - } - @SuppressWarnings("Unused") - public void setEndpointProtocol(String endpointProtocol) { - this.endpointProtocol = endpointProtocol; - } - @SuppressWarnings("Unused") - public List getEndpointProtocolVersion() { - return endpointProtocolVersion; - } - @SuppressWarnings("Unused") - public void setEndpointProtocolVersion(List endpointProtocolVersion) { - this.endpointProtocolVersion = endpointProtocolVersion; - } - @SuppressWarnings("Unused") - public String getSubprotocol() { - return subprotocol; - } - @SuppressWarnings("Unused") - public void setSubprotocol(String subprotocol) { - this.subprotocol = subprotocol; - } - @SuppressWarnings("Unused") - public String getSubprotocolBody() { - return subprotocolBody; - } - public Map getParsedSubprotocolBody() { - try { - return Splitter.on(';').withKeyValueSeparator('=').split(this.subprotocolBody); - }catch (Exception e){ - LogUtil.printException(e, "Error when parsing the subprotocol body params!"); - return null; - } - } - @SuppressWarnings("Unused") - public void setSubprotocolBody(String subprotocolBody) { - this.subprotocolBody = subprotocolBody; - } - @SuppressWarnings("Unused") - public String getSubprotocolBodyEncoding() { - return subprotocolBodyEncoding; - } - @SuppressWarnings("Unused") - public void setSubprotocolBodyEncoding(String subprotocolBodyEncoding) { - this.subprotocolBodyEncoding = subprotocolBodyEncoding; - } - @SuppressWarnings("Unused") - public Object getSecurityAttributes() { - return securityAttributes; - } - @SuppressWarnings("Unused") - public void setSecurityAttributes(Object securityAttributes) { - this.securityAttributes = securityAttributes; - } - } -} diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/SubModel.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/SubModel.java index 682af7f79..348664ea8 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/SubModel.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/SubModel.java @@ -23,14 +23,18 @@ package org.eclipse.tractusx.productpass.models.dtregistry; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.JsonNode; import java.util.ArrayList; /** - * This class consists exclusively to define attributes related to the designed model of the Submodel's first version. + * This class consists exclusively to define attributes related to the designed model of the Submodel's improved version. **/ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) public class SubModel { /** ATTRIBUTES **/ @@ -38,16 +42,21 @@ public class SubModel { ArrayList description; @JsonProperty("idShort") String idShort; - @JsonProperty("identification") + + @JsonProperty("supplementalSemanticId") + Object supplementalSemanticId; + + @JsonProperty("id") String identification; @JsonProperty("semanticId") - JsonNode semanticId; + SemanticId semanticId; + @JsonProperty("endpoints") ArrayList endpoints; /** CONSTRUCTOR(S) **/ @SuppressWarnings("Unused") - public SubModel(ArrayList description, String idShort, String identification, JsonNode semanticId, ArrayList endpoints) { + public SubModel(ArrayList description, String idShort, String identification, SemanticId semanticId, ArrayList endpoints) { this.description = description; this.idShort = idShort; this.identification = identification; @@ -57,20 +66,33 @@ public SubModel(ArrayList description, String idShort, String identifi @SuppressWarnings("Unused") public SubModel() { } + @SuppressWarnings("Unused") + public SubModel(ArrayList description, String idShort, Object supplementalSemanticId, String identification, SemanticId semanticId, ArrayList endpoints) { + this.description = description; + this.idShort = idShort; + this.supplementalSemanticId = supplementalSemanticId; + this.identification = identification; + this.semanticId = semanticId; + this.endpoints = endpoints; + } /** GETTERS AND SETTERS **/ public ArrayList getDescription() { return description; } + public void setDescription(ArrayList description) { this.description = description; } + public String getIdShort() { return idShort; } + public void setIdShort(String idShort) { this.idShort = idShort; } + public String getIdentification() { return identification; } @@ -78,16 +100,97 @@ public String getIdentification() { public void setIdentification(String identification) { this.identification = identification; } - public JsonNode getSemanticId() { + + public SemanticId getSemanticId() { return semanticId; } - public void setSemanticId(JsonNode semanticId) { + + public void setSemanticId(SemanticId semanticId) { this.semanticId = semanticId; } + public ArrayList getEndpoints() { return endpoints; } + public void setEndpoints(ArrayList endpoints) { this.endpoints = endpoints; } + @SuppressWarnings("Unused") + public Object getSupplementalSemanticId() { + return supplementalSemanticId; + } + @SuppressWarnings("Unused") + public void setSupplementalSemanticId(Object supplementalSemanticId) { + this.supplementalSemanticId = supplementalSemanticId; + } + + /** INNER CLASSES **/ + /** + * This class consists exclusively to define attributes related to the Submodel's SemanticId. + **/ + public static class SemanticId { + + /** ATTRIBUTES **/ + @JsonProperty("type") + String type; + @JsonProperty("keys") + ArrayList keys; + + /** CONSTRUCTOR(S) **/ + @SuppressWarnings("Unused") + public SemanticId(String type, ArrayList keys) { + this.type = type; + this.keys = keys; + } + @SuppressWarnings("Unused") + public SemanticId() { + } + + /** GETTERS AND SETTERS **/ + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public ArrayList getKeys() { + return keys; + } + @SuppressWarnings("Unused") + public void setKeys(ArrayList keys) { + this.keys = keys; + } + + /** INNER CLASSES **/ + /** + * This class consists exclusively to define attributes related to the SemanticId's keys property. + **/ + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_NULL) + static public class Key { + + /** ATTRIBUTES **/ + @JsonProperty("type") + String type; + @JsonProperty("value") + String value; + + /** CONSTRUCTOR(S) **/ + public Key() {} + + public Key(String type, String value) { + this.type = type; + this.value = value; + } + + /** GETTERS AND SETTERS **/ + public String getType() { return type; } + public void setType(String type) { this.type = type; } + public String getValue() { return value; } + public void setValue(String value) { this.value = value; } + } + } } diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/SubModel3.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/SubModel3.java deleted file mode 100644 index 8f42f5286..000000000 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/dtregistry/SubModel3.java +++ /dev/null @@ -1,198 +0,0 @@ -/********************************************************************************* - * - * Catena-X - Product Passport Consumer Backend - * - * Copyright (c) 2022, 2023 BASF SE, BMW AG, Henkel AG & Co. KGaA - * - * 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 govern in permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.productpass.models.dtregistry; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.JsonNode; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * This class consists exclusively to define attributes related to the designed model of the Submodel's improved version. - **/ -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class SubModel3 { - - /** ATTRIBUTES **/ - @JsonProperty("description") - ArrayList description; - @JsonProperty("idShort") - String idShort; - - @JsonProperty("supplementalSemanticId") - Object supplementalSemanticId; - - @JsonProperty("id") - String identification; - @JsonProperty("semanticId") - SemanticId semanticId; - - @JsonProperty("endpoints") - ArrayList endpoints; - - /** CONSTRUCTOR(S) **/ - @SuppressWarnings("Unused") - public SubModel3(ArrayList description, String idShort, String identification, SemanticId semanticId, ArrayList endpoints) { - this.description = description; - this.idShort = idShort; - this.identification = identification; - this.semanticId = semanticId; - this.endpoints = endpoints; - } - @SuppressWarnings("Unused") - public SubModel3() { - } - @SuppressWarnings("Unused") - public SubModel3(ArrayList description, String idShort, Object supplementalSemanticId, String identification, SemanticId semanticId, ArrayList endpoints) { - this.description = description; - this.idShort = idShort; - this.supplementalSemanticId = supplementalSemanticId; - this.identification = identification; - this.semanticId = semanticId; - this.endpoints = endpoints; - } - - /** GETTERS AND SETTERS **/ - public ArrayList getDescription() { - return description; - } - - public void setDescription(ArrayList description) { - this.description = description; - } - - public String getIdShort() { - return idShort; - } - - public void setIdShort(String idShort) { - this.idShort = idShort; - } - - public String getIdentification() { - return identification; - } - @SuppressWarnings("Unused") - public void setIdentification(String identification) { - this.identification = identification; - } - - public SemanticId getSemanticId() { - return semanticId; - } - - public void setSemanticId(SemanticId semanticId) { - this.semanticId = semanticId; - } - - public ArrayList getEndpoints() { - return endpoints; - } - - public void setEndpoints(ArrayList endpoints) { - this.endpoints = endpoints; - } - @SuppressWarnings("Unused") - public Object getSupplementalSemanticId() { - return supplementalSemanticId; - } - @SuppressWarnings("Unused") - public void setSupplementalSemanticId(Object supplementalSemanticId) { - this.supplementalSemanticId = supplementalSemanticId; - } - - /** INNER CLASSES **/ - /** - * This class consists exclusively to define attributes related to the Submodel's SemanticId. - **/ - public static class SemanticId { - - /** ATTRIBUTES **/ - @JsonProperty("type") - String type; - @JsonProperty("keys") - ArrayList keys; - - /** CONSTRUCTOR(S) **/ - @SuppressWarnings("Unused") - public SemanticId(String type, ArrayList keys) { - this.type = type; - this.keys = keys; - } - @SuppressWarnings("Unused") - public SemanticId() { - } - - /** GETTERS AND SETTERS **/ - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public ArrayList getKeys() { - return keys; - } - @SuppressWarnings("Unused") - public void setKeys(ArrayList keys) { - this.keys = keys; - } - - /** INNER CLASSES **/ - /** - * This class consists exclusively to define attributes related to the SemanticId's keys property. - **/ - @JsonIgnoreProperties(ignoreUnknown = true) - @JsonInclude(JsonInclude.Include.NON_NULL) - static public class Key { - - /** ATTRIBUTES **/ - @JsonProperty("type") - String type; - @JsonProperty("value") - String value; - - /** CONSTRUCTOR(S) **/ - public Key() {} - - public Key(String type, String value) { - this.type = type; - this.value = value; - } - - /** GETTERS AND SETTERS **/ - public String getType() { return type; } - public void setType(String type) { this.type = type; } - public String getValue() { return value; } - public void setValue(String value) { this.value = value; } - } - } -} diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/http/requests/Search.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/http/requests/Search.java index 477963e63..0d8fc9268 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/http/requests/Search.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/http/requests/Search.java @@ -48,8 +48,6 @@ public class Search { String idType = "partInstanceId"; @JsonProperty(value = "dtIndex", defaultValue = "0") Integer dtIndex = 0; - @JsonProperty(value = "idShort", defaultValue = "digitalProductPass") - String idShort = "digitalProductPass"; @JsonProperty(value = "semanticId") String semanticId; @@ -58,13 +56,12 @@ public class Search { public Search() { } @SuppressWarnings("Unused") - public Search(String processId, String id, String version, String idType, Integer dtIndex, String idShort, String semanticId) { + public Search(String processId, String id, String version, String idType, Integer dtIndex, String semanticId) { this.processId = processId; this.id = id; this.version = version; this.idType = idType; this.dtIndex = dtIndex; - this.idShort = idShort; this.semanticId = semanticId; } @@ -99,12 +96,6 @@ public Integer getDtIndex() { public void setDtIndex(Integer dtIndex) { this.dtIndex = dtIndex; } - public String getIdShort() { - return idShort; - } - public void setIdShort(String idShort) { - this.idShort = idShort; - } public String getVersion() { return version; } diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/AasService.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/AasService.java index ada154c25..03b255927 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/AasService.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/AasService.java @@ -25,14 +25,14 @@ import org.eclipse.tractusx.productpass.config.DtrConfig; import org.eclipse.tractusx.productpass.config.PassportConfig; -import org.eclipse.tractusx.productpass.exceptions.ControllerException; import org.eclipse.tractusx.productpass.exceptions.ServiceException; import org.eclipse.tractusx.productpass.exceptions.ServiceInitializationException; import org.eclipse.tractusx.productpass.managers.DtrSearchManager; import org.eclipse.tractusx.productpass.managers.ProcessManager; import org.eclipse.tractusx.productpass.models.auth.JwtToken; import org.eclipse.tractusx.productpass.models.catenax.Dtr; -import org.eclipse.tractusx.productpass.models.dtregistry.*; +import org.eclipse.tractusx.productpass.models.dtregistry.DigitalTwin; +import org.eclipse.tractusx.productpass.models.dtregistry.SubModel; import org.eclipse.tractusx.productpass.models.edc.AssetSearch; import org.eclipse.tractusx.productpass.models.edc.DataPlaneEndpoint; import org.eclipse.tractusx.productpass.models.http.requests.Search; @@ -60,11 +60,8 @@ @Service public class AasService extends BaseService { - private final String submodelTypeKey = "Submodel"; /** ATTRIBUTES **/ - public String registryUrl; - - public Boolean central; + private final String submodelTypeKey = "Submodel"; private final HttpUtil httpUtil; private final JsonUtil jsonUtil; private final DtrConfig dtrConfig; @@ -97,8 +94,6 @@ public AasService(Environment env, HttpUtil httpUtil, JsonUtil jsonUtil, Authent * Initiates the main needed variables for the AasService by loading from the application's configuration file. **/ public void init(Environment env) { - this.registryUrl = dtrConfig.getCentralUrl(); - this.central = dtrConfig.getCentral(); Object decentralApis = dtrConfig.getDecentralApis(); if (decentralApis == null) { // If the configuration is null use the default variables decentralApis = Map.of( @@ -108,11 +103,6 @@ public void init(Environment env) { ); } this.apis = Map.of( - "central", Map.of( - "search", "/lookup/shells", - "digitalTwin", "/registry/shell-descriptors", - "subModel", "/submodel-descriptors" - ), "decentral", decentralApis ); } @@ -126,92 +116,7 @@ public void init(Environment env) { */ @Override public List getEmptyVariables() { - List missingVariables = new ArrayList<>(); - - if (this.central == null) { - missingVariables.add("dtr.central"); - } else { - if (this.central) { - if (this.registryUrl.isEmpty()) { - missingVariables.add("dtr.centralUrl"); - } - } - } - return missingVariables; - } - - /** - * Searches a {@code Submodel} from a Digital Twin by a given position index. - *

- * @param digitalTwin - * the {@code DigitalTwin} object with its submodels. - * @param position - * the {@code Integer} position index of the intended submodel. - * - * @return a {@code Submodel} object from the position index, if exists. - * - * @throws ServiceException - * if unable to find a submodel for the specified position index. - */ - @SuppressWarnings("Unused") - public SubModel searchSubModelInDigitalTwinByIndex(DigitalTwin digitalTwin, Integer position) { - try { - SubModel subModel = this.getSubModelFromDigitalTwin(digitalTwin, position); - if (subModel == null) { - throw new ServiceException(this.getClass().getName() + "." + "searchSubModelInDigitalTwin", - "It was not possible to get digital twin in the selected position for the selected asset type and the the selected assetId"); - } - return subModel; - } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "getIdShort", - e, - "It was not possible to get subModel!"); - } - } - - /** - * Searches a {@code DigitalTwin3} from a given position index containing the specified parameters. - *

- * @param assetType - * the {@code String} type of the asset. - * @param assetId - * the {@code String} identification of the asset. - * @param position - * the {@code Integer} position index of the intended digital twin. - * @param registryUrl - * the {@code String} registry URL of the Digital Twin. - * @param edr - * the {@code DataPlaneEndpoint} object with the data plane needed parameters. - * - * @return a {@code DigitalTwin3} object from the position index, if exists. - * - * @throws ServiceException - * if unable to find a {@code DigitalTwin3} for the specified position index. - */ - public DigitalTwin3 searchDigitalTwin3(String assetType, String assetId, Integer position, String registryUrl, DataPlaneEndpoint edr) { - try { - ArrayList digitalTwinIds = this.queryDigitalTwin(assetType, assetId, registryUrl, edr); - if (digitalTwinIds == null || digitalTwinIds.size() == 0) { - throw new ServiceException(this.getClass().getName() + "." + "searchDigitalTwin", - "It was not possible to get digital twin for the selected asset type and the the selected assetId"); - } - if (position > digitalTwinIds.size()) { - throw new ServiceException(this.getClass().getName() + "." + "searchDigitalTwin", - "It was not possible to get digital twin in the selected position for the selected asset type and the the selected assetId"); - } - - String digitalTwinId = digitalTwinIds.get(position); - DigitalTwin3 digitalTwin = this.getDigitalTwin3(digitalTwinId, registryUrl, edr); - if (digitalTwin == null) { - throw new ServiceException(this.getClass().getName() + "." + "searchDigitalTwin", - "It was not possible to get digital twin in the selected position for the selected asset type and the the selected assetId"); - } - return digitalTwin; - } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "searchDigitalTwin", - e, - "It was not possible to search digital twin!"); - } + return new ArrayList<>(); //Without central search there's no missing variables } /** @@ -245,7 +150,6 @@ public DigitalTwin searchDigitalTwin(String assetType, String assetId, Integer p "It was not possible to get digital twin in the selected position for the selected asset type and the the selected assetId"); } - String digitalTwinId = digitalTwinIds.get(position); DigitalTwin digitalTwin = this.getDigitalTwin(digitalTwinId, registryUrl, edr); if (digitalTwin == null) { @@ -272,112 +176,28 @@ public DigitalTwin searchDigitalTwin(String assetType, String assetId, Integer p * */ public String getPathEndpoint(String registryUrl, String key) { - if (this.central || registryUrl == null || registryUrl.isEmpty()) { - return (String) jsonUtil.getValue(this.apis, "central." + key, ".", null); - } String path = (String) jsonUtil.getValue(this.apis, "decentral." + key, ".", null); return path; } /** - * Searches a {@code Submodel3} from a Digital Twin by a given short identification. - *

- * @param digitalTwin - * the {@code DigitalTwin3} object with its submodels. - * @param idShort - * the {@code String} short id of the intended submodel. - * - * @return a {@code Submodel3} object with the submodel found, if exists. - * - * @throws ServiceException - * if unable to find a the {@code Submodel3} for the given id. - */ - public SubModel3 searchSubModel3ById(DigitalTwin3 digitalTwin, String idShort) { - try { - SubModel3 subModel = this.getSubModel3ById(digitalTwin, idShort); - if (subModel == null) { - throw new ServiceException(this.getClass().getName() + "." + "searchSubModel3ById", - "It was not possible to get submodel in the selected position for the selected asset type and the the selected assetId"); - } - return subModel; - } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "searchSubModel3ById", - e, - "It was not possible to search submodel!"); - } - } - - /** - * Searches a {@code Submodel3} from a Digital Twin by a given semantic identification. + * Searches a {@code Submodel} from a Digital Twin by a given semantic identification. *

* @param digitalTwin - * the {@code DigitalTwin3} object with its submodels. + * the {@code DigitalTwin} object with its submodels. * @param semanticId * the {@code String} semantic id of the intended submodel. * - * @return a {@code Submodel3} object with the submodel found, if exists. - * - * @throws ServiceException - * if unable to find a the {@code Submodel3} for the given semantic id. - */ - public SubModel3 searchSubModel3BySemanticId(DigitalTwin3 digitalTwin, String semanticId) { - try { - SubModel3 subModel = this.getSubModel3BySemanticId(digitalTwin, semanticId); - if (subModel == null) { - throw new ServiceException(this.getClass().getName() + "." + "searchSubModel3BySemanticId", - "It was not possible to get submodel in the selected position for the selected asset type and the the selected assetId"); - } - return subModel; - } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "searchSubModel3ById", - e, - "It was not possible to search submodel!"); - } - } - /** - * Searches a {@code Submodel3} from a Digital Twin by the configured semanticIds - *

- * @param digitalTwin - * the {@code DigitalTwin3} object with its submodels. - * - * @return a {@code Submodel3} object with the submodel found, if exists. - * - * @throws ServiceException - * if unable to find a the {@code Submodel3} for the given semantic id. - */ - public SubModel3 searchSubModel3BySemanticId(DigitalTwin3 digitalTwin) { - try { - SubModel3 subModel = this.getSubModel3BySemanticId(digitalTwin); - if (subModel == null) { - throw new ServiceException(this.getClass().getName() + "." + "searchSubModel3BySemanticId", - "It was not possible to get submodel in the selected position for the selected asset type and the the selected assetId"); - } - return subModel; - } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "searchSubModel3ById", - e, - "It was not possible to search submodel!"); - } - } - - /** - * Searches a {@code Submodel} from a Digital Twin by a given short identification. - *

- * @param digitalTwin - * the {@code DigitalTwin} object with its submodels. - * @param idShort - * the {@code String} short id of the intended submodel. - * * @return a {@code Submodel} object with the submodel found, if exists. * * @throws ServiceException - * if unable to find a the {@code Submodel} for the given id. + * if unable to find a the {@code Submodel} for the given semantic id. */ - public SubModel searchSubModelById(DigitalTwin digitalTwin, String idShort) { + public SubModel searchSubModelBySemanticId(DigitalTwin digitalTwin, String semanticId) { try { - SubModel subModel = this.getSubModelById(digitalTwin, idShort); + SubModel subModel = this.getSubModelBySemanticId(digitalTwin, semanticId); if (subModel == null) { - throw new ServiceException(this.getClass().getName() + "." + "searchSubModelById", + throw new ServiceException(this.getClass().getName() + "." + "searchSubModelBySemanticId", "It was not possible to get submodel in the selected position for the selected asset type and the the selected assetId"); } return subModel; @@ -387,71 +207,32 @@ public SubModel searchSubModelById(DigitalTwin digitalTwin, String idShort) { "It was not possible to search submodel!"); } } - /** - * Searches a {@code Submodel} from a Digital Twin from a given position index containing the specified parameters. + * Searches a {@code Submodel} from a Digital Twin by the configured semanticIds *

* @param digitalTwin * the {@code DigitalTwin} object with its submodels. - * @param position - * the {@code Integer} position index of the intended submodel. - * @param registryUrl - * the {@code String} registry URL of the Digital Twin. - * @param edr - * the {@code DataPlaneEndpoint} object with the data plane needed parameters. * - * @return a {@code Submodel} object from the position index, if exists. + * @return a {@code Submodel} object with the submodel found, if exists. * * @throws ServiceException - * if unable to find a {@code Submodel} for the specified position index. + * if unable to find a the {@code Submodel} for the given semantic id. */ - public SubModel searchSubModel(DigitalTwin digitalTwin, Integer position, String registryUrl, DataPlaneEndpoint edr) { + public SubModel searchSubModelBySemanticId(DigitalTwin digitalTwin) { try { - SubModel subModel = this.getSubModel(digitalTwin, position, registryUrl, edr); + SubModel subModel = this.getSubModelBySemanticId(digitalTwin); if (subModel == null) { - throw new ServiceException(this.getClass().getName() + "." + "searchSubModel", + throw new ServiceException(this.getClass().getName() + "." + "searchSubModelBySemanticId", "It was not possible to get submodel in the selected position for the selected asset type and the the selected assetId"); } return subModel; } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "searchSubModel", + throw new ServiceException(this.getClass().getName() + "." + "searchSubModelById", e, "It was not possible to search submodel!"); } } - /** - * Gets the {@code DigitalTwin3} of a given id. - *

- * @param digitalTwinId - * the {@code String} identification of the digital twin. - * @param registryUrl - * the {@code String} registry URL of the Digital Twin. - * @param edr - * the {@code DataPlaneEndpoint} object with the data plane needed parameters. - * - * @return a {@code DigitalTwin3} object with the given id, if exists. - * - * @throws ServiceException - * if unable to find a {@code DigitalTwin3} for the specified id. - */ - public DigitalTwin3 getDigitalTwin3(String digitalTwinId, String registryUrl, DataPlaneEndpoint edr) { - try { - String path = this.getPathEndpoint(registryUrl, "digitalTwin"); - String url = this.getRegistryUrl(registryUrl) + path + "/" + CrypUtil.toBase64Url(digitalTwinId); - Map params = httpUtil.getParams(); - HttpHeaders headers = this.getTokenHeader(edr); - ResponseEntity response = httpUtil.doGet(url, String.class, headers, params, true, false); - String responseBody = (String) response.getBody(); - return (DigitalTwin3) jsonUtil.bindJsonNode(jsonUtil.toJsonNode(responseBody), DigitalTwin3.class); - } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "getDigitalTwin", - e, - "It was not possible to get digital twin!"); - } - - } - /** * Gets the {@code DigitalTwin} of a given id. *

@@ -470,7 +251,7 @@ public DigitalTwin3 getDigitalTwin3(String digitalTwinId, String registryUrl, Da public DigitalTwin getDigitalTwin(String digitalTwinId, String registryUrl, DataPlaneEndpoint edr) { try { String path = this.getPathEndpoint(registryUrl, "digitalTwin"); - String url = this.getRegistryUrl(registryUrl) + path + "/" + digitalTwinId; + String url = this.getRegistryUrl(registryUrl) + path + "/" + CrypUtil.toBase64Url(digitalTwinId); Map params = httpUtil.getParams(); HttpHeaders headers = this.getTokenHeader(edr); ResponseEntity response = httpUtil.doGet(url, String.class, headers, params, true, false); @@ -484,127 +265,26 @@ public DigitalTwin getDigitalTwin(String digitalTwinId, String registryUrl, Data } - - /** - * Gets the {@code Submodel} from a Digital Twin from a given position index. - *

- * @param digitalTwin - * the {@code DigitalTwin} object with its submodels. - * @param position - * the {@code Integer} position index of the intended submodel. - * - * @return a {@code Submodel} object from the position index, if exists. - * - * @throws ServiceException - * if unable to find a {@code Submodel} for the specified position index. - */ - public SubModel getSubModelFromDigitalTwin(DigitalTwin digitalTwin, Integer position) { - try { - ArrayList subModels = digitalTwin.getSubmodelDescriptors(); - if (position > subModels.size()) { - throw new ServiceException(this.getClass().getName() + "." + "getSubModelFromDigitalTwin", - "Position selected for subModel is out of range!"); - } - return subModels.get(position); - } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "getSubModelFromDigitalTwin", - e, - "It was not possible to get subModel from digital twin!"); - } - } - /** - * Gets the {@code Submodel} from a Digital Twin from a given position index containing the specified parameters. + * Gets the {@code Submodel} from a Digital Twin by the configured semantic aspects *

* @param digitalTwin * the {@code DigitalTwin} object with its submodels. - * @param position - * the {@code Integer} position index of the intended submodel. - * @param registryUrl - * the {@code String} registry URL of the Digital Twin. - * @param edr - * the {@code DataPlaneEndpoint} object with the data plane needed parameters. * - * @return a {@code Submodel} object from the position index, if exists. - * - * @throws ServiceException - * if unable to find a {@code Submodel} for the specified position index. - */ - public SubModel getSubModel(DigitalTwin digitalTwin, Integer position, String registryUrl, DataPlaneEndpoint edr) { - try { - String path = this.getPathEndpoint(registryUrl, "digitalTwin"); - SubModel subModel = this.getSubModelFromDigitalTwin(digitalTwin, position); - String url = this.getRegistryUrl(registryUrl) + path + "/" + digitalTwin.getIdentification() + this.getPathEndpoint(registryUrl,"subModel") + "/" + subModel.getIdentification(); - Map params = httpUtil.getParams(); - HttpHeaders headers = this.getTokenHeader(edr); - LogUtil.printMessage(jsonUtil.toJson(headers, true)); - ResponseEntity response = httpUtil.doGet(url, String.class, headers, params, true, false); - String responseBody = (String) response.getBody(); - return (SubModel) jsonUtil.bindJsonNode(jsonUtil.toJsonNode(responseBody), SubModel.class); - } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "getSubModel", - e, - "It was not possible to get subModel!"); - } - } - - /** - * Gets the {@code Submodel3} from a Digital Twin by a given short identification. - *

- * @param digitalTwin - * the {@code DigitalTwin3} object with its submodels. - * @param idShort - * the {@code String} short id of the intended submodel. - * - * @return a {@code Submodel3} object with the submodel found, if exists. - * - * @throws ServiceException - * if unable to find a the {@code Submodel3} for the given id. - */ - public SubModel3 getSubModel3ById(DigitalTwin3 digitalTwin, String idShort) { - try { - ArrayList subModels = digitalTwin.getSubmodelDescriptors(); - if (subModels.size() < 1) { - throw new ServiceException(this.getClass().getName() + "." + "getSubModel3ById", - "No subModel found in digitalTwin!"); - } - // Search for first subModel with matching idShort, if it fails gives null - SubModel3 subModel = subModels.stream().filter(s -> s.getIdShort().equalsIgnoreCase(idShort)).findFirst().orElse(null); - - if (subModel == null) { - // If the subModel idShort does not exist - throw new ServiceException(this.getClass().getName() + "." + "getSubModel3ById", - "SubModel for idShort not found!"); - } - // Return subModel if found - return subModel; - } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "getSubModel3ById", - e, - "It was not possible to get subModel!"); - } - } - - /** - * Gets the {@code Submodel3} from a Digital Twin by the configured semantic aspects - *

- * @param digitalTwin - * the {@code DigitalTwin3} object with its submodels. - * - * @return a {@code Submodel3} object with the submodel found, if exists. + * @return a {@code Submodel} object with the submodel found, if exists. * * @throws ServiceException - * if unable to find a the {@code Submodel3} for the given semantic id. + * if unable to find a the {@code Submodel} for the given semantic id. */ - public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin) { + public SubModel getSubModelBySemanticId(DigitalTwin digitalTwin) { try { - ArrayList subModels = digitalTwin.getSubmodelDescriptors(); + ArrayList subModels = digitalTwin.getSubmodelDescriptors(); if (subModels.size() < 1) { - throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", + throw new ServiceException(this.getClass().getName() + "." + "getSubModelBySemanticId", "No subModel found in digitalTwin!"); } - SubModel3 subModel = null; + SubModel subModel = null; // Search for first subModel with matching semanticId, if it fails gives null for (String semanticId: passportConfig.getAspects()) { subModel = subModels.stream().filter(s -> s.getSemanticId().getKeys().stream().filter(k -> k.getType().equalsIgnoreCase(submodelTypeKey) && k.getValue().equalsIgnoreCase(semanticId)) != null).findFirst().orElse(null); @@ -613,82 +293,45 @@ public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin) { } } // If the subModel semanticId does not exist - throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", + throw new ServiceException(this.getClass().getName() + "." + "getSubModelBySemanticId", "SubModel for SemanticId not found!"); } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", + throw new ServiceException(this.getClass().getName() + "." + "getSubModelBySemanticId", e, "It was not possible to get subModel!"); } } /** - * Gets the {@code Submodel3} from a Digital Twin by a given semantic identification. + * Gets the {@code Submodel} from a Digital Twin by a given semantic identification. *

* @param digitalTwin - * the {@code DigitalTwin3} object with its submodels. + * the {@code DigitalTwin} object with its submodels. * @param semanticId * the {@code String} semantic id of the intended submodel. * - * @return a {@code Submodel3} object with the submodel found, if exists. + * @return a {@code Submodel} object with the submodel found, if exists. * * @throws ServiceException - * if unable to find a the {@code Submodel3} for the given semantic id. + * if unable to find a the {@code Submodel} for the given semantic id. */ - public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin, String semanticId) { + public SubModel getSubModelBySemanticId(DigitalTwin digitalTwin, String semanticId) { try { - ArrayList subModels = digitalTwin.getSubmodelDescriptors(); + ArrayList subModels = digitalTwin.getSubmodelDescriptors(); if (subModels.size() < 1) { - throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", + throw new ServiceException(this.getClass().getName() + "." + "getSubModelBySemanticId", "No subModel found in digitalTwin!"); } - SubModel3 subModel = null; + SubModel subModel = null; // Search for first subModel with matching semanticId, if it fails gives null subModel = subModels.stream().filter(s -> s.getSemanticId().getKeys().stream().filter(k -> k.getType().equalsIgnoreCase(submodelTypeKey) && k.getValue().equalsIgnoreCase(semanticId)) != null).findFirst().orElse(null); if (subModel != null) { return subModel; // Return subModel if found } // If the subModel semanticId does not exist - throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", + throw new ServiceException(this.getClass().getName() + "." + "getSubModelBySemanticId", "SubModel for SemanticId not found!"); } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", - e, - "It was not possible to get subModel!"); - } - } - - /** - * Gets the {@code Submodel} from a Digital Twin by a given short identification. - *

- * @param digitalTwin - * the {@code DigitalTwin} object with its submodels. - * @param idShort - * the {@code String} short id of the intended submodel. - * - * @return a {@code Submodel} object with the submodel found, if exists. - * - * @throws ServiceException - * if unable to find a the {@code Submodel} for the given id. - */ - public SubModel getSubModelById(DigitalTwin digitalTwin, String idShort) { - try { - ArrayList subModels = digitalTwin.getSubmodelDescriptors(); - if (subModels.size() < 1) { - throw new ServiceException(this.getClass().getName() + "." + "getSubModelByIdShort", - "No subModel found in digitalTwin!"); - } - // Search for first subModel with matching idShort, if it fails gives null - SubModel subModel = subModels.stream().filter(s -> s.getIdShort().equalsIgnoreCase(idShort)).findFirst().orElse(null); - - if (subModel == null) { - // If the subModel idShort does not exist - throw new ServiceException(this.getClass().getName() + "." + "getSubModelByIdShort", - "SubModel for idShort not found!"); - } - // Return subModel if found - return subModel; - } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "getSubModelByIdShort", + throw new ServiceException(this.getClass().getName() + "." + "getSubModelBySemanticId", e, "It was not possible to get subModel!"); } @@ -707,8 +350,7 @@ public SubModel getSubModelById(DigitalTwin digitalTwin, String idShort) { */ public HttpHeaders getTokenHeader(DataPlaneEndpoint edr) { try { - // If the dtr is central we just need the token - if (this.central || edr == null) { + if (edr == null) { // In case it fails we should throw get the token JwtToken token = authService.getToken(); return this.httpUtil.getHeadersWithToken(token.getAccessToken()); @@ -734,69 +376,7 @@ public HttpHeaders getTokenHeader(DataPlaneEndpoint edr) { * */ public String getRegistryUrl(String url) { - return (url == null || this.central || url.isEmpty()) ? this.registryUrl : url; - } - - /** - * Searches for centralized Digital Twin Registries. - *

- * @param processId - * the {@code String} identification of the process. - * @param searchBody - * the {@code Search} object with the Request Body of the HTTP request. - * - * @return an {@code AssetSearch} object with the connector address and the asset id of the DTR. - * - * @throws ServiceException - * if unable to search and/or find the DTR. - */ - public AssetSearch centralDtrSearch(String processId, Search searchBody){ - try { - // Start Digital Twin Query - AasService.DigitalTwinRegistryQueryById digitalTwinRegistry = this.new DigitalTwinRegistryQueryById(searchBody); - Long dtRequestTime = DateTimeUtil.getTimestamp(); - Thread digitalTwinRegistryThread = ThreadUtil.runThread(digitalTwinRegistry); - - // Wait for digital twin query - digitalTwinRegistryThread.join(); - DigitalTwin digitalTwin; - SubModel subModel; - String connectorId; - String connectorAddress; - try { - digitalTwin = digitalTwinRegistry.getDigitalTwin(); - subModel = digitalTwinRegistry.getSubModel(); - connectorId = subModel.getIdShort(); - EndPoint endpoint = subModel.getEndpoints().stream().filter(obj -> obj.getInterfaceName().equals(dtrConfig.getEndpointInterface())).findFirst().orElse(null); - if (endpoint == null) { - throw new ControllerException(this.getClass().getName(), "No EDC endpoint found in DTR SubModel!"); - } - connectorAddress = endpoint.getProtocolInformation().getEndpointAddress(); - } catch (Exception e) { - return null; - } - if (connectorId.isEmpty() || connectorAddress.isEmpty()) { - return null; - } - - - try { - connectorAddress = CatenaXUtil.buildEndpoint(connectorAddress); - } catch (Exception e) { - return null; - } - if (connectorAddress.isEmpty()) { - return null; - } - processManager.saveDigitalTwin(processId, digitalTwin, dtRequestTime); - LogUtil.printDebug("[PROCESS " + processId + "] Digital Twin [" + digitalTwin.getIdentification() + "] and Submodel [" + subModel.getIdentification() + "] with EDC endpoint [" + connectorAddress + "] retrieved from DTR"); - String assetId = String.join("-", digitalTwin.getIdentification(), subModel.getIdentification()); - return new AssetSearch(assetId, connectorAddress); - } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "centralDtrSearch", - e, - "It was not possible to search and find digital twin"); - } + return url; } /** @@ -873,7 +453,7 @@ public ArrayList queryDigitalTwin(String assetType, String assetId, Stri String url = this.getRegistryUrl(registryUrl) + path; Map params = httpUtil.getParams(); ResponseEntity response = null; - if (!this.central && registryUrl != null && edr != null) { + if (registryUrl != null && edr != null) { // Set request body as post if the central query is disabled // Query as GET if the central query is enabled Map assetIds = Map.of( @@ -965,14 +545,12 @@ public Status getStatus(){ public class DecentralDigitalTwinRegistryQueryById implements Runnable { /** ATTRIBUTES **/ - private final String dppIdShort = "digitalProductPass"; private DataPlaneEndpoint edr; - private SubModel3 subModel; - private DigitalTwin3 digitalTwin; + private SubModel subModel; + private DigitalTwin digitalTwin; private final String assetId; private final String idType; private final Integer dtIndex; - private final String idShort; private final String semanticId; /** CONSTRUCTOR(S) **/ @@ -980,27 +558,10 @@ public DecentralDigitalTwinRegistryQueryById(Search search, DataPlaneEndpoint ed this.assetId = search.getId(); this.idType = search.getIdType(); this.dtIndex = search.getDtIndex(); - this.idShort = search.getIdShort(); this.edr = edr; this.semanticId = search.getSemanticId(); } - /** - * This method is exclusively to search for a digital twin and the submodel. - * - *

It's a Thread level method from Runnable interface and does the {@code DigitalTwin3} and {@code Submodel3} search, setting the results - * to this class object. - *

The submodel search it's done by the idShort or semanticId parameters depending on if the semantic Id is available or not, respectively. - * - */ - @Override - public void run() { - this.setDigitalTwin(searchDigitalTwin3(this.getIdType(), this.getAssetId(), this.getDtIndex(), this.getEdr().getEndpoint(), this.getEdr())); - if(semanticId.isEmpty()){ - this.setSubModel(searchSubModel3BySemanticId(this.getDigitalTwin())); - }else { - this.setSubModel(searchSubModel3BySemanticId(this.getDigitalTwin(), semanticId)); - } - } + /** GETTERS AND SETTERS **/ public DataPlaneEndpoint getEdr() { return edr; @@ -1008,63 +569,14 @@ public DataPlaneEndpoint getEdr() { public void setEdr(DataPlaneEndpoint edr) { this.edr = edr; } - public SubModel3 getSubModel() { + public SubModel getSubModel() { return subModel; } - public void setSubModel(SubModel3 subModel) { + public void setSubModel(SubModel subModel) { this.subModel = subModel; } - public DigitalTwin3 getDigitalTwin() { - return digitalTwin; - } - public void setDigitalTwin(DigitalTwin3 digitalTwin) { - this.digitalTwin = digitalTwin; - } - public String getAssetId() { - return assetId; - } - public String getIdType() { - return idType; - } - public Integer getDtIndex() { - return dtIndex; - } - public String getIdShort() { - return idShort; - } - public String getSemanticId() { return semanticId; } - - /** METHODS **/ - - } - - public class DigitalTwinRegistryQueryById implements Runnable { - - /** ATTRIBUTES **/ - private SubModel subModel; - private DigitalTwin digitalTwin; - private final String assetId; - private final String idType; - private final Integer dtIndex; - private final String idShort; - - /** CONSTRUCTOR(S) **/ - public DigitalTwinRegistryQueryById(Search search) { - this.assetId = search.getId(); - this.idType = search.getIdType(); - this.dtIndex = search.getDtIndex(); - this.idShort = search.getIdShort(); - } - - /** GETTERS AND SETTERS **/ - public SubModel getSubModel() { - return this.subModel; - } public DigitalTwin getDigitalTwin() { - return this.digitalTwin; - } - public void setSubModel(SubModel subModel) { - this.subModel = subModel; + return digitalTwin; } public void setDigitalTwin(DigitalTwin digitalTwin) { this.digitalTwin = digitalTwin; @@ -1078,72 +590,25 @@ public String getIdType() { public Integer getDtIndex() { return dtIndex; } - public String getIdShort() { - return idShort; - } - - /** METHODS **/ - - /** - * This method is exclusively to search for a digital twin and the submodel. - * - *

It's a Thread level method from Runnable interface and does the {@code DigitalTwin} and {@code Submodel} search, setting the results - * to this class object. - *

The submodel search it's done by the idShort. - * - */ - @Override - public void run() { - this.digitalTwin = searchDigitalTwin(this.idType, this.assetId, this.dtIndex, null, null); - this.subModel = searchSubModelById(this.digitalTwin, this.idShort); - } - - } - - @SuppressWarnings("Unused") - public class DigitalTwinRegistryQuery implements Runnable { - - /** ATTRIBUTES **/ - private SubModel subModel; - private DigitalTwin digitalTwin; - private final String assetId; - private final String idType; - private final Integer dtIndex; - - /** CONSTRUCTOR(S) **/ - @SuppressWarnings("Unused") - public DigitalTwinRegistryQuery(String assetId, String idType, Integer dtIndex) { - this.assetId = assetId; - this.idType = idType; - this.dtIndex = dtIndex; - } - - /** GETTERS AND SETTERS **/ - @SuppressWarnings("Unused") - public SubModel getSubModel() { - return this.subModel; - } - @SuppressWarnings("Unused") - public DigitalTwin getDigitalTwin() { - return this.digitalTwin; - } + public String getSemanticId() { return semanticId; } /** METHODS **/ - /** * This method is exclusively to search for a digital twin and the submodel. * *

It's a Thread level method from Runnable interface and does the {@code DigitalTwin} and {@code Submodel} search, setting the results * to this class object. - *

The submodel search it's done by index position. + *

The submodel search it's done by semanticId parameter depending on if the semanticId is available or not, if not does the search by a semanticId default value. * */ @Override public void run() { - this.digitalTwin = searchDigitalTwin(this.idType, this.assetId, this.dtIndex, null, null); - this.subModel = searchSubModel(this.digitalTwin, this.dtIndex, null, null); + this.setDigitalTwin(searchDigitalTwin(this.getIdType(), this.getAssetId(), this.getDtIndex(), this.getEdr().getEndpoint(), this.getEdr())); + if(semanticId.isEmpty()){ + this.setSubModel(searchSubModelBySemanticId(this.getDigitalTwin())); + }else { + this.setSubModel(searchSubModelBySemanticId(this.getDigitalTwin(), semanticId)); + } } - } - } diff --git a/consumer-backend/productpass/src/main/resources/application.yml b/consumer-backend/productpass/src/main/resources/application.yml index e135f4dc2..4bc805bb1 100644 --- a/consumer-backend/productpass/src/main/resources/application.yml +++ b/consumer-backend/productpass/src/main/resources/application.yml @@ -61,8 +61,6 @@ configuration: edc: true dtr: - central: false - centralUrl: 'https://semantics.int.demo.catena-x.net/registry' assetId: 'digital-twin-registry' endpointInterface: 'SUBMODEL-3.0' dspEndpointKey: 'dspEndpoint' From c2f6cb2c51d59fba93301c55015686a98293c64c Mon Sep 17 00:00:00 2001 From: Mathias Brunkow Moser Date: Mon, 16 Oct 2023 15:56:45 +0200 Subject: [PATCH 2/3] feat: changed the dtr searched based in the asset type --- charts/digital-product-pass/values-beta.yaml | 2 +- charts/digital-product-pass/values-dev.yaml | 2 +- charts/digital-product-pass/values-int.yaml | 2 +- charts/digital-product-pass/values.yaml | 4 ++-- .../eclipse/tractusx/productpass/config/DtrConfig.java | 10 +++++----- .../productpass/services/DataTransferService.java | 4 ++-- .../productpass/src/main/resources/application.yml | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/charts/digital-product-pass/values-beta.yaml b/charts/digital-product-pass/values-beta.yaml index d8ffaa0f7..fecc80582 100644 --- a/charts/digital-product-pass/values-beta.yaml +++ b/charts/digital-product-pass/values-beta.yaml @@ -128,7 +128,7 @@ backend: dtr: central: false centralUrl: 'https://semantics.beta.demo.catena-x.net/registry' - assetId: 'digital-twin-registry' + assetType: 'data.core.digitalTwinRegistry' endpointInterface: 'SUBMODEL-3.0' dspEndpointKey: 'dspEndpoint' internalDtr: "https://materialpass.beta.demo.catena-x.net/BPNL000000000000" # -- If there is an internal DTR available it can be referenced here and will be injected in the list of DTRs diff --git a/charts/digital-product-pass/values-dev.yaml b/charts/digital-product-pass/values-dev.yaml index ecd2d910d..62b07d723 100644 --- a/charts/digital-product-pass/values-dev.yaml +++ b/charts/digital-product-pass/values-dev.yaml @@ -128,7 +128,7 @@ backend: dtr: central: false centralUrl: 'https://semantics.dev.demo.catena-x.net/registry' - assetId: 'digital-twin-registry' + assetType: 'data.core.digitalTwinRegistry' dspEndpointKey: 'dspEndpoint' endpointInterface: 'SUBMODEL-3.0' internalDtr: "https://materialpass.dev.demo.catena-x.net/BPNL000000000000" # -- If there is an internal DTR available it can be referenced here and will be injected in the list of DTRs diff --git a/charts/digital-product-pass/values-int.yaml b/charts/digital-product-pass/values-int.yaml index a06a4b030..09b490bf7 100644 --- a/charts/digital-product-pass/values-int.yaml +++ b/charts/digital-product-pass/values-int.yaml @@ -126,7 +126,7 @@ backend: dtr: central: false centralUrl: 'https://semantics.int.demo.catena-x.net/registry' - assetId: 'digital-twin-registry' + assetType: 'data.core.digitalTwinRegistry' dspEndpointKey: 'dspEndpoint' endpointInterface: 'SUBMODEL-3.0' internalDtr: "https://materialpass.int.demo.catena-x.net/BPNL000000000000" # -- If there is an internal DTR available it can be referenced here and will be injected in the list of DTRs diff --git a/charts/digital-product-pass/values.yaml b/charts/digital-product-pass/values.yaml index 377de0444..1b4efe76c 100644 --- a/charts/digital-product-pass/values.yaml +++ b/charts/digital-product-pass/values.yaml @@ -148,8 +148,8 @@ backend: central: false # -- central digital twin registry url centralUrl: 'https://' - # -- asset id to search for the registry in the edc - assetId: 'digital-twin-registry' + # -- asset type to search for the registry in the edc + assetType: 'data.core.digitalTwinRegistry' # -- submodel endpoint interface to search endpointInterface: 'SUBMODEL-3.0' # -- dsp endpoint key inside submodel body diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/DtrConfig.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/DtrConfig.java index 9b55a589e..24d2a8129 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/DtrConfig.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/DtrConfig.java @@ -43,7 +43,7 @@ public class DtrConfig { Timeouts timeouts; Boolean temporaryStorage; DecentralApis decentralApis; - String assetId; + String assetType; String endpointInterface; String dspEndpointKey; @@ -88,11 +88,11 @@ public String getDspEndpointKey() { public void setDspEndpointKey(String dspEndpointKey) { this.dspEndpointKey = dspEndpointKey; } - public String getAssetId() { - return assetId; + public String getAssetType() { + return assetType; } - public void setAssetId(String assetId) { - this.assetId = assetId; + public void setAssetType(String assetType) { + this.assetType = assetType; } /** INNER CLASSES **/ diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataTransferService.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataTransferService.java index d8b06bb70..bb782a0f3 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataTransferService.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataTransferService.java @@ -324,9 +324,9 @@ public Catalog searchDigitalTwinCatalog(String providerUrl) throws ServiceExcept // Simple catalog request query with no limitation. CatalogRequest.QuerySpec querySpec = new CatalogRequest.QuerySpec(); CatalogRequest.QuerySpec.FilterExpression filterExpression = new CatalogRequest.QuerySpec.FilterExpression( - "https://w3id.org/edc/v0.0.1/ns/id", + "https://w3id.org/edc/v0.0.1/ns/type", "=", - this.dtrConfig.getAssetId() + this.dtrConfig.getAssetType() ); // Filter by asset id querySpec.setFilterExpression(List.of(filterExpression)); Object body = new CatalogRequest( diff --git a/consumer-backend/productpass/src/main/resources/application.yml b/consumer-backend/productpass/src/main/resources/application.yml index 4bc805bb1..6aa39654e 100644 --- a/consumer-backend/productpass/src/main/resources/application.yml +++ b/consumer-backend/productpass/src/main/resources/application.yml @@ -61,7 +61,7 @@ configuration: edc: true dtr: - assetId: 'digital-twin-registry' + assetType: 'data.core.digitalTwinRegistry' endpointInterface: 'SUBMODEL-3.0' dspEndpointKey: 'dspEndpoint' internalDtr: "https://materialpass.int.demo.catena-x.net/BPNL000000000000" # -- If there is an internal DTR available it can be referenced here and will be injected in the list of DTRs @@ -80,7 +80,7 @@ configuration: endpoint: "https://semantics.int.demo.catena-x.net/discoveryfinder/api/administration/connectors/discovery/search" bpn: key: "manufacturerPartId" - searchPath: "/api/administration/connectors/bpnDiscovery/search" + searchPath: "/api/administration/v1.0/connectors/bpnDiscovery/search" edc: key: "bpn" From 04969b4bc7309436f399fee7dc482ade5545eedb Mon Sep 17 00:00:00 2001 From: Mathias Brunkow Moser Date: Thu, 19 Oct 2023 11:38:00 +0200 Subject: [PATCH 3/3] merge: fixed merge conflicts with digital product pass branch --- .../org/eclipse/tractusx/productpass/config/DtrConfig.java | 7 +++---- .../eclipse/tractusx/productpass/services/AasService.java | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/DtrConfig.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/DtrConfig.java index d84cc686f..af428936d 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/DtrConfig.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/DtrConfig.java @@ -52,19 +52,18 @@ public class DtrConfig { public DtrConfig() { } - public DtrConfig(Boolean central, String centralUrl, String internalDtr, Timeouts timeouts, Boolean temporaryStorage, DecentralApis decentralApis, String assetId, String endpointInterface, String dspEndpointKey, String semanticIdTypeKey) { - this.central = central; - this.centralUrl = centralUrl; + public DtrConfig(String internalDtr, Timeouts timeouts, Boolean temporaryStorage, DecentralApis decentralApis, String assetType, String endpointInterface, String dspEndpointKey, String semanticIdTypeKey) { this.internalDtr = internalDtr; this.timeouts = timeouts; this.temporaryStorage = temporaryStorage; this.decentralApis = decentralApis; - this.assetId = assetId; + this.assetType = assetType; this.endpointInterface = endpointInterface; this.dspEndpointKey = dspEndpointKey; this.semanticIdTypeKey = semanticIdTypeKey; } + /** GETTERS AND SETTERS **/ public DecentralApis getDecentralApis() { return decentralApis; diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/AasService.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/AasService.java index c55070e36..4d6d9bfd5 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/AasService.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/AasService.java @@ -310,7 +310,7 @@ public SubModel getSubModelBySemanticId(DigitalTwin digitalTwin) { * Gets the {@code Submodel} from a Digital Twin by a given semantic identification. *

* @param digitalTwin - * the {@code DigitalTwin3} object with its submodels. + * the {@code DigitalTwin} object with its submodels. * @param aspectSemanticId * the {@code String} semantic id of the intended submodel. * @@ -319,7 +319,7 @@ public SubModel getSubModelBySemanticId(DigitalTwin digitalTwin) { * @throws ServiceException * if unable to find a the {@code Submodel} for the given semantic id. */ - public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin, String aspectSemanticId) { + public SubModel getSubModelBySemanticId(DigitalTwin digitalTwin, String aspectSemanticId) { try { ArrayList subModels = digitalTwin.getSubmodelDescriptors(); if (subModels.size() < 1) {