62 lines
1.5 KiB
Java
62 lines
1.5 KiB
Java
package org.gcube.gcat.api;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
*/
|
|
public enum Role {
|
|
|
|
MEMBER(GCatConstants.CATALOGUE_MEMBER, "member"), EDITOR(GCatConstants.CATALOGUE_EDITOR, "editor"), ADMIN(GCatConstants.CATALOGUE_ADMIN, "admin");
|
|
|
|
private final String portalRole;
|
|
private final String ckanRole;
|
|
|
|
Role(String portalRole, String ckanRole) {
|
|
this.portalRole = portalRole;
|
|
this.ckanRole = ckanRole;
|
|
}
|
|
|
|
public String getPortalRole() {
|
|
return portalRole;
|
|
}
|
|
|
|
public String getCkanRole() {
|
|
return ckanRole;
|
|
}
|
|
|
|
protected static final Map<String,Role> ROLE_BY_PORTAL_ROLE;
|
|
protected static final Map<String,Role> ROLE_BY_CKAN_ROLE;
|
|
|
|
static {
|
|
ROLE_BY_PORTAL_ROLE = new HashMap<String,Role>();
|
|
|
|
// null or empty string identify a member
|
|
ROLE_BY_PORTAL_ROLE.put(null, MEMBER);
|
|
ROLE_BY_PORTAL_ROLE.put("", MEMBER);
|
|
|
|
ROLE_BY_CKAN_ROLE = new HashMap<String,Role>();
|
|
|
|
for(Role role : Role.values()) {
|
|
ROLE_BY_PORTAL_ROLE.put(role.getPortalRole(), role);
|
|
ROLE_BY_CKAN_ROLE.put(role.getCkanRole(), role);
|
|
}
|
|
}
|
|
|
|
public static Role getRoleFromPortalRole(String portalRole) {
|
|
return ROLE_BY_PORTAL_ROLE.get(portalRole);
|
|
}
|
|
|
|
public static String getCkanRoleFromPortalRole(String portalRole) {
|
|
return getRoleFromPortalRole(portalRole).getCkanRole();
|
|
}
|
|
|
|
public static Role getRoleFromCkanRole(String ckanRole) {
|
|
return ROLE_BY_CKAN_ROLE.get(ckanRole);
|
|
}
|
|
|
|
public static String getPortalRoleFromCkanRole(String ckanRole) {
|
|
return getRoleFromCkanRole(ckanRole).getPortalRole();
|
|
}
|
|
} |