188 lines
4.6 KiB
Java
188 lines
4.6 KiB
Java
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);
|
|
}
|
|
|
|
|
|
}
|