From 891ca3cc9b6a25ab90f804c1b46375eeba75e638 Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Tue, 17 Oct 2023 13:05:39 +0530 Subject: [PATCH 01/23] DT use refactor and PCF issue fix --- DEPENDENCIES | 2 +- .../create/steps/impl/RecordProcessUtils.java | 18 +- .../processreport/ProcessReportUseCase.java | 2 +- .../model/ProcessReportPageResponse.java | 2 +- .../ConsumerControlPanelServiceTest.java | 4 + .../facilitator/DigitalTwinsFacilitator.java | 79 +++---- .../facilitator/DigitalTwinsUtility.java | 8 +- .../external/DigitalTwinsFeignClient.java | 35 ++- .../EDCDigitalTwinProxyForLookUp.java | 46 ++++ .../sde/edc/api/ContractOfferCatalogApi.java | 2 +- .../sde/edc/api/EDCFeignClientApi.java | 2 +- .../tractusx/sde/edc/api/EDRApiProxy.java | 59 +++++ .../asset/AssetEntryRequestFactory.java | 2 +- .../facilitator/AbstractEDCStepsHelper.java | 16 +- .../sde/edc/facilitator/EDRRequestHelper.java | 76 +++++++ .../edc/model/edr/EDRCachedByIdResponse.java | 56 +++++ .../sde/edc/model/edr/EDRCachedResponse.java | 65 ++++++ .../services/ConsumerControlPanelService.java | 138 +++++++++++- .../apr/model/AspectRelationship.java | 2 +- .../apr/steps/DDTRUrlCacheUtility.java | 55 ++++- ...nsAspectRelationShipCsvHandlerUseCase.java | 114 +++++++--- .../submodels/pap/model/PartAsPlanned.java | 2 +- .../model/PartSiteInformationAsPlanned.java | 2 +- .../sde/submodels/pcf/mapper/PcfMapper.java | 16 +- .../sde/submodels/pcf/model/PcfAspect.java | 2 +- .../pcf/model/PcfSubmodelResponse.java | 10 +- .../model/ProductOrSectorSpecificRules.java | 4 +- .../pcf/src/main/resources/pcf.json | 209 +++++++++++------- .../sluab/model/SingleLevelUsageAsBuilt.java | 2 +- 29 files changed, 795 insertions(+), 235 deletions(-) create mode 100644 modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/EDCDigitalTwinProxyForLookUp.java create mode 100644 modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/api/EDRApiProxy.java create mode 100644 modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/EDRRequestHelper.java create mode 100644 modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/model/edr/EDRCachedByIdResponse.java create mode 100644 modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/model/edr/EDRCachedResponse.java diff --git a/DEPENDENCIES b/DEPENDENCIES index 78cbe77f2..8e8b927b9 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -39,7 +39,7 @@ maven/mavencentral/jakarta.annotation/jakarta.annotation-api/2.1.1, EPL-2.0 OR G maven/mavencentral/jakarta.inject/jakarta.inject-api/2.0.1, Apache-2.0, approved, clearlydefined maven/mavencentral/jakarta.persistence/jakarta.persistence-api/3.1.0, EPL-2.0 OR BSD-3-Clause AND (EPL-2.0 OR BSD-3-Clause AND BSD-3-Clause), approved, #7696 maven/mavencentral/jakarta.transaction/jakarta.transaction-api/2.0.1, EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, #7697 -maven/mavencentral/jakarta.validation/jakarta.validation-api/3.0.2, Apache-2.0, approved, clearlydefined +maven/mavencentral/jakarta.validation/jakarta.validation-api/3.0.2, Apache-2.0, approved, ee4j.validation maven/mavencentral/jakarta.xml.bind/jakarta.xml.bind-api/4.0.0, BSD-3-Clause, approved, ee4j.jaxb maven/mavencentral/net.bytebuddy/byte-buddy-agent/1.14.4, Apache-2.0, approved, #7164 maven/mavencentral/net.bytebuddy/byte-buddy/1.14.4, Apache-2.0 AND BSD-3-Clause, approved, #7163 diff --git a/modules/sde-common/src/main/java/org/eclipse/tractusx/sde/common/submodel/executor/create/steps/impl/RecordProcessUtils.java b/modules/sde-common/src/main/java/org/eclipse/tractusx/sde/common/submodel/executor/create/steps/impl/RecordProcessUtils.java index 83c58185a..db379c59b 100644 --- a/modules/sde-common/src/main/java/org/eclipse/tractusx/sde/common/submodel/executor/create/steps/impl/RecordProcessUtils.java +++ b/modules/sde-common/src/main/java/org/eclipse/tractusx/sde/common/submodel/executor/create/steps/impl/RecordProcessUtils.java @@ -38,9 +38,13 @@ public void setFieldValue(ObjectNode rowjObject, String ele, JsonObject jObject, fieldValue = fieldValue.trim(); - if (isNumberTypeField(jObject, fieldValue)) - rowjObject.put(ele, Double.parseDouble(fieldValue)); - else if (isDateFormatField(jObject)) { + if (isNumberTypeField(jObject)) { + if (fieldValue.isBlank()) { + rowjObject.putNull(ele); + } else { + rowjObject.put(ele, Double.parseDouble(fieldValue)); + } + } else if (isDateFormatField(jObject)) { if (fieldValue.isBlank()) fieldValue = null; @@ -57,12 +61,10 @@ private boolean isDateFormatField(JsonObject jObject) { return jObject.get("format") != null && "date-time".equals(jObject.get("format").getAsString()); } - private boolean isNumberTypeField(JsonObject jObject, String fieldValue) { - - if (fieldValue != null && !fieldValue.isBlank() && jObject.get("type") != null - && jObject.get("type").isJsonArray()) { + private boolean isNumberTypeField(JsonObject jObject) { + JsonElement jsonElement = JsonParser.parseString("number"); + if (jObject.get("type") != null && jObject.get("type").isJsonArray()) { JsonArray types = jObject.get("type").getAsJsonArray(); - JsonElement jsonElement = JsonParser.parseString("number"); return types.contains(jsonElement); } return false; diff --git a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/processreport/ProcessReportUseCase.java b/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/processreport/ProcessReportUseCase.java index c82f6ffb5..07ac506b4 100644 --- a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/processreport/ProcessReportUseCase.java +++ b/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/processreport/ProcessReportUseCase.java @@ -103,7 +103,7 @@ public ProcessReportPageResponse listAllProcessReports(int page, int size) { .findAll(PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "startDate"))); List processReports = result.get().map(mapper::mapFrom).toList(); return ProcessReportPageResponse.builder().items(processReports).pageSize(result.getSize()) - .pageNumber(result.getNumber()).totalItems(result.getTotalElements()).build(); + .page(result.getNumber()).totalItems(result.getTotalElements()).build(); } public ProcessReport getProcessReportById(String id) { diff --git a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/processreport/model/ProcessReportPageResponse.java b/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/processreport/model/ProcessReportPageResponse.java index 463f3b67d..6e6b1ee1f 100644 --- a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/processreport/model/ProcessReportPageResponse.java +++ b/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/processreport/model/ProcessReportPageResponse.java @@ -35,7 +35,7 @@ @NoArgsConstructor public class ProcessReportPageResponse { - private int pageNumber; + private int page; private int pageSize; private long totalItems; private List items; diff --git a/modules/sde-core/src/test/java/org/eclipse/tractusx/sde/service/ConsumerControlPanelServiceTest.java b/modules/sde-core/src/test/java/org/eclipse/tractusx/sde/service/ConsumerControlPanelServiceTest.java index 6e45a1863..5f1fc53e0 100644 --- a/modules/sde-core/src/test/java/org/eclipse/tractusx/sde/service/ConsumerControlPanelServiceTest.java +++ b/modules/sde-core/src/test/java/org/eclipse/tractusx/sde/service/ConsumerControlPanelServiceTest.java @@ -40,6 +40,7 @@ import org.eclipse.tractusx.sde.edc.entities.request.policies.Operator; import org.eclipse.tractusx.sde.edc.entities.request.policies.PolicyConstraintBuilderService; import org.eclipse.tractusx.sde.edc.facilitator.ContractNegotiateManagementHelper; +import org.eclipse.tractusx.sde.edc.facilitator.EDRRequestHelper; import org.eclipse.tractusx.sde.edc.gateways.database.ContractNegotiationInfoRepository; import org.eclipse.tractusx.sde.edc.model.contractoffers.ContractOfferRequestFactory; import org.eclipse.tractusx.sde.edc.model.request.ConsumerRequest; @@ -89,6 +90,9 @@ class ConsumerControlPanelServiceTest { @MockBean private ContractOfferRequestFactory contractOfferRequestFactory; + + @MockBean + private EDRRequestHelper eDRRequestHelper; @Test void testQueryOnDataOfferEmpty() throws Exception { diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsFacilitator.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsFacilitator.java index c8594e00e..3166fbf65 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsFacilitator.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsFacilitator.java @@ -20,12 +20,10 @@ package org.eclipse.tractusx.sde.digitaltwins.facilitator; -import java.net.URI; import java.util.ArrayList; import java.util.Base64; import java.util.List; -import org.apache.commons.lang3.StringUtils; import org.eclipse.tractusx.sde.common.exception.ServiceException; import org.eclipse.tractusx.sde.digitaltwins.entities.request.CreateSubModelRequest; import org.eclipse.tractusx.sde.digitaltwins.entities.request.ShellDescriptorRequest; @@ -39,6 +37,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; +import feign.FeignException; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -50,38 +49,30 @@ public class DigitalTwinsFacilitator { private final DigitalTwinsFeignClient digitalTwinsFeignClient; - @Value(value = "${digital-twins.hostname:default}") - private String digitalTwinsHost; - - @Value(value = "${digital-twins.api:/api/v3.0}") - private String dtApiUri; - @Value(value = "${manufacturerId}") public String manufacturerId; - public List shellLookup(ShellLookupRequest request) throws ServiceException { - return shellLookupFromDDTR(request, null, manufacturerId); - } - @SneakyThrows - public List shellLookupFromDDTR(ShellLookupRequest request, String ddtrUrl, String edcBpn) - throws ServiceException { - - URI dtURL = StringUtils.isAllEmpty(ddtrUrl) ? getDtURL(digitalTwinsHost) : getDtURL(ddtrUrl); + public List shellLookup(ShellLookupRequest request) throws ServiceException { List shellIds = List.of(); - try { - ResponseEntity response = digitalTwinsFeignClient.shellLookup(dtURL, - request.toJsonString(), edcBpn); + ResponseEntity response = digitalTwinsFeignClient.shellLookup(request.toJsonString(), + manufacturerId); ShellLookupResponse body = response.getBody(); if (response.getStatusCode() == HttpStatus.OK && body != null) { shellIds = body.getResult(); } + } catch (FeignException e) { + log.error("FeignException RequestBody : " + e.request()); + String errorMsg = "Error in DT twin lookup " + e.request().url() + ", because: " + request.toJsonString() + + "," + e.contentUTF8(); + log.error("FeignException : " + errorMsg); + throw new ServiceException(errorMsg); } catch (Exception e) { - String error = "Error in lookup DT lookup:" + dtURL + ", " + request.toJsonString() + ", " + e.getMessage(); + String error = "Error in DT twin lookup " + request.toJsonString() + ", " + e.getMessage(); log.error(error); throw new ServiceException(error); } @@ -92,14 +83,18 @@ public List shellLookupFromDDTR(ShellLookupRequest request, String ddtrU public String deleteShell(String shellId) { String deleteResponse = ""; try { - ResponseEntity response = digitalTwinsFeignClient.deleteShell(getDtURL(digitalTwinsHost), - encodeShellIdBase64Utf8(shellId)); + ResponseEntity response = digitalTwinsFeignClient.deleteShell(encodeShellIdBase64Utf8(shellId)); if (response.getStatusCode() == HttpStatus.NO_CONTENT) { deleteResponse = "Asset identifier" + shellId + "deleted successfully"; } + } catch (FeignException e) { + log.error("FeignException RequestBody : " + e.request()); + String errorMsg = "Error in deleteShell " + e.request().url() + ", because: " + e.contentUTF8(); + log.error("FeignException : " + errorMsg); + throw new ServiceException(errorMsg); } catch (Exception e) { - String error = "Error in deleteShell :" + digitalTwinsHost + ", " + shellId + "," + e.getMessage(); + String error = "Error in deleteShell : " + shellId + "," + e.getMessage(); log.error(error); throw new ServiceException(error); } @@ -107,29 +102,27 @@ public String deleteShell(String shellId) { } @SneakyThrows - public List getShellDescriptorsWithSubmodelDetails(List shellIds, String ddtrUrl) { + public List getShellDescriptorsWithSubmodelDetails(List shellIds) { List items = new ArrayList<>(); for (String shellId : shellIds) { - items.add(getShellDetailsById(shellId, ddtrUrl, manufacturerId)); + items.add(getShellDetailsById(shellId)); } return items; } - public ShellDescriptorResponse getShellDetailsById(String shellId, String ddtrUrl, String edcBpn) { - - URI dtURL = StringUtils.isAllEmpty(ddtrUrl) ? getDtURL(digitalTwinsHost) : getDtURL(ddtrUrl); + public ShellDescriptorResponse getShellDetailsById(String shellId) { ResponseEntity shellDescriptorResponse = digitalTwinsFeignClient - .getShellDescriptorByShellId(dtURL, encodeShellIdBase64Utf8(shellId), edcBpn); + .getShellDescriptorByShellId(encodeShellIdBase64Utf8(shellId), manufacturerId); return shellDescriptorResponse.getBody(); } @SneakyThrows public void deleteSubmodelfromShellById(String shellId, String subModelId) { try { - digitalTwinsFeignClient.deleteSubmodelfromShellById(getDtURL(digitalTwinsHost), - encodeShellIdBase64Utf8(shellId), encodeShellIdBase64Utf8(subModelId)); + digitalTwinsFeignClient.deleteSubmodelfromShellById(encodeShellIdBase64Utf8(shellId), + encodeShellIdBase64Utf8(subModelId)); } catch (Exception e) { parseExceptionMessage(e); } @@ -138,7 +131,7 @@ public void deleteSubmodelfromShellById(String shellId, String subModelId) { public ShellDescriptorResponse createShellDescriptor(ShellDescriptorRequest request) { ShellDescriptorResponse responseBody; ResponseEntity registerSubmodel = digitalTwinsFeignClient - .createShellDescriptor(getDtURL(digitalTwinsHost), request); + .createShellDescriptor(request); if (registerSubmodel.getStatusCode() != HttpStatus.CREATED) { responseBody = null; } else { @@ -149,11 +142,10 @@ public ShellDescriptorResponse createShellDescriptor(ShellDescriptorRequest requ public void updateShellSpecificAssetIdentifiers(String shellId, List specificAssetIds) { - digitalTwinsFeignClient.deleteShellSpecificAttributes(getDtURL(digitalTwinsHost), - encodeShellIdBase64Utf8(shellId), manufacturerId); + digitalTwinsFeignClient.deleteShellSpecificAttributes(encodeShellIdBase64Utf8(shellId), manufacturerId); - ResponseEntity> registerSubmodel = digitalTwinsFeignClient.createShellSpecificAttributes( - getDtURL(digitalTwinsHost), encodeShellIdBase64Utf8(shellId), manufacturerId, specificAssetIds); + ResponseEntity> registerSubmodel = digitalTwinsFeignClient + .createShellSpecificAttributes(encodeShellIdBase64Utf8(shellId), manufacturerId, specificAssetIds); if (registerSubmodel.getStatusCode() != HttpStatus.CREATED) { log.error("Error in shell SpecificAssetIdentifiers deletion: " + registerSubmodel.toString()); } @@ -163,8 +155,8 @@ public void createSubModel(String shellId, CreateSubModelRequest request) { request.setDescription(List.of()); - ResponseEntity response = digitalTwinsFeignClient.createSubModel(getDtURL(digitalTwinsHost), - encodeShellIdBase64Utf8(shellId), request); + ResponseEntity response = digitalTwinsFeignClient.createSubModel(encodeShellIdBase64Utf8(shellId), + request); if (response.getStatusCode() != HttpStatus.CREATED) { log.error("Unable to create submodel descriptor"); } @@ -173,8 +165,8 @@ public void createSubModel(String shellId, CreateSubModelRequest request) { public SubModelListResponse getSubModels(String shellId) { - ResponseEntity response = digitalTwinsFeignClient.getSubModels(getDtURL(digitalTwinsHost), - encodeShellIdBase64Utf8(shellId)); + ResponseEntity response = digitalTwinsFeignClient + .getSubModels(encodeShellIdBase64Utf8(shellId)); SubModelListResponse responseBody = null; if (response.getStatusCode() == HttpStatus.OK) { responseBody = response.getBody(); @@ -192,9 +184,4 @@ public void parseExceptionMessage(Exception e) throws ServiceException { throw new ServiceException("Exception in Digital delete request process: " + e.getMessage()); } } - - @SneakyThrows - private URI getDtURL(String dtURL) { - return new URI(dtURL.concat(dtApiUri)); - } -} +} \ No newline at end of file diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java index d2cb2f7fb..5786d7d1d 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java @@ -116,7 +116,7 @@ public List prepareDtEndpoint(String shellId, String submodelIdentific .endpointProtocol(CommonConstants.HTTP) .endpointProtocolVersion(List.of(CommonConstants.ENDPOINT_PROTOCOL_VERSION)) .subProtocol(CommonConstants.SUB_PROTOCOL) - .subprotocolBody(encodedUrl("id=" + shellId + "-" + submodelIdentification) + ";dspEndpoint=" + .subprotocolBody("id=" + shellId + "-" + submodelIdentification + ";dspEndpoint=" + edcEndpoint) .subprotocolBodyEncoding(CommonConstants.BODY_ENCODING) .securityAttributes(List.of(new SecurityAttributes("NONE", "NONE", "NONE"))).build()) @@ -144,7 +144,7 @@ public List getSpecificAssetIds(Map specificAssetIds, Li specificIdentifiers.add(new KeyValuePair(entry.getKey(), entry.getValue(), externalSubjectId)); } else { - if (keyList != null && !keyList.isEmpty()) { + if (keyList != null && !keyList.isEmpty() && !entry.getValue().isEmpty()) { externalSubjectId = ExternalSubjectId.builder() .type("ExternalReference").keys(keyList) @@ -172,10 +172,6 @@ private List bpnKeyRefrence(List bpns) { return Collections.emptyList(); } - private String encodedUrl(String format) { - return format.replace(":", "%3A"); - } - private String getFieldFromJsonNode(JsonNode jnode, String fieldName) { if (jnode.get(fieldName) != null) return jnode.get(fieldName).asText(); diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java index d7dbfadfb..6191ad95e 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/DigitalTwinsFeignClient.java @@ -40,46 +40,43 @@ import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; -@FeignClient(value = "DigitalTwinsFeignClient", url = "placeholder", configuration = DigitalTwinsFeignClientConfiguration.class) +@FeignClient(value = "DigitalTwinsFeignClient", url = "${digital-twins.hostname:default}${digital-twins.api:/api/v3.0}", configuration = DigitalTwinsFeignClientConfiguration.class) public interface DigitalTwinsFeignClient { @PostMapping KeycloakJWTTokenResponse readAuthToken(URI url, @RequestBody MultiValueMap body); @PostMapping(path = "/shell-descriptors") - ResponseEntity createShellDescriptor(URI url, @RequestBody ShellDescriptorRequest request); + ResponseEntity createShellDescriptor(@RequestBody ShellDescriptorRequest request); - @GetMapping(path = "/shell-descriptors/{aasIdentifier}") - ResponseEntity getShellDescriptorByShellId(URI url, - @PathVariable("aasIdentifier") String shellId, @RequestHeader("Edc-Bpn") String edcBpn); - + ResponseEntity getShellDescriptorByShellId(@PathVariable("aasIdentifier") String shellId, + @RequestHeader("Edc-Bpn") String edcBpn); + @DeleteMapping(path = "/shell-descriptors/{aasIdentifier}") - ResponseEntity deleteShell(URI url, @PathVariable("assetIds") String shellId); + ResponseEntity deleteShell(@PathVariable("assetIds") String shellId); @PostMapping(path = "/shell-descriptors/{aasIdentifier}/submodel-descriptors") - ResponseEntity createSubModel(URI url, @PathVariable("aasIdentifier") String shellId, + ResponseEntity createSubModel(@PathVariable("aasIdentifier") String shellId, @RequestBody CreateSubModelRequest request); - + @GetMapping(path = "/shell-descriptors/{aasIdentifier}/submodel-descriptors") - ResponseEntity getSubModels(URI digitalTwinsHost, - @PathVariable("aasIdentifier") String shellId); + ResponseEntity getSubModels(@PathVariable("aasIdentifier") String shellId); @DeleteMapping(path = "/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier}") - ResponseEntity deleteSubmodelfromShellById(URI url, @PathVariable("aasIdentifier") String shellId, + ResponseEntity deleteSubmodelfromShellById(@PathVariable("aasIdentifier") String shellId, @PathVariable("submodelIdentifier") String submodelIdentifier); @GetMapping(path = "/lookup/shells") - ResponseEntity shellLookup(URI url, @RequestParam String assetIds, + ResponseEntity shellLookup(@RequestParam String assetIds, @RequestHeader("Edc-Bpn") String edcBpn); - + @PostMapping(path = "/lookup/shells/{assetIds}") - ResponseEntity> createShellSpecificAttributes(URI url, @PathVariable("assetIds") String shellId, + ResponseEntity> createShellSpecificAttributes(@PathVariable("assetIds") String shellId, @RequestHeader("Edc-Bpn") String edcBpn, @RequestBody List specificAssetIds); - + @DeleteMapping(path = "/lookup/shells/{assetIds}") - ResponseEntity deleteShellSpecificAttributes(URI url, @PathVariable("assetIds") String shellId, + ResponseEntity deleteShellSpecificAttributes(@PathVariable("assetIds") String shellId, @RequestHeader("Edc-Bpn") String edcBpn); - -} +} \ No newline at end of file diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/EDCDigitalTwinProxyForLookUp.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/EDCDigitalTwinProxyForLookUp.java new file mode 100644 index 000000000..5fd66b0d2 --- /dev/null +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/gateways/external/EDCDigitalTwinProxyForLookUp.java @@ -0,0 +1,46 @@ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023 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 governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.digitaltwins.gateways.external; + +import java.net.URI; +import java.util.Map; + +import org.eclipse.tractusx.sde.digitaltwins.entities.response.ShellDescriptorResponse; +import org.eclipse.tractusx.sde.digitaltwins.entities.response.ShellLookupResponse; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; + +@FeignClient(value = "EDCDigitalTwinProxyForLookUp", url = "placeholder") +public interface EDCDigitalTwinProxyForLookUp { + + @GetMapping(path = "/shell-descriptors/{aasIdentifier}") + ResponseEntity getShellDescriptorByShellId(URI url, + @PathVariable("aasIdentifier") String shellId, @RequestHeader Map header); + + @GetMapping(path = "/lookup/shells") + ResponseEntity shellLookup(URI url, @RequestParam String assetIds, + @RequestHeader Map header); + +} \ No newline at end of file diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/api/ContractOfferCatalogApi.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/api/ContractOfferCatalogApi.java index 4cd20502e..d3f510edd 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/api/ContractOfferCatalogApi.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/api/ContractOfferCatalogApi.java @@ -26,7 +26,7 @@ import com.fasterxml.jackson.databind.JsonNode; -@FeignClient(value = "ContractOfferCatalogApi", url = "${edc.consumer.hostname}${edc.consumer.managementpath:/data/v2}", configuration = EDCDataConsumerConfiguration.class) +@FeignClient(value = "ContractOfferCatalogApi", url = "${edc.consumer.hostname}${edc.consumer.managementpath:/data}${edc.consumer.managementpath.apiversion:/v2}", configuration = EDCDataConsumerConfiguration.class) public interface ContractOfferCatalogApi { @PostMapping(value = "/catalog/request") diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/api/EDCFeignClientApi.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/api/EDCFeignClientApi.java index 91939c674..a24ab7bd5 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/api/EDCFeignClientApi.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/api/EDCFeignClientApi.java @@ -31,7 +31,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -@FeignClient(value = "EDCFeignClientApi", url = "${edc.hostname}${edc.managementpath:/data/v2}", configuration = EDCDataProviderConfiguration.class) +@FeignClient(value = "EDCFeignClientApi", url = "${edc.hostname}${edc.managementpath:/data}${edc.managementpath.apiversion:/v2}", configuration = EDCDataProviderConfiguration.class) public interface EDCFeignClientApi { @GetMapping(path = "/assets/{id}") diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/api/EDRApiProxy.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/api/EDRApiProxy.java new file mode 100644 index 000000000..45e203589 --- /dev/null +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/api/EDRApiProxy.java @@ -0,0 +1,59 @@ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023 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 governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.edc.api; + +import java.net.URI; +import java.util.List; +import java.util.Map; + +import org.eclipse.tractusx.sde.edc.model.contractnegotiation.AcknowledgementId; +import org.eclipse.tractusx.sde.edc.model.contractnegotiation.ContractNegotiations; +import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedByIdResponse; +import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedResponse; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; + +@FeignClient(value = "EDRApiProxy", url = "placeholder") +public interface EDRApiProxy { + + @PostMapping(path = "/edrs", consumes = MediaType.APPLICATION_JSON_VALUE) + AcknowledgementId edrCacheCreate(URI url, @RequestBody ContractNegotiations requestBody, + @RequestHeader Map requestHeader); + + @GetMapping(path = "/edrs", consumes = MediaType.APPLICATION_JSON_VALUE) + List getEDRCachedByAsset(URI url, @RequestParam("assetId") String assetId, + @RequestHeader Map requestHeader); + + @GetMapping(path = "/edrs/{transferProcessId}") + EDRCachedByIdResponse getEDRCachedByTransferProcessId(URI url, + @PathVariable("transferProcessId") String transferProcessId, + @RequestHeader Map requestHeader); + + @GetMapping + Object getActualDataFromProviderDataPlane(URI url, @RequestHeader Map requestHeader); + +} \ No newline at end of file diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java index 43ede726d..d2c0fcacf 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java @@ -77,7 +77,7 @@ private AssetEntryRequest buildAsset(String submodel, String shellId, String sub private String subModelPayloadUrl(String submodel, String uuid) { return UriComponentsBuilder .fromHttpUrl(dftHostname) - .path("/api/"+submodel+"/public/") + .path(submodel+"/public/") .path(uuid) .toUriString(); } diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/AbstractEDCStepsHelper.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/AbstractEDCStepsHelper.java index 80d64c5f0..4b2a75ddb 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/AbstractEDCStepsHelper.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/AbstractEDCStepsHelper.java @@ -27,9 +27,12 @@ public class AbstractEDCStepsHelper { - @Value("${edc.consumer.hostname}${edc.consumer.managementpath:/data/v2}") + @Value("${edc.consumer.hostname}${edc.consumer.managementpath:/data}${edc.consumer.managementpath.apiversion:/v2}") protected String consumerHost; - + + @Value("${edc.consumer.hostname}${edc.consumer.managementpath:/data}") + protected String consumerHostWithDataPath; + @Value("${edc.consumer.hostname}") protected String consumerHostWithoutDataPath; @@ -39,9 +42,12 @@ public class AbstractEDCStepsHelper { @Value("${edc.consumer.apikey}") private String edcApiKeyValue; - @Value("${edc.hostname}${edc.managementpath:/data/v2}") + @Value("${edc.hostname}${edc.managementpath:/data}${edc.managementpath.apiversion:/v2}") protected String providerHost; - + + @Value("${edc.hostname}${edc.managementpath:/data}") + protected String providerHostWithManagementPath; + @Value("${edc.hostname}") protected String providerHostWithoutDataPath; @@ -66,4 +72,4 @@ public Map getProviderAuthHeader() { return requestHeader; } -} +} \ No newline at end of file diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/EDRRequestHelper.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/EDRRequestHelper.java new file mode 100644 index 000000000..c4d8d0343 --- /dev/null +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/facilitator/EDRRequestHelper.java @@ -0,0 +1,76 @@ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023 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 governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.edc.facilitator; + +import java.net.URI; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.tractusx.sde.edc.api.EDRApiProxy; +import org.eclipse.tractusx.sde.edc.entities.request.policies.ActionRequest; +import org.eclipse.tractusx.sde.edc.mapper.ContractMapper; +import org.eclipse.tractusx.sde.edc.model.contractnegotiation.AcknowledgementId; +import org.eclipse.tractusx.sde.edc.model.contractnegotiation.ContractNegotiations; +import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedByIdResponse; +import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedResponse; +import org.springframework.stereotype.Service; + +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; + +@Service +@RequiredArgsConstructor +public class EDRRequestHelper extends AbstractEDCStepsHelper { + + private final EDRApiProxy edrApiProxy; + private final ContractMapper contractMapper; + + @SneakyThrows + public String edrRequestInitiate(String providerUrl, String providerId, String offerId, String assetId, + ActionRequest action, Map extensibleProperty) { + + ContractNegotiations contractNegotiations = contractMapper + .prepareContractNegotiations(providerUrl + protocolPath, offerId, assetId, providerId, action); + + AcknowledgementId acknowledgementId = edrApiProxy.edrCacheCreate(new URI(consumerHostWithDataPath), contractNegotiations, + getAuthHeader()); + return acknowledgementId.getId(); + } + + @SneakyThrows + public List getEDRCachedByAsset(String assetId) { + return edrApiProxy.getEDRCachedByAsset(new URI(consumerHostWithDataPath), assetId, getAuthHeader()); + } + + @SneakyThrows + public EDRCachedByIdResponse getEDRCachedByTransferProcessId(String transferProcessId) { + return edrApiProxy.getEDRCachedByTransferProcessId(new URI(consumerHostWithDataPath), transferProcessId, getAuthHeader()); + } + + @SneakyThrows + public Object getDataFromProvider(EDRCachedByIdResponse authorizationToken) { + Map authHeader = new HashMap<>(); + authHeader.put(authorizationToken.getAuthKey(), authorizationToken.getAuthCode()); + return edrApiProxy.getActualDataFromProviderDataPlane(new URI(authorizationToken.getEndpoint()), authHeader); + } + +} \ No newline at end of file diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/model/edr/EDRCachedByIdResponse.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/model/edr/EDRCachedByIdResponse.java new file mode 100644 index 000000000..0c018fd59 --- /dev/null +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/model/edr/EDRCachedByIdResponse.java @@ -0,0 +1,56 @@ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023 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 governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.edc.model.edr; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(Include.NON_NULL) +public class EDRCachedByIdResponse { + + @JsonProperty("edc:type") + private String type; + + @JsonProperty("edc:authCode") + private String authCode; + + @JsonProperty("edc:endpoint") + private String endpoint; + + @JsonProperty("edc:id") + private String id; + + @JsonProperty("edc:authKey") + private String authKey; + +} \ No newline at end of file diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/model/edr/EDRCachedResponse.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/model/edr/EDRCachedResponse.java new file mode 100644 index 000000000..66e368894 --- /dev/null +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/model/edr/EDRCachedResponse.java @@ -0,0 +1,65 @@ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023 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 governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.edc.model.edr; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(Include.NON_NULL) +public class EDRCachedResponse { + + @JsonProperty("@type") + private String type; + + @JsonProperty("@context") + private Object context; + + @JsonProperty("edc:agreementId") + private String agreementId; + + @JsonProperty("edc:transferProcessId") + private String transferProcessId; + + @JsonProperty("edc:assetId") + private String assetId; + + @JsonProperty("edc:providerId") + private String providerId; + + @JsonProperty("tx:edrState") + private String edrState; + + @JsonProperty("tx:expirationDate") + private String expirationDate; + +} \ No newline at end of file diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/services/ConsumerControlPanelService.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/services/ConsumerControlPanelService.java index 6a0682b6b..331821e23 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/services/ConsumerControlPanelService.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/services/ConsumerControlPanelService.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; @@ -32,6 +33,7 @@ import org.eclipse.tractusx.sde.common.entities.UsagePolicies; import org.eclipse.tractusx.sde.common.enums.PolicyAccessEnum; import org.eclipse.tractusx.sde.common.enums.UsagePolicyEnum; +import org.eclipse.tractusx.sde.common.exception.ServiceException; import org.eclipse.tractusx.sde.edc.api.ContractOfferCatalogApi; import org.eclipse.tractusx.sde.edc.constants.EDCAssetConstant; import org.eclipse.tractusx.sde.edc.entities.database.ContractNegotiationInfoEntity; @@ -39,10 +41,14 @@ import org.eclipse.tractusx.sde.edc.entities.request.policies.PolicyConstraintBuilderService; import org.eclipse.tractusx.sde.edc.facilitator.AbstractEDCStepsHelper; import org.eclipse.tractusx.sde.edc.facilitator.ContractNegotiateManagementHelper; +import org.eclipse.tractusx.sde.edc.facilitator.EDRRequestHelper; import org.eclipse.tractusx.sde.edc.gateways.database.ContractNegotiationInfoRepository; import org.eclipse.tractusx.sde.edc.model.contractnegotiation.ContractNegotiationDto; import org.eclipse.tractusx.sde.edc.model.contractoffers.ContractOfferRequestFactory; +import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedByIdResponse; +import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedResponse; import org.eclipse.tractusx.sde.edc.model.request.ConsumerRequest; +import org.eclipse.tractusx.sde.edc.model.request.OfferRequest; import org.eclipse.tractusx.sde.edc.model.response.QueryDataOfferModel; import org.eclipse.tractusx.sde.edc.util.UtilityFunctions; import org.springframework.scheduling.annotation.Async; @@ -50,7 +56,9 @@ import com.fasterxml.jackson.databind.JsonNode; +import feign.FeignException; import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -58,6 +66,8 @@ @RequiredArgsConstructor public class ConsumerControlPanelService extends AbstractEDCStepsHelper { + private static final String NEGOTIATED = "NEGOTIATED"; + private final ContractOfferCatalogApi contractOfferCatalogApiProxy; private final ContractNegotiateManagementHelper contractNegotiateManagement; @@ -66,6 +76,12 @@ public class ConsumerControlPanelService extends AbstractEDCStepsHelper { private final ContractOfferRequestFactory contractOfferRequestFactory; + private final EDRRequestHelper edrRequestHelper; + + private static final Integer RETRY = 5; + + private static final Integer THRED_SLEEP_TIME = 5000; + public List queryOnDataOffers(String providerUrl, Integer offset, Integer limit, String filterExpression) { @@ -75,7 +91,7 @@ public List queryOnDataOffers(String providerUrl, Integer o JsonNode contractOfferCatalog = contractOfferCatalogApiProxy .getContractOffersCatalog(contractOfferRequestFactory - .getContractOfferRequest(providerUrl + protocolPath, limit, offset, filterExpression)); + .getContractOfferRequest(sproviderUrl + protocolPath, limit, offset, filterExpression)); JsonNode jOffer = contractOfferCatalog.get("dcat:dataset"); if (jOffer.isArray()) { @@ -95,7 +111,7 @@ private QueryDataOfferModel buildContractOffer(String sproviderUrl, JsonNode con JsonNode policy = offer.get("odrl:hasPolicy"); String edcstr = "edc:"; - + QueryDataOfferModel build = QueryDataOfferModel.builder() .assetId(getFieldFromJsonNode(offer, edcstr + EDCAssetConstant.ASSET_PROP_ID)) .connectorOfferUrl(sproviderUrl + File.separator + getFieldFromJsonNode(offer, "@id")) @@ -209,7 +225,7 @@ public void subscribeDataOffers(ConsumerRequest consumerRequest, String processI && !checkContractNegotiationStatus.get().getState().equals("FINALIZED") && !checkContractNegotiationStatus.get().getState().equals("TERMINATED") && counter <= retry); - } catch(InterruptedException ie) { + } catch (InterruptedException ie) { log.error("Exception in subscribeDataOffers" + ie.getMessage()); Thread.currentThread().interrupt(); } catch (Exception e) { @@ -218,10 +234,8 @@ public void subscribeDataOffers(ConsumerRequest consumerRequest, String processI // Local DB entry ContractNegotiationInfoEntity contractNegotiationInfoEntity = ContractNegotiationInfoEntity.builder() - .id(UUID.randomUUID().toString()) - .processId(processId) - .connectorId(consumerRequest.getConnectorId()) - .offerId(offer.getOfferId()) + .id(UUID.randomUUID().toString()).processId(processId) + .connectorId(consumerRequest.getConnectorId()).offerId(offer.getOfferId()) .contractNegotiationId(negotiateContractId != null ? negotiateContractId.get() : null) .status(checkContractNegotiationStatus.get() != null ? checkContractNegotiationStatus.get().getState() @@ -234,4 +248,114 @@ public void subscribeDataOffers(ConsumerRequest consumerRequest, String processI } + @SneakyThrows + public EDRCachedResponse verifyOrCreateContractNegotiation(String connectorId, + Map extensibleProperty, String recipientURL, ActionRequest action, OfferRequest offer) { + // Verify if there already EDR process initiated then skip t for again download + List eDRCachedResponseList = edrRequestHelper.getEDRCachedByAsset(offer.getAssetId()); + EDRCachedResponse checkContractNegotiationStatus = verifyEDRResponse(eDRCachedResponseList); + + if (checkContractNegotiationStatus == null) { + log.info("There was no EDR process initiated or may be EDR token was expired " + offer.getAssetId() + + ", so initiating EDR process"); + edrRequestHelper.edrRequestInitiate(recipientURL, connectorId, offer.getOfferId(), offer.getAssetId(), + action, extensibleProperty); + } else { + log.info("There was EDR process initiated " + offer.getAssetId() + ", so ignoring EDR process initiation"); + } + + if (checkContractNegotiationStatus == null || !NEGOTIATED.equals(checkContractNegotiationStatus.getEdrState())) + checkContractNegotiationStatus = verifyEDRRequestStatus(offer.getAssetId()); + + return checkContractNegotiationStatus; + } + + @SneakyThrows + public EDRCachedResponse verifyEDRRequestStatus(String assetId) { + EDRCachedResponse eDRCachedResponse = null; + String edrStatus = "NewToSDE"; + List eDRCachedResponseList = null; + int counter = 1; + try { + do { + if (counter > 1) + Thread.sleep(THRED_SLEEP_TIME); + eDRCachedResponseList = edrRequestHelper.getEDRCachedByAsset(assetId); + eDRCachedResponse = verifyEDRResponse(eDRCachedResponseList); + + if (eDRCachedResponse != null) + edrStatus = eDRCachedResponse.getEdrState(); + + log.info("Verifying 'NEGOTIATED' EDC EDR status to download data for '" + assetId + + "', The current status is '" + edrStatus + "', Attempt " + counter); + counter++; + } while (counter <= RETRY && !NEGOTIATED.equals(edrStatus)); + + if (eDRCachedResponse == null) + throw new ServiceException("Time out!! unable to get EDR negotiated status"); + + } catch (FeignException e) { + log.error("RequestBody: " + e.request()); + String errorMsg = "FeignExceptionton for asset " + assetId + "," + e.contentUTF8(); + log.error("Response: " + errorMsg); + throw new ServiceException(errorMsg); + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + String errorMsg = "InterruptedException for asset " + assetId + "," + ie.getMessage(); + log.error(errorMsg); + throw new ServiceException(errorMsg); + } catch (Exception e) { + String errorMsg = "Exception for asset " + assetId + "," + e.getMessage(); + log.error(errorMsg); + throw new ServiceException(errorMsg); + } + return eDRCachedResponse; + } + + private EDRCachedResponse verifyEDRResponse(List eDRCachedResponseList) { + EDRCachedResponse eDRCachedResponse = null; + if (eDRCachedResponseList != null && !eDRCachedResponseList.isEmpty()) { + for (EDRCachedResponse edrCachedResponseObj : eDRCachedResponseList) { + String edrState = edrCachedResponseObj.getEdrState(); + // For EDC connector 5.0 edrState filed not supported so checking token + // validation by calling direct API + if (NEGOTIATED.equalsIgnoreCase(edrState) || isEDRTokenValid(edrCachedResponseObj)) { + eDRCachedResponse = edrCachedResponseObj; + eDRCachedResponse.setEdrState(NEGOTIATED); + break; + } + } + } + return eDRCachedResponse; + } + + @SneakyThrows + private boolean isEDRTokenValid(EDRCachedResponse edrCachedResponseObj) { + String assetId = edrCachedResponseObj.getAssetId(); + try { + edrRequestHelper.getDataFromProvider( + getAuthorizationTokenForDataDownload(edrCachedResponseObj.getTransferProcessId())); + } catch (FeignException e) { + log.error("RequestBody: " + e.request()); + String errorMsg = "FeignExceptionton for verifyEDR token " + assetId + "," + e.status() + "::" + + e.contentUTF8(); + log.error("Response: " + errorMsg); + + if (e.status() == 403) { + log.error("Got 403 as token status so going to try new EDR token: " + errorMsg); + return false; + } + } catch (Exception e) { + String errorMsg = "Exception for asset in isEDRTokenValid " + assetId + "," + e.getMessage(); + log.error(errorMsg); + throw new ServiceException(errorMsg); + } + return true; + } + + @SneakyThrows + public EDRCachedByIdResponse getAuthorizationTokenForDataDownload(String transferProcessId) { + return edrRequestHelper.getEDRCachedByTransferProcessId(transferProcessId); + } + } diff --git a/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/model/AspectRelationship.java b/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/model/AspectRelationship.java index 46c5efeec..e517f433a 100644 --- a/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/model/AspectRelationship.java +++ b/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/model/AspectRelationship.java @@ -52,7 +52,7 @@ public class AspectRelationship { private String oldSubmodelIdforUpdateCase; @JsonProperty(value = "row_number") - private int rowNumber; + private Integer rowNumber; @JsonProperty(value = "process_id") private String processId; diff --git a/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DDTRUrlCacheUtility.java b/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DDTRUrlCacheUtility.java index b93f35ccc..ee987dcc6 100644 --- a/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DDTRUrlCacheUtility.java +++ b/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DDTRUrlCacheUtility.java @@ -22,7 +22,12 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; +import org.eclipse.tractusx.sde.common.exception.ServiceException; +import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedByIdResponse; +import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedResponse; +import org.eclipse.tractusx.sde.edc.model.request.OfferRequest; import org.eclipse.tractusx.sde.edc.model.response.QueryDataOfferModel; import org.eclipse.tractusx.sde.edc.services.ConsumerControlPanelService; import org.eclipse.tractusx.sde.portal.handler.PortalProxyService; @@ -31,7 +36,9 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; +import feign.FeignException; import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -44,11 +51,11 @@ public class DDTRUrlCacheUtility { private final ConsumerControlPanelService consumerControlPanelService; @Cacheable(value = "bpn-ddtr", key = "#bpnNumber") - public List getDDTRUrl(String bpnNumber) { + public List getDDTRUrl(String bpnNumber) { List connectorInfos = portalProxyService.fetchConnectorInfo(List.of(bpnNumber)); - List dtURls = new ArrayList<>(); + List offers = new ArrayList<>(); String filterExpression = String.format(""" "filterExpression": [{ @@ -60,26 +67,50 @@ public List getDDTRUrl(String bpnNumber) { connectorInfos.stream().forEach( connectorInfo -> connectorInfo.getConnectorEndpoint().parallelStream().distinct().forEach(connector -> { try { - List queryDataOfferModel = consumerControlPanelService .queryOnDataOffers(connector, 0, 100, filterExpression); - log.info("For Connector " + connector + ", found asset :" + queryDataOfferModel.size()); - if (queryDataOfferModel != null && !queryDataOfferModel.isEmpty()) { - - List list = queryDataOfferModel.stream().map(QueryDataOfferModel::getPublisher) - .toList(); + queryDataOfferModel.forEach(each -> each.setConnectorOfferUrl(connector)); - dtURls.addAll(list); - } + offers.addAll(queryDataOfferModel); } catch (Exception e) { log.error("Error while looking EDC catalog for digitaltwin registry url, " + connector + ", Exception :" + e.getMessage()); } })); - return dtURls; + return offers; + } + + @SneakyThrows + public EDRCachedByIdResponse verifyAndGetToken(String bpnNumber, QueryDataOfferModel queryDataOfferModel) { + OfferRequest offer = OfferRequest.builder().assetId(queryDataOfferModel.getAssetId()) + .offerId(queryDataOfferModel.getOfferId()).policyId(queryDataOfferModel.getPolicyId()).build(); + try { + EDRCachedResponse eDRCachedResponse = consumerControlPanelService.verifyOrCreateContractNegotiation( + bpnNumber, Map.of(), queryDataOfferModel.getConnectorOfferUrl(), null, offer); + + if (eDRCachedResponse == null) { + throw new ServiceException( + "Time out!! to get 'NEGOTIATED' EDC EDR status to lookup dt twin, The current status is null"); + } else if (!"NEGOTIATED".equalsIgnoreCase(eDRCachedResponse.getEdrState())) { + throw new ServiceException( + "Time out!! to get 'NEGOTIATED' EDC EDR status to lookup dt twin, The current status is '" + + eDRCachedResponse.getEdrState() + "'"); + } else + return consumerControlPanelService + .getAuthorizationTokenForDataDownload(eDRCachedResponse.getTransferProcessId()); + + } catch (FeignException e) { + String errorMsg = "Unable to look up offer because: " + e.contentUTF8(); + log.error("FeignException : " + errorMsg); + } catch (Exception e) { + String errorMsg = "Unable to look up offer because: " + e.getMessage(); + log.error("Exception : " + errorMsg); + } + + return null; } @CacheEvict(value = "bpn-ddtr", key = "#bpnNumber") @@ -92,4 +123,4 @@ public void cleareDDTRUrlAllCache() { log.info("Cleared All bpn-ddtr cache"); } -} +} \ No newline at end of file diff --git a/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DigitalTwinsAspectRelationShipCsvHandlerUseCase.java b/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DigitalTwinsAspectRelationShipCsvHandlerUseCase.java index cc5213c3c..d6d19bda0 100644 --- a/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DigitalTwinsAspectRelationShipCsvHandlerUseCase.java +++ b/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DigitalTwinsAspectRelationShipCsvHandlerUseCase.java @@ -22,8 +22,10 @@ package org.eclipse.tractusx.sde.submodels.apr.steps; +import java.net.URI; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Base64; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -35,12 +37,19 @@ import org.eclipse.tractusx.sde.digitaltwins.entities.request.CreateSubModelRequest; import org.eclipse.tractusx.sde.digitaltwins.entities.request.ShellLookupRequest; import org.eclipse.tractusx.sde.digitaltwins.entities.response.ShellDescriptorResponse; +import org.eclipse.tractusx.sde.digitaltwins.entities.response.ShellLookupResponse; import org.eclipse.tractusx.sde.digitaltwins.entities.response.SubModelResponse; import org.eclipse.tractusx.sde.digitaltwins.facilitator.DigitalTwinsFacilitator; import org.eclipse.tractusx.sde.digitaltwins.facilitator.DigitalTwinsUtility; +import org.eclipse.tractusx.sde.digitaltwins.gateways.external.EDCDigitalTwinProxyForLookUp; +import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedByIdResponse; +import org.eclipse.tractusx.sde.edc.model.response.QueryDataOfferModel; import org.eclipse.tractusx.sde.submodels.apr.model.AspectRelationship; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; +import feign.FeignException; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -53,6 +62,7 @@ public class DigitalTwinsAspectRelationShipCsvHandlerUseCase extends Step { private final DigitalTwinsFacilitator digitalTwinfacilitaor; private final DigitalTwinsUtility digitalTwinsUtility; private final DDTRUrlCacheUtility dDTRUrlCacheUtility; + private final EDCDigitalTwinProxyForLookUp eDCDigitalTwinProxyForLookUp; private static final Map map = new ConcurrentHashMap<>(); @@ -107,7 +117,7 @@ private AspectRelationship doRun(AspectRelationship aspectRelationShip) private SubModelResponse checkShellforSubmodelExistorNot(AspectRelationship aspectRelationShip, ShellLookupRequest shellLookupRequest, List shellIds, SubModelResponse foundSubmodel) throws CsvHandlerDigitalTwinUseCaseException { - List items = digitalTwinfacilitaor.getShellDescriptorsWithSubmodelDetails(shellIds, null); + List items = digitalTwinfacilitaor.getShellDescriptorsWithSubmodelDetails(shellIds); List submodelExistinceCount = new ArrayList<>(); @@ -189,43 +199,35 @@ private CreateSubModelRequest getCreateSubModelRequest(AspectRelationship aspect ShellLookupRequest shellLookupRequest = getShellLookupRequestforChild(aspectRelationShip); - List dtURls = getDDTRUrl(aspectRelationShip.getChildManufacturerId()); + String childManufacturerId = aspectRelationShip.getChildManufacturerId(); + List queryDataOffers = getDDTRUrl(childManufacturerId); String childUUID = null; + String msg = ""; - for (String ddtUrl : dtURls) { + for (QueryDataOfferModel dtOffer : queryDataOffers) { - List childshellIds = digitalTwinfacilitaor.shellLookupFromDDTR(shellLookupRequest, ddtUrl, aspectRelationShip.getChildManufacturerId()); + EDRCachedByIdResponse edrToken = dDTRUrlCacheUtility.verifyAndGetToken(childManufacturerId, dtOffer); - if (childshellIds.isEmpty()) { - log.warn(aspectRelationShip.getRowNumber() + ", " + ddtUrl + ", No child aspect found for " - + shellLookupRequest.toJsonString()); - } - - if (childshellIds.size() > 1) { - log.warn(String.format("Multiple shell id's found for childAspect %s, %s", ddtUrl, - shellLookupRequest.toJsonString())); - } - - if (childshellIds.size() == 1) { - ShellDescriptorResponse shellDescriptorResponse = digitalTwinfacilitaor - .getShellDetailsById(childshellIds.get(0), ddtUrl, aspectRelationShip.getChildManufacturerId()); - childUUID = shellDescriptorResponse.getGlobalAssetId(); - log.debug(aspectRelationShip.getRowNumber() + ", " + ddtUrl + ", Child aspect found for " - + shellLookupRequest.toJsonString()); - break; + if (edrToken != null) { + childUUID = lookUpChildTwin(shellLookupRequest, aspectRelationShip, edrToken, dtOffer); + if (childUUID != null) + break; + } else { + msg = ", EDC connector " + dtOffer.getConnectorOfferUrl() + + ", The EDR token is null to find child twin "; + log.warn(aspectRelationShip.getRowNumber() + msg + shellLookupRequest.toJsonString()); } - } - if (dtURls.isEmpty()) { + if (queryDataOffers.isEmpty()) { throw new CsvHandlerUseCaseException(aspectRelationShip.getRowNumber(), "No DTR registry found for child aspect look up"); } if (childUUID == null) { throw new CsvHandlerUseCaseException(aspectRelationShip.getRowNumber(), - "No child aspect found for " + shellLookupRequest.toJsonString()); + "No child aspect found for " + shellLookupRequest.toJsonString() + " " + msg); } return digitalTwinsUtility.getCreateSubModelRequestForChild(aspectRelationShip.getShellId(), @@ -233,7 +235,66 @@ private CreateSubModelRequest getCreateSubModelRequest(AspectRelationship aspect } - public List getDDTRUrl(String bpnNumber) { + @SneakyThrows + private String lookUpChildTwin(ShellLookupRequest shellLookupRequest, AspectRelationship aspectRelationShip, + EDRCachedByIdResponse edrToken, QueryDataOfferModel dtOffer) { + String childUUID = null; + String endpoint = edrToken.getEndpoint(); + String dtOfferUrl = dtOffer.getConnectorOfferUrl(); + try { + + Map header = Map.of(edrToken.getAuthKey(), edrToken.getAuthCode()); + + ResponseEntity shellLookup = eDCDigitalTwinProxyForLookUp + .shellLookup(new URI(endpoint), shellLookupRequest.toJsonString(), header); + ShellLookupResponse body = shellLookup.getBody(); + + if (shellLookup.getStatusCode() == HttpStatus.OK && body != null) { + childUUID = getChildSubmodelDetails(shellLookupRequest, endpoint, header, aspectRelationShip, + dtOfferUrl, body.getResult()); + } + + } catch (FeignException e) { + String errorMsg = "Unable to look up child twin " + dtOfferUrl + ", " + shellLookupRequest.toJsonString() + + " because: " + e.contentUTF8(); + log.error("FeignException : " + errorMsg); + } catch (Exception e) { + String errorMsg = "Unable to look up child twin " + dtOfferUrl + ", " + shellLookupRequest.toJsonString() + + "because: " + e.getMessage(); + log.error("Exception : " + errorMsg); + } + + return childUUID; + } + + @SneakyThrows + private String getChildSubmodelDetails(ShellLookupRequest shellLookupRequest, String endpoint, + Map header, AspectRelationship aspectRelationShip, String dtOfferUrl, + List childshellIds) { + + String childUUID = null; + if (childshellIds == null) { + log.warn(aspectRelationShip.getRowNumber() + ", " + dtOfferUrl + ", No child aspect found for " + + shellLookupRequest.toJsonString()); + } else if (childshellIds.size() > 1) { + log.warn(String.format("Multiple shell id's found for childAspect %s, %s", dtOfferUrl, + shellLookupRequest.toJsonString())); + } else if (childshellIds.size() == 1) { + ResponseEntity shellDescriptorResponse = eDCDigitalTwinProxyForLookUp + .getShellDescriptorByShellId(new URI(endpoint), encodeShellIdBase64Utf8(childshellIds.get(0)), + header); + ShellDescriptorResponse shellDescriptorResponseBody = shellDescriptorResponse.getBody(); + if (shellDescriptorResponse.getStatusCode() == HttpStatus.OK && shellDescriptorResponseBody != null) { + childUUID = shellDescriptorResponseBody.getGlobalAssetId(); + log.debug(aspectRelationShip.getRowNumber() + ", " + dtOfferUrl + ", Child aspect found for " + + shellLookupRequest.toJsonString()); + } + } + + return childUUID; + } + + public List getDDTRUrl(String bpnNumber) { LocalDateTime cacheExpTime = map.get(bpnNumber); LocalDateTime currDate = LocalDateTime.now(); @@ -253,4 +314,7 @@ public void clearDDTRUrlCache() { dDTRUrlCacheUtility.cleareDDTRUrlAllCache(); } + private String encodeShellIdBase64Utf8(String shellId) { + return Base64.getUrlEncoder().encodeToString(shellId.getBytes()); + } } \ No newline at end of file diff --git a/modules/sde-submodules/part-as-planned/src/main/java/org/eclipse/tractusx/sde/submodels/pap/model/PartAsPlanned.java b/modules/sde-submodules/part-as-planned/src/main/java/org/eclipse/tractusx/sde/submodels/pap/model/PartAsPlanned.java index b93ea5cac..1f47f0d29 100644 --- a/modules/sde-submodules/part-as-planned/src/main/java/org/eclipse/tractusx/sde/submodels/pap/model/PartAsPlanned.java +++ b/modules/sde-submodules/part-as-planned/src/main/java/org/eclipse/tractusx/sde/submodels/pap/model/PartAsPlanned.java @@ -44,7 +44,7 @@ public class PartAsPlanned { private String subModelId; @JsonProperty(value ="row_number") - private int rowNumber; + private Integer rowNumber; @JsonProperty(value ="uuid") private String uuid; diff --git a/modules/sde-submodules/part-site-information-as-planned/src/main/java/org/eclipse/tractusx/sde/submodels/psiap/model/PartSiteInformationAsPlanned.java b/modules/sde-submodules/part-site-information-as-planned/src/main/java/org/eclipse/tractusx/sde/submodels/psiap/model/PartSiteInformationAsPlanned.java index d4f99c9f5..283f41dfa 100644 --- a/modules/sde-submodules/part-site-information-as-planned/src/main/java/org/eclipse/tractusx/sde/submodels/psiap/model/PartSiteInformationAsPlanned.java +++ b/modules/sde-submodules/part-site-information-as-planned/src/main/java/org/eclipse/tractusx/sde/submodels/psiap/model/PartSiteInformationAsPlanned.java @@ -44,7 +44,7 @@ public class PartSiteInformationAsPlanned { private String subModelId; @JsonProperty(value ="row_number") - private int rowNumber; + private Integer rowNumber; @JsonProperty(value ="uuid") private String uuid; diff --git a/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/mapper/PcfMapper.java b/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/mapper/PcfMapper.java index ffc0cb6ae..e54e8e840 100644 --- a/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/mapper/PcfMapper.java +++ b/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/mapper/PcfMapper.java @@ -95,9 +95,9 @@ public JsonObject mapToResponse(PcfEntity entity) { .productMassPerDeclaredUnit(entity.getProductMassPerDeclaredUnit()) .productOrSectorSpecificRules(List.of(ProductOrSectorSpecificRules.builder() .extWBCSDOperator(entity.getExtWBCSDOperator()) - .productOrSectorSpecificRulesObj(ProductOrSectorSpecificRule.builder() + .productOrSectorSpecificRulesObj(List.of(ProductOrSectorSpecificRule.builder() .ruleName(entity.getRuleName()) - .build()) + .build())) .extWBCSDOtherOperatorName(entity.getExtWBCSDOtherOperatorName()) .build())) .extTFSAllocationWasteIncineration(entity.getExtTFSAllocationWasteIncineration()) @@ -140,9 +140,9 @@ public JsonObject mapToResponse(PcfEntity entity) { return new Gson().toJsonTree(PcfSubmodelResponse.builder() .specVersion(entity.getSpecVersion()) - .companyIds(CompanyIds.builder() + .companyIds(List.of(CompanyIds.builder() .companyId(entity.getCompanyId()) - .build()) + .build())) .extWBCSDProductCodeCpc(entity.getExtWBCSDProductCodeCpc()) .created(entity.getCreated()) .companyName(entity.getCompanyName()) @@ -151,9 +151,9 @@ public JsonObject mapToResponse(PcfEntity entity) { .productName(entity.getProductName()) .pcf(pcfResponse) .partialFullPcf(entity.getPartialFullPcf()) - .productIds(ProductIds.builder() + .productIds(List.of(ProductIds.builder() .productId(entity.getProductId()) - .build()) + .build())) .validityPeriodStart(entity.getValidityPeriodStart()) .comment(entity.getComment()) @@ -162,9 +162,9 @@ public JsonObject mapToResponse(PcfEntity entity) { .pcfLegalStatement(entity.getPcfLegalStatement()) .productDescription(entity.getProductDescription()) - .precedingPfIds(PrecedingPfIds.builder() + .precedingPfIds(List.of(PrecedingPfIds.builder() .id(entity.getPrecedingPfId()) - .build()) + .build())) .build()).getAsJsonObject(); } diff --git a/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/model/PcfAspect.java b/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/model/PcfAspect.java index aca59a980..2565c074a 100644 --- a/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/model/PcfAspect.java +++ b/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/model/PcfAspect.java @@ -46,7 +46,7 @@ public class PcfAspect { private String subModelIdforPcf; @JsonProperty(value = "row_number") - private int rowNumberforPcf; + private Integer rowNumberforPcf; @JsonProperty(value = "bpn_numbers") private List bpnNumbersforPcf; diff --git a/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/model/PcfSubmodelResponse.java b/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/model/PcfSubmodelResponse.java index 66b28af42..ebc74d83c 100644 --- a/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/model/PcfSubmodelResponse.java +++ b/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/model/PcfSubmodelResponse.java @@ -19,6 +19,8 @@ ********************************************************************************/ package org.eclipse.tractusx.sde.submodels.pcf.model; +import java.util.List; + import com.google.gson.annotations.SerializedName; import lombok.AllArgsConstructor; @@ -31,7 +33,7 @@ public class PcfSubmodelResponse { private String specVersion; - private CompanyIds companyIds; + private List companyIds; @SerializedName(value = "extWBCSD_productCodeCpc") private String extWBCSDProductCodeCpc; @@ -44,13 +46,13 @@ public class PcfSubmodelResponse { private double version; private Pcf pcf; private String partialFullPcf; - private ProductIds productIds; + private List productIds; private String validityPeriodStart; private String comment; private String id; private String validityPeriodEnd; private String pcfLegalStatement; private String productDescription; - private PrecedingPfIds precedingPfIds; + private List precedingPfIds; -} +} \ No newline at end of file diff --git a/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/model/ProductOrSectorSpecificRules.java b/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/model/ProductOrSectorSpecificRules.java index 4e5937714..79d64dd82 100644 --- a/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/model/ProductOrSectorSpecificRules.java +++ b/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/model/ProductOrSectorSpecificRules.java @@ -19,6 +19,8 @@ ********************************************************************************/ package org.eclipse.tractusx.sde.submodels.pcf.model; +import java.util.List; + import com.google.gson.annotations.SerializedName; import lombok.AllArgsConstructor; @@ -34,7 +36,7 @@ public class ProductOrSectorSpecificRules { private String extWBCSDOperator; @SerializedName(value = "productOrSectorSpecificRules") - private ProductOrSectorSpecificRule productOrSectorSpecificRulesObj; + private List productOrSectorSpecificRulesObj; @SerializedName(value = "extWBCSD_otherOperatorName") private String extWBCSDOtherOperatorName; diff --git a/modules/sde-submodules/pcf/src/main/resources/pcf.json b/modules/sde-submodules/pcf/src/main/resources/pcf.json index 0b1a3dbce..1ddb5b838 100644 --- a/modules/sde-submodules/pcf/src/main/resources/pcf.json +++ b/modules/sde-submodules/pcf/src/main/resources/pcf.json @@ -12,6 +12,7 @@ "items": { "type": "object", "required": [ + "id", "specVersion", "companyId", "companyName", @@ -37,19 +38,19 @@ "pcfExcludingBiogenic", "extWBCSD_packagingGhgEmissions", "precedingPfId", - "secondaryEmissionFactorSource" + "secondaryEmissionFactorSource", + "assetLifeCyclePhase" ], - "dependentRequired": { - }, + "dependentRequired": {}, "properties": { "id": { "type": [ - "string", - "null" + "string" ], "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", "title": "Id", "description": "Constraint for defining a UUID v4 identifier.", + "minLength": 1, "examples": [ "3893bb5d-da16-4dc1-9185-11d97476c254" ] @@ -65,7 +66,7 @@ "2.0.1-20230314" ] }, - "partialFullPcf": { + "partialFullPcf": { "type": [ "string" ], @@ -80,22 +81,24 @@ "Cradle-to-gate" ] }, - "precedingPfId": { + "precedingPfId": { "type": [ "string" ], "title": "PrecedingPfId", + "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", "description": "The product footprint identifier as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "minLength": 1, "examples": [ "3893bb5d-da16-4dc1-9185-11d97476c254" ] }, - "version": { + "version": { "type": [ "number" ], "title": "Version", + "minimum": 0, "description": "Version of the product (carbon) footprint as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative. In Catena-X for example set to \"0\" per default.", "minLength": 1, "examples": [ @@ -106,15 +109,16 @@ "type": [ "string" ], - "format": "date-time", "title": "Created", + "format": "date-time", + "pattern": "-?([1-9][0-9]{3,}|0[0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]+)?|(24:00:00(\\.0+)?))(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?", "description": "Timestamp of the creation of the Product (Carbon) Footprint as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "minLength": 1, "examples": [ "2023-05-22T21:47:32Z" ] }, - "extWBCSD_pfStatus": { + "extWBCSD_pfStatus": { "type": [ "string" ], @@ -129,13 +133,14 @@ "Active" ] }, - "validityPeriodStart": { + "validityPeriodStart": { "type": [ "string", "null" ], "title": "ValidityPeriodStart", "format": "date-time", + "pattern": "-?([1-9][0-9]{3,}|0[0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]+)?|(24:00:00(\\.0+)?))(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?", "description": "Start of interval during which the product (carbon) footprint is declared as valid as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative. If specified, the validity period start must be equal to or greater than the reference period end.", "examples": [ "2022-01-01T00:00:01Z" @@ -148,12 +153,13 @@ ], "title": "ValidityPeriodEnd", "format": "date-time", + "pattern": "-?([1-9][0-9]{3,}|0[0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]+)?|(24:00:00(\\.0+)?))(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?", "description": "End of interval during which the product (carbon) footprint is declared as valid as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "examples": [ "2022-12-31T23:59:59Z" ] }, - "comment": { + "comment": { "type": [ "string", "null" @@ -164,7 +170,7 @@ "Comment for version 42." ] }, - "pcfLegalStatement": { + "pcfLegalStatement": { "type": [ "string", "null" @@ -175,7 +181,7 @@ "This PCF (Product Carbon Footprint) is for information purposes only. It is based upon the standards mentioned above." ] }, - "companyName": { + "companyName": { "type": [ "string" ], @@ -191,6 +197,7 @@ "string" ], "title": "CompanyId", + "format": "uri", "pattern": "^urn:uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", "description": "Identifier of a company in context of a product (carbon) footprint as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "minLength": 1, @@ -198,7 +205,7 @@ "urn:uuid:51131FB5-42A2-4267-A402-0ECFEFAD1619" ] }, - "productDescription": { + "productDescription": { "type": [ "string", "null" @@ -209,11 +216,12 @@ "Ethanol, 95% solution" ] }, - "productId": { + "productId": { "type": [ "string" ], "title": "ProductId", + "format": "uri", "description": "Identifier of a product in context of a product (carbon) footprint as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "minLength": 1, "examples": [ @@ -231,7 +239,7 @@ "011-99000" ] }, - "productName": { + "productName": { "type": [ "string" ], @@ -242,7 +250,7 @@ "My Product Name" ] }, - "declaredUnit": { + "declaredUnit": { "type": [ "string" ], @@ -263,40 +271,41 @@ "liter" ] }, - "unitaryProductAmount": { + "unitaryProductAmount": { "type": [ "number" ], "title": "UnitaryProductAmount", + "minimum": 0, "description": "Amount of units contained within a product in context of the PCF (Product Carbon Footprint) as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", - "minLength": 1, "examples": [ - "1000.0" + 1000.0 ] }, - "productMassPerDeclaredUnit": { + "productMassPerDeclaredUnit": { "type": [ "number" ], "title": "ProductMassPerDeclaredUnit", "description": "Mass of a product per declared unit in context of the PCF (Product Carbon Footprint) as specified in the Catena-X PCF Rulebook.", - "minLength": 1, + "minimum": 0, "examples": [ - "0.456" + 0.456 ] }, - "exemptedEmissionsPercent": { + "exemptedEmissionsPercent": { "type": [ "number" ], "title": "ExemptedEmissionsPercent", "description": "Percentage of emissions excluded from PCF (Product Carbon Footprint) as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", - "minLength": 1, + "maximum": 5, + "minimum": 0, "examples": [ - "0.0" + 0.0 ] }, - "exemptedEmissionsDescription": { + "exemptedEmissionsDescription": { "type": [ "string", "null" @@ -307,7 +316,7 @@ "No exemption" ] }, - "extWBCSD_packagingEmissionsIncluded": { + "extWBCSD_packagingEmissionsIncluded": { "type": [ "string" ], @@ -322,7 +331,7 @@ "true" ] }, - "boundaryProcessesDescription": { + "boundaryProcessesDescription": { "type": [ "string", "null" @@ -333,7 +342,7 @@ "Electricity consumption included as an input in the production phase" ] }, - "geographyCountrySubdivision": { + "geographyCountrySubdivision": { "type": [ "string", "null" @@ -345,7 +354,7 @@ "US-NY" ] }, - "geographyCountry": { + "geographyCountry": { "type": [ "string", "null" @@ -357,12 +366,13 @@ "DE" ] }, - "geographyRegionOrSubregion": { + "geographyRegionOrSubregion": { "type": [ "string", "null" ], "enum": [ + "", "Africa", "Americas", "Asia", @@ -393,31 +403,33 @@ "DE" ] }, - "referencePeriodStart": { + "referencePeriodStart": { "type": [ "string" ], "title": "ReferencePeriodStart", "format": "date-time", + "pattern": "-?([1-9][0-9]{3,}|0[0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]+)?|(24:00:00(\\.0+)?))(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?", "minLength": 1, "description": "Start of time boundary for which a PCF (Product Carbon Footprint) value is considered to be representative as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "examples": [ "2022-01-01T00:00:01Z" ] }, - "referencePeriodEnd": { + "referencePeriodEnd": { "type": [ "string" ], "title": "ReferencePeriodEnd", "format": "date-time", + "pattern": "-?([1-9][0-9]{3,}|0[0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]+)?|(24:00:00(\\.0+)?))(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?", "minLength": 1, "description": "End of time boundary for which a PCF (Product Carbon Footprint) value is considered to be representative as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "examples": [ "2022-12-31T23:59:59Z" ] }, - "crossSectoralStandard": { + "crossSectoralStandard": { "type": [ "string" ], @@ -433,7 +445,7 @@ "GHG Protocol Product standard" ] }, - "extWBCSD_operator": { + "extWBCSD_operator": { "type": [ "string" ], @@ -449,7 +461,7 @@ "PEF" ] }, - "ruleName": { + "ruleName": { "type": [ "string" ], @@ -460,18 +472,19 @@ "urn:tfs-initiative.com:PCR:The Product Carbon Footprint Guideline for the Chemical Industry:version:v2.0" ] }, - "extWBCSD_otherOperatorName": { + "extWBCSD_otherOperatorName": { "type": [ "string", "null" ], "title": "ExtWBCSD_otherOperatorName", "description": "Other operator of PCR (Product Category Rule)/ PSR (Product Specific Rule) as specified in the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative. WBCSD specific extension, in Catena-X for example specified by a default value.", + "minLength": 1, "examples": [ "NSF" ] }, - "extWBCSD_characterizationFactors": { + "extWBCSD_characterizationFactors": { "type": [ "string" ], @@ -486,18 +499,18 @@ "AR5" ] }, - "extWBCSD_allocationRulesDescription": { + "extWBCSD_allocationRulesDescription": { "type": [ - "string" + "string", + "null" ], "title": "ExtWBCSD_allocationRulesDescription", "description": "Allocation rules used and underlying reasoning in context of a product carbon footprint as specified in the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative. WBCSD specific extension, in Catena-X for example specified by default with value \"In accordance with Catena-X PCF Rulebook\".", - "minLength": 1, "examples": [ "In accordance with Catena-X PCF Rulebook" ] }, - "extTFS_allocationWasteIncineration": { + "extTFS_allocationWasteIncineration": { "type": [ "string" ], @@ -513,18 +526,20 @@ "cut-off" ] }, - "primaryDataShare": { + "primaryDataShare": { "type": [ "number", "null" ], "title": "PrimaryDataShare", + "maximum": 1E+2, + "minimum": 0, "description": "Share of primary data in percent as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "examples": [ 56.12 ] }, - "secondaryEmissionFactorSource": { + "secondaryEmissionFactorSource": { "type": [ "string" ], @@ -535,84 +550,97 @@ "ecoinvent 3.8" ] }, - "coveragePercent": { + "coveragePercent": { "type": [ "number", "null" ], "title": "CoveragePercent", + "maximum": 1E+2, + "minimum": 0, "description": "Percentage of PCF (Product Carbon Footprint) included in the data quality assessment based on the >5% emissions threshold as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative. In Catena-X for example set to \"100\" per default.", "examples": [ 100 ] }, - "technologicalDQR": { + "technologicalDQR": { "type": [ "number", "null" ], "title": "TechnologicalDQR", + "maximum": 3, + "minimum": 1, "description": "Technological representativeness of the sources used for PCF (Product Carbon Footprint) calculation based on weighted average of all inputs representing >5% of PCF emissions. Specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "examples": [ 2.0 ] }, - "temporalDQR": { + "temporalDQR": { "type": [ "number", "null" ], "title": "TemporalDQR", + "maximum": 3, + "minimum": 1, "description": "Temporal representativeness of the sources used for PCF (Product Carbon Footprint) calculation based on weighted average of all inputs representing >5% of PCF emissions. Specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "examples": [ 2.0 ] }, - "geographicalDQR": { + "geographicalDQR": { "type": [ "number", "null" ], "title": "GeographicalDQR", + "maximum": 3, + "minimum": 1, "description": "Geographical representativeness of the sources used for PCF (Product Carbon Footprint) calculation based on weighted average of all inputs representing >5% of PCF emissions. Specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "examples": [ 2.0 ] }, - "completenessDQR": { + "completenessDQR": { "type": [ "number", "null" ], "title": "CompletenessDQR", + "maximum": 3, + "minimum": 1, "description": "Completeness of the data collected for PCF (Product Carbon Footprint) calculation based on weighted average of all inputs representing >5% of PCF emissions. Specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "examples": [ 2.0 ] }, - "reliabilityDQR": { + "reliabilityDQR": { "type": [ "number", "null" ], "title": "ReliabilityDQR", + "maximum": 3, + "minimum": 1, "description": "Reliability of the data collected for PCF (Product Carbon Footprint) calculation based on weighted average of all inputs representing >5% of PCF emissions. Specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "examples": [ 2.0 ] }, - "pcfExcludingBiogenic": { + "pcfExcludingBiogenic": { "type": [ "number" ], "title": "PcfExcludingBiogenic", + "minimum": 0, "description": "Product carbon footprint of a product excluding biogenic emissions as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "minLength": 1, "examples": [ 2.0 ] }, - "pcfIncludingBiogenic": { + "pcfIncludingBiogenic": { "type": [ "number", "null" @@ -623,95 +651,103 @@ 1.0 ] }, - "fossilGhgEmissions": { + "fossilGhgEmissions": { "type": [ "number", "null" ], "title": "FossilGhgEmissions", + "minimum": 0, "description": "Emissions from combustion of fossil sources as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative. Identical to \"pcfExcludingBiogenic\", will be removed in later version.", "examples": [ 0.5 ] }, - "biogenicCarbonEmissionsOtherThanCO2": { + "biogenicCarbonEmissionsOtherThanCO2": { "type": [ "number", "null" ], "title": "BiogenicCarbonEmissionsOtherThanCO2", + "minimum": 0, "description": "GWP (Global Warming Potential) of biogenic CO2e-emissions in production phase which contain only GHG (Greenhouse Gas) emissions other than CO2 - excludes biogenic CO2. For specification see Catena-X PCF Rulebook.", "examples": [ 1.0 ] }, - "biogenicCarbonWithdrawal": { + "biogenicCarbonWithdrawal": { "type": [ "number", "null" ], "title": "BiogenicCarbonWithdrawal", + "minimum": 0, "description": "Biogenic carbon content in the product converted to CO2e as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "examples": [ 0.0 ] }, - "dlucGhgEmissions": { + "dlucGhgEmissions": { "type": [ "number", "null" ], "title": "BlucGhgEmissions", + "minimum": 0, "description": "Direct land use change CO2e emissions in context of a product carbon footprint as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "examples": [ 0.4 ] }, - "extTFS_luGhgEmissions": { + "extTFS_luGhgEmissions": { "type": [ "number", "null" ], "title": "ExtTFS_luGhgEmissions", + "minimum": 0, "description": "Land use CO2 emissions in context of a product carbon footprint as specified by the TFS (Together For Sustainability) initiative. TFS specific extension.", "examples": [ 0.3 ] }, - "aircraftGhgEmissions": { + "aircraftGhgEmissions": { "type": [ "number", "null" ], "title": "AircraftGhgEmissions", + "minimum": 0, "description": "GHG (Greenhouse Gas) emissions resulting from aircraft engine usage for the transport of the product as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "examples": [ 0.0 ] }, - "extWBCSD_packagingGhgEmissions": { + "extWBCSD_packagingGhgEmissions": { "type": [ "number" ], "title": "ExtWBCSD_packagingGhgEmissions", + "minimum": 0, "description": "Emissions resulting from the packaging of the product as specified in the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative. WBCSD specific extension, in Catena-X for example value is zero per default.", "minLength": 1, "examples": [ 0 ] }, - "distributionStagePcfExcludingBiogenic": { + "distributionStagePcfExcludingBiogenic": { "type": [ "number", "null" ], "title": "DistributionStagePcfExcludingBiogenic", + "minimum": 0, "description": "Product carbon footprint for the distribution stage of a product excluding biogenic emissions as specified in the Catena-X PCF Rulebook.", "examples": [ 1.5 ] }, - "distributionStagePcfIncludingBiogenic": { + "distributionStagePcfIncludingBiogenic": { "type": [ "number", "null" @@ -722,95 +758,103 @@ 0.0 ] }, - "distributionStageFossilGhgEmissions": { + "distributionStageFossilGhgEmissions": { "type": [ "number", "null" ], "title": "DistributionStageFossilGhgEmissions", + "minimum": 0, "description": "Emissions from the combustion of fossil sources in the distribution stage as specified in the Catena-X PCF Rulebook.", "examples": [ 0.5 ] }, - "distributionStageBiogenicCarbonEmissionsOtherThanCO2": { + "distributionStageBiogenicCarbonEmissionsOtherThanCO2": { "type": [ "number", "null" ], "title": "DistributionStageBiogenicCarbonEmissionsOtherThanCO2", + "minimum": 0, "description": "GWP (Global Warming Potential) of biogenic CO2e-emissions in distribution phase which contain only GHG (Greenhouse Gas) emissions other than CO2 ? excludes biogenic CO2. For specification see Catena-X PCF Rulebook.", "examples": [ 1.0 ] }, - "distributionStageBiogenicCarbonWithdrawal": { + "distributionStageBiogenicCarbonWithdrawal": { "type": [ "number", "null" ], "title": "DistributionStageBiogenicCarbonWithdrawal", + "minimum": 0, "description": "GWP (Global Warming Potential) of biogenic CO2-withdrawal in distribution stage (biogenic CO2 contained in the product) as specified in the Catena-X PCF Rulebook.", "examples": [ 0.5 ] }, - "extTFS_distributionStageDlucGhgEmissions": { + "extTFS_distributionStageDlucGhgEmissions": { "type": [ "number", "null" ], "title": "ExtTFS_distributionStageDlucGhgEmissions", + "minimum": 0, "description": "Direct land use change CO2 emissions during distribution stage in context of a product carbon footprint as specified in the Catena-X PCF Rulebook. TFS specific extension.", "examples": [ 1.0 ] }, - "extTFS_distributionStageLuGhgEmissions": { + "extTFS_distributionStageLuGhgEmissions": { "type": [ "number", "null" ], "title": "ExtTFS_distributionStageLuGhgEmissions", + "minimum": 0, "description": "Land use CO2 emissions in context of a product carbon footprint as specified by the TFS (Together For Sustainability) initiative. TFS specific extension.", "examples": [ 1.1 ] }, - "carbonContentTotal": { + "carbonContentTotal": { "type": [ "number", "null" ], "title": "CarbonContentTotal", + "minimum": 0, "description": "Total carbon content per declared unit in context of a product carbon footprint as specified in the Catena-X PCF Rulebook.", "examples": [ 2.5 ] }, - "extWBCSD_fossilCarbonContent": { + "extWBCSD_fossilCarbonContent": { "type": [ "number", "null" ], "title": "ExtWBCSD_fossilCarbonContent", + "minimum": 0, "description": "Fossil carbon amount embodied in a product as specified in the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative. WBCSD specific extension, in Catena-X for example specified by a calculated value.", "examples": [ 0.1 ] }, - "carbonContentBiogenic": { + "carbonContentBiogenic": { "type": [ "number", "null" ], "title": "carbonContentBiogenic", + "minimum": 0, "description": "Biogenic carbon amount embodied in a product as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "examples": [ 0.0 ] }, - "assetLifeCyclePhase": { + "assetLifeCyclePhase": { "type": [ "string" ], @@ -822,14 +866,13 @@ "AsMaintained", "AsRecycled" ], - "minLength": 1, "title": "Asset Life Cycle Phase", + "minLength": 1, "description": "The lifecycle context in which the child part was assembled into the parent part.", "examples": [ - "lifecycle" + "AsPlanned" ] } - } }, "examples": [ @@ -845,7 +888,7 @@ "validityPeriodEnd": "2022-12-31T23:59:59Z", "comment": "Comment for version 42.", "pcfLegalStatement": "This PCF (Product Carbon Footprint) is for information purposes only. It is based upon the standards mentioned above.", - "companyName": "My Corp", + "companyName": "My Corp", "companyId": "urn:uuid:51131FB5-42A2-4267-A402-0ECFEFAD1619", "productDescription": "Ethanol, 95% solution", "productId": "urn:gtin:4712345060507", @@ -853,7 +896,7 @@ "productName": "My Product Name", "declaredUnit": "liter", "unitaryProductAmount": 1000.0, - "productMassPerDeclaredUnit": 0.456, + "productMassPerDeclaredUnit": 0.456, "exemptedEmissionsPercent": 0.0, "exemptedEmissionsDescription": "No exemption", "extWBCSD_packagingEmissionsIncluded": "true", @@ -865,13 +908,13 @@ "referencePeriodEnd": "2022-12-31T23:59:59Z", "crossSectoralStandard": "GHG Protocol Product standard", "extWBCSD_operator": "PEF", - "ruleName": "urn:tfs-initiative.com:PCR:The Product Carbon Footprint Guideline for the Chemical Industry:version:v2.0", - "extWBCSD_otherOperatorName": "NSF", + "ruleName": "urn:tfs-initiative.com:PCR:The Product Carbon Footprint Guideline for the Chemical Industry:version:v2.0", + "extWBCSD_otherOperatorName": "NSF", "extWBCSD_characterizationFactors": "AR5", - "extWBCSD_allocationRulesDescription": "In accordance with Catena-X PCF Rulebook", + "extWBCSD_allocationRulesDescription": "In accordance with Catena-X PCF Rulebook", "extTFS_allocationWasteIncineration": "cut-off", "primaryDataShare": 56.12, - "secondaryEmissionFactorSource": "ecoinvent 3.8", + "secondaryEmissionFactorSource": "ecoinvent 3.8", "coveragePercent": 100, "technologicalDQR": 2.0, "temporalDQR": 2.0, @@ -896,8 +939,8 @@ "extTFS_distributionStageLuGhgEmissions": 1.1, "carbonContentTotal": 2.5, "extWBCSD_fossilCarbonContent": 0.1, - "carbonContentBiogenic": 0.0, + "carbonContentBiogenic": 0.0, "assetLifeCyclePhase": "AsPlanned" } ] -} +} \ No newline at end of file diff --git a/modules/sde-submodules/single-level-usage-as-built/src/main/java/org/eclipse/tractusx/sde/submodels/sluab/model/SingleLevelUsageAsBuilt.java b/modules/sde-submodules/single-level-usage-as-built/src/main/java/org/eclipse/tractusx/sde/submodels/sluab/model/SingleLevelUsageAsBuilt.java index 4e44fdc85..5b8938776 100644 --- a/modules/sde-submodules/single-level-usage-as-built/src/main/java/org/eclipse/tractusx/sde/submodels/sluab/model/SingleLevelUsageAsBuilt.java +++ b/modules/sde-submodules/single-level-usage-as-built/src/main/java/org/eclipse/tractusx/sde/submodels/sluab/model/SingleLevelUsageAsBuilt.java @@ -48,7 +48,7 @@ public class SingleLevelUsageAsBuilt { private String updated; @JsonProperty(value = "row_number") - private int rowNumber; + private Integer rowNumber; @JsonProperty(value = "process_id") private String processId; From c4f16b7350e2196bda76cfe1c6c028974365c79b Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Wed, 18 Oct 2023 23:01:10 +0530 Subject: [PATCH 02/23] Log twin look up status --- .../DigitalTwinsAspectRelationShipCsvHandlerUseCase.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DigitalTwinsAspectRelationShipCsvHandlerUseCase.java b/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DigitalTwinsAspectRelationShipCsvHandlerUseCase.java index d6d19bda0..5b3713605 100644 --- a/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DigitalTwinsAspectRelationShipCsvHandlerUseCase.java +++ b/modules/sde-submodules/assembly-part-relationship/src/main/java/org/eclipse/tractusx/sde/submodels/apr/steps/DigitalTwinsAspectRelationShipCsvHandlerUseCase.java @@ -211,8 +211,12 @@ private CreateSubModelRequest getCreateSubModelRequest(AspectRelationship aspect if (edrToken != null) { childUUID = lookUpChildTwin(shellLookupRequest, aspectRelationShip, edrToken, dtOffer); - if (childUUID != null) + if (childUUID != null) { break; + } else { + log.warn(aspectRelationShip.getRowNumber() + ", EDC connector " + dtOffer.getConnectorOfferUrl() + + ", No child twin found for " + shellLookupRequest.toJsonString()); + } } else { msg = ", EDC connector " + dtOffer.getConnectorOfferUrl() + ", The EDR token is null to find child twin "; @@ -227,7 +231,7 @@ private CreateSubModelRequest getCreateSubModelRequest(AspectRelationship aspect if (childUUID == null) { throw new CsvHandlerUseCaseException(aspectRelationShip.getRowNumber(), - "No child aspect found for " + shellLookupRequest.toJsonString() + " " + msg); + "No child aspect found for " + shellLookupRequest.toJsonString()); } return digitalTwinsUtility.getCreateSubModelRequestForChild(aspectRelationShip.getShellId(), From e657b77dc6992788d6327974571d6a48df6bcb94 Mon Sep 17 00:00:00 2001 From: Sachin Argade <91305578+sachinargade123@users.noreply.github.com> Date: Thu, 19 Oct 2023 11:50:56 +0530 Subject: [PATCH 03/23] Create sdebuild --- .github/workflows/sdebuild | 83 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/workflows/sdebuild diff --git a/.github/workflows/sdebuild b/.github/workflows/sdebuild new file mode 100644 index 000000000..859239e8f --- /dev/null +++ b/.github/workflows/sdebuild @@ -0,0 +1,83 @@ +################################################################################# +# Copyright (c) 2022,2023 T-Systems International GmbH +# Copyright (c) 2022,2023 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 governing permissions and limitations +# under the License. +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ +name: sdebuild + +on: + push: + branches: + - 'update_twin_lookup_3.2' + tags: + - 'v*.*.*' + - 'v*.*.*-*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up JDK 18 + uses: actions/setup-java@v3 + with: + java-version: '18' + distribution: 'temurin' + + - name: Build + run: mvn -B package + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Create SemVer or ref tags dependent of trigger event + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}},value=v2.1.2 + flavor: | + latest=true + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + file: ./build/Dockerfile + push: true + # build tag :main + tags: ${{ steps.meta.outputs.tags }} + # build tag :latest + # tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + labels: ${{ steps.meta.outputs.labels }} From 95ad0bc92d73a050f6f065e43b30ccdcb5d5eb28 Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Thu, 19 Oct 2023 11:54:48 +0530 Subject: [PATCH 04/23] Added DSP enpoint path for digitaltwin edc url --- .../sde-core/src/main/resources/application.properties | 1 + .../digitaltwins/facilitator/DigitalTwinsUtility.java | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/sde-core/src/main/resources/application.properties b/modules/sde-core/src/main/resources/application.properties index 34288b343..0267e6535 100644 --- a/modules/sde-core/src/main/resources/application.properties +++ b/modules/sde-core/src/main/resources/application.properties @@ -74,6 +74,7 @@ edc.hostname= edc.managementpath=/data/v2 edc.apiKeyHeader= edc.apiKey= +edc.dsp.endpointpath=/api/v1/dsp ## EDC Consumer edc.consumer.hostname= diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java index 5786d7d1d..ab57cc6a7 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java @@ -59,9 +59,9 @@ public class DigitalTwinsUtility { @Value(value = "${manufacturerId}") public String manufacturerId; - @Value(value = "${edc.hostname}") - public String edcEndpoint; - + @Value(value = "${edc.hostname}${edc.dsp.endpointpath:/api/v1/dsp}") + public String digitalTwinEdcDspEndpoint; + ObjectMapper mapper = new ObjectMapper(); private static final Map> publicReadableSpecificAssetIDs = Map.of(MANUFACTURER_PART_ID, @@ -112,12 +112,12 @@ public List prepareDtEndpoint(String shellId, String submodelIdentific List endpoints = new ArrayList<>(); endpoints.add(Endpoint.builder().endpointInterface(CommonConstants.INTERFACE) .protocolInformation(ProtocolInformation.builder() - .endpointAddress(edcEndpoint + CommonConstants.SUBMODEL_CONTEXT_URL) + .endpointAddress(digitalTwinEdcDspEndpoint + CommonConstants.SUBMODEL_CONTEXT_URL) .endpointProtocol(CommonConstants.HTTP) .endpointProtocolVersion(List.of(CommonConstants.ENDPOINT_PROTOCOL_VERSION)) .subProtocol(CommonConstants.SUB_PROTOCOL) .subprotocolBody("id=" + shellId + "-" + submodelIdentification + ";dspEndpoint=" - + edcEndpoint) + + digitalTwinEdcDspEndpoint) .subprotocolBodyEncoding(CommonConstants.BODY_ENCODING) .securityAttributes(List.of(new SecurityAttributes("NONE", "NONE", "NONE"))).build()) .build()); From a717747938dd9f654e81c207f75a75b9576c1eb8 Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Thu, 19 Oct 2023 12:13:46 +0530 Subject: [PATCH 05/23] Update pcf schema for companyId --- modules/sde-submodules/pcf/src/main/resources/pcf.json | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/sde-submodules/pcf/src/main/resources/pcf.json b/modules/sde-submodules/pcf/src/main/resources/pcf.json index 1ddb5b838..eb8f2db72 100644 --- a/modules/sde-submodules/pcf/src/main/resources/pcf.json +++ b/modules/sde-submodules/pcf/src/main/resources/pcf.json @@ -198,7 +198,6 @@ ], "title": "CompanyId", "format": "uri", - "pattern": "^urn:uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", "description": "Identifier of a company in context of a product (carbon) footprint as specified in the Catena-X PCF Rulebook in accordance with the technical specifications for PCF Data Exchange (Version 2.0.0) from the WBCSD (World Business Council for Sustainable Development)/ PACT initiative.", "minLength": 1, "examples": [ From 4fc06cea5cdd33c9b48540dc1cda94def1dc0d40 Mon Sep 17 00:00:00 2001 From: Sachin Argade <91305578+sachinargade123@users.noreply.github.com> Date: Thu, 19 Oct 2023 12:20:42 +0530 Subject: [PATCH 06/23] Rename sdebuild to sdebuild.yml --- .github/workflows/{sdebuild => sdebuild.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{sdebuild => sdebuild.yml} (100%) diff --git a/.github/workflows/sdebuild b/.github/workflows/sdebuild.yml similarity index 100% rename from .github/workflows/sdebuild rename to .github/workflows/sdebuild.yml From 1a0f35a8049456fb469ef345ee9fda959eaa220a Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Thu, 19 Oct 2023 12:44:48 +0530 Subject: [PATCH 07/23] BPN url add API path --- .../bpndiscovery/api/IBpndiscoveryExternalServiceApi.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/sde-external-services/bpn-discovery/src/main/java/org/eclipse/tractusx/sde/bpndiscovery/api/IBpndiscoveryExternalServiceApi.java b/modules/sde-external-services/bpn-discovery/src/main/java/org/eclipse/tractusx/sde/bpndiscovery/api/IBpndiscoveryExternalServiceApi.java index 01b9a5da6..9f94b4bc2 100644 --- a/modules/sde-external-services/bpn-discovery/src/main/java/org/eclipse/tractusx/sde/bpndiscovery/api/IBpndiscoveryExternalServiceApi.java +++ b/modules/sde-external-services/bpn-discovery/src/main/java/org/eclipse/tractusx/sde/bpndiscovery/api/IBpndiscoveryExternalServiceApi.java @@ -36,17 +36,17 @@ @FeignClient(value = "IBpndiscoveryExternalServiceApi", url = "${bpndiscovery.hostname}", configuration = BpndiscoveryExternalServiceApi.class) public interface IBpndiscoveryExternalServiceApi { - @PostMapping(path = "/api/administration/connectors/bpnDiscovery") + @PostMapping(path = "/administration/connectors/bpnDiscovery") BpnDiscoveryResponse bpnDiscoveryDataByKey(@RequestBody BpnDiscoveryRequest bpnDiscoveryKey); - @PostMapping(path = "/api/administration/connectors/bpnDiscovery/batch") + @PostMapping(path = "/administration/connectors/bpnDiscovery/batch") List bpnDiscoveryBatchDataByList( @RequestBody List bpnDiscoveryKeyList); - @PostMapping(path = "/api/administration/connectors/bpnDiscovery/search") + @PostMapping(path = "/administration/connectors/bpnDiscovery/search") BpnDiscoverySearchResponse bpnDiscoverySearchData(@RequestBody BpnDiscoverySearchRequest bpnDiscoverySearchRequest); - @DeleteMapping(path = "/api/administration/connectors/bpnDiscovery/{resourceId}") + @DeleteMapping(path = "/administration/connectors/bpnDiscovery/{resourceId}") ResponseEntity deleteBpnDiscoveryData(@PathVariable String resourceId); } From 3f838fb21e6f08edfff72e5aca965ebb5a43518b Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Thu, 19 Oct 2023 14:32:09 +0530 Subject: [PATCH 08/23] Hide PCF submodel from loading --- .../sde/submodels/pcf/PcfSubmodel.java | 30 +------------------ 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/PcfSubmodel.java b/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/PcfSubmodel.java index 9ef34a2e2..6f6bb3db0 100644 --- a/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/PcfSubmodel.java +++ b/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/PcfSubmodel.java @@ -19,42 +19,14 @@ ********************************************************************************/ package org.eclipse.tractusx.sde.submodels.pcf; -import java.io.InputStream; - -import org.eclipse.tractusx.sde.common.extensions.SubmodelExtension; import org.eclipse.tractusx.sde.common.model.Submodel; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import jakarta.annotation.PostConstruct; - @Component -public class PcfSubmodel extends SubmodelExtension { +public class PcfSubmodel { private Submodel submodel = null; - @Autowired - private PcfExecutor pcfWorkflow; - - @PostConstruct - public void init() { - - String resource = "pcf.json"; - // this is the path within the jar file - InputStream input = this.getClass().getResourceAsStream("/resources/" + resource); - if (input == null) { - // this is how we load file within editor (eg eclipse) - input = this.getClass().getClassLoader().getResourceAsStream(resource); - } - - submodel = loadSubmodel(input); - - submodel.setExecutor(pcfWorkflow); - - submodel.addProperties("tableName", "pcf_aspect"); - } - - @Override public Submodel submodel() { return submodel; } From addcb7212718821d1b70d2b888af477d30a24ca5 Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Fri, 20 Oct 2023 11:08:48 +0530 Subject: [PATCH 09/23] Correct dataplane endpoint for digital twin --- modules/sde-core/src/main/resources/application.properties | 1 + .../sde/digitaltwins/facilitator/DigitalTwinsUtility.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/sde-core/src/main/resources/application.properties b/modules/sde-core/src/main/resources/application.properties index 0267e6535..bd6537192 100644 --- a/modules/sde-core/src/main/resources/application.properties +++ b/modules/sde-core/src/main/resources/application.properties @@ -75,6 +75,7 @@ edc.managementpath=/data/v2 edc.apiKeyHeader= edc.apiKey= edc.dsp.endpointpath=/api/v1/dsp +edc.dataplane.endpointpath=/api/public ## EDC Consumer edc.consumer.hostname= diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java index ab57cc6a7..bb0d47de1 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java @@ -62,6 +62,9 @@ public class DigitalTwinsUtility { @Value(value = "${edc.hostname}${edc.dsp.endpointpath:/api/v1/dsp}") public String digitalTwinEdcDspEndpoint; + @Value(value = "${edc.hostname}${edc.dataplane.endpointpath:/api/public}") + public String digitalTwinEdcDataplaneEndpoint; + ObjectMapper mapper = new ObjectMapper(); private static final Map> publicReadableSpecificAssetIDs = Map.of(MANUFACTURER_PART_ID, @@ -112,7 +115,7 @@ public List prepareDtEndpoint(String shellId, String submodelIdentific List endpoints = new ArrayList<>(); endpoints.add(Endpoint.builder().endpointInterface(CommonConstants.INTERFACE) .protocolInformation(ProtocolInformation.builder() - .endpointAddress(digitalTwinEdcDspEndpoint + CommonConstants.SUBMODEL_CONTEXT_URL) + .endpointAddress(digitalTwinEdcDataplaneEndpoint + CommonConstants.SUBMODEL_CONTEXT_URL) .endpointProtocol(CommonConstants.HTTP) .endpointProtocolVersion(List.of(CommonConstants.ENDPOINT_PROTOCOL_VERSION)) .subProtocol(CommonConstants.SUB_PROTOCOL) From 82a56d718b90b45de42f20ffc360fdf5ac6ce3fd Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Fri, 20 Oct 2023 13:16:00 +0530 Subject: [PATCH 10/23] remove submodel path from twin --- .../sde/digitaltwins/facilitator/DigitalTwinsUtility.java | 2 +- .../edc/entities/request/asset/AssetEntryRequestFactory.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java index bb0d47de1..dc870bd02 100644 --- a/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java +++ b/modules/sde-external-services/digital-twins/src/main/java/org/eclipse/tractusx/sde/digitaltwins/facilitator/DigitalTwinsUtility.java @@ -115,7 +115,7 @@ public List prepareDtEndpoint(String shellId, String submodelIdentific List endpoints = new ArrayList<>(); endpoints.add(Endpoint.builder().endpointInterface(CommonConstants.INTERFACE) .protocolInformation(ProtocolInformation.builder() - .endpointAddress(digitalTwinEdcDataplaneEndpoint + CommonConstants.SUBMODEL_CONTEXT_URL) + .endpointAddress(digitalTwinEdcDataplaneEndpoint) .endpointProtocol(CommonConstants.HTTP) .endpointProtocolVersion(List.of(CommonConstants.ENDPOINT_PROTOCOL_VERSION)) .subProtocol(CommonConstants.SUB_PROTOCOL) diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java index d2c0fcacf..b46e7456e 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java @@ -77,7 +77,7 @@ private AssetEntryRequest buildAsset(String submodel, String shellId, String sub private String subModelPayloadUrl(String submodel, String uuid) { return UriComponentsBuilder .fromHttpUrl(dftHostname) - .path(submodel+"/public/") + .path("/"+submodel+"/public/") .path(uuid) .toUriString(); } From 5d87143b832ffbb78209956039f3f5157bb8136f Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Fri, 20 Oct 2023 13:52:47 +0530 Subject: [PATCH 11/23] Added oauth security for sde pulic api --- .../configuration/ApiHeaderAuthFilter.java | 71 ------------------- .../sde/configuration/SecurityConfig.java | 2 +- .../asset/AssetEntryRequestFactory.java | 34 ++++++--- 3 files changed, 26 insertions(+), 81 deletions(-) delete mode 100644 modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/ApiHeaderAuthFilter.java diff --git a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/ApiHeaderAuthFilter.java b/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/ApiHeaderAuthFilter.java deleted file mode 100644 index 6a1d5f512..000000000 --- a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/ApiHeaderAuthFilter.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2022, 2023 T-Systems International GmbH - * Copyright (c) 2022, 2023 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 governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.sde.configuration; - -import java.io.IOException; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.web.filter.GenericFilterBean; - -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.ServletRequest; -import jakarta.servlet.ServletResponse; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Configuration -public class ApiHeaderAuthFilter extends GenericFilterBean { - - @Value("${dft.apiKeyHeader}") - private String apiKeyHeader; - - @Value("${dft.apiKey}") - private String apiKeyValue; - - @Override - public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) - throws IOException, ServletException { - - var request = (HttpServletRequest) servletRequest; - var response = (HttpServletResponse) servletResponse; - - String authHeaderValue = request.getHeader(apiKeyHeader); - String url = request.getRequestURI(); - - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - - if (url.contains("/public") && !apiKeyValue.equals(authHeaderValue)) { - log.error("**** ApiHeaderAuthFilter genreated Unauthorized response for public api *****************"); - response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); - } else if(auth !=null && auth.getAuthorities()!=null && auth.getAuthorities().isEmpty()){ - log.error("**** ApiHeaderAuthFilter The resource/client is not allowed to access *****************"); - response.setStatus(HttpServletResponse.SC_FORBIDDEN); - } else { - filterChain.doFilter(servletRequest, servletResponse); - } - } -} \ No newline at end of file diff --git a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/SecurityConfig.java b/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/SecurityConfig.java index bed20debb..6f699dcc3 100644 --- a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/SecurityConfig.java +++ b/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/SecurityConfig.java @@ -54,7 +54,7 @@ @EnableMethodSecurity(prePostEnabled = true) public class SecurityConfig { - private static final String[] PUBLIC_URL = { "/ping", "/cache/**", "/*/public/**", "/api-docs/**", "/swagger-ui/**", + private static final String[] PUBLIC_URL = { "/ping", "/cache/**", "/api-docs/**", "/swagger-ui/**", "*/swagger-ui/**", "/actuator/health/readiness", "/actuator/health/liveness", "/v3/api-docs/**" }; @Value("${keycloak.clientid}") diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java index b46e7456e..e495d7fe4 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/entities/request/asset/AssetEntryRequestFactory.java @@ -43,14 +43,24 @@ public class AssetEntryRequestFactory { @Value(value = "${dft.apiKeyHeader}") private String apiKeyHeader; + @Value(value = "${dft.apiKey}") private String apiKey; + @Value(value = "${dft.hostname}") private String dftHostname; + @Value(value = "${manufacturerId}") private String manufacturerId; + @Value(value = "${edc.hostname}") private String edcEndpoint; + + @Value(value = "${spring.security.oauth2.resourceserver.jwt.issuer-uri}/protocol/openid-connect/token") + private String idpIssuerTokenURL; + + @Value(value = "${digital-twins.authentication.clientId}") + private String clientId; public AssetEntryRequest getAssetRequest(String submodel, String assetName, String shellId, String subModelId, String uuid) { @@ -99,14 +109,20 @@ private HashMap getAssetProperties(String assetId, String assetN return assetProperties; } - private HashMap getDataAddressProperties(String shellId, String subModelId, String endpoint) { - HashMap dataAddressProperties = new HashMap<>(); - dataAddressProperties.put("type", TYPE); - dataAddressProperties.put("baseUrl", String.format(endpoint, shellId, subModelId)); - dataAddressProperties.put("name", NAME); - dataAddressProperties.put("authKey", apiKeyHeader); - dataAddressProperties.put("authCode", apiKey); - return dataAddressProperties; - } + private HashMap getDataAddressProperties(String shellId, String subModelId, String endpoint) { + HashMap dataAddressProperties = new HashMap<>(); + dataAddressProperties.put("type", TYPE); + dataAddressProperties.put("baseUrl", String.format(endpoint, shellId, subModelId)); + dataAddressProperties.put("name", NAME); + dataAddressProperties.put("oauth2:tokenUrl", idpIssuerTokenURL); + dataAddressProperties.put("oauth2:clientId", clientId); + dataAddressProperties.put("oauth2:clientSecretKey", "client-secret"); + dataAddressProperties.put("proxyMethod", "true"); + dataAddressProperties.put("proxyBody", "true"); + dataAddressProperties.put("proxyPath", "true"); + dataAddressProperties.put("proxyQueryParams", "true"); + dataAddressProperties.put("contentType", ASSET_PROP_CONTENT_TYPE); + return dataAddressProperties; + } } From 678361f4aed75bc6a42b23628b5f9903ad8fbc4c Mon Sep 17 00:00:00 2001 From: Sachin Argade <91305578+sachinargade123@users.noreply.github.com> Date: Mon, 23 Oct 2023 14:12:10 +0530 Subject: [PATCH 12/23] Update sdebuild.yml --- .github/workflows/sdebuild.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sdebuild.yml b/.github/workflows/sdebuild.yml index 859239e8f..6cfddd39d 100644 --- a/.github/workflows/sdebuild.yml +++ b/.github/workflows/sdebuild.yml @@ -22,7 +22,7 @@ name: sdebuild on: push: branches: - - 'update_twin_lookup_3.2' + - 'hotfix_3.2_with_pcf' tags: - 'v*.*.*' - 'v*.*.*-*' From 1bff180015d436e01f551ee1e9c53d823f1cfdbb Mon Sep 17 00:00:00 2001 From: adityagajbhiye9 <133367448+adityagajbhiye9@users.noreply.github.com> Date: Mon, 20 Nov 2023 15:33:12 +0530 Subject: [PATCH 13/23] [SDE_backend] rel-2.3.1 and Change log update ### Added - Added oauth security for sde public api. - BPN url add API path. ### Fixed - DT use refactor and PCF issue fix. - Correct dataplane endpoint for digital twin. - DSP endpoint path for digital-twin edc url. - trivy worklow fix. --- .github/workflows/sdebuild.yml | 83 ---------------------------------- .github/workflows/trivy.yml | 41 ++--------------- CHANGELOG.md | 13 +++++- INSTALL.md | 2 +- build/Dockerfile | 5 +- 5 files changed, 18 insertions(+), 126 deletions(-) delete mode 100644 .github/workflows/sdebuild.yml diff --git a/.github/workflows/sdebuild.yml b/.github/workflows/sdebuild.yml deleted file mode 100644 index 6cfddd39d..000000000 --- a/.github/workflows/sdebuild.yml +++ /dev/null @@ -1,83 +0,0 @@ -################################################################################# -# Copyright (c) 2022,2023 T-Systems International GmbH -# Copyright (c) 2022,2023 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 governing permissions and limitations -# under the License. -# -# SPDX-License-Identifier: Apache-2.0 -################################################################################ -name: sdebuild - -on: - push: - branches: - - 'hotfix_3.2_with_pcf' - tags: - - 'v*.*.*' - - 'v*.*.*-*' - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - build-and-push-image: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up JDK 18 - uses: actions/setup-java@v3 - with: - java-version: '18' - distribution: 'temurin' - - - name: Build - run: mvn -B package - - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - # Create SemVer or ref tags dependent of trigger event - - name: Docker meta - id: meta - uses: docker/metadata-action@v4 - with: - images: | - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=semver,pattern={{version}},value=v2.1.2 - flavor: | - latest=true - - - name: Build and push Docker image - uses: docker/build-push-action@v2 - with: - context: . - file: ./build/Dockerfile - push: true - # build tag :main - tags: ${{ steps.meta.outputs.tags }} - # build tag :latest - # tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index 97a5bafa7..184239f2b 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -28,34 +28,8 @@ on: # Trigger manually jobs: - analyze-config: - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Run Trivy vulnerability scanner in repo mode - uses: aquasecurity/trivy-action@master - with: - scan-type: "config" - exit-code: "1" - hide-progress: false - format: "sarif" - output: "trivy-results1.sarif" - severity: "CRITICAL,HIGH" - - name: Upload Trivy scan results to GitHub Security tab - uses: github/codeql-action/upload-sarif@v2 - if: always() - with: - sarif_file: "trivy-results1.sarif" - - analyze-product-dft-backend: + analyze-config: runs-on: ubuntu-latest permissions: actions: read @@ -63,23 +37,16 @@ jobs: security-events: write steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Run Trivy vulnerability scanner - if: always() - uses: aquasecurity/trivy-action@master + uses: aquasecurity/trivy-action@0.12.0 with: # Path to Docker image image-ref: "tractusx/managed-simple-data-exchanger-backend:latest" format: "sarif" output: "trivy-results.sarif" - exit-code: "1" - severity: "CRITICAL,HIGH" + vuln-type: "os,library" - name: Upload Trivy scan results to GitHub Security tab - if: always() uses: github/codeql-action/upload-sarif@v2 with: - sarif_file: "trivy-results.sarif" - + sarif_file: "trivy-results.sarif" \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a4c43d1c..2de3f45d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +## [2.3.0] - 2023-11-20 +### Added +- Added oauth security for sde public api. +- BPN url add API path. +### Fixed +- DT use refactor and PCF issue fix. +- Correct dataplane endpoint for digital twin. +- DSP endpoint path for digital-twin edc url. +- trivy worklow fix. + ## [2.2.0] - 2023-09-20 ### Added - Pcf model schema and model registration. @@ -224,7 +234,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Compliance with Catena-X Guidelines - Integration with Digital Twin registry service. -[unreleased]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.2.0...main +[unreleased]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.3.0...main +[2.3.0]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.2.0...v2.3.0 [2.2.0]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.1.1...v2.2.0 [2.1.1]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.1.0...v2.1.1 [2.1.0]: https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/compare/v2.0.11...v2.1.0 diff --git a/INSTALL.md b/INSTALL.md index bd6ae0754..4db632eea 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -28,7 +28,7 @@ For more details, please refer configuration section from [README.md](README.md) ### RUN SDE Backend Locally #### Prerequisites - JDK18 -- Postgres 11.9.13 +- Postgres 13.2.11 #### Steps 1. Clone the GitHub Repository - https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend. diff --git a/build/Dockerfile b/build/Dockerfile index 07f2d414f..261240b97 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -26,9 +26,6 @@ COPY ../pom.xml ./pom.xml # copy your other files COPY ../modules ./modules -# build for release -RUN mvn clean install - # our final base image FROM eclipse-temurin:19-jdk-jammy @@ -52,6 +49,6 @@ WORKDIR /home/user/sdeuser/sdeapp COPY --from=build modules/sde-core/target/*.jar ./app.jar EXPOSE 8080 -# set the startup command to run your binary +# set the startup command to run your binary CMD ["java", "-jar", "./app.jar","--spring.config.location=file:/app/configuration.properties"] From ed88ffea13dde41be43b19ef0300dba3c4348e47 Mon Sep 17 00:00:00 2001 From: adityagajbhiye9 <133367448+adityagajbhiye9@users.noreply.github.com> Date: Tue, 21 Nov 2023 12:15:03 +0530 Subject: [PATCH 14/23] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2de3f45d7..aecc2f539 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -## [2.3.0] - 2023-11-20 +## [2.3.0] - 2023-11-21 ### Added - Added oauth security for sde public api. - BPN url add API path. From bc3db95ff01d8a11941a55d80c8249f92522bbba Mon Sep 17 00:00:00 2001 From: adityagajbhiye9 <133367448+adityagajbhiye9@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:21:33 +0530 Subject: [PATCH 15/23] Updated Readme --- README.md | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c0343eaa7..3369abaf3 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,25 @@ Listed below are configuration keys needed to get the `sde-backend` up and runni | connector.discovery.clientId | X | default | client ID for connector discovery | | connector.discovery.clientSecret | X | default | password for connector discovery | | portal.backend.hostname | X | default | Portal backend svc URL based on BPN| -| springdoc.api-docs.path | X | /api-docs | swagger API path | +| springdoc.api-docs.path | X | default | swagger API path | +| bpndiscovery.hostname | X | default | bpn discovery hostname | +| discovery.authentication.url | X | default | discovery authentication url | +| discovery.clientId | X | default | discovery clientId | +| discovery.clientSecret | X | default | discovery clientSecret | +| discovery.grantType | X | default | discovery grantType | +| edc.consumer.protocol.path | X | default | | +| edc.consumer.managementpath | X | default | | +| edc.managementpath | X | default | | +| partner.pool.hostname | X | default | | +| partner.pool.authentication.url | X | default | | +| partner.pool.clientId | X | default | | +| partner.pool.clientSecret | X | default | | +| partner.pool.grantType | X | default | | +| portal.backend.hostname | X | default | | +| portal.backend.authentication.url | X | default | | +| portal.backend.clientId | X | default | | +| portal.backend.clientSecret | X | default | | +| portal.backend.grantType | X | default | | #### Example Configuration/application.properties @@ -170,6 +188,24 @@ portal.backend.authentication.url=default portal.backend.clientId=default portal.backend.clientSecret=default portal.backend.grantType=default +bpndiscovery.hostname=default +discovery.authentication.url=default +discovery.clientId=default +discovery.clientSecret=default +discovery.grantType=default +edc.consumer.protocol.path=default +edc.consumer.managementpath=default +edc.managementpath=default +partner.pool.hostname=default +partner.pool.authentication.url=default +partner.pool.clientId=default +partner.pool.clientSecret=default +partner.pool.grantType=default +portal.backend.hostname=default +portal.backend.authentication.url=default +portal.backend.clientId=default +portal.backend.clientSecret=default +portal.backend.grantType=default ``` The above configuration we can use as for different deployment as specified here [InstallationGuide.md](InstallationGuide.md) From 3bfb7e8b4ab95201082dca2b1d9276c51f21bd58 Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Tue, 21 Nov 2023 16:27:12 +0530 Subject: [PATCH 16/23] Use jdk 17 for trivy issues --- README.md | 26 +++++++++++++------------- pom.xml | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3369abaf3..479ab6099 100644 --- a/README.md +++ b/README.md @@ -62,12 +62,15 @@ Listed below are configuration keys needed to get the `sde-backend` up and runni | digital-twins.authentication.clientSecret | X | your secrete | Digital twin registry secrete | | digital-twins.authentication.grantType | X | client_credentials | Default value, no need to change | | edc.hostname | X | https://example.provider-connector.com | Your EDC provider connector url | +| edc.managementpath | X | default | edc provider management path | | edc.apiKeyHeader | X | x-api-key | Your connector api key | | edc.apiKey | X | yourpass | Your connector apikey value | | edc.consumer.hostname | X | https://example.consumer-connector.com | Your EDC consumer connector | | edc.consumer.apikeyheader | X | x-api-key | Your connector api key | | edc.consumer.apikey | X | yourpass | Your connector apikey value | | edc.consumer.datauri | X | /api/v1/ids/data | IDS endpoint path | +| edc.consumer.protocol.path | X | default | edc consumer protocol path | +| edc.consumer.managementpath | X | default | edc consumer management path | | dft.hostname | X | https://example.sdehost.com | Your SDE hostname | | dft.apiKeyHeader | X | API_KEY | Your default key | | dft.apiKey | X | yourpass | Your default key password | @@ -83,19 +86,16 @@ Listed below are configuration keys needed to get the `sde-backend` up and runni | discovery.clientId | X | default | discovery clientId | | discovery.clientSecret | X | default | discovery clientSecret | | discovery.grantType | X | default | discovery grantType | -| edc.consumer.protocol.path | X | default | | -| edc.consumer.managementpath | X | default | | -| edc.managementpath | X | default | | -| partner.pool.hostname | X | default | | -| partner.pool.authentication.url | X | default | | -| partner.pool.clientId | X | default | | -| partner.pool.clientSecret | X | default | | -| partner.pool.grantType | X | default | | -| portal.backend.hostname | X | default | | -| portal.backend.authentication.url | X | default | | -| portal.backend.clientId | X | default | | -| portal.backend.clientSecret | X | default | | -| portal.backend.grantType | X | default | | +| partner.pool.hostname | X | default | partner pool hostname | +| partner.pool.authentication.url | X | default | partner pool authentication url | +| partner.pool.clientId | X | default | partner pool clientId | +| partner.pool.clientSecret | X | default | partner pool clientSecret | +| partner.pool.grantType | X | default | partner pool grantType | +| portal.backend.hostname | X | default | portal backend hostname | +| portal.backend.authentication.url | X | default | portal authentication url | +| portal.backend.clientId | X | default | portal clientId | +| portal.backend.clientSecret | X | default | portal clientSecret | +| portal.backend.grantType | X | default | portal grantType | #### Example Configuration/application.properties diff --git a/pom.xml b/pom.xml index 5570f0fbc..68b8cc014 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ SDE for CatenaX - 18 + 17 2.17.1 2022.0.3 1.4.2.Final From 5ecd4e86d3f7f4bcc34a3e5f870c3646f4e10a66 Mon Sep 17 00:00:00 2001 From: adityagajbhiye9 <133367448+adityagajbhiye9@users.noreply.github.com> Date: Tue, 21 Nov 2023 16:31:29 +0530 Subject: [PATCH 17/23] Docker image update - image update and trivy vulernablities fixes. --- INSTALL.md | 2 +- README.md | 2 +- build/Dockerfile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 4db632eea..5cfb367ff 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -27,7 +27,7 @@ For more details, please refer configuration section from [README.md](README.md) ``` ### RUN SDE Backend Locally #### Prerequisites -- JDK18 +- JDK17 - Postgres 13.2.11 #### Steps diff --git a/README.md b/README.md index 479ab6099..bb27cd5ab 100644 --- a/README.md +++ b/README.md @@ -365,7 +365,7 @@ Eclipse Tractus-X product(s) installed within the image: - Project license: [Apache License, Version 2.0] https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend/blob/main/LICENSE **Used base image** -- [eclipse-temurin:19-jdk-jammy](https://github.com/adoptium/containers) +- [eclipse-temurin:17.0.9_9-jdk-jammy](https://github.com/adoptium/containers) - Official Eclipse Temurin DockerHub page: https://hub.docker.com/_/eclipse-temurin - Eclipse Temurin Project: https://projects.eclipse.org/projects/adoptium.temurin - Additional information about the Eclipse Temurin images: https://github.com/docker-library/repo-info/tree/master/repos/eclipse-temurin diff --git a/build/Dockerfile b/build/Dockerfile index 261240b97..265c02734 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -28,7 +28,7 @@ COPY ../modules ./modules # our final base image -FROM eclipse-temurin:19-jdk-jammy +FROM eclipse-temurin:17.0.9_9-jdk-jammy ARG USERNAME=sdeuser ARG USER_UID=1001 From c8782348c50d67ce8b0845cdba43654ae5de63a4 Mon Sep 17 00:00:00 2001 From: Sachin Argade Date: Tue, 21 Nov 2023 16:46:47 +0530 Subject: [PATCH 18/23] revert pcf sumodel changes --- .../sde/submodels/pcf/PcfSubmodel.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/PcfSubmodel.java b/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/PcfSubmodel.java index 6f6bb3db0..9bb32b62c 100644 --- a/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/PcfSubmodel.java +++ b/modules/sde-submodules/pcf/src/main/java/org/eclipse/tractusx/sde/submodels/pcf/PcfSubmodel.java @@ -19,14 +19,42 @@ ********************************************************************************/ package org.eclipse.tractusx.sde.submodels.pcf; +import java.io.InputStream; + +import org.eclipse.tractusx.sde.common.extensions.SubmodelExtension; import org.eclipse.tractusx.sde.common.model.Submodel; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import jakarta.annotation.PostConstruct; + @Component -public class PcfSubmodel { +public class PcfSubmodel extends SubmodelExtension { private Submodel submodel = null; + @Autowired + private PcfExecutor pcfWorkflow; + + @PostConstruct + public void init() { + + String resource = "pcf.json"; + // this is the path within the jar file + InputStream input = this.getClass().getResourceAsStream("/resources/" + resource); + if (input == null) { + // this is how we load file within editor (eg eclipse) + input = this.getClass().getClassLoader().getResourceAsStream(resource); + } + + submodel = loadSubmodel(input); + + submodel.setExecutor(pcfWorkflow); + + submodel.addProperties("tableName", "pcf_aspect"); + } + + @Override public Submodel submodel() { return submodel; } From 16f044ee37f1826571d00e248655c7290133ed18 Mon Sep 17 00:00:00 2001 From: adityagajbhiye9 <133367448+adityagajbhiye9@users.noreply.github.com> Date: Wed, 22 Nov 2023 10:40:59 +0530 Subject: [PATCH 19/23] User-id Changes for docker file. --- build/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Dockerfile b/build/Dockerfile index 265c02734..70ca54a08 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -31,7 +31,7 @@ COPY ../modules ./modules FROM eclipse-temurin:17.0.9_9-jdk-jammy ARG USERNAME=sdeuser -ARG USER_UID=1001 +ARG USER_UID=101 ARG USER_GID=$USER_UID # Create the user From 5acca921d422d5b2f33ec7287e2441f6ca094971 Mon Sep 17 00:00:00 2001 From: adityagajbhiye9 <133367448+adityagajbhiye9@users.noreply.github.com> Date: Wed, 22 Nov 2023 12:10:54 +0530 Subject: [PATCH 20/23] updated postgres chart version --- INSTALL.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 5cfb367ff..a7bf48033 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -28,12 +28,12 @@ For more details, please refer configuration section from [README.md](README.md) ### RUN SDE Backend Locally #### Prerequisites - JDK17 -- Postgres 13.2.11 +- Postgres 12.12.10 #### Steps 1. Clone the GitHub Repository - https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend. 2. Get your instance of postgres running (Create **dftdb** new database). -3. Setup your project environment to JDK 18. +3. Setup your project environment to JDK 17. 4. Provide require application configuration in application.properties as specified in step configuration.properties. 5. Start the SDE spring boot application from your IDE using main class or use spring CLI. From 2b6317010d48f7a71b155e71845c25813cad4c37 Mon Sep 17 00:00:00 2001 From: adityagajbhiye9 <133367448+adityagajbhiye9@users.noreply.github.com> Date: Wed, 22 Nov 2023 13:56:55 +0530 Subject: [PATCH 21/23] Removed r --- build/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index 70ca54a08..409da072d 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -31,12 +31,12 @@ COPY ../modules ./modules FROM eclipse-temurin:17.0.9_9-jdk-jammy ARG USERNAME=sdeuser -ARG USER_UID=101 +ARG USER_UID=1001 ARG USER_GID=$USER_UID # Create the user -RUN useradd -rm -d /home/sdeuser -s /bin/bash -u $USER_UID -U $USERNAME +RUN useradd -m -d /home/sdeuser -s /bin/bash -u $USER_UID -U $USERNAME USER $USERNAME From 090ff08109032c519be5a7689c6197925eb485df Mon Sep 17 00:00:00 2001 From: adityagajbhiye9 <133367448+adityagajbhiye9@users.noreply.github.com> Date: Thu, 23 Nov 2023 10:22:59 +0530 Subject: [PATCH 22/23] updated notice.md --- NOTICE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NOTICE.md b/NOTICE.md index 8d5f49436..788f18cee 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -29,7 +29,7 @@ SPDX-License-Identifier: Apache-2.0 The project maintains the following source code repositories in the GitHub organization https://github.com/eclipse-tractusx: -* https://github.com/eclipse-tractusx/dft-backend +* https://github.com/eclipse-tractusx/managed-simple-data-exchanger-backend ## Third-party Content From a75d572becc77a3135ec843cdebf2c23e993bcb7 Mon Sep 17 00:00:00 2001 From: ChetanT-System Date: Thu, 23 Nov 2023 12:05:36 +0530 Subject: [PATCH 23/23] Fixes #70 --- .../src/main/resources/assemblyPartRelationship.csv | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/sde-submodules/assembly-part-relationship/src/main/resources/assemblyPartRelationship.csv b/modules/sde-submodules/assembly-part-relationship/src/main/resources/assemblyPartRelationship.csv index 348f83116..a37f43a59 100644 --- a/modules/sde-submodules/assembly-part-relationship/src/main/resources/assemblyPartRelationship.csv +++ b/modules/sde-submodules/assembly-part-relationship/src/main/resources/assemblyPartRelationship.csv @@ -1,3 +1,3 @@ -parent_uuid;parent_part_instance_id;parent_manufacturer_part_id;parent_optional_identifier_key;parent_optional_identifier_value;uuid;part_instance_id;manufacturer_part_id;optional_identifier_key;optional_identifier_value;lifecycle_context;quantity_number;measurement_unit_lexical_value;datatype_URI;assembled_on -urn:uuid:8eea5f45-0823-48ce-a4fc-c3bf1cdfa4c2;NO-159040131155901488695555;37754B7-01;;;urn:uuid:f7cf62fe-9e25-472b-9148-66ebcc291f31;NO-056604022229087145032390;98801V5-17;;;AsBuilt;0.1908;kilogram;urn:bamm:io.openmanufacturing:meta-model:1.0.0#kilogram;2022-02-03T14:48:54.709Z -urn:uuid:1ae94880-e6b0-4bf3-ab74-8148b63c0640;NO-628797496367807957077777;65847F9-02;;;urn:uuid:186359fb-4584-40e4-a59b-ed842d3d80d9;NO-565359302028822441908953;74268H5-13;;;AsBuilt;0.1908;kilogram;urn:bamm:io.openmanufacturing:meta-model:1.0.0#kilogram;2022-02-03T14:48:54.709Z \ No newline at end of file +parent_uuid;parent_part_instance_id;parent_manufacturer_part_id;parent_optional_identifier_key;parent_optional_identifier_value;uuid;part_instance_id;manufacturer_part_id;optional_identifier_key;optional_identifier_value;quantity_number;measurement_unit;created_on;last_modified_on +urn:uuid:8eea5f45-0823-48ce-a4fc-c3bf1cdfa4c2;NO-159040131155901488695555;37754B7-01;;;urn:uuid:f7cf62fe-9e25-472b-9148-66ebcc291f31;NO-056604022229087145032390;98801V5-17;;;0.1908;kilogram;2022-02-03T14:48:54.709Z;2022-02-03T14:48:54.709Z +urn:uuid:1ae94880-e6b0-4bf3-ab74-8148b63c0640;NO-628797496367807957077777;65847F9-02;;;urn:uuid:186359fb-4584-40e4-a59b-ed842d3d80d9;NO-565359302028822441908953;74268H5-13;;;0.1908;kilogram;2022-02-03T14:48:54.709Z;2022-02-03T14:48:54.709Z \ No newline at end of file