Skip to content

Commit

Permalink
Merge pull request #135 from catenax-ng/release/v1.2.0-digital-produc…
Browse files Browse the repository at this point in the history
…t-pass

[2º] - Release/v1.2.0 digital product pass: Support the Digital Product Pass aspect in the backend
  • Loading branch information
matbmoser authored Oct 30, 2023
2 parents ca13a9d + 4810e82 commit a889de8
Show file tree
Hide file tree
Showing 32 changed files with 592 additions and 554 deletions.
4 changes: 2 additions & 2 deletions charts/digital-product-pass/values-beta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ backend:
temporaryStorage: true
discovery:
endpoint: "https://semantics.beta.demo.catena-x.net/discoveryfinder/api/administration/connectors/discovery/search"
endpoint: "https://semantics.beta.demo.catena-x.net/discoveryfinder/api/v1.0/administration/connectors/discovery/search"
bpn:
key: "manufacturerPartId"
searchPath: "/api/administration/connectors/bpnDiscovery/search"
searchPath: "/api/v1.0/administration/connectors/bpnDiscovery/search"
edc:
key: "bpn"
Expand Down
6 changes: 3 additions & 3 deletions charts/digital-product-pass/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ backend:
dtr:
central: false
centralUrl: 'https://semantics.dev.demo.catena-x.net/registry'
assetId: 'digital-twin-registry'
assetId: 'registry-asset'
dspEndpointKey: 'dspEndpoint'
endpointInterface: 'SUBMODEL-3.0'
internalDtr: "https://materialpass.dev.demo.catena-x.net/BPNL000000000000" # -- If there is an internal DTR available it can be referenced here and will be injected in the list of DTRs
Expand All @@ -144,10 +144,10 @@ backend:
temporaryStorage: true
discovery:
endpoint: "https://semantics.dev.demo.catena-x.net/discoveryfinder/api/administration/connectors/discovery/search"
endpoint: "https://semantics.dev.demo.catena-x.net/discoveryfinder/api/v1.0/administration/connectors/discovery/search"
bpn:
key: "manufacturerPartId"
searchPath: "/api/administration/connectors/bpnDiscovery/search"
searchPath: "/api/v1.0/administration/connectors/bpnDiscovery/search"
edc:
key: "bpn"
Expand Down
6 changes: 3 additions & 3 deletions charts/digital-product-pass/values-int.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ backend:
dtr:
central: false
centralUrl: 'https://semantics.int.demo.catena-x.net/registry'
assetId: 'digital-twin-registry'
assetId: 'registry-asset'
dspEndpointKey: 'dspEndpoint'
endpointInterface: 'SUBMODEL-3.0'
internalDtr: "https://materialpass.int.demo.catena-x.net/BPNL000000000000" # -- If there is an internal DTR available it can be referenced here and will be injected in the list of DTRs
Expand All @@ -142,10 +142,10 @@ backend:
temporaryStorage: true
discovery:
endpoint: "https://semantics.int.demo.catena-x.net/discoveryfinder/api/administration/connectors/discovery/search"
endpoint: "https://semantics.int.demo.catena-x.net/discoveryfinder/api/v1.0/administration/connectors/discovery/search"
bpn:
key: "manufacturerPartId"
searchPath: "/api/administration/connectors/bpnDiscovery/search"
searchPath: "/api/v1.0/administration/connectors/bpnDiscovery/search"
edc:
key: "bpn"
Expand Down
6 changes: 3 additions & 3 deletions charts/digital-product-pass/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ backend:
# -- central digital twin registry url
centralUrl: 'https://<digital-twin-registry-url>'
# -- asset id to search for the registry in the edc
assetId: 'digital-twin-registry'
assetId: 'registry-asset'
# -- submodel endpoint interface to search
endpointInterface: 'SUBMODEL-3.0'
# -- dsp endpoint key inside submodel body
Expand All @@ -171,11 +171,11 @@ backend:
# -- discovery configuration
discovery:
# -- discovery finder configuration
endpoint: "https://<discovery.finder.url>/discoveryfinder/api/administration/connectors/discovery/search"
endpoint: "https://<discovery.finder.url>/discoveryfinder/api/v1.0/administration/connectors/discovery/search"
# -- bpn discovery configuration
bpn:
key: "manufacturerPartId"
searchPath: "/api/administration/connectors/bpnDiscovery/search"
searchPath: "/api/v1.0/administration/connectors/bpnDiscovery/search"
# -- edc discovery configuration
edc:
key: "bpn"
Expand Down
2 changes: 1 addition & 1 deletion consumer-backend/productpass/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</parent>
<groupId>org.eclipse.tractusx</groupId>
<artifactId>productpass</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<packaging>jar</packaging>
<name>Catena-X Digital Product Passport Backend</name>
<description>Product Passport Consumer Backend System for Product Passport Consumer Frontend Application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,24 @@ public class DtrConfig {
String endpointInterface;
String dspEndpointKey;

String semanticIdTypeKey;
/** CONSTRUCTOR(S) **/
public DtrConfig() {
}

public DtrConfig(Boolean central, String centralUrl, String internalDtr, Timeouts timeouts, Boolean temporaryStorage, DecentralApis decentralApis, String assetId, String endpointInterface, String dspEndpointKey, String semanticIdTypeKey) {
this.central = central;
this.centralUrl = centralUrl;
this.internalDtr = internalDtr;
this.timeouts = timeouts;
this.temporaryStorage = temporaryStorage;
this.decentralApis = decentralApis;
this.assetId = assetId;
this.endpointInterface = endpointInterface;
this.dspEndpointKey = dspEndpointKey;
this.semanticIdTypeKey = semanticIdTypeKey;
}

/** GETTERS AND SETTERS **/
public DecentralApis getDecentralApis() {
return decentralApis;
Expand Down Expand Up @@ -113,6 +127,14 @@ public void setAssetId(String assetId) {
this.assetId = assetId;
}

public String getSemanticIdTypeKey() {
return semanticIdTypeKey;
}

public void setSemanticIdTypeKey(String semanticIdTypeKey) {
this.semanticIdTypeKey = semanticIdTypeKey;
}

/** INNER CLASSES **/

/**
Expand Down
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 @@ -23,6 +23,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;
import io.swagger.v3.oas.annotations.media.Content;
Expand All @@ -34,8 +35,6 @@
import org.eclipse.tractusx.productpass.config.DtrConfig;
import org.eclipse.tractusx.productpass.config.ProcessConfig;
import org.eclipse.tractusx.productpass.exceptions.ControllerException;
import org.eclipse.tractusx.productpass.exceptions.DataModelException;
import org.eclipse.tractusx.productpass.exceptions.ServiceException;
import org.eclipse.tractusx.productpass.managers.ProcessManager;
import org.eclipse.tractusx.productpass.models.catenax.Dtr;
import org.eclipse.tractusx.productpass.models.dtregistry.DigitalTwin3;
Expand All @@ -48,7 +47,6 @@
import org.eclipse.tractusx.productpass.models.manager.History;
import org.eclipse.tractusx.productpass.models.manager.SearchStatus;
import org.eclipse.tractusx.productpass.models.manager.Status;
import org.eclipse.tractusx.productpass.models.passports.Passport;
import org.eclipse.tractusx.productpass.services.AasService;
import org.eclipse.tractusx.productpass.services.DataPlaneService;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -57,6 +55,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 +178,12 @@ 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(this.dtrConfig.getSemanticIdTypeKey())).findFirst().orElse(null)).getValue();
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 +209,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 +288,7 @@ public Response endpoint(@RequestBody Object body, @PathVariable String processI
return httpUtil.buildResponse(httpUtil.getNotFound("Process not found!"), httpResponse);
}

Passport passport = dataPlaneService.getPassport(endpointData);
JsonNode passport = dataPlaneService.getPassport(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 @@ -23,6 +23,7 @@

package org.eclipse.tractusx.productpass.http.controllers.api;

import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
Expand All @@ -41,9 +42,7 @@
import org.eclipse.tractusx.productpass.models.manager.Process;
import org.eclipse.tractusx.productpass.models.manager.Status;
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 @@ -100,16 +99,14 @@ Response index() throws Exception {
* @return this {@code Response} HTTP response with status.
*
*/
@RequestMapping(value = "/passport", method = {RequestMethod.POST})
@Operation(summary = "Returns versioned product passport by id", responses = {
@RequestMapping(value = "/data", method = {RequestMethod.POST})
@Operation(summary = "Returns the data negotiated and transferred", responses = {
@ApiResponse(description = "Default Response Structure", content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Response.class))),
@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)))
})
public Response getPassport(@Valid @RequestBody TokenRequest tokenRequestBody) {
public Response getData(@Valid @RequestBody TokenRequest tokenRequestBody) {
Response response = httpUtil.getInternalError();

// Check for authentication
Expand Down Expand Up @@ -172,24 +169,17 @@ public Response getPassport(@Valid @RequestBody TokenRequest tokenRequestBody) {
return httpUtil.buildResponse(response, httpResponse);
}

if (!status.historyExists("passport-received")) {
response = httpUtil.getNotFound("The passport is not available!");
if (!status.historyExists("data-received")) {
response = httpUtil.getNotFound("The data is not available!");
return httpUtil.buildResponse(response, httpResponse);
}

if (status.historyExists("passport-retrieved")) {
response = httpUtil.getNotFound("The passport was already retrieved and is no longer available!");
if (status.historyExists("data-retrieved")) {
response = httpUtil.getNotFound("The data 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();
JsonNode passport = processManager.loadPassport(processId);
if (passport == null) {
response = httpUtil.getNotFound("Failed to load passport!");
return httpUtil.buildResponse(response, httpResponse);
Expand All @@ -204,7 +194,8 @@ public Response getPassport(@Valid @RequestBody TokenRequest tokenRequestBody) {
"negotiation", negotiation,
"transfer", transfer
),
"passport", passport
"aspect", passport,
"semanticId", semanticId
);
return httpUtil.buildResponse(response, httpResponse);
} catch (Exception e) {
Expand Down
Loading

0 comments on commit a889de8

Please sign in to comment.