added code to set both title and name (if needed) for dataset creation. In case the name is not available, the title is transformed to match a well fitted ckan name

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@133894 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-11-04 10:13:18 +00:00
parent b9733b9154
commit cbe92db9d1
3 changed files with 18 additions and 14 deletions

View File

@ -114,6 +114,7 @@ public interface DataCatalogue {
* Create a dataset with those information.
* @param apiKey
* @param title
* @param name (unique identifier)
* @param organizationNameOrId
* @param author
* @param authorMail
@ -128,7 +129,7 @@ public interface DataCatalogue {
* @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,
String createCKanDataset(String apiKey, String title, String name, 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);
@ -138,6 +139,7 @@ public interface DataCatalogue {
* for the method)
* @param apiKey
* @param title
* @param name (unique identifier)
* @param organizationNameOrId
* @param author
* @param authorMail
@ -152,7 +154,7 @@ public interface DataCatalogue {
* @param setPublic (manage visibility: Admin role is needed)
* @return the id of the dataset on success, null otherwise
*/
String createCKanDatasetMultipleCustomFields(String apiKey, String title, String organizationNameOrId, String author,
String createCKanDatasetMultipleCustomFields(String apiKey, String title, String name, String organizationNameOrId, String author,
String authorMail, String maintainer, String maintainerMail, long version, String description, String licenseId,
List<String> tags, Map<String, List<String>> customFields, List<ResourceBean> resources, boolean setPublic);

View File

@ -612,7 +612,7 @@ public class DataCatalogueImpl implements DataCatalogue{
@Override
public String createCKanDataset(String apiKey,
String title, String organizationNameOrId, String author,
String title, String name, String organizationNameOrId, String author,
String authorMail, String maintainer, String maintainerMail,
long version, String description, String licenseId,
List<String> tags, Map<String, String> customFields,
@ -620,7 +620,7 @@ public class DataCatalogueImpl implements DataCatalogue{
// delegate the private method
return createCkanDatasetBody(apiKey,
title, organizationNameOrId, author,
title, name, organizationNameOrId, author,
authorMail, maintainer,maintainerMail,
version, description, licenseId,
tags, customFields, null,
@ -629,7 +629,7 @@ public class DataCatalogueImpl implements DataCatalogue{
@Override
public String createCKanDatasetMultipleCustomFields(String apiKey,
String title, String organizationNameOrId, String author,
String title, String name, String organizationNameOrId, String author,
String authorMail, String maintainer, String maintainerMail,
long version, String description, String licenseId,
List<String> tags, Map<String, List<String>> customFieldsMultiple,
@ -637,7 +637,7 @@ public class DataCatalogueImpl implements DataCatalogue{
// delegate the private method
return createCkanDatasetBody(apiKey,
title, organizationNameOrId, author,
title, name, organizationNameOrId, author,
authorMail, maintainer,maintainerMail,
version, description, licenseId,
tags, null, customFieldsMultiple,
@ -646,7 +646,7 @@ public class DataCatalogueImpl implements DataCatalogue{
// the body of the actual dataset creation methods
private String createCkanDatasetBody(String apiKey,
String title, String organizationNameOrId, String author,
String title, String name, String organizationNameOrId, String author,
String authorMail, String maintainer, String maintainerMail,
long version, String description, String licenseId,
List<String> tags, Map<String, String> customFields,
@ -655,11 +655,10 @@ public class DataCatalogueImpl implements DataCatalogue{
// checks (minimum)
checkNotNull(apiKey);
checkNotNull(title);
checkNotNull(organizationNameOrId);
checkArgument(!apiKey.isEmpty());
checkArgument(!title.isEmpty());
checkArgument(!organizationNameOrId.isEmpty());
checkArgument(!((title == null && name == null) || (title.isEmpty() && name.isEmpty())), "Name and Title cannot be empty/null at the same time!");
logger.debug("Request for dataset creation");
@ -672,9 +671,12 @@ public class DataCatalogueImpl implements DataCatalogue{
CkanDataset dataset = new CkanDataset();
// get the name from the title
String name = UtilMethods.fromProductTitleToName(title);
logger.debug("Name of the dataset is going to be " + name);
dataset.setName(name);
String nameToUse = name;
if(nameToUse == null)
name = UtilMethods.fromProductTitleToName(title);
logger.debug("Name of the dataset is going to be " + nameToUse);
dataset.setName(nameToUse);
dataset.setTitle(title);
CkanOrganization orgOwner = client.getOrganization(organizationNameOrId);

View File

@ -230,7 +230,7 @@ public class TestDataCatalogueLib {
public void editorCreateDataset() throws Exception{
DataCatalogueImpl instance = factory.getUtilsPerScope("/gcube/devsec/devVRE");
instance.createCKanDataset(instance.getApiKeyFromUsername("user_editor_devvre"), "dataset_as_editor_devvre_private", "devvre", null, null, null, null, 1, null, null, null, null, null, false);
instance.createCKanDataset(instance.getApiKeyFromUsername("user_editor_devvre"), "dataset_as_editor_devvre_private", null, "devvre", null, null, null, null, 1, null, null, null, null, null, false);
}
@ -239,7 +239,7 @@ public class TestDataCatalogueLib {
DataCatalogueImpl instance = factory.getUtilsPerScope("/gcube/devsec/devVRE");
//instance.createCKanDataset(instance.getApiKeyFromUsername("user_admin_devvre"), "dataset_as_admin_devvre", "devvre", null, null, null, null, 1, null, null, null, null, null, false);
instance.createCKanDataset(instance.getApiKeyFromUsername("user_admin_devvre"), "dataset_as_admin_devvre_private", "devvre", null, null, null, null, 1, null, null, null, null, null, false);
instance.createCKanDataset(instance.getApiKeyFromUsername("user_admin_devvre"), "dataset_as_admin_devvre_private", null, "devvre", null, null, null, null, 1, null, null, null, null, null, false);
}
//@Test