From 8f5c57481dafd63eb8bee379222477d407508d54 Mon Sep 17 00:00:00 2001 From: Martin Ledvinka Date: Wed, 24 Jan 2024 15:37:37 +0100 Subject: [PATCH] [kbss-cvut/record-manager-ui#71] Reduce the size of PatientRecordDto data. Also update code to the new OWL2Java constant naming strategy. --- .../cz/cvut/kbss/study/config/WebAppConfig.java | 2 +- .../cvut/kbss/study/dto/PatientRecordDto.java | 17 +++++++++-------- .../kbss/study/rest/InstitutionController.java | 7 +++---- .../kbss/study/rest/StatisticsController.java | 1 - .../study/environment/generator/Generator.java | 4 ++-- .../java/cz/cvut/kbss/study/model/UserTest.java | 2 +- .../cvut/kbss/study/model/qam/AnswerTest.java | 2 +- .../cvut/kbss/study/model/qam/QuestionTest.java | 2 +- 8 files changed, 18 insertions(+), 19 deletions(-) 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 df53da8b..8034cf95 100644 --- a/src/main/java/cz/cvut/kbss/study/config/WebAppConfig.java +++ b/src/main/java/cz/cvut/kbss/study/config/WebAppConfig.java @@ -44,7 +44,7 @@ public ObjectMapper objectMapper() { */ public static ObjectMapper createJsonObjectMapper() { final ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS); + 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); 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 1489461b..8dddf25e 100644 --- a/src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java +++ b/src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java @@ -4,6 +4,7 @@ import cz.cvut.kbss.study.model.*; import cz.cvut.kbss.study.model.util.HasOwlKey; +import java.net.URI; import java.util.Date; @OWLClass(iri = Vocabulary.s_c_patient_record) @@ -21,8 +22,8 @@ public class PatientRecordDto extends AbstractEntity implements HasOwlKey { private String localName; @ParticipationConstraints(nonEmpty = true) - @OWLObjectProperty(iri = Vocabulary.s_p_has_author, fetch = FetchType.EAGER) - private User author; + @OWLObjectProperty(iri = Vocabulary.s_p_has_author) + private URI author; @OWLDataProperty(iri = Vocabulary.s_p_created) private Date dateCreated; @@ -30,8 +31,8 @@ public class PatientRecordDto extends AbstractEntity implements HasOwlKey { @OWLDataProperty(iri = Vocabulary.s_p_modified) private Date lastModified; - @OWLObjectProperty(iri = Vocabulary.s_p_has_last_editor, fetch = FetchType.EAGER) - private User lastModifiedBy; + @OWLObjectProperty(iri = Vocabulary.s_p_has_last_editor) + private URI lastModifiedBy; @OWLObjectProperty(iri = Vocabulary.s_p_was_treated_at, fetch = FetchType.EAGER) private Institution institution; @@ -58,11 +59,11 @@ public void setLocalName(String localName) { this.localName = localName; } - public User getAuthor() { + public URI getAuthor() { return author; } - public void setAuthor(User author) { + public void setAuthor(URI author) { this.author = author; } @@ -82,11 +83,11 @@ public void setLastModified(Date lastModified) { this.lastModified = lastModified; } - public User getLastModifiedBy() { + public URI getLastModifiedBy() { return lastModifiedBy; } - public void setLastModifiedBy(User lastModifiedBy) { + public void setLastModifiedBy(URI lastModifiedBy) { this.lastModifiedBy = lastModifiedBy; } diff --git a/src/main/java/cz/cvut/kbss/study/rest/InstitutionController.java b/src/main/java/cz/cvut/kbss/study/rest/InstitutionController.java index 2ac7fc0f..54f8f340 100644 --- a/src/main/java/cz/cvut/kbss/study/rest/InstitutionController.java +++ b/src/main/java/cz/cvut/kbss/study/rest/InstitutionController.java @@ -8,7 +8,6 @@ import cz.cvut.kbss.study.security.SecurityConstants; import cz.cvut.kbss.study.service.InstitutionService; import cz.cvut.kbss.study.service.PatientRecordService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -16,7 +15,7 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; -import java.util.Collections; +import java.util.Comparator; import java.util.List; @RestController @@ -38,7 +37,7 @@ public InstitutionController(InstitutionService institutionService, @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) public List getAllInstitutions() { final List institutions = institutionService.findAll(); - Collections.sort(institutions, (a, b) -> a.getName().compareTo(b.getName())); + institutions.sort(Comparator.comparing(Institution::getName)); return institutions; } @@ -85,7 +84,7 @@ public void updateInstitution(@PathVariable("key") String key, @RequestBody Inst throw new BadRequestException("The passed institution's key is different from the specified one."); } final Institution original = findInternal(key); - assert original != null; + institutionService.update(institution); if (LOG.isTraceEnabled()) { LOG.trace("Institution {} successfully updated.", institution); diff --git a/src/main/java/cz/cvut/kbss/study/rest/StatisticsController.java b/src/main/java/cz/cvut/kbss/study/rest/StatisticsController.java index 86fcf065..ca1b70d5 100644 --- a/src/main/java/cz/cvut/kbss/study/rest/StatisticsController.java +++ b/src/main/java/cz/cvut/kbss/study/rest/StatisticsController.java @@ -2,7 +2,6 @@ import cz.cvut.kbss.study.security.SecurityConstants; import cz.cvut.kbss.study.service.StatisticsService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; diff --git a/src/test/java/cz/cvut/kbss/study/environment/generator/Generator.java b/src/test/java/cz/cvut/kbss/study/environment/generator/Generator.java index 2a8b5693..93f8a21c 100644 --- a/src/test/java/cz/cvut/kbss/study/environment/generator/Generator.java +++ b/src/test/java/cz/cvut/kbss/study/environment/generator/Generator.java @@ -26,7 +26,7 @@ private Generator() { * @return Random URI */ public static URI generateUri() { - return URI.create(Vocabulary.ONTOLOGY_IRI_record_manager + "/randomInstance" + randomInt()); + return URI.create(Vocabulary.ONTOLOGY_IRI_RECORD_MANAGER + "/randomInstance" + randomInt()); } /** @@ -183,7 +183,7 @@ public static PatientRecord generatePatientRecord(User author) { public static PatientRecordDto generatePatientRecordDto(User author) { final PatientRecordDto rec = new PatientRecordDto(); rec.setLocalName("RandomRecordDto" + randomInt()); - rec.setAuthor(author); + rec.setAuthor(author.getUri()); rec.setUri(generateUri()); rec.setInstitution(author.getInstitution()); return rec; diff --git a/src/test/java/cz/cvut/kbss/study/model/UserTest.java b/src/test/java/cz/cvut/kbss/study/model/UserTest.java index 759cfce6..3b384e27 100644 --- a/src/test/java/cz/cvut/kbss/study/model/UserTest.java +++ b/src/test/java/cz/cvut/kbss/study/model/UserTest.java @@ -82,7 +82,7 @@ public void generateUriThrowsIllegalStateForEmptyLastName() { @Test public void generateUriDoesNothingIfTheUriIsAlreadySet() { - final String uri = Vocabulary.ONTOLOGY_IRI_record_manager + "/test"; + final String uri = Vocabulary.ONTOLOGY_IRI_RECORD_MANAGER + "/test"; user.setUri(URI.create(uri)); user.generateUri(); assertEquals(uri, user.getUri().toString()); diff --git a/src/test/java/cz/cvut/kbss/study/model/qam/AnswerTest.java b/src/test/java/cz/cvut/kbss/study/model/qam/AnswerTest.java index fff4d364..8659c130 100644 --- a/src/test/java/cz/cvut/kbss/study/model/qam/AnswerTest.java +++ b/src/test/java/cz/cvut/kbss/study/model/qam/AnswerTest.java @@ -14,7 +14,7 @@ public void copyConstructorsCopiesValuesAndTypesNoUri() { final Answer a = new Answer(); a.setTextValue("Cough"); a.setCodeValue(Generator.generateUri()); - a.getTypes().add(Vocabulary.ONTOLOGY_IRI_record_manager + "/infectious-disease/"); + a.getTypes().add(Vocabulary.ONTOLOGY_IRI_RECORD_MANAGER + "/infectious-disease/"); final Answer res = new Answer(a); assertNull(res.getUri()); diff --git a/src/test/java/cz/cvut/kbss/study/model/qam/QuestionTest.java b/src/test/java/cz/cvut/kbss/study/model/qam/QuestionTest.java index 7980c937..3059e75a 100644 --- a/src/test/java/cz/cvut/kbss/study/model/qam/QuestionTest.java +++ b/src/test/java/cz/cvut/kbss/study/model/qam/QuestionTest.java @@ -13,7 +13,7 @@ public class QuestionTest { public void copyConstructorCopiesSubQuestions() { final Question q = new Question(); q.setUri(Generator.generateUri()); - q.getTypes().add(Vocabulary.ONTOLOGY_IRI_record_manager + "/infectious-disease/"); + q.getTypes().add(Vocabulary.ONTOLOGY_IRI_RECORD_MANAGER + "/infectious-disease/"); for (int i = 0; i < Generator.randomInt(10); i++) { final Question child = new Question(); child.setUri(Generator.generateUri());