diff --git a/DEPENDENCIES_BACKEND b/DEPENDENCIES_BACKEND index 555f3186d..0dce085d4 100644 --- a/DEPENDENCIES_BACKEND +++ b/DEPENDENCIES_BACKEND @@ -75,6 +75,7 @@ maven/mavencentral/org.bouncycastle/bcutil-jdk15on/1.69, MIT, approved, clearlyd maven/mavencentral/org.checkerframework/checker-qual/3.33.0, MIT, approved, clearlydefined maven/mavencentral/org.codehaus.plexus/plexus-utils/3.2.1, , approved, CQ20774 maven/mavencentral/org.ow2.asm/asm/9.6, BSD-3-Clause, approved, #10776 +maven/mavencentral/org.projectlombok/lombok/1.18.32, MIT AND LicenseRef-Public-Domain, approved, CQ23907 maven/mavencentral/org.reactivestreams/reactive-streams/1.0.4, CC0-1.0, approved, CQ16332 maven/mavencentral/org.slf4j/jul-to-slf4j/2.0.13, MIT, approved, #7698 maven/mavencentral/org.slf4j/slf4j-api/2.0.13, MIT, approved, #5915 diff --git a/charts/digital-product-pass/Chart.yaml b/charts/digital-product-pass/Chart.yaml index e0822b687..c928b4b0c 100644 --- a/charts/digital-product-pass/Chart.yaml +++ b/charts/digital-product-pass/Chart.yaml @@ -42,7 +42,7 @@ type: application # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 2.3.3 +version: 2.3.6 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/digital-product-pass/templates/configmap-backend.yaml b/charts/digital-product-pass/templates/configmap-backend.yaml index 76fd3bb42..b69658cae 100644 --- a/charts/digital-product-pass/templates/configmap-backend.yaml +++ b/charts/digital-product-pass/templates/configmap-backend.yaml @@ -64,6 +64,7 @@ data: transfer: {{ .Values.backend.edc.apis.transfer }} receiverEndpoint: "https://{{ .Values.backend.hostname }}/endpoint" delay: {{ .Values.backend.edc.delay }} # -- Negotiation status Delay in milliseconds in between async requests [<= 500] + authorizationKey: {{ .Values.backend.edc.authorizationKey }} # -- security configuration security: # -- authorization configuration about bpn and role checks diff --git a/charts/digital-product-pass/values-int.yaml b/charts/digital-product-pass/values-int.yaml index 52c5d1444..3c8b23d22 100644 --- a/charts/digital-product-pass/values-int.yaml +++ b/charts/digital-product-pass/values-int.yaml @@ -23,6 +23,8 @@ ################################################################################# backend: + image: + pullPolicy: Always ingress: enabled: true # className: "nginx" @@ -62,12 +64,14 @@ backend: discovery: hostname: "semantics.int.demo.catena-x.net/discoveryfinder" - single-api: + singleApi: maxRetries: 30 delay: 1000 frontend: + image: + pullPolicy: Always ingress: enabled: true #className: "" diff --git a/charts/digital-product-pass/values.yaml b/charts/digital-product-pass/values.yaml index eefa69963..7007c2e42 100644 --- a/charts/digital-product-pass/values.yaml +++ b/charts/digital-product-pass/values.yaml @@ -207,6 +207,7 @@ backend: rightOperand: "cx.circular.dpp:1" prohibition: [] obligation: [] + digitalTwinRegistry: endpoints: search: "/lookup/shells" diff --git a/docs/RELEASE_USER.md b/docs/RELEASE_USER.md index fd63362b9..c153b6bab 100644 --- a/docs/RELEASE_USER.md +++ b/docs/RELEASE_USER.md @@ -25,6 +25,25 @@ # Release Notes Digital Product Pass Application User friendly relase notes without especific technical details. + +**May 13 2024 (Version 3.0.0-rc1)** +*13.05.2024* + +### Added + +#### Data Sovereighty Configuration enabled + +Now in the backend configuration it is possible to add the policies required per contract. +The policy configuration guide can be found here: [Policy Configuration Guide](https://github.com/eclipse-tractusx/digital-product-pass/blob/main/docs/data-sovereignty/PolicyConfigGuide.md) + +#### Single API functionality enabled + +Now the backend allows users to access and retrieve information without pending of a frontend keyclock authentication. With a single api call `/api/data/request` and the API Key configured in the helm charts values, the backend is allowed to be accessed. + +#### EDC 0.7.0 integrated in the application + +The Digital Product Pass application now supports the latest edc version available. The new models and payloads have been integrated into the application. + **May 06 2024 (Version 2.3.0)** *06.05.2024* diff --git a/dpp-backend/digitalproductpass/lombok.config b/dpp-backend/digitalproductpass/lombok.config new file mode 100644 index 000000000..6f7933571 --- /dev/null +++ b/dpp-backend/digitalproductpass/lombok.config @@ -0,0 +1,28 @@ +################################################################################# +# Tractus-X - Digital Product Passport Application +# +# Copyright (c) 2022, 2024 BMW AG, Henkel AG & Co. KGaA +# Copyright (c) 2023, 2024 CGI Deutschland B.V. & Co. KG +# Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0. +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the +# License for the specific language govern in permissions and limitations +# under the License. +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################# + + +config.stopBubbling = true + +lombok.copyableAnnotations += com.fasterxml.jackson.annotation.JsonProperty \ No newline at end of file diff --git a/dpp-backend/digitalproductpass/pom.xml b/dpp-backend/digitalproductpass/pom.xml index 067ab85d3..120a0889a 100644 --- a/dpp-backend/digitalproductpass/pom.xml +++ b/dpp-backend/digitalproductpass/pom.xml @@ -35,10 +35,11 @@ org.eclipse.tractusx digitalproductpass - 2.3.0 + 3.0.0 jar Catena-X Digital Product Passport Backend - Digital Product Passport Consumer Backend Reference Implementation System for Product Passport Consumer Frontend Application + + Digital Product Passport Consumer Backend is a reference implementation system for retrieving aspect models of digital twins in the Catena-X Network. 19 @@ -156,6 +157,11 @@ spring-boot-starter-test test + + org.projectlombok + lombok + true + com.google.code.gson gson diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/http/controllers/AppController.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/http/controllers/AppController.java index 04fa30968..172ad7eb9 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/http/controllers/AppController.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/http/controllers/AppController.java @@ -273,23 +273,17 @@ public Response getDigitalTwin(@RequestBody Object body, @PathVariable String pr public EndpointDataReference getEndpointData(Object body) throws ControllerException { EndpointDataReference endpointData = edcUtil.parseDataPlaneEndpoint(body); if (endpointData == null) { - throw new ControllerException(this.getClass().getName(), "The endpoint data request is empty!"); + throw new ControllerException(this.getClass().getName(), "[EDR] The endpoint data request is empty!"); } - if (endpointData.getEndpoint().isEmpty()) { - throw new ControllerException(this.getClass().getName(), "The data plane endpoint address is empty!"); + EndpointDataReference.Properties properties = endpointData.getPayload().getDataAddress().getProperties(); + if (properties.getEndpoint().isEmpty()) { + throw new ControllerException(this.getClass().getName(), "[EDR] The data plane endpoint address is empty!"); } - if (endpointData.getAuthCode().isEmpty()) { - throw new ControllerException(this.getClass().getName(), "The authorization code is empty!"); + if (endpointData.getPayload().getDataAddress().getProperties().getEndpoint().isEmpty()) { + throw new ControllerException(this.getClass().getName(), "[EDR] The authorization code is empty!"); } - if (endpointData.getContractId().isEmpty() && !endpointData.offerIdExists()) { - Jwt token = httpUtil.parseToken(endpointData.getAuthCode()); - if (!token.getPayload().containsKey("cid") || token.getPayload().get("cid").equals("")) { - throw new ControllerException(this.getClass().getName(), "The Offer Id is empty!"); - } - return endpointData; - } - if (endpointData.getContractId().isEmpty()) { - throw new ControllerException(this.getClass().getName(), "The contractId is empty!"); + if (endpointData.getPayload().getContractId().isEmpty()) { + throw new ControllerException(this.getClass().getName(), "[EDR] The contractId is empty!"); } return endpointData; } diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/http/controllers/api/ApiController.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/http/controllers/api/ApiController.java index 811f80c71..6a53fe28b 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/http/controllers/api/ApiController.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/http/controllers/api/ApiController.java @@ -26,6 +26,7 @@ package org.eclipse.tractusx.digitalproductpass.http.controllers.api; +import com.fasterxml.jackson.core.type.TypeReference; import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -39,6 +40,7 @@ import org.eclipse.tractusx.digitalproductpass.config.PassportConfig; import org.eclipse.tractusx.digitalproductpass.config.SingleApiConfig; import org.eclipse.tractusx.digitalproductpass.managers.ProcessManager; +import org.eclipse.tractusx.digitalproductpass.models.general.Selection; import org.eclipse.tractusx.digitalproductpass.models.http.Response; import org.eclipse.tractusx.digitalproductpass.models.http.requests.DiscoverySearch; import org.eclipse.tractusx.digitalproductpass.models.http.requests.Search; @@ -47,6 +49,7 @@ import org.eclipse.tractusx.digitalproductpass.models.manager.Process; import org.eclipse.tractusx.digitalproductpass.models.manager.Status; import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Dataset; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.policy.Set; import org.eclipse.tractusx.digitalproductpass.models.passports.PassportResponse; import org.eclipse.tractusx.digitalproductpass.services.AasService; import org.eclipse.tractusx.digitalproductpass.services.AuthenticationService; @@ -58,10 +61,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import utils.HttpUtil; -import utils.JsonUtil; -import utils.LogUtil; -import utils.ThreadUtil; +import utils.*; import utils.exceptions.UtilException; import java.util.List; @@ -89,6 +89,8 @@ public class ApiController { private @Autowired AuthenticationService authService; private @Autowired PassportConfig passportConfig; private @Autowired HttpUtil httpUtil; + private @Autowired EdcUtil edcUtil; + private @Autowired PolicyUtil policyUtil; private @Autowired JsonUtil jsonUtil; private @Autowired ProcessManager processManager; private @Autowired SingleApiConfig singleApiConfig; @@ -176,7 +178,7 @@ public Response singleApi(@Valid @RequestBody SingleApiRequest singleApiRequestB try { createResponseData = (Map) jsonUtil.toMap(createResponse.getData()); } catch (UtilException e) { - response = httpUtil.getBadRequest("Create Call:\n" + e.getMessage()); + response = httpUtil.getInternalError("Failed in creating process: " + e.getMessage()); return httpUtil.buildResponse(response, httpResponse); } String processId= createResponseData.get("processId"); @@ -196,10 +198,10 @@ public Response singleApi(@Valid @RequestBody SingleApiRequest singleApiRequestB Map searchResponseData; Map contracts; try { - searchResponseData = (Map) jsonUtil.toMap(searchResponse.getData()); - contracts = (Map) jsonUtil.toMap(searchResponseData.get("contracts")); + searchResponseData = jsonUtil.bind(searchResponse.getData(), new TypeReference<>() {}); + contracts = jsonUtil.bind(searchResponseData.get("contracts"), new TypeReference<>() {}); } catch (UtilException e) { - response = httpUtil.getBadRequest("Search Call:\n" + e.getMessage()); + response = httpUtil.getInternalError("Failed to search for digital twin in dtrs: " + e.getMessage()); return httpUtil.buildResponse(response, httpResponse); } LogUtil.printMessage("[SINGLE API] [PROCESS "+processId + "] Search for contracts done! Digital Twin and Contracts available!"); @@ -207,8 +209,20 @@ public Response singleApi(@Valid @RequestBody SingleApiRequest singleApiRequestB TokenRequest tokenRequest = new TokenRequest(); tokenRequest.setToken(searchResponseData.get("token").toString()); tokenRequest.setProcessId(searchResponseData.get("id").toString()); - String contractId = contracts.entrySet().stream().findFirst().get().getKey(); - tokenRequest.setContractId(contractId); + // Get valid contract and policy + Selection selection = edcUtil.selectValidContractAndPolicy(contracts, passportConfig.getPolicyCheck()); + + if(selection == null){ + LogUtil.printError("[SINGLE API] [PROCESS "+processId + "] No valid contracts and policies found!"); + response = httpUtil.getNotFound("No valid contracts and policies were found in the asset negotiation!"); + return httpUtil.buildResponse(response, httpResponse); + } + LogUtil.printMessage("[SINGLE API] [PROCESS "+processId + "] Selected [CONTRACT "+selection.d().getId()+"]:["+this.jsonUtil.toJson(selection.d(), false)+"]!"); + LogUtil.printMessage("[SINGLE API] [PROCESS "+processId + "] Selected [POLICY "+selection.s().getId()+"]:["+this.jsonUtil.toJson(selection.s(), false)+"]!"); + // Set contract + tokenRequest.setContractId(selection.d().getId()); + // Set policy id + tokenRequest.setPolicyId(selection.s().getId()); Response agreeResponse = contractService.doContractAgreement(httpRequest, httpResponse, tokenRequest); LogUtil.printMessage("[SINGLE API] [PROCESS "+processId + "] Agreed with a contract and started the contract negotiation!"); //The Status from the response must 200 to proceed @@ -220,7 +234,7 @@ public Response singleApi(@Valid @RequestBody SingleApiRequest singleApiRequestB try { status = (Status) jsonUtil.bindObject(agreeResponse.getData(), Status.class); } catch (UtilException e) { - response = httpUtil.getBadRequest("Agree Call:\n" + e.getMessage()); + response = httpUtil.getInternalError("Failed to agree in the contract policy: " + e.getMessage()); return httpUtil.buildResponse(response, httpResponse); } int retry = 1; @@ -239,7 +253,7 @@ public Response singleApi(@Valid @RequestBody SingleApiRequest singleApiRequestB ++retry; ThreadUtil.sleep(singleApiConfig.getDelay()); } catch (Exception e) { - response = httpUtil.getBadRequest("Status Call:\n" + e.getMessage()); + response = httpUtil.getBadRequest("Failed to look for process status: " + e.getMessage()); return httpUtil.buildResponse(response, httpResponse); } } diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/listeners/AppListener.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/listeners/AppListener.java index 4266d0f82..4dba2e74f 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/listeners/AppListener.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/listeners/AppListener.java @@ -113,8 +113,7 @@ public void started() { LogUtil.printMessage( "[ EDC Connection Test ] EDC consumer is ready and accessible!"); if(bpnCheck) { - String bpnNumber = dataTransferService.getEdcConnectorBpn(); - if (!participantId.equals(bpnNumber)) { + if (!dataTransferService.isApplicationEdc(participantId)) { throw new Exception("[" + this.getClass().getName() + ".onStartUp] Incorrect BPN Number configuration, expected the same participant id as the EDC consumer!"); } @@ -217,6 +216,7 @@ public void onStartUp() { "**********************************************************************\n\n" + " " + buildProperties.getName() + "\n" + " Copyright (c) 2022, 2024: BMW AG, Henkel AG & Co. KGaA\n" + + " Copyright (c) 2023, 2024: CGI Deutschland B.V. & Co. KG\n" + " Copyright (c) 2022, 2024: Contributors to the Eclipse Foundation.\n\n" + "**********************************************************************\n\n"; System.out.print(serverStartUpMessage); 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 5f573f917..4a2825b34 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 @@ -38,7 +38,7 @@ import org.eclipse.tractusx.digitalproductpass.models.http.responses.IdResponse; import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Catalog; import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Dataset; -import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Offer; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Policy; import org.eclipse.tractusx.digitalproductpass.models.negotiation.policy.Set; import org.eclipse.tractusx.digitalproductpass.models.negotiation.response.Negotiation; import org.eclipse.tractusx.digitalproductpass.services.DataTransferService; @@ -46,6 +46,7 @@ import org.springframework.stereotype.Component; import utils.*; +import java.lang.reflect.Type; import java.nio.file.Path; import java.time.Duration; @@ -157,7 +158,7 @@ public void run() { state = State.Finished; } catch (Exception e) { state = State.Error; - throw new DataModelException(this.getClass().getName(), e, "Was not possible to process the DTRs"); + throw new DataModelException(this.getClass().getName(), e, "It was not possible find any valid digital twin registry!"); } } }; @@ -206,7 +207,7 @@ public void run() { public void searchEndpoint(String processId, String bpn, String endpoint) { //Search Digital Twin Catalog for each connectionURL with a timeout time - SearchDtrCatalog searchDtrCatalog = new SearchDtrCatalog(endpoint); + SearchDtrCatalog searchDtrCatalog = new SearchDtrCatalog(endpoint, bpn); Thread asyncThread = ThreadUtil.runThread(searchDtrCatalog, "SearchEndpoint-" + processId + "-" + bpn + "-" + endpoint); Dtr dtr = new Dtr("", endpoint, "", bpn, DateTimeUtil.addHoursToCurrentTimestamp(dtrConfig.getTemporaryStorage().getLifetime()), true); try { @@ -249,13 +250,22 @@ public void searchEndpoint(String processId, String bpn, String endpoint) { return; } if (contractOffers instanceof LinkedHashMap) { - Dataset dataset = (Dataset) jsonUtil.bindObject(contractOffers, Dataset.class); + Dataset dataset = jsonUtil.bind(contractOffers, new TypeReference<>() {}); if (dataset != null) { // Store the dataset in the digital twin logs Map datasets = new HashMap<>() {{ put(dataset.getId(), dataset); }}; - Thread singleOfferThread = ThreadUtil.runThread(createAndSaveDtr(datasets, bpn, providerBpn, endpoint, processId), "CreateAndSaveDtr-" + processId + "-" + bpn + "-" + endpoint); + + Selection contractAndPolicy = getDtrDataset(datasets); + if (contractAndPolicy == null) { + throw new ManagerException("DtrSearchManager.searchEndpoint", "There was no valid policy available for the digital twin registry found!"); + } + + LogUtil.printMessage("[DTR-AUTO-NEGOTIATION] [PROCESS "+processId + "] Selected [CONTRACT "+contractAndPolicy.d().getId()+"]:["+this.jsonUtil.toJson(contractAndPolicy.d(), false)+"]!"); + LogUtil.printMessage("[DTR-AUTO-NEGOTIATION] [PROCESS "+processId + "] Selected [POLICY "+contractAndPolicy.s().getId()+"]:["+this.jsonUtil.toJson(contractAndPolicy.s(), false)+"]!"); + + Thread singleOfferThread = ThreadUtil.runThread(createAndSaveDtr(contractAndPolicy, datasets, bpn, providerBpn, endpoint, processId), "CreateAndSaveDtr-" + processId + "-" + bpn + "-" + endpoint); try { if (!singleOfferThread.join(Duration.ofSeconds(this.dtrRequestProcessTimeout))) { singleOfferThread.interrupt(); @@ -268,14 +278,20 @@ public void searchEndpoint(String processId, String bpn, String endpoint) { } return; } - List contractOfferList = (List) jsonUtil.bindObject(contractOffers, List.class); - if (contractOfferList.isEmpty()) { + List contractOfferList = jsonUtil.bind(contractOffers, new TypeReference<>() {}); + if (contractOfferList == null || contractOfferList.isEmpty()) { return; } Map datasets = edcUtil.mapDatasetsById(contractOfferList); + Selection contractAndPolicy = getDtrDataset(datasets); + if (contractAndPolicy == null) { + throw new ManagerException("DtrSearchManager.searchEndpoint", "There was no valid policy available for the digital twin registry found!"); + } + LogUtil.printMessage("[DTR-AUTO-NEGOTIATION] [PROCESS "+processId + "] Selected [CONTRACT "+contractAndPolicy.d().getId()+"]:["+this.jsonUtil.toJson(contractAndPolicy.d(), false)+"]!"); + LogUtil.printMessage("[DTR-AUTO-NEGOTIATION] [PROCESS "+processId + "] Selected [POLICY "+contractAndPolicy.s().getId()+"]:["+this.jsonUtil.toJson(contractAndPolicy.s(), false)+"]!"); // Store datasets in the digital twin logs contractOfferList.parallelStream().forEach(dataset -> { - Thread multipleOffersThread = ThreadUtil.runThread(createAndSaveDtr(datasets, bpn, providerBpn, endpoint, processId), "CreateAndSaveDtr-" + processId + "-" + bpn + "-" + endpoint); + Thread multipleOffersThread = ThreadUtil.runThread(createAndSaveDtr(contractAndPolicy, datasets, bpn, providerBpn, endpoint, processId), "CreateAndSaveDtr-" + processId + "-" + bpn + "-" + endpoint); try { if (!multipleOffersThread.join(Duration.ofSeconds(this.dtrRequestProcessTimeout))) { multipleOffersThread.interrupt(); @@ -339,9 +355,11 @@ public String getDataModelDir() { public class SearchDtrCatalog implements Runnable { Boolean error = true; String connectionUrl; + String bpn; - SearchDtrCatalog(String connectionUrl) { + public SearchDtrCatalog(String connectionUrl, String bpn) { this.connectionUrl = connectionUrl; + this.bpn = bpn; } public Boolean isError() { @@ -351,7 +369,7 @@ public Boolean isError() { @Override public void run() { try { - Catalog catalog = dataTransferService.searchDigitalTwinCatalog(connectionUrl); + Catalog catalog = dataTransferService.searchDigitalTwinCatalog(connectionUrl, bpn); if (catalog == null) { return; } @@ -484,23 +502,19 @@ public Selection getDtrDataset(Map datasets) { * for a given BPN number and an URL connection into a process with the given process id. *

