Skip to content

Commit

Permalink
Merge pull request #77 from kbss-cvut/205-reject-message
Browse files Browse the repository at this point in the history
Reject Message
  • Loading branch information
blcham authored Nov 6, 2024
2 parents 4752dc6 + 722b84d commit 41eb02c
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/main/java/cz/cvut/kbss/study/dto/PatientRecordDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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_reject_reason)
private String rejectReason;


@Override
public String getKey() {
return key;
Expand Down Expand Up @@ -115,6 +119,14 @@ public void setPhase(RecordPhase phase) {
this.phase = phase;
}

public String getRejectReason() {
return rejectReason;
}

public void setRejectReason(String rejectReason) {
this.rejectReason = rejectReason;
}

@Override
public String toString() {
return "PatientRecordDto{" +
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/cz/cvut/kbss/study/model/PatientRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -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_reject_reason)
private String rejectReason;

@Override
public URI getUri() {
return uri;
Expand Down Expand Up @@ -146,6 +149,15 @@ public RecordPhase getPhase() {
return phase;
}

public String getRejectReason() {
return rejectReason;
}

public void setRejectReason(String rejectReason) {
this.rejectReason = rejectReason;
}


public void setPhase(RecordPhase phase) {
this.phase = phase;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,9 @@ public void removeRecord(@PathVariable("key") String key) {
LOG.trace("Patient record {} successfully removed.", toRemove);
}
}

@GetMapping(value = "/allowedRejectReason", produces = MediaType.APPLICATION_JSON_VALUE)
public boolean getAllowedRejectReason(){
return configReader.getConfig(ConfigParam.RECORDS_ALLOWED_REJECT_REASON).equals("true");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ protected void prePersist(PatientRecord instance) {

@Override
protected void preUpdate(PatientRecord instance) {
if(instance.getPhase() != RecordPhase.rejected) {
instance.setRejectReason(null);
}
instance.setLastModifiedBy(securityUtils.getCurrentUser());
instance.setLastModified(new Date());
recordDao.requireUniqueNonEmptyLocalName(instance);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/cz/cvut/kbss/study/util/ConfigParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -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_REASON("records.allowedRejectReason");


private final String name;

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=
cors.allowedOrigins=

records.allowedRejectReason=true
3 changes: 3 additions & 0 deletions src/main/resources/model.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ rm:token rdf:type owl:DatatypeProperty .
<http://xmlns.com/foaf/0.1/mbox> rdf:type owl:DatatypeProperty .


### http://onto.fel.cvut.cz/ontologies/record-manager/reject-reason
rm:reject-reason rdf:type owl:DatatypeProperty .

#################################################################
# Classes
#################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,6 +67,9 @@ public class PatientRecordControllerTest extends BaseControllerTestRunner {
@Mock
private ApplicationEventPublisher eventPublisherMock;

@Mock
private ConfigReader configReaderMock;

@Mock
private UserService userService;

Expand Down Expand Up @@ -487,4 +492,30 @@ void exportRecordsPublishesPagingEvent() throws Exception {
final PaginatedResultRetrievedEvent event = captor.getValue();
assertEquals(page, event.getPage());
}

@Test
void getAllowedRejectReasonTrue() throws Exception {
String expectedValue = "true";
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<>() {
});
assertEquals(result.getResponse().getStatus(), HttpStatus.OK.value());
assertEquals(expectedValue, body);
}

@Test
void getAllowedRejectReasonFalse() throws Exception {
String expectedValue = "false";
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<>() {
});
assertEquals(result.getResponse().getStatus(), HttpStatus.OK.value());
assertEquals(expectedValue, body);
}
}

0 comments on commit 41eb02c

Please sign in to comment.