From f83312dbf336cd478cd68e294b4feb296b24cb7a Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 3 Mar 2022 18:42:59 +0100 Subject: [PATCH] in progress on update --- ....eclipse.wst.common.project.facet.core.xml | 1 + CHANGELOG.md | 5 +- pom.xml | 2 +- .../client/form/MetaDataField.java | 10 +- .../form/generic/CreateMetadataForm.java | 18 +- .../ui/metadata/MetaDataFieldSkeleton.java | 158 ++++++++++++++---- .../server/MetadataDiscovery.java | 30 ++++ .../shared/metadata/MetaDataProfileBean.java | 65 ++++++- .../shared/metadata/MetadataFieldWrapper.java | 84 ++++++---- .../shared/metadata/UpdatableField.java | 8 + 10 files changed, 299 insertions(+), 82 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/metadata/UpdatableField.java diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index 2ad8c36..5f50479 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -5,4 +5,5 @@ + diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ba2ea3..d020b74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [v1.1.0-SNAPSHOT] - 2022-03-01 +## [v2.0.0-SNAPSHOT] - 2022-03-01 #### Enhancement -- [#22890] Overloaded the method getProfilesInTheScope +- [#22890] Overloaded the method getProfilesInTheScope(forName) +- [#22890] Including the set/get currentValue for Update facility ## [v1.0.1-SNAPSHOT] - 2020-10-08 diff --git a/pom.xml b/pom.xml index 0c01f11..74b1066 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.gcube.portlets.widgets metadata-profile-form-builder-widget jar - 1.1.0-SNAPSHOT + 2.0.0-SNAPSHOT Metadata Profile Form Builder The Metadata Profile Form Builder is a widget able to build dynamically a web form by reading "gCube Metadata Profile/s" diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/MetaDataField.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/MetaDataField.java index 5076a76..1d0b7f5 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/MetaDataField.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/MetaDataField.java @@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.mpformbuilder.client.form; import java.util.ArrayList; import java.util.List; +import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm.OPERATION; import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.MetaDataFieldSkeleton; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper; @@ -34,8 +35,6 @@ public class MetaDataField extends Composite { @UiField VerticalPanel panelMetaDataFieldsSkeleton; @UiField Label repeatabilityLabel; - - //@UiField ControlGroup cgMetaDataFieldSkeletonFields; @UiField Button addFieldButton; @@ -47,6 +46,8 @@ public class MetaDataField extends Composite { private HandlerManager eventBus; + private OPERATION operation; + /** * The Interface MetaDataFieldUiBinder. * @@ -65,10 +66,11 @@ public class MetaDataField extends Composite { * @param eventBus the event bus * @throws Exception the exception */ - public MetaDataField(final MetadataFieldWrapper field, HandlerManager eventBus) throws Exception { + public MetaDataField(final MetadataFieldWrapper field, HandlerManager eventBus, OPERATION operation) throws Exception { initWidget(uiBinder.createAndBindUi(this)); this.fieldWrapper = field; this.eventBus = eventBus; + this.operation = operation; addNewOccurrenceOfField(); checkAllowedAddField(); checkAllowedRemoveField(); @@ -143,7 +145,7 @@ public class MetaDataField extends Composite { */ private void addNewOccurrenceOfField() { try { - MetaDataFieldSkeleton fieldWidget = new MetaDataFieldSkeleton(fieldWrapper, eventBus); + MetaDataFieldSkeleton fieldWidget = new MetaDataFieldSkeleton(fieldWrapper, eventBus, operation); listOfMetadataFields.add(fieldWidget); panelMetaDataFieldsSkeleton.add(fieldWidget); } catch (Exception e) { diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/generic/CreateMetadataForm.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/generic/CreateMetadataForm.java index bd2c262..c628922 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/generic/CreateMetadataForm.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/form/generic/CreateMetadataForm.java @@ -61,7 +61,7 @@ import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; -// TODO: Auto-generated Javadoc + /** * Create metadata form for ckan product. * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) @@ -238,6 +238,10 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe /** The form data bean. */ private GenericDatasetBean formDataBean; + private OPERATION operationPerfom; + + public enum OPERATION {NEW, UPDATE} + /** * Invoked in the most general case. * @@ -271,8 +275,9 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe * * @param profiles the profiles */ - public CreateMetadataForm(List profiles, HandlerManager eventBus) { + public CreateMetadataForm(List profiles, HandlerManager eventBus, OPERATION operation) { this(eventBus); + this.operationPerfom = operation; showLoadingProfiles(true); createDatasetFormBody(profiles); showLoadingProfiles(false); @@ -302,7 +307,8 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe showChooseProfileForm(false); showCustomFieldsEntries(false); } - + + /** * Show loading profiles. * @@ -464,7 +470,7 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe MetaDataField fieldWidget; try { - fieldWidget = new MetaDataField(field, uiBus); + fieldWidget = new MetaDataField(field, uiBus, operationPerfom); metadataFieldsPanel.add(fieldWidget); listOfMetadataFields.add(fieldWidget); } catch (Exception e) { @@ -493,7 +499,7 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe MetaDataField fieldWidget; try { - fieldWidget = new MetaDataField(metadataFieldWrapper, uiBus); + fieldWidget = new MetaDataField(metadataFieldWrapper, uiBus,operationPerfom); cp.addField(fieldWidget); listOfMetadataFields.add(fieldWidget); } catch (Exception e) { @@ -519,7 +525,7 @@ public class CreateMetadataForm extends Composite implements HasGenericFormListe MetaDataField fieldWidget; try { - fieldWidget = new MetaDataField(field, uiBus); + fieldWidget = new MetaDataField(field, uiBus, operationPerfom); extrasCategory.addField(fieldWidget); listOfMetadataFields.add(fieldWidget); } catch (Exception e) { diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/metadata/MetaDataFieldSkeleton.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/metadata/MetaDataFieldSkeleton.java index 8bd7a59..4a512df 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/metadata/MetaDataFieldSkeleton.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/ui/metadata/MetaDataFieldSkeleton.java @@ -5,6 +5,7 @@ import java.util.List; import org.gcube.portlets.widgets.mpformbuilder.client.events.CloseCreationFormEvent; import org.gcube.portlets.widgets.mpformbuilder.client.events.CloseCreationFormEventHandler; +import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm.OPERATION; import org.gcube.portlets.widgets.mpformbuilder.client.openlayerwidget.GeoJsonAreaSelectionDialog; import org.gcube.portlets.widgets.mpformbuilder.client.ui.timeandranges.DataTimeBox; import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.DialogUpload; @@ -118,10 +119,11 @@ public class MetaDataFieldSkeleton extends Composite { // time range separator public static final String RANGE_SEPARATOR = ","; private static final String TOOLTIP_MULTISELECTION = "Hold down the Control (CTRL) or Command (CMD) button to select multiple options"; - + private static final String UPLOAD_MISSING_FILE = "You must upload a file"; - public MetaDataFieldSkeleton(final MetadataFieldWrapper field, HandlerManager eventBus) throws Exception { + public MetaDataFieldSkeleton(final MetadataFieldWrapper field, HandlerManager eventBus, OPERATION operation) + throws Exception { initWidget(uiBinder.createAndBindUi(this)); // prepare information @@ -133,6 +135,9 @@ public class MetaDataFieldSkeleton extends Composite { // bind bind(); + if (operation == null) + operation = OPERATION.NEW; + switch (field.getType()) { case Boolean: @@ -141,6 +146,16 @@ public class MetaDataFieldSkeleton extends Composite { holder = new CheckBox(); if (field.getDefaultValue() != null) ((CheckBox) holder).setValue(Boolean.valueOf(field.getDefaultValue())); + + if (operation.equals(OPERATION.UPDATE)) { + try { + if (field.getCurrentValue() != null) + ((CheckBox) holder).setValue(Boolean.valueOf(field.getDefaultValue())); + } catch (Exception e) { + // TODO: handle exception + } + } + break; case GeoJSON: @@ -154,6 +169,15 @@ public class MetaDataFieldSkeleton extends Composite { if (field.getDefaultValue() != null) textArea.setText(field.getDefaultValue()); + if (operation.equals(OPERATION.UPDATE)) { + try { + if (field.getCurrentValue() != null) + textArea.setText((String) field.getCurrentValue()); + } catch (Exception e) { + // TODO: handle exception + } + } + containerGeoJSON.add(textArea); HorizontalPanel hp = new HorizontalPanel(); @@ -216,6 +240,16 @@ public class MetaDataFieldSkeleton extends Composite { if (field.getDefaultValue() != null) ((TextArea) holder).setText(field.getDefaultValue()); + + if (operation.equals(OPERATION.UPDATE)) { + try { + if (field.getCurrentValue() != null) + ((TextArea) holder).setText((String) field.getCurrentValue()); + } catch (Exception e) { + // TODO: handle exception + } + } + break; case Time: @@ -230,6 +264,22 @@ public class MetaDataFieldSkeleton extends Composite { ref.setStartDate(dateAndTime[0], dateAndTime.length > 1 ? dateAndTime[1] : null); } } + + if (operation.equals(OPERATION.UPDATE)) { + // set time, if present + try { + if (field.getCurrentValue() != null) { + String currentValue = (String) field.getCurrentValue(); + String[] dateAndTime = currentValue.split(" "); + if (dateAndTime.length > 0) { + ref.setStartDate(dateAndTime[0], dateAndTime.length > 1 ? dateAndTime[1] : null); + } + } + } catch (Exception e) { + // TODO: handle exception + } + } + break; case Time_Interval: @@ -237,6 +287,15 @@ public class MetaDataFieldSkeleton extends Composite { DataTimeBox rangeBox; holder = rangeBox = new DataTimeBox(true); setRangeTimeInTimeBox(field.getDefaultValue(), rangeBox); + if (operation.equals(OPERATION.UPDATE)) { + // set time, if present + try { + setRangeTimeInTimeBox((String) field.getCurrentValue(), rangeBox); + } catch (Exception e) { + // TODO: handle exception + } + } + rangesList.add(rangeBox); break; @@ -251,6 +310,15 @@ public class MetaDataFieldSkeleton extends Composite { SimplePanel panelFirstRange = new SimplePanel(); DataTimeBox rangeBoxFirst = new DataTimeBox(true); setRangeTimeInTimeBox(field.getDefaultValue(), rangeBoxFirst); + + if (operation.equals(OPERATION.UPDATE)) { + try { + setRangeTimeInTimeBox((String) field.getCurrentValue(), rangeBoxFirst); + } catch (Exception e) { + // TODO: handle exception + } + } + panelFirstRange.add(rangeBoxFirst); rangesList.add(rangeBoxFirst); @@ -303,8 +371,17 @@ public class MetaDataFieldSkeleton extends Composite { if (field.getDefaultValue() != null) ((TextBox) holder).setText(field.getDefaultValue()); + if (operation.equals(OPERATION.UPDATE)) { + try { + if (field.getCurrentValue() != null) + ((TextBox) holder).setText((String) field.getCurrentValue()); + } catch (Exception e) { + // TODO: handle exception + } + } + break; - + case File: holder = new MultipleDilaogUpload(); @@ -322,6 +399,15 @@ public class MetaDataFieldSkeleton extends Composite { if (field.getDefaultValue() != null) ((TextBox) holder).setText(field.getDefaultValue()); + if (operation.equals(OPERATION.UPDATE)) { + try { + if (field.getCurrentValue() != null) + ((TextBox) holder).setText((String) field.getCurrentValue()); + } catch (Exception e) { + // TODO: handle exception + } + } + } else { // listbox @@ -331,11 +417,13 @@ public class MetaDataFieldSkeleton extends Composite { if (field.isMultiSelection()) tempListBox.setTitle(TOOLTIP_MULTISELECTION); - // if it is not mandatory and not multi-selection, add a disabled option (placeholder) - if(!field.getMandatory() && !field.isMultiSelection()){ + // if it is not mandatory and not multi-selection, add a disabled option + // (placeholder) + if (!field.getMandatory() && !field.isMultiSelection()) { tempListBox.addItem("Select " + field.getFieldName()); tempListBox.setValue(0, ""); - tempListBox.getElement().getElementsByTagName("option").getItem(0).setAttribute("disabled", "disabled"); + tempListBox.getElement().getElementsByTagName("option").getItem(0).setAttribute("disabled", + "disabled"); tempListBox.setSelectedValue("Select " + field.getFieldName()); } @@ -350,6 +438,15 @@ public class MetaDataFieldSkeleton extends Composite { if (field.getDefaultValue() != null) tempListBox.setSelectedValue(field.getDefaultValue()); + if (operation.equals(OPERATION.UPDATE)) { + try { + if (field.getCurrentValue() != null) + tempListBox.setSelectedValue((String) field.getCurrentValue()); + } catch (Exception e) { + // TODO: handle exception + } + } + } break; @@ -358,24 +455,22 @@ public class MetaDataFieldSkeleton extends Composite { return; } - + try { ChangeHandler handler = new ChangeHandler() { - + @Override public void onChange(ChangeEvent event) { GWT.log("Fired is field value"); removeError(); isFieldValueValid(); - + } }; holder.addDomHandler(handler, ChangeEvent.getType()); - }catch (Exception e) { + } catch (Exception e) { // TODO: handle exception } - - // add custom css properties controls.addStyleName("form-controls-custom"); @@ -421,8 +516,7 @@ public class MetaDataFieldSkeleton extends Composite { }); } - - + /** * Gets the holder. * @@ -631,22 +725,24 @@ public class MetaDataFieldSkeleton extends Composite { } return null; - + case File: - + GWT.log("Checking is valid File"); if (field.getMandatory()) { - if (holder.getClass().equals(DialogUpload.class) || holder.getClass().equals(MultipleDilaogUpload.class)) { + if (holder.getClass().equals(DialogUpload.class) + || holder.getClass().equals(MultipleDilaogUpload.class)) { DialogUpload dUpload = (DialogUpload) holder; - if(dUpload.getFileUploadingState()!=null && dUpload.getFileUploadingState().getFile()!=null) { - return dUpload.getFileUploadingState().getFile().getTempSystemPath()!=null?null:UPLOAD_MISSING_FILE; + if (dUpload.getFileUploadingState() != null && dUpload.getFileUploadingState().getFile() != null) { + return dUpload.getFileUploadingState().getFile().getTempSystemPath() != null ? null + : UPLOAD_MISSING_FILE; } } return UPLOAD_MISSING_FILE; - + } return null; - + default: return null; @@ -772,14 +868,14 @@ public class MetaDataFieldSkeleton extends Composite { } // if it was not mandatory but there was no choice, returning empty string - if(!field.getMandatory()) { - //Task #20446 - bug fix. Ignoring the placeholder - if(toReturn.size()==1) { + if (!field.getMandatory()) { + // Task #20446 - bug fix. Ignoring the placeholder + if (toReturn.size() == 1) { String placeholder = "Select " + field.getFieldName(); - if(toReturn.get(0).equals(placeholder)){ - GWT.log("Skipping placeholder: "+placeholder); + if (toReturn.get(0).equals(placeholder)) { + GWT.log("Skipping placeholder: " + placeholder); toReturn.clear(); - //toReturn.add(""); + // toReturn.add(""); } } } @@ -787,16 +883,16 @@ public class MetaDataFieldSkeleton extends Composite { break; case File: - + if (holder.getClass().equals(MultipleDilaogUpload.class) || holder.getClass().equals(DialogUpload.class)) { DialogUpload dUpload = (DialogUpload) holder; - if(dUpload.getFileUploadingState()!=null) { + if (dUpload.getFileUploadingState() != null) { String filePath = dUpload.getFileUploadingState().getFile().getTempSystemPath(); toReturn.add(filePath); - }else + } else toReturn.add(null); } - + break; default: diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataDiscovery.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataDiscovery.java index c12b761..47484a7 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataDiscovery.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataDiscovery.java @@ -6,6 +6,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Random; +import java.util.UUID; import javax.xml.bind.JAXBException; @@ -19,6 +21,7 @@ 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; @@ -115,6 +118,11 @@ public class MetadataDiscovery { MetadataFormat metadata = reader.getMetadataFormatForMetadataProfile(profile); MetaDataProfileBean bean = toMetaDataProfileBean(metadata, categories, profile.getName()); beans.add(bean); + + if(!WsUtil.isWithinPortal()) { + LOG.info("DEV MODE ENABLED - Out of portal!"); + randomizeCurrentValues(bean.getMetadataFields()); + } } prettyPrintList(beans); @@ -130,6 +138,28 @@ public class MetadataDiscovery { return beans; } + private static void randomizeCurrentValues(List listFields) { + LOG.info("DEV MODE ENABLED - Generationg random current value"); + for (MetadataFieldWrapper metadataFieldWrapper : listFields) { + DataTypeWrapper dtw = metadataFieldWrapper.getType(); + + switch (dtw) { + case Boolean: + metadataFieldWrapper.setCurrentValue(Boolean.FALSE.toString()); + break; + case Number: + metadataFieldWrapper.setCurrentValue(new Random().nextInt()+""); + break; + case String: + case Text: + metadataFieldWrapper.setCurrentValue("Text "+UUID.randomUUID()); + break; + default: + break; + } + } + } + /** diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/metadata/MetaDataProfileBean.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/metadata/MetaDataProfileBean.java index bec1e35..1d3e2e0 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/metadata/MetaDataProfileBean.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/metadata/MetaDataProfileBean.java @@ -3,22 +3,40 @@ package org.gcube.portlets.widgets.mpformbuilder.shared.metadata; import java.io.Serializable; import java.util.List; + /** - * A MetaDataProfileBean with its children (MetaDataType, MetaDataFields, Categories) - * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + * The Class MetaDataProfileBean. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Mar 3, 2022 */ public class MetaDataProfileBean implements Serializable{ - private static final long serialVersionUID = -7377022025375553568L; - + /** + * + */ + private static final long serialVersionUID = -8307518917648131477L; private String type; private String title; private List categories; private List metadataFields; + /** + * Instantiates a new meta data profile bean. + */ public MetaDataProfileBean(){ super(); } + + /** + * Instantiates a new meta data profile bean. + * + * @param type the type + * @param title the title + * @param metadataFields the metadata fields + * @param categories the categories + */ public MetaDataProfileBean(String type, String title, List metadataFields, @@ -31,43 +49,82 @@ public class MetaDataProfileBean implements Serializable{ } /** + * Gets the type. + * * @return the type */ public String getType() { return type; } + /** + * Sets the type. + * * @param type the type to set */ public void setType(String type) { this.type = type; } + /** + * Gets the metadata fields. + * * @return the metadataFields */ public List getMetadataFields() { return metadataFields; } + /** + * Sets the metadata fields. + * * @param metadataFields the metadataFields to set */ public void setMetadataFields(List metadataFields) { this.metadataFields = metadataFields; } + /** + * Gets the categories. + * + * @return the categories + */ public List getCategories() { return categories; } + /** + * Sets the categories. + * + * @param categories the new categories + */ public void setCategories(List categories) { this.categories = categories; } + + /** + * Gets the title. + * + * @return the title + */ public String getTitle() { return title; } + + /** + * Sets the title. + * + * @param title the new title + */ public void setTitle(String title) { this.title = title; } + + /** + * To string. + * + * @return the string + */ @Override public String toString() { final int maxLen = 10; diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/metadata/MetadataFieldWrapper.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/metadata/MetadataFieldWrapper.java index dd2291f..1094a4b 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/metadata/MetadataFieldWrapper.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/metadata/MetadataFieldWrapper.java @@ -1,16 +1,16 @@ package org.gcube.portlets.widgets.mpformbuilder.shared.metadata; - import java.io.Serializable; import java.util.List; /** * The Class MetadataFieldWrapper. - * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * @author francesco-mangiacrapa at ISTI-CNR (costantino.perciante@isti.cnr.it) + * Mar 3, 2022 */ -public class MetadataFieldWrapper implements Serializable{ +public class MetadataFieldWrapper implements UpdatableField, Serializable { private static final long serialVersionUID = -8476731365884466698L; private String fieldName; @@ -25,9 +25,11 @@ public class MetadataFieldWrapper implements Serializable{ private CategoryWrapper ownerCategory; private FieldAsGroup asGroup; private FieldAsTag asTag; - + private Integer maxOccurs = 1; + private String currentValue; + /** * Instantiates a new metadata field. */ @@ -38,19 +40,17 @@ public class MetadataFieldWrapper implements Serializable{ /** * Instantiates a new metadata field. * - * @param fieldName the field name - * @param mandatory the mandatory - * @param type the type + * @param fieldName the field name + * @param mandatory the mandatory + * @param type the type * @param defaultValue the default value - * @param note the note - * @param vocabulary the vocabulary - * @param validator the validator - * @param category the category + * @param note the note + * @param vocabulary the vocabulary + * @param validator the validator + * @param category the category */ - public MetadataFieldWrapper( - String fieldName, Boolean mandatory, DataTypeWrapper type, - String defaultValue, String note, List vocabulary, - String validator, CategoryWrapper category) { + public MetadataFieldWrapper(String fieldName, Boolean mandatory, DataTypeWrapper type, String defaultValue, + String note, List vocabulary, String validator, CategoryWrapper category) { super(); this.fieldName = fieldName; this.mandatory = mandatory; @@ -61,8 +61,6 @@ public class MetadataFieldWrapper implements Serializable{ this.validator = validator; this.ownerCategory = category; } - - /** * Gets the max occurs. @@ -310,30 +308,48 @@ public class MetadataFieldWrapper implements Serializable{ this.asTag = asTag; } - /* (non-Javadoc) + /** + * Sets the current value. + * + * @param value the new current value + */ + public void setCurrentValue(String value) { + this.currentValue = value; + + } + + /** + * Gets the current value. + * + * @return the current value + */ + public String getCurrentValue() { + return currentValue; + } + + /** + * To string. + * + * @return the string + */ + /* + * (non-Javadoc) + * * @see java.lang.Object#toString() */ @Override public String toString() { - return "MetadataFieldWrapper [" - + (fieldName != null ? "fieldName=" + fieldName + ", " : "") - + (fieldNameFromCategory != null ? "fieldNameFromCategory=" - + fieldNameFromCategory + ", " : "") + return "MetadataFieldWrapper [" + (fieldName != null ? "fieldName=" + fieldName + ", " : "") + + (fieldNameFromCategory != null ? "fieldNameFromCategory=" + fieldNameFromCategory + ", " : "") + (mandatory != null ? "mandatory=" + mandatory + ", " : "") + (maxOccurs != null ? "maxOccurs=" + maxOccurs + ", " : "") + (type != null ? "type=" + type + ", " : "") - + (defaultValue != null ? "defaultValue=" + defaultValue + ", " - : "") + + (defaultValue != null ? "defaultValue=" + defaultValue + ", " : "") + (note != null ? "note=" + note + ", " : "") - + (vocabulary != null ? "vocabulary=" + vocabulary + ", " : "") - + "multiSelection=" - + multiSelection - + ", " - + (validator != null ? "validator=" + validator + ", " : "") - + (ownerCategory != null ? "ownerCategory=" + ownerCategory.getId() - + ", " : "") - + (asGroup != null ? "asGroup=" + asGroup + ", " : "") - + (asTag != null ? "asTag=" + asTag : "") + "]"; + + (vocabulary != null ? "vocabulary=" + vocabulary + ", " : "") + "multiSelection=" + multiSelection + + ", " + (validator != null ? "validator=" + validator + ", " : "") + + (ownerCategory != null ? "ownerCategory=" + ownerCategory.getId() + ", " : "") + + (asGroup != null ? "asGroup=" + asGroup + ", " : "") + (asTag != null ? "asTag=" + asTag : "") + "]"; } } diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/metadata/UpdatableField.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/metadata/UpdatableField.java new file mode 100644 index 0000000..e8c67c7 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/shared/metadata/UpdatableField.java @@ -0,0 +1,8 @@ +package org.gcube.portlets.widgets.mpformbuilder.shared.metadata; + +public interface UpdatableField { + + void setCurrentValue(String value); + + String getCurrentValue(); +}