* - * @param datasets the {@code Map} data for the contract offer. + * @param contractAndPolicy the {@code Selection} the selected contract and policy + * @param datasets the {@code Map} map of contracts available * @param bpn the {@code String} bpn number. * @param connectionUrl the {@code String} URL connection of the Digital Twin. * @param processId the {@code String} id of the application's process. * @return a {@code Runnable} object to be used by a calling thread. * @throws ManagerException if unable to do the contract negotiation for the DTR. */ - private Runnable createAndSaveDtr(Map datasets, String bpn, String providerBpn, String connectionUrl, String processId) { + private Runnable createAndSaveDtr(Selection contractAndPolicy, Map datasets, String bpn, String providerBpn, String connectionUrl, String processId) { return new Runnable() { @Override public void run() { try { - Selection contractAndPolicy = getDtrDataset(datasets); - if (contractAndPolicy == null) { - LogUtil.printError("It was not possible to get the dataset contract and policy!"); - return; - } Dataset dataset = contractAndPolicy.d(); // Get the contract element if (dataset == null) { LogUtil.printError("It was not possible to get the contract!"); @@ -512,9 +526,9 @@ public void run() { return; } - Offer offer = dataTransferService.buildOffer(dataset, set); + Policy policy = dataTransferService.buildOffer(dataset, set, providerBpn); String builtDataEndpoint = CatenaXUtil.buildDataEndpoint(connectionUrl); - IdResponse negotiationResponse = dataTransferService.doContractNegotiation(offer, bpn, providerBpn, builtDataEndpoint); + IdResponse negotiationResponse = dataTransferService.doContractNegotiation(policy, builtDataEndpoint); if (negotiationResponse == null) { return; } @@ -537,9 +551,8 @@ public void run() { } processManager.addSearchStatusDtr(processId, dtr); - } catch (Exception e) { - throw new ManagerException(this.getClass().getName() + ".createAndSaveDtr", e, "Failed to save the dataModel for this connection url: " + connectionUrl); + throw new ManagerException(this.getClass().getName() + ".createAndSaveDtr", e, "Failed to create the digital twin registry for url: " + connectionUrl); } } }; diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/managers/ProcessManager.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/managers/ProcessManager.java index d1aba06be..24d06f739 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/managers/ProcessManager.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/managers/ProcessManager.java @@ -1056,9 +1056,7 @@ public String cancelProcess(HttpServletRequest httpRequest, String processId) { * if unable to update the status file. */ public String setAgreed(HttpServletRequest httpRequest, String processId, Long signedAt, String contractId, String policyId) { - this.setProcessState(httpRequest, processId, "STARTING"); - return this.setStatus(processId, "contract-agreed", new History( contractId+"/"+policyId, "AGREED", @@ -1474,7 +1472,7 @@ public String setEndpoint(String processId, String endpoint, String dataPlaneUrl */ public String getContractId(EndpointDataReference endpointData){ - return endpointData.getContractId(); + return endpointData.getPayload().getContractId(); } /** diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/edc/AssetSearch.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/edc/AssetSearch.java index 0300662f3..0e15ccb9e 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/edc/AssetSearch.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/edc/AssetSearch.java @@ -39,6 +39,9 @@ public class AssetSearch { /** ATTRIBUTES **/ @JsonProperty("assetId") String assetId; + + @JsonProperty("bpn") + String bpn; @JsonProperty("connectorAddress") String connectorAddress; @@ -52,6 +55,12 @@ public AssetSearch(String assetId, String connectorAddress) { this.connectorAddress = connectorAddress; } + public AssetSearch(String assetId, String bpn, String connectorAddress) { + this.assetId = assetId; + this.bpn = bpn; + this.connectorAddress = connectorAddress; + } + /** GETTERS AND SETTERS **/ public String getAssetId() { @@ -67,4 +76,11 @@ public void setConnectorAddress(String connectorAddress) { this.connectorAddress = connectorAddress; } + public String getBpn() { + return bpn; + } + + public void setBpn(String bpn) { + this.bpn = bpn; + } } diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/edc/EndpointDataReference.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/edc/EndpointDataReference.java index 2dad14b5f..38ed4a70d 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/edc/EndpointDataReference.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/edc/EndpointDataReference.java @@ -26,215 +26,151 @@ package org.eclipse.tractusx.digitalproductpass.models.edc; -import com.fasterxml.jackson.annotation.JsonAlias; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.JsonNode; +import lombok.*; +import lombok.extern.jackson.Jacksonized; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.CallbackAddress; import org.eclipse.tractusx.digitalproductpass.models.negotiation.DidDocument; +import java.util.List; +import java.util.Properties; + /** * This class consists exclusively to define attributes related to Endpoint Data Reference (EDR) received from the EDC. - **/ + * */ @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_NULL) -public class EndpointDataReference extends DidDocument { +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Jacksonized +@Data +@Getter +public class EndpointDataReference { + + /** CONSTANTS **/ + @JsonIgnore + private static final String W3C_EDC = "https://w3id.org/edc/v0.0.1/ns/"; + @JsonIgnore + private static final String W3C_TRACTUSX = "https://w3id.org/tractusx/auth/"; /** ATTRIBUTES **/ @JsonProperty("id") @JsonAlias({"id", "edc:id"}) String id; + @JsonProperty("at") + @JsonAlias({"at", "edc:at"}) + Long at; + @JsonProperty("type") @JsonAlias({"type", "edc:type"}) - String edrType; - @JsonProperty("endpoint") - @JsonAlias({"endpoint", "edc:endpoint"}) - String endpoint; - @JsonProperty("properties") - @JsonAlias({"properties", "edc:properties"}) - Properties properties; - @JsonProperty("contractId") - @JsonAlias({"contractId", "edc:contractId"}) - String contractId; - @JsonProperty("authKey") - @JsonAlias({"authKey", "edc:authKey"}) - String authKey; - @JsonProperty("authCode") - @JsonAlias({"authCode", "edc:authCode"}) - String authCode; - - /** CONSTRUCTOR(S) **/ - @SuppressWarnings("Unused") - public EndpointDataReference(String id, String endpoint, String authKey, String authCode) { - this.id = id; - this.endpoint = endpoint; - this.authKey = authKey; - this.authCode = authCode; - } - @SuppressWarnings("Unused") - public EndpointDataReference() { - } - - public EndpointDataReference(String id, String type, String id1, String edrType, String endpoint, String contractId, String authKey, String authCode) { - super(id, type); - this.id = id1; - this.edrType = edrType; - this.endpoint = endpoint; - this.contractId = contractId; - this.authKey = authKey; - this.authCode = authCode; - } - - public EndpointDataReference(JsonNode context, String id, String edrType, String endpoint, Properties properties, String contractId, String authKey, String authCode) { - super(context); - this.id = id; - this.edrType = edrType; - this.endpoint = endpoint; - this.properties = properties; - this.contractId = contractId; - this.authKey = authKey; - this.authCode = authCode; - } - - public EndpointDataReference(String id, String edrType, String endpoint, String contractId, String authKey, String authCode) { - this.id = id; - this.edrType = edrType; - this.endpoint = endpoint; - this.contractId = contractId; - this.authKey = authKey; - this.authCode = authCode; - } - - public EndpointDataReference(String id, String type, JsonNode context, String id1, String edrType, String endpoint, String contractId, String authKey, String authCode) { - super(id, type, context); - this.id = id1; - this.edrType = edrType; - this.endpoint = endpoint; - this.contractId = contractId; - this.authKey = authKey; - this.authCode = authCode; - } - - public EndpointDataReference(String type, String id, String edrType, String endpoint, String contractId, String authKey, String authCode) { - super(type); - this.id = id; - this.edrType = edrType; - this.endpoint = endpoint; - this.contractId = contractId; - this.authKey = authKey; - this.authCode = authCode; - } - - public EndpointDataReference(String id, String type, JsonNode context, String id1, String edrType, String endpoint, Properties properties, String contractId, String authKey, String authCode) { - super(id, type, context); - this.id = id1; - this.edrType = edrType; - this.endpoint = endpoint; - this.properties = properties; - this.contractId = contractId; - this.authKey = authKey; - this.authCode = authCode; - } - - public EndpointDataReference(JsonNode context, String id, String edrType, String endpoint, String contractId, String authKey, String authCode) { - super(context); - this.id = id; - this.edrType = edrType; - this.endpoint = endpoint; - this.contractId = contractId; - this.authKey = authKey; - this.authCode = authCode; - } - - public EndpointDataReference(String id, String type, String id1, String edrType, String endpoint, Properties properties, String contractId, String authKey, String authCode) { - super(id, type); - this.id = id1; - this.edrType = edrType; - this.endpoint = endpoint; - this.properties = properties; - this.contractId = contractId; - this.authKey = authKey; - this.authCode = authCode; - } - + String type; - /** GETTERS AND SETTERS **/ - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - public String getEndpoint() { - return endpoint; - } - public void setEndpoint(String endpoint) { - this.endpoint = endpoint; - } - public String getAuthKey() { - return authKey; - } - @SuppressWarnings("Unused") - public void setAuthKey(String authKey) { - this.authKey = authKey; - } - public String getAuthCode() { - return authCode; - } - @SuppressWarnings("Unused") - public void setAuthCode(String authCode) { - this.authCode = authCode; - } + @JsonProperty("payload") + @JsonAlias({"payload", "edc:payload"}) + Payload payload; - public String getContractId() { - return contractId; - } - - public void setContractId(String contractId) { - this.contractId = contractId; - } - - public String getEdrType() { - return edrType; - } - - public void setEdrType(String edrType) { - this.edrType = edrType; - } - - /** METHODS **/ - /** - * Checks if offerId exists in the properties attribute. - *

