From 4e7dddb7659bd0fffa73036c93c93de4d9c4964a Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 7 Dec 2023 17:10:02 +0100 Subject: [PATCH 01/15] [#29] Extend record manager ontology with generic record states. --- src/main/resources/model.ttl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/resources/model.ttl b/src/main/resources/model.ttl index 39067f2b..4ac5e451 100644 --- a/src/main/resources/model.ttl +++ b/src/main/resources/model.ttl @@ -74,6 +74,10 @@ rm:relates-to rdf:type owl:ObjectProperty . rm:was-treated-at rdf:type owl:ObjectProperty ; rdfs:subPropertyOf rm:relates-to . +### http://onto.fel.cvut.cz/ontologies/record-manager/has-state +rm:has-state rdf:type owl:ObjectProperty ; + rdfs:label "has-state"@en . + ################################################################# # Data properties @@ -163,5 +167,28 @@ rm:user rdf:type owl:Class ; rm:impersonator rdf:type owl:Class ; rdfs:label "Impersonator"@en . +### http://onto.fel.cvut.cz/ontologies/record-manager/record-state +rm:record-state rdf:type owl:Class ; + rdfs:label "record state"@en . + +### http://onto.fel.cvut.cz/ontologies/record-manager/open-record-state +rm:open-record-state rdf:type owl:Class ; + rdfs:subClassOf rm:record-state ; + rdfs:label "open record state"@en . + +### http://onto.fel.cvut.cz/ontologies/record-manager/valid-record-state +rm:valid-record-state rdf:type owl:Class ; + rdfs:subClassOf rm:record-state ; + rdfs:label "valid record state"@en . + +### http://onto.fel.cvut.cz/ontologies/record-manager/completed-record-state +rm:completed-record-state rdf:type owl:Class ; + rdfs:subClassOf rm:record-state ; + rdfs:label "completed record state"@en . + +### http://onto.fel.cvut.cz/ontologies/record-manager/published-record-state +rm:published-record-state rdf:type owl:Class ; + rdfs:subClassOf rm:record-state ; + rdfs:label "published record state"@en . ### Generated by the OWL API (version 4.2.8.20170104-2310) https://github.com/owlcs/owlapi From ff09c7709a97b18cf0cdd3cbad36e80679e829ab Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 7 Dec 2023 17:11:17 +0100 Subject: [PATCH 02/15] [#29] Add state object property to PatientRecord --- .../java/cz/cvut/kbss/study/model/PatientRecord.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 f64db877..12e21807 100644 --- a/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java +++ b/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java @@ -52,6 +52,9 @@ public class PatientRecord implements Serializable, HasOwlKey { CascadeType.REMOVE}, fetch = FetchType.EAGER) private Question question; + @OWLObjectProperty(iri = Vocabulary.s_p_has_state) + private URI state; + public URI getUri() { return uri; } @@ -134,6 +137,14 @@ public void setFormTemplate(String formTemplate) { this.formTemplate = formTemplate; } + public URI getState() { + return state; + } + + public void setState(URI state) { + this.state = state; + } + @Override public String toString() { return "PatientRecord{" + From e6cdb6f9b5670cb3e709a9dd3940ac0868060ed9 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Fri, 8 Dec 2023 09:03:50 +0100 Subject: [PATCH 03/15] [#29] Fix label of rm:has-state --- src/main/resources/model.ttl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/model.ttl b/src/main/resources/model.ttl index 4ac5e451..d62553dd 100644 --- a/src/main/resources/model.ttl +++ b/src/main/resources/model.ttl @@ -76,7 +76,7 @@ rm:was-treated-at rdf:type owl:ObjectProperty ; ### http://onto.fel.cvut.cz/ontologies/record-manager/has-state rm:has-state rdf:type owl:ObjectProperty ; - rdfs:label "has-state"@en . + rdfs:label "has state"@en . ################################################################# From 54e17e9411f69b8a3042190fed218e61db3de172 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Fri, 8 Dec 2023 17:49:09 +0100 Subject: [PATCH 04/15] [#29] Update resources rm:has-record-state and rm:record-state in ontology model.ttl --- src/main/resources/model.ttl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/resources/model.ttl b/src/main/resources/model.ttl index d62553dd..30f3bc43 100644 --- a/src/main/resources/model.ttl +++ b/src/main/resources/model.ttl @@ -7,6 +7,7 @@ @prefix xsd: . @prefix form: . @prefix rdfs: . +@prefix ufo: . @base . rdf:type owl:Ontology ; @@ -76,6 +77,7 @@ rm:was-treated-at rdf:type owl:ObjectProperty ; ### http://onto.fel.cvut.cz/ontologies/record-manager/has-state rm:has-state rdf:type owl:ObjectProperty ; + rdfs:subPropertyOf rdf:type ; rdfs:label "has state"@en . @@ -169,6 +171,7 @@ rm:impersonator rdf:type owl:Class ; ### http://onto.fel.cvut.cz/ontologies/record-manager/record-state rm:record-state rdf:type owl:Class ; + rdfs:subClassOf ufo:phase ; rdfs:label "record state"@en . ### http://onto.fel.cvut.cz/ontologies/record-manager/open-record-state From 874e26c77c89f236f1ae81157a429584cc6f2ae4 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Fri, 8 Dec 2023 17:52:35 +0100 Subject: [PATCH 05/15] [#29] Refactor type of PatientRecord.state from URI to RecordState - add enum RecordState --- .../cvut/kbss/study/model/PatientRecord.java | 16 ++++--------- .../cz/cvut/kbss/study/model/RecordState.java | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 src/main/java/cz/cvut/kbss/study/model/RecordState.java 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 12e21807..aba1fb79 100644 --- a/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java +++ b/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java @@ -1,13 +1,6 @@ package cz.cvut.kbss.study.model; -import cz.cvut.kbss.jopa.model.annotations.CascadeType; -import cz.cvut.kbss.jopa.model.annotations.FetchType; -import cz.cvut.kbss.jopa.model.annotations.Id; -import cz.cvut.kbss.jopa.model.annotations.OWLAnnotationProperty; -import cz.cvut.kbss.jopa.model.annotations.OWLClass; -import cz.cvut.kbss.jopa.model.annotations.OWLDataProperty; -import cz.cvut.kbss.jopa.model.annotations.OWLObjectProperty; -import cz.cvut.kbss.jopa.model.annotations.ParticipationConstraints; +import cz.cvut.kbss.jopa.model.annotations.*; import cz.cvut.kbss.study.model.qam.Question; import cz.cvut.kbss.study.model.util.HasOwlKey; @@ -52,8 +45,9 @@ public class PatientRecord implements Serializable, HasOwlKey { CascadeType.REMOVE}, fetch = FetchType.EAGER) private Question question; + @Enumerated(EnumType.OBJECT_ONE_OF) @OWLObjectProperty(iri = Vocabulary.s_p_has_state) - private URI state; + private RecordState state; public URI getUri() { return uri; @@ -137,11 +131,11 @@ public void setFormTemplate(String formTemplate) { this.formTemplate = formTemplate; } - public URI getState() { + public RecordState getState() { return state; } - public void setState(URI state) { + public void setState(RecordState state) { this.state = state; } diff --git a/src/main/java/cz/cvut/kbss/study/model/RecordState.java b/src/main/java/cz/cvut/kbss/study/model/RecordState.java new file mode 100644 index 00000000..b82b0b54 --- /dev/null +++ b/src/main/java/cz/cvut/kbss/study/model/RecordState.java @@ -0,0 +1,24 @@ +package cz.cvut.kbss.study.model; + +import cz.cvut.kbss.jopa.model.annotations.Individual; + +public enum RecordState { + @Individual(iri = Vocabulary.s_c_open_record_state) + open(Vocabulary.s_c_open_record_state), + @Individual(iri = Vocabulary.s_c_valid_record_state) + valid(Vocabulary.s_c_valid_record_state), + @Individual(iri = Vocabulary.s_c_completed_record_state) + completed(Vocabulary.s_c_completed_record_state), + @Individual(iri = Vocabulary.s_c_published_record_state) + published(Vocabulary.s_c_published_record_state); + + private final String iri; + + RecordState(String iri) { + this.iri = iri; + } + + public String getIri() { + return iri; + } +} From 002c3285761fcd548b66d14c326aa1f53704e302 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Mon, 11 Dec 2023 15:03:34 +0100 Subject: [PATCH 06/15] [#29] Refactor field PatientRecord.state to PatientRecord.phase. - refactor type of PatientRecord.phase from RecordState to RecordPhase. --- .../java/cz/cvut/kbss/study/model/PatientRecord.java | 10 +++++----- .../study/model/{RecordState.java => RecordPhase.java} | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) rename src/main/java/cz/cvut/kbss/study/model/{RecordState.java => RecordPhase.java} (92%) 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 aba1fb79..287386a5 100644 --- a/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java +++ b/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java @@ -47,7 +47,7 @@ public class PatientRecord implements Serializable, HasOwlKey { @Enumerated(EnumType.OBJECT_ONE_OF) @OWLObjectProperty(iri = Vocabulary.s_p_has_state) - private RecordState state; + private RecordPhase phase; public URI getUri() { return uri; @@ -131,12 +131,12 @@ public void setFormTemplate(String formTemplate) { this.formTemplate = formTemplate; } - public RecordState getState() { - return state; + public RecordPhase getPhase() { + return phase; } - public void setState(RecordState state) { - this.state = state; + public void setPhase(RecordPhase phase) { + this.phase = phase; } @Override diff --git a/src/main/java/cz/cvut/kbss/study/model/RecordState.java b/src/main/java/cz/cvut/kbss/study/model/RecordPhase.java similarity index 92% rename from src/main/java/cz/cvut/kbss/study/model/RecordState.java rename to src/main/java/cz/cvut/kbss/study/model/RecordPhase.java index b82b0b54..dbb38e0a 100644 --- a/src/main/java/cz/cvut/kbss/study/model/RecordState.java +++ b/src/main/java/cz/cvut/kbss/study/model/RecordPhase.java @@ -2,7 +2,7 @@ import cz.cvut.kbss.jopa.model.annotations.Individual; -public enum RecordState { +public enum RecordPhase { @Individual(iri = Vocabulary.s_c_open_record_state) open(Vocabulary.s_c_open_record_state), @Individual(iri = Vocabulary.s_c_valid_record_state) @@ -14,7 +14,7 @@ public enum RecordState { private final String iri; - RecordState(String iri) { + RecordPhase(String iri) { this.iri = iri; } From 1da56ae00f9c24173342119d2e8359ea441a5683 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Mon, 11 Dec 2023 17:19:01 +0100 Subject: [PATCH 07/15] [#29] Add phase to PatientRecord.toString --- src/main/java/cz/cvut/kbss/study/model/PatientRecord.java | 1 + 1 file changed, 1 insertion(+) 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 287386a5..249c7dda 100644 --- a/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java +++ b/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java @@ -145,6 +145,7 @@ public String toString() { "localName=" + localName + ", dateCreated=" + dateCreated + ", institution=" + institution + + ", phase=" + phase + "} " + super.toString(); } } From 164974dc726d8e9d3ce3ac1db8534be5c30cbafb Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Tue, 12 Dec 2023 11:56:25 +0100 Subject: [PATCH 08/15] [#29] Refactor state to phase in ontology and jopa model --- .../cvut/kbss/study/model/PatientRecord.java | 2 +- src/main/resources/model.ttl | 34 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) 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 249c7dda..7afedf16 100644 --- a/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java +++ b/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java @@ -46,7 +46,7 @@ public class PatientRecord implements Serializable, HasOwlKey { private Question question; @Enumerated(EnumType.OBJECT_ONE_OF) - @OWLObjectProperty(iri = Vocabulary.s_p_has_state) + @OWLObjectProperty(iri = Vocabulary.s_p_has_phase) private RecordPhase phase; public URI getUri() { diff --git a/src/main/resources/model.ttl b/src/main/resources/model.ttl index 30f3bc43..168363f9 100644 --- a/src/main/resources/model.ttl +++ b/src/main/resources/model.ttl @@ -75,10 +75,10 @@ rm:relates-to rdf:type owl:ObjectProperty . rm:was-treated-at rdf:type owl:ObjectProperty ; rdfs:subPropertyOf rm:relates-to . -### http://onto.fel.cvut.cz/ontologies/record-manager/has-state -rm:has-state rdf:type owl:ObjectProperty ; +### http://onto.fel.cvut.cz/ontologies/record-manager/has-phase +rm:has-phase rdf:type owl:ObjectProperty ; rdfs:subPropertyOf rdf:type ; - rdfs:label "has state"@en . + rdfs:label "has phase"@en . ################################################################# @@ -169,29 +169,29 @@ rm:user rdf:type owl:Class ; rm:impersonator rdf:type owl:Class ; rdfs:label "Impersonator"@en . -### http://onto.fel.cvut.cz/ontologies/record-manager/record-state -rm:record-state rdf:type owl:Class ; +### http://onto.fel.cvut.cz/ontologies/record-manager/record-phase +rm:record-phase rdf:type owl:Class ; rdfs:subClassOf ufo:phase ; rdfs:label "record state"@en . -### http://onto.fel.cvut.cz/ontologies/record-manager/open-record-state -rm:open-record-state rdf:type owl:Class ; - rdfs:subClassOf rm:record-state ; +### http://onto.fel.cvut.cz/ontologies/record-manager/open-record-phase +rm:open-record-phase rdf:type owl:Class ; + rdfs:subClassOf rm:record-phase ; rdfs:label "open record state"@en . -### http://onto.fel.cvut.cz/ontologies/record-manager/valid-record-state -rm:valid-record-state rdf:type owl:Class ; - rdfs:subClassOf rm:record-state ; +### http://onto.fel.cvut.cz/ontologies/record-manager/valid-record-phase +rm:valid-record-phase rdf:type owl:Class ; + rdfs:subClassOf rm:record-phase ; rdfs:label "valid record state"@en . -### http://onto.fel.cvut.cz/ontologies/record-manager/completed-record-state -rm:completed-record-state rdf:type owl:Class ; - rdfs:subClassOf rm:record-state ; +### http://onto.fel.cvut.cz/ontologies/record-manager/completed-record-phase +rm:completed-record-phase rdf:type owl:Class ; + rdfs:subClassOf rm:record-phase ; rdfs:label "completed record state"@en . -### http://onto.fel.cvut.cz/ontologies/record-manager/published-record-state -rm:published-record-state rdf:type owl:Class ; - rdfs:subClassOf rm:record-state ; +### http://onto.fel.cvut.cz/ontologies/record-manager/published-record-phase +rm:published-record-phase rdf:type owl:Class ; + rdfs:subClassOf rm:record-phase ; rdfs:label "published record state"@en . ### Generated by the OWL API (version 4.2.8.20170104-2310) https://github.com/owlcs/owlapi From 4ae185fde400cf8f32c5ae72497728fb4369f1df Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Tue, 12 Dec 2023 12:16:22 +0100 Subject: [PATCH 09/15] [#29] Fix compilation error --- .../cz/cvut/kbss/study/model/RecordPhase.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/study/model/RecordPhase.java b/src/main/java/cz/cvut/kbss/study/model/RecordPhase.java index dbb38e0a..042ad262 100644 --- a/src/main/java/cz/cvut/kbss/study/model/RecordPhase.java +++ b/src/main/java/cz/cvut/kbss/study/model/RecordPhase.java @@ -3,14 +3,14 @@ import cz.cvut.kbss.jopa.model.annotations.Individual; public enum RecordPhase { - @Individual(iri = Vocabulary.s_c_open_record_state) - open(Vocabulary.s_c_open_record_state), - @Individual(iri = Vocabulary.s_c_valid_record_state) - valid(Vocabulary.s_c_valid_record_state), - @Individual(iri = Vocabulary.s_c_completed_record_state) - completed(Vocabulary.s_c_completed_record_state), - @Individual(iri = Vocabulary.s_c_published_record_state) - published(Vocabulary.s_c_published_record_state); + @Individual(iri = Vocabulary.s_c_open_record_phase) + open(Vocabulary.s_c_open_record_phase), + @Individual(iri = Vocabulary.s_c_valid_record_phase) + valid(Vocabulary.s_c_valid_record_phase), + @Individual(iri = Vocabulary.s_c_completed_record_phase) + completed(Vocabulary.s_c_completed_record_phase), + @Individual(iri = Vocabulary.s_c_published_record_phase) + published(Vocabulary.s_c_published_record_phase); private final String iri; From 64e82b6266f90730d0358693c5a58c9bfd0e8173 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Tue, 12 Dec 2023 19:38:57 +0100 Subject: [PATCH 10/15] [#29] Add phase field to PatientRecordDto --- .../cvut/kbss/study/dto/PatientRecordDto.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 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 2c8a69c1..1489461b 100644 --- a/src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java +++ b/src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java @@ -1,10 +1,7 @@ package cz.cvut.kbss.study.dto; import cz.cvut.kbss.jopa.model.annotations.*; -import cz.cvut.kbss.study.model.AbstractEntity; -import cz.cvut.kbss.study.model.Institution; -import cz.cvut.kbss.study.model.User; -import cz.cvut.kbss.study.model.Vocabulary; +import cz.cvut.kbss.study.model.*; import cz.cvut.kbss.study.model.util.HasOwlKey; import java.util.Date; @@ -39,6 +36,10 @@ public class PatientRecordDto extends AbstractEntity implements HasOwlKey { @OWLObjectProperty(iri = Vocabulary.s_p_was_treated_at, fetch = FetchType.EAGER) private Institution institution; + @Enumerated(EnumType.OBJECT_ONE_OF) + @OWLObjectProperty(iri = Vocabulary.s_p_has_phase) + private RecordPhase phase; + @Override public String getKey() { return key; @@ -105,12 +106,21 @@ public void setFormTemplate(String formTemplate) { this.formTemplate = formTemplate; } + public RecordPhase getPhase() { + return phase; + } + + public void setPhase(RecordPhase phase) { + this.phase = phase; + } + @Override public String toString() { return "PatientRecordDto{" + "localName=" + localName + "dateCreated=" + dateCreated + ", institution=" + institution + + ", phase=" + phase + "} " + super.toString(); } } From 3c137e8bb10f6c8708d4e40f2807c95d46bd2536 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Wed, 13 Dec 2023 12:02:01 +0100 Subject: [PATCH 11/15] [#29] Fix labels of record phase classes in model.ttl --- src/main/resources/model.ttl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/resources/model.ttl b/src/main/resources/model.ttl index 168363f9..b92a8399 100644 --- a/src/main/resources/model.ttl +++ b/src/main/resources/model.ttl @@ -172,26 +172,26 @@ rm:impersonator rdf:type owl:Class ; ### http://onto.fel.cvut.cz/ontologies/record-manager/record-phase rm:record-phase rdf:type owl:Class ; rdfs:subClassOf ufo:phase ; - rdfs:label "record state"@en . + rdfs:label "record phase"@en . ### http://onto.fel.cvut.cz/ontologies/record-manager/open-record-phase rm:open-record-phase rdf:type owl:Class ; rdfs:subClassOf rm:record-phase ; - rdfs:label "open record state"@en . + rdfs:label "open record phase"@en . ### http://onto.fel.cvut.cz/ontologies/record-manager/valid-record-phase rm:valid-record-phase rdf:type owl:Class ; rdfs:subClassOf rm:record-phase ; - rdfs:label "valid record state"@en . + rdfs:label "valid record phase"@en . ### http://onto.fel.cvut.cz/ontologies/record-manager/completed-record-phase rm:completed-record-phase rdf:type owl:Class ; rdfs:subClassOf rm:record-phase ; - rdfs:label "completed record state"@en . + rdfs:label "completed record phase"@en . ### http://onto.fel.cvut.cz/ontologies/record-manager/published-record-phase rm:published-record-phase rdf:type owl:Class ; rdfs:subClassOf rm:record-phase ; - rdfs:label "published record state"@en . + rdfs:label "published record phase"@en . ### Generated by the OWL API (version 4.2.8.20170104-2310) https://github.com/owlcs/owlapi From 815f536e052a64b93e8ab8208de8b5e00fb540ee Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Wed, 13 Dec 2023 12:04:51 +0100 Subject: [PATCH 12/15] [#29] Add rejected record phase --- src/main/java/cz/cvut/kbss/study/model/RecordPhase.java | 4 +++- src/main/resources/model.ttl | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/cz/cvut/kbss/study/model/RecordPhase.java b/src/main/java/cz/cvut/kbss/study/model/RecordPhase.java index 042ad262..398a39d9 100644 --- a/src/main/java/cz/cvut/kbss/study/model/RecordPhase.java +++ b/src/main/java/cz/cvut/kbss/study/model/RecordPhase.java @@ -10,7 +10,9 @@ public enum RecordPhase { @Individual(iri = Vocabulary.s_c_completed_record_phase) completed(Vocabulary.s_c_completed_record_phase), @Individual(iri = Vocabulary.s_c_published_record_phase) - published(Vocabulary.s_c_published_record_phase); + published(Vocabulary.s_c_published_record_phase), + @Individual(iri = Vocabulary.s_c_rejected_record_phase) + rejected(Vocabulary.s_c_rejected_record_phase); private final String iri; diff --git a/src/main/resources/model.ttl b/src/main/resources/model.ttl index b92a8399..6cd835e2 100644 --- a/src/main/resources/model.ttl +++ b/src/main/resources/model.ttl @@ -194,4 +194,9 @@ rm:published-record-phase rdf:type owl:Class ; rdfs:subClassOf rm:record-phase ; rdfs:label "published record phase"@en . +### http://onto.fel.cvut.cz/ontologies/record-manager/rejected-record-phase +rm:rejected-record-phase rdf:type owl:Class ; + rdfs:subClassOf rm:record-phase ; + rdfs:label "rejected record phase"@en . + ### Generated by the OWL API (version 4.2.8.20170104-2310) https://github.com/owlcs/owlapi From e16bea508e53cbcc545012f6c3a5800c3365fc70 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Wed, 13 Dec 2023 09:29:25 +0100 Subject: [PATCH 13/15] [#33] Add updateUserInstitution in OidcUserController --- .../kbss/study/rest/OidcUserController.java | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/study/rest/OidcUserController.java b/src/main/java/cz/cvut/kbss/study/rest/OidcUserController.java index 0c01c193..b683333e 100644 --- a/src/main/java/cz/cvut/kbss/study/rest/OidcUserController.java +++ b/src/main/java/cz/cvut/kbss/study/rest/OidcUserController.java @@ -3,19 +3,21 @@ import cz.cvut.kbss.study.exception.NotFoundException; import cz.cvut.kbss.study.model.Institution; import cz.cvut.kbss.study.model.User; +import cz.cvut.kbss.study.rest.exception.BadRequestException; import cz.cvut.kbss.study.security.SecurityConstants; import cz.cvut.kbss.study.service.InstitutionService; import cz.cvut.kbss.study.service.UserService; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import java.net.URI; +import java.util.Arrays; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; /** * API for getting basic user info. @@ -61,6 +63,36 @@ public List getUsers(@RequestParam(value = "institution", required = false return institutionKey != null ? getByInstitution(institutionKey) : userService.findAll(); } + @PreAuthorize("hasRole('" + SecurityConstants.ROLE_ADMIN + "') or #username == authentication.name") + @PutMapping(value = "/{username}", consumes = MediaType.APPLICATION_JSON_VALUE) + @ResponseStatus(HttpStatus.NO_CONTENT) + public void updateUserInstitution(@PathVariable("username") String username, @RequestBody User user, + @RequestParam(value = "email", defaultValue = "true") boolean sendEmail) { + if (!username.equals(user.getUsername())) { + throw new BadRequestException("The passed user's username is different from the specified one."); + } + final User original = getByUsername(username); + + assert original != null; + + // validate institution update is valid + List institutionURIs = Arrays.asList(user.getInstitution(), original.getInstitution()) + .stream().map(i -> i != null ? i.getUri() : null).collect(Collectors.toList()); + if (Objects.equals(institutionURIs.get(0), institutionURIs.get(1))){ + LOG.warn("Ignoring attempt to add user {} to institution {} because it is already in institution {}.", user, institutionURIs.get(0), institutionURIs.get(1)); + return; + } + + // make sure only institution is updated + Institution newInstitution = user.getInstitution(); + user = original.copy(); + user.setInstitution(newInstitution); + userService.update(user, sendEmail, "profileUpdate"); + if (LOG.isTraceEnabled()) { + LOG.trace("Added user {} to institution {} successfully.", user, user.getInstitution()); + } + } + private List getByInstitution(String institutionKey) { assert institutionKey != null; final Institution institution = institutionService.findByKey(institutionKey); From 569a8a3138cdb0eb7f5eaaa88a3f7a23b2c5d9f7 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Wed, 13 Dec 2023 13:01:24 +0100 Subject: [PATCH 14/15] [#33] Refactor method name OidcUserController.updateUserInstitution to OidcUserController.updateUser --- src/main/java/cz/cvut/kbss/study/rest/OidcUserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/cz/cvut/kbss/study/rest/OidcUserController.java b/src/main/java/cz/cvut/kbss/study/rest/OidcUserController.java index b683333e..8beb728e 100644 --- a/src/main/java/cz/cvut/kbss/study/rest/OidcUserController.java +++ b/src/main/java/cz/cvut/kbss/study/rest/OidcUserController.java @@ -66,7 +66,7 @@ public List getUsers(@RequestParam(value = "institution", required = false @PreAuthorize("hasRole('" + SecurityConstants.ROLE_ADMIN + "') or #username == authentication.name") @PutMapping(value = "/{username}", consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.NO_CONTENT) - public void updateUserInstitution(@PathVariable("username") String username, @RequestBody User user, + public void updateUser(@PathVariable("username") String username, @RequestBody User user, @RequestParam(value = "email", defaultValue = "true") boolean sendEmail) { if (!username.equals(user.getUsername())) { throw new BadRequestException("The passed user's username is different from the specified one."); From 29181f78cd75259560c57f9f3d5bb27c88f65b7c Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Wed, 13 Dec 2023 13:11:13 +0100 Subject: [PATCH 15/15] [#33] Fix implementation of updateUser - remove validation check if old and new institutions are the same - use variable "original" to update the institution - log trace level message about the update only if old and new institutions are different - add method to check if HasUri entities are equal by URI - add method to get the URI of HasUri entity --- .../kbss/study/rest/OidcUserController.java | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/study/rest/OidcUserController.java b/src/main/java/cz/cvut/kbss/study/rest/OidcUserController.java index 8beb728e..d2388d20 100644 --- a/src/main/java/cz/cvut/kbss/study/rest/OidcUserController.java +++ b/src/main/java/cz/cvut/kbss/study/rest/OidcUserController.java @@ -3,6 +3,7 @@ import cz.cvut.kbss.study.exception.NotFoundException; import cz.cvut.kbss.study.model.Institution; import cz.cvut.kbss.study.model.User; +import cz.cvut.kbss.study.model.util.HasUri; import cz.cvut.kbss.study.rest.exception.BadRequestException; import cz.cvut.kbss.study.security.SecurityConstants; import cz.cvut.kbss.study.service.InstitutionService; @@ -14,10 +15,9 @@ import org.springframework.web.bind.annotation.*; import java.net.URI; -import java.util.Arrays; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; +import java.util.Optional; /** * API for getting basic user info. @@ -74,23 +74,35 @@ public void updateUser(@PathVariable("username") String username, @RequestBody U final User original = getByUsername(username); assert original != null; + Institution newInstitution = user.getInstitution(); + Institution oldInstitution = original.getInstitution(); + original.setInstitution(newInstitution); + userService.update(original, sendEmail, "profileUpdate"); - // validate institution update is valid - List institutionURIs = Arrays.asList(user.getInstitution(), original.getInstitution()) - .stream().map(i -> i != null ? i.getUri() : null).collect(Collectors.toList()); - if (Objects.equals(institutionURIs.get(0), institutionURIs.get(1))){ - LOG.warn("Ignoring attempt to add user {} to institution {} because it is already in institution {}.", user, institutionURIs.get(0), institutionURIs.get(1)); - return; + if (LOG.isTraceEnabled() && ! equals(newInstitution, oldInstitution)) { + LOG.trace("Set user institution {} to institution {} successfully.", user, oldInstitution, newInstitution); } + } - // make sure only institution is updated - Institution newInstitution = user.getInstitution(); - user = original.copy(); - user.setInstitution(newInstitution); - userService.update(user, sendEmail, "profileUpdate"); - if (LOG.isTraceEnabled()) { - LOG.trace("Added user {} to institution {} successfully.", user, user.getInstitution()); - } + /** + * Input arguments can be null and getUri can be null. + * @param entity1 + * @param entity2 + * @return true if the URIs of the input arguments are equal, false otherwise. + */ + private boolean equals(HasUri entity1, HasUri entity2){ + URI u1 = getURI(entity1); + URI u2 = getURI(entity2); + return Objects.equals(u1, u2); + } + + /** + * Retrieves the URI of entity argument. entity can be null. + * @param entity + * @return the URI of the entity or null if entity is null. + */ + private URI getURI(HasUri entity){ + return Optional.of(entity).map(HasUri::getUri).orElse(null); } private List getByInstitution(String institutionKey) {