From 1cc3345c615bcbc5eccf730aa794c252d891eeea Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Thu, 24 Oct 2024 12:00:40 +0200 Subject: [PATCH 1/7] [#205] Implement records.allowedRejectMessage property --- src/main/java/cz/cvut/kbss/study/util/ConfigParam.java | 5 ++++- src/main/resources/config.properties | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/study/util/ConfigParam.java b/src/main/java/cz/cvut/kbss/study/util/ConfigParam.java index 0ee9caf6..1b75c554 100644 --- a/src/main/java/cz/cvut/kbss/study/util/ConfigParam.java +++ b/src/main/java/cz/cvut/kbss/study/util/ConfigParam.java @@ -41,7 +41,10 @@ public enum ConfigParam { OIDC_ROLE_CLAIM("oidc.roleClaim"), - CORS_ALLOWED_ORIGINS("cors.allowedOrigins"); + CORS_ALLOWED_ORIGINS("cors.allowedOrigins"), + + RECORDS_ALLOWED_REJECT_MESSAGE("records.allowedRejectMessage"); + private final String name; diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index ce8e8d90..c5f1375c 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -61,4 +61,6 @@ security.provider=internal oidc.roleClaim=realm_access.roles # Configures allowed origins for CORS (e.g. http://localhost:3000). Use a comma to separate multiple values -cors.allowedOrigins= \ No newline at end of file +cors.allowedOrigins= + +records.allowedRejectMessage=true \ No newline at end of file From 0f7dc85c63c7b9cb1a854524f95082f0e58a3c85 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Thu, 24 Oct 2024 12:01:13 +0200 Subject: [PATCH 2/7] [#205] Add a field rejectMessage to PatientRecord --- .../cz/cvut/kbss/study/dto/PatientRecordDto.java | 12 ++++++++++++ .../java/cz/cvut/kbss/study/model/PatientRecord.java | 12 ++++++++++++ src/main/resources/model.ttl | 3 +++ 3 files changed, 27 insertions(+) diff --git a/src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java b/src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java index 8dddf25e..f5adf31f 100644 --- a/src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java +++ b/src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java @@ -41,6 +41,10 @@ public class PatientRecordDto extends AbstractEntity implements HasOwlKey { @OWLObjectProperty(iri = Vocabulary.s_p_has_phase) private RecordPhase phase; + @OWLDataProperty(iri = Vocabulary.s_p_has_reject_message) + private String rejectMessage; + + @Override public String getKey() { return key; @@ -115,6 +119,14 @@ public void setPhase(RecordPhase phase) { this.phase = phase; } + public String getRejectMessage() { + return rejectMessage; + } + + public void setRejectMessage(String rejectMessage) { + this.rejectMessage = rejectMessage; + } + @Override public String toString() { return "PatientRecordDto{" + diff --git a/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java b/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java index 3184e3d9..43925dbf 100644 --- a/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java +++ b/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java @@ -59,6 +59,9 @@ public class PatientRecord implements Serializable, HasOwlKey, HasUri { @OWLObjectProperty(iri = Vocabulary.s_p_has_phase, cascade = {CascadeType.MERGE}, fetch = FetchType.EAGER) private RecordPhase phase; + @OWLDataProperty(iri = Vocabulary.s_p_has_reject_message) + private String rejectMessage; + @Override public URI getUri() { return uri; @@ -146,6 +149,15 @@ public RecordPhase getPhase() { return phase; } + public String getRejectMessage() { + return rejectMessage; + } + + public void setRejectMessage(String rejectMessage) { + this.rejectMessage = rejectMessage; + } + + public void setPhase(RecordPhase phase) { this.phase = phase; } diff --git a/src/main/resources/model.ttl b/src/main/resources/model.ttl index 863b9d68..35261110 100644 --- a/src/main/resources/model.ttl +++ b/src/main/resources/model.ttl @@ -132,6 +132,9 @@ rm:token rdf:type owl:DatatypeProperty . rdf:type owl:DatatypeProperty . +### http://onto.fel.cvut.cz/ontologies/record-manager/has-reject-message +rm:has-reject-message rdf:type owl:DatatypeProperty . + ################################################################# # Classes ################################################################# From 24447aadccd585ea397985f28ebdca7d82a09802 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Thu, 24 Oct 2024 12:01:58 +0200 Subject: [PATCH 3/7] [#205] Implement endpoint to get a allowedRejectMessage settings --- .../cz/cvut/kbss/study/rest/PatientRecordController.java | 5 +++++ 1 file changed, 5 insertions(+) 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 73199e0d..30820861 100644 --- a/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java +++ b/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java @@ -354,4 +354,9 @@ public void removeRecord(@PathVariable("key") String key) { LOG.trace("Patient record {} successfully removed.", toRemove); } } + + @GetMapping(value = "/allowedRejectMessage", produces = MediaType.APPLICATION_JSON_VALUE) + public boolean getAllowRejectMessageEnabled(){ + return configReader.getConfig(ConfigParam.RECORDS_ALLOWED_REJECT_MESSAGE).equals("true"); + } } From a38040b048bb305c104939c70904d220af833810 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Thu, 24 Oct 2024 15:47:07 +0200 Subject: [PATCH 4/7] [#205] Refactor endpoint name --- .../java/cz/cvut/kbss/study/rest/PatientRecordController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 30820861..610eb52b 100644 --- a/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java +++ b/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java @@ -356,7 +356,7 @@ public void removeRecord(@PathVariable("key") String key) { } @GetMapping(value = "/allowedRejectMessage", produces = MediaType.APPLICATION_JSON_VALUE) - public boolean getAllowRejectMessageEnabled(){ + public boolean getAllowedRejectMessage(){ return configReader.getConfig(ConfigParam.RECORDS_ALLOWED_REJECT_MESSAGE).equals("true"); } } From 55bac0cf508f92c693a58ae6c79a6f24278d1851 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Thu, 24 Oct 2024 15:47:28 +0200 Subject: [PATCH 5/7] [#205] Implement getAllowedRejectMessage tests --- .../rest/PatientRecordControllerTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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 a82504ef..138ba96e 100644 --- a/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java +++ b/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java @@ -15,8 +15,10 @@ import cz.cvut.kbss.study.persistence.dao.util.RecordSort; import cz.cvut.kbss.study.rest.event.PaginatedResultRetrievedEvent; import cz.cvut.kbss.study.rest.util.RestUtils; +import cz.cvut.kbss.study.service.ConfigReader; import cz.cvut.kbss.study.service.PatientRecordService; import cz.cvut.kbss.study.service.UserService; +import cz.cvut.kbss.study.util.ConfigParam; import cz.cvut.kbss.study.util.Constants; import cz.cvut.kbss.study.util.IdentificationUtils; import org.junit.jupiter.api.BeforeEach; @@ -65,6 +67,9 @@ public class PatientRecordControllerTest extends BaseControllerTestRunner { @Mock private ApplicationEventPublisher eventPublisherMock; + @Mock + private ConfigReader configReaderMock; + @Mock private UserService userService; @@ -487,4 +492,30 @@ void exportRecordsPublishesPagingEvent() throws Exception { final PaginatedResultRetrievedEvent event = captor.getValue(); assertEquals(page, event.getPage()); } + + @Test + void getAllowedRejectMessageTrue() throws Exception { + String expectedValue = "true"; + when(configReaderMock.getConfig(ConfigParam.RECORDS_ALLOWED_REJECT_MESSAGE)).thenReturn(expectedValue); + final MvcResult result = mockMvc.perform(get("/records/allowedRejectMessage").param("institution", user.getInstitution().toString())).andReturn(); + + final String body = objectMapper.readValue(result.getResponse().getContentAsString(), + new TypeReference<>() { + }); + assertEquals(result.getResponse().getStatus(), HttpStatus.OK.value()); + assertEquals(expectedValue, body); + } + + @Test + void getAllowedRejectMessageFalse() throws Exception { + String expectedValue = "false"; + when(configReaderMock.getConfig(ConfigParam.RECORDS_ALLOWED_REJECT_MESSAGE)).thenReturn(expectedValue); + final MvcResult result = mockMvc.perform(get("/records/allowedRejectMessage").param("institution", user.getInstitution().toString())).andReturn(); + + final String body = objectMapper.readValue(result.getResponse().getContentAsString(), + new TypeReference<>() { + }); + assertEquals(result.getResponse().getStatus(), HttpStatus.OK.value()); + assertEquals(expectedValue, body); + } } From fadeaabe38df9b863ba50ced8f53674a8729916b Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Thu, 24 Oct 2024 16:49:20 +0200 Subject: [PATCH 6/7] [#205] Update preUpdate method --- .../service/repository/RepositoryPatientRecordService.java | 3 +++ 1 file changed, 3 insertions(+) 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 896c5c4a..bb30ada7 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 @@ -73,6 +73,9 @@ protected void prePersist(PatientRecord instance) { @Override protected void preUpdate(PatientRecord instance) { + if(instance.getPhase() != RecordPhase.rejected) { + instance.setRejectMessage(null); + } instance.setLastModifiedBy(securityUtils.getCurrentUser()); instance.setLastModified(new Date()); recordDao.requireUniqueNonEmptyLocalName(instance); From 722b84d25c96064a6d9bcb8d4c813f058f7002b5 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Tue, 5 Nov 2024 12:32:36 +0100 Subject: [PATCH 7/7] [#205] Refactor: Rename rejectMessage to rejectReason --- .../cz/cvut/kbss/study/dto/PatientRecordDto.java | 12 ++++++------ .../java/cz/cvut/kbss/study/model/PatientRecord.java | 12 ++++++------ .../kbss/study/rest/PatientRecordController.java | 6 +++--- .../repository/RepositoryPatientRecordService.java | 2 +- .../java/cz/cvut/kbss/study/util/ConfigParam.java | 2 +- src/main/resources/config.properties | 2 +- src/main/resources/model.ttl | 4 ++-- .../kbss/study/rest/PatientRecordControllerTest.java | 12 ++++++------ 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java b/src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java index f5adf31f..0ff51b43 100644 --- a/src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java +++ b/src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java @@ -41,8 +41,8 @@ public class PatientRecordDto extends AbstractEntity implements HasOwlKey { @OWLObjectProperty(iri = Vocabulary.s_p_has_phase) private RecordPhase phase; - @OWLDataProperty(iri = Vocabulary.s_p_has_reject_message) - private String rejectMessage; + @OWLDataProperty(iri = Vocabulary.s_p_reject_reason) + private String rejectReason; @Override @@ -119,12 +119,12 @@ public void setPhase(RecordPhase phase) { this.phase = phase; } - public String getRejectMessage() { - return rejectMessage; + public String getRejectReason() { + return rejectReason; } - public void setRejectMessage(String rejectMessage) { - this.rejectMessage = rejectMessage; + public void setRejectReason(String rejectReason) { + this.rejectReason = rejectReason; } @Override diff --git a/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java b/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java index 43925dbf..84cec452 100644 --- a/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java +++ b/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java @@ -59,8 +59,8 @@ public class PatientRecord implements Serializable, HasOwlKey, HasUri { @OWLObjectProperty(iri = Vocabulary.s_p_has_phase, cascade = {CascadeType.MERGE}, fetch = FetchType.EAGER) private RecordPhase phase; - @OWLDataProperty(iri = Vocabulary.s_p_has_reject_message) - private String rejectMessage; + @OWLDataProperty(iri = Vocabulary.s_p_reject_reason) + private String rejectReason; @Override public URI getUri() { @@ -149,12 +149,12 @@ public RecordPhase getPhase() { return phase; } - public String getRejectMessage() { - return rejectMessage; + public String getRejectReason() { + return rejectReason; } - public void setRejectMessage(String rejectMessage) { - this.rejectMessage = rejectMessage; + public void setRejectReason(String rejectReason) { + this.rejectReason = rejectReason; } 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 610eb52b..aac31673 100644 --- a/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java +++ b/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java @@ -355,8 +355,8 @@ public void removeRecord(@PathVariable("key") String key) { } } - @GetMapping(value = "/allowedRejectMessage", produces = MediaType.APPLICATION_JSON_VALUE) - public boolean getAllowedRejectMessage(){ - return configReader.getConfig(ConfigParam.RECORDS_ALLOWED_REJECT_MESSAGE).equals("true"); + @GetMapping(value = "/allowedRejectReason", produces = MediaType.APPLICATION_JSON_VALUE) + public boolean getAllowedRejectReason(){ + return configReader.getConfig(ConfigParam.RECORDS_ALLOWED_REJECT_REASON).equals("true"); } } 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 bb30ada7..69fa886a 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 @@ -74,7 +74,7 @@ protected void prePersist(PatientRecord instance) { @Override protected void preUpdate(PatientRecord instance) { if(instance.getPhase() != RecordPhase.rejected) { - instance.setRejectMessage(null); + instance.setRejectReason(null); } instance.setLastModifiedBy(securityUtils.getCurrentUser()); instance.setLastModified(new Date()); diff --git a/src/main/java/cz/cvut/kbss/study/util/ConfigParam.java b/src/main/java/cz/cvut/kbss/study/util/ConfigParam.java index 1b75c554..818bc1c6 100644 --- a/src/main/java/cz/cvut/kbss/study/util/ConfigParam.java +++ b/src/main/java/cz/cvut/kbss/study/util/ConfigParam.java @@ -43,7 +43,7 @@ public enum ConfigParam { CORS_ALLOWED_ORIGINS("cors.allowedOrigins"), - RECORDS_ALLOWED_REJECT_MESSAGE("records.allowedRejectMessage"); + RECORDS_ALLOWED_REJECT_REASON("records.allowedRejectReason"); private final String name; diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index c5f1375c..68ec6da6 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -63,4 +63,4 @@ oidc.roleClaim=realm_access.roles # Configures allowed origins for CORS (e.g. http://localhost:3000). Use a comma to separate multiple values cors.allowedOrigins= -records.allowedRejectMessage=true \ No newline at end of file +records.allowedRejectReason=true \ No newline at end of file diff --git a/src/main/resources/model.ttl b/src/main/resources/model.ttl index 35261110..379c2e74 100644 --- a/src/main/resources/model.ttl +++ b/src/main/resources/model.ttl @@ -132,8 +132,8 @@ rm:token rdf:type owl:DatatypeProperty . rdf:type owl:DatatypeProperty . -### http://onto.fel.cvut.cz/ontologies/record-manager/has-reject-message -rm:has-reject-message rdf:type owl:DatatypeProperty . +### http://onto.fel.cvut.cz/ontologies/record-manager/reject-reason +rm:reject-reason rdf:type owl:DatatypeProperty . ################################################################# # Classes 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 138ba96e..0917640d 100644 --- a/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java +++ b/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java @@ -494,10 +494,10 @@ void exportRecordsPublishesPagingEvent() throws Exception { } @Test - void getAllowedRejectMessageTrue() throws Exception { + void getAllowedRejectReasonTrue() throws Exception { String expectedValue = "true"; - when(configReaderMock.getConfig(ConfigParam.RECORDS_ALLOWED_REJECT_MESSAGE)).thenReturn(expectedValue); - final MvcResult result = mockMvc.perform(get("/records/allowedRejectMessage").param("institution", user.getInstitution().toString())).andReturn(); + when(configReaderMock.getConfig(ConfigParam.RECORDS_ALLOWED_REJECT_REASON)).thenReturn(expectedValue); + final MvcResult result = mockMvc.perform(get("/records/allowedRejectReason").param("institution", user.getInstitution().toString())).andReturn(); final String body = objectMapper.readValue(result.getResponse().getContentAsString(), new TypeReference<>() { @@ -507,10 +507,10 @@ void getAllowedRejectMessageTrue() throws Exception { } @Test - void getAllowedRejectMessageFalse() throws Exception { + void getAllowedRejectReasonFalse() throws Exception { String expectedValue = "false"; - when(configReaderMock.getConfig(ConfigParam.RECORDS_ALLOWED_REJECT_MESSAGE)).thenReturn(expectedValue); - final MvcResult result = mockMvc.perform(get("/records/allowedRejectMessage").param("institution", user.getInstitution().toString())).andReturn(); + when(configReaderMock.getConfig(ConfigParam.RECORDS_ALLOWED_REJECT_REASON)).thenReturn(expectedValue); + final MvcResult result = mockMvc.perform(get("/records/allowedRejectReason").param("institution", user.getInstitution().toString())).andReturn(); final String body = objectMapper.readValue(result.getResponse().getContentAsString(), new TypeReference<>() {