From 311a5862e261167ae752da4015008da154e222a0 Mon Sep 17 00:00:00 2001 From: ChetanT-System Date: Mon, 1 Apr 2024 21:33:54 +0530 Subject: [PATCH 1/5] - PCF exchange code changes --- modules/README.md | 1 + modules/pcf-exchange/README.md | 15 ++ modules/pcf-exchange/pom.xml | 99 ++++++++ .../entity/PcfJsonToStringConvertor.java | 46 ++++ .../pcfexchange/entity/PcfRequestEntity.java | 69 ++++++ .../pcfexchange/entity/PcfResponseEntity.java | 56 +++++ .../enums/PCFRequestStatusEnum.java | 43 ++++ .../sde/pcfexchange/enums/PCFTypeEnum.java | 26 +++ .../enums/PCFTypeEnumFormator.java | 45 ++++ .../pcfexchange/mapper/PcfExchangeMapper.java | 37 +++ .../pcfexchange/proxy/PCFExchangeProxy.java | 50 ++++ .../repository/PcfReqsponseRepository.java | 31 +++ .../repository/PcfRequestRepository.java | 45 ++++ .../pcfexchange/request/PcfRequestModel.java | 57 +++++ .../response/PcfExchangeResponse.java | 44 ++++ .../service/IPCFExchangeService.java | 47 ++++ .../AsyncPushPCFDataForApproveRequest.java | 142 +++++++++++ .../service/impl/PCFRepositoryService.java | 149 ++++++++++++ .../service/impl/PcfExchangeServiceImpl.java | 220 ++++++++++++++++++ .../service/impl/ProxyRequestInterface.java | 163 +++++++++++++ modules/sde-core/pom.xml | 6 + .../configuration/EnumMappingAppConfig.java | 40 ++++ .../controller/PcfExchangeController.java | 127 ++++++++++ .../sde/edc/util/EDCAssetUrlCacheService.java | 49 +++- pom.xml | 2 + 25 files changed, 1600 insertions(+), 9 deletions(-) create mode 100644 modules/pcf-exchange/README.md create mode 100644 modules/pcf-exchange/pom.xml create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/entity/PcfJsonToStringConvertor.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/entity/PcfRequestEntity.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/entity/PcfResponseEntity.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/enums/PCFRequestStatusEnum.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/enums/PCFTypeEnum.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/enums/PCFTypeEnumFormator.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/mapper/PcfExchangeMapper.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/proxy/PCFExchangeProxy.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/repository/PcfReqsponseRepository.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/repository/PcfRequestRepository.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/request/PcfRequestModel.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/response/PcfExchangeResponse.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/IPCFExchangeService.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/AsyncPushPCFDataForApproveRequest.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PCFRepositoryService.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PcfExchangeServiceImpl.java create mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/ProxyRequestInterface.java create mode 100644 modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/EnumMappingAppConfig.java create mode 100644 modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/controller/PcfExchangeController.java diff --git a/modules/README.md b/modules/README.md index 7bc540739..130261c9e 100644 --- a/modules/README.md +++ b/modules/README.md @@ -24,3 +24,4 @@ SDE backend splited into multiple services loosely-coupled Maven modules. - modules/sde-submodules/single-level-bom-as-planned - modules/sde-submodules/pcf - modules/sde-usecases/traceability +- modules/pcf-exchange \ No newline at end of file diff --git a/modules/pcf-exchange/README.md b/modules/pcf-exchange/README.md new file mode 100644 index 000000000..5c3a65a8b --- /dev/null +++ b/modules/pcf-exchange/README.md @@ -0,0 +1,15 @@ +# PCF Exchange (SDE Maven module) +--- +## Description + +PCF**(Product Carbon Footprint)** exchange module use for exchange the PCF data/value as per consumer request and provide the pcf data to the consumer. + +This module has provided code changes as per below pcf exchange kit specification. PCF exchanges has external services calls like dDTR, EDC services. + +https://eclipse-tractusx.github.io/docs-kits/category/pcf-exchange-kit + + +##### External service dependency : +- dDTR service. +- EDC Service. +- BPN Discovery. \ No newline at end of file diff --git a/modules/pcf-exchange/pom.xml b/modules/pcf-exchange/pom.xml new file mode 100644 index 000000000..215638996 --- /dev/null +++ b/modules/pcf-exchange/pom.xml @@ -0,0 +1,99 @@ + + + 4.0.0 + + org.eclipse.tractusx + sde + 0.0.1 + ../../ + + pcf-exchange + pcf-exchange + pcf-exchange description + + + org.eclipse.tractusx + sde-common + 0.0.1 + + + + org.eclipse.tractusx + pcf + 0.0.1 + + + + org.eclipse.tractusx + portal + 0.0.1 + + + + org.eclipse.tractusx + edc + 0.0.1 + + + + org.eclipse.tractusx + digital-twins + 0.0.1 + + + + org.eclipse.tractusx + bpn-discovery + 0.0.1 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + ${lombok.version} + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.processor.version} + + + + + -Amapstruct.unmappedTargetPolicy=IGNORE + + + + + + + \ No newline at end of file diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/entity/PcfJsonToStringConvertor.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/entity/PcfJsonToStringConvertor.java new file mode 100644 index 000000000..87e5ffe2f --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/entity/PcfJsonToStringConvertor.java @@ -0,0 +1,46 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.pcfexchange.entity; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; +import lombok.SneakyThrows; + +@Converter +public class PcfJsonToStringConvertor implements AttributeConverter { + + ObjectMapper objectMapper = new ObjectMapper(); + + @Override + @SneakyThrows + public String convertToDatabaseColumn(JsonNode attribute) { + return attribute == null ? "{}" : attribute.toPrettyString(); + } + + @Override + @SneakyThrows + public JsonNode convertToEntityAttribute(String dbData) { + return dbData == null ? null : objectMapper.readTree(dbData); + } +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/entity/PcfRequestEntity.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/entity/PcfRequestEntity.java new file mode 100644 index 000000000..a03d70dc0 --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/entity/PcfRequestEntity.java @@ -0,0 +1,69 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.pcfexchange.entity; + +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnum; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.Data; + +@Table(name = "pcf_requests_tbl") +@Entity +@Data +public class PcfRequestEntity { + + @Id + @Column(name = "request_id") + private String requestId; + + @Column(name = "product_id") + private String productId; + + @Column(name = "bpn_number") + private String bpnNumber; + + @Column(name = "type") + @Enumerated(EnumType.STRING) + private PCFTypeEnum type; + + @Column(name = "message" , columnDefinition = "TEXT") + private String message; + + @Column(name = "status") + @Enumerated(EnumType.STRING) + private PCFRequestStatusEnum status; + + @Column(name = "requested_time") + private Long requestedTime; + + @Column(name = "last_updated_time") + private Long lastUpdatedTime; + + @Column(name = "remark" , columnDefinition = "TEXT") + private String remark; + +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/entity/PcfResponseEntity.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/entity/PcfResponseEntity.java new file mode 100644 index 000000000..c1b127503 --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/entity/PcfResponseEntity.java @@ -0,0 +1,56 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package org.eclipse.tractusx.sde.pcfexchange.entity; + +import com.fasterxml.jackson.databind.JsonNode; + +import jakarta.persistence.Column; +import jakarta.persistence.Convert; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Table(name = "pcf_response_tbl") +@Entity +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PcfResponseEntity { + + @Id + @Column(name = "response_id") + private String responseId; + + @Column(name = "request_id") + private String requestId; + + @Column(name = "pcf_data", columnDefinition = "TEXT") + @Convert(converter = PcfJsonToStringConvertor.class) + private JsonNode pcfData; + + @Column(name = "last_updated_time") + private Long lastUpdatedTime; + +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/enums/PCFRequestStatusEnum.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/enums/PCFRequestStatusEnum.java new file mode 100644 index 000000000..1c0997caa --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/enums/PCFRequestStatusEnum.java @@ -0,0 +1,43 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.pcfexchange.enums; + +public enum PCFRequestStatusEnum { + REQUESTED, + APPROVED, + + PUSHING_DATA, + PUSHING_UPDATED_DATA, + + REJECTED, + SENDING_REJECT_NOTIFICATION, + + PUSHED, + PUSHED_UPDATED_DATA, + + RECEIVED, + FAILED_TO_PUSH_DATA, + FAILED_TO_SEND_REJECT_NOTIFICATION, + FAILED, + + SENDING_REQUEST, + PENDING_DATA_FROM_PROVIDER +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/enums/PCFTypeEnum.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/enums/PCFTypeEnum.java new file mode 100644 index 000000000..d9ca97b09 --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/enums/PCFTypeEnum.java @@ -0,0 +1,26 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.pcfexchange.enums; + +public enum PCFTypeEnum { + CONSUMER, + PROVIDER +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/enums/PCFTypeEnumFormator.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/enums/PCFTypeEnumFormator.java new file mode 100644 index 000000000..d61cb6dac --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/enums/PCFTypeEnumFormator.java @@ -0,0 +1,45 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.pcfexchange.enums; + +import java.text.ParseException; +import java.util.Locale; + +import org.apache.commons.lang3.EnumUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.format.Formatter; + +public class PCFTypeEnumFormator implements Formatter { + + @Override + public String print(PCFTypeEnum object, Locale locale) { + return null; + } + + @Override + public PCFTypeEnum parse(String text, Locale locale) throws ParseException { + if (StringUtils.isBlank(text)) { + return null; + } + + return EnumUtils.getEnum(PCFTypeEnum.class, text.toUpperCase()); + } +} \ No newline at end of file diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/mapper/PcfExchangeMapper.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/mapper/PcfExchangeMapper.java new file mode 100644 index 000000000..f7b969bcd --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/mapper/PcfExchangeMapper.java @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package org.eclipse.tractusx.sde.pcfexchange.mapper; + +import java.util.List; + +import org.eclipse.tractusx.sde.pcfexchange.entity.PcfRequestEntity; +import org.eclipse.tractusx.sde.pcfexchange.request.PcfRequestModel; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring") +public interface PcfExchangeMapper { + + PcfRequestModel mapFrom(PcfRequestEntity entiry); + + PcfRequestEntity mapFrom(PcfRequestModel pojo); + + List mapFrom(List entiry); + +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/proxy/PCFExchangeProxy.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/proxy/PCFExchangeProxy.java new file mode 100644 index 000000000..7f9a2e927 --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/proxy/PCFExchangeProxy.java @@ -0,0 +1,50 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.pcfexchange.proxy; + +import java.net.URI; +import java.util.Map; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; + +import com.fasterxml.jackson.databind.JsonNode; + +@FeignClient(name = "PCFExchangeProxy", url = "placeholder") +public interface PCFExchangeProxy { + + @PutMapping + public ResponseEntity uploadPcfSubmodel(URI url, @RequestHeader Map requestHeader, + @RequestParam(value = "BPN", required = true) String bpnNumber, + @RequestParam(value = "requestId", required = false) String requestId, + @RequestParam(value = "message", required = false) String message, @RequestBody JsonNode pcfData); + + @GetMapping + public ResponseEntity getPcfByProduct(URI url, @RequestHeader Map requestHeader, + @RequestParam(value = "BPN", required = true) String bpnNumber, + @RequestParam(value = "requestId", required = true) String requestId, @RequestParam String message); + +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/repository/PcfReqsponseRepository.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/repository/PcfReqsponseRepository.java new file mode 100644 index 000000000..d578384a0 --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/repository/PcfReqsponseRepository.java @@ -0,0 +1,31 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.pcfexchange.repository; + +import java.util.Optional; + +import org.eclipse.tractusx.sde.pcfexchange.entity.PcfResponseEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PcfReqsponseRepository extends JpaRepository { + + public Optional findFirstByRequestIdOrderByLastUpdatedTimeDesc(String requestId); +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/repository/PcfRequestRepository.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/repository/PcfRequestRepository.java new file mode 100644 index 000000000..c6edbfa62 --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/repository/PcfRequestRepository.java @@ -0,0 +1,45 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.pcfexchange.repository; + +import java.util.List; +import java.util.Optional; + +import org.eclipse.tractusx.sde.pcfexchange.entity.PcfRequestEntity; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnum; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PcfRequestRepository extends JpaRepository { + + Optional findByRequestIdAndProductIdAndBpnNumber(String requestId, String productId, + String bpnNumber); + + Page findByType(Pageable pageable, PCFTypeEnum type); + + Page findByTypeAndStatusIn(Pageable pageable, PCFTypeEnum type, List status); + + Page findByStatusAndTypeLikeOrderByLastUpdatedTimeDesc(PageRequest of, PCFRequestStatusEnum status, PCFTypeEnum type); + +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/request/PcfRequestModel.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/request/PcfRequestModel.java new file mode 100644 index 000000000..26d1da3af --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/request/PcfRequestModel.java @@ -0,0 +1,57 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.pcfexchange.request; + +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnum; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import jakarta.validation.constraints.NotBlank; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class PcfRequestModel { + + private String requestId; + + @NotBlank + private String productId; + + @NotBlank + private String bpnNumber; + + private PCFTypeEnum type; + private String message; + private String remark; + private PCFRequestStatusEnum status; + private Long requestedTime; + private Long lastUpdatedTime; + + +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/response/PcfExchangeResponse.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/response/PcfExchangeResponse.java new file mode 100644 index 000000000..e8d76527b --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/response/PcfExchangeResponse.java @@ -0,0 +1,44 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.pcfexchange.response; + +import org.eclipse.tractusx.sde.digitaltwins.entities.response.ShellDescriptorResponse; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnum; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class PcfExchangeResponse { + + private String message; + private PCFTypeEnum type; + private ShellDescriptorResponse shellDescriptorResponse; + +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/IPCFExchangeService.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/IPCFExchangeService.java new file mode 100644 index 000000000..10d84bcfb --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/IPCFExchangeService.java @@ -0,0 +1,47 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package org.eclipse.tractusx.sde.pcfexchange.service; + +import org.eclipse.tractusx.sde.common.model.PagingResponse; +import org.eclipse.tractusx.sde.edc.model.request.ConsumerRequest; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnum; +import org.eclipse.tractusx.sde.pcfexchange.request.PcfRequestModel; + +import com.fasterxml.jackson.databind.JsonNode; + +public interface IPCFExchangeService { + + public String actionOnPcfRequestAndSendNotificationToConsumer(PcfRequestModel pcfRequestModel); + + public Object requestForPcfDataExistingOffer(String productId, ConsumerRequest consumerRequest); + + public PcfRequestModel savePcfRequestData(String requestId, String productId, String bpnNumber, String message); + + public PagingResponse getPcfData(PCFRequestStatusEnum status, PCFTypeEnum type, Integer page, Integer pageSize); + + public void recievedPCFData(String productId, String bpnNumber, String requestId, String message, + JsonNode pcfData); + + public Object viewForPcfDataOffer(String requestId); + + public Object requestForPcfNotExistDataOffer(PcfRequestModel pcfRequestModel); + +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/AsyncPushPCFDataForApproveRequest.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/AsyncPushPCFDataForApproveRequest.java new file mode 100644 index 000000000..6a1169a2a --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/AsyncPushPCFDataForApproveRequest.java @@ -0,0 +1,142 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.pcfexchange.service.impl; + +import java.util.List; + +import org.eclipse.tractusx.sde.common.entities.PolicyModel; +import org.eclipse.tractusx.sde.common.exception.NoDataFoundException; +import org.eclipse.tractusx.sde.common.model.PagingResponse; +import org.eclipse.tractusx.sde.common.utils.PolicyOperationUtil; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnum; +import org.eclipse.tractusx.sde.pcfexchange.request.PcfRequestModel; +import org.eclipse.tractusx.sde.submodels.pcf.entity.PcfEntity; +import org.eclipse.tractusx.sde.submodels.pcf.service.PcfService; +import org.springframework.stereotype.Component; + +import com.google.gson.JsonObject; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Component +@RequiredArgsConstructor +@SuppressWarnings("unchecked") +public class AsyncPushPCFDataForApproveRequest { + + private final PCFRepositoryService pcfRepositoryService; + + private final PcfService pcfService; + + private final ProxyRequestInterface proxyRequestInterface; + + + public void pushPCFDataForApproveRequest(String processId, PolicyModel policy) { + + List accessBPNList = PolicyOperationUtil.getAccessBPNList(policy); + + List productList = pcfService.readCreatedTwins(processId).stream().map(PcfEntity::getProductId) + .toList(); + + markedPCFDataForPendingProviderRequestAsRequested(productList); + + PagingResponse pcfData = pcfRepositoryService.getPcfData( + List.of(PCFRequestStatusEnum.PUSHED, PCFRequestStatusEnum.PUSHED_UPDATED_DATA), PCFTypeEnum.PROVIDER, 0, + 1000); + List requestList = (List) pcfData.getItems(); + + if (!requestList.isEmpty()) { + + requestList.forEach(request -> { + + if (productList.contains(request.getProductId()) && accessBPNList.contains(request.getBpnNumber())) { + + String msg = ""; + + try { + request.setStatus(PCFRequestStatusEnum.PUSHING_UPDATED_DATA); + + JsonObject calculatedPCFValue = pcfService + .readCreatedTwinsDetailsByProductId(request.getProductId()).get("json") + .getAsJsonObject(); + + PCFRequestStatusEnum status = pcfRepositoryService.identifyRunningStatus(request.getRequestId(), + request.getStatus()); + + // push api call + Runnable runnable = () -> proxyRequestInterface.sendNotificationToConsumer(status, + calculatedPCFValue, request.getProductId(), request.getBpnNumber(), + request.getRequestId()); + + new Thread(runnable).start(); + + msg = "PCF request '" + request.getStatus() + + "' and asynchronously sending notification to consumer"; + + } catch (NoDataFoundException e) { + msg = "Unable to take action on PCF request becasue pcf calculated value does not exist, please provide/upload PCF value for " + + request.getProductId() + ", requestId " + request.getRequestId(); + log.error("Async PushPCFDataForApproveRequest" + msg); + throw new NoDataFoundException(msg); + } catch (Exception e) { + pcfRepositoryService.savePcfStatus(request.getRequestId(), PCFRequestStatusEnum.FAILED); + } + } + }); + } else { + log.debug("Async PushPCFDataForApproveRequest - No APPROVED request found"); + } + + } + + public void markedPCFDataForPendingProviderRequestAsRequested(List productList) { + + PagingResponse pcfData = pcfRepositoryService.getPcfData(List.of(PCFRequestStatusEnum.PENDING_DATA_FROM_PROVIDER), + PCFTypeEnum.PROVIDER, 0, 1000); + List requestList = (List) pcfData.getItems(); + + if (!requestList.isEmpty()) { + requestList.forEach(request -> { + if (productList.contains(request.getProductId())) { + String msg = ""; + try { + pcfService.readCreatedTwinsDetailsByProductId(request.getProductId()).get("json") + .getAsJsonObject(); + pcfRepositoryService.savePcfStatus(request.getRequestId(), PCFRequestStatusEnum.REQUESTED); + + } catch (NoDataFoundException e) { + msg = "Unable to markedPCFDataForPendingProviderRequestAsRequested becasue pcf calculated value does not exist " + + request.getProductId() + ", requestId " + request.getRequestId(); + log.error("Async PushPCFDataForApproveRequest" + msg); + throw new NoDataFoundException(msg); + } catch (Exception e) { + pcfRepositoryService.savePcfStatus(request.getRequestId(), PCFRequestStatusEnum.FAILED); + } + } + }); + } else { + log.debug("Async PushPCFDataForApproveRequest - No 'PENDING_DATA_FROM_PROVIDER' request found"); + } + + } +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PCFRepositoryService.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PCFRepositoryService.java new file mode 100644 index 000000000..4a51743ce --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PCFRepositoryService.java @@ -0,0 +1,149 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.pcfexchange.service.impl; + +import java.time.Instant; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.tractusx.sde.common.model.PagingResponse; +import org.eclipse.tractusx.sde.pcfexchange.entity.PcfRequestEntity; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnum; +import org.eclipse.tractusx.sde.pcfexchange.mapper.PcfExchangeMapper; +import org.eclipse.tractusx.sde.pcfexchange.repository.PcfRequestRepository; +import org.eclipse.tractusx.sde.pcfexchange.request.PcfRequestModel; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.stereotype.Component; + +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Component +@RequiredArgsConstructor +public class PCFRepositoryService { + + private static final String SUCCESS = "SUCCESS"; + private final PcfRequestRepository pcfRequestRepository; + private final PcfExchangeMapper pcfMapper; + + public PcfRequestModel savePcfRequestData(String requestId, String productId, String bpnNumber, String message, + PCFTypeEnum type, PCFRequestStatusEnum status, String remark) { + + PcfRequestModel pojo = PcfRequestModel.builder().requestId(requestId).productId(productId).bpnNumber(bpnNumber) + .status(status).message(message).type(type).requestedTime(Instant.now().getEpochSecond()) + .lastUpdatedTime(Instant.now().getEpochSecond()).remark(remark).build(); + + PcfRequestEntity entity = pcfMapper.mapFrom(pojo); + + return pcfMapper.mapFrom(pcfRequestRepository.save(entity)); + } + + public PCFRequestStatusEnum updatePCFPushStatus(PCFRequestStatusEnum status, String requestId, String sendNotificationStatus) { + + if ((PCFRequestStatusEnum.APPROVED.equals(status) || PCFRequestStatusEnum.PUSHING_DATA.equals(status)) + && SUCCESS.equalsIgnoreCase(sendNotificationStatus)) { + status = PCFRequestStatusEnum.PUSHED; + sendNotificationStatus ="PCF data successfuly pushed"; + } else if (PCFRequestStatusEnum.PUSHING_UPDATED_DATA.equals(status) + && SUCCESS.equalsIgnoreCase(sendNotificationStatus)) { + status = PCFRequestStatusEnum.PUSHED_UPDATED_DATA; + sendNotificationStatus ="PCF updated data successfuly pushed"; + } else if (PCFRequestStatusEnum.REJECTED.equals(status) && SUCCESS.equalsIgnoreCase(sendNotificationStatus)) { + status = PCFRequestStatusEnum.REJECTED; + sendNotificationStatus ="PCF request rejected successfuly"; + } else if (PCFRequestStatusEnum.APPROVED.equals(status) + || PCFRequestStatusEnum.FAILED_TO_PUSH_DATA.equals(status) + || PCFRequestStatusEnum.PUSHING_DATA.equals(status) + || PCFRequestStatusEnum.PUSHING_UPDATED_DATA.equals(status)) { + status = PCFRequestStatusEnum.FAILED_TO_PUSH_DATA; + } else if (PCFRequestStatusEnum.REJECTED.equals(status) + || PCFRequestStatusEnum.FAILED_TO_SEND_REJECT_NOTIFICATION.equals(status)) + status = PCFRequestStatusEnum.FAILED_TO_SEND_REJECT_NOTIFICATION; + else { + status = PCFRequestStatusEnum.FAILED; + } + + savePcfStatus(requestId, status, sendNotificationStatus); + + return status; + } + + public PCFRequestStatusEnum identifyRunningStatus(String requestId, PCFRequestStatusEnum status) { + + boolean isApproval = PCFRequestStatusEnum.APPROVED.equals(status) + || PCFRequestStatusEnum.FAILED_TO_PUSH_DATA.equals(status); + + boolean isRejection = PCFRequestStatusEnum.REJECTED.equals(status) + || PCFRequestStatusEnum.FAILED_TO_SEND_REJECT_NOTIFICATION.equals(status); + + if (isApproval) { + status = PCFRequestStatusEnum.PUSHING_DATA; + } else if (isRejection) { + status = PCFRequestStatusEnum.SENDING_REJECT_NOTIFICATION; + } + + savePcfStatus(requestId, status); + + return status; + } + + @SneakyThrows + public PcfRequestEntity savePcfStatus(String requestId, PCFRequestStatusEnum status) { + return savePcfStatus(requestId, status, null); + } + + @SneakyThrows + public PcfRequestEntity savePcfStatus(String requestId, PCFRequestStatusEnum status, String remark) { + + PcfRequestEntity pcfRequestEntity = pcfRequestRepository.getReferenceById(requestId); + pcfRequestEntity.setLastUpdatedTime(Instant.now().getEpochSecond()); + pcfRequestEntity.setStatus(status); + + if(StringUtils.isNotBlank(remark)) + pcfRequestEntity.setRemark(remark); + + log.info("'" + pcfRequestEntity.getProductId() + "' pcf request saved in the database successfully as {}", + status); + pcfRequestRepository.save(pcfRequestEntity); + return pcfRequestEntity; + + } + + public PagingResponse getPcfData(List status, PCFTypeEnum type, Integer page, Integer pageSize) { + + Page result = null; + if (status == null || status.isEmpty()) { + result = pcfRequestRepository.findByType(PageRequest.of(page, pageSize), type); + } else { + result = pcfRequestRepository.findByTypeAndStatusIn(PageRequest.of(page, pageSize), type, status); + } + + List requestList = result.stream().map(pcfMapper::mapFrom).toList(); + + return PagingResponse.builder().items(requestList).pageSize(result.getSize()).page(result.getNumber()) + .totalItems(result.getTotalElements()).build(); + } + +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PcfExchangeServiceImpl.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PcfExchangeServiceImpl.java new file mode 100644 index 000000000..54c09594d --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PcfExchangeServiceImpl.java @@ -0,0 +1,220 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package org.eclipse.tractusx.sde.pcfexchange.service.impl; + +import java.time.Instant; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.tractusx.sde.common.entities.PolicyModel; +import org.eclipse.tractusx.sde.common.exception.NoDataFoundException; +import org.eclipse.tractusx.sde.common.exception.ServiceException; +import org.eclipse.tractusx.sde.common.exception.ValidationException; +import org.eclipse.tractusx.sde.common.model.PagingResponse; +import org.eclipse.tractusx.sde.edc.model.request.ConsumerRequest; +import org.eclipse.tractusx.sde.edc.model.response.QueryDataOfferModel; +import org.eclipse.tractusx.sde.edc.util.EDCAssetUrlCacheService; +import org.eclipse.tractusx.sde.pcfexchange.entity.PcfResponseEntity; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnum; +import org.eclipse.tractusx.sde.pcfexchange.repository.PcfReqsponseRepository; +import org.eclipse.tractusx.sde.pcfexchange.request.PcfRequestModel; +import org.eclipse.tractusx.sde.pcfexchange.service.IPCFExchangeService; +import org.eclipse.tractusx.sde.submodels.pcf.service.PcfService; +import org.springframework.stereotype.Service; + +import com.fasterxml.jackson.databind.JsonNode; +import com.google.gson.JsonObject; + +import feign.FeignException; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +@RequiredArgsConstructor +public class PcfExchangeServiceImpl implements IPCFExchangeService { + + private final PCFRepositoryService pcfRepositoryService; + private final PcfReqsponseRepository pcfReqsponseRepository; + private final EDCAssetUrlCacheService edcAssetUrlCacheService; + private final PcfService pcfService; + private final ProxyRequestInterface proxyRequestInterface; + + @SneakyThrows + @Override + public String requestForPcfDataExistingOffer(String productId, ConsumerRequest consumerRequest) { + + StringBuilder sb = new StringBuilder(); + consumerRequest.getOffers().stream().forEach(offer -> { + + String requestId = UUID.randomUUID().toString(); + String providerBPNNumber = offer.getConnectorId(); + + String message = "Please provide PCF value for " + productId; + + pcfRepositoryService.savePcfRequestData(requestId, productId, providerBPNNumber, message, + PCFTypeEnum.CONSUMER, PCFRequestStatusEnum.SENDING_REQUEST, ""); + + QueryDataOfferModel queryDataOfferModel = QueryDataOfferModel.builder().assetId(offer.getAssetId()) + .offerId(offer.getOfferId()).policyId(offer.getPolicyId()).connectorId(providerBPNNumber) + .connectorOfferUrl(offer.getConnectorOfferUrl()) + .policy(PolicyModel.builder().usagePolicies(consumerRequest.getUsagePolicies()).build()).build(); + + proxyRequestInterface.requestToProviderForPCFValue(productId, sb, requestId, message, queryDataOfferModel, false); + }); + + return sb.toString(); + + } + + @Override + public Object requestForPcfNotExistDataOffer(PcfRequestModel pcfRequestModel) { + StringBuilder sb = new StringBuilder(); + String requestId = UUID.randomUUID().toString(); + try { + pcfRepositoryService.savePcfRequestData(requestId, pcfRequestModel.getProductId(), + pcfRequestModel.getBpnNumber(), pcfRequestModel.getMessage(), PCFTypeEnum.CONSUMER, + PCFRequestStatusEnum.SENDING_REQUEST, ""); + + // 1 fetch EDC connectors and DTR Assets from EDC connectors + List pcfExchangeUrlOffers = edcAssetUrlCacheService + .getPCFExchangeUrlFromTwin(pcfRequestModel.getBpnNumber()); + + // 2 request for PCF value for non existing sub model and send notification to + // call provider for data + pcfExchangeUrlOffers.parallelStream().forEach(dtOffer -> proxyRequestInterface.requestToProviderForPCFValue( + pcfRequestModel.getProductId(), sb, requestId, pcfRequestModel.getMessage(), dtOffer, true)); + + } catch (FeignException e) { + log.error("FeignRequest requestForPcfNotExistDataOffer:" + e.request()); + String errorMsg = "Unable to request to data provider because: " + + (StringUtils.isBlank(e.contentUTF8()) ? e.getMessage() : e.contentUTF8()); + log.error("FeignException requestForPcfNotExistDataOffer: " + errorMsg); + } + + if (sb.isEmpty()) + throw new ValidationException("Not requested to provider for '" + pcfRequestModel.getProductId() + + "' because there is no PCF exchange endpoint found"); + + return sb.toString(); + } + + @SneakyThrows + @Override + public String actionOnPcfRequestAndSendNotificationToConsumer(PcfRequestModel pcfRequestModel) { + String remark = ""; + try { + + JsonObject calculatedPCFValue = pcfService + .readCreatedTwinsDetailsByProductId(pcfRequestModel.getProductId()).get("json").getAsJsonObject(); + + + PCFRequestStatusEnum status = pcfRepositoryService.identifyRunningStatus(pcfRequestModel.getRequestId(), + pcfRequestModel.getStatus()); + + // push api call + Runnable runnable = () -> proxyRequestInterface.sendNotificationToConsumer(status, + calculatedPCFValue, pcfRequestModel.getProductId(), pcfRequestModel.getBpnNumber(), + pcfRequestModel.getRequestId()); + + new Thread(runnable).start(); + + remark = "PCF push request accepted for '" + pcfRequestModel.getProductId() + + "' and asynchronously pushing notification to consumer"; + + } catch (NoDataFoundException e) { + remark = "Unable to take action on PCF request becasue PCF calculated value does not exist, please upload PCF value for " + + pcfRequestModel.getProductId() + " in systems using Manual/Recurring Upload"; + pcfRepositoryService.savePcfRequestData(pcfRequestModel.getRequestId(), pcfRequestModel.getProductId(), + pcfRequestModel.getBpnNumber(), pcfRequestModel.getMessage(), PCFTypeEnum.PROVIDER, + PCFRequestStatusEnum.FAILED, remark); + log.error(remark); + throw new ValidationException(e.getMessage()); + } catch (Exception e) { + pcfRepositoryService.savePcfStatus(pcfRequestModel.getRequestId(), PCFRequestStatusEnum.FAILED); + throw new ServiceException(e.getMessage()); + } + return remark; + } + + @Override + public PcfRequestModel savePcfRequestData(String requestId, String productId, String bpnNumber, String message) { + PCFRequestStatusEnum status = PCFRequestStatusEnum.REQUESTED; + String remark = ""; + try { + pcfService.readCreatedTwinsDetailsByProductId(productId).get("json").getAsJsonObject(); + } catch (NoDataFoundException e) { + String msg = "The PCF calculated value does not exist in system, please upload PCF value for '" + productId + + "' in systems using Manual/Recurring Upload"; + log.warn(msg); + remark = msg; + status = PCFRequestStatusEnum.PENDING_DATA_FROM_PROVIDER; + } + return pcfRepositoryService.savePcfRequestData(requestId, productId, bpnNumber, message, PCFTypeEnum.PROVIDER, + status, remark); + } + + @Override + public void recievedPCFData(String productId, String bpnNumber, String requestId, String message, + JsonNode pcfData) { + + PCFRequestStatusEnum status = PCFRequestStatusEnum.FAILED; + try { + status = PCFRequestStatusEnum.valueOf(message); + } catch (Exception e) { + log.error("Unable to find PCF value status " + e.getMessage()); + } + + PcfResponseEntity entity = PcfResponseEntity.builder().pcfData(pcfData).requestId(requestId) + .responseId(UUID.randomUUID().toString()).lastUpdatedTime(Instant.now().getEpochSecond()).build(); + + pcfReqsponseRepository.save(entity); + + if (PCFRequestStatusEnum.APPROVED.equals(status) || PCFRequestStatusEnum.PUSHING_DATA.equals(status) + || PCFRequestStatusEnum.PUSHING_UPDATED_DATA.equals(status)) { + status = PCFRequestStatusEnum.RECEIVED; + } + + pcfRepositoryService.savePcfStatus(requestId, status); + + } + + @Override + public PagingResponse getPcfData(PCFRequestStatusEnum status, PCFTypeEnum type, Integer page, Integer pageSize) { + List statusLs = null; + if (status != null) + statusLs = List.of(status); + return pcfRepositoryService.getPcfData(statusLs, type, page, pageSize); + } + + @Override + public PcfResponseEntity viewForPcfDataOffer(String requestId) { + Optional findById = pcfReqsponseRepository + .findFirstByRequestIdOrderByLastUpdatedTimeDesc(requestId); + if (!findById.isPresent()) + throw new NoDataFoundException("No data found uuid " + requestId); + return findById.get(); + } + +} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/ProxyRequestInterface.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/ProxyRequestInterface.java new file mode 100644 index 000000000..f76bca9db --- /dev/null +++ b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/ProxyRequestInterface.java @@ -0,0 +1,163 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package org.eclipse.tractusx.sde.pcfexchange.service.impl; + +import java.net.URI; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.tractusx.sde.common.mapper.JsonObjectMapper; +import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedByIdResponse; +import org.eclipse.tractusx.sde.edc.model.response.QueryDataOfferModel; +import org.eclipse.tractusx.sde.edc.util.EDCAssetUrlCacheService; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; +import org.eclipse.tractusx.sde.pcfexchange.proxy.PCFExchangeProxy; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import com.google.gson.JsonObject; + +import feign.FeignException; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Component +@RequiredArgsConstructor +public class ProxyRequestInterface { + + private static final String PRODUCT_IDS = "productIds"; + private static final String SLASH_DELIMETER = "/"; + private final PCFExchangeProxy pcfExchangeProxy; + private final PCFRepositoryService pcfRepositoryService; + private final EDCAssetUrlCacheService edcAssetUrlCacheService; + private final JsonObjectMapper jsonObjectMapper; + + @Value(value = "${manufacturerId}") + private String manufacturerId; + + @Value(value = "${digital-twins.managed.thirdparty:false}") + private boolean managedThirdParty; + + @SneakyThrows + public void requestToProviderForPCFValue(String productId, StringBuilder sb, String requestId, String message, + QueryDataOfferModel dataset, boolean isRequestToNonexistingTwin) { + + EDRCachedByIdResponse edrToken = edcAssetUrlCacheService.verifyAndGetToken(dataset.getConnectorId(), dataset); + + if (!sb.isEmpty()) + sb.append("\n"); + + if (edrToken != null) { + + URI pcfpushEnpoint = null; + + if(isRequestToNonexistingTwin) + pcfpushEnpoint = new URI( + edrToken.getEndpoint() + SLASH_DELIMETER + PRODUCT_IDS + SLASH_DELIMETER + productId); + else + pcfpushEnpoint = new URI(edrToken.getEndpoint()); + + Map header = new HashMap<>(); + header.put(edrToken.getAuthKey(), edrToken.getAuthCode()); + + // Send request to data provider for PCF value push + pcfExchangeProxy.getPcfByProduct(pcfpushEnpoint, header, manufacturerId, + requestId, message); + + sb.append(productId + ": requested for PCF value"); + pcfRepositoryService.savePcfStatus(requestId, PCFRequestStatusEnum.REQUESTED); + } else { + sb.append(productId + ": Unable to request for PCF value becasue the EDR token status is null"); + log.warn("EDC connector " + dataset.getConnectorOfferUrl() + ": {},{},{}", requestId, productId, + "Unable to request for PCF value becasue the EDR token status is null"); + pcfRepositoryService.savePcfStatus(requestId, PCFRequestStatusEnum.FAILED); + } + } + + @SneakyThrows + public void sendNotificationToConsumer(PCFRequestStatusEnum status, JsonObject calculatedPCFValue, + String productId, String bpnNumber, String requestId) { + + // 1 fetch EDC connectors and DTR Assets from EDC connectors + List pcfExchangeUrlOffers = edcAssetUrlCacheService.getPCFExchangeUrlFromTwin(bpnNumber); + + // 2 lookup shell for PCF sub model and send notification to call consumer + // request + if(pcfExchangeUrlOffers.isEmpty()) { + pcfRepositoryService.updatePCFPushStatus(status, requestId, "Unable to find PCF exchange endpoint"); + } + else { + pcfExchangeUrlOffers.parallelStream().forEach(dtOffer -> { + + if (PCFRequestStatusEnum.SENDING_REJECT_NOTIFICATION.equals(status)) { + sendNotification(null, productId, bpnNumber, requestId, dtOffer, status); + } else { + sendNotification(calculatedPCFValue, productId, bpnNumber, requestId, dtOffer, status); + } + + }); + } + } + + @SneakyThrows + private void sendNotification(JsonObject calculatedPCFValue, String productId, String bpnNumber, String requestId, + QueryDataOfferModel dtOffer, PCFRequestStatusEnum status) { + String sendNotificationStatus = ""; + try { + String message = status.name(); + + EDRCachedByIdResponse edrToken = edcAssetUrlCacheService.verifyAndGetToken(bpnNumber, dtOffer); + + if (edrToken != null) { + + URI pcfpushEnpoint = new URI( + edrToken.getEndpoint() + SLASH_DELIMETER + PRODUCT_IDS + SLASH_DELIMETER + productId); + + Map header = new HashMap<>(); + header.put(edrToken.getAuthKey(), edrToken.getAuthCode()); + + pcfExchangeProxy.uploadPcfSubmodel(pcfpushEnpoint, header, bpnNumber, requestId, message, + jsonObjectMapper.gsonObjectToJsonNode(calculatedPCFValue)); + + sendNotificationStatus = "SUCCESS"; + } else { + String warn="EDC connector " + dtOffer.getConnectorOfferUrl() + + ", The EDR token is null to find pcf exchange asset"; + log.warn(warn); + sendNotificationStatus = warn; + } + } catch (FeignException e) { + log.error("FeignRequest:" + e.request()); + String errorMsg = "Unable to send notification to consumer because: " + + (StringUtils.isBlank(e.contentUTF8()) ? e.getMessage() : e.contentUTF8()); + log.error("FeignException : " + errorMsg); + sendNotificationStatus = errorMsg; + } finally { + pcfRepositoryService.updatePCFPushStatus(status, requestId, sendNotificationStatus); + } + } + + + +} diff --git a/modules/sde-core/pom.xml b/modules/sde-core/pom.xml index 6b28384bb..44a4e5abf 100644 --- a/modules/sde-core/pom.xml +++ b/modules/sde-core/pom.xml @@ -185,6 +185,12 @@ 0.0.1 + + org.eclipse.tractusx + pcf-exchange + 0.0.1 + + com.opencsv opencsv diff --git a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/EnumMappingAppConfig.java b/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/EnumMappingAppConfig.java new file mode 100644 index 000000000..319ba0f17 --- /dev/null +++ b/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/EnumMappingAppConfig.java @@ -0,0 +1,40 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.sde.configuration; + +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnumFormator; +import org.springframework.context.annotation.Configuration; +import org.springframework.format.FormatterRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class EnumMappingAppConfig implements WebMvcConfigurer { + + private PCFTypeEnumFormator pcfEnumFormatter() { + return new PCFTypeEnumFormator(); + } + + @Override + public void addFormatters(FormatterRegistry registry) { + registry.addFormatter(this.pcfEnumFormatter()); + } + +} diff --git a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/controller/PcfExchangeController.java b/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/controller/PcfExchangeController.java new file mode 100644 index 000000000..f50f1a827 --- /dev/null +++ b/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/controller/PcfExchangeController.java @@ -0,0 +1,127 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package org.eclipse.tractusx.sde.core.controller; + +import static org.springframework.http.ResponseEntity.ok; + +import java.util.Map; + +import org.eclipse.tractusx.sde.edc.model.request.ConsumerRequest; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; +import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnum; +import org.eclipse.tractusx.sde.pcfexchange.request.PcfRequestModel; +import org.eclipse.tractusx.sde.pcfexchange.service.IPCFExchangeService; +import org.springframework.data.repository.query.Param; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +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.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.fasterxml.jackson.databind.JsonNode; + +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestController +@RequiredArgsConstructor +@RequestMapping("pcf") +public class PcfExchangeController { + + private final IPCFExchangeService pcfExchangeService; + + @PostMapping(value = "/request/{productId}") + @PreAuthorize("hasPermission('','request_for_pcf_value')") + public ResponseEntity requestForPcfDataOffer(@PathVariable String productId, + @Valid @RequestBody ConsumerRequest consumerRequest) throws Exception { + log.info("Request received for POST: /api/pcf/request/{}", productId); + return ok().body(Map.of("msg", pcfExchangeService.requestForPcfDataExistingOffer(productId, consumerRequest))); + } + + @PostMapping(value = "/request/nonexistdataoffer") + @PreAuthorize("hasPermission('','request_for_pcf_value')") + public ResponseEntity requestForPcfNotExistDataOffer(@Valid @RequestBody PcfRequestModel pcfRequestModel) + throws Exception { + log.info("Request received for POST: /api/pcf/nonexistdataoffer/{}", pcfRequestModel.getProductId()); + return ok().body(Map.of("msg", + pcfExchangeService.requestForPcfNotExistDataOffer(pcfRequestModel))); + } + + @GetMapping(value = "/request/{requestId}") + @PreAuthorize("hasPermission('','request_for_pcf_value')") + public ResponseEntity viewForPcfDataOffer(@PathVariable String requestId) throws Exception { + log.info("Request received for GET: /request/{}", requestId); + return ok().body(pcfExchangeService.viewForPcfDataOffer(requestId)); + } + + @PostMapping(value = "/actionsonrequest") + @PreAuthorize("hasPermission('','action_on_pcf_request')") + public ResponseEntity actionOnPcfRequestAndSendNotificationToConsumer( + @Valid @RequestBody PcfRequestModel pcfRequestModel) throws Exception { + + log.info("Request received for POST: /request/actionsonrequest"); + + String msg = pcfExchangeService.actionOnPcfRequestAndSendNotificationToConsumer(pcfRequestModel); + + return ok().body(Map.of("msg", msg)); + } + + @GetMapping(value = "/{type}/requests") + @PreAuthorize("hasPermission('','view_pcf_history')") + public ResponseEntity getPcfProviderData(@PathVariable PCFTypeEnum type, + @RequestParam(value = "status", required = false) PCFRequestStatusEnum status, @Param("page") Integer page, + @Param("pageSize") Integer pageSize) throws Exception { + log.info("Request received for GET: /api/pcf/{}/requests/", type.name().toLowerCase()); + + page = page == null ? 0 : page; + pageSize = pageSize == null ? 10 : pageSize; + + return ok().body(pcfExchangeService.getPcfData(status, type, page, pageSize)); + } + + // PCF data exchange api's + @GetMapping(value = "/productIds/{productId}") + public ResponseEntity getPcfByProduct(@PathVariable String productId, + @RequestParam(value = "BPN", required = true) String bpnNumber, + @RequestParam(value = "requestId", required = true) String requestId, @RequestParam String message) + throws Exception { + log.info("Request received for GET: /api/pcf/productIds/{}", productId); + pcfExchangeService.savePcfRequestData(requestId, productId, bpnNumber, message); + return ResponseEntity.accepted().body(Map.of("msg", "PCF request accepted")); + } + + @PutMapping(value = "/productIds/{productId}") + public ResponseEntity uploadPcfSubmodel(@PathVariable String productId, + @RequestParam(value = "BPN", required = true) String bpnNumber, + @RequestParam(value = "requestId", required = false) String requestId, + @RequestParam(value = "message", required = false) String message, @RequestBody JsonNode pcfData) { + log.info("Request received for PUT: /api/pcf/productIds/{}", productId); + + pcfExchangeService.recievedPCFData(productId, bpnNumber, requestId, message, pcfData); + return ResponseEntity.ok().body(Map.of("msg", "PCF response recieved")); + } +} diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/util/EDCAssetUrlCacheService.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/util/EDCAssetUrlCacheService.java index 2cc977418..99aba0812 100644 --- a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/util/EDCAssetUrlCacheService.java +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/util/EDCAssetUrlCacheService.java @@ -39,17 +39,20 @@ import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; + @Slf4j @Service @RequiredArgsConstructor public class EDCAssetUrlCacheService { private static final Map dDTRmap = new ConcurrentHashMap<>(); + private static final Map pcfExchangeURLMap = new ConcurrentHashMap<>(); private final ContractNegotiationService contractNegotiationService; private final PolicyConstraintBuilderService policyConstraintBuilderService; private final DDTRUrlCacheUtility dDTRUrlCacheUtility; + private final PCFExchangeAssetUtils pcfExchangeAssetUtils; @SneakyThrows public EDRCachedByIdResponse verifyAndGetToken(String bpnNumber, QueryDataOfferModel queryDataOfferModel) { @@ -58,22 +61,21 @@ public EDRCachedByIdResponse verifyAndGetToken(String bpnNumber, QueryDataOfferM .getUsagePoliciesConstraints(queryDataOfferModel.getPolicy().getUsagePolicies()); Offer offer = Offer.builder().assetId(queryDataOfferModel.getAssetId()) - .offerId(queryDataOfferModel.getOfferId()) - .policyId(queryDataOfferModel.getPolicyId()) + .offerId(queryDataOfferModel.getOfferId()).policyId(queryDataOfferModel.getPolicyId()) .connectorId(queryDataOfferModel.getConnectorId()) - .connectorOfferUrl(queryDataOfferModel.getConnectorOfferUrl()) - .build(); + .connectorOfferUrl(queryDataOfferModel.getConnectorOfferUrl()).build(); try { EDRCachedResponse eDRCachedResponse = contractNegotiationService.verifyOrCreateContractNegotiation( bpnNumber, Map.of(), queryDataOfferModel.getConnectorOfferUrl(), action, offer); if (eDRCachedResponse == null) { throw new ServiceException("Time out!! to get 'NEGOTIATED' EDC EDR status to lookup '" - + queryDataOfferModel.getAssetId() + "', The current status is null"); + + queryDataOfferModel.getConnectorOfferUrl() + ", " + queryDataOfferModel.getAssetId() + + "', The current status is null"); } else if (!"NEGOTIATED".equalsIgnoreCase(eDRCachedResponse.getEdrState())) { - throw new ServiceException( - "Time out!! to get 'NEGOTIATED' EDC EDR status to lookup '" + queryDataOfferModel.getAssetId() - + "', The current status is '" + eDRCachedResponse.getEdrState() + "'"); + throw new ServiceException("Time out!! to get 'NEGOTIATED' EDC EDR status to lookup for '" + + queryDataOfferModel.getConnectorOfferUrl() + ", " + queryDataOfferModel.getAssetId() + + "', The current status is '" + eDRCachedResponse.getEdrState() + "'"); } else return contractNegotiationService .getAuthorizationTokenForDataDownload(eDRCachedResponse.getTransferProcessId()); @@ -106,7 +108,6 @@ else if (currDate.isAfter(cacheExpTime)) { if (ddtrUrl.isEmpty()) { log.info("Found connector list empty so removing existing cache and retry to fetch"); removeDDTRUrlCache(bpnNumber); - ddtrUrl = dDTRUrlCacheUtility.getDDTRUrl(bpnNumber); } return ddtrUrl; } @@ -121,4 +122,34 @@ public void removeDDTRUrlCache(String bpnNumber) { dDTRmap.remove(bpnNumber); } + public List getPCFExchangeUrlFromTwin(String bpnNumber) { + + LocalDateTime cacheExpTime = pcfExchangeURLMap.get(bpnNumber); + LocalDateTime currDate = LocalDateTime.now(); + + if (cacheExpTime == null) + cacheExpTime = currDate.plusHours(12); + else if (currDate.isAfter(cacheExpTime)) { + pcfExchangeAssetUtils.removePCFExchangeCache(bpnNumber); + cacheExpTime = currDate.plusHours(12); + } + pcfExchangeURLMap.put(bpnNumber, cacheExpTime); + List pcfExchangeurls = pcfExchangeAssetUtils.getPCFExchangeUrl(bpnNumber); + if (pcfExchangeurls.isEmpty()) { + log.info("Found connector list empty so removing existing cache and retry to fetch"); + removePCFExchangeCache(bpnNumber); + } + return pcfExchangeurls; + } + + public void clearPCFExchangeUrlCache() { + pcfExchangeURLMap.clear(); + pcfExchangeAssetUtils.clearePCFExchangeAllCache(); + } + + public void removePCFExchangeCache(String bpnNumber) { + pcfExchangeAssetUtils.removePCFExchangeCache(bpnNumber); + pcfExchangeURLMap.remove(bpnNumber); + } + } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 01e62138f..9c3b35d3f 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,7 @@ modules/sde-common modules/sde-core + modules/pcf-exchange modules/sde-submodules/serial-part-typization modules/sde-submodules/batch @@ -66,6 +67,7 @@ modules/sde-submodules/part-site-information-as-planned modules/sde-submodules/single-level-usage-as-built modules/sde-submodules/pcf + From 311104ba1db6ef15462589ca49b68f88991815a6 Mon Sep 17 00:00:00 2001 From: ChetanT-System Date: Mon, 1 Apr 2024 22:24:56 +0530 Subject: [PATCH 2/5] - PCF exchange draft changes --- .../AsyncPushPCFDataForApproveRequest.java | 142 ----------- .../service/impl/PCFRepositoryService.java | 149 ------------ .../service/impl/PcfExchangeServiceImpl.java | 220 ------------------ .../service/impl/ProxyRequestInterface.java | 163 ------------- .../configuration/EnumMappingAppConfig.java | 40 ---- .../controller/PcfExchangeController.java | 127 ---------- 6 files changed, 841 deletions(-) delete mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/AsyncPushPCFDataForApproveRequest.java delete mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PCFRepositoryService.java delete mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PcfExchangeServiceImpl.java delete mode 100644 modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/ProxyRequestInterface.java delete mode 100644 modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/EnumMappingAppConfig.java delete mode 100644 modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/controller/PcfExchangeController.java diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/AsyncPushPCFDataForApproveRequest.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/AsyncPushPCFDataForApproveRequest.java deleted file mode 100644 index 6a1169a2a..000000000 --- a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/AsyncPushPCFDataForApproveRequest.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2024 T-Systems International GmbH - * Copyright (c) 2024 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.sde.pcfexchange.service.impl; - -import java.util.List; - -import org.eclipse.tractusx.sde.common.entities.PolicyModel; -import org.eclipse.tractusx.sde.common.exception.NoDataFoundException; -import org.eclipse.tractusx.sde.common.model.PagingResponse; -import org.eclipse.tractusx.sde.common.utils.PolicyOperationUtil; -import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; -import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnum; -import org.eclipse.tractusx.sde.pcfexchange.request.PcfRequestModel; -import org.eclipse.tractusx.sde.submodels.pcf.entity.PcfEntity; -import org.eclipse.tractusx.sde.submodels.pcf.service.PcfService; -import org.springframework.stereotype.Component; - -import com.google.gson.JsonObject; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Component -@RequiredArgsConstructor -@SuppressWarnings("unchecked") -public class AsyncPushPCFDataForApproveRequest { - - private final PCFRepositoryService pcfRepositoryService; - - private final PcfService pcfService; - - private final ProxyRequestInterface proxyRequestInterface; - - - public void pushPCFDataForApproveRequest(String processId, PolicyModel policy) { - - List accessBPNList = PolicyOperationUtil.getAccessBPNList(policy); - - List productList = pcfService.readCreatedTwins(processId).stream().map(PcfEntity::getProductId) - .toList(); - - markedPCFDataForPendingProviderRequestAsRequested(productList); - - PagingResponse pcfData = pcfRepositoryService.getPcfData( - List.of(PCFRequestStatusEnum.PUSHED, PCFRequestStatusEnum.PUSHED_UPDATED_DATA), PCFTypeEnum.PROVIDER, 0, - 1000); - List requestList = (List) pcfData.getItems(); - - if (!requestList.isEmpty()) { - - requestList.forEach(request -> { - - if (productList.contains(request.getProductId()) && accessBPNList.contains(request.getBpnNumber())) { - - String msg = ""; - - try { - request.setStatus(PCFRequestStatusEnum.PUSHING_UPDATED_DATA); - - JsonObject calculatedPCFValue = pcfService - .readCreatedTwinsDetailsByProductId(request.getProductId()).get("json") - .getAsJsonObject(); - - PCFRequestStatusEnum status = pcfRepositoryService.identifyRunningStatus(request.getRequestId(), - request.getStatus()); - - // push api call - Runnable runnable = () -> proxyRequestInterface.sendNotificationToConsumer(status, - calculatedPCFValue, request.getProductId(), request.getBpnNumber(), - request.getRequestId()); - - new Thread(runnable).start(); - - msg = "PCF request '" + request.getStatus() - + "' and asynchronously sending notification to consumer"; - - } catch (NoDataFoundException e) { - msg = "Unable to take action on PCF request becasue pcf calculated value does not exist, please provide/upload PCF value for " - + request.getProductId() + ", requestId " + request.getRequestId(); - log.error("Async PushPCFDataForApproveRequest" + msg); - throw new NoDataFoundException(msg); - } catch (Exception e) { - pcfRepositoryService.savePcfStatus(request.getRequestId(), PCFRequestStatusEnum.FAILED); - } - } - }); - } else { - log.debug("Async PushPCFDataForApproveRequest - No APPROVED request found"); - } - - } - - public void markedPCFDataForPendingProviderRequestAsRequested(List productList) { - - PagingResponse pcfData = pcfRepositoryService.getPcfData(List.of(PCFRequestStatusEnum.PENDING_DATA_FROM_PROVIDER), - PCFTypeEnum.PROVIDER, 0, 1000); - List requestList = (List) pcfData.getItems(); - - if (!requestList.isEmpty()) { - requestList.forEach(request -> { - if (productList.contains(request.getProductId())) { - String msg = ""; - try { - pcfService.readCreatedTwinsDetailsByProductId(request.getProductId()).get("json") - .getAsJsonObject(); - pcfRepositoryService.savePcfStatus(request.getRequestId(), PCFRequestStatusEnum.REQUESTED); - - } catch (NoDataFoundException e) { - msg = "Unable to markedPCFDataForPendingProviderRequestAsRequested becasue pcf calculated value does not exist " - + request.getProductId() + ", requestId " + request.getRequestId(); - log.error("Async PushPCFDataForApproveRequest" + msg); - throw new NoDataFoundException(msg); - } catch (Exception e) { - pcfRepositoryService.savePcfStatus(request.getRequestId(), PCFRequestStatusEnum.FAILED); - } - } - }); - } else { - log.debug("Async PushPCFDataForApproveRequest - No 'PENDING_DATA_FROM_PROVIDER' request found"); - } - - } -} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PCFRepositoryService.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PCFRepositoryService.java deleted file mode 100644 index 4a51743ce..000000000 --- a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PCFRepositoryService.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2024 T-Systems International GmbH - * Copyright (c) 2024 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.sde.pcfexchange.service.impl; - -import java.time.Instant; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.tractusx.sde.common.model.PagingResponse; -import org.eclipse.tractusx.sde.pcfexchange.entity.PcfRequestEntity; -import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; -import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnum; -import org.eclipse.tractusx.sde.pcfexchange.mapper.PcfExchangeMapper; -import org.eclipse.tractusx.sde.pcfexchange.repository.PcfRequestRepository; -import org.eclipse.tractusx.sde.pcfexchange.request.PcfRequestModel; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.stereotype.Component; - -import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Component -@RequiredArgsConstructor -public class PCFRepositoryService { - - private static final String SUCCESS = "SUCCESS"; - private final PcfRequestRepository pcfRequestRepository; - private final PcfExchangeMapper pcfMapper; - - public PcfRequestModel savePcfRequestData(String requestId, String productId, String bpnNumber, String message, - PCFTypeEnum type, PCFRequestStatusEnum status, String remark) { - - PcfRequestModel pojo = PcfRequestModel.builder().requestId(requestId).productId(productId).bpnNumber(bpnNumber) - .status(status).message(message).type(type).requestedTime(Instant.now().getEpochSecond()) - .lastUpdatedTime(Instant.now().getEpochSecond()).remark(remark).build(); - - PcfRequestEntity entity = pcfMapper.mapFrom(pojo); - - return pcfMapper.mapFrom(pcfRequestRepository.save(entity)); - } - - public PCFRequestStatusEnum updatePCFPushStatus(PCFRequestStatusEnum status, String requestId, String sendNotificationStatus) { - - if ((PCFRequestStatusEnum.APPROVED.equals(status) || PCFRequestStatusEnum.PUSHING_DATA.equals(status)) - && SUCCESS.equalsIgnoreCase(sendNotificationStatus)) { - status = PCFRequestStatusEnum.PUSHED; - sendNotificationStatus ="PCF data successfuly pushed"; - } else if (PCFRequestStatusEnum.PUSHING_UPDATED_DATA.equals(status) - && SUCCESS.equalsIgnoreCase(sendNotificationStatus)) { - status = PCFRequestStatusEnum.PUSHED_UPDATED_DATA; - sendNotificationStatus ="PCF updated data successfuly pushed"; - } else if (PCFRequestStatusEnum.REJECTED.equals(status) && SUCCESS.equalsIgnoreCase(sendNotificationStatus)) { - status = PCFRequestStatusEnum.REJECTED; - sendNotificationStatus ="PCF request rejected successfuly"; - } else if (PCFRequestStatusEnum.APPROVED.equals(status) - || PCFRequestStatusEnum.FAILED_TO_PUSH_DATA.equals(status) - || PCFRequestStatusEnum.PUSHING_DATA.equals(status) - || PCFRequestStatusEnum.PUSHING_UPDATED_DATA.equals(status)) { - status = PCFRequestStatusEnum.FAILED_TO_PUSH_DATA; - } else if (PCFRequestStatusEnum.REJECTED.equals(status) - || PCFRequestStatusEnum.FAILED_TO_SEND_REJECT_NOTIFICATION.equals(status)) - status = PCFRequestStatusEnum.FAILED_TO_SEND_REJECT_NOTIFICATION; - else { - status = PCFRequestStatusEnum.FAILED; - } - - savePcfStatus(requestId, status, sendNotificationStatus); - - return status; - } - - public PCFRequestStatusEnum identifyRunningStatus(String requestId, PCFRequestStatusEnum status) { - - boolean isApproval = PCFRequestStatusEnum.APPROVED.equals(status) - || PCFRequestStatusEnum.FAILED_TO_PUSH_DATA.equals(status); - - boolean isRejection = PCFRequestStatusEnum.REJECTED.equals(status) - || PCFRequestStatusEnum.FAILED_TO_SEND_REJECT_NOTIFICATION.equals(status); - - if (isApproval) { - status = PCFRequestStatusEnum.PUSHING_DATA; - } else if (isRejection) { - status = PCFRequestStatusEnum.SENDING_REJECT_NOTIFICATION; - } - - savePcfStatus(requestId, status); - - return status; - } - - @SneakyThrows - public PcfRequestEntity savePcfStatus(String requestId, PCFRequestStatusEnum status) { - return savePcfStatus(requestId, status, null); - } - - @SneakyThrows - public PcfRequestEntity savePcfStatus(String requestId, PCFRequestStatusEnum status, String remark) { - - PcfRequestEntity pcfRequestEntity = pcfRequestRepository.getReferenceById(requestId); - pcfRequestEntity.setLastUpdatedTime(Instant.now().getEpochSecond()); - pcfRequestEntity.setStatus(status); - - if(StringUtils.isNotBlank(remark)) - pcfRequestEntity.setRemark(remark); - - log.info("'" + pcfRequestEntity.getProductId() + "' pcf request saved in the database successfully as {}", - status); - pcfRequestRepository.save(pcfRequestEntity); - return pcfRequestEntity; - - } - - public PagingResponse getPcfData(List status, PCFTypeEnum type, Integer page, Integer pageSize) { - - Page result = null; - if (status == null || status.isEmpty()) { - result = pcfRequestRepository.findByType(PageRequest.of(page, pageSize), type); - } else { - result = pcfRequestRepository.findByTypeAndStatusIn(PageRequest.of(page, pageSize), type, status); - } - - List requestList = result.stream().map(pcfMapper::mapFrom).toList(); - - return PagingResponse.builder().items(requestList).pageSize(result.getSize()).page(result.getNumber()) - .totalItems(result.getTotalElements()).build(); - } - -} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PcfExchangeServiceImpl.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PcfExchangeServiceImpl.java deleted file mode 100644 index 54c09594d..000000000 --- a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/PcfExchangeServiceImpl.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2024 T-Systems International GmbH - * Copyright (c) 2024 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ -package org.eclipse.tractusx.sde.pcfexchange.service.impl; - -import java.time.Instant; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.tractusx.sde.common.entities.PolicyModel; -import org.eclipse.tractusx.sde.common.exception.NoDataFoundException; -import org.eclipse.tractusx.sde.common.exception.ServiceException; -import org.eclipse.tractusx.sde.common.exception.ValidationException; -import org.eclipse.tractusx.sde.common.model.PagingResponse; -import org.eclipse.tractusx.sde.edc.model.request.ConsumerRequest; -import org.eclipse.tractusx.sde.edc.model.response.QueryDataOfferModel; -import org.eclipse.tractusx.sde.edc.util.EDCAssetUrlCacheService; -import org.eclipse.tractusx.sde.pcfexchange.entity.PcfResponseEntity; -import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; -import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnum; -import org.eclipse.tractusx.sde.pcfexchange.repository.PcfReqsponseRepository; -import org.eclipse.tractusx.sde.pcfexchange.request.PcfRequestModel; -import org.eclipse.tractusx.sde.pcfexchange.service.IPCFExchangeService; -import org.eclipse.tractusx.sde.submodels.pcf.service.PcfService; -import org.springframework.stereotype.Service; - -import com.fasterxml.jackson.databind.JsonNode; -import com.google.gson.JsonObject; - -import feign.FeignException; -import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Service -@RequiredArgsConstructor -public class PcfExchangeServiceImpl implements IPCFExchangeService { - - private final PCFRepositoryService pcfRepositoryService; - private final PcfReqsponseRepository pcfReqsponseRepository; - private final EDCAssetUrlCacheService edcAssetUrlCacheService; - private final PcfService pcfService; - private final ProxyRequestInterface proxyRequestInterface; - - @SneakyThrows - @Override - public String requestForPcfDataExistingOffer(String productId, ConsumerRequest consumerRequest) { - - StringBuilder sb = new StringBuilder(); - consumerRequest.getOffers().stream().forEach(offer -> { - - String requestId = UUID.randomUUID().toString(); - String providerBPNNumber = offer.getConnectorId(); - - String message = "Please provide PCF value for " + productId; - - pcfRepositoryService.savePcfRequestData(requestId, productId, providerBPNNumber, message, - PCFTypeEnum.CONSUMER, PCFRequestStatusEnum.SENDING_REQUEST, ""); - - QueryDataOfferModel queryDataOfferModel = QueryDataOfferModel.builder().assetId(offer.getAssetId()) - .offerId(offer.getOfferId()).policyId(offer.getPolicyId()).connectorId(providerBPNNumber) - .connectorOfferUrl(offer.getConnectorOfferUrl()) - .policy(PolicyModel.builder().usagePolicies(consumerRequest.getUsagePolicies()).build()).build(); - - proxyRequestInterface.requestToProviderForPCFValue(productId, sb, requestId, message, queryDataOfferModel, false); - }); - - return sb.toString(); - - } - - @Override - public Object requestForPcfNotExistDataOffer(PcfRequestModel pcfRequestModel) { - StringBuilder sb = new StringBuilder(); - String requestId = UUID.randomUUID().toString(); - try { - pcfRepositoryService.savePcfRequestData(requestId, pcfRequestModel.getProductId(), - pcfRequestModel.getBpnNumber(), pcfRequestModel.getMessage(), PCFTypeEnum.CONSUMER, - PCFRequestStatusEnum.SENDING_REQUEST, ""); - - // 1 fetch EDC connectors and DTR Assets from EDC connectors - List pcfExchangeUrlOffers = edcAssetUrlCacheService - .getPCFExchangeUrlFromTwin(pcfRequestModel.getBpnNumber()); - - // 2 request for PCF value for non existing sub model and send notification to - // call provider for data - pcfExchangeUrlOffers.parallelStream().forEach(dtOffer -> proxyRequestInterface.requestToProviderForPCFValue( - pcfRequestModel.getProductId(), sb, requestId, pcfRequestModel.getMessage(), dtOffer, true)); - - } catch (FeignException e) { - log.error("FeignRequest requestForPcfNotExistDataOffer:" + e.request()); - String errorMsg = "Unable to request to data provider because: " - + (StringUtils.isBlank(e.contentUTF8()) ? e.getMessage() : e.contentUTF8()); - log.error("FeignException requestForPcfNotExistDataOffer: " + errorMsg); - } - - if (sb.isEmpty()) - throw new ValidationException("Not requested to provider for '" + pcfRequestModel.getProductId() - + "' because there is no PCF exchange endpoint found"); - - return sb.toString(); - } - - @SneakyThrows - @Override - public String actionOnPcfRequestAndSendNotificationToConsumer(PcfRequestModel pcfRequestModel) { - String remark = ""; - try { - - JsonObject calculatedPCFValue = pcfService - .readCreatedTwinsDetailsByProductId(pcfRequestModel.getProductId()).get("json").getAsJsonObject(); - - - PCFRequestStatusEnum status = pcfRepositoryService.identifyRunningStatus(pcfRequestModel.getRequestId(), - pcfRequestModel.getStatus()); - - // push api call - Runnable runnable = () -> proxyRequestInterface.sendNotificationToConsumer(status, - calculatedPCFValue, pcfRequestModel.getProductId(), pcfRequestModel.getBpnNumber(), - pcfRequestModel.getRequestId()); - - new Thread(runnable).start(); - - remark = "PCF push request accepted for '" + pcfRequestModel.getProductId() - + "' and asynchronously pushing notification to consumer"; - - } catch (NoDataFoundException e) { - remark = "Unable to take action on PCF request becasue PCF calculated value does not exist, please upload PCF value for " - + pcfRequestModel.getProductId() + " in systems using Manual/Recurring Upload"; - pcfRepositoryService.savePcfRequestData(pcfRequestModel.getRequestId(), pcfRequestModel.getProductId(), - pcfRequestModel.getBpnNumber(), pcfRequestModel.getMessage(), PCFTypeEnum.PROVIDER, - PCFRequestStatusEnum.FAILED, remark); - log.error(remark); - throw new ValidationException(e.getMessage()); - } catch (Exception e) { - pcfRepositoryService.savePcfStatus(pcfRequestModel.getRequestId(), PCFRequestStatusEnum.FAILED); - throw new ServiceException(e.getMessage()); - } - return remark; - } - - @Override - public PcfRequestModel savePcfRequestData(String requestId, String productId, String bpnNumber, String message) { - PCFRequestStatusEnum status = PCFRequestStatusEnum.REQUESTED; - String remark = ""; - try { - pcfService.readCreatedTwinsDetailsByProductId(productId).get("json").getAsJsonObject(); - } catch (NoDataFoundException e) { - String msg = "The PCF calculated value does not exist in system, please upload PCF value for '" + productId - + "' in systems using Manual/Recurring Upload"; - log.warn(msg); - remark = msg; - status = PCFRequestStatusEnum.PENDING_DATA_FROM_PROVIDER; - } - return pcfRepositoryService.savePcfRequestData(requestId, productId, bpnNumber, message, PCFTypeEnum.PROVIDER, - status, remark); - } - - @Override - public void recievedPCFData(String productId, String bpnNumber, String requestId, String message, - JsonNode pcfData) { - - PCFRequestStatusEnum status = PCFRequestStatusEnum.FAILED; - try { - status = PCFRequestStatusEnum.valueOf(message); - } catch (Exception e) { - log.error("Unable to find PCF value status " + e.getMessage()); - } - - PcfResponseEntity entity = PcfResponseEntity.builder().pcfData(pcfData).requestId(requestId) - .responseId(UUID.randomUUID().toString()).lastUpdatedTime(Instant.now().getEpochSecond()).build(); - - pcfReqsponseRepository.save(entity); - - if (PCFRequestStatusEnum.APPROVED.equals(status) || PCFRequestStatusEnum.PUSHING_DATA.equals(status) - || PCFRequestStatusEnum.PUSHING_UPDATED_DATA.equals(status)) { - status = PCFRequestStatusEnum.RECEIVED; - } - - pcfRepositoryService.savePcfStatus(requestId, status); - - } - - @Override - public PagingResponse getPcfData(PCFRequestStatusEnum status, PCFTypeEnum type, Integer page, Integer pageSize) { - List statusLs = null; - if (status != null) - statusLs = List.of(status); - return pcfRepositoryService.getPcfData(statusLs, type, page, pageSize); - } - - @Override - public PcfResponseEntity viewForPcfDataOffer(String requestId) { - Optional findById = pcfReqsponseRepository - .findFirstByRequestIdOrderByLastUpdatedTimeDesc(requestId); - if (!findById.isPresent()) - throw new NoDataFoundException("No data found uuid " + requestId); - return findById.get(); - } - -} diff --git a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/ProxyRequestInterface.java b/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/ProxyRequestInterface.java deleted file mode 100644 index f76bca9db..000000000 --- a/modules/pcf-exchange/src/main/java/org/eclipse/tractusx/sde/pcfexchange/service/impl/ProxyRequestInterface.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2024 T-Systems International GmbH - * Copyright (c) 2024 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ -package org.eclipse.tractusx.sde.pcfexchange.service.impl; - -import java.net.URI; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.tractusx.sde.common.mapper.JsonObjectMapper; -import org.eclipse.tractusx.sde.edc.model.edr.EDRCachedByIdResponse; -import org.eclipse.tractusx.sde.edc.model.response.QueryDataOfferModel; -import org.eclipse.tractusx.sde.edc.util.EDCAssetUrlCacheService; -import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; -import org.eclipse.tractusx.sde.pcfexchange.proxy.PCFExchangeProxy; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import com.google.gson.JsonObject; - -import feign.FeignException; -import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Component -@RequiredArgsConstructor -public class ProxyRequestInterface { - - private static final String PRODUCT_IDS = "productIds"; - private static final String SLASH_DELIMETER = "/"; - private final PCFExchangeProxy pcfExchangeProxy; - private final PCFRepositoryService pcfRepositoryService; - private final EDCAssetUrlCacheService edcAssetUrlCacheService; - private final JsonObjectMapper jsonObjectMapper; - - @Value(value = "${manufacturerId}") - private String manufacturerId; - - @Value(value = "${digital-twins.managed.thirdparty:false}") - private boolean managedThirdParty; - - @SneakyThrows - public void requestToProviderForPCFValue(String productId, StringBuilder sb, String requestId, String message, - QueryDataOfferModel dataset, boolean isRequestToNonexistingTwin) { - - EDRCachedByIdResponse edrToken = edcAssetUrlCacheService.verifyAndGetToken(dataset.getConnectorId(), dataset); - - if (!sb.isEmpty()) - sb.append("\n"); - - if (edrToken != null) { - - URI pcfpushEnpoint = null; - - if(isRequestToNonexistingTwin) - pcfpushEnpoint = new URI( - edrToken.getEndpoint() + SLASH_DELIMETER + PRODUCT_IDS + SLASH_DELIMETER + productId); - else - pcfpushEnpoint = new URI(edrToken.getEndpoint()); - - Map header = new HashMap<>(); - header.put(edrToken.getAuthKey(), edrToken.getAuthCode()); - - // Send request to data provider for PCF value push - pcfExchangeProxy.getPcfByProduct(pcfpushEnpoint, header, manufacturerId, - requestId, message); - - sb.append(productId + ": requested for PCF value"); - pcfRepositoryService.savePcfStatus(requestId, PCFRequestStatusEnum.REQUESTED); - } else { - sb.append(productId + ": Unable to request for PCF value becasue the EDR token status is null"); - log.warn("EDC connector " + dataset.getConnectorOfferUrl() + ": {},{},{}", requestId, productId, - "Unable to request for PCF value becasue the EDR token status is null"); - pcfRepositoryService.savePcfStatus(requestId, PCFRequestStatusEnum.FAILED); - } - } - - @SneakyThrows - public void sendNotificationToConsumer(PCFRequestStatusEnum status, JsonObject calculatedPCFValue, - String productId, String bpnNumber, String requestId) { - - // 1 fetch EDC connectors and DTR Assets from EDC connectors - List pcfExchangeUrlOffers = edcAssetUrlCacheService.getPCFExchangeUrlFromTwin(bpnNumber); - - // 2 lookup shell for PCF sub model and send notification to call consumer - // request - if(pcfExchangeUrlOffers.isEmpty()) { - pcfRepositoryService.updatePCFPushStatus(status, requestId, "Unable to find PCF exchange endpoint"); - } - else { - pcfExchangeUrlOffers.parallelStream().forEach(dtOffer -> { - - if (PCFRequestStatusEnum.SENDING_REJECT_NOTIFICATION.equals(status)) { - sendNotification(null, productId, bpnNumber, requestId, dtOffer, status); - } else { - sendNotification(calculatedPCFValue, productId, bpnNumber, requestId, dtOffer, status); - } - - }); - } - } - - @SneakyThrows - private void sendNotification(JsonObject calculatedPCFValue, String productId, String bpnNumber, String requestId, - QueryDataOfferModel dtOffer, PCFRequestStatusEnum status) { - String sendNotificationStatus = ""; - try { - String message = status.name(); - - EDRCachedByIdResponse edrToken = edcAssetUrlCacheService.verifyAndGetToken(bpnNumber, dtOffer); - - if (edrToken != null) { - - URI pcfpushEnpoint = new URI( - edrToken.getEndpoint() + SLASH_DELIMETER + PRODUCT_IDS + SLASH_DELIMETER + productId); - - Map header = new HashMap<>(); - header.put(edrToken.getAuthKey(), edrToken.getAuthCode()); - - pcfExchangeProxy.uploadPcfSubmodel(pcfpushEnpoint, header, bpnNumber, requestId, message, - jsonObjectMapper.gsonObjectToJsonNode(calculatedPCFValue)); - - sendNotificationStatus = "SUCCESS"; - } else { - String warn="EDC connector " + dtOffer.getConnectorOfferUrl() - + ", The EDR token is null to find pcf exchange asset"; - log.warn(warn); - sendNotificationStatus = warn; - } - } catch (FeignException e) { - log.error("FeignRequest:" + e.request()); - String errorMsg = "Unable to send notification to consumer because: " - + (StringUtils.isBlank(e.contentUTF8()) ? e.getMessage() : e.contentUTF8()); - log.error("FeignException : " + errorMsg); - sendNotificationStatus = errorMsg; - } finally { - pcfRepositoryService.updatePCFPushStatus(status, requestId, sendNotificationStatus); - } - } - - - -} diff --git a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/EnumMappingAppConfig.java b/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/EnumMappingAppConfig.java deleted file mode 100644 index 319ba0f17..000000000 --- a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/configuration/EnumMappingAppConfig.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2024 T-Systems International GmbH - * Copyright (c) 2024 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.sde.configuration; - -import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnumFormator; -import org.springframework.context.annotation.Configuration; -import org.springframework.format.FormatterRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Configuration -public class EnumMappingAppConfig implements WebMvcConfigurer { - - private PCFTypeEnumFormator pcfEnumFormatter() { - return new PCFTypeEnumFormator(); - } - - @Override - public void addFormatters(FormatterRegistry registry) { - registry.addFormatter(this.pcfEnumFormatter()); - } - -} diff --git a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/controller/PcfExchangeController.java b/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/controller/PcfExchangeController.java deleted file mode 100644 index f50f1a827..000000000 --- a/modules/sde-core/src/main/java/org/eclipse/tractusx/sde/core/controller/PcfExchangeController.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2024 T-Systems International GmbH - * Copyright (c) 2024 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ -package org.eclipse.tractusx.sde.core.controller; - -import static org.springframework.http.ResponseEntity.ok; - -import java.util.Map; - -import org.eclipse.tractusx.sde.edc.model.request.ConsumerRequest; -import org.eclipse.tractusx.sde.pcfexchange.enums.PCFRequestStatusEnum; -import org.eclipse.tractusx.sde.pcfexchange.enums.PCFTypeEnum; -import org.eclipse.tractusx.sde.pcfexchange.request.PcfRequestModel; -import org.eclipse.tractusx.sde.pcfexchange.service.IPCFExchangeService; -import org.springframework.data.repository.query.Param; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -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.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import com.fasterxml.jackson.databind.JsonNode; - -import jakarta.validation.Valid; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@RestController -@RequiredArgsConstructor -@RequestMapping("pcf") -public class PcfExchangeController { - - private final IPCFExchangeService pcfExchangeService; - - @PostMapping(value = "/request/{productId}") - @PreAuthorize("hasPermission('','request_for_pcf_value')") - public ResponseEntity requestForPcfDataOffer(@PathVariable String productId, - @Valid @RequestBody ConsumerRequest consumerRequest) throws Exception { - log.info("Request received for POST: /api/pcf/request/{}", productId); - return ok().body(Map.of("msg", pcfExchangeService.requestForPcfDataExistingOffer(productId, consumerRequest))); - } - - @PostMapping(value = "/request/nonexistdataoffer") - @PreAuthorize("hasPermission('','request_for_pcf_value')") - public ResponseEntity requestForPcfNotExistDataOffer(@Valid @RequestBody PcfRequestModel pcfRequestModel) - throws Exception { - log.info("Request received for POST: /api/pcf/nonexistdataoffer/{}", pcfRequestModel.getProductId()); - return ok().body(Map.of("msg", - pcfExchangeService.requestForPcfNotExistDataOffer(pcfRequestModel))); - } - - @GetMapping(value = "/request/{requestId}") - @PreAuthorize("hasPermission('','request_for_pcf_value')") - public ResponseEntity viewForPcfDataOffer(@PathVariable String requestId) throws Exception { - log.info("Request received for GET: /request/{}", requestId); - return ok().body(pcfExchangeService.viewForPcfDataOffer(requestId)); - } - - @PostMapping(value = "/actionsonrequest") - @PreAuthorize("hasPermission('','action_on_pcf_request')") - public ResponseEntity actionOnPcfRequestAndSendNotificationToConsumer( - @Valid @RequestBody PcfRequestModel pcfRequestModel) throws Exception { - - log.info("Request received for POST: /request/actionsonrequest"); - - String msg = pcfExchangeService.actionOnPcfRequestAndSendNotificationToConsumer(pcfRequestModel); - - return ok().body(Map.of("msg", msg)); - } - - @GetMapping(value = "/{type}/requests") - @PreAuthorize("hasPermission('','view_pcf_history')") - public ResponseEntity getPcfProviderData(@PathVariable PCFTypeEnum type, - @RequestParam(value = "status", required = false) PCFRequestStatusEnum status, @Param("page") Integer page, - @Param("pageSize") Integer pageSize) throws Exception { - log.info("Request received for GET: /api/pcf/{}/requests/", type.name().toLowerCase()); - - page = page == null ? 0 : page; - pageSize = pageSize == null ? 10 : pageSize; - - return ok().body(pcfExchangeService.getPcfData(status, type, page, pageSize)); - } - - // PCF data exchange api's - @GetMapping(value = "/productIds/{productId}") - public ResponseEntity getPcfByProduct(@PathVariable String productId, - @RequestParam(value = "BPN", required = true) String bpnNumber, - @RequestParam(value = "requestId", required = true) String requestId, @RequestParam String message) - throws Exception { - log.info("Request received for GET: /api/pcf/productIds/{}", productId); - pcfExchangeService.savePcfRequestData(requestId, productId, bpnNumber, message); - return ResponseEntity.accepted().body(Map.of("msg", "PCF request accepted")); - } - - @PutMapping(value = "/productIds/{productId}") - public ResponseEntity uploadPcfSubmodel(@PathVariable String productId, - @RequestParam(value = "BPN", required = true) String bpnNumber, - @RequestParam(value = "requestId", required = false) String requestId, - @RequestParam(value = "message", required = false) String message, @RequestBody JsonNode pcfData) { - log.info("Request received for PUT: /api/pcf/productIds/{}", productId); - - pcfExchangeService.recievedPCFData(productId, bpnNumber, requestId, message, pcfData); - return ResponseEntity.ok().body(Map.of("msg", "PCF response recieved")); - } -} From 4068bad1360b8a5a85f3e9f82b550cbc8a8c35fe Mon Sep 17 00:00:00 2001 From: ChetanT-System Date: Mon, 1 Apr 2024 22:58:58 +0530 Subject: [PATCH 3/5] - Changelog file updated. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c488b2cf..de4bcba98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Updated supported sub-model implementation classes. - EDC asset update refactored in supported submodels. - Support for pcf v6.0.0 submodel. +- Added module for pcf exchange service. ## [2.3.6] - 2024-03-06 From b4fa67713787edc1d6303f2ac63457b28d49cb38 Mon Sep 17 00:00:00 2001 From: Chetan Parate <94056821+ChetanT-System@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:23:21 +0530 Subject: [PATCH 4/5] Added PCF exchange asset util file --- .../sde/edc/util/PCFExchangeAssetUtils.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/util/PCFExchangeAssetUtils.java diff --git a/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/util/PCFExchangeAssetUtils.java b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/util/PCFExchangeAssetUtils.java new file mode 100644 index 000000000..1d996ad4d --- /dev/null +++ b/modules/sde-external-services/edc/src/main/java/org/eclipse/tractusx/sde/edc/util/PCFExchangeAssetUtils.java @@ -0,0 +1,54 @@ +/******************************************************************************** + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package org.eclipse.tractusx.sde.edc.util; + +import java.util.List; + +import org.eclipse.tractusx.sde.edc.model.response.QueryDataOfferModel; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +@RequiredArgsConstructor +public class PCFExchangeAssetUtils { + + private final EDCAssetLookUp edcAssetLookUp; + + @Cacheable(value = "bpn-pcfexchange", key = "#bpnNumber") + public List getPCFExchangeUrl(String bpnNumber) { + return edcAssetLookUp.getEDCAssetsByType(bpnNumber, "data.pcf.exchangeEndpoint"); + } + + @CacheEvict(value = "bpn-pcfexchange", key = "#bpnNumber") + public void removePCFExchangeCache(String bpnNumber) { + log.info("Cleared '" + bpnNumber + "' bpn-pcfexchange cache"); + } + + @CacheEvict(value = "bpn-pcfexchange", allEntries = true) + public void clearePCFExchangeAllCache() { + log.info("Cleared All bpn-pcfexchange cache"); + } + +} From b789bb1b90d22c06d488e6b6085ec81ab6b6ab6e Mon Sep 17 00:00:00 2001 From: ChetanT-System Date: Mon, 8 Apr 2024 17:46:07 +0530 Subject: [PATCH 5/5] - Dependencies file updated --- DEPENDENCIES | 1 + 1 file changed, 1 insertion(+) diff --git a/DEPENDENCIES b/DEPENDENCIES index 0f56d30f1..0b94259f2 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -73,6 +73,7 @@ maven/mavencentral/org.eclipse.tractusx/digital-twins/0.0.1, Apache-2.0, approve maven/mavencentral/org.eclipse.tractusx/edc/0.0.1, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.eclipse.tractusx/part-as-planned/0.0.1, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.eclipse.tractusx/part-site-information-as-planned/0.0.1, Apache-2.0, approved, automotive.tractusx +maven/mavencentral/org.eclipse.tractusx/pcf-exchange/0.0.1, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.eclipse.tractusx/pcf/0.0.1, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.eclipse.tractusx/policy-hub/0.0.1, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.eclipse.tractusx/portal/0.0.1, Apache-2.0, approved, automotive.tractusx