diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/http/controllers/api/ContractController.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/http/controllers/api/ContractController.java index 399523bc7..755cd73f1 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/http/controllers/api/ContractController.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/http/controllers/api/ContractController.java @@ -165,7 +165,11 @@ public Response create(@Valid @RequestBody DiscoverySearch searchBody) { LogUtil.printWarning("Failed to load data model from disk!"); } } - // 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 + System.out.println("Temporary Storage is: "+dtrConfig.getTemporaryStorage().getEnabled()); + System.out.println(dataModel); + System.out.println(bpnList); + System.out.println("Has all keys: "+jsonUtil.checkJsonKeys(dataModel, bpnList, ".", false)); + // This checks if the cache is deactivated or if the bns are not in the dataModel, if one of them is not in the data model then we need to check for them if(!dtrConfig.getTemporaryStorage().getEnabled() || ((dataModel==null) || !jsonUtil.checkJsonKeys(dataModel, bpnList, ".", false))){ catenaXService.searchDTRs(bpnList, processId); }else{ diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/managers/DtrSearchManager.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/managers/DtrSearchManager.java index dab8130fe..1e56374cf 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/managers/DtrSearchManager.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/managers/DtrSearchManager.java @@ -208,6 +208,11 @@ public void searchEndpoint(String processId, String bpn, String endpoint){ try { if (!asyncThread.join(Duration.ofSeconds(searchTimeoutSeconds))) { asyncThread.interrupt(); + if (dtrConfig.getTemporaryStorage().getEnabled()) { + addConnectionToBpnEntry(bpn, null); + saveDtrDataModel(); + } + LogUtil.printWarning("Failed to retrieve the Catalog due a timeout for the URL: " + endpoint); return; } @@ -343,7 +348,10 @@ public void run() { * */ public DtrSearchManager addConnectionToBpnEntry(String bpn, Dtr dtr) { - if (!(bpn == null || bpn.isEmpty() || bpn.isBlank() || dtr.getEndpoint().isEmpty() || dtr.getEndpoint().isBlank())) { + if(bpn == null || bpn.isEmpty() || bpn.isBlank()){ + return this; + } + if (!(dtr == null || dtr.getEndpoint().isEmpty() || dtr.getEndpoint().isBlank())) { if (this.dtrDataModel.containsKey(bpn)) { if (!hasDtrDuplicates(this.dtrDataModel.get(bpn), dtr)){ this.dtrDataModel.get(bpn).add(dtr); @@ -351,6 +359,8 @@ public DtrSearchManager addConnectionToBpnEntry(String bpn, Dtr dtr) { } else { this.dtrDataModel.put(bpn, new ArrayList<>(){{add(dtr);}}); } + }else{ + this.dtrDataModel.put(bpn, new ArrayList<>(){}); } return this; } @@ -369,7 +379,17 @@ public Boolean hasDtrDuplicates(List dtrList, Dtr dtr){ if(dtrList.contains(dtr)){ return true; } - return dtrList.stream().anyMatch(e -> e.getAssetId().equals(dtr.getAssetId()) && e.getEndpoint().equals(dtr.getEndpoint()) && e.getBpn().equals(dtr.getBpn())); + List dtrListParsed = null; + try { + dtrListParsed = (List) jsonUtil.bindReferenceType(dtrList, new TypeReference>() { + }); + } catch (Exception e) { + throw new ManagerException(this.getClass().getName(), e, "Could not bind the reference type for the DTR list!"); + } + if(dtrListParsed == null){ + throw new ManagerException(this.getClass().getName(), "Could not bind the reference type for the DTR list because it is null!"); + } + return dtrListParsed.stream().anyMatch(e -> e.getAssetId().equals(dtr.getAssetId()) && e.getEndpoint().equals(dtr.getEndpoint()) && e.getBpn().equals(dtr.getBpn())); } /** @@ -515,6 +535,8 @@ public void deleteBpns(ConcurrentHashMap> dataModel, List