Skip to content

Commit

Permalink
[kbss-cvut/record-manager-ui#71] Reduce the size of PatientRecordDto …
Browse files Browse the repository at this point in the history
…data.

Also update code to the new OWL2Java constant naming strategy.
  • Loading branch information
ledsoft committed Jan 24, 2024
1 parent 280b171 commit 8f5c574
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main/java/cz/cvut/kbss/study/config/WebAppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -21,17 +22,17 @@ 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;

@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;
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
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;
import org.springframework.http.ResponseEntity;
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
Expand All @@ -38,7 +37,7 @@ public InstitutionController(InstitutionService institutionService,
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public List<Institution> getAllInstitutions() {
final List<Institution> institutions = institutionService.findAll();
Collections.sort(institutions, (a, b) -> a.getName().compareTo(b.getName()));
institutions.sort(Comparator.comparing(Institution::getName));
return institutions;
}

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/cz/cvut/kbss/study/model/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/cz/cvut/kbss/study/model/qam/AnswerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 8f5c574

Please sign in to comment.