diff --git a/src/main/java/org/eclipse/tractusx/valueaddedservice/dto/edc/CatalogItemDTO.java b/src/main/java/org/eclipse/tractusx/valueaddedservice/dto/edc/CatalogItemDTO.java index 05fca5a..e1e4b53 100644 --- a/src/main/java/org/eclipse/tractusx/valueaddedservice/dto/edc/CatalogItemDTO.java +++ b/src/main/java/org/eclipse/tractusx/valueaddedservice/dto/edc/CatalogItemDTO.java @@ -30,7 +30,7 @@ @Schema(description = "Represents a catalog item available for negotiation") public class CatalogItemDTO { - @Schema(description = "Unique identifier of the catalog item", example = "1", required = true) + @Schema(description = "Unique identifier of the catalog item", example = "5191c813-97c7-4a50-8acc-5ad500772640", required = true) private String id; @Schema(description = "Identifier of the offer associated with the catalog item", example = "offer123", required = true) diff --git a/src/main/java/org/eclipse/tractusx/valueaddedservice/service/logic/EdcLogicService.java b/src/main/java/org/eclipse/tractusx/valueaddedservice/service/logic/EdcLogicService.java index 3219f22..883acd0 100644 --- a/src/main/java/org/eclipse/tractusx/valueaddedservice/service/logic/EdcLogicService.java +++ b/src/main/java/org/eclipse/tractusx/valueaddedservice/service/logic/EdcLogicService.java @@ -19,6 +19,7 @@ ********************************************************************************/ package org.eclipse.tractusx.valueaddedservice.service.logic; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; @@ -82,8 +83,8 @@ public List queryCatalog() { log.debug("Request Headers: " + headers); log.debug("Request Body: " + requestBody); - - return invokeService.executeRequest("default",consumerManagementUrl + "/v2/catalog/request/", HttpMethod.POST, httpEntity, this::mapResponseFromQueryCatalog).block(); + return getMockCatalog(); + //return invokeService.executeRequest("default",consumerManagementUrl + "/v2/catalog/request/", HttpMethod.POST, httpEntity, this::mapResponseFromQueryCatalog).block(); } // Helper methods @@ -160,5 +161,33 @@ private CatalogItemDTO processDatasetAndCreateDTO(JsonNode dataset) { + public List getMockCatalog() { + String json = "[\n" + + " {\n" + + " \"id\": \"5191c813-97c7-4a50-8acc-5ad500772640\",\n" + + " \"offerId\": \"offer123\",\n" + + " \"provider\": \"BPDMGate\",\n" + + " \"subject\": \"cx-taxo:ReadAccessPoolForCatenaXMember\",\n" + + " \"description\": \"Grants the Catena-X Member read access to the Pool API, allowing for efficient data sharing and management within the BPDM Gate.\"\n" + + " },\n" + + " {\n" + + " \"id\": \"5191c813-97c7-4a50-8acc-5ad500772642\",\n" + + " \"offerId\": \"offer124\",\n" + + " \"provider\": \"BPDMPool\",\n" + + " \"subject\": \"cx-taxo:WriteAccessPoolForCatenaXMember\",\n" + + " \"description\": \"Enables the Catena-X Member write access to the Pool API, facilitating active participation and contribution to the BPDMPool ecosystem.\"\n" + + " }\n" + + "]\n"; + + ObjectMapper objectMapper = new ObjectMapper(); + List businessPartnerDTOList = new ArrayList<>(); + try { + businessPartnerDTOList = objectMapper.readValue(json, new TypeReference>(){}); + } catch (Exception e) { + e.printStackTrace(); + } + return businessPartnerDTOList; + } + } diff --git a/src/main/java/org/eclipse/tractusx/valueaddedservice/service/logic/NegotiationServiceLogic.java b/src/main/java/org/eclipse/tractusx/valueaddedservice/service/logic/NegotiationServiceLogic.java index a78b5a2..9312b9b 100644 --- a/src/main/java/org/eclipse/tractusx/valueaddedservice/service/logic/NegotiationServiceLogic.java +++ b/src/main/java/org/eclipse/tractusx/valueaddedservice/service/logic/NegotiationServiceLogic.java @@ -19,6 +19,8 @@ ********************************************************************************/ package org.eclipse.tractusx.valueaddedservice.service.logic; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.valueaddedservice.dto.edc.EDRResponseDTO; import org.eclipse.tractusx.valueaddedservice.dto.edc.NegotiationRequestDTO; @@ -33,14 +35,10 @@ import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; -import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.time.Duration; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; @@ -74,12 +72,22 @@ public class NegotiationServiceLogic { public List triggerNegotiation(List negotiationItems) { log.info("Triggering negotiation for items: {}", negotiationItems); - List responses = Flux.fromIterable(negotiationItems) - .flatMap(dto -> - executeSequentialNegotiationRequests(dto.getId(), dto.getOfferId()) - .map(response -> new NegotiationResponseDTO(dto.getId(), dto.getOfferId(), gateProviderProtocolUrl, "Success", response.getAuthCode(), response.getEndpoint())) - .onErrorResume(e -> Mono.just(new NegotiationResponseDTO(dto.getId(), dto.getOfferId(), gateProviderProtocolUrl, "Error", null, null))) - ).collectList().block(); + List responses = new ArrayList<>(); + // Flux.fromIterable(getMockNegotiationDto()) + // .flatMap(dto -> new NegotiationResponseDTO(dto.getId(), dto.getOfferId(), gateProviderProtocolUrl, "Success", response.getAuthCode(), response.getEndpoint() ) +// Flux.fromIterable(negotiationItems) +// .flatMap(dto -> +// executeSequentialNegotiationRequests(dto.getId(), dto.getOfferId()) +// .map(response -> new NegotiationResponseDTO(dto.getId(), dto.getOfferId(), gateProviderProtocolUrl, "Success", response.getAuthCode(), response.getEndpoint())) +// .onErrorResume(e -> Mono.just(new NegotiationResponseDTO(dto.getId(), dto.getOfferId(), gateProviderProtocolUrl, "Error", null, null))) +// ).collectList().block(); + negotiationItems.forEach(each -> { + getMockNegotiationDto().forEach(eachResponse -> { + if(each.getId().equals(eachResponse.getId())){ + responses.add(new NegotiationResponseDTO(each.getId(), each.getOfferId(), gateProviderProtocolUrl, "Success", eachResponse.getAuthCode(), eachResponse.getEndpoint())); + } + }); + }); responses.stream().forEach(dto -> negotiationCache.put(dto.getId(), dto)); @@ -224,4 +232,34 @@ private HttpHeaders createHttpHeaders() { } + public List getMockNegotiationDto() { + String json = "[\n" + + " {\n" + + " \"id\": \"5191c813-97c7-4a50-8acc-5ad500772640\",\n" + + " \"offerId\": \"offer123\",\n" + + " \"provider\": \"BPDMGate\",\n" + + " \"status\": \"Success\",\n" + + " \"authCode\": \"abc123xyz890\",\n" + + " \"endpoint\": \"http://api.bpdmgate.com/negotiate/finalize\"\n" + + " },\n" + + " {\n" + + " \"id\": \"5191c813-97c7-4a50-8acc-5ad500772642\",\n" + + " \"offerId\": \"offer124\",\n" + + " \"provider\": \"BPDMPool\",\n" + + " \"status\": \"Success\",\n" + + " \"authCode\": \"def456uvw567\",\n" + + " \"endpoint\": \"http://api.bpdmpool.com/negotiate/finalize\"\n" + + " }\n" + + "]\n"; + + ObjectMapper objectMapper = new ObjectMapper(); + List businessPartnerDTOList = new ArrayList<>(); + try { + businessPartnerDTOList = objectMapper.readValue(json, new TypeReference>(){}); + } catch (Exception e) { + e.printStackTrace(); + } + return businessPartnerDTOList; + } + } diff --git a/src/main/java/org/eclipse/tractusx/valueaddedservice/service/logic/RequestLogicService.java b/src/main/java/org/eclipse/tractusx/valueaddedservice/service/logic/RequestLogicService.java index 1d355fe..f899d21 100644 --- a/src/main/java/org/eclipse/tractusx/valueaddedservice/service/logic/RequestLogicService.java +++ b/src/main/java/org/eclipse/tractusx/valueaddedservice/service/logic/RequestLogicService.java @@ -19,6 +19,8 @@ ********************************************************************************/ package org.eclipse.tractusx.valueaddedservice.service.logic; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.valueaddedservice.domain.enumeration.AddressType; import org.eclipse.tractusx.valueaddedservice.domain.enumeration.BusinessPartnerRole; @@ -82,9 +84,11 @@ public List handleRequestsToBpdm(List roles) { return Collections.emptyList(); } // Handle sequential requests by passing the map - finalDtoList.addAll(handleSequentialRequests(negotiationRequestDTOS)); + finalDtoList.addAll(getMockBusinessPartnerDTOs()); + //finalDtoList.addAll(handleSequentialRequests(negotiationRequestDTOS)); } else { - finalDtoList.addAll(handleNonSequentialRequests()); + finalDtoList.addAll(getMockBusinessPartnerDTOs()); + //finalDtoList.addAll(handleNonSequentialRequests()); } return finalDtoList; } @@ -224,6 +228,75 @@ public List getBpnsByAddressType(Map getMockBusinessPartnerDTOs() { + String json = "[\n" + + " {\n" + + " \"id\": 1,\n" + + " \"bpn\": \"BPN-0001\",\n" + + " \"legalName\": \"Divape Company\",\n" + + " \"street\": \"1st Avenue\",\n" + + " \"houseNumber\": \"100A\",\n" + + " \"zipCode\": \"633104\",\n" + + " \"city\": \"Covilhã\",\n" + + " \"country\": \"ES\",\n" + + " \"longitude\": \"107.6185727\",\n" + + " \"latitude\": \"-6.6889038\",\n" + + " \"supplier\": false,\n" + + " \"customer\": true\n" + + " },\n" + + " {\n" + + " \"id\": 2,\n" + + " \"bpn\": \"BPN-0002\",\n" + + " \"legalName\": \"Innovatech Solutions\",\n" + + " \"street\": \"Tech Park Rd\",\n" + + " \"houseNumber\": \"20B\",\n" + + " \"zipCode\": \"500010\",\n" + + " \"city\": \"Lisbon\",\n" + + " \"country\": \"DE\",\n" + + " \"longitude\": \"108.123456\",\n" + + " \"latitude\": \"-7.123456\",\n" + + " \"supplier\": true,\n" + + " \"customer\": false\n" + + " },\n" + + " {\n" + + " \"id\": 3,\n" + + " \"bpn\": \"BPN-0004\",\n" + + " \"legalName\": \"Innovatech Solutions Made Up\",\n" + + " \"street\": \"Tech Park Rd\",\n" + + " \"houseNumber\": \"20B\",\n" + + " \"zipCode\": \"500010\",\n" + + " \"city\": \"Paris\",\n" + + " \"country\": \"FR\",\n" + + " \"longitude\": \"108.123456\",\n" + + " \"latitude\": \"-7.123456\",\n" + + " \"supplier\": false,\n" + + " \"customer\": false\n" + + " },\n" + + " {\n" + + " \"id\": 3,\n" + + " \"bpn\": \"BPN-0003\",\n" + + " \"legalName\": \"Eco Friendly Packaging\",\n" + + " \"street\": \"Greenway Dr\",\n" + + " \"houseNumber\": \"5\",\n" + + " \"zipCode\": \"755004\",\n" + + " \"city\": \"Porto\",\n" + + " \"country\": \"PT\",\n" + + " \"longitude\": \"106.654321\",\n" + + " \"latitude\": \"-5.654321\",\n" + + " \"supplier\": true,\n" + + " \"customer\": true\n" + + " }\n" + + "]"; + + ObjectMapper objectMapper = new ObjectMapper(); + List businessPartnerDTOList = new ArrayList<>(); + try { + businessPartnerDTOList = objectMapper.readValue(json, new TypeReference>(){}); + } catch (Exception e) { + e.printStackTrace(); + } + return businessPartnerDTOList; + } }