From 2660fa72976c3673737a126cf97c17ed6e9f6bc9 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Tue, 1 Jul 2025 22:04:30 +0200 Subject: [PATCH 1/2] [kbss-cvut/23ava-distribution#165] Implement Comment model --- .../cz/cvut/kbss/study/model/qam/Comment.java | 56 +++++++++++++++++++ .../cvut/kbss/study/model/qam/Question.java | 14 +++++ src/main/resources/form.ttl | 3 + src/main/resources/model.ttl | 11 ++++ 4 files changed, 84 insertions(+) create mode 100644 src/main/java/cz/cvut/kbss/study/model/qam/Comment.java diff --git a/src/main/java/cz/cvut/kbss/study/model/qam/Comment.java b/src/main/java/cz/cvut/kbss/study/model/qam/Comment.java new file mode 100644 index 00000000..48bdc080 --- /dev/null +++ b/src/main/java/cz/cvut/kbss/study/model/qam/Comment.java @@ -0,0 +1,56 @@ +package cz.cvut.kbss.study.model.qam; + +import cz.cvut.kbss.jopa.model.annotations.OWLClass; +import cz.cvut.kbss.jopa.model.annotations.OWLDataProperty; +import cz.cvut.kbss.study.model.AbstractEntity; +import cz.cvut.kbss.study.model.Vocabulary; + +import java.util.Date; + +@OWLClass(iri = Vocabulary.s_c_comment) +public class Comment extends AbstractEntity { + + @OWLDataProperty(iri = Vocabulary.s_p_has_comment_value) + private String value; + + @OWLDataProperty(iri = Vocabulary.s_p_has_timestamp) + private Date timestamp; + + public Comment(String value, Date created) { + this.value = value; + this.timestamp = created; + } + + public Comment() { + } + + public Comment(Comment other) { + this.value = other.value; + this.timestamp = other.timestamp; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } + + @Override + public String toString() { + return "Comment{" + + "value='" + value + '\'' + + ", created=" + timestamp + + '}'; + } + +} diff --git a/src/main/java/cz/cvut/kbss/study/model/qam/Question.java b/src/main/java/cz/cvut/kbss/study/model/qam/Question.java index 1d43026b..d52bf387 100644 --- a/src/main/java/cz/cvut/kbss/study/model/qam/Question.java +++ b/src/main/java/cz/cvut/kbss/study/model/qam/Question.java @@ -30,6 +30,9 @@ public class Question extends AbstractEntity { @OWLDataProperty(iri = Vocabulary.s_p_has_origin_path_id) private String originPathId; + @OWLObjectProperty(iri = Vocabulary.s_p_has_comment, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER) + private Set comments = new HashSet<>();; + @Types private Set types = new HashSet<>(); @@ -43,6 +46,9 @@ public Question(Question other) { if (other.answers != null) { this.answers = other.answers.stream().map(Answer::new).collect(Collectors.toSet()); } + if(other.comments != null) { + this.comments = other.comments.stream().map(Comment::new).collect(Collectors.toSet()); + } if (other.types != null) { this.types.addAll(other.types); } @@ -81,6 +87,14 @@ public void setTypes(Set types) { this.types = types; } + public Set getComments() { + return comments; + } + + public void setComments(Set comments) { + this.comments = comments; + } + @Override public String toString() { return "Question (" + types + "){" + diff --git a/src/main/resources/form.ttl b/src/main/resources/form.ttl index c83b5ec7..46a81411 100644 --- a/src/main/resources/form.ttl +++ b/src/main/resources/form.ttl @@ -58,6 +58,9 @@ form:has-origin-path-id rdf:type owl:DatatypeProperty . doc:answer rdf:type owl:Class ; rdfs:label "Answer"@en . +### http://onto.fel.cvut.cz/ontologies/form/comment +form:comment rdf:type owl:Class ; + rdfs:label "Comment"@en . ### http://onto.fel.cvut.cz/ontologies/documentation/question doc:question rdf:type owl:Class ; diff --git a/src/main/resources/model.ttl b/src/main/resources/model.ttl index b5c0f357..39eb6e59 100644 --- a/src/main/resources/model.ttl +++ b/src/main/resources/model.ttl @@ -21,6 +21,9 @@ doc:has_answer rdf:type owl:ObjectProperty ; rdfs:subPropertyOf rm:relates-to . +### http://onto.fel.cvut.cz/ontologies/form/has-comment +form:has-comment rdf:type owl:ObjectProperty ; + rdfs:subPropertyOf rm:relates-to . ### http://onto.fel.cvut.cz/ontologies/documentation/has_related_question doc:has_related_question rdf:type owl:ObjectProperty ; @@ -104,6 +107,10 @@ rm:has-role rdf:type owl:ObjectProperty ; ### http://onto.fel.cvut.cz/ontologies/record-manager/action_type rm:action_type rdf:type owl:DatatypeProperty . +### http://onto.fel.cvut.cz/ontologies/form/has-comment-value +form:has-comment-value rdf:type owl:DatatypeProperty ; + rdfs:subPropertyOf rm:relates-to . + ### http://onto.fel.cvut.cz/ontologies/record-manager/isInvited rm:isInvited rdf:type owl:DatatypeProperty . @@ -120,6 +127,10 @@ rm:has-form-template-version rdf:type owl:DatatypeProperty ; rm:key rdf:type owl:DatatypeProperty . +form:has-timestamp rdf:type owl:DatatypeProperty ; + rdfs:subPropertyOf rm:relates-to . + + ### http://onto.fel.cvut.cz/ontologies/record-manager/password rm:password rdf:type owl:DatatypeProperty . From fba6f27bd97c5d3733ca866cf923b17ff4001737 Mon Sep 17 00:00:00 2001 From: palagdan Date: Wed, 1 Oct 2025 17:50:40 +0200 Subject: [PATCH 2/2] [kbss-cvut/23ava-distribution#165] Add author attribute --- .../cz/cvut/kbss/study/model/PatientRecord.java | 2 +- .../cz/cvut/kbss/study/model/qam/Comment.java | 17 ++++++++++++++++- .../study/persistence/dao/PatientRecordDao.java | 4 ++-- src/main/resources/model.ttl | 5 +++++ 4 files changed, 24 insertions(+), 4 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 9682546c..2659c845 100644 --- a/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java +++ b/src/main/java/cz/cvut/kbss/study/model/PatientRecord.java @@ -33,7 +33,7 @@ public class PatientRecord implements Serializable, HasOwlKey, HasUri { private String localName; @ParticipationConstraints(nonEmpty = true) - @OWLObjectProperty(iri = Vocabulary.s_p_has_author, fetch = FetchType.EAGER) + @OWLObjectProperty(iri = Vocabulary.s_p_record_manager_has_author, fetch = FetchType.EAGER) private User author; @OWLDataProperty(iri = Vocabulary.s_p_created) diff --git a/src/main/java/cz/cvut/kbss/study/model/qam/Comment.java b/src/main/java/cz/cvut/kbss/study/model/qam/Comment.java index 48bdc080..4af139b0 100644 --- a/src/main/java/cz/cvut/kbss/study/model/qam/Comment.java +++ b/src/main/java/cz/cvut/kbss/study/model/qam/Comment.java @@ -2,6 +2,7 @@ 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.study.model.AbstractEntity; import cz.cvut.kbss.study.model.Vocabulary; @@ -10,13 +11,17 @@ @OWLClass(iri = Vocabulary.s_c_comment) public class Comment extends AbstractEntity { + @OWLObjectProperty(iri = Vocabulary.s_p_has_author) + private String author; + @OWLDataProperty(iri = Vocabulary.s_p_has_comment_value) private String value; @OWLDataProperty(iri = Vocabulary.s_p_has_timestamp) private Date timestamp; - public Comment(String value, Date created) { + public Comment(String author, String value, Date created) { + this.author = author; this.value = value; this.timestamp = created; } @@ -25,10 +30,19 @@ public Comment() { } public Comment(Comment other) { + this.author = other.author; this.value = other.value; this.timestamp = other.timestamp; } + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + public String getValue() { return value; } @@ -48,6 +62,7 @@ public void setTimestamp(Date timestamp) { @Override public String toString() { return "Comment{" + + "author='" + author + '\'' + "value='" + value + '\'' + ", created=" + timestamp + '}'; 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 59d929f6..71e5ce2d 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 @@ -154,7 +154,7 @@ public List findByAuthor(User author) { Objects.requireNonNull(author); return em.createNativeQuery("SELECT ?r WHERE { ?r a ?type ; ?createdBy ?author . }", PatientRecord.class) .setParameter("type", typeUri) - .setParameter("createdBy", URI.create(Vocabulary.s_p_has_author)) + .setParameter("createdBy", URI.create(Vocabulary.s_p_record_manager_has_author)) .setParameter("author", author.getUri()).getResultList(); } @@ -291,7 +291,7 @@ public Page findAllRecordsRaw(RecordFilterParams filters, Pageable pa private void setQueryParameters(Query query, Map queryParams) { query .setParameter("type", typeUri) - .setParameter("hasAuthor", URI.create(Vocabulary.s_p_has_author)) + .setParameter("hasAuthor", URI.create(Vocabulary.s_p_record_manager_has_author)) .setParameter("hasUsername", URI.create(Vocabulary.s_p_accountName)) .setParameter("hasPhase", URI.create(Vocabulary.s_p_has_phase)) .setParameter("hasFormTemplate", URI.create(Vocabulary.s_p_has_form_template)) diff --git a/src/main/resources/model.ttl b/src/main/resources/model.ttl index 39eb6e59..b065cd6d 100644 --- a/src/main/resources/model.ttl +++ b/src/main/resources/model.ttl @@ -107,6 +107,11 @@ rm:has-role rdf:type owl:ObjectProperty ; ### http://onto.fel.cvut.cz/ontologies/record-manager/action_type rm:action_type rdf:type owl:DatatypeProperty . + +### http://onto.fel.cvut.cz/ontologies/form/has-author +form:has-author rdf:type owl:DatatypeProperty ; + rdfs:subPropertyOf rm:relates-to . + ### http://onto.fel.cvut.cz/ontologies/form/has-comment-value form:has-comment-value rdf:type owl:DatatypeProperty ; rdfs:subPropertyOf rm:relates-to .