fixed tags switch between vocabulary and free insertion. Fixed generations of groups on metadata field on both value/name

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@147256 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-04-28 15:31:42 +00:00
parent c63dea6e00
commit b5d377fdb6
5 changed files with 118 additions and 73 deletions

View File

@ -318,13 +318,13 @@ public class CreateDatasetForm extends Composite{
authorEmailTextbox.setText(bean.getAuthorEmail()); authorEmailTextbox.setText(bean.getAuthorEmail());
maintainerTextbox.setText(bean.getAuthorSurname() + " " + bean.getAuthorName()); maintainerTextbox.setText(bean.getAuthorSurname() + " " + bean.getAuthorName());
maintainerEmailTextbox.setText(bean.getMaintainerEmail()); maintainerEmailTextbox.setText(bean.getMaintainerEmail());
setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true); setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true);
// vocabulary list of tags has preemption // vocabulary list of tags has preemption
List<String> vocabularyTags = bean.getTagsVocabulary(); List<String> vocabularyTags = bean.getTagsVocabulary();
tagsPanel.setVocabulary(vocabularyTags); tagsPanel.setVocabulary(vocabularyTags);
// retrieve custom fields // retrieve custom fields
Map<String, List<String>> customFieldsMap = bean.getCustomFields(); Map<String, List<String>> customFieldsMap = bean.getCustomFields();
@ -403,7 +403,6 @@ public class CreateDatasetForm extends Composite{
public void onFailure(Throwable arg0) { public void onFailure(Throwable arg0) {
setAlertBlock("Error while checking if a vocabulary of tags is defined in the selected organization.", AlertType.ERROR, true); setAlertBlock("Error while checking if a vocabulary of tags is defined in the selected organization.", AlertType.ERROR, true);
tagsPanel.setVocabulary(null);
tagsPanel.setVisible(true); tagsPanel.setVisible(true);
} }
@ -932,8 +931,8 @@ public class CreateDatasetForm extends Composite{
// prepare custom fields // prepare custom fields
for (MetaDataFieldSkeleton field : listOfMetadataFields) { for (MetaDataFieldSkeleton field : listOfMetadataFields) {
String value = field.getFieldCurrentValue(); List<String> valuesForField = field.getFieldCurrentValue();
if(!value.isEmpty()){ if(!valuesForField.isEmpty()){
String key = field.getFieldNameQualified(); String key = field.getFieldNameQualified();
List<String> valuesForThisField = null; List<String> valuesForThisField = null;
if(customFieldsMap.containsKey(key)) if(customFieldsMap.containsKey(key))
@ -941,20 +940,22 @@ public class CreateDatasetForm extends Composite{
else else
valuesForThisField = new ArrayList<String>(); valuesForThisField = new ArrayList<String>();
valuesForThisField.add(value); valuesForThisField.addAll(valuesForField);
customFieldsMap.put(key, valuesForThisField); customFieldsMap.put(key, valuesForThisField);
// get also tag/group if it is the case for this field // get also tag/group if it is the case for this field
String tag = field.getTagFromThisField(); List<String> tagsField = field.getTagFromThisField();
if(tag != null) if(tagsField != null)
tags.add(tag); tags.addAll(tagsField);
String groupTitle = field.getGroupTitleFromThisGroup(); List<String> groupsTitle = field.getGroupTitleFromThisGroup();
if(groupTitle != null){ if(groupsTitle != null){
if(field.isGroupToForce()) for (String groupTitle : groupsTitle) {
groupsToForceCreation.add(new OrganizationBean(groupTitle, groupTitle, false)); if(field.isGroupToForce())
else groupsToForceCreation.add(new OrganizationBean(groupTitle, groupTitle, false));
groups.add(new OrganizationBean(groupTitle, groupTitle, false)); else
groups.add(new OrganizationBean(groupTitle, groupTitle, false));
}
} }
} }
} }

View File

@ -358,7 +358,7 @@ public class MetaDataFieldSkeleton extends Composite{
case Text: case Text:
case GeoJSON: // validation for geojson will be performed at server side as well TODO case GeoJSON: // validation for geojson will be performed at server side as well TODO
String textAreaValue = getFieldCurrentValue(); String textAreaValue = getFieldCurrentValue().get(0);
if(field.getMandatory()){ if(field.getMandatory()){
@ -379,7 +379,7 @@ public class MetaDataFieldSkeleton extends Composite{
case Time: case Time:
String dateValue = getFieldCurrentValue(); String dateValue = getFieldCurrentValue().get(0);
if(field.getMandatory()){ if(field.getMandatory()){
if(dateValue.isEmpty()) if(dateValue.isEmpty())
@ -450,7 +450,7 @@ public class MetaDataFieldSkeleton extends Composite{
// just handle the case of textbox // just handle the case of textbox
if(holder.getClass().equals(TextBox.class)){ if(holder.getClass().equals(TextBox.class)){
String textBoxValue = getFieldCurrentValue(); String textBoxValue = getFieldCurrentValue().get(0);
if(field.getMandatory()){ if(field.getMandatory()){
if(!textBoxValue.trim().isEmpty()) if(!textBoxValue.trim().isEmpty())
if(field.getValidator() == null || field.getValidator().isEmpty()) if(field.getValidator() == null || field.getValidator().isEmpty())
@ -466,24 +466,31 @@ public class MetaDataFieldSkeleton extends Composite{
} }
else{ else{
String listBoxCurrentValue = getFieldCurrentValue(); List<String> listboxValues = getFieldCurrentValue();
// listbox case for (String value : listboxValues) {
if(!field.getMandatory()){ if(!field.getMandatory()){
if(field.getValidator() == null || field.getValidator().isEmpty()) if(field.getValidator() == null || field.getValidator().isEmpty())
return null; continue;
else else
return checkValidator(listBoxCurrentValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE; if(checkValidator(value, field.getValidator()))
continue;
else return MALFORMED_ATTRIBUTE;
}else{ }else{
return listBoxCurrentValue == null || listBoxCurrentValue.isEmpty() ? MANDATORY_ATTRIBUTE_MISSING : null; if(value == null || value.isEmpty())
return MANDATORY_ATTRIBUTE_MISSING;
else
continue;
}
} }
} }
return null;
default: return null; default: return null;
} }
@ -513,47 +520,49 @@ public class MetaDataFieldSkeleton extends Composite{
} }
/** /**
* Returns the current value of the field (in case of multiselection Listbox returns * Returns the current value of the field. In case of TimeInterval or TimeList see getTimeIntervalOrTimeListWithoutMissing()
* the values separated by column ','). In case of TimeInterval or TimeList see getTimeIntervalOrTimeListWithoutMissing()
* @return * @return
*/ */
public String getFieldCurrentValue(){ public List<String> getFieldCurrentValue(){
String toReturn = ""; List<String> toReturn = new ArrayList<String>();
String manipulatedTemp = "";
switch(field.getType()){ switch(field.getType()){
case Boolean : case Boolean :
toReturn = ((CheckBox)holder).getValue().toString(); toReturn.add(((CheckBox)holder).getValue().toString());
break; break;
case Text: case Text:
case GeoJSON: case GeoJSON:
toReturn = ((TextArea)holder).getText();
toReturn.add(((TextArea)holder).getText());
break; break;
case Time: case Time:
toReturn = ((DataTimeBox)holder).getCurrentValue().replaceAll(DataTimeBox.MISSING_RANGE_VALUE_START, ""); // it was a noRange metadata toReturn.add(((DataTimeBox)holder).getCurrentValue().replaceAll(DataTimeBox.MISSING_RANGE_VALUE_START, "")); // it was a noRange metadata
break; break;
case Time_Interval: case Time_Interval:
toReturn = rangesList.get(0).getCurrentValue().replaceAll(DataTimeBox.MISSING_RANGE_VALUE_START, "").replaceAll(DataTimeBox.MISSING_RANGE_VALUE_END, UPPER_RANGE_NOT_SPECIFIED); manipulatedTemp = rangesList.get(0).getCurrentValue().replaceAll(DataTimeBox.MISSING_RANGE_VALUE_START, "").replaceAll(DataTimeBox.MISSING_RANGE_VALUE_END, UPPER_RANGE_NOT_SPECIFIED);
if(toReturn.equals(DataTimeBox.RANGE_SEPARATOR_START_END + UPPER_RANGE_NOT_SPECIFIED)) if(toReturn.equals(DataTimeBox.RANGE_SEPARATOR_START_END + UPPER_RANGE_NOT_SPECIFIED))
toReturn = ""; manipulatedTemp = "";
// split to check if the extreme are equals // split to check if the extreme are equals
String[] temp = toReturn.split(DataTimeBox.RANGE_SEPARATOR_START_END); String[] temp = manipulatedTemp.split(DataTimeBox.RANGE_SEPARATOR_START_END);
if(temp[0].equals(temp[1])) if(temp[0].equals(temp[1]))
toReturn = temp[0]; manipulatedTemp = temp[0];
toReturn.add(manipulatedTemp);
break; break;
case Times_ListOf: case Times_ListOf:
toReturn = ""; manipulatedTemp = "";
for (DataTimeBox elem : rangesList) { for (DataTimeBox elem : rangesList) {
String currentRange = elem.getCurrentValue().replaceAll(DataTimeBox.MISSING_RANGE_VALUE_START, "").replaceAll(DataTimeBox.MISSING_RANGE_VALUE_END, UPPER_RANGE_NOT_SPECIFIED); String currentRange = elem.getCurrentValue().replaceAll(DataTimeBox.MISSING_RANGE_VALUE_START, "").replaceAll(DataTimeBox.MISSING_RANGE_VALUE_END, UPPER_RANGE_NOT_SPECIFIED);
@ -562,39 +571,39 @@ public class MetaDataFieldSkeleton extends Composite{
String[] splitted = currentRange.split(DataTimeBox.RANGE_SEPARATOR_START_END); String[] splitted = currentRange.split(DataTimeBox.RANGE_SEPARATOR_START_END);
if(splitted[0].equals(splitted[1])) if(splitted[0].equals(splitted[1]))
toReturn += (toReturn.isEmpty()) ? splitted[0] : RANGE_SEPARATOR + splitted[0]; manipulatedTemp += (manipulatedTemp.isEmpty()) ? splitted[0] : RANGE_SEPARATOR + splitted[0];
else else
toReturn += (toReturn.isEmpty()) ? splitted[0] + DataTimeBox.RANGE_SEPARATOR_START_END + splitted[1] : manipulatedTemp += (manipulatedTemp.isEmpty()) ? splitted[0] + DataTimeBox.RANGE_SEPARATOR_START_END + splitted[1] :
RANGE_SEPARATOR + splitted[0] + DataTimeBox.RANGE_SEPARATOR_START_END + splitted[1]; RANGE_SEPARATOR + splitted[0] + DataTimeBox.RANGE_SEPARATOR_START_END + splitted[1];
} }
if(toReturn.endsWith(RANGE_SEPARATOR)) if(manipulatedTemp.endsWith(RANGE_SEPARATOR))
toReturn = toReturn.substring(0, toReturn.length() - 1); manipulatedTemp = manipulatedTemp.substring(0, manipulatedTemp.length() - 1);
toReturn.add(manipulatedTemp);
break; break;
case Number: case Number:
case String: case String:
if(holder.getClass().equals(TextBox.class)) if(holder.getClass().equals(TextBox.class))
toReturn = ((TextBox)holder).getText(); toReturn.add(((TextBox)holder).getText());
else{// listbox case else{
boolean first = true;
// handle multiselected case // handle multiselected case
for(int i = 0; i < ((ListBox)holder).getItemCount(); i++){ for(int i = 0; i < ((ListBox)holder).getItemCount(); i++){
if(((ListBox)holder).isItemSelected(i)){ if(((ListBox)holder).isItemSelected(i)){
toReturn += first ? ((ListBox)holder).getItemText(i) : ", " + ((ListBox)holder).getItemText(i); toReturn.add(((ListBox)holder).getItemText(i));
first = false;
} }
} }
// if it was not mandatory but there was no choice, returning empty string // if it was not mandatory but there was no choice, returning empty string
if(!field.getMandatory()) if(!field.getMandatory())
if(toReturn.equals("Select " + field.getFieldName())) if(toReturn.equals("Select " + field.getFieldName())){
toReturn = ""; toReturn.clear();
toReturn.add("");
}
} }
break; break;
@ -728,13 +737,17 @@ public class MetaDataFieldSkeleton extends Composite{
* Given the name and the value of this field, return a tag if it is the case. * Given the name and the value of this field, return a tag if it is the case.
* @return a tag as string * @return a tag as string
*/ */
public String getTagFromThisField(){ public List<String> getTagFromThisField(){
FieldAsTag asTag = field.getAsTag(); FieldAsTag asTag = field.getAsTag();
List<String> generatedTags = new ArrayList<String>();
if(asTag != null){ if(asTag != null){
return TaggingGroupingValue.getComposedValue(field.getFieldName(), getFieldCurrentValue(), asTag.getSeparator(), asTag.getTaggingValue()); List<String> values = getFieldCurrentValue();
for (String value : values) {
generatedTags.add(TaggingGroupingValue.getComposedValueTag(field.getFieldName(), value, asTag.getSeparator(), asTag.getTaggingValue()));
}
return generatedTags;
} }
return null; return null;
} }
@ -742,10 +755,15 @@ public class MetaDataFieldSkeleton extends Composite{
* Given the name and the value of this field, return a group title if it is the case. * Given the name and the value of this field, return a group title if it is the case.
* @return a tag as string * @return a tag as string
*/ */
public String getGroupTitleFromThisGroup(){ public List<String> getGroupTitleFromThisGroup(){
FieldAsGroup asGroup = field.getAsGroup(); FieldAsGroup asGroup = field.getAsGroup();
List<String> generatedGroups = new ArrayList<String>();
if(asGroup != null){ if(asGroup != null){
return TaggingGroupingValue.getComposedValue(field.getFieldName(), getFieldCurrentValue(), " ", asGroup.getGroupingValue()); List<String> values = getFieldCurrentValue();
for (String value : values) {
generatedGroups.addAll(TaggingGroupingValue.getComposedValueGroup(field.getFieldName(), value, asGroup.getGroupingValue()));
}
return generatedGroups;
} }
return null; return null;
} }

View File

@ -12,6 +12,10 @@ import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
/**
* Widget for handling date-like fields.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class DataTimeBox extends Composite{ public class DataTimeBox extends Composite{
private static DataTimeBoxUiBinder uiBinder = GWT private static DataTimeBoxUiBinder uiBinder = GWT
@ -55,12 +59,12 @@ public class DataTimeBox extends Composite{
singleDataEnd.setVisible(true); singleDataEnd.setVisible(true);
singleDataEnd.setWidth("50%"); singleDataEnd.setWidth("50%");
singleDataStart.setWidth("50%"); singleDataStart.setWidth("50%");
startRangeTime.setWidth("30%"); startRangeTime.setWidth("30%");
endRangeTime.setWidth("30%"); endRangeTime.setWidth("30%");
startRangeDate.setWidth("60%"); startRangeDate.setWidth("60%");
endRangeDate.setWidth("60%"); endRangeDate.setWidth("60%");
startRangeDate.setPlaceholder(INSERT_DATE_START_LABEL); startRangeDate.setPlaceholder(INSERT_DATE_START_LABEL);
endRangeDate.setPlaceholder(INSERT_DATE_END_LABEL); endRangeDate.setPlaceholder(INSERT_DATE_END_LABEL);
endRangeTime.setPlaceholder(INSERT_TIME_INSTANT_LABEL); endRangeTime.setPlaceholder(INSERT_TIME_INSTANT_LABEL);

View File

@ -53,13 +53,14 @@ public class TagsPanel extends Composite{
// tags list // tags list
private List<String> tagsList = new ArrayList<String>(); private List<String> tagsList = new ArrayList<String>();
// vocabulary
private List<String> vocabulary; private List<String> vocabulary;
public TagsPanel() { public TagsPanel() {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
tagsEnterListBox.setVisible(false); tagsEnterListBox.setVisible(false);
tagsPanel.clear();
tagsList.clear(); tagsList.clear();
tagsPanel.clear();
} }
@ -69,22 +70,21 @@ public class TagsPanel extends Composite{
*/ */
public void setVocabulary(List<String> vocabularyTags) { public void setVocabulary(List<String> vocabularyTags) {
tagsEnterListBox.clear();
tagsPanel.clear();
tagsList.clear();
GWT.log("Vocabulary of tags is " + vocabularyTags); GWT.log("Vocabulary of tags is " + vocabularyTags);
if(vocabularyTags == null || vocabularyTags.isEmpty()){ if(vocabularyTags == null || vocabularyTags.isEmpty()){
vocabulary = null;
tagsEnterListBox.setVisible(false); tagsEnterListBox.setVisible(false);
tagsPanel.setVisible(true); tagsPanel.setVisible(true);
tagsEnterTextBox.setVisible(true); tagsEnterTextBox.setVisible(true);
}else{ }else{
vocabulary = vocabularyTags;
tagsEnterListBox.clear();
tagsPanel.clear();
tagsList.clear();
for (String vocabularyTag : vocabularyTags) { for (String vocabularyTag : vocabularyTags) {
tagsEnterListBox.addItem(vocabularyTag, vocabularyTag); tagsEnterListBox.addItem(vocabularyTag, vocabularyTag);
} }
vocabulary = vocabularyTags;
tagsPanel.setVisible(false); tagsPanel.setVisible(false);
tagsEnterTextBox.setVisible(false); tagsEnterTextBox.setVisible(false);
tagsEnterListBox.setVisible(true); tagsEnterListBox.setVisible(true);
@ -256,7 +256,6 @@ public class TagsPanel extends Composite{
* Freeze tags * Freeze tags
*/ */
public void freeze() { public void freeze() {
tagsEnterTextBox.setEnabled(false); tagsEnterTextBox.setEnabled(false);
tagsEnterListBox.setEnabled(false); tagsEnterListBox.setEnabled(false);
for(int i = 0; i < tagsList.size(); i++){ for(int i = 0; i < tagsList.size(); i++){
@ -268,7 +267,6 @@ public class TagsPanel extends Composite{
tagWidget.getWidget(1).removeFromParent(); tagWidget.getWidget(1).removeFromParent();
} }
} }
/** /**
@ -276,8 +274,6 @@ public class TagsPanel extends Composite{
* @param none * @param none
*/ */
public void setGroupPanelType(ControlGroupType type) { public void setGroupPanelType(ControlGroupType type) {
tagsInsertGroup.setType(type); tagsInsertGroup.setType(type);
} }
} }

View File

@ -1,5 +1,8 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata; package org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata;
import java.util.Arrays;
import java.util.List;
/** /**
* Specifies the action to take when a tag or a group must be created from a field. * Specifies the action to take when a tag or a group must be created from a field.
@ -14,14 +17,14 @@ public enum TaggingGroupingValue {
onValue_onFieldName; onValue_onFieldName;
/** /**
* Returns the composed value * Returns the composed value in case of tag
* @param name * @param name
* @param value * @param value
* @param separator * @param separator
* @param action * @param action
* @return * @return
*/ */
public static String getComposedValue(String name, String value, String separator, TaggingGroupingValue action){ public static String getComposedValueTag(String name, String value, String separator, TaggingGroupingValue action){
switch(action){ switch(action){
case onFieldName: case onFieldName:
@ -36,5 +39,28 @@ public enum TaggingGroupingValue {
} }
} }
/**
* Returns the composed value in case of group
* @param name
* @param value
* @param separator
* @param action
* @return a list of group names
*/
public static List<String> getComposedValueGroup(String name, String value, TaggingGroupingValue action){
switch(action){
case onFieldName:
return Arrays.asList(name);
case onValue:
return Arrays.asList(value);
case onFieldName_onValue:
case onValue_onFieldName:
return Arrays.asList(value, name);
default: return null;
}
}
} }