added method to pass multiple values for the same key for custom fields (basically a Map<String, List<String>>). the old method is still there
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@133424 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
32981b71ee
commit
e143607f13
|
@ -132,6 +132,30 @@ public interface DataCatalogue {
|
|||
String authorMail, String maintainer, String maintainerMail, long version, String description, String licenseId,
|
||||
List<String> tags, Map<String, String> customFields, List<ResourceBean> resources, boolean setPublic);
|
||||
|
||||
/**
|
||||
* Create a dataset with those information. The method allows to have multiple values for the same custom field key.
|
||||
* NOTE: unfortunately java doesn't support overload in java interface methods (that's way I cannot use the same name
|
||||
* for the method)
|
||||
* @param apiKey
|
||||
* @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: 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 authorMail, String maintainer, String maintainerMail, long version, String description, String licenseId,
|
||||
List<String> tags, Map<String, List<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
|
||||
|
@ -296,7 +320,7 @@ public interface DataCatalogue {
|
|||
* @return
|
||||
*/
|
||||
boolean deleteProduct(String datasetId, String apiKey, boolean purge);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a ckan dataset given its id
|
||||
* @param datasetId
|
||||
|
|
|
@ -618,6 +618,41 @@ public class DataCatalogueImpl implements DataCatalogue{
|
|||
List<String> tags, Map<String, String> customFields,
|
||||
List<ResourceBean> resources, boolean setPublic) {
|
||||
|
||||
// delegate the private method
|
||||
return createCkanDatasetBody(apiKey,
|
||||
title, organizationNameOrId, author,
|
||||
authorMail, maintainer,maintainerMail,
|
||||
version, description, licenseId,
|
||||
tags, customFields, null,
|
||||
resources, setPublic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createCKanDatasetMultipleCustomFields(String apiKey,
|
||||
String title, String organizationNameOrId, String author,
|
||||
String authorMail, String maintainer, String maintainerMail,
|
||||
long version, String description, String licenseId,
|
||||
List<String> tags, Map<String, List<String>> customFieldsMultiple,
|
||||
List<ResourceBean> resources, boolean setPublic) {
|
||||
|
||||
// delegate the private method
|
||||
return createCkanDatasetBody(apiKey,
|
||||
title, organizationNameOrId, author,
|
||||
authorMail, maintainer,maintainerMail,
|
||||
version, description, licenseId,
|
||||
tags, null, customFieldsMultiple,
|
||||
resources, setPublic);
|
||||
}
|
||||
|
||||
// the body of the actual dataset creation methods
|
||||
private String createCkanDatasetBody(String apiKey,
|
||||
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,
|
||||
Map<String, List<String>> customFieldsMultipleValues,
|
||||
List<ResourceBean> resources, boolean setPublic){
|
||||
|
||||
// checks (minimum)
|
||||
checkNotNull(apiKey);
|
||||
checkNotNull(title);
|
||||
|
@ -680,7 +715,7 @@ public class DataCatalogueImpl implements DataCatalogue{
|
|||
// iterate and create
|
||||
Iterator<Entry<String, String>> iterator = customFields.entrySet().iterator();
|
||||
|
||||
List<CkanPair> extras = new ArrayList<CkanPair>(customFields.entrySet().size());
|
||||
List<CkanPair> extras = new ArrayList<CkanPair>();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
|
@ -690,6 +725,24 @@ public class DataCatalogueImpl implements DataCatalogue{
|
|||
}
|
||||
|
||||
dataset.setExtras(extras);
|
||||
}else if(customFieldsMultipleValues != null && !customFieldsMultipleValues.isEmpty()){
|
||||
|
||||
// iterate and create
|
||||
Iterator<Entry<String, List<String>>> iterator = customFieldsMultipleValues.entrySet().iterator();
|
||||
|
||||
List<CkanPair> extras = new ArrayList<CkanPair>();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
Map.Entry<String, List<String>> entry = (Map.Entry<String, List<String>>) iterator.next();
|
||||
List<String> valuesForEntry = entry.getValue();
|
||||
for (String value : valuesForEntry) {
|
||||
extras.add(new CkanPair(entry.getKey(), value));
|
||||
}
|
||||
}
|
||||
|
||||
dataset.setExtras(extras);
|
||||
|
||||
}
|
||||
|
||||
// check if we need to add the resources
|
||||
|
@ -754,6 +807,7 @@ public class DataCatalogueImpl implements DataCatalogue{
|
|||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue