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:
Costantino Perciante 2016-09-09 14:38:05 +00:00
parent f8de0ce20a
commit 73a187b382
3 changed files with 16 additions and 63 deletions

View File

@ -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
* from ScopeProvider is returned).
* @param url
* @return the scope to be used
* @return the scope to be used for the given url
*/
public String getScopePerUrl(String url){
logger.debug("Request scope for ckan portlet at url " + url);
if(url == null || url.isEmpty())
throw new IllegalArgumentException();
throw new IllegalArgumentException("The url passed is null or empty!");
String scopeToReturn = null;
String scope = ScopeProvider.instance.get();

View File

@ -95,8 +95,8 @@ public interface CKanUtils {
/**
* Set dataset private
* @param priv
* @param organizationId
* @param datasetId
* @param organizationId (NOTE: The ID, not the name!)
* @param datasetId (NOTE: The ID, not the name!)
* @param apiKey the user's api key
* @return true on success, false otherwise
*/
@ -133,7 +133,7 @@ public interface CKanUtils {
* @param tags
* @param customFields
* @param resources
* @param setPublic (manage visibility)
* @param setPublic (manage visibility: Admin role is needed)
* @return the id of the dataset on success, null otherwise
*/
String createCKanDataset(String apiKey, String title, String organizationNameOrId, String author,
@ -158,7 +158,7 @@ public interface CKanUtils {
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 organizationName
* @param correspondentRoleToCheck
@ -167,15 +167,6 @@ public interface CKanUtils {
boolean checkRole(String username, String organizationName,
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

View File

@ -5,8 +5,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
@ -19,8 +17,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.net.ssl.HttpsURLConnection;
import net.htmlparser.jericho.Renderer;
import net.htmlparser.jericho.Segment;
import net.htmlparser.jericho.Source;
@ -477,7 +473,6 @@ public class CKanUtilsImpl implements CKanUtils{
+ "\"datasets\":[\"DATASET_ID\"]"
+ "}";
if(organizationId != null && !organizationId.isEmpty() && datasetId != null && !datasetId.isEmpty()){
// replace with right data
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);
}
}
}
return false;
}
@ -631,12 +625,14 @@ public class CKanUtilsImpl implements CKanUtils{
dataset.setVersion(String.valueOf(version));
// description must be escaped
Source descriptionEscaped = new Source(description);
Segment htmlSeg = new Segment(descriptionEscaped, 0, descriptionEscaped.length());
Renderer htmlRend = new Renderer(htmlSeg);
dataset.setNotes(htmlRend.toString());
if(description != null && !description.isEmpty()){
Source descriptionEscaped = new Source(description);
Segment htmlSeg = new Segment(descriptionEscaped, 0, descriptionEscaped.length());
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);
@ -712,11 +708,13 @@ public class CKanUtilsImpl implements CKanUtils{
logger.debug("Dataset with name " + res.getName() + " has been created. Setting visibility");
// set visibility
setDatasetPrivate(
boolean visibilitySet = setDatasetPrivate(
!setPublic, // swap to private
res.getOrganization().getId(),
res.getId(),
apiKey);
logger.debug("Is visibility set to " + (setPublic ? "public" : "private") + "? " + visibilitySet);
return res.getId();
}
@ -874,42 +872,6 @@ public class CKanUtilsImpl implements CKanUtils{
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
public boolean createDatasetRelationship(String datasetIdSubject,
String datasetIdObject, DatasetRelationships relation, String relationComment, String apiKey) {