2016-06-07 16:00:05 +02:00
|
|
|
package org.gcube.datacatalogue.ckanutillibrary;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.models.CKanUserWrapper;
|
2016-06-14 12:31:19 +02:00
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean;
|
2016-06-14 17:05:24 +02:00
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization;
|
2016-06-07 16:00:05 +02:00
|
|
|
|
|
|
|
import eu.trentorise.opendata.jackan.model.CkanOrganization;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the ckan-util-library interface that shows the utility methods.
|
|
|
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
|
|
|
*/
|
|
|
|
public interface CKanUtilsInterface {
|
2016-06-10 16:26:01 +02:00
|
|
|
|
2016-06-07 16:00:05 +02:00
|
|
|
/**
|
2016-06-14 17:05:24 +02:00
|
|
|
* Retrieve the API_KEY given the username (only if it is active).
|
2016-06-07 16:00:05 +02:00
|
|
|
* @param username
|
2016-06-14 17:05:24 +02:00
|
|
|
* @return an API_KEY string on success, null otherwise
|
2016-06-07 16:00:05 +02:00
|
|
|
*/
|
2016-06-16 18:09:26 +02:00
|
|
|
public String getApiKeyFromUsername(String username);
|
2016-06-10 16:26:01 +02:00
|
|
|
|
2016-06-07 16:00:05 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the user given the API_KEY (the user is retrieved if it is active).
|
2016-06-16 18:09:26 +02:00
|
|
|
* @param the user api key
|
2016-06-07 16:00:05 +02:00
|
|
|
* @return an API_KEY string
|
|
|
|
*/
|
|
|
|
public CKanUserWrapper getUserFromApiKey(String apiKey);
|
2016-06-10 16:26:01 +02:00
|
|
|
|
2016-06-07 16:00:05 +02:00
|
|
|
/**
|
|
|
|
* Returns the list of organizations to whom the user belongs.
|
|
|
|
* @param username
|
|
|
|
* @return a list of organizations
|
|
|
|
*/
|
|
|
|
public List<CkanOrganization> getOrganizationsByUser(String username);
|
2016-06-10 16:26:01 +02:00
|
|
|
|
2016-06-07 16:00:05 +02:00
|
|
|
/**
|
|
|
|
* Returns the list of organizations' names to whom the user belongs.
|
|
|
|
* @param username
|
|
|
|
* @return a list of organizations
|
|
|
|
*/
|
|
|
|
public List<String> getOrganizationsNamesByUser(String username);
|
2016-06-10 16:26:01 +02:00
|
|
|
|
2016-06-07 16:00:05 +02:00
|
|
|
/**
|
2016-06-14 17:05:24 +02:00
|
|
|
* Given a username and a list of roles to be matched, find the organizations in which the user has these roles.
|
|
|
|
* If the user is a sysadmin, for every organization in the map, the role will be present as well.
|
2016-06-07 16:00:05 +02:00
|
|
|
* @param username
|
|
|
|
* @param rolesToMatch
|
|
|
|
* @return
|
|
|
|
*/
|
2016-06-14 17:05:24 +02:00
|
|
|
public Map<String, List<RolesIntoOrganization>> getGroupsAndRolesByUser(String username, List<RolesIntoOrganization> rolesToMatch);
|
2016-06-07 16:00:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the ckan catalogue url in this scope.
|
2016-06-16 18:09:26 +02:00
|
|
|
* @return the catalogue url
|
2016-06-07 16:00:05 +02:00
|
|
|
*/
|
|
|
|
public String getCatalogueUrl();
|
2016-06-10 16:26:01 +02:00
|
|
|
|
2016-06-07 16:00:05 +02:00
|
|
|
/**
|
|
|
|
* Get the list of licenses' titles.
|
2016-06-08 18:31:25 +02:00
|
|
|
* @return the list of licenses' titles
|
2016-06-07 16:00:05 +02:00
|
|
|
*/
|
|
|
|
public List<String> getLicenseTitles();
|
2016-06-18 10:12:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the list of organizations ids
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<String> getOrganizationsIds();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the list of organizations names
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<String> getOrganizationsNames();
|
2016-06-10 16:26:01 +02:00
|
|
|
|
2016-06-07 16:00:05 +02:00
|
|
|
/**
|
|
|
|
* Finds the id associated to the chosen license
|
|
|
|
* @param chosenLicense
|
2016-06-08 18:31:25 +02:00
|
|
|
* @return the id on success, null otherwise
|
2016-06-07 16:00:05 +02:00
|
|
|
*/
|
|
|
|
public String findLicenseIdByLicense(String chosenLicense);
|
2016-06-10 16:26:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set dataset private
|
|
|
|
* @param priv
|
|
|
|
* @param organizationId
|
|
|
|
* @param datasetId
|
2016-06-16 18:09:26 +02:00
|
|
|
* @param apiKey the user's api key
|
2016-06-10 16:26:01 +02:00
|
|
|
* @return true on success, false otherwise
|
|
|
|
*/
|
2016-06-16 18:09:26 +02:00
|
|
|
public boolean setDatasetPrivate(boolean priv, String organizationId, String datasetId, String apiKey);
|
2016-06-10 16:26:01 +02:00
|
|
|
|
2016-06-14 12:31:19 +02:00
|
|
|
/**
|
|
|
|
* Add a resource described by the bean to the dataset id into resource.datasetId
|
|
|
|
* @param resource
|
2016-06-16 18:09:26 +02:00
|
|
|
* @param apiKey the user api key
|
2016-06-14 12:31:19 +02:00
|
|
|
* @return String the id of the resource on success, null otherwise
|
|
|
|
*/
|
2016-06-16 18:09:26 +02:00
|
|
|
public String addResourceToDataset(ResourceBean resource, String apiKey);
|
2016-06-14 12:31:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the resource with id resourceId from the dataset in which it is.
|
|
|
|
* @param resourceId
|
2016-06-16 18:09:26 +02:00
|
|
|
* @param apiKey the user's api key
|
2016-06-14 12:31:19 +02:00
|
|
|
* @return true on success, false otherwise.
|
|
|
|
*/
|
2016-06-16 18:09:26 +02:00
|
|
|
public boolean deleteResourceFromDataset(String resourceId, String apiKey);
|
2016-06-14 12:31:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a dataset with those information.
|
2016-06-16 18:09:26 +02:00
|
|
|
* @param apiKey
|
2016-06-14 12:31:19 +02:00
|
|
|
* @param withId
|
|
|
|
* @param title
|
|
|
|
* @param organizationNameOrId
|
|
|
|
* @param author
|
|
|
|
* @param authorMail
|
|
|
|
* @param maintainer
|
|
|
|
* @param maintainerMail
|
|
|
|
* @param version
|
|
|
|
* @param description
|
|
|
|
* @param licenseId
|
|
|
|
* @param tags
|
|
|
|
* @param customFields
|
|
|
|
* @param resources
|
|
|
|
* @param setPublic (manage visibility)
|
|
|
|
* @return the id of the dataset on success, null otherwise
|
|
|
|
*/
|
2016-06-16 18:09:26 +02:00
|
|
|
public String createCKanDataset(String apiKey, String withId, String title, String organizationNameOrId, String author,
|
2016-06-14 12:31:19 +02:00
|
|
|
String authorMail, String maintainer, String maintainerMail, long version, String description, String licenseId,
|
|
|
|
List<String> tags, Map<String, String> customFields, List<ResourceBean> resources, boolean setPublic);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given the id or the name of the dataset it returns its current url (e.g., http://ckan-catalogue-address.org/dataset/dataset-name)
|
2016-06-16 18:09:26 +02:00
|
|
|
* @param apiKey
|
2016-06-14 12:31:19 +02:00
|
|
|
* @param datasetId
|
|
|
|
* @return The url of the dataset on success, null otherwise
|
|
|
|
*/
|
2016-06-16 18:09:26 +02:00
|
|
|
public String getUrlFromDatasetIdOrName(String apiKey, String datasetIdOrName);
|
2016-06-14 17:05:24 +02:00
|
|
|
|
|
|
|
/**
|
2016-06-16 18:09:26 +02:00
|
|
|
* Check if this user is a sysadmin. The api key is used to authorize this call.
|
2016-06-14 17:05:24 +02:00
|
|
|
* @param username
|
2016-06-16 18:09:26 +02:00
|
|
|
* @param apiKey the current user's api key
|
2016-06-14 17:05:24 +02:00
|
|
|
* @return true on success, false otherwise
|
|
|
|
*/
|
2016-06-16 18:09:26 +02:00
|
|
|
public boolean isSysAdmin(String username, String apiKey);
|
2016-06-14 17:05:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if this role is present for this user in that organization. If it is not present we need to add it.
|
|
|
|
* @param username
|
|
|
|
* @param organizationName
|
|
|
|
* @param correspondentRoleToCheck
|
2016-06-18 10:05:10 +02:00
|
|
|
* @return true if the role can be set, false if it cannot
|
2016-06-14 17:05:24 +02:00
|
|
|
*/
|
2016-06-18 10:05:10 +02:00
|
|
|
public boolean checkRole(String username, String organizationName,
|
2016-06-14 17:05:24 +02:00
|
|
|
RolesIntoOrganization correspondentRoleToCheck);
|
2016-06-07 16:00:05 +02:00
|
|
|
}
|