Working on Feature #11331 Field repeatability

Updated pom version at 1.6.0

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@179748 82a268e6-3cf1-43bd-a215-b396298e98cf
migrate-to-catalogue-util-library_#19764
Francesco Mangiacrapa 5 years ago
parent 849fe5e104
commit 16beccba5d

@ -1,18 +1,27 @@
<ReleaseNotes>
<Changeset
component="org.gcube.portlets-widgets.ckan-metadata-publisher-widget.1-6-0"
date="${buildDate}">
<Change>[Feature #11331] Field repeatability: support for catalogue widget
</Change>
</Changeset>
<Changeset
component="org.gcube.portlets-widgets.ckan-metadata-publisher-widget.1-5-0"
date="${buildDate}">
<Change>[Feature #13074] Integrated with 'openlayer-basic-widgets'</Change>
<Change>[Feature #13074] Integrated with 'openlayer-basic-widgets'
</Change>
</Changeset>
<Changeset
component="org.gcube.portlets-widgets.ckan-metadata-publisher-widget.1-4-1"
date="2018-11-20">
<Change>[Bug #12914] The form to add/choice the resources to publishing remains frozen</Change>
<Change>[Bug #12914] The form to add/choice the resources to
publishing remains frozen</Change>
</Changeset>
<Changeset
component="org.gcube.portlets-widgets.ckan-metadata-publisher-widget.1-4-0"
date="2018-09-28">
<Change>[Incident #12563] Error when trying to publish the content of a workspace folder into the catalogue</Change>
<Change>[Incident #12563] Error when trying to publish the content of
a workspace folder into the catalogue</Change>
</Changeset>
<Changeset
component="org.gcube.portlets-widgets.ckan-metadata-publisher-widget.1-3-3"

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ckan-metadata-publisher-widget</artifactId>
<version>1.5.0-SNAPSHOT</version>
<version>1.6.0-SNAPSHOT</version>
<name>gCube Ckan metadata publisher widget</name>
<description>

@ -62,7 +62,6 @@ import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
@ -193,8 +192,8 @@ public class CreateDatasetForm extends Composite{
// added custom field entries (by the user)
private List<CustomFieldEntry> customFieldEntriesList = new ArrayList<CustomFieldEntry>();
// the list of MetaDataFieldSkeleton added
private List<MetaDataFieldSkeleton> listOfMetadataFields = new ArrayList<MetaDataFieldSkeleton>();
// the list of MetaDataField added
private List<MetaDataField> listOfMetadataFields = new ArrayList<MetaDataField>();
// dataset metadata bean
private DatasetBean receivedBean;
@ -713,13 +712,22 @@ public class CreateDatasetForm extends Composite{
if(categories == null || categories.isEmpty()){
for (MetadataFieldWrapper field : fields) {
MetaDataFieldSkeleton fieldWidget;
/*MetaDataFieldSkeleton fieldWidget;
try {
fieldWidget = new MetaDataFieldSkeleton(field, eventBus);
metadataFieldsPanel.add(fieldWidget);
listOfMetadataFields.add(fieldWidget);
} catch (Exception e) {
GWT.log("Unable to build such widget", e);
}*/
MetaDataField fieldWidget;
try {
fieldWidget = new MetaDataField(field, eventBus);
metadataFieldsPanel.add(fieldWidget);
listOfMetadataFields.add(fieldWidget);
} catch (Exception e) {
GWT.log("Unable to build such widget", e);
}
}
}else{
@ -732,13 +740,23 @@ public class CreateDatasetForm extends Composite{
fields.removeAll(fieldsForThisCategory);
for (MetadataFieldWrapper metadataFieldWrapper : fieldsForThisCategory) {
MetaDataFieldSkeleton fieldWidget;
/*MetaDataFieldSkeleton fieldWidget;
try {
fieldWidget = new MetaDataFieldSkeleton(metadataFieldWrapper, eventBus);
cp.addField(fieldWidget);
listOfMetadataFields.add(fieldWidget);
} catch (Exception e) {
GWT.log("Unable to build such widget", e);
}*/
MetaDataField fieldWidget;
try {
fieldWidget = new MetaDataField(metadataFieldWrapper, eventBus);
cp.addField(fieldWidget);
listOfMetadataFields.add(fieldWidget);
} catch (Exception e) {
GWT.log("Unable to build such widget", e);
}
}
metadataFieldsPanel.add(cp);
@ -748,13 +766,23 @@ public class CreateDatasetForm extends Composite{
// add the remaining one at the end of the categories
CategoryPanel extrasCategory = new CategoryPanel("Other", null);
for (MetadataFieldWrapper field : fields) {
MetaDataFieldSkeleton fieldWidget;
/*MetaDataFieldSkeleton fieldWidget;
try {
fieldWidget = new MetaDataFieldSkeleton(field, eventBus);
extrasCategory.addField(fieldWidget);
listOfMetadataFields.add(fieldWidget);
} catch (Exception e) {
GWT.log("Unable to build such widget", e);
}*/
MetaDataField fieldWidget;
try {
fieldWidget = new MetaDataField(field, eventBus);
extrasCategory.addField(fieldWidget);
listOfMetadataFields.add(fieldWidget);
} catch (Exception e) {
GWT.log("Unable to build such widget", e);
}
}
metadataFieldsPanel.add(extrasCategory);
@ -931,31 +959,35 @@ public class CreateDatasetForm extends Composite{
Map<String, List<String>> customFieldsMap = new HashMap<String, List<String>>();
// prepare custom fields
for (MetaDataFieldSkeleton field : listOfMetadataFields) {
List<String> valuesForField = field.getFieldCurrentValue();
if(!valuesForField.isEmpty()){
String key = field.getFieldNameQualified();
List<String> valuesForThisField = null;
if(customFieldsMap.containsKey(key))
valuesForThisField = customFieldsMap.get(key);
else
valuesForThisField = new ArrayList<String>();
valuesForThisField.addAll(valuesForField);
customFieldsMap.put(key, valuesForThisField);
// get also tag/group if it is the case for this field
List<String> tagsField = field.getTagFromThisField();
if(tagsField != null)
tags.addAll(tagsField);
List<String> groupsTitle = field.getGroupTitleFromThisGroup();
if(groupsTitle != null){
for (String groupTitle : groupsTitle) {
if(field.isGroupToForce())
groupsToForceCreation.add(new OrganizationBean(groupTitle, groupTitle, false, field.isPropagateUp()));
else
groups.add(new OrganizationBean(groupTitle, groupTitle, false, field.isPropagateUp()));
for (MetaDataField metaField : listOfMetadataFields) {
for (MetaDataFieldSkeleton field : metaField.getListOfMetadataFields()) {
List<String> valuesForField = field.getFieldCurrentValue();
if(!valuesForField.isEmpty()){
String key = field.getFieldNameQualified();
List<String> valuesForThisField = null;
if(customFieldsMap.containsKey(key))
valuesForThisField = customFieldsMap.get(key);
else
valuesForThisField = new ArrayList<String>();
valuesForThisField.addAll(valuesForField);
customFieldsMap.put(key, valuesForThisField);
// get also tag/group if it is the case for this field
List<String> tagsField = field.getTagFromThisField();
if(tagsField != null)
tags.addAll(tagsField);
List<String> groupsTitle = field.getGroupTitleFromThisGroup();
if(groupsTitle != null){
for (String groupTitle : groupsTitle) {
if(field.isGroupToForce())
groupsToForceCreation.add(new OrganizationBean(groupTitle, groupTitle, false, field.isPropagateUp()));
else
groups.add(new OrganizationBean(groupTitle, groupTitle, false, field.isPropagateUp()));
}
}
}
}
@ -1258,14 +1290,17 @@ public class CreateDatasetForm extends Composite{
*/
private String areProfileDataValid() {
for (MetaDataFieldSkeleton field : listOfMetadataFields) {
field.removeError();
for (MetaDataField metaField : listOfMetadataFields) {
for (MetaDataFieldSkeleton field : metaField.getListOfMetadataFields()) {
String error = field.isFieldValueValid();
if(error != null){
field.showError();
return field.getFieldNameOriginal() + " is not valid. Suggestion: " + error;
field.removeError();
String error = field.isFieldValueValid();
if(error != null){
field.showError();
return field.getFieldNameOriginal() + " is not valid. Suggestion: " + error;
}
}
}
@ -1447,8 +1482,11 @@ public class CreateDatasetForm extends Composite{
ce.freeze();
// disable profile fields
for (MetaDataFieldSkeleton field : listOfMetadataFields) {
field.freeze();
for (MetaDataField metaField : listOfMetadataFields) {
for (MetaDataFieldSkeleton field : metaField.getListOfMetadataFields()) {
field.freeze();
}
}
// freeze table of resources

@ -0,0 +1,160 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.form;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.MetaDataFieldSkeleton;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.MetadataFieldWrapper;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.ControlLabel;
import com.github.gwtbootstrap.client.ui.Label;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* The Class MetaDataField.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jun 10, 2019
*/
public class MetaDataField extends Composite {
private static MetaDataFieldUiBinder uiBinder = GWT.create(MetaDataFieldUiBinder.class);
@UiField VerticalPanel panelMetaDataFieldsSkeleton;
@UiField Label repeatabilityLabel;
//@UiField ControlGroup cgMetaDataFieldSkeletonFields;
@UiField Button addFieldButton;
@UiField Button removeFieldButton;
private List<MetaDataFieldSkeleton> listOfMetadataFields = new ArrayList<MetaDataFieldSkeleton>();
private MetadataFieldWrapper fieldWrapper;
private HandlerManager eventBus;
/**
* The Interface MetaDataFieldUiBinder.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jun 10, 2019
*/
interface MetaDataFieldUiBinder extends UiBinder<Widget, MetaDataField> {
}
/**
* Instantiates a new meta data field.
*
* @param field the field
* @param eventBus the event bus
* @throws Exception the exception
*/
public MetaDataField(final MetadataFieldWrapper field, HandlerManager eventBus) throws Exception {
initWidget(uiBinder.createAndBindUi(this));
this.fieldWrapper = field;
this.eventBus = eventBus;
addNewOccurrenceOfField();
checkAllowedAddField();
checkAllowedRemoveField();
addFieldButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
addNewOccurrenceOfField();
checkAllowedAddField();
checkAllowedRemoveField();
}
});
removeFieldButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
removeLatestOccurrenceOfFiled();
checkAllowedAddField();
checkAllowedRemoveField();
}
});
//The field is repeatable
if(field.getMaxOccurs()>1) {
repeatabilityLabel.setVisible(true);
repeatabilityLabel.setText(field.getFieldName()+" repeatability");
}
}
/**
* Check allowed remove field.
*/
private void checkAllowedRemoveField() {
boolean removeCond = fieldWrapper.getMaxOccurs()>1 && listOfMetadataFields.size()>1;
removeFieldButton.setVisible(removeCond);
}
/**
* Checks if is allowed add occurrence.
*/
private void checkAllowedAddField() {
boolean repeatibilityCond = fieldWrapper.getMaxOccurs()>1 && listOfMetadataFields.size()<fieldWrapper.getMaxOccurs();
addFieldButton.setVisible(repeatibilityCond);
}
/**
* Removes the latest occurrence of filed.
*/
private void removeLatestOccurrenceOfFiled() {
int size = listOfMetadataFields.size();
MetaDataFieldSkeleton skeleton = listOfMetadataFields.get(size-1);
try {
panelMetaDataFieldsSkeleton.remove(skeleton);
listOfMetadataFields.remove(size-1);
}catch (Exception e) {
GWT.log("Error: ",e);
}
}
/**
* Adds the new occurrence of field.
*/
private void addNewOccurrenceOfField() {
try {
MetaDataFieldSkeleton fieldWidget = new MetaDataFieldSkeleton(fieldWrapper, eventBus);
listOfMetadataFields.add(fieldWidget);
panelMetaDataFieldsSkeleton.add(fieldWidget);
} catch (Exception e) {
GWT.log("Error: ",e);
}
}
/**
* Gets the list of metadata fields.
*
* @return the list of metadata fields
*/
public List<MetaDataFieldSkeleton> getListOfMetadataFields() {
return listOfMetadataFields;
}
}

@ -0,0 +1,22 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.important {
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
<g:VerticalPanel
ui:field="panelMetaDataFieldsSkeleton" width="100%">
</g:VerticalPanel>
<b:ControlGroup>
<b:Label ui:field="repeatabilityLabel" visible="false">Repeatability</b:Label>
<b:Button icon="MINUS_SIGN" title="Remove Latest Field"
ui:field="removeFieldButton" visible="false"></b:Button>
<b:Button icon="PLUS_SIGN" title="Add Another Field"
ui:field="addFieldButton" visible="false"></b:Button>
</b:ControlGroup>
</g:HTMLPanel>
</ui:UiBinder>

@ -3,6 +3,8 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.form.MetaDataField;
import com.github.gwtbootstrap.client.ui.PageHeader;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Float;
@ -22,7 +24,9 @@ public class CategoryPanel extends Composite{
@UiField VerticalPanel fieldsPanel;
@UiField PageHeader categoryHeader;
private List<MetaDataFieldSkeleton> fieldsForThisCategory;
//private List<MetaDataFieldSkeleton> fieldsForThisCategory;
private List<MetaDataField> fieldsForThisCategory;
public CategoryPanel() {
initWidget(uiBinder.createAndBindUi(this));
@ -48,7 +52,7 @@ public class CategoryPanel extends Composite{
* Add a field to this widget
* @param fieldWidget
*/
public void addField(MetaDataFieldSkeleton fieldWidget) {
/*public void addField(MetaDataFieldSkeleton fieldWidget) {
if(fieldsForThisCategory == null){
fieldsForThisCategory = new ArrayList<MetaDataFieldSkeleton>();
fieldWidget.setVisible(true);
@ -56,6 +60,21 @@ public class CategoryPanel extends Composite{
}
fieldsForThisCategory.add(fieldWidget);
fieldsPanel.add(fieldWidget);
}*/
/**
* Add a field to this widget
* @param fieldWidget
*/
public void addField(MetaDataField fieldWidget) {
if(fieldsForThisCategory == null){
fieldsForThisCategory = new ArrayList<MetaDataField>();
fieldWidget.setVisible(true);
fieldsPanel.setVisible(true);
}
fieldsForThisCategory.add(fieldWidget);
fieldsPanel.add(fieldWidget);
}
}

@ -242,6 +242,24 @@ public class MetadataDiscovery {
ownerCategory.setFieldsForThisCategory(fieldsPerCategoryN);
}
}
//Added by Francesco
int maxOccurs = 1; //Default value is 1. A field should occur once.
if(metadataField.getMaxOccurs()!=null) {
try {
//the field can appear an unlimited number of times.
if(metadataField.getMaxOccurs().equals("*")) {
maxOccurs = Integer.MAX_VALUE;
}else {
//the field must appear N times;
maxOccurs = Integer.parseInt(metadataField.getMaxOccurs());
}
}catch (Exception e) {
//silent
}
wrapperObj.setMaxOccurs(maxOccurs);
}
fieldsWrapper.add(wrapperObj);
}

@ -7,6 +7,8 @@ import java.util.List;
/**
* The Class MetadataFieldWrapper.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*
* @author francesco-mangiacrapa at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class MetadataFieldWrapper implements Serializable{
@ -23,6 +25,8 @@ public class MetadataFieldWrapper implements Serializable{
private CategoryWrapper ownerCategory;
private FieldAsGroup asGroup;
private FieldAsTag asTag;
private Integer maxOccurs = 1;
/**
* Instantiates a new metadata field.
@ -36,11 +40,12 @@ public class MetadataFieldWrapper implements Serializable{
*
* @param fieldName the field name
* @param mandatory the mandatory
* @param DataType the type
* @param defaulValue the defaul value
* @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
*/
public MetadataFieldWrapper(
String fieldName, Boolean mandatory, DataTypeWrapper type,
@ -56,6 +61,26 @@ public class MetadataFieldWrapper implements Serializable{
this.validator = validator;
this.ownerCategory = category;
}
/**
* Gets the max occurs.
*
* @return the max occurs
*/
public Integer getMaxOccurs() {
return maxOccurs;
}
/**
* Sets the max occurs.
*
* @param maxOccurs the new max occurs
*/
public void setMaxOccurs(Integer maxOccurs) {
this.maxOccurs = maxOccurs;
}
/**
* Gets the field name.
@ -140,7 +165,7 @@ public class MetadataFieldWrapper implements Serializable{
/**
* Sets the defaul value.
*
* @param defaulValue the defaulValue to set
* @param defaultValue the new default value
*/
public void setDefaultValue(String defaultValue) {
@ -177,54 +202,117 @@ public class MetadataFieldWrapper implements Serializable{
this.validator = validator;
}
/**
* Gets the type.
*
* @return the type
*/
public DataTypeWrapper getType() {
return type;
}
/**
* Sets the type.
*
* @param type the new type
*/
public void setType(DataTypeWrapper type) {
this.type = type;
}
/**
* Checks if is multi selection.
*
* @return true, if is multi selection
*/
public boolean isMultiSelection() {
return multiSelection;
}
/**
* Sets the multi selection.
*
* @param multiSelection the new multi selection
*/
public void setMultiSelection(boolean multiSelection) {
this.multiSelection = multiSelection;
}
/**
* Gets the owner category.
*
* @return the owner category
*/
public CategoryWrapper getOwnerCategory() {
return ownerCategory;
}
/**
* Sets the owner category.
*
* @param ownerCategory the new owner category
*/
public void setOwnerCategory(CategoryWrapper ownerCategory) {
this.ownerCategory = ownerCategory;
}
/**
* Gets the field name from category.
*
* @return the field name from category
*/
public String getFieldNameFromCategory() {
return fieldNameFromCategory;
}
/**
* Sets the field name from category.
*
* @param fieldNameFromCategory the new field name from category
*/
public void setFieldNameFromCategory(String fieldNameFromCategory) {
this.fieldNameFromCategory = fieldNameFromCategory;
}
/**
* Gets the as group.
*
* @return the as group
*/
public FieldAsGroup getAsGroup() {
return asGroup;
}
/**
* Sets the as group.
*
* @param asGroup the new as group
*/
public void setAsGroup(FieldAsGroup asGroup) {
this.asGroup = asGroup;
}
/**
* Gets the as tag.
*
* @return the as tag
*/
public FieldAsTag getAsTag() {
return asTag;
}
/**
* Sets the as tag.
*
* @param asTag the new as tag
*/
public void setAsTag(FieldAsTag asTag) {
this.asTag = asTag;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "MetadataFieldWrapper ["
@ -232,6 +320,7 @@ public class MetadataFieldWrapper implements Serializable{
+ (fieldNameFromCategory != null ? "fieldNameFromCategory="
+ fieldNameFromCategory + ", " : "")
+ (mandatory != null ? "mandatory=" + mandatory + ", " : "")
+ (maxOccurs != null ? "maxOccurs=" + maxOccurs + ", " : "")
+ (type != null ? "type=" + type + ", " : "")
+ (defaultValue != null ? "defaultValue=" + defaultValue + ", "
: "")

Loading…
Cancel
Save