Moved enums from gcat service to gcat-api
This commit is contained in:
parent
ef46b5ca0a
commit
cd9a1069ec
|
@ -0,0 +1,40 @@
|
||||||
|
package org.gcube.gcat.api;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
public enum CMItemStatus {
|
||||||
|
|
||||||
|
PENDING("pending"),
|
||||||
|
APPROVED("approved"),
|
||||||
|
REJECTED("rejected");
|
||||||
|
|
||||||
|
protected static final Map<String,CMItemStatus> CM_ITEM_STATUS_FROM_VALUE;
|
||||||
|
|
||||||
|
static {
|
||||||
|
CM_ITEM_STATUS_FROM_VALUE = new HashMap<>();
|
||||||
|
|
||||||
|
for(CMItemStatus s : CMItemStatus.values()) {
|
||||||
|
CM_ITEM_STATUS_FROM_VALUE.put(s.getValue(), s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final String value;
|
||||||
|
|
||||||
|
private CMItemStatus(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CMItemStatus getCMItemStatusFromValue(String value) {
|
||||||
|
return CM_ITEM_STATUS_FROM_VALUE.get(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package org.gcube.gcat.api;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
|
public enum CMItemVisibility {
|
||||||
|
|
||||||
|
RESTRICTED("restricted"),
|
||||||
|
PUBLIC("public");
|
||||||
|
|
||||||
|
protected static final Map<String,CMItemStatus> CM_ITEM_VISIBILITY_FROM_VALUE;
|
||||||
|
|
||||||
|
static {
|
||||||
|
CM_ITEM_VISIBILITY_FROM_VALUE = new HashMap<>();
|
||||||
|
|
||||||
|
for(CMItemStatus s : CMItemStatus.values()) {
|
||||||
|
CM_ITEM_VISIBILITY_FROM_VALUE.put(s.getValue(), s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final String value;
|
||||||
|
|
||||||
|
private CMItemVisibility(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CMItemStatus getCMItemStatusFromValue(String value) {
|
||||||
|
return CM_ITEM_VISIBILITY_FROM_VALUE.get(value);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
package org.gcube.gcat.api;
|
package org.gcube.gcat.api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
public class GCatConstants {
|
public class GCatConstants {
|
||||||
|
|
||||||
public static final String SERVICE_CLASS = "data-catalogue";
|
public static final String SERVICE_CLASS = "data-catalogue";
|
||||||
|
@ -21,4 +24,13 @@ public class GCatConstants {
|
||||||
|
|
||||||
public static final String ORGANIZATION_FILTER_TEMPLATE = ORGANIZATION_PARAMETER + ":%s";
|
public static final String ORGANIZATION_FILTER_TEMPLATE = ORGANIZATION_PARAMETER + ":%s";
|
||||||
|
|
||||||
|
public static final String CATALOGUE_MEMBER = "Catalogue-Member";
|
||||||
|
public static final String CATALOGUE_EDITOR = "Catalogue-Editor";
|
||||||
|
public static final String CATALOGUE_ADMIN = "Catalogue-Admin";
|
||||||
|
public static final String CATALOGUE_MODERATOR = "Catalogue-Moderator";
|
||||||
|
|
||||||
|
/* Content Moderation fields */
|
||||||
|
public static final String CM_ITEM_STATUS = "system:cm_item_status";
|
||||||
|
public static final String CM_ITEM_VISIBILITY = "system:cm_item_visibility";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue