diff --git a/backend/akr/src/main/java/fi/oph/akr/onr/ContactDetailsUtil.java b/backend/akr/src/main/java/fi/oph/akr/onr/ContactDetailsUtil.java index bf048a8de..7086f08db 100644 --- a/backend/akr/src/main/java/fi/oph/akr/onr/ContactDetailsUtil.java +++ b/backend/akr/src/main/java/fi/oph/akr/onr/ContactDetailsUtil.java @@ -15,6 +15,7 @@ import static java.util.Comparator.nullsLast; import fi.oph.akr.api.dto.translator.TranslatorAddressDTO; +import fi.oph.akr.model.Translator; import fi.oph.akr.onr.dto.ContactDetailsDTO; import fi.oph.akr.onr.dto.ContactDetailsGroupDTO; import fi.oph.akr.onr.dto.ContactDetailsGroupSource; @@ -26,6 +27,7 @@ import java.util.Collection; import java.util.Comparator; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -193,8 +195,16 @@ static PersonalDataDTO combineContactDetails( return personalDataDTO; } - public static TranslatorAddressDTO getPrimaryAddress(final PersonalData personalData) { - return personalData.getAddress().get(0); + public static TranslatorAddressDTO getPrimaryAddress(final PersonalData personalData, final Translator translator) { + return personalData + .getAddress() + .stream() + .filter(addr -> + addr.source().toString().equals(translator.getSelectedSource()) && + addr.type().toString().equals(translator.getSelectedType()) + ) + .findFirst() + .orElse(personalData.getAddress().get(0)); } public static List getAddresses(final List contactDetailGroups) { diff --git a/backend/akr/src/main/java/fi/oph/akr/onr/mock/PersonalDataFactory.java b/backend/akr/src/main/java/fi/oph/akr/onr/mock/PersonalDataFactory.java index cc66f33c8..b94f3076a 100644 --- a/backend/akr/src/main/java/fi/oph/akr/onr/mock/PersonalDataFactory.java +++ b/backend/akr/src/main/java/fi/oph/akr/onr/mock/PersonalDataFactory.java @@ -46,6 +46,15 @@ public PersonalData create(final String onrId) { .country(countries.next()) .source(ContactDetailsGroupSource.AKR) .type(ContactDetailsGroupType.AKR_OSOITE) + .build(), + TranslatorAddressDTO + .builder() + .street(streetsVTJ.next()) + .postalCode(postalCodesVTJ.next()) + .town(townsVTJ.next()) + .country(countriesVTJ.next()) + .source(ContactDetailsGroupSource.VTJ) + .type(ContactDetailsGroupType.VAKINAINEN_ULKOMAAN_OSOITE) .build() ) ) @@ -252,4 +261,21 @@ private static Iterator cyclicIterator(final String... values) { ); private final Iterator countries = cyclicIterator("Suomi", "suomi", "SUOMI", "Finland", "", null); + + private final Iterator streetsVTJ = cyclicIterator( + "Downing Street 1", + null + ); + + private final Iterator postalCodesVTJ = cyclicIterator( + "00100", + null + ); + + private final Iterator townsVTJ = cyclicIterator( + "London", + null + ); + + private final Iterator countriesVTJ = cyclicIterator("UK", "DEU", "", null); } diff --git a/backend/akr/src/main/java/fi/oph/akr/service/ClerkTranslatorService.java b/backend/akr/src/main/java/fi/oph/akr/service/ClerkTranslatorService.java index 8cfad5eb2..971f10114 100644 --- a/backend/akr/src/main/java/fi/oph/akr/service/ClerkTranslatorService.java +++ b/backend/akr/src/main/java/fi/oph/akr/service/ClerkTranslatorService.java @@ -151,8 +151,8 @@ private List createClerkTranslatorDTOs( private boolean isAddressSelected(final Translator translator, final TranslatorAddressDTO address) { return ( - translator.getSelectedSource().equals(address.source().toString()) && - translator.getSelectedType().equals(address.type().toString()) + address.source().toString().equals(translator.getSelectedSource()) && + address.type().toString().equals(translator.getSelectedType()) ); } @@ -166,6 +166,7 @@ private List createTranslatorAddressDTO( .map(addr -> ClerkTranslatorAddressDTO .builder() + .street(addr.street()) .town(addr.town()) .postalCode(addr.postalCode()) .country(addr.country()) @@ -326,15 +327,18 @@ private PersonalData createPersonalData(final String onrId, final TranslatorDTOC .email(dto.email()) .phoneNumber(dto.phoneNumber()) .address( - dto.address().stream().map(addr -> - TranslatorAddressDTO - .builder() - .town(addr.town()) - .country(addr.country()) - .street(addr.street()) - .source(addr.source()) - .type(addr.type()) - .build() + dto + .address() + .stream() + .map(addr -> + TranslatorAddressDTO + .builder() + .town(addr.town()) + .country(addr.country()) + .street(addr.street()) + .source(addr.source()) + .type(addr.type()) + .build() ) .toList() ) diff --git a/backend/akr/src/main/java/fi/oph/akr/service/PublicTranslatorService.java b/backend/akr/src/main/java/fi/oph/akr/service/PublicTranslatorService.java index 11b2543e9..1fc9ff9db 100644 --- a/backend/akr/src/main/java/fi/oph/akr/service/PublicTranslatorService.java +++ b/backend/akr/src/main/java/fi/oph/akr/service/PublicTranslatorService.java @@ -109,7 +109,7 @@ private PublicTranslatorDTO toDTO( final PersonalData personalData, final List languagePairDTOS ) { - final TranslatorAddressDTO primaryAddress = ContactDetailsUtil.getPrimaryAddress(personalData); + final TranslatorAddressDTO primaryAddress = ContactDetailsUtil.getPrimaryAddress(personalData, translator); final String country = getNonFinlandCountryCode(primaryAddress); final Pair townTranslated = postalCodeService.translateTown(primaryAddress.town()); return PublicTranslatorDTO @@ -138,7 +138,7 @@ private List getDistinctTowns( .stream() .map(translator -> { final PersonalData personalData = personalDatas.get(translator.getOnrId()); - final TranslatorAddressDTO primaryAddress = ContactDetailsUtil.getPrimaryAddress(personalData); + final TranslatorAddressDTO primaryAddress = ContactDetailsUtil.getPrimaryAddress(personalData, translator); if (personalData == null || !StringUtils.hasText(primaryAddress.town())) { return null; diff --git a/frontend/packages/akr/public/i18n/fi-FI/translation.json b/frontend/packages/akr/public/i18n/fi-FI/translation.json index e6c6df249..22df21b8e 100644 --- a/frontend/packages/akr/public/i18n/fi-FI/translation.json +++ b/frontend/packages/akr/public/i18n/fi-FI/translation.json @@ -119,7 +119,10 @@ }, "address": { "alkupera1": "VTJ", - "yhteystietotyyppi4": "Vakinainen, kotimaa" + "yhteystietotyyppi4": "Vakinainen, kotimaa", + "yhteystietotyyppi5": "Vakinainen, ulkomaa", + "alkupera8": "AKR", + "yhteystietotyyppi14": "AKR" }, "caveats": { "isNotAssuranceGiven": "Auktorisoinnit eivät ole näkyvissä julkisessa listauksessa!"