ckan-util-library/src/main/java/org/gcube/datacatalogue/ckanutillibrary/CKanUtilsInterface.java

161 lines
5.0 KiB
Java
Raw Normal View History

package org.gcube.datacatalogue.ckanutillibrary;
import java.util.List;
import java.util.Map;
import org.gcube.datacatalogue.ckanutillibrary.models.CKanUserWrapper;
import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean;
import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization;
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 {
/**
* Retrieve the API_KEY given the username (only if it is active).
* @param username
* @return an API_KEY string on success, null otherwise
*/
public String getApiKeyFromUsername(String username);
/**
* Retrieve the user given the API_KEY (the user is retrieved if it is active).
* @param the user api key
* @return an API_KEY string
*/
public CKanUserWrapper getUserFromApiKey(String apiKey);
/**
* Returns the list of organizations to whom the user belongs.
* @param username
* @return a list of organizations
*/
public List<CkanOrganization> getOrganizationsByUser(String username);
/**
* Returns the list of organizations' names to whom the user belongs.
* @param username
* @return a list of organizations
*/
public List<String> getOrganizationsNamesByUser(String username);
/**
* 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.
* @param username
* @param rolesToMatch
* @return
*/
public Map<String, List<RolesIntoOrganization>> getGroupsAndRolesByUser(String username, List<RolesIntoOrganization> rolesToMatch);
/**
* Return the ckan catalogue url in this scope.
* @return the catalogue url
*/
public String getCatalogueUrl();
/**
* Get the list of licenses' titles.
* @return the list of licenses' titles
*/
public List<String> getLicenseTitles();
/**
* Retrieve the list of organizations ids
* @return
*/
public List<String> getOrganizationsIds();
/**
* Retrieve the list of organizations names
* @return
*/
public List<String> getOrganizationsNames();
/**
* Finds the id associated to the chosen license
* @param chosenLicense
* @return the id on success, null otherwise
*/
public String findLicenseIdByLicense(String chosenLicense);
/**
* Set dataset private
* @param priv
* @param organizationId
* @param datasetId
* @param apiKey the user's api key
* @return true on success, false otherwise
*/
public boolean setDatasetPrivate(boolean priv, String organizationId, String datasetId, String apiKey);
/**
* Add a resource described by the bean to the dataset id into resource.datasetId
* @param resource
* @param apiKey the user api key
* @return String the id of the resource on success, null otherwise
*/
public String addResourceToDataset(ResourceBean resource, String apiKey);
/**
* Remove the resource with id resourceId from the dataset in which it is.
* @param resourceId
* @param apiKey the user's api key
* @return true on success, false otherwise.
*/
public boolean deleteResourceFromDataset(String resourceId, String apiKey);
/**
* Create a dataset with those information.
* @param apiKey
* @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
*/
public String createCKanDataset(String apiKey, String withId, String title, String organizationNameOrId, String author,
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)
* @param apiKey
* @param datasetId
* @return The url of the dataset on success, null otherwise
*/
public String getUrlFromDatasetIdOrName(String apiKey, String datasetIdOrName);
/**
* Check if this user is a sysadmin. The api key is used to authorize this call.
* @param username
* @param apiKey the current user's api key
* @return true on success, false otherwise
*/
public 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.
* @param username
* @param organizationName
* @param correspondentRoleToCheck
* @return true if the role can be set, false if it cannot
*/
public boolean checkRole(String username, String organizationName,
RolesIntoOrganization correspondentRoleToCheck);
}