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

Commit

Permalink
Merge pull request #127 from eclipse-tractusx/fix/remove-mocks-for-bp…
Browse files Browse the repository at this point in the history
…dm-data

Adapt to new data model of BPDM Gate & Pool
  • Loading branch information
fabiodmota authored Apr 15, 2024
2 parents 4f0fed2 + bd5a909 commit d32b609
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
********************************************************************************/
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 @@ -71,17 +69,15 @@ public class RequestLogicService {

@Cacheable(value = "vas-bpdm", key = "{#root.methodName , {#roles}}", unless = "#result == null")
public List<BusinessPartnerDTO> handleRequestsToBpdm(List<String> roles) {
List<BusinessPartnerDTO> finalDtoList = getMockBusinessPartnerDTOs();
//if (sequentialRequestsEnabled) {
// finalDtoList.addAll(handleSequentialRequests());
// } else {
// finalDtoList.addAll(handleNonSequentialRequests());
// }
return getMockBusinessPartnerDTOs();
List<BusinessPartnerDTO> finalDtoList = new ArrayList<>();
if (sequentialRequestsEnabled) {
finalDtoList.addAll(handleSequentialRequests());
} else {
finalDtoList.addAll(handleNonSequentialRequests());
}
return finalDtoList;
}



private List<BusinessPartnerDTO> handleSequentialRequests() {
List<BusinessPartnerDTO> finalDtoList = new ArrayList<>();

Expand Down Expand Up @@ -136,22 +132,24 @@ private List<BusinessPartnerDTO> handleNonSequentialRequests() {

log.info("Starting process to fetch external business partners from legal entity on pool.");
List<String> bpnlList = getBpnsByAddressType(map, AddressType.LegalAddress);
httpEntity = createHttpEntity(bpnlList);
Map<String, List<String>> legalEntityBody = new HashMap<>();
legalEntityBody.put("bpnLs", bpnlList);
httpEntity = createHttpEntity(legalEntityBody);
List<PoolLegalEntityDto> poolLegalEntityDtos = invokeService.executeRequest("pool", bpdmLegalUrl, HttpMethod.POST, httpEntity, JsonMappingUtils::mapToListOfPoolLegalEntityDto).block();
log.info("Processed business partners from legal entity on pool, list size {}", poolLegalEntityDtos.size());

log.info("Starting process to fetch external business partners from site on pool.");
List<String> bpnsList = getBpnsByAddressType(map, AddressType.SiteMainAddress);
Map<String, List<String>> sitesBody = new HashMap<>();
sitesBody.put("sites", bpnsList);
sitesBody.put("siteBpns", bpnsList);
httpEntity = createHttpEntity(sitesBody);
List<PoolSiteDto> poolSiteDtos = invokeService.executeRequest("pool", bpdmSiteUrl, HttpMethod.POST, httpEntity, JsonMappingUtils::mapJsonToListOfPoolSiteDto).block();
log.info("Processed business partners from site on pool, list size {}", poolSiteDtos.size());

log.info("Starting process to fetch external business partners from address on pool.");
List<String> bpnaList = getBpnsByAddressType(map, AddressType.AdditionalAddress);
Map<String, List<String>> addressesBody = new HashMap<>();
addressesBody.put("addresses", bpnaList);
addressesBody.put("addressBpns", bpnaList);
httpEntity = createHttpEntity(addressesBody);

List<PoolAddressDto> poolAddressDtos = invokeService.executeRequest("pool", bpdmAddressUrl, HttpMethod.POST, httpEntity, JsonMappingUtils::mapJsonToListOfPoolAddressDto).block();
Expand Down Expand Up @@ -203,75 +201,6 @@ 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;
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ public static List<GateBusinessPartnerOutputDto> mapContentToListOfBusinessPartn
}
}
public static List<PoolLegalEntityDto> mapToListOfPoolLegalEntityDto(String jsonResponse) {

try {
return objectMapper.readValue(jsonResponse, new TypeReference<>() {
});
JsonNode rootNode = objectMapper.readTree(jsonResponse);
JsonNode contentNode = rootNode.path("content");
return objectMapper.readValue(contentNode.toString(), new TypeReference<List<PoolLegalEntityDto>>() {});
} catch (Exception e) {
throw new RuntimeException("Error mapping JSON to List<PoolLegalEntityDto>", e);
}
Expand Down

0 comments on commit d32b609

Please sign in to comment.