Skip to content

Commit

Permalink
Merge pull request #177 from catenax-ng/feature/cmp-870/change-search…
Browse files Browse the repository at this point in the history
…-dpp

Feature/cmp 870/change search dpp
  • Loading branch information
matbmoser authored Oct 12, 2023
2 parents 50e043b + 2757279 commit 8cf72c5
Show file tree
Hide file tree
Showing 19 changed files with 470 additions and 447 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,94 +35,21 @@
@ConfigurationProperties(prefix="configuration.passport")
public class PassportConfig {

/** ATTRIBUTES **/
private BatteryPass batteryPass;
private DigitalProductPass digitalProductPass;
private List<String> aspects;

/** GETTERS AND SETTERS **/
public BatteryPass getBatteryPass() {
return batteryPass;
}
public void setBatteryPass(BatteryPass batteryPass) {
this.batteryPass = batteryPass;
}
public DigitalProductPass getDigitalProductPass() {
return digitalProductPass;
}
public void setDigitalProductPass(DigitalProductPass digitalProductPass) {
this.digitalProductPass = digitalProductPass;
public PassportConfig() {
}

/** INNER CLASSES **/

/**
* This class consists exclusively to define the attributes and methods needed for the BatterPass configuration.
**/
public static class BatteryPass extends DigitalProductPass {
public PassportConfig(List<String> aspects) {
this.aspects = aspects;
}

/**
* This class consists exclusively to define the attributes and methods needed for the DigitalProductPass configuration.
**/
public static class DigitalProductPass {

/** ATTRIBUTES **/
private List<String> versions;
private String semanticId;
private String aspectId;
private String fullSemanticId;

/** CONSTRUCTOR(S) **/
@SuppressWarnings("Unused")
public DigitalProductPass(List<String> versions, String semanticId, String aspectId) {
this.versions = versions;
this.semanticId = semanticId;
this.aspectId = aspectId;
}

public DigitalProductPass() {
}

/** GETTERS AND SETTERS **/
public List<String> getVersions() {
return this.versions;
}
public void setVersions(List<String> versions) {
this.versions = versions;
}
public String getSemanticId() {
return semanticId;
}
public void setSemanticId(String semanticId) {
this.semanticId = semanticId;
}
@SuppressWarnings("Unused")
public String getAspectId() {
return aspectId;
}
@SuppressWarnings("Unused")
public void setAspectId(String aspectId) {
this.aspectId = aspectId;
}

/** METHODS **/

/**
* Builds the semanticId to search the submodel inside the Digital twin.
* It concatenates the semanticId, the passport version and the aspectId.
* <p>
* @param version
* the {@code String} intended passport's version .
*
* @return this {@code String} with the built semanticId.
*
*/
public String getFullSemanticId(String version) {
if (this.fullSemanticId == null) {
this.fullSemanticId = semanticId + ":" + versions.stream().filter(v -> v.equalsIgnoreCase(version)).findFirst().get() + "#" + aspectId;
}
return fullSemanticId;
}
public List<String> getAspects() {
return aspects;
}
public void setAspects(List<String> aspects) {
this.aspects = aspects;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
********************************************************************************/

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;
Expand Down Expand Up @@ -57,6 +58,7 @@
import utils.*;

import java.util.Map;
import java.util.Objects;

/**
* This class consists exclusively to define the HTTP methods of the Application's controller.
Expand Down Expand Up @@ -179,9 +181,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();
semanticId = Objects.requireNonNull(subModel.getSemanticId().getKeys().stream().filter(k -> k.getType().equalsIgnoreCase("Submodel") || k.getType().equalsIgnoreCase("GlobalReference")).findFirst().orElse(null)).getValue();
LogUtil.printMessage("SemanticId "+ semanticId);
connectorId = subModel.getIdShort();
EndPoint3 endpoint = subModel.getEndpoints().stream().filter(obj -> obj.getInterfaceName().equals(dtrConfig.getEndpointInterface())).findFirst().orElse(null);
if (endpoint == null) {
Expand All @@ -207,6 +213,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(
Expand Down Expand Up @@ -285,7 +292,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.eclipse.tractusx.productpass.models.negotiation.Dataset;
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.services.AasService;
import org.eclipse.tractusx.productpass.services.AuthenticationService;
import org.eclipse.tractusx.productpass.services.DataTransferService;
Expand Down Expand Up @@ -107,7 +106,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 = Passport.class)))
})
public Response getPassport(@Valid @RequestBody TokenRequest tokenRequestBody) {
Response response = httpUtil.getInternalError();
Expand Down Expand Up @@ -181,15 +180,8 @@ 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);
}

Passport passport;
if (process.getIsDigitalProductPass()) {
passport = processManager.loadDigitalProductPassport(processId);
} else {
passport = processManager.loadPassport(processId);
}


String semanticId = status.getSemanticId();
Passport passport = processManager.loadPassport(processId);
if (passport == null) {
response = httpUtil.getNotFound("Failed to load passport!");
return httpUtil.buildResponse(response, httpResponse);
Expand All @@ -204,7 +196,8 @@ public Response getPassport(@Valid @RequestBody TokenRequest tokenRequestBody) {
"negotiation", negotiation,
"transfer", transfer
),
"passport", passport
"data", passport,
"aspect", semanticId
);
return httpUtil.buildResponse(response, httpResponse);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import utils.JsonUtil;
import utils.LogUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -133,22 +134,25 @@ public Response create(@Valid @RequestBody DiscoverySearch searchBody) {
return httpUtil.buildResponse(response, httpResponse);
}

BpnDiscovery bpnDiscovery = null;
List<BpnDiscovery> 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<String> bpnList = bpnDiscovery.getBpnNumbers();
List<String> bpnList = new ArrayList<>();
for(BpnDiscovery bpnDiscovery : bpnDiscoveries){
bpnList.addAll(bpnDiscovery.getBpnNumbers());
}
String processId = processManager.initProcess();
ConcurrentHashMap<String, List<Dtr>> dataModel = null;
List<EdcDiscoveryEndpoint> edcEndpointBinded = null;
Expand All @@ -161,7 +165,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<EdcDiscoveryEndpoint> edcEndpoints = catenaXService.getEdcDiscovery(bpnDiscovery.getBpnNumbers());
List<EdcDiscoveryEndpoint> edcEndpoints = catenaXService.getEdcDiscovery(bpnList);
try {
edcEndpointBinded = (List<EdcDiscoveryEndpoint>) jsonUtil.bindReferenceType(edcEndpoints, new TypeReference<List<EdcDiscoveryEndpoint>>() {});
} catch (Exception e) {
Expand Down Expand Up @@ -239,30 +243,21 @@ public Response search(@Valid @RequestBody Search searchBody) {
return httpUtil.buildResponse(response, httpResponse);
}
try {
List<String> mandatoryParams = List.of("id", "version");
List<String> 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<String> versions;
boolean isDigitalProductPass;
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)));
isDigitalProductPass = true;
} else {
versions = passportConfig.getBatteryPass().getVersions();
searchBody.setSemanticId(passportConfig.getBatteryPass().getFullSemanticId(versions.get(0)));
isDigitalProductPass = false;
}

// 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;
Expand All @@ -283,7 +278,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!");
Expand Down
Loading

0 comments on commit 8cf72c5

Please sign in to comment.