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

Change Mapping country to iso code on logic service #125

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# Changelog

## [1.3.2] - [unreleased]

### Changed
- Changed Mapping from Country to ISOCode
- Fix vulnerability on spring boot web version upgrade to 6.2.3

## [1.3.1] - [2024-02-29]

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</parent>
<groupId>org.eclipse.tractusx</groupId>
<artifactId>value-added-service</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
<name>vas-country-risk-backend</name>
<description>Project to Validate Country Risks Score</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@Repository
public interface CountryRepository extends JpaRepository<Country, Long> {

List<Country> findByCountryIn(List<String> stringList);
List<Country> findByIso2In(List<String> stringList);

Optional<Country> findByCountry(String countryName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface DataSourceValueRepository extends JpaRepository<DataSourceValue
@Query("select new org.eclipse.tractusx.valueaddedservice.dto.DataDTO(dsv.country,dsv.score,ds.dataSourceName,dsv.iso3,dsv.iso2,dsv.continent) " +
"from DataSource ds INNER JOIN DataSourceValue dsv " +
"ON dsv.dataSource.id = ds.id " +
"and dsv.country in ?2 " +
"and dsv.iso2 in ?2 " +
"and ds.dataSourceName in ?3 "+
"and ds.yearPublished = ?4 "+
"and dsv.score > ?1 ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public CountryService(CountryRepository countryRepository, CountryMapper country
}

@Transactional(readOnly = true)
public List<CountryDTO> findByCountryIn(List<String> stringList){
return countryMapper.toDto(countryRepository.findByCountryIn(stringList));
public List<CountryDTO> findByIso2In(List<String> stringList){
return countryMapper.toDto(countryRepository.findByIso2In(stringList));
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public List<CountryDTO> getAssociatedCountries (CompanyUserDTO companyUserDTO,St
countryList = externalBusinessPartnersLogicService.getExternalPartnersCountry(companyUserDTO,token,roles);

List<CountryDTO> countryDTOS;
countryDTOS = countryService.findByCountryIn(countryList);
countryDTOS = countryService.findByIso2In(countryList);

return countryDTOS;
}
Expand Down
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 @@ -69,15 +71,17 @@ public class RequestLogicService {

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



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

Expand Down Expand Up @@ -199,6 +203,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;
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private DashBoardTableDTO setBusinessPartnerProps(BusinessPartnerDTO businessPar
}

private DashBoardTableDTO mapScoreForEachBpn(DashBoardTableDTO d, List<DataDTO> dataDTOS,List<RatingDTO> ratingDTOS){
List<DataDTO> dataSourceForCountry = dataDTOS.stream().filter(each -> each.getCountry().equalsIgnoreCase(d.getCountry())).toList();
List<DataDTO> dataSourceForCountry = dataDTOS.stream().filter(each -> each.getIso2().equalsIgnoreCase(d.getCountry())).toList();
final float[] generalFormulaTotal = {0F};
final String[] ratingsList = {""};
final float[] totalRatedByUser = {0F};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static void mapAddressDetails(BusinessPartnerDTO businessPartnerDTO, Pool
businessPartnerDTO.setStreet(physicalAddress.getStreet().getName());
businessPartnerDTO.setHouseNumber(physicalAddress.getStreet().getHouseNumber());
businessPartnerDTO.setCity(physicalAddress.getCity());
businessPartnerDTO.setCountry(physicalAddress.getCountry());
businessPartnerDTO.setCountry(physicalAddress.getPoolCountry().getTechnicalKey());
businessPartnerDTO.setZipCode(physicalAddress.getPostalCode());
if (physicalAddress.getGeographicCoordinates() != null) {
GateGeoCoordinateDto coordinates = physicalAddress.getGeographicCoordinates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void getAssociatedCountriesWhenCompanyUserDTONotNullThenReturnListOfCountries()
countryDTO.setContinent("Europe");
countryDTOList.add(countryDTO);

when(countryService.findByCountryIn(anyList())).thenReturn(countryDTOList);
when(countryService.findByIso2In(anyList())).thenReturn(countryDTOList);

List<CountryDTO> result = countryLogicService.getAssociatedCountries(companyUserDTO, "", new ArrayList<>());

Expand Down