Skip to content

Commit

Permalink
Merge branch 'main' into refactor-backend-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
blcham authored Nov 7, 2024
2 parents 4bc966b + f7f98e2 commit 3581c36
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 12 deletions.
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OFN Record Manager
# Record Manager

Manager of records based on OFN (https://data.gov.cz/ofn/).
Record Manager is an application for generic form-based collection of data. This repository contains the backend of the application.

## Required Technologies

Expand All @@ -9,14 +9,21 @@ Manager of records based on OFN (https://data.gov.cz/ofn/).

## System Architecture

The system can be split into two parts. __Main application__ provides management of users, organizations and their records. The system manages multiple types of records which are generated dynamically by __Form service__ defined in https://github.com/opendata-mvcr/sgov-forms .
The system can be split into two parts. __Main application__ provides management of users, organizations and their records. The system manages multiple types of records which are generated dynamically by __Form service__.

## Documentation
## Configuration

Build configuration and deployment is described in [Setup Guide](doc/setup.md).
Development is described in [Development notes](doc/development.md).
### Further Record Manager Configuration

The following table lists the names of environment variables that can be
passed to Record Manager backend either directly in `docker-compose.yml`, in
an [env_file](https://docs.docker.com/compose/compose-file/compose-file-v3/#env_file), or via command line.

-----
| Variable | Explanation |
|:---------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ```RECORDS_ALLOWEDREJECTREASON``` | Allow user to enter reason when rejecting records. Default value: `false.` |

Tento repozitář je udržován v rámci projektu OPZ č. CZ.03.4.74/0.0/0.0/15_025/0004172.
![Evropská unie - Evropský sociální fond - Operační program Zaměstnanost](https://data.gov.cz/images/ozp_logo_cz.jpg)
## Documentation

Build configuration and deployment are described in [Setup Guide](doc/setup.md).
Development is described in [Development notes](doc/development.md).
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
@@ -1,5 +1,6 @@
package cz.cvut.kbss.study.service;

import cz.cvut.kbss.study.model.RecordPhase;
import cz.cvut.kbss.study.model.export.ExportRecord;
import cz.cvut.kbss.study.model.export.Path;
import cz.cvut.kbss.study.model.export.RawRecord;
Expand Down Expand Up @@ -63,6 +64,11 @@ private List<ExportRecord> findExportRecordsData(List<RawRecord> rawRecords){
codeListValuesDao.findItems(uris).forEach(i -> translatorMap.put(i.getUri(), i.getName()));
codeListValuesDao.findAircraft().forEach(i -> translatorMap.put(i.getUri(), i.getName()));
codeListValuesDao.findInstitutions().forEach(i -> translatorMap.put(i.getUri(), i.getName()));
rawRecords.stream().map(r -> r.getPhase()).filter(p -> p != null)
.forEach(pUri ->
Optional.of(RecordPhase.fromIri(pUri.toString()))
.ifPresent(pStr -> translatorMap.put(pUri, pStr.name()))
);

Map<URI, List<String>> pathMap = new HashMap<>();
paths.forEach(p -> pathMap.put(p.getUri(), Arrays.asList(
Expand All @@ -78,6 +84,7 @@ private List<ExportRecord> findExportRecordsData(List<RawRecord> rawRecords){
for(RawRecord r : rawRecords){
ExportRecord er = new ExportRecord();
exportRecords.add(er);
er.setPhase(translatorMap.get(r.getPhase()));
er.setPath(pathMap.get(r.getAc_comp()));
er.setInstitution(translatorMap.get(r.getInstitution()));
er.setAircraftType(translatorMap.get(r.getAircraftType()));
Expand Down Expand Up @@ -118,7 +125,7 @@ private void addDataToExcel(XSSFWorkbook workbook, List<ExportRecord> data) thro
for(ExportRecord rec : data) {
XSSFRow r = s.createRow(rowIndex++);
r.createCell(0).setCellValue(rowIndex);
// r.createCell(1).setCellValue(rowIndex);
r.createCell(1).setCellValue(rec.getPhase());
r.createCell(2).setCellValue(rec.getCreated());
// r.createCell(3).setCellValue(rec.ed);
r.createCell(4).setCellValue(rec.getLastModified());
Expand Down
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
4 changes: 3 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,9 @@ public enum ConfigParam {

OIDC_ROLE_CLAIM("security.oidc.roleClaim"),

CORS_ALLOWED_ORIGINS("security.cors.allowedOrigins");
CORS_ALLOWED_ORIGINS("security.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
security.oidc.roleClaim=realm_access.roles

# Configures allowed origins for CORS (e.g. http://localhost:3000). Use a comma to separate multiple values
security.cors.allowedOrigins=
security.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 3581c36

Please sign in to comment.