improved MetadataFieldWrapper by adding current values (as list)

This commit is contained in:
Francesco Mangiacrapa 2023-04-21 15:24:08 +02:00
parent ca51fc0543
commit 669dbb34e8
5 changed files with 72 additions and 41 deletions

View File

@ -1,7 +1,6 @@
package org.gcube.portlets.widgets.mpformbuilder.client.form.generic;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

View File

@ -149,7 +149,7 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) {
try {
if (field.getCurrentValue() != null)
if (field.getCurrentSingleValue() != null)
((CheckBox) holder).setValue(Boolean.valueOf(field.getDefaultValue()));
} catch (Exception e) {
// TODO: handle exception
@ -171,8 +171,8 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) {
try {
if (field.getCurrentValue() != null)
textArea.setText((String) field.getCurrentValue());
if (field.getCurrentSingleValue() != null)
textArea.setText((String) field.getCurrentSingleValue());
} catch (Exception e) {
// TODO: handle exception
}
@ -243,8 +243,8 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) {
try {
if (field.getCurrentValue() != null)
((TextArea) holder).setText((String) field.getCurrentValue());
if (field.getCurrentSingleValue() != null)
((TextArea) holder).setText((String) field.getCurrentSingleValue());
} catch (Exception e) {
// TODO: handle exception
}
@ -268,8 +268,8 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) {
// set time, if present
try {
if (field.getCurrentValue() != null) {
String currentValue = (String) field.getCurrentValue();
if (field.getCurrentSingleValue() != null) {
String currentValue = (String) field.getCurrentSingleValue();
String[] dateAndTime = currentValue.split(" ");
if (dateAndTime.length > 0) {
ref.setStartDate(dateAndTime[0], dateAndTime.length > 1 ? dateAndTime[1] : null);
@ -290,7 +290,7 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) {
// set time, if present
try {
setRangeTimeInTimeBox((String) field.getCurrentValue(), rangeBox);
setRangeTimeInTimeBox((String) field.getCurrentSingleValue(), rangeBox);
} catch (Exception e) {
// TODO: handle exception
}
@ -313,7 +313,7 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) {
try {
setRangeTimeInTimeBox((String) field.getCurrentValue(), rangeBoxFirst);
setRangeTimeInTimeBox((String) field.getCurrentSingleValue(), rangeBoxFirst);
} catch (Exception e) {
// TODO: handle exception
}
@ -373,8 +373,8 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) {
try {
if (field.getCurrentValue() != null)
((TextBox) holder).setText((String) field.getCurrentValue());
if (field.getCurrentSingleValue() != null)
((TextBox) holder).setText((String) field.getCurrentSingleValue());
} catch (Exception e) {
// TODO: handle exception
}
@ -401,8 +401,8 @@ public class MetaDataFieldSkeleton extends Composite {
if (operation.equals(OPERATION.UPDATE)) {
try {
if (field.getCurrentValue() != null)
((TextBox) holder).setText((String) field.getCurrentValue());
if (field.getCurrentSingleValue() != null)
((TextBox) holder).setText((String) field.getCurrentSingleValue());
} catch (Exception e) {
// TODO: handle exception
}
@ -431,17 +431,31 @@ public class MetaDataFieldSkeleton extends Composite {
List<String> vocabulary = field.getVocabulary();
for (String term : vocabulary) {
tempListBox.addItem(term);
tempListBox.addItem(term, term);
}
// set default value
if (field.getDefaultValue() != null)
tempListBox.setSelectedValue(field.getDefaultValue());
//to be sure
tempListBox.setMultipleSelect(field.isMultiSelection());
if (operation.equals(OPERATION.UPDATE)) {
try {
if (field.getCurrentValue() != null)
tempListBox.setSelectedValue((String) field.getCurrentValue());
if (field.getCurrentValues() != null) {
if (field.isMultiSelection()) {
//Buggy in Bootstrap
for (String value : field.getCurrentValues()) {
GWT.log("Multiple Selecting: "+value);
tempListBox.setSelectedValue((String) value);
}
}else {
GWT.log("Selecting: "+field.getCurrentSingleValue());
tempListBox.setSelectedValue((String) field.getCurrentSingleValue());
}
}
} catch (Exception e) {
// TODO: handle exception
}

View File

@ -21,7 +21,6 @@ import org.gcube.common.metadataprofilediscovery.jaxb.MetadataValidator;
import org.gcube.common.metadataprofilediscovery.jaxb.MetadataVocabulary;
import org.gcube.common.metadataprofilediscovery.jaxb.NamespaceCategory;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.widgets.mpformbuilder.server.util.WsUtil;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.CategoryWrapper;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.DataTypeWrapper;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.FieldAsGroup;
@ -119,10 +118,10 @@ public class MetadataDiscovery {
MetaDataProfileBean bean = toMetaDataProfileBean(metadata, categories, profile.getName());
beans.add(bean);
if(!WsUtil.isWithinPortal()) {
LOG.info("DEV MODE ENABLED - Out of portal!");
randomizeCurrentValues(bean.getMetadataFields());
}
// if(!WsUtil.isWithinPortal()) {
// LOG.info("DEV MODE ENABLED - Out of portal!");
// randomizeCurrentValues(bean.getMetadataFields());
// }
}
prettyPrintList(beans);
@ -145,14 +144,14 @@ public class MetadataDiscovery {
switch (dtw) {
case Boolean:
metadataFieldWrapper.setCurrentValue(Boolean.FALSE.toString());
metadataFieldWrapper.setCurrentValues(Boolean.FALSE.toString());
break;
case Number:
metadataFieldWrapper.setCurrentValue(new Random().nextInt()+"");
metadataFieldWrapper.setCurrentValues(new Random().nextInt()+"");
break;
case String:
case Text:
metadataFieldWrapper.setCurrentValue("Text "+UUID.randomUUID());
metadataFieldWrapper.setCurrentValues("Text "+UUID.randomUUID());
break;
default:
break;

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.widgets.mpformbuilder.shared.metadata;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
/**
@ -29,7 +30,7 @@ public class MetadataFieldWrapper implements UpdatableField, Serializable {
private Integer maxOccurs = 1;
private String currentValue;
private String[] currentValues;
/**
* Instantiates a new metadata field.
@ -331,24 +332,42 @@ public class MetadataFieldWrapper implements UpdatableField, Serializable {
}
/**
* Sets the current value.
* Gets the current values.
*
* @param value the new current value
* @return the current values
*/
public void setCurrentValue(String value) {
this.currentValue = value;
public List<String> getCurrentValues() {
if (currentValues == null)
return null;
return Arrays.asList(currentValues);
}
/**
* Gets the current value.
* Sets the current values.
*
* @return the current value
* @param currentValues the new current values
*/
public String getCurrentValue() {
return currentValue;
public void setCurrentValues(String... currentValues) {
this.currentValues = currentValues;
}
/**
* Gets the current single value.
*
* @return the current single value
*/
public String getCurrentSingleValue() {
if (this.currentValues != null && this.currentValues.length > 0)
return this.currentValues[0];
return null;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
@ -380,12 +399,10 @@ public class MetadataFieldWrapper implements UpdatableField, Serializable {
builder.append(asTag);
builder.append(", maxOccurs=");
builder.append(maxOccurs);
builder.append(", currentValue=");
builder.append(currentValue);
builder.append(", currentValues=");
builder.append(currentValues);
builder.append("]");
return builder.toString();
}
}

View File

@ -1,8 +1,10 @@
package org.gcube.portlets.widgets.mpformbuilder.shared.metadata;
import java.util.List;
public interface UpdatableField {
void setCurrentValue(String value);
void setCurrentValues(String... values);
String getCurrentValue();
List<String> getCurrentValues();
}