From eb2819198f873c789610121334baf41a8e9f3358 Mon Sep 17 00:00:00 2001 From: Miroslav Blasko Date: Wed, 5 Jun 2024 15:52:39 +0200 Subject: [PATCH 1/2] [kbss-cvut/record-manager-ui#168] Add filtering of records according to form templates --- .../persistence/dao/PatientRecordDao.java | 7 +++++ .../dao/util/RecordFilterParams.java | 17 +++++++++-- .../study/rest/util/RecordFilterMapper.java | 7 +++++ .../persistence/dao/PatientRecordDaoTest.java | 30 ++++++++++++++++--- .../rest/PatientRecordControllerTest.java | 8 ++--- .../rest/util/RecordFilterMapperTest.java | 10 +++---- 6 files changed, 64 insertions(+), 15 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 cb72d921..6fd233ef 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 @@ -240,6 +240,7 @@ private Page findRecords(RecordFilterParams filters, Pageable pageSpec, C private void setQueryParameters(TypedQuery query, Map queryParams) { query.setParameter("type", typeUri) .setParameter("hasPhase", URI.create(Vocabulary.s_p_has_phase)) + .setParameter("hasFormTemplate", URI.create(Vocabulary.s_p_has_form_template)) .setParameter("hasInstitution", URI.create(Vocabulary.s_p_was_treated_at)) .setParameter("hasKey", URI.create(Vocabulary.s_p_key)) @@ -256,6 +257,7 @@ private static String constructWhereClause(RecordFilterParams filters, Map new LangString(id, Constants.PU_LANGUAGE)).collect(Collectors.toList())); + } return String.join(" ", filters); } diff --git a/src/main/java/cz/cvut/kbss/study/persistence/dao/util/RecordFilterParams.java b/src/main/java/cz/cvut/kbss/study/persistence/dao/util/RecordFilterParams.java index 337934a2..bdd383d0 100644 --- a/src/main/java/cz/cvut/kbss/study/persistence/dao/util/RecordFilterParams.java +++ b/src/main/java/cz/cvut/kbss/study/persistence/dao/util/RecordFilterParams.java @@ -17,6 +17,8 @@ public class RecordFilterParams { private LocalDate maxModifiedDate = LocalDate.now(); + private Set formTemplateIds = Collections.emptySet(); + private Set phaseIds = Collections.emptySet(); public RecordFilterParams() { @@ -28,11 +30,12 @@ public RecordFilterParams(String institutionKey) { // This one mainly is for test data setup public RecordFilterParams(String institutionKey, LocalDate minModifiedDate, LocalDate maxModifiedDate, - Set phaseIds) { + Set phaseIds, Set formTemplateIds) { this.institutionKey = institutionKey; this.minModifiedDate = minModifiedDate; this.maxModifiedDate = maxModifiedDate; this.phaseIds = phaseIds; + this.formTemplateIds = formTemplateIds; } public Optional getInstitutionKey() { @@ -59,6 +62,14 @@ public void setMaxModifiedDate(LocalDate maxModifiedDate) { this.maxModifiedDate = maxModifiedDate; } + public Set getFormTemplateIds() { + return formTemplateIds; + } + + public void setFormTemplateIds(Set formTemplateIds) { + this.formTemplateIds = formTemplateIds; + } + public Set getPhaseIds() { return phaseIds; } @@ -78,12 +89,13 @@ public boolean equals(Object o) { return Objects.equals(institutionKey, that.institutionKey) && Objects.equals(minModifiedDate, that.minModifiedDate) && Objects.equals(maxModifiedDate, that.maxModifiedDate) + && Objects.equals(formTemplateIds, that.formTemplateIds) && Objects.equals(phaseIds, that.phaseIds); } @Override public int hashCode() { - return Objects.hash(institutionKey, minModifiedDate, maxModifiedDate, phaseIds); + return Objects.hash(institutionKey, minModifiedDate, maxModifiedDate, formTemplateIds, phaseIds); } @Override @@ -92,6 +104,7 @@ public String toString() { "institutionKey='" + institutionKey + '\'' + ", minModifiedDate=" + minModifiedDate + ", maxModifiedDate=" + maxModifiedDate + + ", formTemplateIds=" + formTemplateIds + ", phaseIds=" + phaseIds + '}'; } diff --git a/src/main/java/cz/cvut/kbss/study/rest/util/RecordFilterMapper.java b/src/main/java/cz/cvut/kbss/study/rest/util/RecordFilterMapper.java index d565f059..a3473cd0 100644 --- a/src/main/java/cz/cvut/kbss/study/rest/util/RecordFilterMapper.java +++ b/src/main/java/cz/cvut/kbss/study/rest/util/RecordFilterMapper.java @@ -3,6 +3,7 @@ import cz.cvut.kbss.study.model.RecordPhase; import cz.cvut.kbss.study.persistence.dao.util.RecordFilterParams; import cz.cvut.kbss.study.rest.exception.BadRequestException; +import java.util.HashSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.LinkedMultiValueMap; @@ -30,6 +31,8 @@ public class RecordFilterMapper { private static final String INSTITUTION_KEY_PARAM = "institution"; + private static final String FORM_TEMPLATE_ID_PARAM = "formTemplate"; + private static final String PHASE_ID_PARAM = "phase"; /** @@ -69,6 +72,10 @@ public static RecordFilterParams constructRecordFilter(MultiValueMap RecordPhase.fromIriOrName(s).getIri()).collect(Collectors.toSet())); + + result.setFormTemplateIds( + new HashSet<>(params.getOrDefault(FORM_TEMPLATE_ID_PARAM, Collections.emptyList())) + ); return result; } diff --git a/src/test/java/cz/cvut/kbss/study/persistence/dao/PatientRecordDaoTest.java b/src/test/java/cz/cvut/kbss/study/persistence/dao/PatientRecordDaoTest.java index dac6c38f..c6ec6d77 100644 --- a/src/test/java/cz/cvut/kbss/study/persistence/dao/PatientRecordDaoTest.java +++ b/src/test/java/cz/cvut/kbss/study/persistence/dao/PatientRecordDaoTest.java @@ -277,7 +277,7 @@ void findAllFullReturnsRecordsMatchingSpecifiedDatePeriod() { }).toList(); final Page result = - sut.findAllRecordsFull(new RecordFilterParams(null, minDate, maxDate, Collections.emptySet()), + sut.findAllRecordsFull(new RecordFilterParams(null, minDate, maxDate, Collections.emptySet(), Collections.emptySet()), Pageable.unpaged()); assertFalse(result.isEmpty()); assertThat(result.getContent(), containsSameEntities(expected)); @@ -316,7 +316,7 @@ void findAllFullReturnsRecordsMatchingSpecifiedDatePeriodAndInstitution() { }).toList(); final Page result = - sut.findAllRecordsFull(new RecordFilterParams(institution.getKey(), minDate, maxDate, Collections.emptySet()), + sut.findAllRecordsFull(new RecordFilterParams(institution.getKey(), minDate, maxDate, Collections.emptySet(), Collections.emptySet()), Pageable.unpaged()); assertFalse(result.isEmpty()); assertThat(result.getContent(), containsSameEntities(expected)); @@ -327,7 +327,7 @@ void findAllFullReturnsRecordsMatchingSpecifiedPhase() { final User author = generateAuthorWithInstitution(); final List allRecords = generateRecordsForAuthor(author, 5); transactional(() -> allRecords.forEach(r -> { - r.setPhase(RecordPhase.values()[Generator.randomInt(RecordPhase.values().length)]); + r.setPhase(RecordPhase.values()[Generator.randomInt(0, RecordPhase.values().length)]); persistRecordWithIdentification(r); })); final RecordPhase phase = allRecords.get(Generator.randomIndex(allRecords)).getPhase(); @@ -339,6 +339,28 @@ void findAllFullReturnsRecordsMatchingSpecifiedPhase() { result.forEach(res -> assertEquals(phase, res.getPhase())); } + @Test + void findAllFullReturnsRecordsMatchingSpecifiedFormTemplate() { + String[] formTemplates = new String[]{ + "http://example.org/form-template-1", + "http://example.org/form-template-2" + }; + final User author = generateAuthorWithInstitution(); + final List allRecords = generateRecordsForAuthor(author, 5); + transactional(() -> allRecords.forEach(r -> { + r.setFormTemplate(formTemplates[Generator.randomInt(0, formTemplates.length)]); + persistRecordWithIdentification(r); + })); + final String formTemplate = allRecords.get(Generator.randomIndex(allRecords)).getFormTemplate(); + final RecordFilterParams filterParams = new RecordFilterParams(); + filterParams.setFormTemplateIds(Set.of(formTemplate)); + + final Page result = sut.findAllRecordsFull(filterParams, Pageable.unpaged()); + assertFalse(result.isEmpty()); + result.forEach(res -> assertEquals(formTemplate, res.getFormTemplate())); + } + + @Test void findAllFullReturnsRecordsMatchingSpecifiedPage() { final User author = generateAuthorWithInstitution(); @@ -408,7 +430,7 @@ void findAllRecordsReturnsPageWithMatchingRecords() { final int pageSize = 3; final Page result = - sut.findAllRecords(new RecordFilterParams(null, minDate, maxDate, Collections.emptySet()), + sut.findAllRecords(new RecordFilterParams(null, minDate, maxDate, Collections.emptySet(), Collections.emptySet()), PageRequest.of(0, pageSize, Sort.Direction.ASC, RecordSort.SORT_DATE_PROPERTY)); assertEquals(Math.min(pageSize, allMatching.size()), result.getNumberOfElements()); assertEquals(allMatching.size(), result.getTotalElements()); 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 901120cb..fbbeea2f 100644 --- a/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java +++ b/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java @@ -263,7 +263,7 @@ void exportRecordsParsesProvidedDateBoundsAndPassesThemToService() throws Except }); assertThat(result, containsSameEntities(records)); verify(patientRecordServiceMock).findAllFull( - new RecordFilterParams(null, minDate, maxDate, Collections.emptySet()), Pageable.unpaged()); + new RecordFilterParams(null, minDate, maxDate, Collections.emptySet(), Collections.emptySet()), Pageable.unpaged()); } @Test @@ -298,7 +298,7 @@ void exportRecordsExportsRecordsForProvidedInstitutionForSpecifiedPeriod() throw }); assertThat(result, containsSameEntities(records)); verify(patientRecordServiceMock).findAllFull( - new RecordFilterParams(user.getInstitution().getKey(), minDate, maxDate, Collections.emptySet()), + new RecordFilterParams(user.getInstitution().getKey(), minDate, maxDate, Collections.emptySet(), Collections.emptySet()), Pageable.unpaged()); } @@ -369,7 +369,7 @@ void getRecordsResolvesPagingConfigurationFromRequestParameters() throws Excepti }); assertThat(result, containsSameEntities(records)); verify(patientRecordServiceMock).findAllFull( - new RecordFilterParams(null, minDate, maxDate, Collections.emptySet()), + new RecordFilterParams(null, minDate, maxDate, Collections.emptySet(), Collections.emptySet()), PageRequest.of(page, pageSize, Sort.Direction.DESC, RecordSort.SORT_DATE_PROPERTY)); } @@ -417,7 +417,7 @@ void exportRecordsPublishesPagingEvent() throws Exception { }); assertThat(result, containsSameEntities(records)); verify(patientRecordServiceMock).findAllFull( - new RecordFilterParams(null, minDate, maxDate, Collections.emptySet()), PageRequest.of(0, 50)); + new RecordFilterParams(null, minDate, maxDate, Collections.emptySet(), Collections.emptySet()), PageRequest.of(0, 50)); final ArgumentCaptor captor = ArgumentCaptor.forClass(PaginatedResultRetrievedEvent.class); verify(eventPublisherMock).publishEvent(captor.capture()); diff --git a/src/test/java/cz/cvut/kbss/study/rest/util/RecordFilterMapperTest.java b/src/test/java/cz/cvut/kbss/study/rest/util/RecordFilterMapperTest.java index ec36d28d..e4535703 100644 --- a/src/test/java/cz/cvut/kbss/study/rest/util/RecordFilterMapperTest.java +++ b/src/test/java/cz/cvut/kbss/study/rest/util/RecordFilterMapperTest.java @@ -30,27 +30,27 @@ static Stream testValues() { Arguments.of(new LinkedMultiValueMap<>(Map.of( "minDate", List.of(LocalDate.now().minusYears(1).toString()) )), new RecordFilterParams(null, LocalDate.now().minusYears(1), LocalDate.now(), - Collections.emptySet())), + Collections.emptySet(), Collections.emptySet())), Arguments.of(new LinkedMultiValueMap<>(Map.of( "minDate", List.of(LocalDate.now().minusYears(1).toString()), "maxDate", List.of(LocalDate.now().minusDays(1).toString()) )), new RecordFilterParams(null, LocalDate.now().minusYears(1), LocalDate.now().minusDays(1), - Collections.emptySet())), + Collections.emptySet(), Collections.emptySet())), Arguments.of(new LinkedMultiValueMap<>(Map.of( "institution", List.of("1111111") - )), new RecordFilterParams("1111111", LocalDate.EPOCH, LocalDate.now(), Collections.emptySet())), + )), new RecordFilterParams("1111111", LocalDate.EPOCH, LocalDate.now(), Collections.emptySet(), Collections.emptySet())), Arguments.of(new LinkedMultiValueMap<>(Map.of( "institution", List.of("1111111"), "phase", List.of(RecordPhase.open.getIri(), RecordPhase.completed.name()) )), new RecordFilterParams("1111111", LocalDate.EPOCH, LocalDate.now(), - Set.of(RecordPhase.open.getIri(), RecordPhase.completed.getIri()))), + Set.of(RecordPhase.open.getIri(), RecordPhase.completed.getIri()), Collections.emptySet())), Arguments.of(new LinkedMultiValueMap<>(Map.of( "minDate", List.of(LocalDate.now().minusYears(1).toString()), "maxDate", List.of(LocalDate.now().minusDays(1).toString()), "institution", List.of("1111111"), "phase", List.of(RecordPhase.published.name()) )), new RecordFilterParams("1111111", LocalDate.now().minusYears(1), LocalDate.now().minusDays(1), - Set.of(RecordPhase.published.getIri()))) + Set.of(RecordPhase.published.getIri()), Collections.emptySet())) ); } } \ No newline at end of file From 1a1e84d1717f36276d820f7ba297b5360b030728 Mon Sep 17 00:00:00 2001 From: Miroslav Blasko Date: Thu, 6 Jun 2024 11:13:15 +0200 Subject: [PATCH 2/2] [Upd] Upgrade JOPA version from snapshot to release - Also remove deprecated configuration --- pom.xml | 30 ++----------------- .../cvut/kbss/study/config/WebAppConfig.java | 4 --- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/pom.xml b/pom.xml index 5ba25417..afbbfc74 100644 --- a/pom.xml +++ b/pom.xml @@ -15,39 +15,13 @@ OFN Record Manager jar - - - - central-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - central-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - UTF-8 17 ${jdk.version} ${jdk.version} - 2.0.0-SNAPSHOT + 2.0.0 4.11.0 1.5.5.Final @@ -101,7 +75,7 @@ com.github.ledsoft jopa-spring-transaction - 0.3.0-SNAPSHOT + 0.3.0 diff --git a/src/main/java/cz/cvut/kbss/study/config/WebAppConfig.java b/src/main/java/cz/cvut/kbss/study/config/WebAppConfig.java index 8034cf95..f74a86f1 100644 --- a/src/main/java/cz/cvut/kbss/study/config/WebAppConfig.java +++ b/src/main/java/cz/cvut/kbss/study/config/WebAppConfig.java @@ -5,10 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import cz.cvut.kbss.jopa.sessions.UnitOfWorkImpl; import cz.cvut.kbss.study.rest.servlet.DiagnosticsContextFilter; import cz.cvut.kbss.study.util.Constants; -import cz.cvut.kbss.study.util.json.ManageableIgnoreMixin; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -46,8 +44,6 @@ public static ObjectMapper createJsonObjectMapper() { final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - // Ignore UoW references injected into entities - objectMapper.addMixIn(UnitOfWorkImpl.class, ManageableIgnoreMixin.class); // JSR 310 (Java 8 DateTime API) objectMapper.registerModule(new JavaTimeModule()); // Serialize datetime as ISO strings