minor fixes on loading and on number fields validation

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@147230 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-04-27 15:22:04 +00:00
parent f73277c929
commit b4ea5e79c6
4 changed files with 39 additions and 22 deletions

14
pom.xml
View File

@ -55,11 +55,11 @@
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<!-- <dependency> --> <!-- <dependency> -->
<!-- <groupId>xerces</groupId> --> <!-- <groupId>xerces</groupId> -->
<!-- <artifactId>xercesImpl</artifactId> --> <!-- <artifactId>xercesImpl</artifactId> -->
<!-- <version>2.9.1</version> --> <!-- <version>2.9.1</version> -->
<!-- </dependency> --> <!-- </dependency> -->
<dependency> <dependency>
<groupId>com.google.gwt</groupId> <groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId> <artifactId>gwt-servlet</artifactId>
@ -215,6 +215,10 @@
<goal>compile</goal> <goal>compile</goal>
<goal>test</goal> <goal>test</goal>
</goals> </goals>
<!-- <configuration> -->
<!-- <draftCompile>true</draftCompile> -->
<!-- <localWorkers>8</localWorkers> -->
<!-- </configuration> -->
</execution> </execution>
</executions> </executions>
<!-- Plugin configuration. There are many available options, see gwt-maven-plugin <!-- Plugin configuration. There are many available options, see gwt-maven-plugin

View File

@ -319,14 +319,17 @@ public class CreateDatasetForm extends Composite{
maintainerTextbox.setText(bean.getAuthorSurname() + " " + bean.getAuthorName()); maintainerTextbox.setText(bean.getAuthorSurname() + " " + bean.getAuthorName());
maintainerEmailTextbox.setText(bean.getMaintainerEmail()); maintainerEmailTextbox.setText(bean.getMaintainerEmail());
// retrieve custom fields setAlertBlock("Retrieving information, please wait...", AlertType.INFO, true);
Map<String, List<String>> customFieldsMap = bean.getCustomFields();
List<String> vocabularyTags = bean.getTagsVocabulary();
// vocabulary list of tags has preemption // vocabulary list of tags has preemption
List<String> vocabularyTags = bean.getTagsVocabulary();
tagsPanel.setVocabulary(vocabularyTags); tagsPanel.setVocabulary(vocabularyTags);
if(customFieldsMap != null){ // retrieve custom fields
Map<String, List<String>> customFieldsMap = bean.getCustomFields();
// TODO Check if these tags are ok for the vocabulary
if(customFieldsMap != null && vocabularyTags == null){
// get the keys and put them as tags // get the keys and put them as tags
Iterator<Entry<String, List<String>>> iteratorOverCustomField = customFieldsMap.entrySet().iterator(); Iterator<Entry<String, List<String>>> iteratorOverCustomField = customFieldsMap.entrySet().iterator();
@ -382,9 +385,6 @@ public class CreateDatasetForm extends Composite{
} }
}); });
// try to retrieve the profiles
setAlertBlock("Retrieving types, please wait...", AlertType.INFO, true);
// get the name of the organization from the title // get the name of the organization from the title
final String orgName = nameTitleOrganizationMap.get(organizationsListbox.getSelectedItemText()); final String orgName = nameTitleOrganizationMap.get(organizationsListbox.getSelectedItemText());
@ -397,7 +397,6 @@ public class CreateDatasetForm extends Composite{
tagsPanel.setVocabulary(vocabulary); tagsPanel.setVocabulary(vocabulary);
tagsPanel.setVisible(true); tagsPanel.setVisible(true);
setAlertBlock("", AlertType.ERROR, false);
} }
@Override @Override
@ -410,6 +409,8 @@ public class CreateDatasetForm extends Composite{
} }
}); });
// try to retrieve the profiles
setAlertBlock("Retrieving types, please wait...", AlertType.INFO, true);
// perform remote request of profiles for the selected organization // perform remote request of profiles for the selected organization
ckanServices.getProfiles(orgName, new AsyncCallback<List<MetaDataProfileBean>>() { ckanServices.getProfiles(orgName, new AsyncCallback<List<MetaDataProfileBean>>() {
@ -492,7 +493,7 @@ public class CreateDatasetForm extends Composite{
}); });
}else{ }else{
setAlertBlock("Error while retrieving licenses, try later", AlertType.ERROR, true); setAlertBlock("Error while retrieving licenses", AlertType.ERROR, true);
} }
} }
}); });

View File

@ -2,7 +2,7 @@
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" <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"> xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<g:HTMLPanel> <g:HTMLPanel>
<g:VerticalPanel> <g:VerticalPanel width="100%">
<b:PageHeader ui:field="categoryHeader"></b:PageHeader> <b:PageHeader ui:field="categoryHeader"></b:PageHeader>
<!-- Here will be placed the metadata fields formats --> <!-- Here will be placed the metadata fields formats -->
<g:VerticalPanel ui:field="fieldsPanel" visible="false" <g:VerticalPanel ui:field="fieldsPanel" visible="false"

View File

@ -66,7 +66,7 @@ public class MetaDataFieldSkeleton extends Composite{
@UiField FocusPanel focusPanelIconContainer; @UiField FocusPanel focusPanelIconContainer;
@UiField ControlGroup metafieldControlGroup; @UiField ControlGroup metafieldControlGroup;
private static final String REGEX_IS_NUMBER = "[0-9]+[.]?[0-9]+"; // private static final String REGEX_IS_NUMBER = "[0-9]+[.]?[0-9]+";
// the element that holds the value (it could be a checkbox, textbox or listbox, textarea, calendar, two calendars, more calendars) // the element that holds the value (it could be a checkbox, textbox or listbox, textarea, calendar, two calendars, more calendars)
private Widget holder; private Widget holder;
@ -428,7 +428,7 @@ public class MetaDataFieldSkeleton extends Composite{
if(!numberValue.trim().isEmpty()) if(!numberValue.trim().isEmpty())
if(field.getValidator() == null || field.getValidator().isEmpty()) if(field.getValidator() == null || field.getValidator().isEmpty())
return checkValidator(numberValue, REGEX_IS_NUMBER) ? null : MALFORMED_ATTRIBUTE; return isANumber(numberValue) ? null : MALFORMED_ATTRIBUTE;
else return checkValidator(numberValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE; else return checkValidator(numberValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE;
else return " a mandatory attribute cannot be empty"; else return " a mandatory attribute cannot be empty";
@ -437,8 +437,11 @@ public class MetaDataFieldSkeleton extends Composite{
if(numberValue.trim().isEmpty()) if(numberValue.trim().isEmpty())
return null; return null;
else { else {
String validatorToUse = field.getValidator() == null || field.getValidator().isEmpty() ? REGEX_IS_NUMBER : field.getValidator(); String validatorToUse = field.getValidator();
if(validatorToUse != null && !validatorToUse.isEmpty())
return checkValidator(numberValue, validatorToUse) ? null : MALFORMED_ATTRIBUTE; return checkValidator(numberValue, validatorToUse) ? null : MALFORMED_ATTRIBUTE;
else
return isANumber(numberValue) ? null : MALFORMED_ATTRIBUTE;
} }
} }
@ -486,6 +489,15 @@ public class MetaDataFieldSkeleton extends Composite{
} }
} }
/**
* Check if this string is a number
* @param numberValue
* @return
*/
private boolean isANumber(String numberValue) {
return numberValue.matches("-?\\d+(\\.\\d+)?");
}
/** /**
* Check if value matches validator (regex). In case validator is null, true is returned. * Check if value matches validator (regex). In case validator is null, true is returned.
* @param value * @param value