duplicated custom fields (i.e., with same keys) are now supported

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@139745 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-12-07 09:58:11 +00:00
parent 9699fd9fcc
commit f7da157540
4 changed files with 62 additions and 23 deletions

View File

@ -299,25 +299,28 @@ public class CreateDatasetForm extends Composite{
maintainerEmailTextbox.setText(bean.getMaintainerEmail()); maintainerEmailTextbox.setText(bean.getMaintainerEmail());
// retrieve custom fields // retrieve custom fields
Map<String, String> customFieldsMap = bean.getCustomFields(); Map<String, List<String>> customFieldsMap = bean.getCustomFields();
if(customFieldsMap != null){ if(customFieldsMap != null){
// get the keys and put them as tags // get the keys and put them as tags
Iterator<Entry<String, String>> iteratorOverCustomField = customFieldsMap.entrySet().iterator(); Iterator<Entry<String, List<String>>> iteratorOverCustomField = customFieldsMap.entrySet().iterator();
while (iteratorOverCustomField.hasNext()) { while (iteratorOverCustomField.hasNext()) {
Map.Entry<String, String> entry = (Map.Entry<String, String>) iteratorOverCustomField Map.Entry<java.lang.String, java.util.List<java.lang.String>> entry = (Map.Entry<java.lang.String, java.util.List<java.lang.String>>) iteratorOverCustomField
.next(); .next();
// these are fixed key, variable value custom fields List<String> values = entry.getValue();
CustomFieldEntry toAdd = new CustomFieldEntry(eventBus, entry.getKey(), entry.getValue(), false);
customFieldEntriesList.add(toAdd);
customFields.add(toAdd);
// add as tag for (String value : values) {
tagsPanel.addTagElement(entry.getKey()); // these are fixed key, variable value custom fields
CustomFieldEntry toAdd = new CustomFieldEntry(eventBus, entry.getKey(), value, false);
customFieldEntriesList.add(toAdd);
customFields.add(toAdd);
// add as tag
tagsPanel.addTagElement(entry.getKey());
}
} }
} }
@ -829,15 +832,25 @@ public class CreateDatasetForm extends Composite{
if(resourcesTwinPanel != null) if(resourcesTwinPanel != null)
receivedBean.setResources(resourcesTwinPanel.getResourcesToPublish()); receivedBean.setResources(resourcesTwinPanel.getResourcesToPublish());
Map<String, String> customFieldsMap = new HashMap<String, String>(); Map<String, List<String>> customFieldsMap = new HashMap<String, List<String>>();
// prepare custom fields // prepare custom fields
for (MetaDataFieldSkeleton field : listOfMetadataFields) { for (MetaDataFieldSkeleton field : listOfMetadataFields) {
String value = field.getFieldCurrentValue(); String value = field.getFieldCurrentValue();
if(!value.isEmpty()) if(!value.isEmpty()){
customFieldsMap.put(field.getFieldName(), field.getFieldCurrentValue()); String key = field.getFieldName();
List<String> valuesForThisField = null;
if(customFieldsMap.containsKey(key))
valuesForThisField = customFieldsMap.get(key);
else
valuesForThisField = new ArrayList<String>();
valuesForThisField.add(value);
customFieldsMap.put(key, valuesForThisField);
}
} }
@ -845,8 +858,18 @@ public class CreateDatasetForm extends Composite{
String key = customEntry.getKey(); String key = customEntry.getKey();
String value = customEntry.getValue(); String value = customEntry.getValue();
if(value != null && !value.isEmpty())
customFieldsMap.put(key, value); if(value != null && !value.isEmpty()){
List<String> valuesForThisField = null;
if(customFieldsMap.containsKey(key))
valuesForThisField = customFieldsMap.get(key);
else
valuesForThisField = new ArrayList<String>();
valuesForThisField.add(value);
customFieldsMap.put(key, valuesForThisField);
}
} }

View File

