From 5b5c69f2d0c0df82af0c12a9594e9f15f4f63991 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Thu, 8 Aug 2024 18:07:10 +0200 Subject: [PATCH] [kbss-cvut/record-manager-ui#203] Change method name to findUsedRecordsPhases --- .../cvut/kbss/study/persistence/dao/PatientRecordDao.java | 6 +++--- .../cz/cvut/kbss/study/rest/PatientRecordController.java | 6 ++---- .../cz/cvut/kbss/study/service/PatientRecordService.java | 2 +- .../service/repository/RepositoryPatientRecordService.java | 4 ++-- .../cvut/kbss/study/rest/PatientRecordControllerTest.java | 4 ++-- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/study/persistence/dao/PatientRecordDao.java b/src/main/java/cz/cvut/kbss/study/persistence/dao/PatientRecordDao.java index d7f4e445..2a9ffb93 100644 --- a/src/main/java/cz/cvut/kbss/study/persistence/dao/PatientRecordDao.java +++ b/src/main/java/cz/cvut/kbss/study/persistence/dao/PatientRecordDao.java @@ -236,9 +236,9 @@ private Page findRecords(RecordFilterParams filters, Pageable pageSpec, C return new PageImpl<>(records, pageSpec, totalCount); } - public Set findAllAvailableRecordsPhases(){ - return em.createNativeQuery("SELECT ?o WHERE { ?s ?p ?o } ", String.class) - .setParameter("p", URI.create(Vocabulary.s_p_has_phase)) + public Set findUsedRecordsPhases(){ + return em.createNativeQuery("SELECT ?phase WHERE { ?record ?hasPhase ?phase } ", String.class) + .setParameter("hasPhase", URI.create(Vocabulary.s_p_has_phase)) .getResultList() .stream() .map(RecordPhase::fromIri) diff --git a/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java b/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java index cb64f01a..7d4f6a55 100644 --- a/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java +++ b/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java @@ -8,7 +8,6 @@ import cz.cvut.kbss.study.exception.NotFoundException; import cz.cvut.kbss.study.model.PatientRecord; import cz.cvut.kbss.study.model.RecordPhase; -import cz.cvut.kbss.study.model.User; import cz.cvut.kbss.study.model.export.RawRecord; import cz.cvut.kbss.study.persistence.dao.util.RecordFilterParams; import cz.cvut.kbss.study.rest.event.PaginatedResultRetrievedEvent; @@ -42,7 +41,6 @@ import java.io.InputStream; import java.net.URI; import java.util.*; -import java.util.stream.Collectors; import java.util.stream.Stream; @RestController @@ -86,8 +84,8 @@ public List getRecords( @PreAuthorize("hasRole('" + SecurityConstants.ROLE_ADMIN + "') or @securityUtils.isMemberOfInstitution(#institutionKey)") @GetMapping(value="availablePhases", produces = MediaType.APPLICATION_JSON_VALUE) - public Set getAvailableRecordPhases(@RequestParam(value = "institution", required = false) String institutionKey){ - return recordService.findAllAvailableRecordsPhases(); + public Set getUsedRecordsPhases(@RequestParam(value = "institution", required = false) String institutionKey){ + return recordService.findUsedRecordsPhases(); } diff --git a/src/main/java/cz/cvut/kbss/study/service/PatientRecordService.java b/src/main/java/cz/cvut/kbss/study/service/PatientRecordService.java index d942101a..1df82dec 100644 --- a/src/main/java/cz/cvut/kbss/study/service/PatientRecordService.java +++ b/src/main/java/cz/cvut/kbss/study/service/PatientRecordService.java @@ -100,7 +100,7 @@ public interface PatientRecordService extends BaseService { * * @return Set of all available record phases */ - Set findAllAvailableRecordsPhases(); + Set findUsedRecordsPhases(); } diff --git a/src/main/java/cz/cvut/kbss/study/service/repository/RepositoryPatientRecordService.java b/src/main/java/cz/cvut/kbss/study/service/repository/RepositoryPatientRecordService.java index 5d6f2529..3d188aae 100644 --- a/src/main/java/cz/cvut/kbss/study/service/repository/RepositoryPatientRecordService.java +++ b/src/main/java/cz/cvut/kbss/study/service/repository/RepositoryPatientRecordService.java @@ -134,7 +134,7 @@ public Page exportRecords(RecordFilterParams filters, Pageable pageSp @Transactional(readOnly = true) @Override - public Set findAllAvailableRecordsPhases() { - return recordDao.findAllAvailableRecordsPhases(); + public Set findUsedRecordsPhases() { + return recordDao.findUsedRecordsPhases(); } } diff --git a/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java b/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java index 15a640f1..80595c99 100644 --- a/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java +++ b/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java @@ -96,11 +96,11 @@ public void getRecordThrowsNotFoundWhenReportIsNotFound() throws Exception { } @Test - public void testGetAvailableRecordPhases() throws Exception{ + public void testGetUsedRecordsPhases() throws Exception{ Set phases = new HashSet<>(Arrays.asList(RecordPhase.completed, RecordPhase.valid)); - when(patientRecordServiceMock.findAllAvailableRecordsPhases()).thenReturn(phases); + when(patientRecordServiceMock.findUsedRecordsPhases()).thenReturn(phases); final MvcResult result = mockMvc.perform(get("/records/availablePhases")) .andReturn();