minor fixes
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@131267 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f8de0ce20a
commit
73a187b382
|
@ -37,14 +37,14 @@ public class ApplicationProfileScopePerUrlReader {
|
||||||
* Get the scope in which discover for this url. If the Application Profile doesn't contain it, the current scope (taken
|
* Get the scope in which discover for this url. If the Application Profile doesn't contain it, the current scope (taken
|
||||||
* from ScopeProvider is returned).
|
* from ScopeProvider is returned).
|
||||||
* @param url
|
* @param url
|
||||||
* @return the scope to be used
|
* @return the scope to be used for the given url
|
||||||
*/
|
*/
|
||||||
public String getScopePerUrl(String url){
|
public String getScopePerUrl(String url){
|
||||||
|
|
||||||
logger.debug("Request scope for ckan portlet at url " + url);
|
logger.debug("Request scope for ckan portlet at url " + url);
|
||||||
|
|
||||||
if(url == null || url.isEmpty())
|
if(url == null || url.isEmpty())
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException("The url passed is null or empty!");
|
||||||
|
|
||||||
String scopeToReturn = null;
|
String scopeToReturn = null;
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = ScopeProvider.instance.get();
|
||||||
|
|
|
@ -95,8 +95,8 @@ public interface CKanUtils {
|
||||||
/**
|
/**
|
||||||
* Set dataset private
|
* Set dataset private
|
||||||
* @param priv
|
* @param priv
|
||||||
* @param organizationId
|
* @param organizationId (NOTE: The ID, not the name!)
|
||||||
* @param datasetId
|
* @param datasetId (NOTE: The ID, not the name!)
|
||||||
* @param apiKey the user's api key
|
* @param apiKey the user's api key
|
||||||
* @return true on success, false otherwise
|
* @return true on success, false otherwise
|
||||||
*/
|
*/
|
||||||
|
@ -133,7 +133,7 @@ public interface CKanUtils {
|
||||||
* @param tags
|
* @param tags
|
||||||
* @param customFields
|
* @param customFields
|
||||||
* @param resources
|
* @param resources
|
||||||
* @param setPublic (manage visibility)
|
* @param setPublic (manage visibility: Admin role is needed)
|
||||||
* @return the id of the dataset on success, null otherwise
|
* @return the id of the dataset on success, null otherwise
|
||||||
*/
|
*/
|
||||||
String createCKanDataset(String apiKey, String title, String organizationNameOrId, String author,
|
String createCKanDataset(String apiKey, String title, String organizationNameOrId, String author,
|
||||||
|
@ -158,7 +158,7 @@ public interface CKanUtils {
|
||||||
boolean isSysAdmin(String username, String apiKey);
|
boolean isSysAdmin(String username, String apiKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this role is present for this user in that organization. If it is not present we need to add it.
|
* Check if this role is present for this user in that organization. If it is not present we need to add it with the given role.
|
||||||
* @param username
|
* @param username
|
||||||
* @param organizationName
|
* @param organizationName
|
||||||
* @param correspondentRoleToCheck
|
* @param correspondentRoleToCheck
|
||||||
|
@ -167,15 +167,6 @@ public interface CKanUtils {
|
||||||
boolean checkRole(String username, String organizationName,
|
boolean checkRole(String username, String organizationName,
|
||||||
RolesIntoOrganization correspondentRoleToCheck);
|
RolesIntoOrganization correspondentRoleToCheck);
|
||||||
|
|
||||||
/**
|
|
||||||
* The method tries to create an organization with name orgName
|
|
||||||
* @param orgName the name of the organization
|
|
||||||
* @param token the gcube token to perform the operation
|
|
||||||
* @return true on success, false otherwise
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
boolean createOrganization(String orgName, String token) throws Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the catalogue portlet for this context(i.e. scope)
|
* Return the catalogue portlet for this context(i.e. scope)
|
||||||
* @return
|
* @return
|
||||||
|
|
|
@ -5,8 +5,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
@ -19,8 +17,6 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
|
|
||||||
import net.htmlparser.jericho.Renderer;
|
import net.htmlparser.jericho.Renderer;
|
||||||
import net.htmlparser.jericho.Segment;
|
import net.htmlparser.jericho.Segment;
|
||||||
import net.htmlparser.jericho.Source;
|
import net.htmlparser.jericho.Source;
|
||||||
|
@ -477,7 +473,6 @@ public class CKanUtilsImpl implements CKanUtils{
|
||||||
+ "\"datasets\":[\"DATASET_ID\"]"
|
+ "\"datasets\":[\"DATASET_ID\"]"
|
||||||
+ "}";
|
+ "}";
|
||||||
|
|
||||||
if(organizationId != null && !organizationId.isEmpty() && datasetId != null && !datasetId.isEmpty()){
|
|
||||||
|
|
||||||
// replace with right data
|
// replace with right data
|
||||||
parameter = parameter.replace("ORGANIZATION_ID", organizationId);
|
parameter = parameter.replace("ORGANIZATION_ID", organizationId);
|
||||||
|
@ -515,7 +510,6 @@ public class CKanUtilsImpl implements CKanUtils{
|
||||||
logger.error("Error while trying to set public the dataset ", ex);
|
logger.error("Error while trying to set public the dataset ", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -631,12 +625,14 @@ public class CKanUtilsImpl implements CKanUtils{
|
||||||
dataset.setVersion(String.valueOf(version));
|
dataset.setVersion(String.valueOf(version));
|
||||||
|
|
||||||
// description must be escaped
|
// description must be escaped
|
||||||
Source descriptionEscaped = new Source(description);
|
if(description != null && !description.isEmpty()){
|
||||||
Segment htmlSeg = new Segment(descriptionEscaped, 0, descriptionEscaped.length());
|
Source descriptionEscaped = new Source(description);
|
||||||
Renderer htmlRend = new Renderer(htmlSeg);
|
Segment htmlSeg = new Segment(descriptionEscaped, 0, descriptionEscaped.length());
|
||||||
dataset.setNotes(htmlRend.toString());
|
Renderer htmlRend = new Renderer(htmlSeg);
|
||||||
|
dataset.setNotes(htmlRend.toString());
|
||||||
|
|
||||||
logger.debug("Description (escaped is ) " + htmlRend.toString());
|
logger.debug("Description (escaped is ) " + htmlRend.toString());
|
||||||
|
}
|
||||||
|
|
||||||
dataset.setLicenseId(licenseId);
|
dataset.setLicenseId(licenseId);
|
||||||
|
|
||||||
|
@ -712,11 +708,13 @@ public class CKanUtilsImpl implements CKanUtils{
|
||||||
logger.debug("Dataset with name " + res.getName() + " has been created. Setting visibility");
|
logger.debug("Dataset with name " + res.getName() + " has been created. Setting visibility");
|
||||||
|
|
||||||
// set visibility
|
// set visibility
|
||||||
setDatasetPrivate(
|
boolean visibilitySet = setDatasetPrivate(
|
||||||
!setPublic, // swap to private
|
!setPublic, // swap to private
|
||||||
res.getOrganization().getId(),
|
res.getOrganization().getId(),
|
||||||
res.getId(),
|
res.getId(),
|
||||||
apiKey);
|
apiKey);
|
||||||
|
|
||||||
|
logger.debug("Is visibility set to " + (setPublic ? "public" : "private") + "? " + visibilitySet);
|
||||||
|
|
||||||
return res.getId();
|
return res.getId();
|
||||||
}
|
}
|
||||||
|
@ -874,42 +872,6 @@ public class CKanUtilsImpl implements CKanUtils{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean createOrganization(String orgName, String token)throws Exception{
|
|
||||||
logger.debug("Create organization method call for creation of an organization named " + orgName);
|
|
||||||
|
|
||||||
// we invoke the ckan connector to create this organization
|
|
||||||
boolean result = false;
|
|
||||||
|
|
||||||
// checks
|
|
||||||
checkNotNull(orgName);
|
|
||||||
checkNotNull(token);
|
|
||||||
checkArgument(!token.isEmpty());
|
|
||||||
checkArgument(!orgName.isEmpty());
|
|
||||||
|
|
||||||
try{
|
|
||||||
String callUrl = CKAN_CATALOGUE_URL + "/ckan-connector/gcube/service/organization/" + orgName + "?gcube-token=" + token;
|
|
||||||
URL url = new URL(callUrl);
|
|
||||||
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
|
|
||||||
connection.setRequestMethod("PUT");
|
|
||||||
|
|
||||||
logger.debug("Response code is " + connection.getResponseCode() + " and message is " + connection.getResponseMessage());
|
|
||||||
|
|
||||||
if(connection.getResponseCode() == HttpURLConnection.HTTP_OK){
|
|
||||||
logger.info("CKan organization created [" + connection.getResponseMessage() + "]");
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// close the connection
|
|
||||||
connection.disconnect();
|
|
||||||
|
|
||||||
}catch(Exception e){
|
|
||||||
logger.error("Unable to create the organization", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean createDatasetRelationship(String datasetIdSubject,
|
public boolean createDatasetRelationship(String datasetIdSubject,
|
||||||
String datasetIdObject, DatasetRelationships relation, String relationComment, String apiKey) {
|
String datasetIdObject, DatasetRelationships relation, String relationComment, String apiKey) {
|
||||||
|
|
Loading…
Reference in New Issue