-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VKT(Backend): Examiner details controller
- Loading branch information
Showing
9 changed files
with
189 additions
and
21 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
backend/vkt/src/main/java/fi/oph/vkt/api/dto/examiner/ExaminerDetailsCreateDTO.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,11 @@ | ||
package fi.oph.vkt.api.dto.examiner; | ||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
@Builder | ||
public record ExaminerDetailsCreateDTO( | ||
@NonNull String email, | ||
@NonNull Boolean examLanguageFinnish, | ||
@NonNull Boolean examLanguageSwedish | ||
) {} |
16 changes: 16 additions & 0 deletions
16
backend/vkt/src/main/java/fi/oph/vkt/api/dto/examiner/ExaminerDetailsDTO.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,16 @@ | ||
package fi.oph.vkt.api.dto.examiner; | ||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
@Builder | ||
public record ExaminerDetailsDTO( | ||
@NonNull Long id, | ||
@NonNull Integer version, | ||
@NonNull String oid, | ||
@NonNull String email, | ||
@NonNull String lastName, | ||
@NonNull String firstName, | ||
@NonNull Boolean examLanguageFinnish, | ||
@NonNull Boolean examLanguageSwedish | ||
) {} |
7 changes: 7 additions & 0 deletions
7
backend/vkt/src/main/java/fi/oph/vkt/api/dto/examiner/ExaminerDetailsInitDTO.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,7 @@ | ||
package fi.oph.vkt.api.dto.examiner; | ||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
@Builder | ||
public record ExaminerDetailsInitDTO(@NonNull String oid, @NonNull String lastName, @NonNull String firstName) {} |
41 changes: 41 additions & 0 deletions
41
backend/vkt/src/main/java/fi/oph/vkt/api/examiner/ExaminerDetailsController.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,41 @@ | ||
package fi.oph.vkt.api.examiner; | ||
|
||
import fi.oph.vkt.api.dto.examiner.ExaminerDetailsCreateDTO; | ||
import fi.oph.vkt.api.dto.examiner.ExaminerDetailsDTO; | ||
import fi.oph.vkt.api.dto.examiner.ExaminerDetailsInitDTO; | ||
import fi.oph.vkt.service.ExaminerDetailsService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import jakarta.annotation.Resource; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping(value = "/api/v1/tv/{oid}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public class ExaminerDetailsController { | ||
|
||
private static final String TAG_EXAMINER = "Examiner details API"; | ||
|
||
@Resource | ||
private ExaminerDetailsService examinerDetailsService; | ||
|
||
@GetMapping | ||
@Operation(tags = TAG_EXAMINER, summary = "Get examiner details") | ||
public ExaminerDetailsDTO getExaminerDetails(@PathVariable("oid") String oid) { | ||
return examinerDetailsService.getExaminer(oid); | ||
} | ||
|
||
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) | ||
@Operation(tags = TAG_EXAMINER, summary = "Create examiner") | ||
public ExaminerDetailsDTO createExaminer( | ||
@PathVariable("oid") String oid, | ||
@RequestBody ExaminerDetailsCreateDTO examinerDetailsCreateDTO | ||
) { | ||
return examinerDetailsService.createExaminer(oid, examinerDetailsCreateDTO); | ||
} | ||
|
||
@GetMapping(path = "/init") | ||
@Operation(tags = TAG_EXAMINER, summary = "Get examiner personal data needed for initializing examiner details") | ||
public ExaminerDetailsInitDTO getInitialExaminerDetails(@PathVariable("oid") String oid) { | ||
return examinerDetailsService.getInitialExaminerPersonalData(oid); | ||
} | ||
} |
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
106 changes: 106 additions & 0 deletions
106
backend/vkt/src/main/java/fi/oph/vkt/service/ExaminerDetailsService.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,106 @@ | ||
package fi.oph.vkt.service; | ||
|
||
import fi.oph.vkt.api.dto.examiner.ExaminerDetailsCreateDTO; | ||
import fi.oph.vkt.api.dto.examiner.ExaminerDetailsDTO; | ||
import fi.oph.vkt.api.dto.examiner.ExaminerDetailsInitDTO; | ||
import fi.oph.vkt.audit.AuditService; | ||
import fi.oph.vkt.model.Examiner; | ||
import fi.oph.vkt.repository.ExaminerRepository; | ||
import fi.oph.vkt.service.onr.OnrService; | ||
import fi.oph.vkt.service.onr.PersonalData; | ||
import fi.oph.vkt.util.exception.APIException; | ||
import fi.oph.vkt.util.exception.APIExceptionType; | ||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ExaminerDetailsService { | ||
|
||
private final ExaminerRepository examinerRepository; | ||
private final OnrService onrService; | ||
private final AuditService auditService; | ||
|
||
private PersonalData getOnrPersonalData(final String oid) { | ||
Map<String, PersonalData> oidToData = onrService.getOnrPersonalData(List.of(oid)); | ||
return oidToData.get(oid); | ||
} | ||
|
||
private static ExaminerDetailsDTO toExaminerDetailsDTO(final Examiner examiner) { | ||
return ExaminerDetailsDTO | ||
.builder() | ||
.id(examiner.getId()) | ||
.version(examiner.getVersion()) | ||
.oid(examiner.getOid()) | ||
.lastName(examiner.getLastName()) | ||
.firstName(examiner.getFirstName()) | ||
.email(examiner.getEmail()) | ||
.examLanguageFinnish(examiner.isExamLanguageFinnish()) | ||
.examLanguageSwedish(examiner.isExamLanguageSwedish()) | ||
.build(); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public ExaminerDetailsInitDTO getInitialExaminerPersonalData(final String oid) { | ||
// TODO Audit log entry | ||
if (examinerRepository.findByOid(oid).isPresent()) { | ||
throw new APIException(APIExceptionType.EXAMINER_ALREADY_INITIALIZED); | ||
} | ||
PersonalData personalData = this.getOnrPersonalData(oid); | ||
if (personalData == null) { | ||
throw new APIException(APIExceptionType.EXAMINER_ONR_NOT_FOUND); | ||
} | ||
return ExaminerDetailsInitDTO | ||
.builder() | ||
.oid(oid) | ||
.lastName(personalData.getLastName()) | ||
.firstName(personalData.getFirstName()) | ||
.build(); | ||
} | ||
|
||
@Transactional | ||
public ExaminerDetailsDTO createExaminer(final String oid, ExaminerDetailsCreateDTO examinerDetailsCreateDTO) { | ||
// TODO Audit log entry | ||
if (examinerRepository.findByOid(oid).isPresent()) { | ||
throw new APIException(APIExceptionType.EXAMINER_ALREADY_INITIALIZED); | ||
} | ||
PersonalData personalData = this.getOnrPersonalData(oid); | ||
if (personalData == null) { | ||
throw new APIException(APIExceptionType.EXAMINER_ONR_NOT_FOUND); | ||
} | ||
Examiner examiner = new Examiner(); | ||
examiner.setOid(oid); | ||
examiner.setLastName(personalData.getLastName()); | ||
examiner.setFirstName(personalData.getFirstName()); | ||
examiner.setNickname(personalData.getNickname()); | ||
examiner.setEmail(examinerDetailsCreateDTO.email()); | ||
examiner.setExamLanguageFinnish(examinerDetailsCreateDTO.examLanguageFinnish()); | ||
examiner.setExamLanguageSwedish(examinerDetailsCreateDTO.examLanguageSwedish()); | ||
examinerRepository.saveAndFlush(examiner); | ||
|
||
return toExaminerDetailsDTO(examiner); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public ExaminerDetailsDTO getExaminer(final String oid) { | ||
// TODO Audit log entry | ||
Examiner examiner = examinerRepository.getByOid(oid); | ||
return toExaminerDetailsDTO(examiner); | ||
} | ||
|
||
@Transactional | ||
public void updateStoredPersonalData() { | ||
final List<String> onrIds = examinerRepository.listExistingOnrIds(); | ||
final Map<String, PersonalData> oidToPersonalData = onrService.getOnrPersonalData(onrIds); | ||
oidToPersonalData.forEach((k, v) -> { | ||
Examiner examiner = examinerRepository.getByOid(k); | ||
examiner.setLastName(v.getLastName()); | ||
examiner.setFirstName(v.getFirstName()); | ||
examiner.setNickname(v.getNickname()); | ||
examinerRepository.saveAndFlush(examiner); | ||
}); | ||
} | ||
} |
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