Skip to content

Commit

Permalink
feat: initial structure prepared for check of multiple bpns
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Brunkow Moser committed Jan 3, 2024
1 parent 26296b2 commit 6078ce4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -343,14 +348,19 @@ 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);
}
} else {
this.dtrDataModel.put(bpn, new ArrayList<>(){{add(dtr);}});
}
}else{
this.dtrDataModel.put(bpn, new ArrayList<>(){});
}
return this;
}
Expand All @@ -369,7 +379,17 @@ public Boolean hasDtrDuplicates(List<Dtr> 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<Dtr> dtrListParsed = null;
try {
dtrListParsed = (List<Dtr>) jsonUtil.bindReferenceType(dtrList, new TypeReference<List<Dtr>>() {
});
} 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()));
}

/**
Expand Down Expand Up @@ -515,6 +535,8 @@ public void deleteBpns(ConcurrentHashMap<String, List<Dtr>> dataModel, List<Stri
if(deleted){
LogUtil.printMessage("[DTR DataModel Cache Cleaning] Deleted [" + bpnList.size() + "] bpn numbers from the DTR.");
saveDtrDataModel(dataModel);
}else{
LogUtil.printError("[DTR DataModel Cache Cleaning] Failed to do the dtrDataModel cleanup!");
}
}catch(Exception e){
throw new ManagerException(this.getClass().getName() + ".deleteBpns",e,"It was not possible to delete bpns from the DTR data model");
Expand Down

0 comments on commit 6078ce4

Please sign in to comment.