From f7f181831628eb9b15a4c1242c48b63883d2bd27 Mon Sep 17 00:00:00 2001 From: Parracho Date: Mon, 18 Sep 2023 09:51:47 +0100 Subject: [PATCH 01/18] feat: fixed a missing call on searchSubmodel3BySemanticId method for dpp search --- .../org/eclipse/tractusx/productpass/services/AasService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 0138a0745..8545a8769 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 @@ -230,10 +230,10 @@ public SubModel3 searchSubModel3ById(DigitalTwin3 digitalTwin, String idShort) { public SubModel3 searchSubModel3BySemanticId(DigitalTwin3 digitalTwin, String semanticId) { try { - SubModel3 subModel = this.getSubModel3ById(digitalTwin, semanticId); + SubModel3 subModel = this.getSubModel3BySemanticId(digitalTwin, semanticId); LogUtil.printWarning("SUBMODEL3:\n" + jsonUtil.toJson(subModel, true)); if (subModel == null) { - throw new ServiceException(this.getClass().getName() + "." + "searchSubModel3ById", + 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; From 370b57884efba76790c68aeb38ed637a42ebd158 Mon Sep 17 00:00:00 2001 From: Parracho Date: Wed, 20 Sep 2023 09:01:08 +0100 Subject: [PATCH 02/18] feat: fixed issue in getting submodel by semanticId method --- .../productpass/services/AasService.java | 36 ++++++++++++------- .../src/main/resources/application.yml | 8 ++--- 2 files changed, 28 insertions(+), 16 deletions(-) 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 8545a8769..77bb9072d 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 @@ -65,6 +65,7 @@ @Service public class AasService extends BaseService { + private final String submodelTypeKey = "Submodel"; public String registryUrl; public Boolean central; @@ -147,7 +148,13 @@ public SubModel searchSubModelInDigitalTwinByIndex(DigitalTwin digitalTwin, Inte } public DigitalTwin3 searchDigitalTwin3(String assetType, String assetId, Integer position, String registryUrl, DataPlaneEndpoint edr) { try { + LogUtil.printWarning("ASSET TYPE: " + assetType); + LogUtil.printWarning("ASSET ID: " + assetId); + LogUtil.printWarning("POSITION: " + position); + LogUtil.printWarning("REGISTRY URL: " + registryUrl); + LogUtil.printWarning("DATA PLANE END POINT\n" + jsonUtil.toJson(edr, true)); ArrayList digitalTwinIds = this.queryDigitalTwin(assetType, assetId, registryUrl, edr); + LogUtil.printWarning("DIGITAL TWINS ARRAY SIZE: " + digitalTwinIds.size()); 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"); @@ -160,6 +167,7 @@ public DigitalTwin3 searchDigitalTwin3(String assetType, String assetId, Integer String digitalTwinId = digitalTwinIds.get(position); DigitalTwin3 digitalTwin = this.getDigitalTwin3(digitalTwinId, registryUrl, edr); + LogUtil.printWarning("DIGITAL TWIN:\n" + jsonUtil.toJson(digitalTwin, true)); 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"); @@ -174,11 +182,6 @@ public DigitalTwin3 searchDigitalTwin3(String assetType, String assetId, Integer public DigitalTwin searchDigitalTwin(String assetType, String assetId, Integer position, String registryUrl, DataPlaneEndpoint edr) { try { - LogUtil.printWarning("ASSET TYPE: " + assetType); - LogUtil.printWarning("ASSET ID: " + assetId); - LogUtil.printWarning("POSITION: " + position); - LogUtil.printWarning("REGISTRY URL: " + registryUrl); - LogUtil.printWarning("DATA PLANE END POINT\n" + jsonUtil.toJson(edr, true)); ArrayList digitalTwinIds = this.queryDigitalTwin(assetType, assetId, registryUrl, edr); if (digitalTwinIds == null || digitalTwinIds.size() == 0) { throw new ServiceException(this.getClass().getName() + "." + "searchDigitalTwin", @@ -192,7 +195,6 @@ public DigitalTwin searchDigitalTwin(String assetType, String assetId, Integer p String digitalTwinId = digitalTwinIds.get(position); DigitalTwin digitalTwin = this.getDigitalTwin(digitalTwinId, registryUrl, edr); - LogUtil.printWarning("DIGITAL TWIN:\n" + jsonUtil.toJson(digitalTwin, true)); 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"); @@ -368,15 +370,15 @@ public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin, String seman try { ArrayList subModels = digitalTwin.getSubmodelDescriptors(); if (subModels.size() < 1) { - throw new ServiceException(this.getClass().getName() + "." + "getSubModel3ById", + throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", "No subModel found in digitalTwin!"); } // Search for first subModel with matching idShort, if it fails gives null - SubModel3 subModel = subModels.stream().filter(s -> s.getSemanticId().getKeys().get("Submodel").equalsIgnoreCase(semanticId)).findFirst().orElse(null); + SubModel3 subModel = subModels.stream().filter(s -> s.getSemanticId().getKeys().containsKey(submodelTypeKey) ? s.getSemanticId().getKeys().get(submodelTypeKey).equalsIgnoreCase(semanticId) : false).findFirst().orElse(null); if (subModel == null) { // If the subModel idShort does not exist - throw new ServiceException(this.getClass().getName() + "." + "getSubModel3ById", + throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", "SubModel for SemanticId not found!"); } // Return subModel if found @@ -505,15 +507,22 @@ public AssetSearch decentralDtrSearch(String processId, Search searchBody){ searchBody, dtr ); - LogUtil.printWarning("Decentral DTRTransfer:\n" + jsonUtil.toJson(dtrTransfer, true)); Thread thread = ThreadUtil.runThread(dtrTransfer, dtr.getEndpoint()); thread.join(Duration.ofSeconds(this.dtrConfig.getTimeouts().getTransfer())); + LogUtil.printWarning("Decentral DTRTransfer:\n"); + LogUtil.printWarning("STATUS\n" + jsonUtil.toJson(dtrTransfer.status, true)); + LogUtil.printWarning("TRANSFER\n" + jsonUtil.toJson(dtrTransfer.transfer, true)); + LogUtil.printWarning("DTR\n" + jsonUtil.toJson(dtrTransfer.dtr, true)); + LogUtil.printWarning("ENDPOINT\n" + jsonUtil.toJson(dtrTransfer.endpointId, true)); + LogUtil.printWarning("TRANSFER RESPONSE\n" + jsonUtil.toJson(dtrTransfer.transferResponse, true)); + } // TODO: Wait until transfer is finished and retrieve digital twin ids Thread blockThread = ThreadUtil.runThread(new DigitalTwinTimeout(this.processManager, processId)); try { if(!blockThread.join(Duration.ofSeconds(this.dtrConfig.getTimeouts().getDigitalTwin()))){ LogUtil.printError("Timeout reached while waiting for receiving digital twin!"); + LogUtil.printWarning("STATUS\n" + jsonUtil.toJson(this.processManager.getStatus(processId), true)); return null; }; } catch (InterruptedException e) { @@ -610,6 +619,7 @@ public ArrayList queryDigitalTwin(String assetType, String assetId, Stri public class DecentralDigitalTwinRegistryQueryById implements Runnable { + private final String dppIdShort = "digitalProductPass"; private DataPlaneEndpoint edr; private SubModel3 subModel; private DigitalTwin3 digitalTwin; @@ -634,8 +644,10 @@ public DecentralDigitalTwinRegistryQueryById(Search search, DataPlaneEndpoint ed @Override public void run() { this.setDigitalTwin(searchDigitalTwin3(this.getIdType(), this.getAssetId(), this.getDtIndex(), this.getEdr().getEndpoint(), this.getEdr())); - if (this.getIdShort().equalsIgnoreCase("digitalProductPass")) { - this.setSubModel(searchSubModel3BySemanticId(this.getDigitalTwin(), this.getSemanticId())); + if (this.getIdShort().equalsIgnoreCase(dppIdShort)) { + SubModel3 submodelTest = searchSubModel3BySemanticId(this.getDigitalTwin(), this.getIdShort()); + LogUtil.printWarning("SUBMODEL BY SEMANTIC ID:\n" + jsonUtil.toJson(submodelTest, true)); + this.setSubModel(searchSubModel3ById(this.getDigitalTwin(), this.getIdShort())); } else { this.setSubModel(searchSubModel3ById(this.getDigitalTwin(), this.getIdShort())); } diff --git a/consumer-backend/productpass/src/main/resources/application.yml b/consumer-backend/productpass/src/main/resources/application.yml index c1c949fda..8fc366cf9 100644 --- a/consumer-backend/productpass/src/main/resources/application.yml +++ b/consumer-backend/productpass/src/main/resources/application.yml @@ -72,10 +72,10 @@ configuration: digitalTwin: "/shell-descriptors" subModel: "/submodel-descriptors" timeouts: - search: 100 - negotiation: 100 - transfer: 100 - digitalTwin: 120 + search: 10 + negotiation: 40 + transfer: 10 + digitalTwin: 20 temporaryStorage: true discovery: From 037ac6885962050cc3c4d9e36d0576c9a68fb334 Mon Sep 17 00:00:00 2001 From: Parracho Date: Wed, 20 Sep 2023 11:27:20 +0100 Subject: [PATCH 03/18] feat: fix typo on Submmodel3 class in jsonProperty name --- .../tractusx/productpass/models/dtregistry/SubModel3.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 50c9e1eb3..1559b8595 100644 --- 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 @@ -96,7 +96,7 @@ public void setEndpoints(ArrayList endpoints) { public static class SemanticId { @JsonProperty("type") String type; - @JsonProperty("idShort") + @JsonProperty("keys") Map keys; public SemanticId(String type, Map keys) { From 6b81698509e02122811e21078802c8d529564038 Mon Sep 17 00:00:00 2001 From: Mathias Brunkow Moser Date: Thu, 28 Sep 2023 16:34:43 +0200 Subject: [PATCH 04/18] fix: fixed multiple bpn + edc endpoints search in discovery service --- .../controllers/api/ContractController.java | 14 +- .../productpass/services/CatenaXService.java | 164 +++++++++++++----- .../productpass/services/VaultService.java | 4 +- 3 files changed, 131 insertions(+), 51 deletions(-) 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 bdd6db917..1547b94b3 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 @@ -62,6 +62,7 @@ import org.springframework.web.bind.annotation.*; import utils.*; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -120,22 +121,25 @@ public Response create(@Valid @RequestBody DiscoverySearch searchBody) { return httpUtil.buildResponse(response, httpResponse); } - BpnDiscovery bpnDiscovery = null; + List bpnDiscoveries = null; try { - bpnDiscovery = catenaXService.getBpnDiscovery(searchBody.getId(), searchBody.getType()); + bpnDiscoveries = catenaXService.getBpnDiscovery(searchBody.getId(), searchBody.getType()); } catch (Exception e) { response.message = "Failed to get the bpn number from the discovery service"; response.status = 404; response.statusText = "Not Found"; return httpUtil.buildResponse(response, httpResponse); } - if (bpnDiscovery == null) { + if (bpnDiscoveries == null) { response.message = "Failed to get the bpn number from the discovery service, discovery response is null"; response.status = 404; response.statusText = "Not Found"; return httpUtil.buildResponse(response, httpResponse); } - List bpnList = bpnDiscovery.getBpnNumbers(); + List bpnList = new ArrayList<>(); + for(BpnDiscovery bpnDiscovery : bpnDiscoveries){ + bpnList.addAll(bpnDiscovery.getBpnNumbers()); + } String processId = processManager.initProcess(); ConcurrentHashMap> dataModel = null; List edcEndpointBinded = null; @@ -148,7 +152,7 @@ public Response create(@Valid @RequestBody DiscoverySearch searchBody) { } // This checks if the cache is deactivated or if the bns are not in thedataModel, if one of them is not in the data model then we need to check for them if(!dtrConfig.getTemporaryStorage() || ((dataModel==null) || !jsonUtil.checkJsonKeys(dataModel, bpnList, ".", false))){ - List edcEndpoints = catenaXService.getEdcDiscovery(bpnDiscovery.getBpnNumbers()); + List edcEndpoints = catenaXService.getEdcDiscovery(bpnList); try { edcEndpointBinded = (List) jsonUtil.bindReferenceType(edcEndpoints, new TypeReference>() {}); } catch (Exception e) { diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/CatenaXService.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/CatenaXService.java index 8a1a6f597..598276bf2 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/CatenaXService.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/CatenaXService.java @@ -27,6 +27,7 @@ import com.fasterxml.jackson.databind.JsonNode; +import org.apache.juli.logging.Log; import org.eclipse.tractusx.productpass.config.DiscoveryConfig; import org.eclipse.tractusx.productpass.config.DtrConfig; import org.eclipse.tractusx.productpass.exceptions.ServiceException; @@ -48,6 +49,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Stream; @Service public class CatenaXService extends BaseService { @@ -147,6 +149,15 @@ public Discovery addEndpoint(String key){ } } + public List getDiscoveryEndpoints(Discovery discovery, String key) { + List endpoints = discovery.getEndpoints(); + List filteredEndpoints = endpoints.stream().filter(endpoint -> endpoint.getType().equals(key)).toList(); + if(filteredEndpoints.isEmpty()){ + throw new ServiceException(this.getClass().getName() + "." + "updateDiscovery", + "The endpoint ["+key+"] is not available in the discovery endpoint ["+this.discoveryEndpoint +"]"); + } + return filteredEndpoints; + } public Discovery.Endpoint getDiscoveryEndpoint(Discovery discovery, String key) { @@ -180,16 +191,29 @@ public Boolean updateDefaultDiscovery(Discovery discovery){ return false; } // Get discovery endpoints by key - Discovery.Endpoint bpnEndpoint = this.getDiscoveryEndpoint(discovery, this.discoveryConfig.getBpn().getKey()); - Discovery.Endpoint edcEndpoint = this.getDiscoveryEndpoint(discovery, this.discoveryConfig.getEdc().getKey()); - return this.updateDefaultDiscoveryFile(bpnEndpoint, edcEndpoint); // Create default discovery file + List bpnEndpoints = this.getDiscoveryEndpoints(discovery, this.discoveryConfig.getBpn().getKey()); + List edcEndpoints = this.getDiscoveryEndpoints(discovery, this.discoveryConfig.getEdc().getKey()); + return this.updateDefaultDiscoveryFile(bpnEndpoints, edcEndpoints); // Create default discovery file }catch(Exception e){ throw new ServiceException(this.getClass().getName() + "." + "updateDiscovery", e, "Failed to update the discovery endpoints"); } } - + public Boolean updateEndpointFile(List endpoints, String key){ + try { + boolean returnState; + for(Discovery.Endpoint endpoint: endpoints) { + returnState = this.updateEndpointFile(endpoint, key); + if(!returnState){ + return false; + } + } + return true; + }catch (Exception e){ + throw new ServiceException(this.getClass().getName(), e, "It was not possible to create/update discovery endpoints for key [" + key + "]"); + } + } public Boolean updateEndpointFile(Discovery.Endpoint endpoint, String key){ try { String address = endpoint.getEndpointAddress(); @@ -197,17 +221,39 @@ public Boolean updateEndpointFile(Discovery.Endpoint endpoint, String key){ LogUtil.printError("The endpoint for key ["+key+"] address is not defined!"); return false; } - - if(!this.vaultService.setLocalSecret("discovery."+key, address)){ - LogUtil.printError("Failed to create/update discovery key ["+key+"] endpoint!"); - return false; - }; + List endpoints = new ArrayList(); + if(this.vaultService.secretExists("discovery."+key)){ + endpoints = (List) this.vaultService.getLocalSecret("discovery."+key); + } + if(!endpoints.contains(address)){ + endpoints.add(address); + if(!this.vaultService.setLocalSecret("discovery."+key, endpoints)){ + LogUtil.printError("Failed to create/update discovery key ["+key+"] endpoint!"); + return false; + }; + } return true; }catch (Exception e){ throw new ServiceException(this.getClass().getName(), e, "It was not possible to create/update discovery endpoints for key [" + key + "]"); } } - + public Boolean updateDefaultDiscoveryFile(List bpnEndpoints, List edcEndpoints){ + try { + Boolean bpnResponse = this.updateEndpointFile(bpnEndpoints, this.discoveryConfig.getBpn().getKey()); + Boolean edcResponse = this.updateEndpointFile(edcEndpoints, "edc"); + if(!bpnResponse){ + LogUtil.printError("Something went wrong when getting the bpn endpoint"); + return false; + } + if(!edcResponse){ + LogUtil.printError("Something went wrong when getting the edc endpoint"); + return false; + } + return true; + }catch (Exception e){ + throw new ServiceException(this.getClass().getName(), e, "It was not possible to create/update main discovery endpoints"); + } + } public Boolean updateDefaultDiscoveryFile(Discovery.Endpoint bpnEndpoint, Discovery.Endpoint edcEndpoint){ try { Boolean bpnResponse = this.updateEndpointFile(bpnEndpoint, this.discoveryConfig.getBpn().getKey()); @@ -260,24 +306,40 @@ public Discovery getDiscoveryEndpoints(List endpoints) { public List getEdcDiscovery(List bpns) { try { this.checkEmptyVariables(); - String edcEndpoint = null; + List edcEndpoints = null; // Check if the variable edc endpoint is correct try { - edcEndpoint = (String) this.vaultService.getLocalSecret("discovery.edc"); + edcEndpoints = (List) this.vaultService.getLocalSecret("discovery.edc"); } catch (Exception e) { throw new ServiceException(this.getClass().getName() + ".getEdcDiscovery", e, "It was not possible to retrieve the edc discovery endpoint from the vault"); } - if (edcEndpoint == null) { + if (edcEndpoints == null) { throw new ServiceException(this.getClass().getName() + ".getEdcDiscovery", "The edc discovery endpoint is empty!"); } + List edcDiscoveryResponses = new ArrayList<>(); + for(String edcEndpoint : edcEndpoints) { + + // Add the technical token + HttpHeaders headers = httpUtil.getHeadersWithToken(this.authService.getToken().getAccessToken()); + headers.add("Content-Type", "application/json"); + try{ + ResponseEntity response = httpUtil.doPost(edcEndpoint, JsonNode.class, headers, httpUtil.getParams(), bpns, false, false); + JsonNode result = (JsonNode) response.getBody(); + List edcDiscoveryResponse = (List) jsonUtil.bindJsonNode(result, List.class); + if(edcDiscoveryResponse.isEmpty()) { + LogUtil.printWarning("List of EDCs not found in EDC Discovery Url: ["+edcEndpoint+"]"); + continue; + } + edcDiscoveryResponses.addAll(edcDiscoveryResponse); + }catch (Exception e){ + LogUtil.printException(e, "It was not possible to get the edc endpoints from the EDC Discovery Service endpoint: ["+edcEndpoint+"]"); + } - // Add the technical token - HttpHeaders headers = httpUtil.getHeadersWithToken(this.authService.getToken().getAccessToken()); - headers.add("Content-Type", "application/json"); - - ResponseEntity response = httpUtil.doPost(edcEndpoint, JsonNode.class, headers, httpUtil.getParams(), bpns, false, false); - JsonNode result = (JsonNode) response.getBody(); - return (List) jsonUtil.bindJsonNode(result, List.class); + } + if(edcDiscoveryResponses.isEmpty()){ + return null; + } + return edcDiscoveryResponses; } catch (Exception e) { throw new ServiceException(this.getClass().getName() + "." + "getEdcDiscovery", e, @@ -285,10 +347,9 @@ public List getEdcDiscovery(List bpns) { } } - public BpnDiscovery getBpnDiscovery(String id, String type){ + public List getBpnDiscovery(String id, String type){ try { this.checkEmptyVariables(); - String bpnEndpoint = null; // Check if the discovery type id exists in the endpoint from the edc discovery if(!this.vaultService.secretExists("discovery."+type)){ Discovery discovery = this.addEndpoint(type); @@ -296,34 +357,49 @@ public BpnDiscovery getBpnDiscovery(String id, String type){ throw new ServiceException(this.getClass().getName() + ".getBpnDiscovery", "The discovery finder service failed"); } } - + List bpnEndpoints = new ArrayList<>(); try { - bpnEndpoint = (String) this.vaultService.getLocalSecret("discovery."+type); + bpnEndpoints = (List) this.vaultService.getLocalSecret("discovery."+type); }catch (Exception e) { throw new ServiceException(this.getClass().getName() + ".getBpnDiscovery", e, "It was not possible to retrieve the bpn discovery endpoint from the vault"); } - if(bpnEndpoint == null){ + if(bpnEndpoints == null){ throw new ServiceException(this.getClass().getName() + ".getBpnDiscovery", "The bpn discovery endpoint is empty!"); } - - String searchEndpoint = bpnEndpoint + this.discoveryConfig.getBpn().getSearchPath(); - - - // Set request body - Object body = Map.of( - "searchFilter",List.of( - Map.of( - "type", type, "keys", List.of(id) - ) - ) - ); - - HttpHeaders headers = httpUtil.getHeadersWithToken(this.authService.getToken().getAccessToken()); - headers.add("Content-Type", "application/json"); - - ResponseEntity response = httpUtil.doPost(searchEndpoint, JsonNode.class, headers, httpUtil.getParams(), body, false, false); - JsonNode result = (JsonNode) response.getBody(); - return (BpnDiscovery) jsonUtil.bindJsonNode(result, BpnDiscovery.class); + List bpnDiscoveryResponse = new ArrayList<>(); + for(String bpnEndpoint : bpnEndpoints) { + + String searchEndpoint = bpnEndpoint + this.discoveryConfig.getBpn().getSearchPath(); + + + // Set request body + Object body = Map.of( + "searchFilter", List.of( + Map.of( + "type", type, "keys", List.of(id) + ) + ) + ); + + HttpHeaders headers = httpUtil.getHeadersWithToken(this.authService.getToken().getAccessToken()); + headers.add("Content-Type", "application/json"); + try{ + ResponseEntity response = httpUtil.doPost(searchEndpoint, JsonNode.class, headers, httpUtil.getParams(), body, false, false); + JsonNode result = (JsonNode) response.getBody(); + BpnDiscovery bpnDiscovery = (BpnDiscovery) jsonUtil.bindJsonNode(result, BpnDiscovery.class); + if(bpnDiscovery == null){ + LogUtil.printWarning("Response from search endpoint: [" + searchEndpoint + "]"); + continue; + } + bpnDiscoveryResponse.add(bpnDiscovery); + }catch (Exception e){ + LogUtil.printException(e, "BPN Number not found for ["+searchEndpoint+"] and keyType ["+type+"]!"); + } + } + if(bpnDiscoveryResponse.isEmpty()){ + return null; + } + return bpnDiscoveryResponse; } catch (Exception e) { throw new ServiceException(this.getClass().getName() + "." + "getBpnDiscovery", e, diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/VaultService.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/VaultService.java index 2e9b4d961..309e7e9c3 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/VaultService.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/VaultService.java @@ -114,11 +114,11 @@ public Boolean secretExists(String localSecretPath){ public Object getLocalSecret(String localSecretPath) { try { - String secret = null; + Object secret = null; String filePath = this.createLocalVaultFile(true); Map content = yamlUtil.readFile(filePath); try { - secret = (String) jsonUtil.getValue(content,localSecretPath, ".",null); + secret = jsonUtil.getValue(content,localSecretPath, ".",null); }catch (Exception e){ LogUtil.printException(e, "["+this.getClass().getName()+"."+"getLocalSecret] " + "There was an error while searching the secret ["+localSecretPath+"] in file!"); } From 4e979602cfc6f27073ac660e8323ae990e84c326 Mon Sep 17 00:00:00 2001 From: Parracho Date: Fri, 6 Oct 2023 14:00:08 +0100 Subject: [PATCH 05/18] feat: fixed the semanticId model in the Submodel3 class --- .../models/dtregistry/SubModel3.java | 35 ++++++++++++++++--- .../productpass/services/AasService.java | 6 ++-- 2 files changed, 33 insertions(+), 8 deletions(-) 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 index ae5982f5a..d0f36dcdd 100644 --- 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 @@ -29,7 +29,6 @@ import com.fasterxml.jackson.databind.JsonNode; import java.util.ArrayList; -import java.util.Map; @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_NULL) @@ -110,13 +109,15 @@ public void setEndpoints(ArrayList endpoints) { this.endpoints = endpoints; } + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_NULL) public static class SemanticId { @JsonProperty("type") String type; @JsonProperty("keys") - Map keys; + ArrayList keys; - public SemanticId(String type, Map keys) { + public SemanticId(String type, ArrayList keys) { this.type = type; this.keys = keys; } @@ -132,13 +133,37 @@ public void setType(String type) { this.type = type; } - public Map getKeys() { + public ArrayList getKeys() { return keys; } - public void setKeys(Map keys) { + 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) + public class Key { + + /** ATTRIBUTES **/ + @JsonProperty("type") + String type; + @JsonProperty("value") + String value; + + /** CONSTRUCTOR(S) **/ + public Key() {} + + /** 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; } + } } public Object getSupplementalSemanticId() { return supplementalSemanticId; 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 d1c8f773b..20173c76b 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 @@ -373,11 +373,11 @@ public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin, String seman throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", "No subModel found in digitalTwin!"); } - // Search for first subModel with matching idShort, if it fails gives null - SubModel3 subModel = subModels.stream().filter(s -> s.getSemanticId().getKeys().containsKey(submodelTypeKey) ? s.getSemanticId().getKeys().get(submodelTypeKey).equalsIgnoreCase(semanticId) : false).findFirst().orElse(null); + // Search for first subModel with matching semanticId, if it fails gives null + SubModel3 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) { - // If the subModel idShort does not exist + // If the subModel semanticId does not exist throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", "SubModel for SemanticId not found!"); } From 1c305f1b5fae21d819451f490952614889a75945 Mon Sep 17 00:00:00 2001 From: Mathias Brunkow Moser Date: Fri, 6 Oct 2023 16:14:45 +0200 Subject: [PATCH 06/18] fix: added missing contructor and the missing static reference --- .../tractusx/productpass/models/dtregistry/SubModel3.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 index d0f36dcdd..32a389a08 100644 --- 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 @@ -147,7 +147,7 @@ public void setKeys(ArrayList keys) { **/ @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_NULL) - public class Key { + static public class Key { /** ATTRIBUTES **/ @JsonProperty("type") @@ -158,6 +158,11 @@ public class Key { /** 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; } From 3ccc69bb06e48fffc75c035c9f236265cb0421a2 Mon Sep 17 00:00:00 2001 From: Mathias Brunkow Moser Date: Fri, 6 Oct 2023 16:39:58 +0200 Subject: [PATCH 07/18] fix: fixed set is digital product pass --- .../eclipse/tractusx/productpass/models/manager/Process.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Process.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Process.java index fd828dec5..6a30defd1 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Process.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Process.java @@ -136,6 +136,6 @@ public boolean getIsDigitalProductPass() { } public void setIsDigitalProductPass(boolean isDigitalProductPass) { - isDigitalProductPass = isDigitalProductPass; + this.isDigitalProductPass = isDigitalProductPass; } } From 85158b679236aa5d60228cee4c635f729fda3c9e Mon Sep 17 00:00:00 2001 From: Mathias Brunkow Moser Date: Fri, 6 Oct 2023 16:53:37 +0200 Subject: [PATCH 08/18] fix: removed boolean that specifies if is DPP --- .../productpass/http/controllers/api/ApiController.java | 8 +------- .../http/controllers/api/ContractController.java | 4 ---- .../tractusx/productpass/managers/ProcessManager.java | 1 + .../tractusx/productpass/models/manager/Process.java | 9 --------- 4 files changed, 2 insertions(+), 20 deletions(-) diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java index 78f60d3a4..848d6f683 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java @@ -172,13 +172,7 @@ public Response getPassport(@Valid @RequestBody TokenRequest tokenRequestBody) { return httpUtil.buildResponse(response, httpResponse); } - Passport passport; - if (process.getIsDigitalProductPass()) { - passport = processManager.loadDigitalProductPassport(processId); - } else { - passport = processManager.loadPassport(processId); - } - + Passport passport = processManager.loadDigitalProductPassport(processId); if (passport == null) { response = httpUtil.getNotFound("Failed to load passport!"); 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 1547b94b3..b1db2e3cc 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 @@ -229,16 +229,13 @@ public Response search(@Valid @RequestBody Search searchBody) { } List versions; - boolean isDigitalProductPass; 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))); - isDigitalProductPass = true; } else { versions = passportConfig.getBatteryPass().getVersions(); searchBody.setSemanticId(passportConfig.getBatteryPass().getFullSemanticId(versions.get(0))); - isDigitalProductPass = false; } // Initialize variables @@ -266,7 +263,6 @@ public Response search(@Valid @RequestBody Search searchBody) { return httpUtil.buildResponse(response, httpResponse); } process = processManager.createProcess(processId, httpRequest); - process.setIsDigitalProductPass(isDigitalProductPass); Status status = processManager.getStatus(processId); if (status == null) { response = httpUtil.getBadRequest("The status is not available!"); 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 1e7ee17a4..baf056242 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 @@ -282,6 +282,7 @@ public Process createProcess(HttpServletRequest httpRequest, String processId, S return process; } + public String newStatusFile(String processId, String connectorAddress, Long created){ try { String path = this.getProcessFilePath(processId, this.metaFileName); diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Process.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Process.java index 6a30defd1..d161f736b 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Process.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Process.java @@ -46,8 +46,6 @@ public class Process { @JsonProperty("thread") public Thread thread; - @JsonProperty("isDigitalProductPass") - private boolean isDigitalProductPass; public Process(String id, String state, Thread thread) { this.id = id; @@ -131,11 +129,4 @@ public void setCreated(Long created) { this.created = created; } - public boolean getIsDigitalProductPass() { - return isDigitalProductPass; - } - - public void setIsDigitalProductPass(boolean isDigitalProductPass) { - this.isDigitalProductPass = isDigitalProductPass; - } } From d585e1e97c93545109f056115ca350763a621682 Mon Sep 17 00:00:00 2001 From: Mathias Brunkow Moser Date: Fri, 6 Oct 2023 17:06:20 +0200 Subject: [PATCH 09/18] fix: added digital product pass when receiving the data --- .../tractusx/productpass/services/DataPlaneService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataPlaneService.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataPlaneService.java index cba91bb2d..affad373f 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataPlaneService.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataPlaneService.java @@ -28,6 +28,7 @@ import org.eclipse.tractusx.productpass.models.auth.JwtToken; import org.eclipse.tractusx.productpass.models.dtregistry.DigitalTwin; import org.eclipse.tractusx.productpass.models.edc.DataPlaneEndpoint; +import org.eclipse.tractusx.productpass.models.passports.DigitalProductPassport; import org.eclipse.tractusx.productpass.models.passports.Passport; import org.eclipse.tractusx.productpass.models.passports.PassportV3; import org.eclipse.tractusx.productpass.models.service.BaseService; @@ -69,7 +70,7 @@ public Object getTransferData(DataPlaneEndpoint endpointData) { } public Passport getPassport(DataPlaneEndpoint endpointData) { try { - return (PassportV3) jsonUtil.bindObject(this.getTransferData(endpointData), PassportV3.class); + return (DigitalProductPassport) jsonUtil.bindObject(this.getTransferData(endpointData), DigitalProductPassport.class); }catch (Exception e){ throw new ServiceException(this.getClass().getName()+"."+"getPassport", e, From 0e8b20c0c01741f4cfe98008e9b8eb6d19b48f35 Mon Sep 17 00:00:00 2001 From: Mathias Brunkow Moser Date: Fri, 6 Oct 2023 17:16:51 +0200 Subject: [PATCH 10/18] fix: fixed metadata and aditional information as jsonNode --- .../passports/DigitalProductPassport.java | 110 +++++++++++++++++- 1 file changed, 107 insertions(+), 3 deletions(-) diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/DigitalProductPassport.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/DigitalProductPassport.java index 8ac5eb3a7..36df7050a 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/DigitalProductPassport.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/DigitalProductPassport.java @@ -11,12 +11,11 @@ public class DigitalProductPassport extends Passport { @JsonProperty("typology") JsonNode typology; @JsonProperty("metadata") - String metadata; + JsonNode metadata; @JsonProperty("characteristics") JsonNode characteristics; @JsonProperty("commercial") JsonNode commercial; - @JsonProperty("identification") JsonNode identification; @JsonProperty("sources") @@ -24,9 +23,114 @@ public class DigitalProductPassport extends Passport { @JsonProperty("handling") JsonNode handling; @JsonProperty("additionalData") - String additionalData; + JsonNode additionalData; @JsonProperty("sustainability") JsonNode sustainability; @JsonProperty("operation") JsonNode operation; + + public DigitalProductPassport(JsonNode serialization, JsonNode typology, JsonNode metadata, JsonNode characteristics, JsonNode commercial, JsonNode identification, JsonNode sources, JsonNode handling, JsonNode additionalData, JsonNode sustainability, JsonNode operation) { + this.serialization = serialization; + this.typology = typology; + this.metadata = metadata; + this.characteristics = characteristics; + this.commercial = commercial; + this.identification = identification; + this.sources = sources; + this.handling = handling; + this.additionalData = additionalData; + this.sustainability = sustainability; + this.operation = operation; + } + + public DigitalProductPassport() { + } + + public JsonNode getSerialization() { + return serialization; + } + + public void setSerialization(JsonNode serialization) { + this.serialization = serialization; + } + + public JsonNode getTypology() { + return typology; + } + + public void setTypology(JsonNode typology) { + this.typology = typology; + } + + public JsonNode getMetadata() { + return metadata; + } + + public void setMetadata(JsonNode metadata) { + this.metadata = metadata; + } + + public JsonNode getCharacteristics() { + return characteristics; + } + + public void setCharacteristics(JsonNode characteristics) { + this.characteristics = characteristics; + } + + public JsonNode getCommercial() { + return commercial; + } + + public void setCommercial(JsonNode commercial) { + this.commercial = commercial; + } + + public JsonNode getIdentification() { + return identification; + } + + public void setIdentification(JsonNode identification) { + this.identification = identification; + } + + public JsonNode getSources() { + return sources; + } + + public void setSources(JsonNode sources) { + this.sources = sources; + } + + public JsonNode getHandling() { + return handling; + } + + public void setHandling(JsonNode handling) { + this.handling = handling; + } + + public JsonNode getAdditionalData() { + return additionalData; + } + + public void setAdditionalData(JsonNode additionalData) { + this.additionalData = additionalData; + } + + public JsonNode getSustainability() { + return sustainability; + } + + public void setSustainability(JsonNode sustainability) { + this.sustainability = sustainability; + } + + public JsonNode getOperation() { + return operation; + } + + public void setOperation(JsonNode operation) { + this.operation = operation; + } } From 3a2a64f664551ebb5b2f06319fe1e38d2fe55b9a Mon Sep 17 00:00:00 2001 From: Parracho Date: Tue, 10 Oct 2023 08:31:21 +0100 Subject: [PATCH 11/18] feat: change code to search for both digital product and battery passes --- .../productpass/config/PassportConfig.java | 72 ++---------- .../http/controllers/api/ApiController.java | 1 - .../controllers/api/ContractController.java | 12 +- .../productpass/models/manager/Status.java | 2 + .../passports/DigitalProductPassport.java | 105 ------------------ .../productpass/services/AasService.java | 44 +++----- .../src/main/resources/application.yml | 15 +-- 7 files changed, 33 insertions(+), 218 deletions(-) diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/PassportConfig.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/PassportConfig.java index b9edce975..c2e0e2386 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/PassportConfig.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/config/PassportConfig.java @@ -32,77 +32,21 @@ @ConfigurationProperties(prefix="configuration.passport") public class PassportConfig { - private BatteryPass batteryPass; - private DigitalProductPass digitalProductPass; + private List aspects; - public BatteryPass getBatteryPass() { - return batteryPass; + public PassportConfig() { } - public void setBatteryPass(BatteryPass batteryPass) { - this.batteryPass = batteryPass; + public PassportConfig(List aspects) { + this.aspects = aspects; } - public DigitalProductPass getDigitalProductPass() { - return digitalProductPass; + public List getAspects() { + return aspects; } - - public void setDigitalProductPass(DigitalProductPass digitalProductPass) { - this.digitalProductPass = digitalProductPass; - } - - - public static class BatteryPass extends DigitalProductPass { + public void setAspects(List aspects) { + this.aspects = aspects; } - public static class DigitalProductPass { - private List versions; - private String semanticId; - private String aspectId; - private String fullSemanticId; - - public DigitalProductPass(List versions, String semanticId, String aspectId) { - this.versions = versions; - this.semanticId = semanticId; - this.aspectId = aspectId; - } - - public DigitalProductPass() { - } - - public List getVersions() { - return this.versions; - } - - public void setVersions(List versions) { - this.versions = versions; - } - - public String getSemanticId() { - return semanticId; - } - - public void setSemanticId(String semanticId) { - this.semanticId = semanticId; - } - - public String getAspectId() { - return aspectId; - } - - public void setAspectId(String aspectId) { - this.aspectId = aspectId; - } - - public String getFullSemanticId(String version) { - if (this.fullSemanticId == null) { - this.fullSemanticId = semanticId + ":" + versions.stream().filter(v -> v.equalsIgnoreCase(version)).findFirst().get() + "#" + aspectId; - } - return fullSemanticId; - } - private void setFullSemanticId(String semanticId, List versions, String aspectId) { - - } - } } diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java index 848d6f683..19a137fe9 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java @@ -173,7 +173,6 @@ public Response getPassport(@Valid @RequestBody TokenRequest tokenRequestBody) { } Passport passport = processManager.loadDigitalProductPassport(processId); - if (passport == null) { response = httpUtil.getNotFound("Failed to load passport!"); return httpUtil.buildResponse(response, httpResponse); 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 b1db2e3cc..df6751f96 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 @@ -222,27 +222,21 @@ public Response search(@Valid @RequestBody Search searchBody) { return httpUtil.buildResponse(response, httpResponse); } try { - List mandatoryParams = List.of("id", "version"); + List mandatoryParams = List.of("id"); if (!jsonUtil.checkJsonKeys(searchBody, mandatoryParams, ".", false)) { response = httpUtil.getBadRequest("One or all the mandatory parameters " + mandatoryParams + " are missing"); return httpUtil.buildResponse(response, httpResponse); } List versions; - if (searchBody.getIdShort().equalsIgnoreCase("digitalProductPass")) { + /*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))); } else { versions = passportConfig.getBatteryPass().getVersions(); searchBody.setSemanticId(passportConfig.getBatteryPass().getFullSemanticId(versions.get(0))); - } - - // Initialize variables - // Check if version is available - if (!versions.contains(searchBody.getVersion())) { - return httpUtil.buildResponse(httpUtil.getForbiddenResponse("This passport version is not available at the moment!"), httpResponse); - } + }*/ Process process = null; AssetSearch assetSearch = null; diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Status.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Status.java index 95f8a9138..f291a7bf9 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Status.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Status.java @@ -27,6 +27,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import org.springframework.boot.context.properties.bind.DefaultValue; import utils.DateTimeUtil; import java.util.HashMap; @@ -57,6 +58,7 @@ public class Status { @JsonProperty("history") public Map history; + public Status(String id, String status, Long created, Long modified, String endpoint, Map history) { this.id = id; this.status = status; diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/DigitalProductPassport.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/DigitalProductPassport.java index 36df7050a..81eb493ee 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/DigitalProductPassport.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/DigitalProductPassport.java @@ -28,109 +28,4 @@ public class DigitalProductPassport extends Passport { JsonNode sustainability; @JsonProperty("operation") JsonNode operation; - - public DigitalProductPassport(JsonNode serialization, JsonNode typology, JsonNode metadata, JsonNode characteristics, JsonNode commercial, JsonNode identification, JsonNode sources, JsonNode handling, JsonNode additionalData, JsonNode sustainability, JsonNode operation) { - this.serialization = serialization; - this.typology = typology; - this.metadata = metadata; - this.characteristics = characteristics; - this.commercial = commercial; - this.identification = identification; - this.sources = sources; - this.handling = handling; - this.additionalData = additionalData; - this.sustainability = sustainability; - this.operation = operation; - } - - public DigitalProductPassport() { - } - - public JsonNode getSerialization() { - return serialization; - } - - public void setSerialization(JsonNode serialization) { - this.serialization = serialization; - } - - public JsonNode getTypology() { - return typology; - } - - public void setTypology(JsonNode typology) { - this.typology = typology; - } - - public JsonNode getMetadata() { - return metadata; - } - - public void setMetadata(JsonNode metadata) { - this.metadata = metadata; - } - - public JsonNode getCharacteristics() { - return characteristics; - } - - public void setCharacteristics(JsonNode characteristics) { - this.characteristics = characteristics; - } - - public JsonNode getCommercial() { - return commercial; - } - - public void setCommercial(JsonNode commercial) { - this.commercial = commercial; - } - - public JsonNode getIdentification() { - return identification; - } - - public void setIdentification(JsonNode identification) { - this.identification = identification; - } - - public JsonNode getSources() { - return sources; - } - - public void setSources(JsonNode sources) { - this.sources = sources; - } - - public JsonNode getHandling() { - return handling; - } - - public void setHandling(JsonNode handling) { - this.handling = handling; - } - - public JsonNode getAdditionalData() { - return additionalData; - } - - public void setAdditionalData(JsonNode additionalData) { - this.additionalData = additionalData; - } - - public JsonNode getSustainability() { - return sustainability; - } - - public void setSustainability(JsonNode sustainability) { - this.sustainability = sustainability; - } - - public JsonNode getOperation() { - return operation; - } - - public void setOperation(JsonNode operation) { - this.operation = operation; - } } 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 20173c76b..25ca70f41 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 @@ -28,6 +28,7 @@ import jakarta.servlet.http.HttpServletRequest; import org.apache.juli.logging.Log; 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; @@ -82,8 +83,10 @@ public class AasService extends BaseService { private DataTransferService dataService; + private PassportConfig passportConfig; + @Autowired - public AasService(Environment env, HttpUtil httpUtil, JsonUtil jsonUtil, AuthenticationService authService, DtrConfig dtrConfig, DtrSearchManager dtrSearchManager, ProcessManager processManager, DataTransferService dataService) throws ServiceInitializationException { + public AasService(Environment env, HttpUtil httpUtil, JsonUtil jsonUtil, AuthenticationService authService, DtrConfig dtrConfig, DtrSearchManager dtrSearchManager, ProcessManager processManager, DataTransferService dataService, PassportConfig passportConfig) throws ServiceInitializationException { this.httpUtil = httpUtil; this.jsonUtil = jsonUtil; this.authService = authService; @@ -93,6 +96,7 @@ public AasService(Environment env, HttpUtil httpUtil, JsonUtil jsonUtil, Authent this.dataService = dataService; this.init(env); this.checkEmptyVariables(); + this.passportConfig = passportConfig; } public void init(Environment env) { @@ -148,11 +152,6 @@ public SubModel searchSubModelInDigitalTwinByIndex(DigitalTwin digitalTwin, Inte } public DigitalTwin3 searchDigitalTwin3(String assetType, String assetId, Integer position, String registryUrl, DataPlaneEndpoint edr) { try { - LogUtil.printWarning("ASSET TYPE: " + assetType); - LogUtil.printWarning("ASSET ID: " + assetId); - LogUtil.printWarning("POSITION: " + position); - LogUtil.printWarning("REGISTRY URL: " + registryUrl); - LogUtil.printWarning("DATA PLANE END POINT\n" + jsonUtil.toJson(edr, true)); ArrayList digitalTwinIds = this.queryDigitalTwin(assetType, assetId, registryUrl, edr); LogUtil.printWarning("DIGITAL TWINS ARRAY SIZE: " + digitalTwinIds.size()); if (digitalTwinIds == null || digitalTwinIds.size() == 0) { @@ -230,9 +229,9 @@ public SubModel3 searchSubModel3ById(DigitalTwin3 digitalTwin, String idShort) { } } - public SubModel3 searchSubModel3BySemanticId(DigitalTwin3 digitalTwin, String semanticId) { + public SubModel3 searchSubModel3BySemanticId(DigitalTwin3 digitalTwin) { try { - SubModel3 subModel = this.getSubModel3BySemanticId(digitalTwin, semanticId); + SubModel3 subModel = this.getSubModel3BySemanticId(digitalTwin); LogUtil.printWarning("SUBMODEL3:\n" + jsonUtil.toJson(subModel, true)); if (subModel == null) { throw new ServiceException(this.getClass().getName() + "." + "searchSubModel3BySemanticId", @@ -366,15 +365,21 @@ public SubModel3 getSubModel3ById(DigitalTwin3 digitalTwin, String idShort) { } } - public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin, String semanticId) { + public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin) { try { ArrayList subModels = digitalTwin.getSubmodelDescriptors(); if (subModels.size() < 1) { throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", "No subModel found in digitalTwin!"); } + SubModel3 subModel = null; // Search for first subModel with matching semanticId, if it fails gives null - SubModel3 subModel = subModels.stream().filter(s -> s.getSemanticId().getKeys().stream().filter(k -> k.getType().equalsIgnoreCase(submodelTypeKey) && k.getValue().equalsIgnoreCase(semanticId)) != null).findFirst().orElse(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); + if (subModel != null) { + break; + } + } if (subModel == null) { // If the subModel semanticId does not exist @@ -495,7 +500,6 @@ public AssetSearch decentralDtrSearch(String processId, Search searchBody){ try { Status status = this.processManager.getStatus(processId); SearchStatus searchStatus = this.processManager.setSearch(processId, searchBody); - LogUtil.printWarning("Decentral SearchStatus:\n" + jsonUtil.toJson(searchStatus, true)); for (String endpointId : searchStatus.getDtrs().keySet()) { Dtr dtr = searchStatus.getDtr(endpointId); LogUtil.printWarning("EndpointId: " + endpointId); @@ -509,27 +513,18 @@ public AssetSearch decentralDtrSearch(String processId, Search searchBody){ ); Thread thread = ThreadUtil.runThread(dtrTransfer, dtr.getEndpoint()); thread.join(Duration.ofSeconds(this.dtrConfig.getTimeouts().getTransfer())); - LogUtil.printWarning("Decentral DTRTransfer:\n"); - LogUtil.printWarning("STATUS\n" + jsonUtil.toJson(dtrTransfer.status, true)); - LogUtil.printWarning("TRANSFER\n" + jsonUtil.toJson(dtrTransfer.transfer, true)); - LogUtil.printWarning("DTR\n" + jsonUtil.toJson(dtrTransfer.dtr, true)); - LogUtil.printWarning("ENDPOINT\n" + jsonUtil.toJson(dtrTransfer.endpointId, true)); - LogUtil.printWarning("TRANSFER RESPONSE\n" + jsonUtil.toJson(dtrTransfer.transferResponse, true)); - } // TODO: Wait until transfer is finished and retrieve digital twin ids Thread blockThread = ThreadUtil.runThread(new DigitalTwinTimeout(this.processManager, processId)); try { if(!blockThread.join(Duration.ofSeconds(this.dtrConfig.getTimeouts().getDigitalTwin()))){ LogUtil.printError("Timeout reached while waiting for receiving digital twin!"); - LogUtil.printWarning("STATUS\n" + jsonUtil.toJson(this.processManager.getStatus(processId), true)); return null; }; } catch (InterruptedException e) { return null; } status = this.processManager.getStatus(processId); - LogUtil.printWarning("STATUS:\n" + jsonUtil.toJson(status, true)); if(status.historyExists("digital-twin-found")){ return new AssetSearch(status.getHistory("digital-twin-found").getId(), status.getEndpoint()); }; @@ -648,14 +643,7 @@ public DecentralDigitalTwinRegistryQueryById(Search search, DataPlaneEndpoint ed @Override public void run() { this.setDigitalTwin(searchDigitalTwin3(this.getIdType(), this.getAssetId(), this.getDtIndex(), this.getEdr().getEndpoint(), this.getEdr())); - if (this.getIdShort().equalsIgnoreCase(dppIdShort)) { - SubModel3 submodelTest = searchSubModel3BySemanticId(this.getDigitalTwin(), this.getIdShort()); - LogUtil.printWarning("SUBMODEL BY SEMANTIC ID:\n" + jsonUtil.toJson(submodelTest, true)); - this.setSubModel(searchSubModel3ById(this.getDigitalTwin(), this.getIdShort())); - } else { - this.setSubModel(searchSubModel3ById(this.getDigitalTwin(), this.getIdShort())); - } - + this.setSubModel(searchSubModel3BySemanticId(this.getDigitalTwin())); } public DataPlaneEndpoint getEdr() { return edr; diff --git a/consumer-backend/productpass/src/main/resources/application.yml b/consumer-backend/productpass/src/main/resources/application.yml index 329e44ecb..e135f4dc2 100644 --- a/consumer-backend/productpass/src/main/resources/application.yml +++ b/consumer-backend/productpass/src/main/resources/application.yml @@ -98,16 +98,9 @@ configuration: encrypt: true indent: true dir: "data/transfer" - digitalProductPass: - versions: - - '1.0.0' - semanticId: "urn:bamm:io.catenax.generic.digital_product_passport" - aspectId: "DigitalProductPassport" - batteryPass: - versions: - - '3.0.1' - semanticId: "urn:bamm:io.catenax.battery.battery_pass" - aspectId: "BatteryPass" + aspects: + - "urn:bamm:io.catenax.generic.digital_product_passport:1.0.0#DigitalProductPassport" + - "urn:bamm:io.catenax.battery.battery_pass:3.0.1#BatteryPass" vault: type: 'local' @@ -130,4 +123,4 @@ server: include-exception: false port: 8888 tomcat: - max-connections: 10000 \ No newline at end of file + max-connections: 10000 From e59d23e149cf6c95967eaee895b70de0b51b6224 Mon Sep 17 00:00:00 2001 From: Parracho Date: Tue, 10 Oct 2023 09:53:10 +0100 Subject: [PATCH 12/18] feat: deleted debug logs and added semanticId into Status class --- .../productpass/http/controllers/AppController.java | 1 + .../tractusx/productpass/models/manager/Status.java | 11 +++++++++++ .../tractusx/productpass/services/AasService.java | 6 ------ .../productpass/services/DataTransferService.java | 5 +---- 4 files changed, 13 insertions(+), 10 deletions(-) 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 228d1370a..726b39753 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 @@ -159,6 +159,7 @@ public Response getDigitalTwin(@RequestBody Object body, @PathVariable String pr try { digitalTwin = digitalTwinRegistry.getDigitalTwin(); subModel = digitalTwinRegistry.getSubModel(); + //status.setSemanticId(String.valueOf(subModel.getSemanticId().getKeys().stream().filter(k -> k.getType().equalsIgnoreCase("Submodel")).findFirst().orElse(null))); connectorId = subModel.getIdShort(); EndPoint3 endpoint = subModel.getEndpoints().stream().filter(obj -> obj.getInterfaceName().equals(dtrConfig.getEndpointInterface())).findFirst().orElse(null); if (endpoint == null) { diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Status.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Status.java index f291a7bf9..f4375f10c 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Status.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/manager/Status.java @@ -58,6 +58,9 @@ public class Status { @JsonProperty("history") public Map history; + @JsonProperty("semanticId") + public String semanticId; + public Status(String id, String status, Long created, Long modified, String endpoint, Map history) { this.id = id; @@ -232,6 +235,14 @@ public String getBpn() { public void setBpn(String bpn) { this.bpn = bpn; } + + public String getSemanticId() { + return semanticId; + } + + public void setSemanticId(String semanticId) { + this.semanticId = semanticId; + } } 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 25ca70f41..1f217f20e 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 @@ -153,7 +153,6 @@ public SubModel searchSubModelInDigitalTwinByIndex(DigitalTwin digitalTwin, Inte public DigitalTwin3 searchDigitalTwin3(String assetType, String assetId, Integer position, String registryUrl, DataPlaneEndpoint edr) { try { ArrayList digitalTwinIds = this.queryDigitalTwin(assetType, assetId, registryUrl, edr); - LogUtil.printWarning("DIGITAL TWINS ARRAY SIZE: " + digitalTwinIds.size()); 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"); @@ -163,10 +162,8 @@ public DigitalTwin3 searchDigitalTwin3(String assetType, String assetId, Integer "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); - LogUtil.printWarning("DIGITAL TWIN:\n" + jsonUtil.toJson(digitalTwin, true)); 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"); @@ -232,7 +229,6 @@ public SubModel3 searchSubModel3ById(DigitalTwin3 digitalTwin, String idShort) { public SubModel3 searchSubModel3BySemanticId(DigitalTwin3 digitalTwin) { try { SubModel3 subModel = this.getSubModel3BySemanticId(digitalTwin); - LogUtil.printWarning("SUBMODEL3:\n" + jsonUtil.toJson(subModel, true)); 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"); @@ -502,8 +498,6 @@ public AssetSearch decentralDtrSearch(String processId, Search searchBody){ SearchStatus searchStatus = this.processManager.setSearch(processId, searchBody); for (String endpointId : searchStatus.getDtrs().keySet()) { Dtr dtr = searchStatus.getDtr(endpointId); - LogUtil.printWarning("EndpointId: " + endpointId); - LogUtil.printWarning("Decentral DTR:\n" + jsonUtil.toJson(dtr, true)); DataTransferService.DigitalTwinRegistryTransfer dtrTransfer = dataService.new DigitalTwinRegistryTransfer( processId, endpointId, 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 499ec7249..38062ad14 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 @@ -869,13 +869,10 @@ public DigitalTwinRegistryTransfer(String processId, String endpointId, Status s public void run() { try { this.dtrRequest = this.buildTransferRequest(this.processId,this.dtr, this.endpointId); - LogUtil.printWarning("DTR REQUEST:\n" + jsonUtil.toJson(this.dtrRequest, true)); processManager.saveTransferRequest(this.processId, dtrRequest, new IdResponse(processId, null), true); this.transferResponse = this.requestTransfer(dtrRequest); - processManager.saveTransferRequest(this.processId, dtrRequest, this.transferResponse, true); this.transfer = this.getTransferData(this.transferResponse); - LogUtil.printWarning("TRANSFER:\n" + jsonUtil.toJson(this.transfer, true)); if (this.transfer == null) { return; } @@ -946,4 +943,4 @@ public Transfer getTransferData(IdResponse transferData) { } -} \ No newline at end of file +} From 69cf589bcafce5a8aad8adde44fb9860d8765ae3 Mon Sep 17 00:00:00 2001 From: Mathias Brunkow Moser Date: Tue, 10 Oct 2023 11:38:26 +0200 Subject: [PATCH 13/18] feat: added semantic id filtering for dynamic passes --- .../http/controllers/AppController.java | 11 ++++++-- .../http/controllers/api/ApiController.java | 13 ++------- .../productpass/managers/ProcessManager.java | 28 +++++++++++++++---- .../{PassportV3.java => BatteryPass.java} | 4 +-- .../productpass/services/AasService.java | 15 ++++------ .../services/DataPlaneService.java | 15 +++++----- .../services/DataTransferService.java | 14 ++-------- .../src/main/java/utils/CatenaXUtil.java | 9 ++++++ .../src/main/java/utils/ReflectionUtil.java | 13 +++++++++ 9 files changed, 73 insertions(+), 49 deletions(-) rename consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/{PassportV3.java => BatteryPass.java} (96%) 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 726b39753..7a15cc8b6 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 @@ -58,6 +58,7 @@ import java.util.List; import java.util.Map; +import java.util.Objects; @RestController @Tag(name = "Public Controller") @@ -156,10 +157,13 @@ public Response getDigitalTwin(@RequestBody Object body, @PathVariable String pr String connectorId = null; String assetId = null; String connectorAddress = null; + String semanticId = null; + try { digitalTwin = digitalTwinRegistry.getDigitalTwin(); subModel = digitalTwinRegistry.getSubModel(); - //status.setSemanticId(String.valueOf(subModel.getSemanticId().getKeys().stream().filter(k -> k.getType().equalsIgnoreCase("Submodel")).findFirst().orElse(null))); + semanticId = Objects.requireNonNull(subModel.getSemanticId().getKeys().stream().filter(k -> k.getType().equalsIgnoreCase("Submodel")).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); if (endpoint == null) { @@ -185,6 +189,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); 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( @@ -242,7 +247,9 @@ public Response endpoint(@RequestBody Object body, @PathVariable String processI return httpUtil.buildResponse(httpUtil.getNotFound("Process not found!"), httpResponse); } - Passport passport = dataPlaneService.getPassport(endpointData); + Status status = processManager.getStatus(processId); + String semanticId = status.getSemanticId(); + Passport passport = dataPlaneService.getPassport(semanticId, endpointData); if (passport == null) { return httpUtil.buildResponse(httpUtil.getNotFound("Passport not found in data plane!"), httpResponse); } diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java index 19a137fe9..f0bec5447 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java @@ -31,23 +31,17 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; -import org.bouncycastle.pqc.crypto.lms.LMOtsParameters; import org.eclipse.tractusx.productpass.config.PassportConfig; -import org.eclipse.tractusx.productpass.exceptions.ControllerException; import org.eclipse.tractusx.productpass.managers.ProcessManager; -import org.eclipse.tractusx.productpass.models.dtregistry.DigitalTwin; -import org.eclipse.tractusx.productpass.models.dtregistry.SubModel; import org.eclipse.tractusx.productpass.models.http.Response; import org.eclipse.tractusx.productpass.models.http.requests.TokenRequest; -import org.eclipse.tractusx.productpass.models.http.responses.IdResponse; import org.eclipse.tractusx.productpass.models.manager.History; import org.eclipse.tractusx.productpass.models.manager.Process; import org.eclipse.tractusx.productpass.models.manager.Status; import org.eclipse.tractusx.productpass.models.negotiation.*; -import org.eclipse.tractusx.productpass.models.passports.DigitalProductPassport; import org.eclipse.tractusx.productpass.models.passports.Passport; import org.eclipse.tractusx.productpass.models.passports.PassportResponse; -import org.eclipse.tractusx.productpass.models.passports.PassportV3; +import org.eclipse.tractusx.productpass.models.passports.BatteryPass; import org.eclipse.tractusx.productpass.services.AasService; import org.eclipse.tractusx.productpass.services.AuthenticationService; import org.eclipse.tractusx.productpass.services.DataTransferService; @@ -59,9 +53,6 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import javax.xml.crypto.Data; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; @@ -97,7 +88,7 @@ Response index() throws Exception { @ApiResponse(description = "Content of Data Field in Response", responseCode = "200", content = @Content(mediaType = "application/json", schema = @Schema(implementation = PassportResponse.class))), @ApiResponse(description = "Content of Passport Field in Data Field", useReturnTypeSchema = true, content = @Content(mediaType = "application/json", - schema = @Schema(implementation = PassportV3.class))) + schema = @Schema(implementation = BatteryPass.class))) }) public Response getPassport(@Valid @RequestBody TokenRequest tokenRequestBody) { Response response = httpUtil.getInternalError(); 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 baf056242..c591dbae0 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 @@ -26,7 +26,6 @@ package org.eclipse.tractusx.productpass.managers; import jakarta.servlet.http.HttpServletRequest; -import org.eclipse.tractusx.productpass.config.PassportConfig; import org.eclipse.tractusx.productpass.models.passports.DigitalProductPassport; import org.eclipse.tractusx.productpass.config.ProcessConfig; import org.eclipse.tractusx.productpass.exceptions.ManagerException; @@ -43,7 +42,7 @@ import org.eclipse.tractusx.productpass.models.manager.Status; import org.eclipse.tractusx.productpass.models.negotiation.*; import org.eclipse.tractusx.productpass.models.passports.Passport; -import org.eclipse.tractusx.productpass.models.passports.PassportV3; +import org.eclipse.tractusx.productpass.models.passports.BatteryPass; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @@ -335,6 +334,23 @@ public String setBpn(String processId, String bpn) { } } + public String setSemanticId(String processId, String semanticId) { + try { + String path = this.getProcessFilePath(processId, this.metaFileName); + Status statusFile = null; + if (!fileUtil.pathExists(path)) { + throw new ManagerException(this.getClass().getName(), "Process file does not exists for id ["+processId+"]!"); + } + + statusFile = (Status) jsonUtil.fromJsonFileToObject(path, Status.class); + statusFile.setSemanticId(semanticId); + statusFile.setModified(DateTimeUtil.getTimestamp()); + return jsonUtil.toJsonFile(path, statusFile, processConfig.getIndent()); // Store the plain JSON + } catch (Exception e) { + throw new ManagerException(this.getClass().getName(), e, "It was not possible to set the semanticId!"); + } + } + public String setStatus(String processId, String historyId, History history) { try { String path = this.getProcessFilePath(processId, this.metaFileName); @@ -573,7 +589,7 @@ public String getContractId(DataPlaneEndpoint endpointData){ return endpointData.getOfferId(); } - public PassportV3 loadPassport(String processId){ + public BatteryPass loadPassport(String processId){ try { String path = this.getProcessFilePath(processId, this.passportFileName); History history = new History( @@ -583,7 +599,7 @@ public PassportV3 loadPassport(String processId){ if(!fileUtil.pathExists(path)){ throw new ManagerException(this.getClass().getName(), "Passport file ["+path+"] not found!"); } - PassportV3 passport = null; + BatteryPass passport = null; Boolean encrypt = env.getProperty("passport.dataTransfer.encrypt", Boolean.class, true); if(encrypt){ Status status = this.getStatus(processId); @@ -591,9 +607,9 @@ public PassportV3 loadPassport(String processId){ String decryptedPassportJson = CrypUtil.decryptAes(fileUtil.readFile(path), this.generateStatusToken(status, negotiationHistory.getId())); // Delete passport file - passport = (PassportV3) jsonUtil.loadJson(decryptedPassportJson, PassportV3.class); + passport = (BatteryPass) jsonUtil.loadJson(decryptedPassportJson, BatteryPass.class); }else{ - passport = (PassportV3) jsonUtil.fromJsonFileToObject(path, PassportV3.class); + passport = (BatteryPass) jsonUtil.fromJsonFileToObject(path, BatteryPass.class); } if(passport == null){ diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/PassportV3.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/BatteryPass.java similarity index 96% rename from consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/PassportV3.java rename to consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/BatteryPass.java index 76475470f..9a2414ee7 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/PassportV3.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/models/passports/BatteryPass.java @@ -30,7 +30,7 @@ /* * =======[DESCRIPTION]========================================================= - * Passport Semantic BAMM Version @v3.0.1 + * Battery Pass Semantic BAMM Version @v3.0.1 * Aspect model URN: urn:bamm:io.catenax.battery.battery_pass:3.0.1#BatteryPass * https://portal.int.demo.catena-x.net/semantichub/urn%3Abamm%3Aio.catenax.battery.battery_pass%3A3.0.1%23BatteryPass * Flexible Structure (Abstraction from main attributes using JsonNodes) @@ -38,7 +38,7 @@ */ @JsonInclude(JsonInclude.Include.NON_NULL) -public class PassportV3 extends Passport{ +public class BatteryPass extends Passport{ @JsonProperty("electrochemicalProperties") JsonNode electrochemicalProperties; 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 1f217f20e..8c5a92735 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 @@ -373,19 +373,14 @@ public SubModel3 getSubModel3BySemanticId(DigitalTwin3 digitalTwin) { 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); if (subModel != null) { - break; + return subModel; // Return subModel if found } } - - if (subModel == null) { - // If the subModel semanticId does not exist - throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", - "SubModel for SemanticId not found!"); - } - // Return subModel if found - return subModel; + // If the subModel semanticId does not exist + throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", + "SubModel for SemanticId not found!"); } catch (Exception e) { - throw new ServiceException(this.getClass().getName() + "." + "getSubModel3ById", + throw new ServiceException(this.getClass().getName() + "." + "getSubModel3BySemanticId", e, "It was not possible to get subModel!"); } diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataPlaneService.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataPlaneService.java index affad373f..4fd26c2e3 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataPlaneService.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataPlaneService.java @@ -23,21 +23,18 @@ package org.eclipse.tractusx.productpass.services; +import org.apache.juli.logging.Log; import org.eclipse.tractusx.productpass.exceptions.ServiceException; import org.eclipse.tractusx.productpass.exceptions.ServiceInitializationException; -import org.eclipse.tractusx.productpass.models.auth.JwtToken; -import org.eclipse.tractusx.productpass.models.dtregistry.DigitalTwin; import org.eclipse.tractusx.productpass.models.edc.DataPlaneEndpoint; import org.eclipse.tractusx.productpass.models.passports.DigitalProductPassport; import org.eclipse.tractusx.productpass.models.passports.Passport; -import org.eclipse.tractusx.productpass.models.passports.PassportV3; import org.eclipse.tractusx.productpass.models.service.BaseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; -import utils.HttpUtil; -import utils.JsonUtil; +import utils.*; import java.util.ArrayList; import java.util.List; @@ -68,9 +65,13 @@ public Object getTransferData(DataPlaneEndpoint endpointData) { "It was not possible to get transfer from transfer id ["+endpointData.getId()+"]"); } } - public Passport getPassport(DataPlaneEndpoint endpointData) { + public Passport getPassport(String semanticId, DataPlaneEndpoint endpointData) { try { - return (DigitalProductPassport) jsonUtil.bindObject(this.getTransferData(endpointData), DigitalProductPassport.class); + String aspectName = CatenaXUtil.getAspectNameFromSemanticId(semanticId); // Get aspect name from semantic Id + String packagePath = this.getClass().getPackageName().replace("services", "models.passports"); + LogUtil.printMessage("aspect name: "+aspectName + " packagePath: "+ packagePath); + Class passportClass = ReflectionUtil.instanceClass(packagePath, aspectName); + return (Passport) jsonUtil.bindObject(this.getTransferData(endpointData), passportClass); }catch (Exception e){ throw new ServiceException(this.getClass().getName()+"."+"getPassport", e, 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 38062ad14..ff19be6ff 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 @@ -24,9 +24,6 @@ package org.eclipse.tractusx.productpass.services; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.type.LogicalType; -import com.google.common.math.Stats; -import org.apache.juli.logging.Log; import org.eclipse.tractusx.productpass.config.DtrConfig; import org.eclipse.tractusx.productpass.exceptions.ControllerException; import org.eclipse.tractusx.productpass.exceptions.ServiceException; @@ -34,15 +31,13 @@ import org.eclipse.tractusx.productpass.managers.ProcessDataModel; import org.eclipse.tractusx.productpass.managers.ProcessManager; import org.eclipse.tractusx.productpass.models.catenax.Dtr; -import org.eclipse.tractusx.productpass.models.edc.DataPlaneEndpoint; import org.eclipse.tractusx.productpass.models.http.requests.Search; import org.eclipse.tractusx.productpass.models.http.responses.IdResponse; import org.eclipse.tractusx.productpass.models.manager.History; import org.eclipse.tractusx.productpass.models.manager.Status; import org.eclipse.tractusx.productpass.models.negotiation.*; -import org.eclipse.tractusx.productpass.models.negotiation.Properties; import org.eclipse.tractusx.productpass.models.negotiation.Set; -import org.eclipse.tractusx.productpass.models.passports.PassportV3; +import org.eclipse.tractusx.productpass.models.passports.BatteryPass; import org.eclipse.tractusx.productpass.models.service.BaseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; @@ -51,12 +46,9 @@ import org.springframework.stereotype.Service; import utils.*; -import javax.xml.crypto.Data; -import java.nio.file.Paths; import java.time.Duration; import java.time.Instant; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; @Service public class DataTransferService extends BaseService { @@ -810,7 +802,7 @@ public Transfer seeTransfer(String id, String processId, ProcessDataModel dataMo } - public PassportV3 getPassportV3(String transferProcessId, String endpoint) { + public BatteryPass getPassportV3(String transferProcessId, String endpoint) { try { this.checkEmptyVariables(); Map params = httpUtil.getParams(); @@ -825,7 +817,7 @@ public PassportV3 getPassportV3(String transferProcessId, String endpoint) { throw new ServiceException(this.getClass().getName() + ".getPassportV3", "It was not possible to get passport with id " + transferProcessId); } String responseBody = (String) response.getBody(); - return (PassportV3) jsonUtil.bindJsonNode(jsonUtil.toJsonNode(responseBody), PassportV3.class); + return (BatteryPass) jsonUtil.bindJsonNode(jsonUtil.toJsonNode(responseBody), BatteryPass.class); } catch (Exception e) { throw new ServiceException(this.getClass().getName() + "." + "getPassportV3", e, diff --git a/consumer-backend/productpass/src/main/java/utils/CatenaXUtil.java b/consumer-backend/productpass/src/main/java/utils/CatenaXUtil.java index 3ab9fd7ac..1b1dd4a2e 100644 --- a/consumer-backend/productpass/src/main/java/utils/CatenaXUtil.java +++ b/consumer-backend/productpass/src/main/java/utils/CatenaXUtil.java @@ -31,6 +31,7 @@ import utils.exceptions.UtilException; import java.nio.file.Paths; +import java.util.concurrent.ExecutionException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -52,6 +53,14 @@ public static String buildDataEndpoint(String endpoint) { return endpoint + edcDataEndpoint; } + public static String getAspectNameFromSemanticId(String semanticId){ + try { + return semanticId.split(String.format("\\%s","#"))[1]; + }catch(Exception e){ + throw new UtilException(CatenaXUtil.class, e, "[ERROR] It was not possible to ge the semantic aspect!"); + } + } + public static String getBPN(String str) { Pattern pattern = Pattern.compile(bpnNumberPattern); Matcher matcher = pattern.matcher(str); diff --git a/consumer-backend/productpass/src/main/java/utils/ReflectionUtil.java b/consumer-backend/productpass/src/main/java/utils/ReflectionUtil.java index 320d64a7a..0a889487e 100644 --- a/consumer-backend/productpass/src/main/java/utils/ReflectionUtil.java +++ b/consumer-backend/productpass/src/main/java/utils/ReflectionUtil.java @@ -23,6 +23,8 @@ package utils; +import utils.exceptions.UtilException; + public final class ReflectionUtil { private ReflectionUtil() { throw new IllegalStateException("Tool/Utility Class Illegal Initialization"); @@ -33,4 +35,15 @@ public static String getCurrentClassName(Class classObj){ public static Boolean classIsTest(Class classObj){ return ReflectionUtil.getCurrentClassName(classObj).contains("test"); } + public static Class instanceClass(String packagePath, String className){ + try { + String classPath = packagePath + "." + className; + LogUtil.printMessage("class path: " + classPath); + return Class.forName(classPath); + }catch (ClassNotFoundException e){ + throw new UtilException(ReflectionUtil.class, e, "It was not possible to instance class, class ["+packagePath+"."+className+"] not found!"); + }catch (Exception e){ + throw new UtilException(ReflectionUtil.class, e, "It was not possible to instance class!"); + } + } } From b01f762acfb756d03a6c5ddebca2824d22d78fb1 Mon Sep 17 00:00:00 2001 From: Mathias Brunkow Moser Date: Tue, 10 Oct 2023 11:52:35 +0200 Subject: [PATCH 14/18] fix: parse passport by aspect type --- .../productpass/http/controllers/AppController.java | 1 - .../http/controllers/api/ApiController.java | 3 ++- .../tractusx/productpass/managers/ProcessManager.java | 11 +++++++---- .../productpass/services/DataPlaneService.java | 1 - 4 files changed, 9 insertions(+), 7 deletions(-) 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 7a15cc8b6..1e1c8fca3 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; diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java index f0bec5447..1d0a1cb0d 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/http/controllers/api/ApiController.java @@ -162,8 +162,9 @@ public Response getPassport(@Valid @RequestBody TokenRequest tokenRequestBody) { response = httpUtil.getNotFound("The passport was already retrieved and is no longer available!"); return httpUtil.buildResponse(response, httpResponse); } + String semanticId = status.getSemanticId(); - Passport passport = processManager.loadDigitalProductPassport(processId); + Passport passport = processManager.loadPassport(semanticId, processId); if (passport == null) { response = httpUtil.getNotFound("Failed to load passport!"); return httpUtil.buildResponse(response, httpResponse); 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 c591dbae0..f07dec3ae 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 @@ -589,7 +589,7 @@ public String getContractId(DataPlaneEndpoint endpointData){ return endpointData.getOfferId(); } - public BatteryPass loadPassport(String processId){ + public Passport loadPassport(String semanticId, String processId){ try { String path = this.getProcessFilePath(processId, this.passportFileName); History history = new History( @@ -599,7 +599,10 @@ public BatteryPass loadPassport(String processId){ if(!fileUtil.pathExists(path)){ throw new ManagerException(this.getClass().getName(), "Passport file ["+path+"] not found!"); } - BatteryPass passport = null; + Passport passport = null; + String aspectName = CatenaXUtil.getAspectNameFromSemanticId(semanticId); // Get aspect name from semantic Id + String packagePath = this.getClass().getPackageName().replace("http.controllers.api", "models.passports"); + Class passportClass = ReflectionUtil.instanceClass(packagePath, aspectName); Boolean encrypt = env.getProperty("passport.dataTransfer.encrypt", Boolean.class, true); if(encrypt){ Status status = this.getStatus(processId); @@ -607,9 +610,9 @@ public BatteryPass loadPassport(String processId){ String decryptedPassportJson = CrypUtil.decryptAes(fileUtil.readFile(path), this.generateStatusToken(status, negotiationHistory.getId())); // Delete passport file - passport = (BatteryPass) jsonUtil.loadJson(decryptedPassportJson, BatteryPass.class); + passport = (Passport) jsonUtil.loadJson(decryptedPassportJson, passportClass); }else{ - passport = (BatteryPass) jsonUtil.fromJsonFileToObject(path, BatteryPass.class); + passport = (Passport) jsonUtil.fromJsonFileToObject(path, passportClass); } if(passport == null){ diff --git a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataPlaneService.java b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataPlaneService.java index 4fd26c2e3..014ada1d9 100644 --- a/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataPlaneService.java +++ b/consumer-backend/productpass/src/main/java/org/eclipse/tractusx/productpass/services/DataPlaneService.java @@ -69,7 +69,6 @@ public Passport getPassport(String semanticId, DataPlaneEndpoint endpointData) { try { String aspectName = CatenaXUtil.getAspectNameFromSemanticId(semanticId); // Get aspect name from semantic Id String packagePath = this.getClass().getPackageName().replace("services", "models.passports"); - LogUtil.printMessage("aspect name: "+aspectName + " packagePath: "+ packagePath); Class passportClass = ReflectionUtil.instanceClass(packagePath, aspectName); return (Passport) jsonUtil.bindObject(this.getTransferData(endpointData), passportClass); }catch (Exception e){ From 0cfa7f813ae0ab5bacb68db5c0bf9ee603cbc78e Mon Sep 17 00:00:00 2001 From: Mathias Brunkow Moser Date: Tue, 10 Oct 2023 11:58:39 +0200 Subject: [PATCH 15/18] fix: parse passport by aspect type mend --- .../eclipse/tractusx/productpass/managers/ProcessManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f07dec3ae..e57c58b18 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 @@ -601,7 +601,7 @@ public Passport loadPassport(String semanticId, String processId){ } Passport passport = null; String aspectName = CatenaXUtil.getAspectNameFromSemanticId(semanticId); // Get aspect name from semantic Id - String packagePath = this.getClass().getPackageName().replace("http.controllers.api", "models.passports"); + String packagePath = this.getClass().getPackageName().replace("managers", "models.passports"); Class passportClass = ReflectionUtil.instanceClass(packagePath, aspectName); Boolean encrypt = env.getProperty("passport.dataTransfer.encrypt", Boolean.class, true); if(encrypt){ From e1f9f8bd22faa1d021f56d042c49fa9d23e040cf Mon Sep 17 00:00:00 2001 From: Parracho Date: Tue, 10 Oct 2023 14:20:49 +0100 Subject: [PATCH 16/18] fix: added logs to understand an issue with missing endpoint for submodel --- .../tractusx/productpass/http/controllers/AppController.java | 4 ++++ 1 file changed, 4 insertions(+) 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 1e1c8fca3..0e1a34588 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 @@ -172,6 +172,10 @@ public Response getDigitalTwin(@RequestBody Object body, @PathVariable String pr connectorAddress = subProtocolBody.get(dtrConfig.getDspEndpointKey()); // Get DSP endpoint address assetId = subProtocolBody.get("id"); // Get Asset Id } catch (Exception e) { + LogUtil.printException(e, "AppController Error"); + LogUtil.printMessage("Submodel:\n" + jsonUtil.toJson(subModel, true)); + LogUtil.printMessage("SemanticId:\n" + semanticId); + LogUtil.printMessage("ConnectorId:\n" + connectorId); return httpUtil.buildResponse(httpUtil.getNotFound("No endpoint address found"), httpResponse); } if (connectorId.isEmpty() || connectorAddress.isEmpty()) { From c54caf65edb74e38bd9fe370410ff7f5f5bd7b76 Mon Sep 17 00:00:00 2001 From: Parracho Date: Tue, 10 Oct 2023 14:39:29 +0100 Subject: [PATCH 17/18] fix: added logs in appController and type globalreference to search for semantiId --- .../productpass/http/controllers/AppController.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 0e1a34588..2954e4e05 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 @@ -161,9 +161,12 @@ public Response getDigitalTwin(@RequestBody Object body, @PathVariable String pr try { digitalTwin = digitalTwinRegistry.getDigitalTwin(); subModel = digitalTwinRegistry.getSubModel(); - semanticId = Objects.requireNonNull(subModel.getSemanticId().getKeys().stream().filter(k -> k.getType().equalsIgnoreCase("Submodel")).findFirst().orElse(null)).getValue(); + 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(); + LogUtil.printMessage("Submodel:\n" + jsonUtil.toJson(subModel, true)); + LogUtil.printMessage("SemanticId:\n" + semanticId); + LogUtil.printMessage("ConnectorId:\n" + connectorId); EndPoint3 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!"); @@ -172,10 +175,6 @@ public Response getDigitalTwin(@RequestBody Object body, @PathVariable String pr connectorAddress = subProtocolBody.get(dtrConfig.getDspEndpointKey()); // Get DSP endpoint address assetId = subProtocolBody.get("id"); // Get Asset Id } catch (Exception e) { - LogUtil.printException(e, "AppController Error"); - LogUtil.printMessage("Submodel:\n" + jsonUtil.toJson(subModel, true)); - LogUtil.printMessage("SemanticId:\n" + semanticId); - LogUtil.printMessage("ConnectorId:\n" + connectorId); return httpUtil.buildResponse(httpUtil.getNotFound("No endpoint address found"), httpResponse); } if (connectorId.isEmpty() || connectorAddress.isEmpty()) { From 0718403a8a52f4a3274a198af49dc75dabdd9403 Mon Sep 17 00:00:00 2001 From: Parracho Date: Tue, 10 Oct 2023 15:58:56 +0100 Subject: [PATCH 18/18] added GlobalReference to search semanticIds from DPP submodels --- .../tractusx/productpass/http/controllers/AppController.java | 3 --- 1 file changed, 3 deletions(-) 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 2954e4e05..3d687e15c 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 @@ -164,9 +164,6 @@ 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(); - LogUtil.printMessage("Submodel:\n" + jsonUtil.toJson(subModel, true)); - LogUtil.printMessage("SemanticId:\n" + semanticId); - LogUtil.printMessage("ConnectorId:\n" + connectorId); EndPoint3 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!");