@ -250,7 +250,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
String chosenLicense = toCreate.getLicense(); String chosenLicense = toCreate.getLicense();
String licenseId = findLicenseIdByLicense(chosenLicense); String licenseId = findLicenseIdByLicense(chosenLicense);
List<String> listOfTags = toCreate.getTags(); List<String> listOfTags = toCreate.getTags();
Map<String, String> customFields = toCreate.getCustomFields(); Map<String, List<String>> customFields = toCreate.getCustomFields();
boolean setPublic = toCreate.getVisibility(); boolean setPublic = toCreate.getVisibility();
// get the list of resources and convert to ResourceBean // get the list of resources and convert to ResourceBean
@ -267,9 +267,9 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
DataCatalogue utils = getCatalogue(scope); DataCatalogue utils = getCatalogue(scope);
String userApiKey = utils.getApiKeyFromUsername(userName); String userApiKey = utils.getApiKeyFromUsername(userName);
String datasetId = utils.createCKanDataset(userApiKey, title, null, organizationNameOrId, author, String datasetId = utils.createCKanDatasetMultipleCustomFields
authorMail, maintainer, maintainerMail, version, description, licenseId, (userApiKey, title, null, organizationNameOrId, author, authorMail, maintainer,
listOfTags, customFields, resources, setPublic); maintainerMail, version, description, licenseId, listOfTags, customFields, resources, setPublic);
if(datasetId != null){ if(datasetId != null){

View File

@ -2,8 +2,11 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
@ -114,7 +117,20 @@ public class WorkspaceUtils {
// Create the folder in the catalogue // Create the folder in the catalogue
Map<String, String> folderItems = Utils.getGcubeItemProperties(originalFolder); Map<String, String> folderItems = Utils.getGcubeItemProperties(originalFolder);
bean.setCustomFields(folderItems);
if(folderItems != null){
// transform this properties
Map<String, List<String>> tempItems = new HashMap<String, List<String>>(folderItems.size());
Iterator<Entry<String, String>> iterator = folderItems.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<java.lang.String, java.lang.String> entry = (Map.Entry<java.lang.String, java.lang.String>) iterator
.next();
tempItems.put(entry.getKey(), Arrays.asList(entry.getValue()));
}
bean.setCustomFields(tempItems);
}
// set them into the bean // set them into the bean
bean.setResources(Arrays.asList(WorkspaceUtils.getTreeFromFolder(folderId, ws))); bean.setResources(Arrays.asList(WorkspaceUtils.getTreeFromFolder(folderId, ws)));

View File

@ -47,7 +47,7 @@ public class DatasetMetadataBean implements Serializable {
private List<ResourceElementBean> resources; // in case of workspace, this is the list of children of the folder private List<ResourceElementBean> resources; // in case of workspace, this is the list of children of the folder
private List<MetaDataProfileBean> metadataList; private List<MetaDataProfileBean> metadataList;
private List<String> tags; // on retrieve, they are the keys of the custom fields private List<String> tags; // on retrieve, they are the keys of the custom fields
private Map<String, String> customFields; private Map<String, List<String>> customFields;
private List<GroupBean> groups; private List<GroupBean> groups;
public DatasetMetadataBean(){ public DatasetMetadataBean(){
@ -76,7 +76,7 @@ public class DatasetMetadataBean implements Serializable {
* @param metadataList * @param metadataList
*/ */
public DatasetMetadataBean(String id, String title, String description, public DatasetMetadataBean(String id, String title, String description,
Map<String, String> customFields, List<String> tags, Map<String, List<String>> customFields, List<String> tags,
String license, boolean visibility, String source, long version, String license, boolean visibility, String source, long version,
String authorName, String authorSurname, String authorEmail, String maintainer, String authorName, String authorSurname, String authorEmail, String maintainer,
String maintainerEmail, String ownerIdentifier, String maintainerEmail, String ownerIdentifier,
@ -146,11 +146,11 @@ public class DatasetMetadataBean implements Serializable {
this.description = description; this.description = description;
} }
public Map<String, String> getCustomFields() { public Map<String, List<String>> getCustomFields() {
return customFields; return customFields;
} }
public void setCustomFields(Map<String, String> customFields) { public void setCustomFields(Map<String, List<String>> customFields) {
this.customFields = customFields; this.customFields = customFields;
} }