Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
release(backend): with catalog and negotiation mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiodmota committed Apr 20, 2024
1 parent ea8f3ee commit d82f73f
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,8 +83,8 @@ public List<CatalogItemDTO> 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
Expand Down Expand Up @@ -160,5 +161,33 @@ private CatalogItemDTO processDatasetAndCreateDTO(JsonNode dataset) {



public List<CatalogItemDTO> 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<CatalogItemDTO> businessPartnerDTOList = new ArrayList<>();
try {
businessPartnerDTOList = objectMapper.readValue(json, new TypeReference<List<CatalogItemDTO>>(){});
} catch (Exception e) {
e.printStackTrace();
}
return businessPartnerDTOList;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -74,12 +72,22 @@ public class NegotiationServiceLogic {
public List<NegotiationResponseDTO> triggerNegotiation(List<NegotiationRequestDTO> negotiationItems) {
log.info("Triggering negotiation for items: {}", negotiationItems);

List<NegotiationResponseDTO> 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<NegotiationResponseDTO> 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));

Expand Down Expand Up @@ -224,4 +232,34 @@ private HttpHeaders createHttpHeaders() {
}


public List<NegotiationResponseDTO> 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<NegotiationResponseDTO> businessPartnerDTOList = new ArrayList<>();
try {
businessPartnerDTOList = objectMapper.readValue(json, new TypeReference<List<NegotiationResponseDTO>>(){});
} catch (Exception e) {
e.printStackTrace();
}
return businessPartnerDTOList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,9 +84,11 @@ public List<BusinessPartnerDTO> handleRequestsToBpdm(List<String> 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;
}
Expand Down Expand Up @@ -224,6 +228,75 @@ public List<String> getBpnsByAddressType(Map<AddressType, Map<String, Collection



public List<BusinessPartnerDTO> 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<BusinessPartnerDTO> businessPartnerDTOList = new ArrayList<>();
try {
businessPartnerDTOList = objectMapper.readValue(json, new TypeReference<List<BusinessPartnerDTO>>(){});
} catch (Exception e) {
e.printStackTrace();
}
return businessPartnerDTOList;
}


}

0 comments on commit d82f73f

Please sign in to comment.