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:
parent
c63dea6e00
commit
b5d377fdb6
|
@ -318,13 +318,13 @@ public class CreateDatasetForm extends Composite{
|
|||
authorEmailTextbox.setText(bean.getAuthorEmail());
|
||||
maintainerTextbox.setText(bean.getAuthorSurname() + " " + bean.getAuthorName());
|
||||
maintainerEmailTextbox.setText(bean.getMaintainerEmail());
|
||||
|
||||
|
||||
setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true);
|
||||
|
||||
// vocabulary list of tags has preemption
|
||||
List<String> vocabularyTags = bean.getTagsVocabulary();
|
||||
tagsPanel.setVocabulary(vocabularyTags);
|
||||
|
||||
|
||||
// retrieve custom fields
|
||||
Map<String, List<String>> customFieldsMap = bean.getCustomFields();
|
||||
|
||||
|
@ -403,7 +403,6 @@ public class CreateDatasetForm extends Composite{
|
|||
public void onFailure(Throwable arg0) {
|
||||
|
||||
setAlertBlock("Error while checking if a vocabulary of tags is defined in the selected organization.", AlertType.ERROR, true);
|
||||
tagsPanel.setVocabulary(null);
|
||||
tagsPanel.setVisible(true);
|
||||
|
||||
}
|
||||
|
@ -932,8 +931,8 @@ public class CreateDatasetForm extends Composite{
|
|||
|
||||
// prepare custom fields
|
||||
for (MetaDataFieldSkeleton field : listOfMetadataFields) {
|
||||
String value = field.getFieldCurrentValue();
|
||||
if(!value.isEmpty()){
|
||||
List<String> valuesForField = field.getFieldCurrentValue();
|
||||
if(!valuesForField.isEmpty()){
|
||||
String key = field.getFieldNameQualified();
|
||||
List<String> valuesForThisField = null;
|
||||
if(customFieldsMap.containsKey(key))
|
||||
|
@ -941,20 +940,22 @@ public class CreateDatasetForm extends Composite{
|
|||
else
|
||||
valuesForThisField = new ArrayList<String>();
|
||||
|
||||
valuesForThisField.add(value);
|
||||
valuesForThisField.addAll(valuesForField);
|
||||
customFieldsMap.put(key, valuesForThisField);
|
||||
|
||||
// get also tag/group if it is the case for this field
|
||||
String tag = field.getTagFromThisField();
|
||||
if(tag != null)
|
||||
tags.add(tag);
|
||||
List<String> tagsField = field.getTagFromThisField();
|
||||
if(tagsField != null)
|
||||
tags.addAll(tagsField);
|
||||
|
||||
String groupTitle = field.getGroupTitleFromThisGroup();
|
||||
if(groupTitle != null){
|
||||
if(field.isGroupToForce())
|
||||
groupsToForceCreation.add(new OrganizationBean(groupTitle, groupTitle, false));
|
||||
else
|
||||
groups.add(new OrganizationBean(groupTitle, groupTitle, false));
|
||||
List<String> groupsTitle = field.getGroupTitleFromThisGroup();
|
||||
if(groupsTitle != null){
|
||||
for (String groupTitle : groupsTitle) {
|
||||
if(field.isGroupToForce())
|
||||
groupsToForceCreation.add(new OrganizationBean(groupTitle, groupTitle, false));
|
||||
else
|
||||
groups.add(new OrganizationBean(groupTitle, groupTitle, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -358,7 +358,7 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
case Text:
|
||||
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()){
|
||||
|
||||
|
@ -379,7 +379,7 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
|
||||
case Time:
|
||||
|
||||
String dateValue = getFieldCurrentValue();
|
||||
String dateValue = getFieldCurrentValue().get(0);
|
||||
|
||||
if(field.getMandatory()){
|
||||
if(dateValue.isEmpty())
|
||||
|
@ -450,7 +450,7 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
// just handle the case of textbox
|
||||
if(holder.getClass().equals(TextBox.class)){
|
||||
|
||||
String textBoxValue = getFieldCurrentValue();
|
||||
String textBoxValue = getFieldCurrentValue().get(0);
|
||||
if(field.getMandatory()){
|
||||
if(!textBoxValue.trim().isEmpty())
|
||||
if(field.getValidator() == null || field.getValidator().isEmpty())
|
||||
|
@ -466,24 +466,31 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
}
|
||||
else{
|
||||
|
||||
String listBoxCurrentValue = getFieldCurrentValue();
|
||||
List<String> listboxValues = getFieldCurrentValue();
|
||||
|
||||
// listbox case
|
||||
if(!field.getMandatory()){
|
||||
for (String value : listboxValues) {
|
||||
if(!field.getMandatory()){
|
||||
|
||||
if(field.getValidator() == null || field.getValidator().isEmpty())
|
||||
return null;
|
||||
else
|
||||
return checkValidator(listBoxCurrentValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE;
|
||||
if(field.getValidator() == null || field.getValidator().isEmpty())
|
||||
continue;
|
||||
else
|
||||
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;
|
||||
|
||||
}
|
||||
|
@ -513,47 +520,49 @@ public class MetaDataFieldSkeleton extends Composite{
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the current value of the field (in case of multiselection Listbox returns
|
||||
* the values separated by column ','). In case of TimeInterval or TimeList see getTimeIntervalOrTimeListWithoutMissing()
|
||||
* Returns the current value of the field. In case of TimeInterval or TimeList see getTimeIntervalOrTimeListWithoutMissing()
|
||||
* @return
|
||||
*/
|
||||
public String getFieldCurrentValue(){
|
||||
public List<String> getFieldCurrentValue(){
|
||||
|
||||
String toReturn = "";
|
||||
List<String> toReturn = new ArrayList<String>();
|
||||
String manipulatedTemp = "";
|
||||
|
||||
switch(field.getType()){
|
||||
|
||||
case Boolean :
|
||||
|
||||
toReturn = ((CheckBox)holder).getValue().toString();
|
||||
toReturn.add(((CheckBox)holder).getValue().toString());
|
||||
break;
|
||||
|
||||
case Text:
|
||||
case GeoJSON:
|
||||
toReturn = ((TextArea)holder).getText();
|
||||
|
||||
toReturn.add(((TextArea)holder).getText());
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
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))
|
||||
toReturn = "";
|
||||
manipulatedTemp = "";
|
||||
|
||||
// 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]))
|
||||
toReturn = temp[0];
|
||||
manipulatedTemp = temp[0];
|
||||
|
||||
toReturn.add(manipulatedTemp);
|
||||
break;
|
||||
|
||||
case Times_ListOf:
|
||||
|
||||
toReturn = "";
|
||||
manipulatedTemp = "";
|
||||
for (DataTimeBox elem : rangesList) {
|
||||
|
||||
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);
|
||||
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
|
||||
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];
|
||||
|
||||
}
|
||||
|
||||
if(toReturn.endsWith(RANGE_SEPARATOR))
|
||||
toReturn = toReturn.substring(0, toReturn.length() - 1);
|
||||
if(manipulatedTemp.endsWith(RANGE_SEPARATOR))
|
||||
manipulatedTemp = manipulatedTemp.substring(0, manipulatedTemp.length() - 1);
|
||||
|
||||
toReturn.add(manipulatedTemp);
|
||||
break;
|
||||
|
||||
case Number:
|
||||
case String:
|
||||
|
||||
if(holder.getClass().equals(TextBox.class))
|
||||
toReturn = ((TextBox)holder).getText();
|
||||
else{// listbox case
|
||||
|
||||
boolean first = true;
|
||||
toReturn.add(((TextBox)holder).getText());
|
||||
else{
|
||||
|
||||
// handle multiselected case
|
||||
for(int i = 0; i < ((ListBox)holder).getItemCount(); i++){
|
||||
if(((ListBox)holder).isItemSelected(i)){
|
||||
toReturn += first ? ((ListBox)holder).getItemText(i) : ", " + ((ListBox)holder).getItemText(i);
|
||||
first = false;
|
||||
toReturn.add(((ListBox)holder).getItemText(i));
|
||||
}
|
||||
}
|
||||
|
||||
// if it was not mandatory but there was no choice, returning empty string
|
||||
if(!field.getMandatory())
|
||||
if(toReturn.equals("Select " + field.getFieldName()))
|
||||
toReturn = "";
|
||||
if(toReturn.equals("Select " + field.getFieldName())){
|
||||
toReturn.clear();
|
||||
toReturn.add("");
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
* @return a tag as string
|
||||
*/
|
||||
public String getTagFromThisField(){
|
||||
public List<String> getTagFromThisField(){
|
||||
|
||||
FieldAsTag asTag = field.getAsTag();
|
||||
List<String> generatedTags = new ArrayList<String>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
* @return a tag as string
|
||||
*/
|
||||
public String getGroupTitleFromThisGroup(){
|
||||
public List<String> getGroupTitleFromThisGroup(){
|
||||
FieldAsGroup asGroup = field.getAsGroup();
|
||||
List<String> generatedGroups = new ArrayList<String>();
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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.Widget;
|
||||
|
||||
/**
|
||||
* Widget for handling date-like fields.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class DataTimeBox extends Composite{
|
||||
|
||||
private static DataTimeBoxUiBinder uiBinder = GWT
|
||||
|
@ -55,12 +59,12 @@ public class DataTimeBox extends Composite{
|
|||
singleDataEnd.setVisible(true);
|
||||
singleDataEnd.setWidth("50%");
|
||||
singleDataStart.setWidth("50%");
|
||||
|
||||
|
||||
startRangeTime.setWidth("30%");
|
||||
endRangeTime.setWidth("30%");
|
||||
startRangeDate.setWidth("60%");
|
||||
endRangeDate.setWidth("60%");
|
||||
|
||||
|
||||
startRangeDate.setPlaceholder(INSERT_DATE_START_LABEL);
|
||||
endRangeDate.setPlaceholder(INSERT_DATE_END_LABEL);
|
||||
endRangeTime.setPlaceholder(INSERT_TIME_INSTANT_LABEL);
|
||||
|
|
|
@ -53,13 +53,14 @@ public class TagsPanel extends Composite{
|
|||
// tags list
|
||||
private List<String> tagsList = new ArrayList<String>();
|
||||
|
||||
// vocabulary
|
||||
private List<String> vocabulary;
|
||||
|
||||
public TagsPanel() {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
tagsEnterListBox.setVisible(false);
|
||||
tagsPanel.clear();
|
||||
tagsList.clear();
|
||||
tagsPanel.clear();
|
||||
}
|
||||
|
||||
|
||||
|
@ -69,22 +70,21 @@ public class TagsPanel extends Composite{
|
|||
*/
|
||||
public void setVocabulary(List<String> vocabularyTags) {
|
||||
|
||||
tagsEnterListBox.clear();
|
||||
tagsPanel.clear();
|
||||
tagsList.clear();
|
||||
|
||||
GWT.log("Vocabulary of tags is " + vocabularyTags);
|
||||
|
||||
|
||||
if(vocabularyTags == null || vocabularyTags.isEmpty()){
|
||||
vocabulary = null;
|
||||
tagsEnterListBox.setVisible(false);
|
||||
tagsPanel.setVisible(true);
|
||||
tagsEnterTextBox.setVisible(true);
|
||||
}else{
|
||||
|
||||
vocabulary = vocabularyTags;
|
||||
tagsEnterListBox.clear();
|
||||
tagsPanel.clear();
|
||||
tagsList.clear();
|
||||
for (String vocabularyTag : vocabularyTags) {
|
||||
tagsEnterListBox.addItem(vocabularyTag, vocabularyTag);
|
||||
}
|
||||
vocabulary = vocabularyTags;
|
||||
tagsPanel.setVisible(false);
|
||||
tagsEnterTextBox.setVisible(false);
|
||||
tagsEnterListBox.setVisible(true);
|
||||
|
@ -256,7 +256,6 @@ public class TagsPanel extends Composite{
|
|||
* Freeze tags
|
||||
*/
|
||||
public void freeze() {
|
||||
|
||||
tagsEnterTextBox.setEnabled(false);
|
||||
tagsEnterListBox.setEnabled(false);
|
||||
for(int i = 0; i < tagsList.size(); i++){
|
||||
|
@ -268,7 +267,6 @@ public class TagsPanel extends Composite{
|
|||
tagWidget.getWidget(1).removeFromParent();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -276,8 +274,6 @@ public class TagsPanel extends Composite{
|
|||
* @param none
|
||||
*/
|
||||
public void setGroupPanelType(ControlGroupType type) {
|
||||
|
||||
tagsInsertGroup.setType(type);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
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.
|
||||
|
@ -14,14 +17,14 @@ public enum TaggingGroupingValue {
|
|||
onValue_onFieldName;
|
||||
|
||||
/**
|
||||
* Returns the composed value
|
||||
* Returns the composed value in case of tag
|
||||
* @param name
|
||||
* @param value
|
||||
* @param separator
|
||||
* @param action
|
||||
* @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){
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue