fix for check on maintainer email

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@132479 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-10-03 14:56:32 +00:00
parent 78a3b1c82c
commit ce69eaa9aa
1 changed files with 19 additions and 16 deletions

View File

@ -169,6 +169,7 @@ public class CreateDatasetForm extends Composite{
private static final String REGEX_TITLE_PRODUCT_SUBWORD = "[^a-zA-Z0-9_.-]"; private static final String REGEX_TITLE_PRODUCT_SUBWORD = "[^a-zA-Z0-9_.-]";
private static final String REGEX_MAIL = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b"; private static final String REGEX_MAIL = "\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b";
private static final String NONE_PROFILE = "none";
// error/info messages // error/info messages
protected static final String ERROR_PRODUCT_CREATION = "There was an error while trying to publish your product, sorry.. Retry later"; protected static final String ERROR_PRODUCT_CREATION = "There was an error while trying to publish your product, sorry.. Retry later";
@ -481,7 +482,7 @@ public class CreateDatasetForm extends Composite{
} }
// add "none" item again // add "none" item again
metadataProfilesFormatListbox.addItem("none"); metadataProfilesFormatListbox.addItem(NONE_PROFILE);
// select "none" // select "none"
metadataProfilesFormatListbox.setSelectedIndex(0); metadataProfilesFormatListbox.setSelectedIndex(0);
@ -549,7 +550,7 @@ public class CreateDatasetForm extends Composite{
String selectedItem = metadataProfilesFormatListbox.getSelectedItemText(); String selectedItem = metadataProfilesFormatListbox.getSelectedItemText();
if(selectedItem.equals("none")){ if(selectedItem.equals(NONE_PROFILE)){
// hide the panel // hide the panel
metadataFieldsPanel.clear(); metadataFieldsPanel.clear();
metadataFieldsPanel.setVisible(false); metadataFieldsPanel.setVisible(false);
@ -659,7 +660,7 @@ public class CreateDatasetForm extends Composite{
} }
if(metadataProfilesFormatListbox.getSelectedItemText().equals("none")) if(metadataProfilesFormatListbox.getSelectedItemText().equals(NONE_PROFILE))
selectedProfile.setText(""); selectedProfile.setText("");
else else
selectedProfile.setText("Selected Profile is " + metadataProfilesFormatListbox.getSelectedItemText()); selectedProfile.setText("Selected Profile is " + metadataProfilesFormatListbox.getSelectedItemText());
@ -728,15 +729,15 @@ public class CreateDatasetForm extends Composite{
} }
else{ else{
String title = titleTextBox.getValue(); String title = titleTextBox.getValue().trim();
String description = descriptionTextarea.getText(); String description = descriptionTextarea.getText().trim();
String selectedLicense = licenseListbox.getSelectedItemText(); String selectedLicense = licenseListbox.getSelectedItemText();
String visibility = visibilityListbox.getSelectedItemText(); String visibility = visibilityListbox.getSelectedItemText();
long version = Long.valueOf(versionTextbox.getValue()); long version = Long.valueOf(versionTextbox.getValue().trim());
String author = authorTextbox.getValue(); String author = authorTextbox.getValue();
String authorEmail = authorEmailTextbox.getValue(); String authorEmail = authorEmailTextbox.getValue();
String maintainer = maintainerTextbox.getValue(); String maintainer = maintainerTextbox.getValue().trim();
String maintainerEmail = maintainerEmailTextbox.getValue(); String maintainerEmail = maintainerEmailTextbox.getValue().trim();
String chosenOrganizationTitle = organizationsListbox.getSelectedItemText(); String chosenOrganizationTitle = organizationsListbox.getSelectedItemText();
//we need to retrieve the organization's name from this title //we need to retrieve the organization's name from this title
@ -1096,13 +1097,14 @@ public class CreateDatasetForm extends Composite{
metadataProfilesControlGroup.setType(ControlGroupType.NONE); metadataProfilesControlGroup.setType(ControlGroupType.NONE);
organizationsGroup.setType(ControlGroupType.NONE); organizationsGroup.setType(ControlGroupType.NONE);
if(titleTextBox.getText().isEmpty()){ String title = titleTextBox.getText().trim();
if(title.isEmpty()){
productTitleGroup.setType(ControlGroupType.ERROR); productTitleGroup.setType(ControlGroupType.ERROR);
return "Missing title"; return "Missing title";
} }
// better check for the title // better check for the title
String[] splittedTitle = titleTextBox.getText().split(" "); String[] splittedTitle = title.split(" ");
for (String word : splittedTitle) { for (String word : splittedTitle) {
String replaced = word.replaceAll(REGEX_TITLE_PRODUCT_SUBWORD, ""); String replaced = word.replaceAll(REGEX_TITLE_PRODUCT_SUBWORD, "");
@ -1113,14 +1115,15 @@ public class CreateDatasetForm extends Composite{
} }
// email reg expression // email reg expression
if(!maintainerEmailTextbox.getText().matches(REGEX_MAIL)){ String maintainerMail = maintainerEmailTextbox.getText();
if(!maintainerMail.isEmpty() && !maintainerMail.matches(REGEX_MAIL)){
maintainerControlGroup.setType(ControlGroupType.ERROR); maintainerControlGroup.setType(ControlGroupType.ERROR);
return "Not valid maintainer email"; return "Not valid maintainer email";
} }
// check if version is a number // check if version is a number
try{ try{
int number = Integer.valueOf(versionTextbox.getText()); int number = Integer.valueOf(versionTextbox.getText().trim());
if(number <= 0) if(number <= 0)
throw new Exception(); throw new Exception();
}catch(Exception e){ }catch(Exception e){
@ -1147,7 +1150,7 @@ public class CreateDatasetForm extends Composite{
* @return * @return
*/ */
private boolean checkSelectedMetaDataProfile() { private boolean checkSelectedMetaDataProfile() {
return metadataProfilesFormatListbox.getSelectedItemText().equals("none") && (metadataProfilesFormatListbox.getItemCount() != 1); return metadataProfilesFormatListbox.getSelectedItemText().equals(NONE_PROFILE) && (metadataProfilesFormatListbox.getItemCount() != 1);
} }
@UiHandler("resetButton") @UiHandler("resetButton")
@ -1227,7 +1230,7 @@ public class CreateDatasetForm extends Composite{
void onAddTag(KeyDownEvent event){ void onAddTag(KeyDownEvent event){
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
if (!"".equals(tagsEnterTextBox.getValue().trim())) { if (!tagsEnterTextBox.getValue().trim().isEmpty()) {
addTagElement(tagsEnterTextBox); addTagElement(tagsEnterTextBox);
@ -1274,9 +1277,9 @@ public class CreateDatasetForm extends Composite{
*/ */
private void addTagElement(TextBox itemBox){ private void addTagElement(TextBox itemBox){
if (itemBox.getValue() != null && !"".equals(itemBox.getValue().trim())) { if (itemBox.getValue() != null && !itemBox.getValue().trim().isEmpty()) {
if(tagsList.contains(itemBox.getValue())){ if(tagsList.contains(itemBox.getValue().trim())){
itemBox.setValue(""); itemBox.setValue("");
return; return;
} }