forked from blcham/record-manager
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[kbss-cvut/record-manager-ui#202] Implement Roles and permission
- Loading branch information
Showing
4 changed files
with
193 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package cz.cvut.kbss.study.model; | ||
|
||
|
||
import cz.cvut.kbss.jopa.model.annotations.Individual; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum Permission { | ||
|
||
@Individual(iri=Vocabulary.s_i_delete_all_records_permission) | ||
deleteAllRecords(Vocabulary.s_i_delete_all_records_permission), | ||
|
||
@Individual(iri=Vocabulary.s_i_view_all_records_permission) | ||
viewAllRecords(Vocabulary.s_i_view_all_records_permission), | ||
|
||
@Individual(iri=Vocabulary.s_i_edit_all_records_permission) | ||
editAllRecords(Vocabulary.s_i_edit_all_records_permission), | ||
|
||
@Individual(iri=Vocabulary.s_i_delete_organization_records_permission) | ||
deleteOrganizationRecords(Vocabulary.s_i_delete_organization_records_permission), | ||
|
||
@Individual(iri=Vocabulary.s_i_view_organization_records_permission) | ||
viewOrganizationRecords(Vocabulary.s_i_view_organization_records_permission), | ||
|
||
@Individual(iri=Vocabulary.s_i_edit_organization_records_permission) | ||
editOrganizationRecords(Vocabulary.s_i_edit_organization_records_permission), | ||
|
||
@Individual(iri=Vocabulary.s_i_edit_users_permission) | ||
editUsers(Vocabulary.s_i_edit_users_permission), | ||
|
||
@Individual(iri=Vocabulary.s_i_complete_records_permission) | ||
completeRecords(Vocabulary.s_i_complete_records_permission), | ||
|
||
@Individual(iri=Vocabulary.s_i_reject_records_permission) | ||
rejectRecords(Vocabulary.s_i_reject_records_permission), | ||
|
||
@Individual(iri=Vocabulary.s_i_publish_records_permission) | ||
publishRecords(Vocabulary.s_i_publish_records_permission), | ||
|
||
@Individual(iri=Vocabulary.s_i_import_codelists_permission) | ||
importCodelists(Vocabulary.s_i_import_codelists_permission); | ||
|
||
private final String iri; | ||
|
||
|
||
Permission(String iri) { | ||
this.iri = iri; | ||
} | ||
|
||
public String getIri() { | ||
return iri; | ||
} | ||
|
||
|
||
/** | ||
* Returns {@link Permission} with the specified IRI. | ||
* | ||
* @param iri permission identifier | ||
* @return matching {@code Permission} | ||
* @throws IllegalArgumentException When no matching permission is found | ||
*/ | ||
public static Permission fromIri(String iri) { | ||
for (Permission p : values()) { | ||
if (p.getIri().equals(iri)) { | ||
return p; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown permission identifier '" + iri + "'."); | ||
} | ||
|
||
|
||
/** | ||
* Returns {@link Permission} with the specified constant name. | ||
* | ||
* @param name permission name | ||
* @return matching {@code Permission} | ||
* @throws IllegalArgumentException When no matching permission is found | ||
*/ | ||
public static Permission fromName(String name) { | ||
for (Permission p : values()) { | ||
if (p.name().equalsIgnoreCase(name)) { | ||
return p; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown permission '" + name + "'."); | ||
} | ||
|
||
|
||
/** | ||
* Returns a {@link Permission} with the specified IRI or constant name. | ||
* <p> | ||
* This function first tries to find the enum constant by IRI. If it is not found, constant name matching is | ||
* attempted. | ||
* | ||
* @param identification Constant IRI or name to find match by | ||
* @return matching {@code Permission} | ||
* @throws IllegalArgumentException When no matching permission is found | ||
*/ | ||
public static Permission fromIriOrName(String identification) { | ||
try { | ||
return fromIri(identification); | ||
} catch (IllegalArgumentException e) { | ||
return fromName(identification); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cz.cvut.kbss.study.model; | ||
|
||
import cz.cvut.kbss.jopa.model.annotations.Id; | ||
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 lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.net.URI; | ||
import java.util.Set; | ||
|
||
@OWLClass(iri = Vocabulary.s_c_role) | ||
@Getter | ||
@Setter | ||
public class Role { | ||
|
||
@Id | ||
private URI uri; | ||
|
||
@OWLDataProperty(iri = Vocabulary.s_p_roleName) | ||
private String roleName; | ||
|
||
@OWLObjectProperty(iri = Vocabulary.s_p_has_permission) | ||
private Set<Permission> permission; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.