Added support for configuration management
This commit is contained in:
parent
b5dacfbfc4
commit
7d6de07bac
4
pom.xml
4
pom.xml
|
@ -48,5 +48,9 @@
|
|||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>gcube-jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -26,7 +26,6 @@ public class GCatConstants {
|
|||
|
||||
public static final String REFER_ONLY_RESOURCE_QUERY_PARAMETER = "refers_only";
|
||||
|
||||
|
||||
public static final String ORGANIZATION_FILTER_TEMPLATE = ORGANIZATION_PARAMETER + ":%s";
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,187 @@
|
|||
package org.gcube.gcat.api.configuration;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class CatalogueConfiguration {
|
||||
|
||||
public static final String CONTEXT_KEY = "context";
|
||||
public static final String CKAN_URL_KEY = "ckanURL";
|
||||
public static final String SOLR_URL_KEY = "solrURL";
|
||||
|
||||
protected String id;
|
||||
|
||||
protected String context;
|
||||
protected ScopeBean scopeBean;
|
||||
protected String defaultOrganization;
|
||||
protected Set<String> supportedOrganizations;
|
||||
|
||||
protected String ckanURL;
|
||||
protected String sysAdminToken;
|
||||
|
||||
protected String solrURL;
|
||||
|
||||
protected boolean socialPostEnabled;
|
||||
protected boolean notificationToUsersEnabled;
|
||||
|
||||
protected boolean moderationEnabled;
|
||||
|
||||
private ObjectMapper mapper;
|
||||
|
||||
/*
|
||||
* Return the CKAN organization name using the current context name
|
||||
*/
|
||||
public static String getOrganizationName(String context) {
|
||||
ScopeBean scopeBean = new ScopeBean(context);
|
||||
return getOrganizationName(scopeBean);
|
||||
}
|
||||
|
||||
public static String getOrganizationName(ScopeBean scopeBean) {
|
||||
String contextName = scopeBean.name();
|
||||
return contextName.toLowerCase().replace(" ", "_");
|
||||
}
|
||||
|
||||
private CatalogueConfiguration() {
|
||||
this.supportedOrganizations = new HashSet<>();
|
||||
|
||||
/* CKAN URL and sysAdminToken can only be retrieved from the IS*/
|
||||
this.ckanURL = null;
|
||||
this.sysAdminToken = null;
|
||||
|
||||
this.socialPostEnabled = true; // default is true
|
||||
this.notificationToUsersEnabled = false; // default is false
|
||||
|
||||
this.moderationEnabled = false; // default is false
|
||||
}
|
||||
|
||||
public CatalogueConfiguration(String context) {
|
||||
this();
|
||||
setContext(context);
|
||||
this.defaultOrganization = CatalogueConfiguration.getOrganizationName(context);
|
||||
this.supportedOrganizations.add(defaultOrganization);
|
||||
}
|
||||
|
||||
@JsonProperty(value = CKAN_URL_KEY)
|
||||
public String getCkanURL() {
|
||||
return ckanURL;
|
||||
}
|
||||
|
||||
public void setCkanURL(String ckanURL) {
|
||||
this.ckanURL = ckanURL;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getSysAdminToken() {
|
||||
return sysAdminToken;
|
||||
}
|
||||
|
||||
public void setSysAdminToken(String sysAdminToken) {
|
||||
this.sysAdminToken = sysAdminToken;
|
||||
}
|
||||
|
||||
@JsonProperty(value = SOLR_URL_KEY)
|
||||
public String getSolrURL() {
|
||||
return solrURL;
|
||||
}
|
||||
|
||||
public void setSolrURL(String solrURL) {
|
||||
this.solrURL = solrURL;
|
||||
}
|
||||
|
||||
public boolean isSocialPostEnabled() {
|
||||
return socialPostEnabled;
|
||||
}
|
||||
|
||||
public void setSocialPostEnabled(boolean socialPostEnabled) {
|
||||
this.socialPostEnabled = socialPostEnabled;
|
||||
}
|
||||
|
||||
public boolean isNotificationToUsersEnabled() {
|
||||
return notificationToUsersEnabled;
|
||||
}
|
||||
|
||||
public void setNotificationToUsersEnabled(boolean notificationToUsersEnabled) {
|
||||
this.notificationToUsersEnabled = notificationToUsersEnabled;
|
||||
}
|
||||
|
||||
public boolean isModerationEnabled() {
|
||||
return moderationEnabled;
|
||||
}
|
||||
|
||||
public void setModerationEnabled(boolean moderationEnabled) {
|
||||
this.moderationEnabled = moderationEnabled;
|
||||
}
|
||||
|
||||
@JsonProperty(value = CONTEXT_KEY)
|
||||
public String getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
@JsonSetter
|
||||
private void setContext(String context) {
|
||||
this.context = context;
|
||||
this.scopeBean = new ScopeBean(context);
|
||||
}
|
||||
|
||||
public String getDefaultOrganization() {
|
||||
if(defaultOrganization == null) {
|
||||
defaultOrganization = CatalogueConfiguration.getOrganizationName(context);
|
||||
}
|
||||
return defaultOrganization;
|
||||
}
|
||||
|
||||
public void setDefaultOrganization(String defaultOrganization) {
|
||||
this.defaultOrganization = defaultOrganization;
|
||||
}
|
||||
|
||||
public Set<String> getSupportedOrganizations() {
|
||||
if(supportedOrganizations.isEmpty()) {
|
||||
supportedOrganizations.add(getDefaultOrganization());
|
||||
}
|
||||
return supportedOrganizations;
|
||||
}
|
||||
|
||||
public void setSupportedOrganizations(Set<String> supportedOrganizations) {
|
||||
this.supportedOrganizations = supportedOrganizations;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setID(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public ScopeBean getScopeBean() {
|
||||
return scopeBean;
|
||||
}
|
||||
|
||||
public ObjectNode toObjetNode() throws JsonProcessingException {
|
||||
if(mapper==null) {
|
||||
mapper = new ObjectMapper();
|
||||
}
|
||||
return mapper.valueToTree(this);
|
||||
}
|
||||
|
||||
public String toJsonString() throws JsonProcessingException {
|
||||
if(mapper==null) {
|
||||
mapper = new ObjectMapper();
|
||||
}
|
||||
return mapper.writeValueAsString(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.gcube.gcat.api.interfaces;
|
||||
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public interface Configuration<C,D> {
|
||||
|
||||
public static final String CONFIGURATION = "configuration";
|
||||
|
||||
public static final String CURRENT_CONTEXT_PATH_PARAMETER = "CURRENT_CONTEXT";
|
||||
|
||||
public C create(String json) throws WebServiceException;
|
||||
|
||||
public String read() throws WebServiceException ;
|
||||
|
||||
public String update(String json) throws WebServiceException;
|
||||
|
||||
public String patch(String json) throws WebServiceException;
|
||||
|
||||
public D delete() throws WebServiceException;
|
||||
|
||||
public D purge() throws WebServiceException;
|
||||
|
||||
}
|
|
@ -10,11 +10,13 @@ public enum Role {
|
|||
|
||||
MEMBER(Role.CATALOGUE_MEMBER, "member"),
|
||||
EDITOR(Role.CATALOGUE_EDITOR, "editor"),
|
||||
ADMIN(Role.CATALOGUE_ADMIN, "admin");
|
||||
ADMIN(Role.CATALOGUE_ADMIN, "admin"),
|
||||
MANAGER(Role.CATALOGUE_MANAGER, "admin");
|
||||
|
||||
private static final String CATALOGUE_ADMIN = "Catalogue-Admin";
|
||||
private static final String CATALOGUE_EDITOR = "Catalogue-Editor";
|
||||
private static final String CATALOGUE_MEMBER = "Catalogue-Member";
|
||||
private static final String CATALOGUE_MANAGER = "Catalogue-Manager";
|
||||
|
||||
private final String portalRole;
|
||||
private final String ckanRole;
|
||||
|
|
Loading…
Reference in New Issue