202 lines
4.0 KiB
Java
202 lines
4.0 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
* The Class CkanConnectorAccessPoint.
|
|
*
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
* Jun 23, 2016
|
|
*/
|
|
public class CkanConnectorAccessPoint implements Serializable{
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 3771903616375335843L;
|
|
|
|
private static final String LIST_OF_VRES_PARAMETER = "listOfVres";
|
|
private static final String GCUBE_TOKEN_PARAMETER = "gcube-token";
|
|
private String baseUrl;
|
|
private String pathInfoParameter;
|
|
private String queryStringParameters;
|
|
private String gcubeTokenValue;
|
|
private List<String> listOfVRes;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public CkanConnectorAccessPoint() {
|
|
}
|
|
|
|
/**
|
|
* Instantiates a new ckan connector access point.
|
|
*
|
|
* @param baseUrl the base url
|
|
*/
|
|
public CkanConnectorAccessPoint(String baseUrl){
|
|
this.baseUrl = baseUrl;
|
|
}
|
|
|
|
/**
|
|
* Adds the generic parameter.
|
|
*
|
|
* @param key the key
|
|
* @param value the value
|
|
*/
|
|
public void addGenericParameter(String key, String value){
|
|
queryStringParameters=queryStringParameters==null?key+"="+value:queryStringParameters+"&"+key+"="+value;
|
|
}
|
|
|
|
|
|
/**
|
|
* Adds the query string.
|
|
*
|
|
* @param queryString the query string
|
|
*/
|
|
public void addQueryString(String queryString){
|
|
|
|
if(queryString==null || queryString.isEmpty())
|
|
return;
|
|
|
|
if(queryString.startsWith("&")){
|
|
queryString = queryString.substring(1, queryString.length()); //removes '&'
|
|
}
|
|
|
|
queryStringParameters=queryStringParameters==null?queryString:queryStringParameters+"&"+queryString;
|
|
}
|
|
|
|
/**
|
|
* Adds the gube token.
|
|
*
|
|
* @param value the value
|
|
*/
|
|
public void addGubeToken(String value){
|
|
this.gcubeTokenValue = value;
|
|
addGenericParameter(GCUBE_TOKEN_PARAMETER, value);
|
|
}
|
|
|
|
/**
|
|
* Adds the list of vr es.
|
|
*
|
|
* @param listVREs the list vr es
|
|
*/
|
|
public void addListOfVREs(List<String> listVREs){
|
|
this.listOfVRes = listVREs;
|
|
String vres = "";
|
|
if(listVREs!=null && listVREs.size()>0){
|
|
for (String vre : listVREs) {
|
|
vres+=vre+",";
|
|
}
|
|
vres = vres.substring(0, vres.length()-1).toLowerCase(); //remove last "," and to lower case. A CKAN Organization ID must be lower case
|
|
}
|
|
|
|
if(vres.length()>0){
|
|
addGenericParameter(LIST_OF_VRES_PARAMETER, vres);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Adds the path info.
|
|
*
|
|
* @param pathInfo the path info
|
|
*/
|
|
public void addPathInfo(String pathInfo){
|
|
pathInfoParameter = pathInfo;
|
|
}
|
|
|
|
|
|
/**
|
|
* Builds the uri to contact the CKAN Connector.
|
|
*
|
|
* @return the string
|
|
*/
|
|
public String buildURI(){
|
|
|
|
if(pathInfoParameter!=null && !pathInfoParameter.isEmpty())
|
|
pathInfoParameter=pathInfoParameter.startsWith("/")?pathInfoParameter:"/"+pathInfoParameter;
|
|
else
|
|
pathInfoParameter="";
|
|
|
|
if(queryStringParameters==null)
|
|
queryStringParameters="";
|
|
|
|
return baseUrl+pathInfoParameter+"?"+queryStringParameters;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* @return the baseUrl
|
|
*/
|
|
public String getBaseUrl() {
|
|
|
|
return baseUrl;
|
|
}
|
|
|
|
|
|
/**
|
|
* @return the pathInfoParameter
|
|
*/
|
|
public String getPathInfoParameter() {
|
|
|
|
return pathInfoParameter;
|
|
}
|
|
|
|
|
|
/**
|
|
* @return the queryStringParameters
|
|
*/
|
|
public String getQueryStringParameters() {
|
|
|
|
return queryStringParameters;
|
|
}
|
|
|
|
|
|
/**
|
|
* @return the gcubeTokenValue
|
|
*/
|
|
public String getGcubeTokenValue() {
|
|
|
|
return gcubeTokenValue;
|
|
}
|
|
|
|
|
|
/**
|
|
* @return the listOfVRes
|
|
*/
|
|
public List<String> getListOfVRes() {
|
|
|
|
return listOfVRes;
|
|
}
|
|
|
|
/* (non-Javadoc)
|
|
* @see java.lang.Object#toString()
|
|
*/
|
|
@Override
|
|
public String toString() {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
builder.append("CkanConnectorAccessPoint [baseUrl=");
|
|
builder.append(baseUrl);
|
|
builder.append(", pathInfoParameter=");
|
|
builder.append(pathInfoParameter);
|
|
builder.append(", queryStringParameters=");
|
|
builder.append(queryStringParameters);
|
|
builder.append(", gcubeTokenValue=");
|
|
builder.append(gcubeTokenValue);
|
|
builder.append(", listOfVRes=");
|
|
builder.append(listOfVRes);
|
|
builder.append("]");
|
|
return builder.toString();
|
|
}
|
|
|
|
}
|