Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues/33 admin setting user institution in keycloack deployment #34

22 changes: 14 additions & 8 deletions src/main/java/cz/cvut/kbss/study/model/PatientRecord.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package cz.cvut.kbss.study.model;

import cz.cvut.kbss.jopa.model.annotations.CascadeType;
import cz.cvut.kbss.jopa.model.annotations.FetchType;
import cz.cvut.kbss.jopa.model.annotations.Id;
import cz.cvut.kbss.jopa.model.annotations.OWLAnnotationProperty;
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.jopa.model.annotations.ParticipationConstraints;
import cz.cvut.kbss.jopa.model.annotations.*;
import cz.cvut.kbss.study.model.qam.Question;
import cz.cvut.kbss.study.model.util.HasOwlKey;

Expand Down Expand Up @@ -52,6 +45,10 @@ public class PatientRecord implements Serializable, HasOwlKey {
CascadeType.REMOVE}, fetch = FetchType.EAGER)
private Question question;

@Enumerated(EnumType.OBJECT_ONE_OF)
@OWLObjectProperty(iri = Vocabulary.s_p_has_phase)
private RecordPhase phase;

public URI getUri() {
return uri;
}
Expand Down Expand Up @@ -134,12 +131,21 @@ public void setFormTemplate(String formTemplate) {
this.formTemplate = formTemplate;
}

public RecordPhase getPhase() {
return phase;
}

public void setPhase(RecordPhase phase) {
this.phase = phase;
}

@Override
public String toString() {
return "PatientRecord{" +
"localName=" + localName +
", dateCreated=" + dateCreated +
", institution=" + institution +
", phase=" + phase +
"} " + super.toString();
}
}
24 changes: 24 additions & 0 deletions src/main/java/cz/cvut/kbss/study/model/RecordPhase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cz.cvut.kbss.study.model;

import cz.cvut.kbss.jopa.model.annotations.Individual;

public enum RecordPhase {
@Individual(iri = Vocabulary.s_c_open_record_phase)
open(Vocabulary.s_c_open_record_phase),
@Individual(iri = Vocabulary.s_c_valid_record_phase)
valid(Vocabulary.s_c_valid_record_phase),
@Individual(iri = Vocabulary.s_c_completed_record_phase)
completed(Vocabulary.s_c_completed_record_phase),
@Individual(iri = Vocabulary.s_c_published_record_phase)
published(Vocabulary.s_c_published_record_phase);

private final String iri;

RecordPhase(String iri) {
this.iri = iri;
}

public String getIri() {
return iri;
}
}
19 changes: 19 additions & 0 deletions src/main/java/cz/cvut/kbss/study/rest/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ public void removeUser(@PathVariable("username") String username) {
}
}

@ConditionalOnProperty(prefix = "security", name = "provider", havingValue = "oidc")
@PreAuthorize("hasRole('" + SecurityConstants.ROLE_ADMIN + "') or #username == authentication.name")
@PutMapping(value = "/{username}", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateUserInstitution(@PathVariable("username") String username, @RequestBody User user,
blcham marked this conversation as resolved.
Show resolved Hide resolved
@RequestParam(value = "email", defaultValue = "true") boolean sendEmail) {
if (!username.equals(user.getUsername())) {
throw new BadRequestException("The passed user's username is different from the specified one.");
}
final User original = getByUsername(username);
original.setInstitution(user.getInstitution());
assert original != null;
userService.update(original, sendEmail, "profileUpdate");
if (LOG.isTraceEnabled()) {
LOG.trace("Added user {} to institution {} successfully.", user, user.getInstitution());
}
}

@ConditionalOnProperty(prefix = "security", name = "provider", havingValue = "internal")
@PreAuthorize("hasRole('" + SecurityConstants.ROLE_ADMIN + "') or #username == authentication.name")
@PutMapping(value = "/{username}", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
Expand Down
30 changes: 30 additions & 0 deletions src/main/resources/model.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix form: <http://onto.fel.cvut.cz/ontologies/form/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ufo: <http://onto.fel.cvut.cz/ontologies/ufo/> .
@base <http://onto.fel.cvut.cz/ontologies/record-manager> .

<http://onto.fel.cvut.cz/ontologies/record-manager> rdf:type owl:Ontology ;
Expand Down Expand Up @@ -74,6 +75,11 @@ rm:relates-to rdf:type owl:ObjectProperty .
rm:was-treated-at rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf rm:relates-to .

### http://onto.fel.cvut.cz/ontologies/record-manager/has-phase
rm:has-phase rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf rdf:type ;
rdfs:label "has phase"@en .


#################################################################
# Data properties
Expand Down Expand Up @@ -163,5 +169,29 @@ rm:user rdf:type owl:Class ;
rm:impersonator rdf:type owl:Class ;
rdfs:label "Impersonator"@en .

### http://onto.fel.cvut.cz/ontologies/record-manager/record-phase
rm:record-phase rdf:type owl:Class ;
rdfs:subClassOf ufo:phase ;
rdfs:label "record state"@en .

### http://onto.fel.cvut.cz/ontologies/record-manager/open-record-phase
rm:open-record-phase rdf:type owl:Class ;
rdfs:subClassOf rm:record-phase ;
rdfs:label "open record state"@en .

### http://onto.fel.cvut.cz/ontologies/record-manager/valid-record-phase
rm:valid-record-phase rdf:type owl:Class ;
rdfs:subClassOf rm:record-phase ;
rdfs:label "valid record state"@en .

### http://onto.fel.cvut.cz/ontologies/record-manager/completed-record-phase
rm:completed-record-phase rdf:type owl:Class ;
rdfs:subClassOf rm:record-phase ;
rdfs:label "completed record state"@en .

### http://onto.fel.cvut.cz/ontologies/record-manager/published-record-phase
rm:published-record-phase rdf:type owl:Class ;
rdfs:subClassOf rm:record-phase ;
rdfs:label "published record state"@en .

### Generated by the OWL API (version 4.2.8.20170104-2310) https://github.com/owlcs/owlapi
Loading