Skip to content

Commit

Permalink
[kbss-cvut/record-manager-ui#203] Change method name to findUsedRecor…
Browse files Browse the repository at this point in the history
…dsPhases
  • Loading branch information
palagdan committed Aug 8, 2024
1 parent fede72f commit 5b5c69f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ private <T> Page<T> findRecords(RecordFilterParams filters, Pageable pageSpec, C
return new PageImpl<>(records, pageSpec, totalCount);
}

public Set<RecordPhase> findAllAvailableRecordsPhases(){
return em.createNativeQuery("SELECT ?o WHERE { ?s ?p ?o } ", String.class)
.setParameter("p", URI.create(Vocabulary.s_p_has_phase))
public Set<RecordPhase> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -86,8 +84,8 @@ public List<PatientRecordDto> getRecords(

@PreAuthorize("hasRole('" + SecurityConstants.ROLE_ADMIN + "') or @securityUtils.isMemberOfInstitution(#institutionKey)")
@GetMapping(value="availablePhases", produces = MediaType.APPLICATION_JSON_VALUE)
public Set<RecordPhase> getAvailableRecordPhases(@RequestParam(value = "institution", required = false) String institutionKey){
return recordService.findAllAvailableRecordsPhases();
public Set<RecordPhase> getUsedRecordsPhases(@RequestParam(value = "institution", required = false) String institutionKey){
return recordService.findUsedRecordsPhases();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public interface PatientRecordService extends BaseService<PatientRecord> {
*
* @return Set of all available record phases
*/
Set<RecordPhase> findAllAvailableRecordsPhases();
Set<RecordPhase> findUsedRecordsPhases();


}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Page<RawRecord> exportRecords(RecordFilterParams filters, Pageable pageSp

@Transactional(readOnly = true)
@Override
public Set<RecordPhase> findAllAvailableRecordsPhases() {
return recordDao.findAllAvailableRecordsPhases();
public Set<RecordPhase> findUsedRecordsPhases() {
return recordDao.findUsedRecordsPhases();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ public void getRecordThrowsNotFoundWhenReportIsNotFound() throws Exception {
}

@Test
public void testGetAvailableRecordPhases() throws Exception{
public void testGetUsedRecordsPhases() throws Exception{

Set<RecordPhase> 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();
Expand Down

0 comments on commit 5b5c69f

Please sign in to comment.