- * - * @return true if the offerId exists, false otherwise. - * - */ /** INNER CLASSES **/ - /** - * This class consists exclusively to define attributes related to the Asset search's properties. - **/ - @JsonIgnoreProperties(ignoreUnknown = true) - @JsonInclude(JsonInclude.Include.NON_NULL) - static class Properties { - @JsonProperty("https://w3id.org/edc/v0.0.1/ns/cid") - String offerId; - } - public Boolean offerIdExists(){ - try { - return this.properties != null && this.properties.offerId != null; - }catch (Exception e){ - // Do nothing because is non-existent the offer id - } - return false; - } - public Properties getProperties() { - return properties; + @Builder + @Data + @NoArgsConstructor + @AllArgsConstructor + @Jacksonized + public static class Payload { + @JsonProperty("transferProcessId") + @JsonAlias({"transferProcessId", "edc:transferProcessId"}) + String transferProcessId; + @JsonProperty("callbackAddresses") + @JsonAlias({"callbackAddresses", "edc:callbackAddresses"}) + List callbackAddresses; + + @JsonProperty("assetId") + @JsonAlias({"assetId", "edc:assetId"}) + String assetId; + + @JsonProperty("type") + @JsonAlias({"type", "edc:type"}) + String type; + + @JsonProperty("contractId") + @JsonAlias({"contractId", "edc:contractId"}) + String contractId; + + @JsonProperty("dataAddress") + @JsonAlias({"dataAddress", "edc:dataAddress"}) + DataAddress dataAddress; + } + @Builder + @Data + @NoArgsConstructor + @AllArgsConstructor + @Jacksonized + public static class DataAddress{ + @JsonProperty("properties") + @JsonAlias({"properties", "edc:properties"}) + Properties properties; + } + + @Builder + @Data + @NoArgsConstructor + @AllArgsConstructor + @Jacksonized + public static class Properties{ + @JsonProperty("processId") + @JsonAlias({"process_id", "edc:process_id"}) + String processId; + @JsonProperty("participantId") + @JsonAlias({"participant_id", "edc:participant_id"}) + String participantId; + + @JsonProperty("assetId") + @JsonAlias({"asset_id", "edc:asset_id"}) + String assetId; + + @JsonProperty("endpointType") + @JsonAlias({W3C_EDC+"endpointType", "endpointType", "edc:endpointType"}) + String endpointType; + + @JsonProperty("refreshEndpoint") + @JsonAlias({W3C_TRACTUSX+"refreshEndpoint", "refreshEndpoint", "edc:refreshEndpoint"}) + String refreshEndpoint; + + @JsonProperty("audience") + @JsonAlias({W3C_TRACTUSX+"audience", "audience", "edc:audience"}) + String audience; + + @JsonProperty("agreementId") + @JsonAlias({"agreement_id", "edc:agreement_id"}) + String agreement_id; + + @JsonProperty("flowType") + @JsonAlias({"flow_type", "edc:flow_type"}) + String flow_type; + + @JsonProperty("type") + @JsonAlias({W3C_EDC+"type", "type", "edc:type"}) + String type; + + @JsonProperty("endpoint") + @JsonAlias({W3C_EDC+"endpoint", "endpoint", "edc:endpoint"}) + String endpoint; + @JsonProperty("refreshToken") + @JsonAlias({W3C_TRACTUSX+"refreshToken", "refreshToken", "edc:refreshToken"}) + String refreshToken; + + @JsonProperty("expiresIn") + @JsonAlias({W3C_TRACTUSX+"expiresIn", "expiresIn", "edc:expiresIn"}) + String expiresIn; + + @JsonProperty("authorization") + @JsonAlias({W3C_EDC+"authorization", "authorization", "edc:authorization"}) + String authorization; + + @JsonProperty("refreshAudience") + @JsonAlias({W3C_TRACTUSX+"refreshAudience", "refreshAudience", "edc:refreshAudience"}) + String refreshAudience; } - - public void setProperties(Properties properties) { - this.properties = properties; - } - } diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/http/requests/SingleApiRequest.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/http/requests/SingleApiRequest.java index e7dd40183..672a53b8b 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/http/requests/SingleApiRequest.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/http/requests/SingleApiRequest.java @@ -51,7 +51,7 @@ public class SingleApiRequest { @JsonProperty(value="discoveryIdType", defaultValue = "manufacturerPartId") String discoveryIdType; - @JsonProperty("children") + @JsonProperty(value="children", defaultValue = "false") Boolean children; @JsonProperty("semanticId") diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/CallbackAddress.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/CallbackAddress.java index f86949c20..4d50a0e7a 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/CallbackAddress.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/CallbackAddress.java @@ -29,6 +29,11 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.extern.jackson.Jacksonized; import java.util.List; @@ -37,6 +42,11 @@ **/ @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_NULL) +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +@Jacksonized public class CallbackAddress { /** * ATTRIBUTES @@ -51,65 +61,7 @@ public class CallbackAddress { String authKey; @JsonProperty("authCodeId") String authCodeId; - /** - * CONSTRUCTORS - **/ - - public CallbackAddress(Boolean transactional, String uri, String authKey, String authCodeId) { - this.transactional = transactional; - this.uri = uri; - this.authKey = authKey; - this.authCodeId = authCodeId; - } - - public CallbackAddress(Boolean transactional, String uri, List events) { - this.transactional = transactional; - this.uri = uri; - this.events = events; - } - - /** - * GETTERS AND SETTERS - **/ - - public Boolean getTransactional() { - return transactional; - } - - public void setTransactional(Boolean transactional) { - this.transactional = transactional; - } - - public String getUri() { - return uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public String getAuthKey() { - return authKey; - } - - public void setAuthKey(String authKey) { - this.authKey = authKey; - } - - public String getAuthCodeId() { - return authCodeId; - } - - public void setAuthCodeId(String authCodeId) { - this.authCodeId = authCodeId; - } - public List getEvents() { - return events; - } - public void setEvents(List events) { - this.events = events; - } } diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/DidDocument.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/DidDocument.java index 8ad30b4f4..5cfb1d335 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/DidDocument.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/DidDocument.java @@ -26,6 +26,7 @@ package org.eclipse.tractusx.digitalproductpass.models.negotiation; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -38,11 +39,18 @@ @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_NULL) public class DidDocument { + @JsonIgnore + public static final String ID = "@id"; + @JsonIgnore + public static final String TYPE = "@type"; + @JsonIgnore + public static final String CONTEXT = "@context"; /** ATTRIBUTES **/ - @JsonProperty("@id") + @JsonProperty(ID) public String id; - @JsonProperty("@type") + + @JsonProperty(TYPE) public String type; @JsonProperty("@context") @@ -69,6 +77,10 @@ public DidDocument(String type) { public DidDocument(JsonNode context) { this.context = context; } + public DidDocument(JsonNode context, String type) { + this.context = context; + this.type = type; + } /** GETTERS AND SETTERS **/ public String getId() { diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Catalog.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Catalog.java index 68cc5fa26..a74197d06 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Catalog.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Catalog.java @@ -49,7 +49,7 @@ public class Catalog extends DidDocument { @JsonProperty("dcat:service") DataService service; @JsonProperty("participantId") - @JsonAlias({"participantId", "edc:participantId"}) + @JsonAlias({"participantId", "edc:participantId", "dspace:participantId"}) String participantId; @JsonIgnore protected Map contractOffersMap = new HashMap<>(); diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/CatalogRequest.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/CatalogRequest.java index 92d19d49b..475817bca 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/CatalogRequest.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/CatalogRequest.java @@ -46,6 +46,8 @@ public class CatalogRequest extends DidDocument { String protocol; @JsonProperty("counterPartyAddress") String counterPartyAddress; + @JsonProperty("counterPartyId") + String counterPartyId; @JsonProperty("querySpec") QuerySpec querySpec; @@ -67,6 +69,52 @@ public CatalogRequest(JsonNode context, String protocol, String counterPartyAddr public CatalogRequest() { } + public CatalogRequest(String id, String type, String protocol, String counterPartyAddress, String counterPartyId, QuerySpec querySpec) { + super(id, type); + this.protocol = protocol; + this.counterPartyAddress = counterPartyAddress; + this.counterPartyId = counterPartyId; + this.querySpec = querySpec; + } + + public CatalogRequest(String protocol, String counterPartyAddress, String counterPartyId, QuerySpec querySpec) { + this.protocol = protocol; + this.counterPartyAddress = counterPartyAddress; + this.counterPartyId = counterPartyId; + this.querySpec = querySpec; + } + + public CatalogRequest(String id, String type, JsonNode context, String protocol, String counterPartyAddress, String counterPartyId, QuerySpec querySpec) { + super(id, type, context); + this.protocol = protocol; + this.counterPartyAddress = counterPartyAddress; + this.counterPartyId = counterPartyId; + this.querySpec = querySpec; + } + + public CatalogRequest(String type, String protocol, String counterPartyAddress, String counterPartyId, QuerySpec querySpec) { + super(type); + this.protocol = protocol; + this.counterPartyAddress = counterPartyAddress; + this.counterPartyId = counterPartyId; + this.querySpec = querySpec; + } + + public CatalogRequest(JsonNode context, String protocol, String counterPartyAddress, String counterPartyId, QuerySpec querySpec) { + super(context); + this.protocol = protocol; + this.counterPartyAddress = counterPartyAddress; + this.counterPartyId = counterPartyId; + this.querySpec = querySpec; + } + public CatalogRequest(JsonNode context, String protocol, String counterPartyAddress, String counterPartyId, QuerySpec querySpec, String type) { + super(context, type); + this.protocol = protocol; + this.counterPartyAddress = counterPartyAddress; + this.counterPartyId = counterPartyId; + this.querySpec = querySpec; + } + /** GETTERS AND SETTERS **/ public String getProtocol() { return protocol; @@ -91,6 +139,14 @@ public void setQuerySpec(QuerySpec querySpec) { this.querySpec = querySpec; } + public String getCounterPartyId() { + return counterPartyId; + } + + public void setCounterPartyId(String counterPartyId) { + this.counterPartyId = counterPartyId; + } + /** INNER CLASSES **/ /** * This class consists exclusively to define attributes related to the Query specification of the Catalog request. diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Distribution.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Distribution.java index ccd80e429..b864c0bfb 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Distribution.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Distribution.java @@ -29,6 +29,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.DataService; import org.eclipse.tractusx.digitalproductpass.models.negotiation.DidDocument; /** @@ -40,60 +42,65 @@ public class Distribution extends DidDocument { /** ATTRIBUTES **/ @JsonProperty("dct:format") - Format format; + DidDocument format; @JsonProperty("dcat:accessService") - String accessService; + DataService accessService; /** CONSTRUCTOR(S) **/ - public Distribution(String type, Format format, String accessService) { - this.type = type; + + public Distribution() { + } + + public Distribution(String id, String type, DidDocument format, DataService accessService) { + super(id, type); this.format = format; this.accessService = accessService; } - public Distribution() { + + public Distribution(DidDocument format, DataService accessService) { + this.format = format; + this.accessService = accessService; } + public Distribution(String id, String type, JsonNode context, DidDocument format, DataService accessService) { + super(id, type, context); + this.format = format; + this.accessService = accessService; + } + + public Distribution(String type, DidDocument format, DataService accessService) { + super(type); + this.format = format; + this.accessService = accessService; + } + + public Distribution(JsonNode context, DidDocument format, DataService accessService) { + super(context); + this.format = format; + this.accessService = accessService; + } + + public Distribution(JsonNode context, String type, DidDocument format, DataService accessService) { + super(context, type); + this.format = format; + this.accessService = accessService; + } /** GETTERS AND SETTERS **/ - public Format getFormat() { + + public DidDocument getFormat() { return format; } - public void setFormat(Format format) { + + public void setFormat(DidDocument format) { this.format = format; } - @SuppressWarnings("Unused") - public String getAccessService() { + + public DataService getAccessService() { return accessService; } - @SuppressWarnings("Unused") - public void setAccessService(String accessService) { - this.accessService = accessService; - } - /** INNER CLASSES **/ - /** - * This class consists exclusively to define attributes related to the Distribution's format property. - **/ - static class Format { - /** ATTRIBUTES **/ - @JsonProperty("@id") - String id; - - /** CONSTRUCTOR(S) **/ - @SuppressWarnings("Unused") - public Format(String id) { - this.id = id; - } - @SuppressWarnings("Unused") - public Format() { - } - - /** GETTERS AND SETTERS **/ - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } + public void setAccessService(DataService accessService) { + this.accessService = accessService; } diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Offer.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Offer.java deleted file mode 100644 index 26561ad17..000000000 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Offer.java +++ /dev/null @@ -1,78 +0,0 @@ -/********************************************************************************* - * - * Tractus-X - Digital Product Passport Application - * - * Copyright (c) 2022, 2024 BMW AG, Henkel AG & Co. KGaA - * Copyright (c) 2023, 2024 CGI Deutschland B.V. & Co. KG - * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation - * - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the - * License for the specific language govern in permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.eclipse.tractusx.digitalproductpass.models.negotiation.policy.Set; - -/** - * This class consists exclusively to define attributes related to the Offer's data. - **/ -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -public class Offer { - - /** ATTRIBUTES **/ - @JsonProperty("offerId") - String offerId; - @JsonProperty("assetId") - String assetId; - @JsonProperty("policy") - Set policy; - - /** CONSTRUCTOR(S) **/ - public Offer(String offerId, String assetId, Set policy) { - this.offerId = offerId; - this.assetId = assetId; - this.policy = policy; - } - public Offer() { - } - - /** GETTERS AND SETTERS **/ - public String getOfferId() { - return offerId; - } - @SuppressWarnings("Unused") - public void setOfferId(String offerId) { - this.offerId = offerId; - } - public String getAssetId() { - return assetId; - } - public void setAssetId(String assetId) { - this.assetId = assetId; - } - public Set getPolicy() { - return policy; - } - public void setPolicy(Set policy) { - this.policy = policy; - } -} diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Policy.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Policy.java new file mode 100644 index 000000000..36ba0d537 --- /dev/null +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/catalog/Policy.java @@ -0,0 +1,168 @@ +/********************************************************************************* + * + * Tractus-X - Digital Product Passport Application + * + * Copyright (c) 2022, 2024 BMW AG, Henkel AG & Co. KGaA + * Copyright (c) 2023, 2024 CGI Deutschland B.V. & Co. KG + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation + * + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the + * License for the specific language govern in permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; +import org.eclipse.tractusx.digitalproductpass.config.PolicyCheckConfig; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.DidDocument; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.policy.Action; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.policy.Set; + +import java.util.List; + +/** + * Policy representing the offer from the catalog + **/ +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Policy extends Set { + + /** + * ATTRIBUTES + **/ + @JsonProperty("odrl:target") + DidDocument target; + @JsonProperty("odrl:assigner") + DidDocument assigner; + + /** CONSTRUCTOR(S) **/ + + public Policy(String id, String type, List permissions, List prohibitions, List obligations, DidDocument target, DidDocument assigner) { + super(id, type, permissions, prohibitions, obligations); + this.target = target; + this.assigner = assigner; + } + + public Policy(List permissions, List prohibitions, List obligations, DidDocument target, DidDocument assigner) { + super(permissions, prohibitions, obligations); + this.target = target; + this.assigner = assigner; + } + + public Policy(String id, String type, JsonNode context, List permissions, List prohibitions, List obligations, DidDocument target, DidDocument assigner) { + super(id, type, context, permissions, prohibitions, obligations); + this.target = target; + this.assigner = assigner; + } + + public Policy(String type, List permissions, List prohibitions, List obligations, DidDocument target, DidDocument assigner) { + super(type, permissions, prohibitions, obligations); + this.target = target; + this.assigner = assigner; + } + + public Policy(JsonNode context, List permissions, List prohibitions, List obligations, DidDocument target, DidDocument assigner) { + super(context, permissions, prohibitions, obligations); + this.target = target; + this.assigner = assigner; + } + + public Policy(String id, String type, DidDocument target, DidDocument assigner) { + super(id, type); + this.target = target; + this.assigner = assigner; + } + + public Policy(DidDocument target, DidDocument assigner) { + this.target = target; + this.assigner = assigner; + } + + public Policy(PolicyCheckConfig.PolicyConfig policyConfig, DidDocument target, DidDocument assigner) { + super(policyConfig); + this.target = target; + this.assigner = assigner; + } + + public Policy(String id, String type, List permissions, List prohibitions, List obligations) { + super(id, type, permissions, prohibitions, obligations); + } + + public Policy(List permissions, List prohibitions, List obligations) { + super(permissions, prohibitions, obligations); + } + + public Policy(String id, String type, JsonNode context, List permissions, List prohibitions, List obligations) { + super(id, type, context, permissions, prohibitions, obligations); + } + + public Policy(String type, List permissions, List prohibitions, List obligations) { + super(type, permissions, prohibitions, obligations); + } + + public Policy(JsonNode context, List permissions, List prohibitions, List obligations) { + super(context, permissions, prohibitions, obligations); + } + + public Policy(String id, String type) { + super(id, type); + } + + public Policy(String id, String targetId, String assignerId) { + super(id, "odrl:Offer"); + this.target = new DidDocument(); // Set Target + this.target.setId(targetId); + this.assigner = new DidDocument(); // Set BPN from assigner + this.assigner.setId(assignerId); + } + + + public Policy() { + } + + public Policy(PolicyCheckConfig.PolicyConfig policyConfig) { + super(policyConfig); + } + + public DidDocument getTarget() { + return target; + } + + public void setTarget(DidDocument target) { + this.target = target; + } + + public DidDocument getAssigner() { + return assigner; + } + + public void setAssigner(DidDocument assigner) { + this.assigner = assigner; + } + + public Policy setup(String targetId, String assignerId, String type) { + this.setType(type); + this.target = new DidDocument(); // Set Target + this.target.setId(targetId); + this.assigner = new DidDocument(); // Set BPN from assigner + this.assigner.setId(assignerId); + return this; + } +} diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/policy/Action.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/policy/Action.java index 4d4fa5b7e..48bd5d7aa 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/policy/Action.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/policy/Action.java @@ -30,9 +30,15 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.tractusx.digitalproductpass.config.PolicyCheckConfig; import org.eclipse.tractusx.digitalproductpass.exceptions.ModelException; +import java.util.ArrayList; +import java.util.List; + /** * This class responsible for mapping the logic constraints from a policy set **/ @@ -45,7 +51,7 @@ public class Action { **/ @JsonProperty("odrl:action") @JsonAlias({"action", "odrl:action"}) - String action; + ActionType action; @JsonProperty("odrl:constraint") @JsonAlias({"constraint", "odrl:constraint"}) LogicalConstraint constraint; @@ -58,7 +64,7 @@ public class Action { public Action() { } - public Action(String action, LogicalConstraint constraint) { + public Action(ActionType action, LogicalConstraint constraint) { this.action = action; this.constraint = constraint; } @@ -75,17 +81,28 @@ public Action(PolicyCheckConfig.ActionConfig actionConfig) { */ public void buildAction(PolicyCheckConfig.ActionConfig actionConfig){ // Create clean list of constraints - this.action = actionConfig.getAction(); + addAction(actionConfig.getAction()); this.constraint = new LogicalConstraint(actionConfig); } /** * GETTERS AND SETTERS **/ - public String getAction() { + public String retrieveAction() { + if(this.action == null){ + return null; + } + return this.action.getType(); + } + public void addAction(String action) { + this.action = new ActionType(); + this.action.setType(action); + } + + public ActionType getAction() { return action; } - public void setAction(String action) { + public void setAction(ActionType action) { this.action = action; } @@ -107,10 +124,48 @@ public void setConstraint(LogicalConstraint constraint) { public Boolean compare(Action action){ try{ if(action == null){return false;} // If action is null not continue - if(!action.getAction().equalsIgnoreCase(this.getAction())){return false;} // If actions strings are not the same + if(!action.retrieveAction().equalsIgnoreCase(this.retrieveAction())){return false;} // If actions strings are not the same return action.getConstraint().compare(this.getConstraint()); //If constraints are the same }catch (Exception e){ throw new ModelException(this.getClass().getName(), e, "It was not possible to compare the actions!"); } } + /** + * Builds an action from a raw policy object + *

+ * + * @param node {@code JsonNode} action to be checked + * @return {@code List} the list of actions parsed + * @throws ModelException if error when parsing the contracts + */ + static public List build(JsonNode node){ + ObjectMapper mapper = new ObjectMapper(); + // If node is not array parse a single action object + if(!node.isArray()){ + return new ArrayList<>(){{add(mapper.convertValue(node, new TypeReference<>(){}));}}; + } + // If node is array parse the action node as a list + return mapper.convertValue(node, new TypeReference<>(){}); + } + + static class ActionType{ + @JsonProperty("odrl:type") + @JsonAlias({"type", "odrl:type", "@type"}) + String type; + + public ActionType(String type) { + this.type = type; + } + + public ActionType() { + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + } } \ No newline at end of file diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/policy/Set.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/policy/Set.java index 8affb8476..64e51ab71 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/policy/Set.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/policy/Set.java @@ -26,16 +26,23 @@ package org.eclipse.tractusx.digitalproductpass.models.negotiation.policy; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.eclipse.tractusx.digitalproductpass.config.PolicyCheckConfig; import org.eclipse.tractusx.digitalproductpass.exceptions.ModelException; import org.eclipse.tractusx.digitalproductpass.models.negotiation.DidDocument; +import org.springframework.beans.factory.annotation.Autowired; +import utils.LogUtil; +import utils.PolicyUtil; +import utils.exceptions.UtilException; import java.util.ArrayList; -import java.util.Collection; +import java.util.List; import java.util.List; import java.util.Objects; @@ -47,42 +54,50 @@ public class Set extends DidDocument { /** ATTRIBUTES **/ - @JsonProperty("odrl:permission") - Collection permissions; - @JsonProperty("odrl:prohibition") - Collection prohibitions; - @JsonProperty("odrl:obligation") - Collection obligations; + @JsonIgnore + static final String PERMISSION = "odrl:permission"; + @JsonIgnore + static final String PROHIBITION = "odrl:prohibition"; + @JsonIgnore + static final String OBLIGATION = "odrl:obligation"; + + @JsonProperty(PERMISSION) + List permissions; + @JsonProperty(PROHIBITION) + List prohibitions; + + @JsonProperty(OBLIGATION) + List obligations; /** CONSTRUCTOR(S) **/ - public Set(String id, String type, Collection permissions, Collection prohibitions, Collection obligations) { + public Set(String id, String type, List permissions, List prohibitions, List obligations) { super(id, type); this.permissions = permissions; this.prohibitions = prohibitions; this.obligations = obligations; } - public Set(Collection permissions, Collection prohibitions, Collection obligations) { + public Set(List permissions, List prohibitions, List obligations) { this.permissions = permissions; this.prohibitions = prohibitions; this.obligations = obligations; } - public Set(String id, String type, JsonNode context, Collection permissions, Collection prohibitions, Collection obligations) { + public Set(String id, String type, JsonNode context, List permissions, List prohibitions, List obligations) { super(id, type, context); this.permissions = permissions; this.prohibitions = prohibitions; this.obligations = obligations; } - public Set(String type, Collection permissions, Collection prohibitions, Collection obligations) { + public Set(String type, List permissions, List prohibitions, List obligations) { super(type); this.permissions = permissions; this.prohibitions = prohibitions; this.obligations = obligations; } - public Set(JsonNode context, Collection permissions, Collection prohibitions, Collection obligations) { + public Set(JsonNode context, List permissions, List prohibitions, List obligations) { super(context); this.permissions = permissions; this.prohibitions = prohibitions; @@ -112,10 +127,10 @@ public void buildSet(PolicyCheckConfig.PolicyConfig policyConfig){ this.prohibitions = this.buildActions(policyConfig.getProhibition()); } - public Collection buildActions(List actionConfigs){ + public List buildActions(List actionConfigs){ try { // Set actions to the collection - Collection actions = new ArrayList<>(actionConfigs.size()); + List actions = new ArrayList<>(actionConfigs.size()); actionConfigs.forEach(actionConfig -> actions.add(new Action(actionConfig))); // Parse and create actions return actions; }catch (Exception e){ @@ -123,31 +138,73 @@ public Collection buildActions(List acti } } + /** + * Builds a policy from a raw policy object + *

+ * + * @param rawPolicy {@code Object} the policy to be checked + * @throws ModelException if error when parsing the contracts + */ + static public Set build(Object rawPolicy){ + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode policy = mapper.convertValue(rawPolicy, new TypeReference<>(){}); + String policyId = null; + String policyType = null; + // Parse policy to json node + if(policy.has(ID)) { + policyId = mapper.convertValue(policy.get(ID), new TypeReference<>() {}); + } + if(policy.has(TYPE)) { + policyType = mapper.convertValue(policy.get(TYPE), new TypeReference<>() {}); + } + + // Get permission, prohibition and obligation + JsonNode permission = policy.get(PERMISSION); + JsonNode prohibition = policy.get(PROHIBITION); + JsonNode obligation = policy.get(OBLIGATION); + + // Check if its null + if(permission == null || prohibition == null || obligation == null){ + throw new ModelException(Set.class.getName(), "One of the mandatory fields where not found! This is not a valid policy set!"); + } + // Check if all them are array then parse as default + if(permission.isArray() && prohibition.isArray() && obligation.isArray()){ + return mapper.convertValue(rawPolicy, new TypeReference<>(){}); + } + // If not parse the set by action type + return new Set(policyId, policyType, Action.build(permission), Action.build(prohibition), Action.build(obligation)); + }catch (Exception e) { + throw new ModelException(Set.class.getName(), "It was not possible to create a new policy!"); + } + } + + /** GETTERS AND SETTERS **/ - public Collection getPermissions() { + public List getPermissions() { return permissions; } - public void setPermissions(Collection permissions) { + public void setPermissions(List permissions) { this.permissions = permissions; } - public Collection getProhibitions() { + public List getProhibitions() { return prohibitions; } - public void setProhibitions(Collection prohibitions) { + public void setProhibitions(List prohibitions) { this.prohibitions = prohibitions; } - public Collection getObligations() { + public List getObligations() { return obligations; } - public void setObligations(Collection obligations) { + public void setObligations(List obligations) { this.obligations = obligations; } @@ -176,11 +233,11 @@ public Boolean compare(Set set){ /** * Method responsible for comparing two actions constraints *

- * @param currentActions {@code Collection} is the object to be compared - * @param incomingActions {@code Collection} is the object to be compared to + * @param currentActions {@code List} is the object to be compared + * @param incomingActions {@code List} is the object to be compared to * @return true if the actions are the same */ - public Boolean compareActions(Collection currentActions, Collection incomingActions){ + public Boolean compareActions(List currentActions, List incomingActions){ try { // Optimizations to avoid searching in children if(currentActions == null && incomingActions == null){return true;} // If both actions are null they are equal diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/request/NegotiationRequest.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/request/NegotiationRequest.java index f6c47d324..1bfa0f999 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/request/NegotiationRequest.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/request/NegotiationRequest.java @@ -31,7 +31,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.JsonNode; import org.eclipse.tractusx.digitalproductpass.models.negotiation.DidDocument; -import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Offer; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Policy; /** * This class consists exclusively to define attributes related to the Negotiation requests. @@ -41,83 +41,105 @@ public class NegotiationRequest extends DidDocument { /** ATTRIBUTES **/ - @JsonProperty("connectorAddress") - String connectorAddress; + @JsonProperty("counterPartyAddress") + String counterPartyAddress; @JsonProperty("protocol") String protocol; - @JsonProperty("connectorId") - String connectorId; - @JsonProperty("providerId") - String providerId; - @JsonProperty("offer") - Offer offer; + @JsonProperty("policy") + Policy policy; - /** CONSTRUCTOR(S) **/ - @SuppressWarnings("Unused") - public NegotiationRequest(JsonNode context, String connectorAddress, String protocol, String connectorId, String providerId, Offer offer) { - this.context = context; - this.type = "NegotiationInitiateRequestDto"; - this.connectorAddress = connectorAddress; + public NegotiationRequest(String id, String type, String counterPartyAddress, String protocol, Policy policy) { + super(id, type); + this.counterPartyAddress = counterPartyAddress; + this.protocol = protocol; + this.policy = policy; + } + + public NegotiationRequest(String counterPartyAddress, String protocol, Policy policy) { + this.counterPartyAddress = counterPartyAddress; + this.protocol = protocol; + this.policy = policy; + } + + public NegotiationRequest(String id, String type, JsonNode context, String counterPartyAddress, String protocol, Policy policy) { + super(id, type, context); + this.counterPartyAddress = counterPartyAddress; + this.protocol = protocol; + this.policy = policy; + } + + public NegotiationRequest(String type, String counterPartyAddress, String protocol, Policy policy) { + super(type); + this.counterPartyAddress = counterPartyAddress; this.protocol = protocol; - this.connectorId = connectorId; - this.providerId = providerId; - this.offer = offer; - } - public NegotiationRequest(JsonNode context, String connectorAddress, String connectorId, String providerId, Offer offer) { - this.context = context; - this.type = "NegotiationInitiateRequestDto"; - this.connectorAddress = connectorAddress; - this.protocol = "dataspace-protocol-http"; - this.connectorId = connectorId; - this.providerId = providerId; - this.offer = offer; - } - @SuppressWarnings("Unused") - public NegotiationRequest(JsonNode context, String type, String connectorAddress, String protocol, String connectorId, String providerId, Offer offer) { - this.context = context; - this.type = type; - this.connectorAddress = connectorAddress; + this.policy = policy; + } + + public NegotiationRequest(JsonNode context, String counterPartyAddress, String protocol, Policy policy) { + super(context); + this.counterPartyAddress = counterPartyAddress; this.protocol = protocol; - this.connectorId = connectorId; - this.providerId = providerId; - this.offer = offer; + this.policy = policy; } - @SuppressWarnings("Unused") + + public NegotiationRequest(JsonNode context, String type, String counterPartyAddress, String protocol, Policy policy) { + super(context, type); + this.counterPartyAddress = counterPartyAddress; + this.protocol = protocol; + this.policy = policy; + } + + public NegotiationRequest(String id, String type) { + super(id, type); + } + public NegotiationRequest() { } - /** GETTERS AND SETTERS **/ - public String getConnectorId() { - return connectorId; + public NegotiationRequest(String id, String type, JsonNode context) { + super(id, type, context); } - public void setConnectorId(String connectorId) { - this.connectorId = connectorId; + + public NegotiationRequest(String type) { + super(type); } - public String getConnectorAddress() { - return connectorAddress; + + public NegotiationRequest(JsonNode context) { + super(context); } - public void setConnectorAddress(String connectorAddress) { - this.connectorAddress = connectorAddress; + + public NegotiationRequest(JsonNode context, String type) { + super(context, type); } - public Offer getOffer() { - return offer; + + + public String getCounterPartyAddress() { + return counterPartyAddress; } - @SuppressWarnings("Unused") - public void setOffer(Offer offer) { - this.offer = offer; + + public void setCounterPartyAddress(String counterPartyAddress) { + this.counterPartyAddress = counterPartyAddress; } + public String getProtocol() { return protocol; } + public void setProtocol(String protocol) { this.protocol = protocol; } - @SuppressWarnings("Unused") - public String getProviderId() { - return providerId; + + public Policy getPolicy() { + return policy; } - @SuppressWarnings("Unused") - public void setProviderId(String providerId) { - this.providerId = providerId; + + public void setPolicy(Policy policy) { + this.policy = policy; } + + /** CONSTRUCTOR(S) **/ + + + /** GETTERS AND SETTERS **/ + } diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/request/TransferRequest.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/request/TransferRequest.java index b84f8b107..cba25cc85 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/request/TransferRequest.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/request/TransferRequest.java @@ -47,21 +47,16 @@ public class TransferRequest extends DidDocument { String assetId; @JsonProperty("connectorAddress") String connectorAddress; - @JsonProperty("connectorId") - String connectorId; @JsonProperty("contractId") String contractId; @JsonProperty("dataDestination") DataDestination dataDestination; @JsonProperty("managedResources") Boolean managedResources; - @JsonProperty("privateProperties") - PrivateProperties privateProperties; @JsonProperty("protocol") String protocol; @JsonProperty("transferType") - TransferType transferType; - + String transferType; @JsonProperty("callbackAddresses") List callbackAddresses; @@ -69,113 +64,79 @@ public class TransferRequest extends DidDocument { public TransferRequest() { } - public TransferRequest(JsonNode context, String assetId, String connectorAddress, String connectorId, String contractId, DataDestination dataDestination, Boolean managedResources, PrivateProperties privateProperties, String protocol, TransferType transferType) { - this.context = context; - this.assetId = assetId; - this.connectorAddress = connectorAddress; - this.connectorId = connectorId; - this.contractId = contractId; - this.dataDestination = dataDestination; - this.managedResources = managedResources; - this.privateProperties = privateProperties; - this.protocol = protocol; - this.transferType = transferType; - } - public TransferRequest(String id, String type, String assetId, String connectorAddress, String connectorId, String contractId, DataDestination dataDestination, Boolean managedResources, PrivateProperties privateProperties, String protocol, TransferType transferType) { + public TransferRequest(String id, String type, String assetId, String connectorAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List callbackAddresses) { super(id, type); this.assetId = assetId; this.connectorAddress = connectorAddress; - this.connectorId = connectorId; - this.contractId = contractId; - this.dataDestination = dataDestination; - this.managedResources = managedResources; - this.privateProperties = privateProperties; - this.protocol = protocol; - this.transferType = transferType; - } - - public TransferRequest(String assetId, String connectorAddress, String connectorId, String contractId, DataDestination dataDestination, Boolean managedResources, PrivateProperties privateProperties, String protocol, TransferType transferType) { - this.assetId = assetId; - this.connectorAddress = connectorAddress; - this.connectorId = connectorId; this.contractId = contractId; this.dataDestination = dataDestination; this.managedResources = managedResources; - this.privateProperties = privateProperties; this.protocol = protocol; this.transferType = transferType; + this.callbackAddresses = callbackAddresses; } - public TransferRequest(String id, String type, String assetId, String connectorAddress, String connectorId, String contractId, DataDestination dataDestination, Boolean managedResources, PrivateProperties privateProperties, String protocol, TransferType transferType, List callbackAddresses) { - super(id, type); + public TransferRequest(String assetId, String connectorAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List callbackAddresses) { this.assetId = assetId; this.connectorAddress = connectorAddress; - this.connectorId = connectorId; this.contractId = contractId; this.dataDestination = dataDestination; this.managedResources = managedResources; - this.privateProperties = privateProperties; this.protocol = protocol; this.transferType = transferType; this.callbackAddresses = callbackAddresses; } - public TransferRequest(String assetId, String connectorAddress, String connectorId, String contractId, DataDestination dataDestination, Boolean managedResources, PrivateProperties privateProperties, String protocol, TransferType transferType, List callbackAddresses) { + public TransferRequest(String id, String type, JsonNode context, String assetId, String connectorAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List callbackAddresses) { + super(id, type, context); this.assetId = assetId; this.connectorAddress = connectorAddress; - this.connectorId = connectorId; this.contractId = contractId; this.dataDestination = dataDestination; this.managedResources = managedResources; - this.privateProperties = privateProperties; this.protocol = protocol; this.transferType = transferType; this.callbackAddresses = callbackAddresses; } - public TransferRequest(String id, String type, JsonNode context, String assetId, String connectorAddress, String connectorId, String contractId, DataDestination dataDestination, Boolean managedResources, PrivateProperties privateProperties, String protocol, TransferType transferType, List callbackAddresses) { - super(id, type, context); + public TransferRequest(String type, String assetId, String connectorAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List callbackAddresses) { + super(type); this.assetId = assetId; this.connectorAddress = connectorAddress; - this.connectorId = connectorId; this.contractId = contractId; this.dataDestination = dataDestination; this.managedResources = managedResources; - this.privateProperties = privateProperties; this.protocol = protocol; this.transferType = transferType; this.callbackAddresses = callbackAddresses; } - public TransferRequest(String type, String assetId, String connectorAddress, String connectorId, String contractId, DataDestination dataDestination, Boolean managedResources, PrivateProperties privateProperties, String protocol, TransferType transferType, List callbackAddresses) { - super(type); + public TransferRequest(JsonNode context, String assetId, String connectorAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List callbackAddresses) { + super(context); this.assetId = assetId; this.connectorAddress = connectorAddress; - this.connectorId = connectorId; this.contractId = contractId; this.dataDestination = dataDestination; this.managedResources = managedResources; - this.privateProperties = privateProperties; this.protocol = protocol; this.transferType = transferType; this.callbackAddresses = callbackAddresses; } - public TransferRequest(JsonNode context, String assetId, String connectorAddress, String connectorId, String contractId, DataDestination dataDestination, Boolean managedResources, PrivateProperties privateProperties, String protocol, TransferType transferType, List callbackAddresses) { - super(context); + public TransferRequest(JsonNode context, String type, String assetId, String connectorAddress, String contractId, DataDestination dataDestination, Boolean managedResources, String protocol, String transferType, List callbackAddresses) { + super(context, type); this.assetId = assetId; this.connectorAddress = connectorAddress; - this.connectorId = connectorId; this.contractId = contractId; this.dataDestination = dataDestination; this.managedResources = managedResources; - this.privateProperties = privateProperties; this.protocol = protocol; this.transferType = transferType; this.callbackAddresses = callbackAddresses; } + /** GETTERS AND SETTERS **/ public String getAssetId() { return assetId; @@ -195,14 +156,11 @@ public void setConnectorAddress(String connectorAddress) { public void setDataDestination(DataDestination dataDestination) { this.dataDestination = dataDestination; } public Boolean getManagedResources() { return managedResources; } public void setManagedResources(Boolean managedResources) { this.managedResources = managedResources; } - public PrivateProperties getPrivateProperties() { return privateProperties; } - public void setPrivateProperties(PrivateProperties privateProperties) { this.privateProperties = privateProperties; } + public String getProtocol() { return protocol; } public void setProtocol(String protocol) { this.protocol = protocol; } - public TransferType getTransferType() { return transferType; } - public void setTransferType(TransferType transferType) { this.transferType = transferType; } - public String getConnectorId() { return connectorId; } - public void setConnectorId(String connectorId) { this.connectorId = connectorId; } + public String getString() { return transferType; } + public void setString(String transferType) { this.transferType = transferType; } public List getCallbackAddresses() { return callbackAddresses; @@ -214,32 +172,6 @@ public void setCallbackAddresses(List callbackAddresses) { /** INNER CLASSES **/ - /** - * This class consists exclusively to define attributes related to the Transfer request's transfer type property. - **/ - @JsonInclude(JsonInclude.Include.NON_NULL) - public static class TransferType { - - /** ATTRIBUTES **/ - @JsonProperty("contentType") - String contentType; - @JsonProperty("isFinite") - Boolean isFinite; - - /** GETTERS AND SETTERS **/ - public String getContentType() { - return contentType; - } - public void setContentType(String contentType) { - this.contentType = contentType; - } - public Boolean getIsFinite() { - return isFinite; - } - public void setIsFinite(Boolean isFinite) { - this.isFinite = isFinite; - } - } /** * This class consists exclusively to define attributes related to the Transfer request's private properties' attribute. diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/response/Negotiation.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/response/Negotiation.java index fe049ee1c..4cde40504 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/response/Negotiation.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/response/Negotiation.java @@ -57,38 +57,63 @@ public class Negotiation extends NegotiationTransferResponse { String contractAgreementId; /** CONSTRUCTOR(S) **/ - public Negotiation(String id, String type, String state, String edcType, Long createdAt, List callbackAddresses, JsonNode context, String errorDetail, String protocol, String counterPartyId, String counterPartyAddress, String contractAgreementId) { - super(id, type, state, edcType, createdAt, callbackAddresses, context, errorDetail); + + public Negotiation() { + } + + public Negotiation(String protocol, String counterPartyId, String counterPartyAddress, String contractAgreementId) { this.protocol = protocol; this.counterPartyId = counterPartyId; this.counterPartyAddress = counterPartyAddress; this.contractAgreementId = contractAgreementId; } - public Negotiation(String state, String edcType, Long createdAt, List callbackAddresses, JsonNode context, String errorDetail, String protocol, String counterPartyId, String counterPartyAddress, String contractAgreementId) { - super(state, edcType, createdAt, callbackAddresses, context, errorDetail); + public Negotiation(String id, String type, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail, String protocol, String counterPartyId, String counterPartyAddress, String contractAgreementId) { + super(id, type, state, edcType, createdAt, callbackAddresses, errorDetail); this.protocol = protocol; this.counterPartyId = counterPartyId; this.counterPartyAddress = counterPartyAddress; this.contractAgreementId = contractAgreementId; } - public Negotiation(String protocol, String counterPartyId, String counterPartyAddress, String contractAgreementId) { + public Negotiation(String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail, String protocol, String counterPartyId, String counterPartyAddress, String contractAgreementId) { + super(state, edcType, createdAt, callbackAddresses, errorDetail); this.protocol = protocol; this.counterPartyId = counterPartyId; this.counterPartyAddress = counterPartyAddress; this.contractAgreementId = contractAgreementId; } - public Negotiation(String id, String type, String state, String edcType, Long createdAt, List callbackAddresses, JsonNode context, String errorDetail) { - super(id, type, state, edcType, createdAt, callbackAddresses, context, errorDetail); + public Negotiation(String id, String type, JsonNode context, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail, String protocol, String counterPartyId, String counterPartyAddress, String contractAgreementId) { + super(id, type, context, state, edcType, createdAt, callbackAddresses, errorDetail); + this.protocol = protocol; + this.counterPartyId = counterPartyId; + this.counterPartyAddress = counterPartyAddress; + this.contractAgreementId = contractAgreementId; } - public Negotiation(String state, String edcType, Long createdAt, List callbackAddresses, JsonNode context, String errorDetail) { - super(state, edcType, createdAt, callbackAddresses, context, errorDetail); + public Negotiation(String type, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail, String protocol, String counterPartyId, String counterPartyAddress, String contractAgreementId) { + super(type, state, edcType, createdAt, callbackAddresses, errorDetail); + this.protocol = protocol; + this.counterPartyId = counterPartyId; + this.counterPartyAddress = counterPartyAddress; + this.contractAgreementId = contractAgreementId; } - public Negotiation() { + public Negotiation(JsonNode context, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail, String protocol, String counterPartyId, String counterPartyAddress, String contractAgreementId) { + super(context, state, edcType, createdAt, callbackAddresses, errorDetail); + this.protocol = protocol; + this.counterPartyId = counterPartyId; + this.counterPartyAddress = counterPartyAddress; + this.contractAgreementId = contractAgreementId; + } + + public Negotiation(JsonNode context, String type, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail, String protocol, String counterPartyId, String counterPartyAddress, String contractAgreementId) { + super(context, type, state, edcType, createdAt, callbackAddresses, errorDetail); + this.protocol = protocol; + this.counterPartyId = counterPartyId; + this.counterPartyAddress = counterPartyAddress; + this.contractAgreementId = contractAgreementId; } /** GETTERS AND SETTERS **/ diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/response/NegotiationTransferResponse.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/response/NegotiationTransferResponse.java index 1d05c818b..4c6a12522 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/response/NegotiationTransferResponse.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/response/NegotiationTransferResponse.java @@ -31,6 +31,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.JsonNode; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.CallbackAddress; import org.eclipse.tractusx.digitalproductpass.models.negotiation.DidDocument; import java.util.List; @@ -56,32 +57,67 @@ public class NegotiationTransferResponse extends DidDocument { Long createdAt; @JsonProperty("callbackAddresses") @JsonAlias({"callbackAddresses","edc:callbackAddresses"}) - List callbackAddresses; + Object callbackAddresses; + @JsonProperty("errorDetail") @JsonAlias({"errorDetail","edc:errorDetail"}) String errorDetail; /** CONSTRUCTOR(S) **/ - public NegotiationTransferResponse(String id, String type, String state, String edcType, Long createdAt, List callbackAddresses, JsonNode context, String errorDetail) { + public NegotiationTransferResponse() { + } + + public NegotiationTransferResponse(String id, String type, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail) { super(id, type); this.state = state; this.edcType = edcType; this.createdAt = createdAt; this.callbackAddresses = callbackAddresses; - this.context = context; this.errorDetail = errorDetail; } - public NegotiationTransferResponse(String state, String edcType, Long createdAt, List callbackAddresses, JsonNode context, String errorDetail) { + public NegotiationTransferResponse(String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail) { this.state = state; this.edcType = edcType; this.createdAt = createdAt; this.callbackAddresses = callbackAddresses; - this.context = context; this.errorDetail = errorDetail; } - public NegotiationTransferResponse() { + public NegotiationTransferResponse(String id, String type, JsonNode context, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail) { + super(id, type, context); + this.state = state; + this.edcType = edcType; + this.createdAt = createdAt; + this.callbackAddresses = callbackAddresses; + this.errorDetail = errorDetail; + } + + public NegotiationTransferResponse(String type, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail) { + super(type); + this.state = state; + this.edcType = edcType; + this.createdAt = createdAt; + this.callbackAddresses = callbackAddresses; + this.errorDetail = errorDetail; + } + + public NegotiationTransferResponse(JsonNode context, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail) { + super(context); + this.state = state; + this.edcType = edcType; + this.createdAt = createdAt; + this.callbackAddresses = callbackAddresses; + this.errorDetail = errorDetail; + } + + public NegotiationTransferResponse(JsonNode context, String type, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail) { + super(context, type); + this.state = state; + this.edcType = edcType; + this.createdAt = createdAt; + this.callbackAddresses = callbackAddresses; + this.errorDetail = errorDetail; } /** GETTERS AND SETTERS **/ @@ -109,14 +145,6 @@ public void setCreatedAt(Long createdAt) { this.createdAt = createdAt; } - public List getCallbackAddresses() { - return callbackAddresses; - } - - public void setCallbackAddresses(List callbackAddresses) { - this.callbackAddresses = callbackAddresses; - } - public String getErrorDetail() { return errorDetail; } @@ -126,4 +154,11 @@ public void setErrorDetail(String errorDetail) { } + public Object getCallbackAddresses() { + return callbackAddresses; + } + + public void setCallbackAddresses(Object callbackAddresses) { + this.callbackAddresses = callbackAddresses; + } } diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/response/Transfer.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/response/Transfer.java index 95120628c..7765b486c 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/response/Transfer.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/models/negotiation/response/Transfer.java @@ -31,6 +31,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.JsonNode; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.CallbackAddress; import org.eclipse.tractusx.digitalproductpass.models.negotiation.DidDocument; import org.eclipse.tractusx.digitalproductpass.models.negotiation.response.NegotiationTransferResponse; @@ -65,44 +66,59 @@ public class Transfer extends NegotiationTransferResponse { @JsonProperty("receiverHttpEndpoint") @JsonAlias({"receiverHttpEndpoint","edc:receiverHttpEndpoint"}) String receiverHttpEndpoint; + @JsonProperty("callbackAddresses") + @JsonAlias({"callbackAddresses","edc:callbackAddresses"}) + Object callbackAddresses; - /** CONSTRUCTOR(S) **/ - public Transfer(String id, String type, String state, String edcType, Long createdAt, List callbackAddresses, JsonNode context, String errorDetail, Long stateTimestamp, DataDestination dataDestination, DataRequest dataRequest, String receiverHttpEndpoint) { - super(id, type, state, edcType, createdAt, callbackAddresses, context, errorDetail); + public Transfer(Long stateTimestamp, String correlationId, String assetId, String contractId, DataDestination dataDestination, DataRequest dataRequest, String receiverHttpEndpoint, Object callbackAddresses) { this.stateTimestamp = stateTimestamp; + this.correlationId = correlationId; + this.assetId = assetId; + this.contractId = contractId; this.dataDestination = dataDestination; this.dataRequest = dataRequest; this.receiverHttpEndpoint = receiverHttpEndpoint; + this.callbackAddresses = callbackAddresses; } - public Transfer(String state, String edcType, Long createdAt, List callbackAddresses, JsonNode context, String errorDetail, Long stateTimestamp, DataDestination dataDestination, DataRequest dataRequest, String receiverHttpEndpoint) { - super(state, edcType, createdAt, callbackAddresses, context, errorDetail); + public Transfer(String id, String type, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail, Long stateTimestamp, String correlationId, String assetId, String contractId, DataDestination dataDestination, DataRequest dataRequest, String receiverHttpEndpoint, Object callbackAddresses1) { + super(id, type, state, edcType, createdAt, callbackAddresses, errorDetail); this.stateTimestamp = stateTimestamp; + this.correlationId = correlationId; + this.assetId = assetId; + this.contractId = contractId; this.dataDestination = dataDestination; this.dataRequest = dataRequest; this.receiverHttpEndpoint = receiverHttpEndpoint; + this.callbackAddresses = callbackAddresses1; } - public Transfer(Long stateTimestamp, DataDestination dataDestination, DataRequest dataRequest, String receiverHttpEndpoint) { + public Transfer(String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail, Long stateTimestamp, String correlationId, String assetId, String contractId, DataDestination dataDestination, DataRequest dataRequest, String receiverHttpEndpoint, Object callbackAddresses1) { + super(state, edcType, createdAt, callbackAddresses, errorDetail); this.stateTimestamp = stateTimestamp; + this.correlationId = correlationId; + this.assetId = assetId; + this.contractId = contractId; this.dataDestination = dataDestination; this.dataRequest = dataRequest; this.receiverHttpEndpoint = receiverHttpEndpoint; + this.callbackAddresses = callbackAddresses1; } - public Transfer(String id, String type, String state, String edcType, Long createdAt, List callbackAddresses, JsonNode context, String errorDetail) { - super(id, type, state, edcType, createdAt, callbackAddresses, context, errorDetail); - } - - public Transfer(String state, String edcType, Long createdAt, List callbackAddresses, JsonNode context, String errorDetail) { - super(state, edcType, createdAt, callbackAddresses, context, errorDetail); - } - - public Transfer() { + public Transfer(String id, String type, JsonNode context, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail, Long stateTimestamp, String correlationId, String assetId, String contractId, DataDestination dataDestination, DataRequest dataRequest, String receiverHttpEndpoint, Object callbackAddresses1) { + super(id, type, context, state, edcType, createdAt, callbackAddresses, errorDetail); + this.stateTimestamp = stateTimestamp; + this.correlationId = correlationId; + this.assetId = assetId; + this.contractId = contractId; + this.dataDestination = dataDestination; + this.dataRequest = dataRequest; + this.receiverHttpEndpoint = receiverHttpEndpoint; + this.callbackAddresses = callbackAddresses1; } - public Transfer(String id, String type, String state, String edcType, Long createdAt, List callbackAddresses, JsonNode context, String errorDetail, Long stateTimestamp, String correlationId, String assetId, String contractId, DataDestination dataDestination, DataRequest dataRequest, String receiverHttpEndpoint) { - super(id, type, state, edcType, createdAt, callbackAddresses, context, errorDetail); + public Transfer(String type, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail, Long stateTimestamp, String correlationId, String assetId, String contractId, DataDestination dataDestination, DataRequest dataRequest, String receiverHttpEndpoint, Object callbackAddresses1) { + super(type, state, edcType, createdAt, callbackAddresses, errorDetail); this.stateTimestamp = stateTimestamp; this.correlationId = correlationId; this.assetId = assetId; @@ -110,10 +126,11 @@ public Transfer(String id, String type, String state, String edcType, Long creat this.dataDestination = dataDestination; this.dataRequest = dataRequest; this.receiverHttpEndpoint = receiverHttpEndpoint; + this.callbackAddresses = callbackAddresses1; } - public Transfer(String state, String edcType, Long createdAt, List callbackAddresses, JsonNode context, String errorDetail, Long stateTimestamp, String correlationId, String assetId, String contractId, DataDestination dataDestination, DataRequest dataRequest, String receiverHttpEndpoint) { - super(state, edcType, createdAt, callbackAddresses, context, errorDetail); + public Transfer(JsonNode context, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail, Long stateTimestamp, String correlationId, String assetId, String contractId, DataDestination dataDestination, DataRequest dataRequest, String receiverHttpEndpoint, Object callbackAddresses1) { + super(context, state, edcType, createdAt, callbackAddresses, errorDetail); this.stateTimestamp = stateTimestamp; this.correlationId = correlationId; this.assetId = assetId; @@ -121,9 +138,11 @@ public Transfer(String state, String edcType, Long createdAt, List cal this.dataDestination = dataDestination; this.dataRequest = dataRequest; this.receiverHttpEndpoint = receiverHttpEndpoint; + this.callbackAddresses = callbackAddresses1; } - public Transfer(Long stateTimestamp, String correlationId, String assetId, String contractId, DataDestination dataDestination, DataRequest dataRequest, String receiverHttpEndpoint) { + public Transfer(JsonNode context, String type, String state, String edcType, Long createdAt, Object callbackAddresses, String errorDetail, Long stateTimestamp, String correlationId, String assetId, String contractId, DataDestination dataDestination, DataRequest dataRequest, String receiverHttpEndpoint, Object callbackAddresses1) { + super(context, type, state, edcType, createdAt, callbackAddresses, errorDetail); this.stateTimestamp = stateTimestamp; this.correlationId = correlationId; this.assetId = assetId; @@ -131,8 +150,15 @@ public Transfer(Long stateTimestamp, String correlationId, String assetId, Strin this.dataDestination = dataDestination; this.dataRequest = dataRequest; this.receiverHttpEndpoint = receiverHttpEndpoint; + this.callbackAddresses = callbackAddresses1; + } + + public Transfer() { } + /** CONSTRUCTOR(S) **/ + + public Long getStateTimestamp() { return stateTimestamp; } diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/AasService.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/AasService.java index be37b246d..44140c5a0 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/AasService.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/AasService.java @@ -62,6 +62,8 @@ */ @Service public class AasService extends BaseService { + /** CONSTANTS **/ + public static final String AUTHORIZATION_KEY = "Authorization"; /** ATTRIBUTES **/ public String registryUrl; @@ -71,6 +73,8 @@ public class AasService extends BaseService { private final HttpUtil httpUtil; private final JsonUtil jsonUtil; private final DtrConfig dtrConfig; + + public Environment env; private final AuthenticationService authService; Map apis; private DtrSearchManager dtrSearchManager; @@ -368,7 +372,11 @@ public HttpHeaders getTokenHeader(EndpointDataReference edr) { // Get the normal headers based on the EDR HttpHeaders headers = this.httpUtil.getHeaders(); - headers.add(edr.getAuthKey(), ""+edr.getAuthCode()); + String authKey = AUTHORIZATION_KEY; + if(env != null){ + authKey = env.getProperty("configuration.edc.authorizationKey", AUTHORIZATION_KEY); + } + headers.add(authKey, edr.getPayload().getDataAddress().getProperties().getAuthorization()); return headers; } catch (Exception e) { throw new ServiceException(this.getClass().getName() + "." + "getTokenHeader", @@ -429,7 +437,7 @@ public AssetSearch decentralDtrSearch(String processId, Search searchBody){ } status = this.processManager.getStatus(processId); if (status.historyExists("digital-twin-found")) { - return new AssetSearch(status.getHistory("digital-twin-found").getId(), status.getEndpoint()); + return new AssetSearch(status.getHistory("digital-twin-found").getId(), status.getBpn(), status.getEndpoint()); } return null; } catch (Exception e) { @@ -622,7 +630,7 @@ public Integer getDtIndex() { */ @Override public void run() { - this.setDigitalTwin(searchDigitalTwin(this.getIdType(), this.getAssetId(), this.getDtIndex(), this.getEdr().getEndpoint(), this.getEdr())); + this.setDigitalTwin(searchDigitalTwin(this.getIdType(), this.getAssetId(), this.getDtIndex(), this.getEdr().getPayload().getDataAddress().getProperties().getEndpoint(), this.getEdr())); if(this.semanticId == null || this.semanticId.isEmpty()){ this.setSubModel(searchSubModelBySemanticId(this.getDigitalTwin())); }else { diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/ContractService.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/ContractService.java index 1e6bfc52a..f75414d75 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/ContractService.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/ContractService.java @@ -177,8 +177,7 @@ public Response createCall (HttpServletResponse httpResponse, DiscoverySearch se for (String bpn : bpnList) { List dtrs = null; try { - dtrs = (List) jsonUtil.bindReferenceType(dataModel.get(bpn), new TypeReference>() { - }); + dtrs = (List) jsonUtil.bindReferenceType(dataModel.get(bpn), new TypeReference>() {}); } catch (Exception e) { throw new ControllerException(this.getClass().getName(), e, "Could not bind the reference type!"); } @@ -215,10 +214,10 @@ public Response createCall (HttpServletResponse httpResponse, DiscoverySearch se SearchStatus status = processManager.getSearchStatus(processId); if (status == null) { - return httpUtil.buildResponse(httpUtil.getNotFound("It was not possible to search for the decentral digital twin registries"), httpResponse); + return httpUtil.buildResponse(httpUtil.getNotFound("It was not possible to search for the decentralized digital twin registries"), httpResponse); } if (status.getDtrs().isEmpty()) { - return httpUtil.buildResponse(httpUtil.getNotFound("No decentral digital twin registry was found"), httpResponse); + return httpUtil.buildResponse(httpUtil.getNotFound("No valid decentralized digital twin registries found for the configured policies!"), httpResponse); } response = httpUtil.getResponse(); response.data = Map.of( @@ -355,12 +354,16 @@ public Response searchCall(HttpServletRequest httpRequest, HttpServletResponse h // Assing the variables with the content String assetId = assetSearch.getAssetId(); String connectorAddress = assetSearch.getConnectorAddress(); + String bpn = assetSearch.getBpn(); /*[1]=========================================*/ // Get catalog with all the contract offers if(connectorAddress == null){ LogUtil.printError("The connector address is empty!"); } + if(bpn == null){ + LogUtil.printError("The bpn is empty!"); + } if(assetId == null){ LogUtil.printError("The assetId is empty!"); } @@ -368,11 +371,11 @@ public Response searchCall(HttpServletRequest httpRequest, HttpServletResponse h Map datasets = null; Long startedTime = DateTimeUtil.getTimestamp(); try { - catalog = dataService.getContractOfferCatalog(connectorAddress, assetId); + catalog = dataService.getContractOfferCatalog(connectorAddress, bpn, assetId); datasets = edcUtil.filterValidContracts(dataService.getContractOffers(catalog), this.passportConfig.getPolicyCheck()); } catch (ServiceException e) { LogUtil.printError("The EDC is not reachable, it was not possible to retrieve catalog! Trying again..."); - catalog = dataService.getContractOfferCatalog(connectorAddress, assetId); + catalog = dataService.getContractOfferCatalog(connectorAddress, bpn, assetId); datasets = edcUtil.filterValidContracts(dataService.getContractOffers(catalog), this.passportConfig.getPolicyCheck()); if (datasets == null) { // If the contract catalog is not reachable retry... response.message = "The EDC is not reachable, it was not possible to retrieve catalog! Please try again!"; @@ -385,7 +388,7 @@ public Response searchCall(HttpServletRequest httpRequest, HttpServletResponse h if (datasets == null) { // Retry again... LogUtil.printWarning("[PROCESS " + process.id + "] No asset id found for the dataset contract offers in the catalog! Requesting catalog again..."); - catalog = dataService.getContractOfferCatalog(connectorAddress, assetId); + catalog = dataService.getContractOfferCatalog(connectorAddress, bpn, assetId); datasets = edcUtil.filterValidContracts(dataService.getContractOffers(catalog), this.passportConfig.getPolicyCheck()); if (datasets == null) { // If the contract catalog is not reachable retry... response.message = "Asset Id not found in any contract!"; @@ -517,19 +520,23 @@ public Response doContractAgreement(HttpServletRequest httpRequest, HttpServletR String policyId = tokenRequestBody.getPolicyId(); Set policy = null; DataTransferService.NegotiateContract contractNegotiation = null; - policy = policyUtil.getPolicyById(dataset, policyId); + // This function will always get a complaint policy from the allowed ones + policy = policyUtil.getCompliantPolicyById(dataset, policyId, passportConfig.getPolicyCheck()); if (policy == null) { - response = httpUtil.getBadRequest("The policy selected does not exists!"); + response = httpUtil.getBadRequest("The policy selected is not allowed per configuration or does not exists!"); return httpUtil.buildResponse(response, httpResponse); } + + LogUtil.printMessage("[ASSET"+(policyId == null?"-":"-AUTO-")+"NEGOTIATION] [PROCESS "+processId + "] Selected [POLICY "+policy.getId()+"]:["+this.jsonUtil.toJson(policy, false)+"]!"); + LogUtil.printMessage("[ASSET-NEGOTIATION] [PROCESS "+processId + "] Selected [CONTRACT "+dataset.getId()+"]:["+this.jsonUtil.toJson(dataset, false)+"]!"); + contractNegotiation = dataService .new NegotiateContract( processManager.loadDataModel(httpRequest), processId, - status.getBpn(), status.getProviderBpn(), dataset, - processManager.getStatus(processId), + processManager.getStatus(processId).getEndpoint(), policy ); String statusPath = processManager.setAgreed(httpRequest, processId, signedAt, contractId, policyId); diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/DataPlaneService.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/DataPlaneService.java index a923e737c..562957239 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/DataPlaneService.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/DataPlaneService.java @@ -32,6 +32,7 @@ import org.eclipse.tractusx.digitalproductpass.models.edc.EndpointDataReference; import org.eclipse.tractusx.digitalproductpass.models.service.BaseService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -50,12 +51,17 @@ @Service public class DataPlaneService extends BaseService { + /** CONSTANTS **/ + public static final String AUTHORIZATION_KEY = "Authorization"; + /** ATTRIBUTES **/ @Autowired HttpUtil httpUtil; @Autowired JsonUtil jsonUtil; + public Environment env; + /** CONSTRUCTOR(S) **/ public DataPlaneService() throws ServiceInitializationException { this.checkEmptyVariables(); @@ -78,8 +84,12 @@ public Object getTransferData(EndpointDataReference endpointData) { try { Map params = httpUtil.getParams(); HttpHeaders headers = new HttpHeaders(); - headers.add(endpointData.getAuthKey(), endpointData.getAuthCode()); - ResponseEntity response = httpUtil.doGet(endpointData.getEndpoint(), Object.class, headers, params, true, true); + String authKey = AUTHORIZATION_KEY; + if(env != null){ + authKey = env.getProperty("configuration.edc.authorizationKey", AUTHORIZATION_KEY); + } + headers.add(authKey, endpointData.getPayload().getDataAddress().getProperties().getAuthorization()); + ResponseEntity response = httpUtil.doGet(endpointData.getPayload().getDataAddress().getProperties().getEndpoint(), Object.class, headers, params, true, true); return response.getBody(); }catch (Exception e){ throw new ServiceException(this.getClass().getName()+"."+"getTransferData", @@ -102,7 +112,11 @@ public JsonNode getTransferDataFromEndpoint(EndpointDataReference endpointData, try { Map params = httpUtil.getParams(); HttpHeaders headers = new HttpHeaders(); - headers.add(endpointData.getAuthKey(), endpointData.getAuthCode()); + String authKey = AUTHORIZATION_KEY; + if(env != null){ + authKey = env.getProperty("configuration.edc.authorizationKey", AUTHORIZATION_KEY); + } + headers.add(authKey, endpointData.getPayload().getDataAddress().getProperties().getAuthorization()); ResponseEntity response = httpUtil.doGet(dataPlaneEndpoint, String.class, headers, params, true, true); return jsonUtil.toJsonNode((String) response.getBody()); }catch (Exception e){ diff --git a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/DataTransferService.java b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/DataTransferService.java index 98fde2280..5f2d7042a 100644 --- a/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/DataTransferService.java +++ b/dpp-backend/digitalproductpass/src/main/java/org/eclipse/tractusx/digitalproductpass/services/DataTransferService.java @@ -41,10 +41,11 @@ import org.eclipse.tractusx.digitalproductpass.models.http.responses.IdResponse; import org.eclipse.tractusx.digitalproductpass.models.manager.History; import org.eclipse.tractusx.digitalproductpass.models.manager.Status; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.CallbackAddress; import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Catalog; import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.CatalogRequest; import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Dataset; -import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Offer; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Policy; import org.eclipse.tractusx.digitalproductpass.models.negotiation.policy.Set; import org.eclipse.tractusx.digitalproductpass.models.negotiation.response.Negotiation; import org.eclipse.tractusx.digitalproductpass.models.negotiation.response.NegotiationTransferResponse; @@ -74,6 +75,8 @@ public class DataTransferService extends BaseService { /** ATTRIBUTES **/ private final HttpUtil httpUtil; + + private final PolicyUtil policyUtil; private final JsonUtil jsonUtil; public String apiKey; public String bpnNumber; @@ -110,10 +113,11 @@ public class DataTransferService extends BaseService { /** CONSTRUCTOR(S) **/ @Autowired - public DataTransferService(Environment env, HttpUtil httpUtil, EdcUtil edcUtil, JsonUtil jsonUtil, VaultService vaultService, ProcessManager processManager, DtrConfig dtrConfig) throws ServiceInitializationException { + public DataTransferService(Environment env, HttpUtil httpUtil, EdcUtil edcUtil, JsonUtil jsonUtil, PolicyUtil policyUtil, VaultService vaultService, ProcessManager processManager, DtrConfig dtrConfig) throws ServiceInitializationException { this.httpUtil = httpUtil; this.edcUtil = edcUtil; this.jsonUtil = jsonUtil; + this.policyUtil =policyUtil; this.processManager = processManager; this.dtrConfig = dtrConfig; this.env = env; @@ -191,21 +195,21 @@ public Boolean checkEdcConsumerConnection() throws ServiceException { * Checks the EDC consumer connection by trying to establish a connection and retrieve an empty catalog. *

* - * @return a {@code String} participantId of the retrieved catalog. + * @return a {@code Boolean} true if bpn number is the same as the application one * * @throws ControllerException * if unable to check the EDC consumer connection. */ - public String getEdcConnectorBpn() throws ServiceException { + public Boolean isApplicationEdc(String applicationBpn) throws ServiceException { try { String edcConsumerDsp = this.edcEndpoint + CatenaXUtil.edcDataEndpoint; - Catalog catalog = this.getContractOfferCatalog(edcConsumerDsp, ""); // Get empty catalog - if (catalog == null || catalog.getParticipantId().isEmpty()) { - throw new ControllerException(this.getClass().getName()+".checkEdcConsumerConnection", "The catalog response is null or the participant id is not set!"); + Catalog catalog = this.getContractOfferCatalog(edcConsumerDsp, applicationBpn, ""); // Get empty catalog + if (catalog == null || catalog.getParticipantId() == null || catalog.getParticipantId().isEmpty()) { + return false; } - return catalog.getParticipantId(); + return catalog.getParticipantId().equals(applicationBpn); // Return true if the bpns matches } catch (Exception e) { - throw new ServiceException(this.getClass().getName()+".checkEdcConsumerConnection", e, "It was not possible to establish connection with the EDC consumer endpoint [" + this.edcEndpoint+"]"); + throw new ServiceException(this.getClass().getName()+".isApplicationEdc", e, "It was not possible to establish connection with the EDC consumer endpoint [" + this.edcEndpoint+"]"); } } /** @@ -293,12 +297,12 @@ public Map getContractOffers(Catalog catalog) throws ServiceExc * @throws ServiceException * if unable to get the contract offer for the assetId. */ - public Dataset getContractOfferByAssetId(String assetId, String counterPartyAddress) throws ServiceException { + public Dataset getContractOfferByAssetId(String assetId, String counterPartyAddress, String counterPartId) throws ServiceException { /* * This method receives the assetId and looks up for targets with the same name. */ try { - Catalog catalog = this.getContractOfferCatalog(counterPartyAddress, assetId); + Catalog catalog = this.getContractOfferCatalog(counterPartyAddress, counterPartId, assetId); if(catalog == null){ return null; } @@ -336,24 +340,20 @@ public Dataset getContractOfferByAssetId(String assetId, String counterPartyAddr *

* @param dataset * the {@code Dataset} data for the contract offer. - * @param status - * the {@code Status} status of the process. + * @param endpoint + * the {@code String} url from the edc * @param providerBpn * the {@code String} BPN number from provider of the catalog - * @param bpn - * the {@code String} BPN number from BNP discovery for the request. * * @return a {@code NegotiationRequest} object with the given data. * */ - public NegotiationRequest buildRequest(Dataset dataset, Status status, String bpn, String providerBpn) { - Offer contractOffer = this.buildOffer(dataset, 0); + public NegotiationRequest buildRequestFirstPolicy(Dataset dataset, String endpoint, String providerBpn) { return new NegotiationRequest( jsonUtil.toJsonNode(Map.of("odrl", "http://www.w3.org/ns/odrl/2/")), - status.getEndpoint(), - bpn, - providerBpn, - contractOffer + endpoint, + "dataspace-protocol-http", + this.buildOffer(dataset, 0, providerBpn) ); } @@ -362,36 +362,48 @@ public NegotiationRequest buildRequest(Dataset dataset, Status status, String bp *

* @param dataset * the {@code Dataset} data for the contract offer. - * @param status - * the {@code Status} status of the process. + * @param endpoint + * the {@code String} sedc endpoint * @param providerBpn * the {@code String} BPN number from provider of the catalog - * @param bpn - * the {@code String} BPN number from BNP discovery for the request. + * @param policyId + * the {@code policyId} id from the policy + * @return a {@code NegotiationRequest} object with the given data. + * + */ + public NegotiationRequest buildRequestById(Dataset dataset, String endpoint, String providerBpn, String policyId) { + Policy policy = this.buildOfferById(dataset, policyId, providerBpn); + return this.buildRequest(dataset, endpoint, providerBpn, policy); + } + + /** + * Builds a negotiation request with the given policy + *

+ * @param endpoint + * the {@code String} edc endpoint + * @param policyOffer + * the {@code Policy} policy offer to be negotiated + * * * @return a {@code NegotiationRequest} object with the given data. * */ - public NegotiationRequest buildRequestById(Dataset dataset, Status status, String bpn, String providerBpn, String policyId) { - Offer contractOffer = this.buildOfferById(dataset, policyId); + public NegotiationRequest buildRequest(String endpoint, Policy policyOffer) { return new NegotiationRequest( jsonUtil.toJsonNode(Map.of("odrl", "http://www.w3.org/ns/odrl/2/")), - status.getEndpoint(), - bpn, - providerBpn, - contractOffer + "odrl:ContractRequest", + endpoint, + "dataspace-protocol-http", + policyOffer ); } - /** * Builds a negotiation request with the given policy *

* @param dataset * the {@code Dataset} data for the contract offer. - * @param status - * the {@code Status} status of the process. - * @param bpn - * the {@code String} BPN number from BNP discovery for the request. + * @param endpoint + * the {@code String} edc endpoint * @param providerBpn * the {@code String} BPN number from provider of the catalog * @param policy @@ -401,16 +413,13 @@ public NegotiationRequest buildRequestById(Dataset dataset, Status status, Strin * @return a {@code NegotiationRequest} object with the given data. * */ - public NegotiationRequest buildRequest(Dataset dataset, Status status, String bpn, String providerBpn, Set policy) { - Offer contractOffer = this.buildOffer(dataset, policy); - return new NegotiationRequest( - jsonUtil.toJsonNode(Map.of("odrl", "http://www.w3.org/ns/odrl/2/")), - status.getEndpoint(), - bpn, - providerBpn, - contractOffer + public NegotiationRequest buildRequest(Dataset dataset, String endpoint, String providerBpn, Set policy) { + return this.buildRequest( + endpoint, + this.buildOffer(dataset, policy, providerBpn) ); } + /** * Gets a policy by index from a dataset dynamic policy data *

@@ -423,14 +432,11 @@ public NegotiationRequest buildRequest(Dataset dataset, Status status, String bp * */ public Set selectPolicyByIndex(Object policies, Integer defaultIndex){ - Set policy = null; if(policies instanceof LinkedHashMap){ - policy = (Set) jsonUtil.bindObject(policies, Set.class); - }else{ - List policyList = (List) jsonUtil.bindObject(policies, List.class); - policy = (Set) jsonUtil.bindObject(policyList.get(defaultIndex), Set.class); // Get fist policy from the list to resolve the conflict + return Set.build(policies); } - return (Set) jsonUtil.bindObject(policy, Set.class); + List policyList = (List) jsonUtil.bindObject(policies, List.class); + return Set.build(policyList.get(defaultIndex)); // Get fist policy from the list to resolve the conflict } /** @@ -444,22 +450,16 @@ public Set selectPolicyByIndex(Object policies, Integer defaultIndex){ * @return a {@code Offer} object with the given data built offer. * */ - public Offer buildOffer(Dataset dataset, Integer defaultIndex) { + public Policy buildOffer(Dataset dataset, Integer defaultIndex, String bpn) { Object rawPolicy = dataset.getPolicy(); Set policy = null; if(rawPolicy instanceof LinkedHashMap){ - policy = (Set) jsonUtil.bindObject(rawPolicy, Set.class); + policy = Set.build(rawPolicy); }else{ List policyList = (List) jsonUtil.bindObject(rawPolicy, List.class); - policy = (Set) jsonUtil.bindObject(policyList.get(defaultIndex), Set.class); // Get fist policy from the list to resolve the conflict - } - Set policyCopy = (Set) jsonUtil.bindObject(policy, Set.class); - policyCopy.setId(null); - return new Offer( - policy.getId(), - dataset.getAssetId(), - policyCopy - ); + policy = Set.build(policyList.get(defaultIndex)); // Get fist policy from the list to resolve the conflict + } + return this.buildOffer(dataset, policy, bpn); } /** * Builds a negotiation request with the given data. @@ -472,26 +472,20 @@ public Offer buildOffer(Dataset dataset, Integer defaultIndex) { * @return a {@code Offer} object with the given data built offer. * */ - public Offer buildOfferById(Dataset dataset, String policyId) { + public Policy buildOfferById(Dataset dataset, String policyId, String bpn) { try { Object rawPolicy = dataset.getPolicy(); Set policy = null; if (rawPolicy instanceof LinkedHashMap) { - policy = (Set) jsonUtil.bindObject(rawPolicy, Set.class); + policy = Set.build(rawPolicy); } else { - List policyList = (List) jsonUtil.bindReferenceType(rawPolicy, new TypeReference>() {}); + List policyList = policyUtil.parsePolicies(rawPolicy); policy = policyList.stream().filter(p -> p.getId().equals(policyId)).findAny().orElse(null); } if(policy == null) { throw new ServiceException("DataTransferService.buildOfferById()", "Failed to build offer by id! ["+policyId+"] Because policy does not exists!"); } - Set policyCopy = (Set) jsonUtil.bindObject(policy, Set.class); - policyCopy.setId(null); - return new Offer( - policy.getId(), - dataset.getAssetId(), - policyCopy - ); + return this.buildOffer(dataset, policy, bpn); }catch (Exception e) { throw new ServiceException("DataTransferService.buildOfferById()", e, "Failed to build offer by id! ["+policyId+"]"); } @@ -507,14 +501,9 @@ public Offer buildOfferById(Dataset dataset, String policyId) { * @return a {@code Offer} object with the given data built offer. * */ - public Offer buildOffer(Dataset dataset, Set policy) { - Set policyCopy = (Set) jsonUtil.bindObject(policy, Set.class); - policyCopy.setId(null); - return new Offer( - policy.getId(), - dataset.getAssetId(), - policyCopy - ); + public Policy buildOffer(Dataset dataset, Set policy, String bpn) { + Policy policyOffer = jsonUtil.bind(policy, new TypeReference<>() {}); + return policyOffer.setup(dataset.getAssetId(), bpn, "odrl:Offer"); } /** * Gets the Contract Offer's Catalog from the provider. @@ -529,7 +518,7 @@ public Offer buildOffer(Dataset dataset, Set policy) { * @throws ServiceException * if unable to retrieve the catalog. */ - public Catalog getContractOfferCatalog(String counterPartyAddress, String assetId) { + public Catalog getContractOfferCatalog(String counterPartyAddress, String counterPartyId, String assetId) { try { this.checkEmptyVariables(); @@ -544,11 +533,15 @@ public Catalog getContractOfferCatalog(String counterPartyAddress, String assetI querySpec.setFilterExpression(List.of(filterExpression)); Object body = new CatalogRequest( jsonUtil.toJsonNode(Map.of( - "@vocab", "https://w3id.org/edc/v0.0.1/ns/", - "odrl", "http://www.w3.org/ns/odrl/2/" + "edc", "https://w3id.org/edc/v0.0.1/ns/", + "odrl", "http://www.w3.org/ns/odrl/2/", + "dct","https://purl.org/dc/terms/" )), + "dataspace-protocol-http", counterPartyAddress, - querySpec + counterPartyId, + querySpec, + "edc:CatalogRequest" ); HttpHeaders headers = httpUtil.getHeaders(); headers.add("Content-Type", "application/json"); @@ -574,7 +567,7 @@ public Catalog getContractOfferCatalog(String counterPartyAddress, String assetI * @throws ServiceException * if unable to retrieve the catalog. */ - public Catalog searchDigitalTwinCatalog(String counterPartyAddress) throws ServiceException { + public Catalog searchDigitalTwinCatalog(String counterPartyAddress, String counterPartId) throws ServiceException { try { this.checkEmptyVariables(); @@ -589,11 +582,15 @@ public Catalog searchDigitalTwinCatalog(String counterPartyAddress) throws Servi querySpec.setFilterExpression(List.of(filterExpression)); Object body = new CatalogRequest( jsonUtil.toJsonNode(Map.of( - "@vocab", "https://w3id.org/edc/v0.0.1/ns/", - "odrl", "http://www.w3.org/ns/odrl/2/" + "edc", "https://w3id.org/edc/v0.0.1/ns/", + "odrl", "http://www.w3.org/ns/odrl/2/", + "dct","https://purl.org/dc/terms/" )), + "dataspace-protocol-http", CatenaXUtil.buildDataEndpoint(counterPartyAddress), - querySpec + counterPartId, + querySpec, + "edc:CatalogRequest" ); HttpHeaders headers = httpUtil.getHeaders(); @@ -626,7 +623,7 @@ public Catalog searchDigitalTwinCatalog(String counterPartyAddress) throws Servi public IdResponse doContractNegotiation(NegotiationRequest negotiationRequest) { try { this.checkEmptyVariables(); - LogUtil.printDebug("[" + negotiationRequest.getOffer().getOfferId() + "] ===== [INITIALIZING CONTRACT NEGOTIATION] ==========================================="); + LogUtil.printDebug("[" + negotiationRequest.getPolicy().getId() + "] ===== [INITIALIZING CONTRACT NEGOTIATION] ==========================================="); String url = CatenaXUtil.buildManagementEndpoint(env, this.negotiationPath); HttpHeaders headers = httpUtil.getHeaders(); headers.add("Content-Type", "application/json"); @@ -644,10 +641,8 @@ public IdResponse doContractNegotiation(NegotiationRequest negotiationRequest) { /** * Initiates the Contract Negotiation in order to retrieve it. *

- * @param contractOffer + * @param policy * the {@code Offer} object with contract offer data. - * @param bpn - * the {@code String} BPN number from BNP discovery for the request. * @param counterPartyAddress * the {@code String} URL from the provider. * @@ -656,17 +651,10 @@ public IdResponse doContractNegotiation(NegotiationRequest negotiationRequest) { * @throws ServiceException * if unable to retrieve the contract negotiation. */ - public IdResponse doContractNegotiation(Offer contractOffer, String bpn, String providerBpn, String counterPartyAddress) { + public IdResponse doContractNegotiation(Policy policy, String counterPartyAddress) { try { this.checkEmptyVariables(); - NegotiationRequest body = new NegotiationRequest( - jsonUtil.toJsonNode(Map.of("odrl", "http://www.w3.org/ns/odrl/2/")), - counterPartyAddress, - bpn, - providerBpn, - contractOffer - ); - return this.doContractNegotiation(body); + return this.doContractNegotiation(this.buildRequest(counterPartyAddress, policy)); } catch (Exception e) { throw new ServiceException(this.getClass().getName() + "." + "doContractNegotiations", e, @@ -993,42 +981,33 @@ public class NegotiateContract implements Runnable { private IdResponse tranferResponse; private Integer negotiationAttempts; private Integer transferAttempts; - private Status status; - private String bpn; + private String endpoint; private String processId; + private String providerBpn; /** CONSTRUCTOR(S) **/ public NegotiateContract() {}; - public NegotiateContract(ProcessDataModel dataModel, String processId, String bpn, String providerBpn, Dataset dataset, Status status) { - this.dataModel = dataModel; - this.processId = processId; - this.dataset = dataset; - this.status = status; - this.bpn = bpn; - this.providerBpn = providerBpn; - this.negotiationRequest = buildRequest(dataset, status, bpn, providerBpn); - } // Negotiate contract with policy - public NegotiateContract(ProcessDataModel dataModel, String processId, String bpn, String providerBpn, Dataset dataset, Status status, Set policy) { + public NegotiateContract(ProcessDataModel dataModel, String processId, String providerBpn, Dataset dataset, String endpoint, Set policy) { this.dataModel = dataModel; this.processId = processId; this.dataset = dataset; - this.status = status; - this.bpn = bpn; - this.negotiationRequest = buildRequest(dataset, status, bpn, providerBpn, policy); + this.endpoint = endpoint; + this.providerBpn = providerBpn; + this.negotiationRequest = buildRequest(dataset, endpoint, providerBpn, policy); } // Start the negotiation and build contract by policy id - public NegotiateContract(ProcessDataModel dataModel, String processId, String bpn, String providerBpn, Dataset dataset, Status status, String policyId) { + public NegotiateContract(ProcessDataModel dataModel, String processId,String providerBpn, Dataset dataset, String endpoint, String policyId) { this.dataModel = dataModel; this.processId = processId; this.dataset = dataset; - this.status = status; - this.bpn = bpn; - this.negotiationRequest = buildRequestById(dataset, status, bpn, providerBpn, policyId); + this.endpoint = endpoint; + this.providerBpn = providerBpn; + this.negotiationRequest = buildRequestById(dataset, endpoint, providerBpn, policyId); } - public NegotiateContract(NegotiationRequest negotiationRequest, ProcessDataModel dataModel, Dataset dataset, Negotiation negotiation, Transfer transfer, TransferRequest transferRequest, IdResponse negotiationResponse, IdResponse tranferResponse, Integer negotiationAttempts, Integer transferAttempts, Status status, String bpn, String processId, String providerBpn) { + public NegotiateContract(NegotiationRequest negotiationRequest, ProcessDataModel dataModel, Dataset dataset, Negotiation negotiation, Transfer transfer, TransferRequest transferRequest, IdResponse negotiationResponse, IdResponse tranferResponse, Integer negotiationAttempts, Integer transferAttempts, String endpoint, String processId, String providerBpn) { this.negotiationRequest = negotiationRequest; this.dataModel = dataModel; this.dataset = dataset; @@ -1039,8 +1018,7 @@ public NegotiateContract(NegotiationRequest negotiationRequest, ProcessDataModel this.tranferResponse = tranferResponse; this.negotiationAttempts = negotiationAttempts; this.transferAttempts = transferAttempts; - this.status = status; - this.bpn = bpn; + this.endpoint = endpoint; this.processId = processId; this.providerBpn = providerBpn; } @@ -1102,12 +1080,12 @@ public void setTransferAttempts(Integer transferAttempts) { this.transferAttempts = transferAttempts; } - public Status getStatus() { - return status; + public String getEndpoint() { + return endpoint; } - public void setStatus(Status status) { - this.status = status; + public void setEndpoint(String endpoint) { + this.endpoint = endpoint; } public String getProcessId() { @@ -1163,45 +1141,37 @@ public void setTranferResponse(IdResponse tranferResponse) { *

* @param dataset * the {@code Dataset} data for the contract offer. - * @param status - * the {@code Status} object of the process. + * @param endpoint + * the {@code String} edc endpoint * @param negotiation * the {@code Negotiation} object for the request. - * @param bpn - * the {@code String} BPN number from BNP discovery for the request. * * @return a {@code TransferRequest} object with the given data. * * @throws ServiceException * if unable to build the transfer request. */ - public TransferRequest buildTransferRequest(Dataset dataset, Status status, Negotiation negotiation, String bpn) { + public TransferRequest buildTransferRequest(Dataset dataset, String endpoint, Negotiation negotiation) { try { String receiverEndpoint = env.getProperty("configuration.edc.receiverEndpoint") + "/" + this.processId; // Send process Id to identification the session. - TransferRequest.TransferType transferType = new TransferRequest.TransferType(); - - transferType.setContentType(env.getProperty("configuration.edc.transferType")); - transferType.setIsFinite(true); TransferRequest.DataDestination dataDestination = new TransferRequest.DataDestination(); dataDestination.setType("HttpProxy"); - TransferRequest.PrivateProperties privateProperties = new TransferRequest.PrivateProperties(); - privateProperties.setReceiverHttpEndpoint(receiverEndpoint); - privateProperties.setReceiverHttpEndpoint(receiverEndpoint); + + List callbackAddresses = List.of(CallbackAddress.builder().transactional(false).uri(receiverEndpoint).events(List.of("transfer.process.started")).build()); + return new TransferRequest( jsonUtil.toJsonNode(Map.of("odrl", "http://www.w3.org/ns/odrl/2/","@vocab", "https://w3id.org/edc/v0.0.1/ns/")), dataset.getAssetId(), - status.getEndpoint(), - bpn, + endpoint, negotiation.getContractAgreementId(), dataDestination, false, - privateProperties, "dataspace-protocol-http", - transferType, - List.of() + env.getProperty("configuration.edc.transferType"), + callbackAddresses ); } catch (Exception e) { throw new ServiceException(this.getClass().getName(), e, "Failed to build the transfer request!"); @@ -1251,7 +1221,7 @@ public void run() { LogUtil.printStatus("[PROCESS " + this.processId + "] Negotiation Finished with status [" + negotiation.getState() + "]!"); // TRANSFER PROCESS try { - this.transferRequest = buildTransferRequest(this.dataset, this.status, this.negotiation, this.bpn); + this.transferRequest = buildTransferRequest(this.dataset, this.endpoint, this.negotiation); processManager.saveTransferRequest(this.processId, transferRequest, new IdResponse(processId, null), false); this.tranferResponse = this.requestTransfer(transferRequest); processManager.saveTransferRequest(this.processId, transferRequest, this.tranferResponse, false); @@ -1312,11 +1282,11 @@ public IdResponse requestNegotiation(NegotiationRequest negotiationRequest) { try { negotiationResponse = doContractNegotiation(negotiationRequest); } catch (Exception e) { - throw new ServiceException(this.getClass().getName(), e, "Failed to start the negotiation for offer [" + negotiationRequest.getOffer().getOfferId() + "]"); + throw new ServiceException(this.getClass().getName(), e, "Failed to start the negotiation for offer [" + negotiationRequest.getPolicy().getId() + "]"); } if (negotiationResponse.getId() == null) { - throw new ServiceException(this.getClass().getName(), "The ID from the Offer is null [" + negotiationRequest.getOffer().getOfferId() + "]"); + throw new ServiceException(this.getClass().getName(), "The ID from the Offer is null [" + negotiationRequest.getPolicy().getId() + "]"); } LogUtil.printMessage("[PROCESS " + this.processId + "] Negotiation Requested [" + negotiationResponse.getId() + "]"); return negotiationResponse; @@ -1451,27 +1421,20 @@ public TransferRequest buildTransferRequest(String processId, Dtr dtr, String en try { // Build transfer request to make the Digital Twin Query String receiverEndpoint = env.getProperty("configuration.edc.receiverEndpoint") + "/" + processId + "/" + endpointId; - TransferRequest.TransferType transferType = new TransferRequest.TransferType(); - - transferType.setContentType(env.getProperty("configuration.edc.transferType")); - transferType.setIsFinite(true); TransferRequest.DataDestination dataDestination = new TransferRequest.DataDestination(); dataDestination.setType("HttpProxy"); - TransferRequest.PrivateProperties privateProperties = new TransferRequest.PrivateProperties(); - privateProperties.setReceiverHttpEndpoint(receiverEndpoint); + List callbackAddresses = List.of(CallbackAddress.builder().transactional(false).uri(receiverEndpoint).events(List.of("transfer.process.started")).build()); return new TransferRequest( jsonUtil.toJsonNode(Map.of("odrl", "http://www.w3.org/ns/odrl/2/","@vocab", "https://w3id.org/edc/v0.0.1/ns/")), dtr.getAssetId(), CatenaXUtil.buildDataEndpoint(dtr.getEndpoint()), - bpnNumber, dtr.getContractId(), dataDestination, false, - privateProperties, "dataspace-protocol-http", - transferType, - List.of() + env.getProperty("configuration.edc.transferType"), + callbackAddresses ); } catch (Exception e) { throw new ServiceException(this.getClass().getName(), e, "Failed to build the transfer request!"); diff --git a/dpp-backend/digitalproductpass/src/main/java/utils/CatenaXUtil.java b/dpp-backend/digitalproductpass/src/main/java/utils/CatenaXUtil.java index 6e54e6d8d..3d314862b 100644 --- a/dpp-backend/digitalproductpass/src/main/java/utils/CatenaXUtil.java +++ b/dpp-backend/digitalproductpass/src/main/java/utils/CatenaXUtil.java @@ -88,6 +88,8 @@ public static Boolean containsEdcEndpoint(String str) { * */ public static String buildDataEndpoint(String endpoint) { + if(endpoint.contains(edcDataEndpoint)) + return endpoint; return endpoint + edcDataEndpoint; } diff --git a/dpp-backend/digitalproductpass/src/main/java/utils/EdcUtil.java b/dpp-backend/digitalproductpass/src/main/java/utils/EdcUtil.java index cd91f90cd..63000cc26 100644 --- a/dpp-backend/digitalproductpass/src/main/java/utils/EdcUtil.java +++ b/dpp-backend/digitalproductpass/src/main/java/utils/EdcUtil.java @@ -74,7 +74,7 @@ public EdcUtil(JsonUtil jsonUtil,PolicyUtil policyUtil) { */ public EndpointDataReference parseDataPlaneEndpoint(Object body) { try { - return (EndpointDataReference) this.jsonUtil.bindObject(body, EndpointDataReference.class); + return this.jsonUtil.bind(body, new TypeReference<>() {}); } catch (Exception e) { throw new UtilException(EdcUtil.class, e, "It was not possible to parse the data plain endpoint"); } @@ -206,7 +206,7 @@ public Map filterValidContracts(Map contracts, */ public Boolean isContractValid(Dataset contract, PolicyCheckConfig policyConfig){ try { - return policyUtil.getValidPoliciesByConstraints(contract, policyConfig).size() > 0; // If any policy is found the contract is valid + return policyUtil.getValidPoliciesByConstraints(contract.getPolicy(), policyConfig).size() > 0; // If any policy is found the contract is valid } catch (Exception e) { throw new UtilException(EdcUtil.class, e, "It was not possible to check if contract is valid"); } diff --git a/dpp-backend/digitalproductpass/src/main/java/utils/PolicyUtil.java b/dpp-backend/digitalproductpass/src/main/java/utils/PolicyUtil.java index 0ec3b6a89..d37f3ada6 100644 --- a/dpp-backend/digitalproductpass/src/main/java/utils/PolicyUtil.java +++ b/dpp-backend/digitalproductpass/src/main/java/utils/PolicyUtil.java @@ -26,22 +26,18 @@ package utils; -import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; import org.eclipse.tractusx.digitalproductpass.config.PolicyCheckConfig; -import org.eclipse.tractusx.digitalproductpass.config.PolicyCheckConfig.ActionConfig; import org.eclipse.tractusx.digitalproductpass.config.PolicyCheckConfig.PolicyConfig; -import org.eclipse.tractusx.digitalproductpass.models.edc.EndpointDataReference; import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Dataset; -import org.eclipse.tractusx.digitalproductpass.models.negotiation.policy.Constraint; import org.eclipse.tractusx.digitalproductpass.models.negotiation.policy.Set; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import utils.exceptions.UtilException; -import java.util.ArrayList; - -import java.util.LinkedHashMap; -import java.util.List; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; /** @@ -89,18 +85,19 @@ public Set getPolicyById(Dataset dataset, String policyId) { if (rawPolicy == null) { return null; } + Set policy = null; // If the policy is an object if (rawPolicy instanceof LinkedHashMap) { - policy = (Set) this.jsonUtil.bindObject(rawPolicy, Set.class); + policy = Set.build(rawPolicy); } else { - List policyList = (List) this.jsonUtil.bindObject(rawPolicy, List.class); + List policyList = this.parsePolicies(rawPolicy); if (policyList == null) { return null; } - policy = (Set) this.jsonUtil.bindObject(policyList.stream().filter( - (p) -> p.get("@id").equals(policyId) - ).findFirst(), Set.class); // Get policy with the specific policy id + policy = policyList.stream().filter( + (p) -> p.getId().equals(policyId) + ).findFirst().orElse(null); } // If the policy does not exist if (policy == null) { @@ -113,6 +110,88 @@ public Set getPolicyById(Dataset dataset, String policyId) { return policy; } + /** + * Gets a specific policy from a dataset by id + *

+ * + * @param dataset the {@code Dataset} object of data set contained in the catalog + * @param policyId {@code String} the id of the policy to get + * @param policyConfig {@code PolicyCheckConfig} the policy configuration + * @return Set of policy if found or null otherwise. + */ + public Set getCompliantPolicyById(Dataset dataset, String policyId, PolicyCheckConfig policyConfig) { + // If the policy check is disabled get the policy from all the contract available policies + if(!policyConfig.getEnabled()){ + return this.getPolicyById(dataset,policyId); + } + + Object rawPolicies = dataset.getPolicy(); + // If the policy is not available + if (rawPolicies == null) { + return null; + } + + // Get all the valid policies for this contract + Map policies = this.getValidPolicyMapByConstraints(rawPolicies, policyConfig); + + java.util.Set keys = policies.keySet(); + + if(keys.size() == 0){ + return null; // No valid policies available for this contract + } + + // If policy id is not specified find any compliant policy in the contract + if(policyId == null){ + policyId = keys.stream().findAny().orElse(null); + } + + if(!policies.containsKey(policyId)){ + return null; // Policy does not exists; + } + return policies.get(policyId); + } + + /** + * Gets a specific policy from a dataset by constraint + *

+ * + * @param policies the {@code Object} object of with one or more policies + * @param policyCheckConfigs {@code List} list of constraints for the permissions + * @return Map of of valid policies for constraints by id or null if the policy or policies are not valid. + */ + public Map getValidPolicyMapByConstraints(Object policies, PolicyCheckConfig policyCheckConfigs) { + // Find if policy is array or object and call the evaluate functions + try { + // If the policy is not available + if (policies == null || policyCheckConfigs == null) { + return null; + } + // Generate configuration policies + List policyConfigs = policyCheckConfigs.getPolicies(); + List validPolicies = this.buildPolicies(policyConfigs); + + Boolean strictMode = policyCheckConfigs.getStrictMode(); + // There is no valid policy available + if (validPolicies == null || validPolicies.size() == 0) { + return null; + } + if (policies instanceof LinkedHashMap) { + // Check if policy is valid or not + Set policy = Set.build(policies); + // In case the policy is valid return the policy + if(this.isPolicyValid(policy, validPolicies, strictMode)){ + return new HashMap<>(){{put(policy.getId(), policy);}}; // Add policy to a list of valid policies + } + // If the policy is not valid return an empty list + return new HashMap<>(); + } + List policyList = this.parsePolicies(policies); + //Search for policies that are valid and get one of the valid ones + return policyList.stream().parallel().filter(p -> this.isPolicyValid(p, validPolicies, strictMode)).collect(Collectors.toMap(Set::getId, Function.identity())); + }catch (Exception e) { + throw new UtilException(PolicyUtil.class, "It was not possible to get policy by constraints!"); + } + } /** * Gets a specific policy from a dataset by constraint @@ -129,8 +208,10 @@ public List getValidPoliciesByConstraints(Object policies, PolicyCheckConfi if (policies == null || policyCheckConfigs == null) { return null; } + // Generate configuration policies List policyConfigs = policyCheckConfigs.getPolicies(); List validPolicies = this.buildPolicies(policyConfigs); + Boolean strictMode = policyCheckConfigs.getStrictMode(); // There is no valid policy available if (validPolicies == null || validPolicies.size() == 0) { @@ -138,7 +219,7 @@ public List getValidPoliciesByConstraints(Object policies, PolicyCheckConfi } if (policies instanceof LinkedHashMap) { // Check if policy is valid or not - Set policy = jsonUtil.bind(policies, new TypeReference<>(){}); + Set policy = Set.build(policies); // In case the policy is valid return the policy if(this.isPolicyValid(policy, validPolicies, strictMode)){ return new ArrayList<>(){{add(policy);}}; // Add policy to a list of valid policies @@ -146,12 +227,7 @@ public List getValidPoliciesByConstraints(Object policies, PolicyCheckConfi // If the policy is not valid return an empty list return new ArrayList<>(); } - List policyList; - try { - policyList = jsonUtil.bind(policies, new TypeReference<>(){}); - } catch (Exception e) { - throw new UtilException(PolicyUtil.class, e, "It was not possible to parse the policy list"); - } + List policyList = this.parsePolicies(policies); //Search for policies that are valid and get one of the valid ones return policyList.stream().parallel().filter(p -> this.isPolicyValid(p, validPolicies, strictMode)).toList(); }catch (Exception e) { @@ -230,6 +306,30 @@ public Boolean isPolicyConstraintsValid(Set policy, Set configPolicy){ throw new UtilException(PolicyUtil.class, e, "[DEFAULT MODE] It was not possible to check if policy is valid!"); } } + /** + * Builds a policy from a raw policy object + *

+ * + * @param rawPolicy {@code Object} the policy to be checked + * @return {@code Set} the list of parsed policies built from the configuration parameters + * @throws UtilException if error when parsing the contracts + */ + public List parsePolicies(Object rawPolicy){ + try { + JsonNode policy = jsonUtil.toJsonNode(rawPolicy); + if(!policy.isArray()){ + return new ArrayList<>(){{add(Set.build(policy));}}; + } + List policies = new ArrayList<>(); + for (JsonNode p : policy) { + policies.add(Set.build(p)); + } + return policies; + }catch (Exception e) { + throw new UtilException(PolicyUtil.class, e, "It was not possible to create a new policies!"); + } + } + /** * Checks a policy configuration strictly against the incoming policy *

@@ -243,7 +343,6 @@ public Boolean defaultPolicyCheck(Set policy, List validPolicies){ try { // Filter the list of policies based on the policy configuration List policies = validPolicies.stream().filter(p -> this.isPolicyConstraintsValid(policy, p)).toList(); - System.out.println("[VALID POLICIES] " + policies); return policies.size() > 0; //If any policy is valid then return true }catch (Exception e) { throw new UtilException(PolicyUtil.class, e, "[DEFAULT MODE] It was not possible to check if policy is valid!"); diff --git a/dpp-backend/digitalproductpass/src/main/resources/application.yml b/dpp-backend/digitalproductpass/src/main/resources/application.yml index e31aacf78..e3bbeee9a 100644 --- a/dpp-backend/digitalproductpass/src/main/resources/application.yml +++ b/dpp-backend/digitalproductpass/src/main/resources/application.yml @@ -56,9 +56,10 @@ configuration: transfer: '/transferprocesses' receiverEndpoint: 'https://dpp.int.demo.catena-x.net/endpoint' delay: 100 # -- Negotiation status Delay in milliseconds in between async requests [<= 500] - transferType: "application/octet-stream" + transferType: "HttpData-PULL" timeout: exchange: 10 + authorizationKey: "Authorization" security: authorization: @@ -152,6 +153,7 @@ configuration: - "urn:samm:io.catenax.generic.digital_product_passport:2.0.0#DigitalProductPassport" policyCheck: enabled: true + strictMode: false policies: - permission: - action: "USE" diff --git a/dpp-backend/digitalproductpass/src/test/java/managers/ProcessManagerTest.java b/dpp-backend/digitalproductpass/src/test/java/managers/ProcessManagerTest.java index 3a8841e2a..c21cea6e2 100644 --- a/dpp-backend/digitalproductpass/src/test/java/managers/ProcessManagerTest.java +++ b/dpp-backend/digitalproductpass/src/test/java/managers/ProcessManagerTest.java @@ -43,7 +43,6 @@ import org.eclipse.tractusx.digitalproductpass.models.manager.History; import org.eclipse.tractusx.digitalproductpass.models.manager.Process; import org.eclipse.tractusx.digitalproductpass.models.manager.Status; -import org.eclipse.tractusx.digitalproductpass.models.negotiation.*; import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Dataset; import org.eclipse.tractusx.digitalproductpass.models.negotiation.request.NegotiationRequest; import org.eclipse.tractusx.digitalproductpass.models.negotiation.request.TransferRequest; @@ -493,12 +492,8 @@ void saveTransferInfo() { @Test void saveNegotiationRequestAndNegotiation() { NegotiationRequest negotiationRequest = new NegotiationRequest(); - String providerId = UUID.randomUUID().toString(); - String connectorId = UUID.randomUUID().toString(); negotiationRequest.setProtocol("HTTP"); - negotiationRequest.setProviderId(providerId); - negotiationRequest.setConnectorAddress("connectorAddress"); - negotiationRequest.setConnectorId(connectorId); + negotiationRequest.setCounterPartyAddress("connectorAddress"); String negotiationId = UUID.randomUUID().toString(); String contractAgreement = UUID.randomUUID().toString(); @@ -524,8 +519,6 @@ void saveNegotiationRequestAndNegotiation() { Map init = (Map) updatedNegotiation.get("init"); NegotiationRequest updatedNegotiationRequest = (NegotiationRequest) jsonUtil.bindObject(init.get("request"), NegotiationRequest.class); - assertEquals(providerId, updatedNegotiationRequest.getProviderId()); - assertEquals(connectorId, updatedNegotiationRequest.getConnectorId()); assertEquals("HTTP", updatedNegotiationRequest.getProtocol()); Map get = (Map) updatedNegotiation.get("get"); @@ -615,7 +608,6 @@ void saveTransferRequestAndTransfer() { transferRequest.setContractId(contractId); transferRequest.setAssetId(assetId); transferRequest.setConnectorAddress("connectorAddress"); - transferRequest.setConnectorId(connectorId); String transferId = UUID.randomUUID().toString(); Transfer transfer = new Transfer(); @@ -639,7 +631,6 @@ void saveTransferRequestAndTransfer() { TransferRequest updatedTransferRequest = (TransferRequest) jsonUtil.bindObject(init.get("request"), TransferRequest.class); assertEquals(contractId, updatedTransferRequest.getContractId()); - assertEquals(connectorId, updatedTransferRequest.getConnectorId()); assertEquals("HTTP", updatedTransferRequest.getProtocol()); Map get = (Map) updatedTransfer.get("get"); @@ -656,29 +647,7 @@ void loadPassportReturnsManagerException() { } @Test void saveAndLoadPassport() { - when(env.getProperty("passport.dataTransfer.encrypt", Boolean.class, true)).thenReturn(false); - EndpointDataReference dataPlaneEndpoint = new EndpointDataReference(); - String id = UUID.randomUUID().toString(); - String authKey = UUID.randomUUID().toString(); - String contractId = UUID.randomUUID().toString(); - String authCode = processManager.generateToken(processManager.getProcess(mockedHttpServletRequest, testProcessId), contractId); - dataPlaneEndpoint.setId(id); - dataPlaneEndpoint.setEndpoint("passportEndpoint"); - dataPlaneEndpoint.setAuthCode(authCode); - dataPlaneEndpoint.setAuthKey(authKey); - - - String file = Paths.get(fileUtil.getBaseClassDir(this.getClass()), testPassportPath).toString(); - JsonNode passport = (JsonNode) jsonUtil.fromJsonFileToObject(file, JsonNode.class); - - processManager.savePassport(testProcessId, dataPlaneEndpoint, passport); - - JsonNode loadedPassport = processManager.loadPassport(testProcessId); - Status status = processManager.getStatus(testProcessId); - - assertEquals(passport, loadedPassport); - assertEquals("RETRIEVED", status.getHistory("data-retrieved").getStatus()); } @Test diff --git a/dpp-backend/digitalproductpass/src/test/java/services/AasServiceTest.java b/dpp-backend/digitalproductpass/src/test/java/services/AasServiceTest.java index 015267db8..715e154a6 100644 --- a/dpp-backend/digitalproductpass/src/test/java/services/AasServiceTest.java +++ b/dpp-backend/digitalproductpass/src/test/java/services/AasServiceTest.java @@ -140,7 +140,7 @@ void setUpAll() throws ServiceInitializationException { baseDataDirPath = Path.of(fileUtil.getDataDir(), processConfig.getDir()).toString(); processManager = new ProcessManager(httpUtil, jsonUtil, fileUtil, processConfig); dtrSearchManager = new DtrSearchManager(fileUtil,edcUtil, jsonUtil, new PolicyUtil(), dataTransferService, dtrConfig, processManager); - dataTransferService = new DataTransferService(env, httpUtil,edcUtil, jsonUtil,vaultService, processManager, dtrConfig); + dataTransferService = new DataTransferService(env, httpUtil,edcUtil, jsonUtil,new PolicyUtil(),vaultService, processManager, dtrConfig); authenticationService = Mockito.spy(new AuthenticationService(vaultService, env, httpUtil, jsonUtil, securityConfig)); mockedToken = (JwtToken) jsonUtil.fromJsonFileToObject(Paths.get(fileUtil.getBaseClassDir(this.getClass()), mockedTokenPath).toString(), JwtToken.class); doReturn(mockedToken).when(authenticationService).getToken(); diff --git a/dpp-backend/digitalproductpass/src/test/java/services/CatenaXServiceTest.java b/dpp-backend/digitalproductpass/src/test/java/services/CatenaXServiceTest.java index bb9a9291a..88740999f 100644 --- a/dpp-backend/digitalproductpass/src/test/java/services/CatenaXServiceTest.java +++ b/dpp-backend/digitalproductpass/src/test/java/services/CatenaXServiceTest.java @@ -128,7 +128,7 @@ void setUpAll() throws ServiceInitializationException { ProcessConfig processConfig = new ProcessConfig(); processConfig.setDir("process"); ProcessManager processManager = new ProcessManager(httpUtil, jsonUtil, fileUtil, processConfig); - dataTransferService = new DataTransferService(env, httpUtil,edcUtil, jsonUtil, vaultService, processManager, dtrConfig); + dataTransferService = new DataTransferService(env, httpUtil,edcUtil, jsonUtil, new PolicyUtil(),vaultService, processManager, dtrConfig); discoveryConfig = initDiscoveryConfig(); dtrConfig = initDtrConfig(); diff --git a/dpp-backend/digitalproductpass/src/test/java/services/DataPlaneServiceTest.java b/dpp-backend/digitalproductpass/src/test/java/services/DataPlaneServiceTest.java index a27614090..cd0736168 100644 --- a/dpp-backend/digitalproductpass/src/test/java/services/DataPlaneServiceTest.java +++ b/dpp-backend/digitalproductpass/src/test/java/services/DataPlaneServiceTest.java @@ -93,11 +93,14 @@ void getPassportFromEndpoint() { String endpoint = UUID.randomUUID().toString(); String authKey = UUID.randomUUID().toString(); String authCode = UUID.randomUUID().toString(); - EndpointDataReference dataPlaneEndpoint = new EndpointDataReference(); - dataPlaneEndpoint.setId(id); - dataPlaneEndpoint.setEndpoint(endpoint); - dataPlaneEndpoint.setAuthKey(authKey); - dataPlaneEndpoint.setAuthCode(authCode); + EndpointDataReference dataPlaneEndpoint = EndpointDataReference.builder().id(id) + .payload( + EndpointDataReference.Payload.builder().dataAddress( + EndpointDataReference.DataAddress.builder().properties( + EndpointDataReference.Properties.builder().endpoint(endpoint).authorization(authCode).build() + ).build() + ).build() + ).build(); String dataPLaneEndpointStr = "test.endpoint"; JsonNode passport = dataPlaneService.getPassportFromEndpoint(dataPlaneEndpoint, dataPLaneEndpointStr); diff --git a/dpp-backend/digitalproductpass/src/test/java/services/DataTransferServiceTest.java b/dpp-backend/digitalproductpass/src/test/java/services/DataTransferServiceTest.java index 5f34a695c..10f206b14 100644 --- a/dpp-backend/digitalproductpass/src/test/java/services/DataTransferServiceTest.java +++ b/dpp-backend/digitalproductpass/src/test/java/services/DataTransferServiceTest.java @@ -34,11 +34,11 @@ import org.eclipse.tractusx.digitalproductpass.managers.ProcessManager; import org.eclipse.tractusx.digitalproductpass.models.http.responses.IdResponse; import org.eclipse.tractusx.digitalproductpass.models.manager.Status; -import org.eclipse.tractusx.digitalproductpass.models.negotiation.*; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.CallbackAddress; import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Catalog; import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.CatalogRequest; import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Dataset; -import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Offer; +import org.eclipse.tractusx.digitalproductpass.models.negotiation.catalog.Policy; import org.eclipse.tractusx.digitalproductpass.models.negotiation.policy.Set; import org.eclipse.tractusx.digitalproductpass.models.negotiation.request.NegotiationRequest; import org.eclipse.tractusx.digitalproductpass.models.negotiation.request.TransferRequest; @@ -53,7 +53,6 @@ import org.junit.jupiter.api.TestInstance; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.sonarsource.scanner.api.internal.shaded.minimaljson.Json; import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -120,7 +119,7 @@ void setUpAll() throws ServiceInitializationException { processConfig.setDir("process"); processManager = new ProcessManager(httpUtil, jsonUtil, fileUtil, processConfig); - dataTransferService = new DataTransferService(env, httpUtil,edcUtil, jsonUtil, vaultService, processManager, dtrConfig); + dataTransferService = new DataTransferService(env, httpUtil,edcUtil, jsonUtil,new PolicyUtil(), vaultService, processManager, dtrConfig); when(httpUtil.getHeaders()).thenReturn(new HttpHeaders()); when(httpUtil.getParams()).thenReturn(new HashMap<>()); @@ -187,10 +186,9 @@ void checkEdcConsumerConnection() { when(httpUtil.doPost(anyString(), any(Class.class), any(HttpHeaders.class), any(Map.class), any(Object.class), eq(false), eq(false))) .thenReturn(new ResponseEntity<>(jsonUtil.fromJsonFileToObject(Paths.get(fileUtil.getBaseClassDir(this.getClass()), testCOCatalogPath).toString(), JsonNode.class), HttpStatus.OK)); - String participantId = dataTransferService.getEdcConnectorBpn(); + Boolean result = dataTransferService.isApplicationEdc(bpn); - assertNotNull(participantId); - assertEquals(vaultService.getLocalSecret("edc.participantId"), participantId); + assertTrue(result); } @Test @@ -198,36 +196,32 @@ void buildRequestAndOffer() { Status status = new Status(); status.setEndpoint("test.endpoint"); - NegotiationRequest negotiationRequest = dataTransferService.buildRequest(dataSet, status, bpn, bpn); + NegotiationRequest negotiationRequest = dataTransferService.buildRequest(dataSet, status.getEndpoint(), bpn, this.policy); assertNotNull(negotiationRequest); - assertEquals(status.getEndpoint(), negotiationRequest.getConnectorAddress()); - assertEquals(bpn, negotiationRequest.getConnectorId()); + assertEquals(status.getEndpoint(), negotiationRequest.getCounterPartyAddress()); + assertEquals(bpn, negotiationRequest.getPolicy().getAssigner().getId()); - Offer offer = negotiationRequest.getOffer(); + Policy policyOffer = negotiationRequest.getPolicy(); - assertNotNull(offer); - assertEquals(dataSet.getAssetId(), offer.getAssetId()); - assertEquals(policy.getId(), offer.getOfferId()); - assertNotNull(offer.getPolicy()); + assertNotNull(policyOffer); + assertEquals(dataSet.getAssetId(), policyOffer.getTarget().getId()); + assertEquals(policy.getId(), policyOffer.getId()); + assertNotNull(policy); } @Test void getContractOfferCatalog() { String providerUrl = UUID.randomUUID().toString(); Catalog catalog = (Catalog) jsonUtil.fromJsonFileToObject(Paths.get(fileUtil.getBaseClassDir(this.getClass()), testCOCatalogPath).toString(), Catalog.class); - String assetId = catalog.getParticipantId(); + String assetId = catalog.getId(); when(httpUtil.doPost(anyString(), any(Class.class), any(HttpHeaders.class), any(Map.class), any(Object.class), eq(false), eq(false))) .then(invocation -> { - CatalogRequest body = invocation.getArgument(4); - if (body.getCounterPartyAddress().equals(providerUrl)) { - return new ResponseEntity<>(jsonUtil.fromJsonFileToObject(Paths.get(fileUtil.getBaseClassDir(this.getClass()), testCOCatalogPath).toString(), JsonNode.class), HttpStatus.OK); - } - return new ResponseEntity<>(null, HttpStatus.NOT_FOUND); + return new ResponseEntity<>(jsonUtil.fromJsonFileToObject(Paths.get(fileUtil.getBaseClassDir(this.getClass()), testCOCatalogPath).toString(), JsonNode.class), HttpStatus.OK); }); - Catalog offerCatalog = dataTransferService.getContractOfferCatalog(providerUrl, assetId); + Catalog offerCatalog = dataTransferService.getContractOfferCatalog(providerUrl, bpn, assetId); assertNotNull(offerCatalog); assertNotEquals(catalog, offerCatalog); @@ -248,15 +242,11 @@ void searchDigitalTwinCatalog() { when(httpUtil.doPost(anyString(), any(Class.class), any(HttpHeaders.class), any(Map.class), any(Object.class), eq(false), eq(false))) .then(invocation -> { - CatalogRequest body = invocation.getArgument(4); - if (body.getCounterPartyAddress().equals(CatenaXUtil.buildDataEndpoint(providerUrl))) { - return new ResponseEntity<>(jsonUtil.fromJsonFileToObject(Paths.get(fileUtil.getBaseClassDir(this.getClass()), testDTCatalogPath).toString(), JsonNode.class), HttpStatus.OK); - } - return new ResponseEntity<>(null, HttpStatus.NOT_FOUND); + return new ResponseEntity<>(jsonUtil.fromJsonFileToObject(Paths.get(fileUtil.getBaseClassDir(this.getClass()), testDTCatalogPath).toString(), JsonNode.class), HttpStatus.OK); }); - Catalog digitalTwinCatalog = dataTransferService.searchDigitalTwinCatalog(providerUrl); - + Catalog digitalTwinCatalog = dataTransferService.searchDigitalTwinCatalog(providerUrl, bpn); + LogUtil.printTest(jsonUtil.toJson(digitalTwinCatalog, true)); assertNotNull(digitalTwinCatalog); assertNotEquals(catalog, digitalTwinCatalog); assertEquals(catalog.getId(), digitalTwinCatalog.getId()); @@ -265,14 +255,14 @@ void searchDigitalTwinCatalog() { assertEquals(catalog.getContext(), digitalTwinCatalog.getContext()); Map contractOffer = (Map) jsonUtil.toMap(digitalTwinCatalog.getContractOffers()); - assertEquals("data.core.digitalTwinRegistry", contractOffer.get("type")); + assertEquals("data.core.digitalTwinRegistry", contractOffer.get("asset:prop:type")); } @Test void doContractNegotiationAndSeeNegotiation() { String providerUrl = UUID.randomUUID().toString(); - Offer offer = dataTransferService.buildOffer(dataSet, 0); + Policy policyOffer = dataTransferService.buildOffer(dataSet, 0, bpn); when(httpUtil.doPost(anyString(), any(Class.class), any(HttpHeaders.class), any(Map.class), any(NegotiationRequest.class), eq(false), eq(false))) .then(invocation -> { @@ -283,11 +273,11 @@ void doContractNegotiationAndSeeNegotiation() { return new ResponseEntity<>(null, HttpStatus.NOT_FOUND); }); - IdResponse response = dataTransferService.doContractNegotiation(offer, bpn, bpn, providerUrl); + IdResponse response = dataTransferService.doContractNegotiation(policyOffer, providerUrl); assertNotNull(response); assertEquals("189f4957-0fbe-4d73-b215-977e3303a45e", response.getId()); - assertEquals("IdResponseDto", response.getType()); + assertEquals("IdResponse", response.getType()); when(httpUtil.doGet(anyString(), eq(NegotiationTransferResponse.class), any(HttpHeaders.class), any(Map.class), eq(false), eq(false))) .thenReturn(new ResponseEntity<>(jsonUtil.fromJsonFileToObject(Paths.get(fileUtil.getBaseClassDir(this.getClass()), testResponseNegotiationPath).toString(), Negotiation.class), HttpStatus.OK)); @@ -298,13 +288,13 @@ void doContractNegotiationAndSeeNegotiation() { Negotiation negotiation = dataTransferService.seeNegotiation(response.getId()); assertEquals(response.getId(), negotiation.getId()); - assertEquals("ContractNegotiationDto", negotiation.getType()); + assertEquals("ContractNegotiation", negotiation.getType()); assertEquals("FINALIZED", negotiation.getState()); } private Negotiation getNegotiation() { String providerUrl = UUID.randomUUID().toString(); - Offer offer = dataTransferService.buildOffer(dataSet, 0); + Policy policyOffer = dataTransferService.buildOffer(dataSet, 0, bpn); when(httpUtil.doPost(anyString(), any(Class.class), any(HttpHeaders.class), any(Map.class), any(NegotiationRequest.class), eq(false), eq(false))) .then(invocation -> { @@ -315,7 +305,7 @@ private Negotiation getNegotiation() { return new ResponseEntity<>(null, HttpStatus.NOT_FOUND); }); - IdResponse negotiationResponse = dataTransferService.doContractNegotiation(offer, bpn,bpn, providerUrl); + IdResponse negotiationResponse = dataTransferService.doContractNegotiation(policyOffer, providerUrl); when(httpUtil.doGet(anyString(), eq(NegotiationTransferResponse.class), any(HttpHeaders.class), any(Map.class), eq(false), eq(false))) .thenReturn(new ResponseEntity<>(jsonUtil.fromJsonFileToObject(Paths.get(fileUtil.getBaseClassDir(this.getClass()), testResponseNegotiationPath).toString(), Negotiation.class), HttpStatus.OK)); @@ -332,18 +322,17 @@ void initiateTransferAndSeeTransfer() { Negotiation negotiation = getNegotiation(); Status status = new Status(); status.setEndpoint("test.endpoint"); - + List callbackAddresses = List.of(CallbackAddress.builder().transactional(false).uri("http://test.endpoint/4546").events(List.of("transfer.process")).build()); TransferRequest transferRequest = new TransferRequest( jsonUtil.toJsonNode(Map.of("odrl", "http://www.w3.org/ns/odrl/2/")), dataSet.getAssetId(), status.getEndpoint(), - bpn, negotiation.getContractAgreementId(), null, false, - null, "dataspace-protocol-http", - null + env.getProperty("configuration.edc.transferType"), + callbackAddresses ); when(httpUtil.doPost(anyString(), any(Class.class), any(HttpHeaders.class), any(Map.class), any(Object.class), eq(false), eq(false))) @@ -352,8 +341,8 @@ void initiateTransferAndSeeTransfer() { IdResponse response = dataTransferService.initiateTransfer(transferRequest); assertNotNull(response); - assertEquals("9ab72e5b-f2d4-4f60-85e6-0985f9b6b579", response.getId()); - assertEquals("IdResponseDto", response.getType()); + assertEquals("73af176d-bc46-4cc2-80e2-423c0c6fb244", response.getId()); + assertEquals("IdResponse", response.getType()); when(httpUtil.doGet(anyString(), eq(NegotiationTransferResponse.class), any(HttpHeaders.class), any(Map.class), eq(false), eq(false))) .thenReturn(new ResponseEntity<>(jsonUtil.fromJsonFileToObject(Paths.get(fileUtil.getBaseClassDir(this.getClass()), testResponseTransferPath).toString(), Transfer.class), HttpStatus.OK)); @@ -364,7 +353,7 @@ void initiateTransferAndSeeTransfer() { Transfer transfer = dataTransferService.seeTransfer(response.getId()); assertEquals(response.getId(), transfer.getId()); - assertEquals("TransferProcessDto", transfer.getType()); - assertEquals("COMPLETED", transfer.getState()); + assertEquals("TransferProcess", transfer.getType()); + assertEquals("STARTED", transfer.getState()); } } \ No newline at end of file diff --git a/dpp-backend/digitalproductpass/src/test/java/utils/PolicyUtilTest.java b/dpp-backend/digitalproductpass/src/test/java/utils/PolicyUtilTest.java index 840a9c6f8..fff3992f9 100644 --- a/dpp-backend/digitalproductpass/src/test/java/utils/PolicyUtilTest.java +++ b/dpp-backend/digitalproductpass/src/test/java/utils/PolicyUtilTest.java @@ -28,6 +28,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import org.bouncycastle.est.ESTAuth; import org.eclipse.tractusx.digitalproductpass.config.DtrConfig; +import org.eclipse.tractusx.digitalproductpass.config.PassportConfig; import org.eclipse.tractusx.digitalproductpass.config.PolicyCheckConfig; import org.eclipse.tractusx.digitalproductpass.models.negotiation.policy.Set; import org.junit.jupiter.api.BeforeEach; @@ -48,6 +49,7 @@ import org.springframework.test.context.junit4.SpringRunner; import utils.exceptions.UtilException; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -59,12 +61,15 @@ */ @ActiveProfiles("test") @ExtendWith(SpringExtension.class) -@SpringBootTest(classes = {utils.JsonUtil.class, utils.PolicyUtil.class, utils.FileUtil.class, org.eclipse.tractusx.digitalproductpass.config.DtrConfig.class}) +@SpringBootTest(classes = {utils.JsonUtil.class, utils.PolicyUtil.class, utils.FileUtil.class, org.eclipse.tractusx.digitalproductpass.config.DtrConfig.class, org.eclipse.tractusx.digitalproductpass.config.PassportConfig.class}) @EnableConfigurationProperties class PolicyUtilTest { @Autowired DtrConfig dtrConfig; + @Autowired + PassportConfig passportConfig; + @Autowired JsonUtil jsonUtil; @Autowired @@ -83,18 +88,23 @@ class PolicyUtilTest { LinkedHashMap action; LinkedHashMap actionDtr; LinkedList> permissions; + + LinkedHashMap singlePermission; LinkedList> permissionsDtr; LinkedList> prohibitions; LinkedList> obligations; LinkedHashMap policy; + LinkedHashMap uniquePolicy; LinkedHashMap policyDtr; LinkedList> policies; LinkedList> policiesDtr; LinkedHashMap credential; + LinkedHashMap uniqueCredential; LinkedHashMap credentialDtr; LinkedHashMap multipleCredential; LinkedHashMap multipleCredentialDtr; PolicyCheckConfig policyCheckConfig; + PolicyCheckConfig policyCheckConfigPassport; Set mappedPolicy; Set mappedPolicyDtr; @@ -111,12 +121,15 @@ void setUp() { constraints = new LinkedList<>(); configuredConstraints = new LinkedList<>(); policy = new LinkedHashMap<>(); + uniquePolicy = new LinkedHashMap<>(); policyDtr = new LinkedHashMap<>(); credential = new LinkedHashMap<>(); + uniqueCredential = new LinkedHashMap<>(); credentialDtr = new LinkedHashMap<>(); action = new LinkedHashMap<>(); actionDtr = new LinkedHashMap<>(); permissions = new LinkedList<>(); + singlePermission = new LinkedHashMap<>(); permissionsDtr = new LinkedList<>(); prohibitions = new LinkedList<>(); obligations = new LinkedList<>(); @@ -132,9 +145,19 @@ void setUp() { constraint2.put("odrl:leftOperand", "cx-policy:FrameworkAgreement"); constraint2.put("odrl:operator", operator); constraint2.put("odrl:rightOperand", "circulareconomy:1.0"); + + LinkedHashMap constraint5 = new LinkedHashMap<>(); + LinkedList> correctContraints = new LinkedList<>(); + LinkedHashMap correctAction = new LinkedHashMap<>(); + LinkedHashMap correctLogicalConstraint = new LinkedHashMap<>(); + constraint5.put("odrl:leftOperand", "cx-policy:UsagePurpose"); + constraint5.put("odrl:operator", operator); + constraint5.put("odrl:rightOperand", "cx.circular.dpp:1"); constraints.add(constraint1); constraints.add(constraint2); - + correctContraints.add(constraint1); + correctContraints.add(constraint2); + correctContraints.add(constraint5); operator.put("@id", "odrl:eq"); constraint3.put("odrl:leftOperand", "cx-policy:Membership"); constraint3.put("odrl:operator", operator); @@ -148,13 +171,24 @@ void setUp() { logicalConstraintDtr.put("odrl:and", configuredConstraints); logicalConstraint.put("odrl:and", constraints); - action.put("odrl:action", "USE"); + correctLogicalConstraint.put("odrl:and", correctContraints); + + action.put("odrl:action", new LinkedHashMap<>(){{put("odrl:type","USE");}}); action.put("odrl:constraint", logicalConstraint); - actionDtr.put("odrl:action", "USE"); + correctAction.put("odrl:action", new LinkedHashMap<>(){{put("odrl:type","USE");}}); + correctAction.put("odrl:constraint", correctLogicalConstraint); + + actionDtr.put("odrl:action", new LinkedHashMap<>(){{put("odrl:type","USE");}}); actionDtr.put("odrl:constraint", logicalConstraintDtr); + singlePermission = correctAction; permissions.add(action); + uniquePolicy.put("odrl:permission", singlePermission); + uniquePolicy.put("odrl:prohibition", prohibitions); + uniquePolicy.put("odrl:obligation", obligations); + uniqueCredential.put("policy", uniquePolicy); + policy.put("odrl:permission", permissions); policy.put("odrl:prohibition", prohibitions); policy.put("odrl:obligation", obligations); @@ -185,6 +219,7 @@ void setUp() { if(this.dtrConfig == null){ throw new UtilException(PolicyUtilTest.class, "[TEST EXCEPTION]: Configuration not found!"); } + policyCheckConfigPassport = this.passportConfig.getPolicyCheck(); policyCheckConfig = this.dtrConfig.getPolicyCheck(); if(policyCheckConfig == null){ throw new UtilException(PolicyUtilTest.class, "[TEST EXCEPTION]: The policy configuration was not found!"); @@ -359,4 +394,36 @@ void getPolicyInvalidByConstraints() { } } + /** + * Parse unique policy instead of array + * **/ + @Test + void parseUniquePolicy(){ + try{ + LogUtil.printTest("[INPUT]: " + jsonUtil.toJson(uniquePolicy, true)); + LogUtil.printTest("[POLICY CONFIGURATION]: " + jsonUtil.toJson(policyCheckConfigPassport, true)); + Set validPolicy = this.policyUtil.getPolicyByConstraints(uniquePolicy, policyCheckConfigPassport); + LogUtil.printTest("[RESPONSE]: " + jsonUtil.toJson(validPolicy, true)); + assertNotNull(validPolicy); + }catch(Exception e){ + throw new UtilException(PolicyUtilTest.class, e,"It was not possible to test the default policy check!"); + } + } + + /** + * Parse unique policy instead of array + * **/ + @Test + void getUniquePolicies(){ + try{ + LogUtil.printTest("[INPUT]: " + jsonUtil.toJson(uniquePolicy, true)); + LogUtil.printTest("[POLICY CONFIGURATION]: " + jsonUtil.toJson(policyCheckConfigPassport, true)); + List validPolicies = this.policyUtil.getValidPoliciesByConstraints(uniquePolicy, policyCheckConfigPassport); + LogUtil.printTest("[RESPONSE]: " + jsonUtil.toJson(validPolicies, true)); + assertTrue(validPolicies.size() > 0); + }catch(Exception e){ + throw new UtilException(PolicyUtilTest.class, e,"It was not possible to test the default policy check!"); + } + } + } \ No newline at end of file diff --git a/dpp-backend/digitalproductpass/src/test/resources/application-test.yml b/dpp-backend/digitalproductpass/src/test/resources/application-test.yml index c70f7ec24..66cad8372 100644 --- a/dpp-backend/digitalproductpass/src/test/resources/application-test.yml +++ b/dpp-backend/digitalproductpass/src/test/resources/application-test.yml @@ -56,7 +56,7 @@ configuration: transfer: '/transferprocesses' receiverEndpoint: 'https://dpp.int.demo.catena-x.net/endpoint' delay: 100 # -- Negotiation status Delay in milliseconds in between async requests [<= 500] - transferType: "application/octet-stream" + transferType: "HttpData-PULL" timeout: exchange: 10 diff --git a/dpp-backend/digitalproductpass/src/test/resources/dpp/catalogs/TestContractOfferCatalog.json b/dpp-backend/digitalproductpass/src/test/resources/dpp/catalogs/TestContractOfferCatalog.json index 2e789f099..4d920b8ea 100644 --- a/dpp-backend/digitalproductpass/src/test/resources/dpp/catalogs/TestContractOfferCatalog.json +++ b/dpp-backend/digitalproductpass/src/test/resources/dpp/catalogs/TestContractOfferCatalog.json @@ -1,63 +1,75 @@ { - "@id": "c86305ef-e8ee-4163-913c-ce074dfa274f", + "@id": "2c156143-eb4b-496a-9dad-b7fc776ed865", "@type": "dcat:Catalog", + "dspace:participantId": "BPNL00000000000", "dcat:dataset": { - "@id": "urn:uuid:9992f962-6f69-875d-0ea4-fb4db3bb3b23", + "@id": "dpp-registry", "@type": "dcat:Dataset", "odrl:hasPolicy": { - "@id": "ZDkxMzRjNmQtNWUzNy03ZDc5LTRkOTEtZmM5MGIzZWVkMzMw:dXJuOnV1aWQ6OTk5MmY5NjItNmY2OS04NzVkLTBlYTQtZmI0ZGIzYmIzYjIz:YjZkMzFkNGYtNGYyNS00MWI1LWFkMzctNjJjY2U4NGI3NjA0", - "@type": "odrl:Set", - "odrl:permission": { - "odrl:target": "urn:uuid:9992f962-6f69-875d-0ea4-fb4db3bb3b23", - "odrl:action": { - "odrl:type": "USE" - }, - "odrl:constraint": { - "odrl:or": { - "odrl:leftOperand": "PURPOSE", - "odrl:operator": { - "@id": "odrl:eq" - }, - "odrl:rightOperand": "ID 3.0 Trace" - } - } - }, + "@id": "cmVnaXN0cnktY29udHJhY3QtZGVmaW5pdGlvbg==:ZHBwLXJlZ2lzdHJ5:N2FjZDM0OGItNzk3Ny00MGRhLWIyZTktMGQyY2Y4NzBkNjhi", + "@type": "odrl:Offer", + "odrl:permission": [], "odrl:prohibition": [], - "odrl:obligation": [], - "odrl:target": "urn:uuid:9992f962-6f69-875d-0ea4-fb4db3bb3b23" + "odrl:obligation": [] }, "dcat:distribution": [ { "@type": "dcat:Distribution", "dct:format": { - "@id": "HttpProxy" + "@id": "AzureStorage-PUSH" }, - "dcat:accessService": "e2a066b3-5a16-45dc-8552-8d96ac787e02" + "dcat:accessService": { + "@id": "efecedfa-43bb-4b73-8728-aea6e246dda0", + "@type": "dcat:DataService", + "dct:terms": "connector", + "dct:endpointUrl": "https://test.com/api/v1/dsp" + } }, { "@type": "dcat:Distribution", "dct:format": { - "@id": "AmazonS3" + "@id": "HttpData-PULL" }, - "dcat:accessService": "e2a066b3-5a16-45dc-8552-8d96ac787e02" + "dcat:accessService": { + "@id": "efecedfa-43bb-4b73-8728-aea6e246dda0", + "@type": "dcat:DataService", + "dct:terms": "connector", + "dct:endpointUrl": "https://test.com/api/v1/dsp" + } + }, + { + "@type": "dcat:Distribution", + "dct:format": { + "@id": "AmazonS3-PUSH" + }, + "dcat:accessService": { + "@id": "efecedfa-43bb-4b73-8728-aea6e246dda0", + "@type": "dcat:DataService", + "dct:terms": "connector", + "dct:endpointUrl": "https://test.com/api/v1/dsp" + } } ], "description": "batterypass test data", - "id": "urn:uuid:9992f962-6f69-875d-0ea4-fb4db3bb3b23" + "version": "3.0", + "id": "dpp-asset" }, "dcat:service": { - "@id": "e2a066b3-5a16-45dc-8552-8d96ac787e02", + "@id": "efecedfa-43bb-4b73-8728-aea6e246dda0", "@type": "dcat:DataService", "dct:terms": "connector", - "dct:endpointUrl": "https://materialpass.int.demo.catena-x.net/BPNL000000000000/api/v1/dsp" + "dct:endpointUrl": "https://test.com/api/v1/dsp" }, "participantId": "BPNL00000000000", "@context": { - "dct": "https://purl.org/dc/terms/", - "tx": "https://w3id.org/tractusx/v0.0.1/ns/", + "@vocab": "https://w3id.org/edc/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", - "dcat": "https://www.w3.org/ns/dcat/", + "tx": "https://w3id.org/tractusx/v0.0.1/ns/", + "tx-auth": "https://w3id.org/tractusx/auth/", + "cx-policy": "https://w3id.org/catenax/policy/", + "dcat": "http://www.w3.org/ns/dcat#", + "dct": "http://purl.org/dc/terms/", "odrl": "http://www.w3.org/ns/odrl/2/", "dspace": "https://w3id.org/dspace/v0.8/" } -} +} \ No newline at end of file diff --git a/dpp-backend/digitalproductpass/src/test/resources/dpp/catalogs/TestDigitalTwinCatalog.json b/dpp-backend/digitalproductpass/src/test/resources/dpp/catalogs/TestDigitalTwinCatalog.json index 35ddc1302..970d1d45e 100644 --- a/dpp-backend/digitalproductpass/src/test/resources/dpp/catalogs/TestDigitalTwinCatalog.json +++ b/dpp-backend/digitalproductpass/src/test/resources/dpp/catalogs/TestDigitalTwinCatalog.json @@ -1,51 +1,78 @@ { - "@id": "bb824702-08dc-4315-9ff1-6373330a0cd9", + "@id": "2c156143-eb4b-496a-9dad-b7fc776ed865", "@type": "dcat:Catalog", + "dspace:participantId": "BPNL00000000000", "dcat:dataset": { - "@id": "registry-asset", + "@id": "dpp-registry", "@type": "dcat:Dataset", "odrl:hasPolicy": { - "@id": "ZGVmYXVsdC1jb250cmFjdC1kZWZpbml0aW9u:cmVnaXN0cnktYXNzZXQ=:MTIxMjYzMzgtYzhkMC00MGQ4LTkxYWMtZmY2ZTY0ZTQ5ZmM0", - "@type": "odrl:Set", + "@id": "cmVnaXN0cnktY29udHJhY3QtZGVmaW5pdGlvbg==:ZHBwLXJlZ2lzdHJ5:N2FjZDM0OGItNzk3Ny00MGRhLWIyZTktMGQyY2Y4NzBkNjhi", + "@type": "odrl:Offer", "odrl:permission": [], "odrl:prohibition": [], - "odrl:obligation": [], - "odrl:target": "registry-asset" + "odrl:obligation": [] }, "dcat:distribution": [ { "@type": "dcat:Distribution", "dct:format": { - "@id": "HttpProxy" + "@id": "AzureStorage-PUSH" }, - "dcat:accessService": "bc491229-1b41-49a9-9101-a430a4907e6e" + "dcat:accessService": { + "@id": "efecedfa-43bb-4b73-8728-aea6e246dda0", + "@type": "dcat:DataService", + "dct:terms": "connector", + "dct:endpointUrl": "https://test.com/api/v1/dsp" + } }, { "@type": "dcat:Distribution", "dct:format": { - "@id": "AmazonS3" + "@id": "HttpData-PULL" }, - "dcat:accessService": "bc491229-1b41-49a9-9101-a430a4907e6e" + "dcat:accessService": { + "@id": "efecedfa-43bb-4b73-8728-aea6e246dda0", + "@type": "dcat:DataService", + "dct:terms": "connector", + "dct:endpointUrl": "https://test.com/api/v1/dsp" + } + }, + { + "@type": "dcat:Distribution", + "dct:format": { + "@id": "AmazonS3-PUSH" + }, + "dcat:accessService": { + "@id": "efecedfa-43bb-4b73-8728-aea6e246dda0", + "@type": "dcat:DataService", + "dct:terms": "connector", + "dct:endpointUrl": "https://test.com/api/v1/dsp" + } } ], - "type": "data.core.digitalTwinRegistry", - "description": "Digital Twin Registry for DPP", - "id": "registry-asset", - "contenttype": "application/json" + "version": "3.0", + "type": { + "@id": "DigitalTwinRegistry" + }, + "asset:prop:type": "data.core.digitalTwinRegistry", + "id": "dpp-registry" }, "dcat:service": { - "@id": "bc491229-1b41-49a9-9101-a430a4907e6e", + "@id": "efecedfa-43bb-4b73-8728-aea6e246dda0", "@type": "dcat:DataService", "dct:terms": "connector", - "dct:endpointUrl": "https://materialpass.int.demo.catena-x.net/BPNL000000000000/api/v1/dsp" + "dct:endpointUrl": "https://test.com/api/v1/dsp" }, "participantId": "BPNL00000000000", "@context": { - "dct": "https://purl.org/dc/terms/", - "tx": "https://w3id.org/tractusx/v0.0.1/ns/", + "@vocab": "https://w3id.org/edc/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", - "dcat": "https://www.w3.org/ns/dcat/", + "tx": "https://w3id.org/tractusx/v0.0.1/ns/", + "tx-auth": "https://w3id.org/tractusx/auth/", + "cx-policy": "https://w3id.org/catenax/policy/", + "dcat": "http://www.w3.org/ns/dcat#", + "dct": "http://purl.org/dc/terms/", "odrl": "http://www.w3.org/ns/odrl/2/", "dspace": "https://w3id.org/dspace/v0.8/" } -} +} \ No newline at end of file diff --git a/dpp-backend/digitalproductpass/src/test/resources/dpp/contractpolicies/TestPolicy.json b/dpp-backend/digitalproductpass/src/test/resources/dpp/contractpolicies/TestPolicy.json index 460c4f79a..6a4a36042 100644 --- a/dpp-backend/digitalproductpass/src/test/resources/dpp/contractpolicies/TestPolicy.json +++ b/dpp-backend/digitalproductpass/src/test/resources/dpp/contractpolicies/TestPolicy.json @@ -1,8 +1,7 @@ { - "@id": "ZGVmYXVsdC1jb250cmFjdC1kZWZpbml0aW9u:cmVnaXN0cnktYXNzZXQ=:MTIxMjYzMzgtYzhkMC00MGQ4LTkxYWMtZmY2ZTY0ZTQ5ZmM0", - "@type": "odrl:Set", - "odrl:permission" : [], + "@id": "cmVnaXN0cnktY29udHJhY3QtZGVmaW5pdGlvbg==:ZHBwLXJlZ2lzdHJ5:N2FjZDM0OGItNzk3Ny00MGRhLWIyZTktMGQyY2Y4NzBkNjhi", + "@type": "odrl:Offer", + "odrl:permission": [], "odrl:prohibition": [], - "odrl:obligation": [], - "odrl:target": "registry-asset" + "odrl:obligation": [] } diff --git a/dpp-backend/digitalproductpass/src/test/resources/dpp/negotiation/TestResponseInitNegotiation.json b/dpp-backend/digitalproductpass/src/test/resources/dpp/negotiation/TestResponseInitNegotiation.json index 59e633ed5..3bbc9ab77 100644 --- a/dpp-backend/digitalproductpass/src/test/resources/dpp/negotiation/TestResponseInitNegotiation.json +++ b/dpp-backend/digitalproductpass/src/test/resources/dpp/negotiation/TestResponseInitNegotiation.json @@ -1,5 +1,5 @@ { - "@type" : "IdResponseDto", + "@type" : "IdResponse", "@id" : "189f4957-0fbe-4d73-b215-977e3303a45e", "createdAt" : 1699439557127, "@context" : { diff --git a/dpp-backend/digitalproductpass/src/test/resources/dpp/negotiation/TestResponseNegotiation.json b/dpp-backend/digitalproductpass/src/test/resources/dpp/negotiation/TestResponseNegotiation.json index 160280758..f702ca3df 100644 --- a/dpp-backend/digitalproductpass/src/test/resources/dpp/negotiation/TestResponseNegotiation.json +++ b/dpp-backend/digitalproductpass/src/test/resources/dpp/negotiation/TestResponseNegotiation.json @@ -1,18 +1,20 @@ { - "@type": "ContractNegotiationDto", + "@type": "ContractNegotiation", "@id": "189f4957-0fbe-4d73-b215-977e3303a45e", "type": "CONSUMER", "protocol": "dataspace-protocol-http", "state": "FINALIZED", - "counterPartyAddress": "https://materialpass.int.demo.catena-x.net/BPNL000000000000/api/v1/dsp", + "counterPartyId": "BPNL00000000000", + "counterPartyAddress": "https://test.com/api/v1/dsp", "callbackAddresses": [], - "contractAgreementId": "ZGVmYXVsdC1jb250cmFjdC1kZWZpbml0aW9u:cmVnaXN0cnktYXNzZXQ=:NmRjMDFlOTQtMGE0MC00MTQzLThhOTYtY2IyMmYxN2JjZGJj", + "createdAt": 1715192601315, + "contractAgreementId": "1ce31703-bca2-4cd0-809c-b716fba61c03", "@context": { - "dct": "https://purl.org/dc/terms/", - "tx": "https://w3id.org/tractusx/v0.0.1/ns/", + "@vocab": "https://w3id.org/edc/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", - "dcat": "https://www.w3.org/ns/dcat/", - "odrl": "http://www.w3.org/ns/odrl/2/", - "dspace": "https://w3id.org/dspace/v0.8/" + "tx": "https://w3id.org/tractusx/v0.0.1/ns/", + "tx-auth": "https://w3id.org/tractusx/auth/", + "cx-policy": "https://w3id.org/catenax/policy/", + "odrl": "http://www.w3.org/ns/odrl/2/" } -} +} \ No newline at end of file diff --git a/dpp-backend/digitalproductpass/src/test/resources/dpp/transfer/TestResponseInitTransfer.json b/dpp-backend/digitalproductpass/src/test/resources/dpp/transfer/TestResponseInitTransfer.json index d2ff5e87a..6a646718a 100644 --- a/dpp-backend/digitalproductpass/src/test/resources/dpp/transfer/TestResponseInitTransfer.json +++ b/dpp-backend/digitalproductpass/src/test/resources/dpp/transfer/TestResponseInitTransfer.json @@ -1,6 +1,6 @@ { - "@type": "IdResponseDto", - "@id": "9ab72e5b-f2d4-4f60-85e6-0985f9b6b579", + "@type": "IdResponse", + "@id": "73af176d-bc46-4cc2-80e2-423c0c6fb244", "createdAt": 1699439575484, "@context": { "dct": "https://purl.org/dc/terms/", diff --git a/dpp-backend/digitalproductpass/src/test/resources/dpp/transfer/TestResponseTransfer.json b/dpp-backend/digitalproductpass/src/test/resources/dpp/transfer/TestResponseTransfer.json index 76385f5ab..c33f2d487 100644 --- a/dpp-backend/digitalproductpass/src/test/resources/dpp/transfer/TestResponseTransfer.json +++ b/dpp-backend/digitalproductpass/src/test/resources/dpp/transfer/TestResponseTransfer.json @@ -1,27 +1,29 @@ { - "@id": "9ab72e5b-f2d4-4f60-85e6-0985f9b6b579", - "@type": "TransferProcessDto", - "state": "COMPLETED", - "stateTimestamp": 1699439577253, + "@id": "73af176d-bc46-4cc2-80e2-423c0c6fb244", + "@type": "TransferProcess", + "state": "STARTED", + "stateTimestamp": 1715192724130, "type": "CONSUMER", - "callbackAddresses": [], + "callbackAddresses": { + "@type": "CallbackAddress", + "transactional": false, + "uri": "https://callback.address.com/endpoint", + "events": "transfer.process" + }, + "correlationId": "caa51b56-b4db-4f36-b95d-8de56d1cbe7e", + "assetId": "dpp-asset", + "contractId": "1ce31703-bca2-4cd0-809c-b716fba61c03", + "transferType": "HttpData-PULL", "dataDestination": { + "@type": "DataAddress", "type": "HttpProxy" }, - "dataRequest": { - "@type": "DataRequestDto", - "@id": "9ab72e5b-f2d4-4f60-85e6-0985f9b6b579", - "assetId": "365e6fbe-bb34-11ec-8422-0242ac120002-61125dc3-5e6f-4f4b-838d-447432b97918", - "contractId": "ZGVmYXVsdC1jb250cmFjdC1kZWZpbml0aW9u:cmVnaXN0cnktYXNzZXQ=:NmRjMDFlOTQtMGE0MC00MTQzLThhOTYtY2IyMmYxN2JjZGJj", - "connectorId": "BPNL00000000CBA5" - }, - "receiverHttpEndpoint": "https://testUrl.com/BPNL000000000000/endpoint/ebc08cdc-fc22-41e8-9394-81142de0b35a/365e6fbe-bb34-11ec-8422-0242ac120002-61125dc3-5e6f-4f4b-838d-447432b97918", "@context": { - "dct": "https://purl.org/dc/terms/", - "tx": "https://w3id.org/tractusx/v0.0.1/ns/", + "@vocab": "https://w3id.org/edc/v0.0.1/ns/", "edc": "https://w3id.org/edc/v0.0.1/ns/", - "dcat": "https://www.w3.org/ns/dcat/", - "odrl": "http://www.w3.org/ns/odrl/2/", - "dspace": "https://w3id.org/dspace/v0.8/" + "tx": "https://w3id.org/tractusx/v0.0.1/ns/", + "tx-auth": "https://w3id.org/tractusx/auth/", + "cx-policy": "https://w3id.org/catenax/policy/", + "odrl": "http://www.w3.org/ns/odrl/2/" } -} +} \ No newline at end of file diff --git a/dpp-frontend/package-lock.json b/dpp-frontend/package-lock.json index fb1ba1026..e0e5c78da 100644 --- a/dpp-frontend/package-lock.json +++ b/dpp-frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "digital-product-pass-frontend", - "version": "2.3.0", + "version": "3.0.0-rc1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "digital-product-pass-frontend", - "version": "2.3.0", + "version": "3.0.0-rc1", "dependencies": { "@mdi/font": "5.9.55", "@popperjs/core": "^2.11.2", diff --git a/dpp-frontend/package.json b/dpp-frontend/package.json index b4875803e..fbba6f587 100644 --- a/dpp-frontend/package.json +++ b/dpp-frontend/package.json @@ -1,6 +1,6 @@ { "name": "digital-product-pass-frontend", - "version": "2.3.0", + "version": "3.0.0-rc1", "private": true, "scripts": { "serve": "vite --host localhost", diff --git a/dpp-frontend/src/components/general/ErrorComponent.vue b/dpp-frontend/src/components/general/ErrorComponent.vue index 7988dd4b5..d289fc3bd 100644 --- a/dpp-frontend/src/components/general/ErrorComponent.vue +++ b/dpp-frontend/src/components/general/ErrorComponent.vue @@ -51,8 +51,8 @@ - + > +