-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OTR(Backend & Frontend) OPHOTRKEH-248: NPE/Enum korjaus kun ONR-tiedot muuttuneet #587
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0c7b469
OTR(Backend) OPHOTRKEH-248: NPE fix when interpreter is not found fro…
jrkkp 071d757
OTR(Backend) OPHOTRKEH-248: NPE fix when not found from cache. Also f…
jrkkp 0268171
OTR(Backend) OPHOTRKEH-248: test for ONR response deserialization
jrkkp f2437f5
OTR(Backend) OPHOTRKEH-248: test for ONR response deserialization
jrkkp cf63254
OTR(Frontend) OPHOTRKEH-248: show alert if interpreters are not synch…
jrkkp 98a1f94
OTR(Frontend) OPHOTRKEH-248: mock-up endpoint for missing interpreter…
jrkkp 937c577
OTR(Frontend) OPHOTRKEH-248: error handler for missing interpreters […
jrkkp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
backend/otr/src/main/java/fi/oph/otr/onr/dto/ContactDetailsGroupSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
backend/otr/src/main/java/fi/oph/otr/onr/dto/ContactDetailsGroupType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,10 +34,13 @@ | |
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import lombok.RequiredArgsConstructor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
|
@@ -69,13 +72,24 @@ public class ClerkInterpreterService { | |
@Resource | ||
private final AuditService auditService; | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(ClerkInterpreterService.class); | ||
|
||
@Transactional(readOnly = true) | ||
public List<ClerkInterpreterDTO> list() { | ||
final List<ClerkInterpreterDTO> result = listWithoutAudit(); | ||
auditService.logOperation(OtrOperation.LIST_INTERPRETERS); | ||
return result; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @transactional ymmärtääkseni vaikuttaa vain tietokantakutsuihin, tuossa sillä ei ole väliä, koska tietokantaa ei kutsuta. |
||
public List<String> listMissing() { | ||
final List<Interpreter> interpreters = interpreterRepository.findExistingInterpreters(); | ||
final Map<String, PersonalData> personalDatas = onrService.getCachedPersonalDatas(); | ||
auditService.logOperation(OtrOperation.LIST_INTERPRETERS); | ||
|
||
return interpreters.stream().map(Interpreter::getOnrId).filter(onrId -> personalDatas.get(onrId) == null).toList(); | ||
} | ||
|
||
private List<ClerkInterpreterDTO> listWithoutAudit() { | ||
final Map<Long, List<InterpreterRegionProjection>> interpreterRegionProjections = regionRepository | ||
.listInterpreterRegionProjections() | ||
|
@@ -105,16 +119,22 @@ private List<ClerkInterpreterDTO> listWithoutAudit() { | |
|
||
return createClerkInterpreterDTO(interpreter, personalData, qualifications, regionProjections); | ||
}) | ||
.filter(Optional::isPresent) | ||
.map(Optional::get) | ||
.sorted(Comparator.comparing(ClerkInterpreterDTO::lastName).thenComparing(ClerkInterpreterDTO::nickName)) | ||
.toList(); | ||
} | ||
|
||
private ClerkInterpreterDTO createClerkInterpreterDTO( | ||
private Optional<ClerkInterpreterDTO> createClerkInterpreterDTO( | ||
final Interpreter interpreter, | ||
final PersonalData personalData, | ||
final List<Qualification> qualifications, | ||
final List<InterpreterRegionProjection> regionProjections | ||
) { | ||
if (personalData == null) { | ||
LOG.error("Personal data by onr id {} not found", interpreter.getOnrId()); | ||
return Optional.empty(); | ||
} | ||
final List<String> regions = regionProjections.stream().map(InterpreterRegionProjection::code).toList(); | ||
|
||
final List<ClerkQualificationDTO> qualificationDTOs = qualifications | ||
|
@@ -127,30 +147,32 @@ private ClerkInterpreterDTO createClerkInterpreterDTO( | |
.toList(); | ||
final ClerkInterpreterQualificationsDTO interpreterQualificationsDTO = splitQualificationDTOs(qualificationDTOs); | ||
|
||
return ClerkInterpreterDTO | ||
.builder() | ||
.id(interpreter.getId()) | ||
.version(interpreter.getVersion()) | ||
.isIndividualised(personalData.getIndividualised()) | ||
.hasIndividualisedAddress(personalData.getHasIndividualisedAddress()) | ||
.identityNumber(personalData.getIdentityNumber()) | ||
.lastName(personalData.getLastName()) | ||
.firstName(personalData.getFirstName()) | ||
.nickName(personalData.getNickName()) | ||
.email(personalData.getEmail()) | ||
.permissionToPublishEmail(interpreter.isPermissionToPublishEmail()) | ||
.phoneNumber(personalData.getPhoneNumber()) | ||
.permissionToPublishPhone(interpreter.isPermissionToPublishPhone()) | ||
.otherContactInfo(interpreter.getOtherContactInformation()) | ||
.permissionToPublishOtherContactInfo(interpreter.isPermissionToPublishOtherContactInfo()) | ||
.street(personalData.getStreet()) | ||
.postalCode(personalData.getPostalCode()) | ||
.town(personalData.getTown()) | ||
.country(personalData.getCountry()) | ||
.extraInformation(interpreter.getExtraInformation()) | ||
.regions(regions) | ||
.qualifications(interpreterQualificationsDTO) | ||
.build(); | ||
return Optional.of( | ||
ClerkInterpreterDTO | ||
.builder() | ||
.id(interpreter.getId()) | ||
.version(interpreter.getVersion()) | ||
.isIndividualised(personalData.getIndividualised()) | ||
.hasIndividualisedAddress(personalData.getHasIndividualisedAddress()) | ||
.identityNumber(personalData.getIdentityNumber()) | ||
.lastName(personalData.getLastName()) | ||
.firstName(personalData.getFirstName()) | ||
.nickName(personalData.getNickName()) | ||
.email(personalData.getEmail()) | ||
.permissionToPublishEmail(interpreter.isPermissionToPublishEmail()) | ||
.phoneNumber(personalData.getPhoneNumber()) | ||
.permissionToPublishPhone(interpreter.isPermissionToPublishPhone()) | ||
.otherContactInfo(interpreter.getOtherContactInformation()) | ||
.permissionToPublishOtherContactInfo(interpreter.isPermissionToPublishOtherContactInfo()) | ||
.street(personalData.getStreet()) | ||
.postalCode(personalData.getPostalCode()) | ||
.town(personalData.getTown()) | ||
.country(personalData.getCountry()) | ||
.extraInformation(interpreter.getExtraInformation()) | ||
.regions(regions) | ||
.qualifications(interpreterQualificationsDTO) | ||
.build() | ||
); | ||
} | ||
|
||
private ClerkQualificationDTO createQualificationDTO(final Qualification qualification) { | ||
|
@@ -341,7 +363,7 @@ public ClerkInterpreterDTO getInterpreter(final long interpreterId) { | |
|
||
private ClerkInterpreterDTO getInterpreterWithoutAudit(final long interpreterId) { | ||
// This could be optimized, by fetching only one interpreter and it's data, but is it worth of the programming work? | ||
for (ClerkInterpreterDTO i : listWithoutAudit()) { | ||
for (final ClerkInterpreterDTO i : listWithoutAudit()) { | ||
if (i.id() == interpreterId) { | ||
return i; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
backend/otr/src/test/java/fi/oph/otr/onr/OnrRequestTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package fi.oph.otr.onr; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import fi.oph.otr.onr.model.PersonalData; | ||
import fi.vm.sade.javautils.nio.cas.CasClient; | ||
import java.io.IOException; | ||
import java.util.Optional; | ||
import org.asynchttpclient.Response; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.security.test.context.support.WithMockUser; | ||
|
||
@WithMockUser | ||
@DataJpaTest | ||
class OnrRequestTest { | ||
|
||
@Value("classpath:json/henkilo-hetu-response.json") | ||
private org.springframework.core.io.Resource hetuRequestResponse; | ||
|
||
@Test | ||
void testFindPersonByIdentityNumberDeserializes() throws Exception { | ||
final Response response = mock(Response.class); | ||
final CasClient casClient = mock(CasClient.class); | ||
final OnrOperationApiImpl onrOperationApi = new OnrOperationApiImpl(casClient, "http://localhost"); | ||
|
||
when(casClient.executeBlocking(any())).thenReturn(response); | ||
when(response.getStatusCode()).thenReturn(200); | ||
when(response.getResponseBody()).thenReturn(getHetuMockJsonResponse()); | ||
|
||
final Optional<PersonalData> personalDataOptional = onrOperationApi.findPersonalDataByIdentityNumber("54321-54312"); | ||
|
||
assertTrue(personalDataOptional.isPresent()); | ||
} | ||
|
||
private String getHetuMockJsonResponse() throws IOException { | ||
return new String(hetuRequestResponse.getInputStream().readAllBytes()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pitäisikö se lisätä myös ContactDetailsGroupType? Siihen voi myös tulla uusia tyyppejä.