Skip to content

Commit

Permalink
AKR(Backend & Frontend) ONR multiple address feature continues
Browse files Browse the repository at this point in the history
  • Loading branch information
jrkkp committed Feb 9, 2024
1 parent b8d128d commit d2eca11
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 16 deletions.
14 changes: 12 additions & 2 deletions backend/akr/src/main/java/fi/oph/akr/onr/ContactDetailsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<TranslatorAddressDTO> getAddresses(final List<ContactDetailsGroupDTO> contactDetailGroups) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
)
Expand Down Expand Up @@ -252,4 +261,21 @@ private static Iterator<String> cyclicIterator(final String... values) {
);

private final Iterator<String> countries = cyclicIterator("Suomi", "suomi", "SUOMI", "Finland", "", null);

private final Iterator<String> streetsVTJ = cyclicIterator(
"Downing Street 1",
null
);

private final Iterator<String> postalCodesVTJ = cyclicIterator(
"00100",
null
);

private final Iterator<String> townsVTJ = cyclicIterator(
"London",
null
);

private final Iterator<String> countriesVTJ = cyclicIterator("UK", "DEU", "", null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ private List<ClerkTranslatorDTO> 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())
);
}

Expand All @@ -166,6 +166,7 @@ private List<ClerkTranslatorAddressDTO> createTranslatorAddressDTO(
.map(addr ->
ClerkTranslatorAddressDTO
.builder()
.street(addr.street())
.town(addr.town())
.postalCode(addr.postalCode())
.country(addr.country())
Expand Down Expand Up @@ -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()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private PublicTranslatorDTO toDTO(
final PersonalData personalData,
final List<LanguagePairDTO> languagePairDTOS
) {
final TranslatorAddressDTO primaryAddress = ContactDetailsUtil.getPrimaryAddress(personalData);
final TranslatorAddressDTO primaryAddress = ContactDetailsUtil.getPrimaryAddress(personalData, translator);
final String country = getNonFinlandCountryCode(primaryAddress);
final Pair<String, String> townTranslated = postalCodeService.translateTown(primaryAddress.town());
return PublicTranslatorDTO
Expand Down Expand Up @@ -138,7 +138,7 @@ private List<PublicTownDTO> 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;
Expand Down
5 changes: 4 additions & 1 deletion frontend/packages/akr/public/i18n/fi-FI/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down

0 comments on commit d2eca11

Please sign in to comment.