creating a new user has validation, search configurator defaults get set correctly
authorn.hoffmann <n.hoffmann@localhost>
Wed, 8 Jul 2009 14:03:32 +0000 (14:03 +0000)
committern.hoffmann <n.hoffmann@localhost>
Wed, 8 Jul 2009 14:03:32 +0000 (14:03 +0000)
taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchBar.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/wizard/UserWizardPage.java

index 3a02dc2acafc6bc1202dd00839ef114fa2e03038..79e35c170a139e58d005c6bb7c38f89f96ca29cb 100644 (file)
@@ -218,9 +218,15 @@ public class SearchBar extends WorkbenchWindowControlContribution{
                }
                
                public boolean getPreference(){
+                       if(! PreferencesUtil.getPreferenceStore().contains(PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_TAXA)){
+                               // initializes the search configurator
+                               PreferencesUtil.initializeSearchConfigurator();
+                       }
+                       
                        switch(this){
                        case TAXON:
-                               return PreferencesUtil.getPreferenceStore().getBoolean(PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_TAXA);
+                               boolean result = PreferencesUtil.getPreferenceStore().getBoolean(PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_TAXA);
+                               return result;
                        case SYNONYM:
                                return PreferencesUtil.getPreferenceStore().getBoolean(PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_SYNONYMS);
                        case NAME:
index fe1ba4b8b65e3f896a6ae6c005199611bf414619..0d0aa20846f6ba59a3a1ac99d89c256fd144f2ec 100644 (file)
@@ -46,10 +46,10 @@ public class PreferencesUtil {
        private static final Logger logger = Logger\r
                        .getLogger(PreferencesUtil.class);\r
 \r
-       public static final String TAXON_SERVICE_CONFIGURATOR_TAXA = "TAXON_SERVICE_CONFIGURATOR_TAXA";\r
-       public static final String TAXON_SERVICE_CONFIGURATOR_SYNONYMS = "TAXON_SERVICE_CONFIGURATOR_SYNONYMS";\r
-       public static final String TAXON_SERVICE_CONFIGURATOR_NAMES = "TAXON_SERVICE_CONFIGURATOR_NAMES";\r
-       public static final String TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES = "TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES";\r
+       public static final String TAXON_SERVICE_CONFIGURATOR_TAXA = "taxonServiceConfigurator.doTaxa";\r
+       public static final String TAXON_SERVICE_CONFIGURATOR_SYNONYMS = "taxonServiceConfigurator.doSynonyms";\r
+       public static final String TAXON_SERVICE_CONFIGURATOR_NAMES = "taxonServiceConfigurator.doNamesWithoutTaxa";\r
+       public static final String TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES = "taxonServiceConfigurator.doTaxaByCommonNames";\r
        \r
        /**\r
         * \r
@@ -230,7 +230,7 @@ public class PreferencesUtil {
         * @return an <code>ITaxonServiceConfigurator</code> to pass to search methods\r
         */\r
        public static ITaxonServiceConfigurator getSearchConfigurator() {\r
-               ITaxonServiceConfigurator configurator = TaxonServiceConfiguratorImpl.NewInstance();\r
+               ITaxonServiceConfigurator configurator = initializeSearchConfigurator();\r
                // check for existence of at least one preference variable\r
                if(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_TAXA)){\r
                        // preferences exist\r
@@ -238,15 +238,25 @@ public class PreferencesUtil {
                        configurator.setDoSynonyms(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_SYNONYMS));\r
                        configurator.setDoNamesWithoutTaxa(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_NAMES));\r
                        configurator.setDoTaxaByCommonNames(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES));                  \r
-               }else{\r
-                       // create new preferences setting everything to true\r
-                       configurator.setDoTaxa(true);\r
-                       configurator.setDoSynonyms(true);\r
-                       configurator.setDoNamesWithoutTaxa(true);\r
-                       configurator.setDoTaxaByCommonNames(true);\r
-                       setSearchConfigurator(configurator);\r
                }\r
                \r
+               return configurator;\r
+       }\r
+       \r
+       /**\r
+        * create new preferences, setting all search options to true\r
+        * @return \r
+        */\r
+       public static ITaxonServiceConfigurator initializeSearchConfigurator(){\r
+               ITaxonServiceConfigurator configurator = TaxonServiceConfiguratorImpl.NewInstance();\r
+               \r
+               configurator.setDoTaxa(true);\r
+               configurator.setDoSynonyms(true);\r
+               configurator.setDoNamesWithoutTaxa(true);\r
+               configurator.setDoTaxaByCommonNames(true);\r
+               \r
+               setSearchConfigurator(configurator);\r
+               \r
                // DEFAULT VALUES               \r
                // match mode default only\r
                configurator.setMatchMode(MatchMode.BEGINNING);\r
index 1e2b48de526014a728a76d7f838622b7a07b8017..5d0bb14dc8893ef44396b7fc869879d1a04b69c8 100644 (file)
@@ -22,6 +22,7 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Text;
+import org.springframework.security.userdetails.UsernameNotFoundException;
 
 import eu.etaxonomy.cdm.model.agent.Person;
 import eu.etaxonomy.cdm.model.common.User;
@@ -52,7 +53,7 @@ public class UserWizardPage extends WizardPage implements ModifyListener{
        private Text text_userEmail;
 
        private IInputValidator uniqueUserNameValidator;
-       private IInputValidator passwordRepetitionEqualityValidator;
+       private PasswordValidator passwordValidator;
        
        /**
         * @param pageName
@@ -73,7 +74,7 @@ public class UserWizardPage extends WizardPage implements ModifyListener{
                }
 
                uniqueUserNameValidator = new UniqueUserNameValidator();
-               passwordRepetitionEqualityValidator = new PasswordRepetitionEqualityValidator();
+               passwordValidator = new PasswordValidator();
        }
 
        private static final Logger logger = Logger.getLogger(UserWizardPage.class);
@@ -102,7 +103,7 @@ public class UserWizardPage extends WizardPage implements ModifyListener{
                
                if(newMode){
                        createPasswordFieldsNew(composite);
-               }else if(CdmStore.getLoginManager().getAuthenticatedUser().equals(user)){
+               }else if(user.equals(CdmStore.getLoginManager().getAuthenticatedUser())){
                        createPasswordFieldsEdit(composite);
                }
 
@@ -135,9 +136,8 @@ public class UserWizardPage extends WizardPage implements ModifyListener{
                text_password.addModifyListener(this);
                
                new CLabel(parent, SWT.NULL);
-               text_passwordRepeat = new Text(parent, SWT.BORDER);
+               text_passwordRepeat = new Text(parent, SWT.PASSWORD | SWT.BORDER);
                text_passwordRepeat.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-               text_passwordRepeat.setEchoChar('*');
                text_passwordRepeat.addModifyListener(this);
        }
        
@@ -189,8 +189,9 @@ public class UserWizardPage extends WizardPage implements ModifyListener{
         */
        public void modifyText(ModifyEvent e) {
                if(newMode){
-                       user.setUsername(text_username.getText().trim());
+                       user.setUsername(text_username.getText().trim());                       
                        user.setPassword(text_password.getText());
+                       validate();
                }
                user.getPerson().setFirstname(text_personFirstName.getText());
                user.getPerson().setLastname(text_personLastName.getText());
@@ -204,30 +205,72 @@ public class UserWizardPage extends WizardPage implements ModifyListener{
                return user;
        }
        
+       private void validate(){
+               String message;
+               if((message = uniqueUserNameValidator.isValid(text_username.getText())) != null){
+                       // pass
+               }else if((message = passwordValidator.isValid(text_password.getText())) != null){
+                       // pass
+               }else if((message = passwordValidator.passwordsMatch(text_password.getText(), text_passwordRepeat.getText())) != null){
+                       // pass
+               }
+               
+               setErrorMessage(message);               
+       }
+       
        private class UniqueUserNameValidator implements IInputValidator{
 
-               private static final String MESSAGE = "Username already exists";
+               private static final String USER_EXISTS = "Username already exists";
+               private static final String NAME_TO_SHORT = "Username is empty";
                
                /* (non-Javadoc)
                 * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
                 */
                public String isValid(String newText) {
                        // query for username
-                       if( CdmStore.getUserService().loadUserByUsername(newText) != null){
-                               return MESSAGE;
+                       if(newText.length() < 1){
+                               setPageComplete(false);
+                               return NAME_TO_SHORT;
                        }
+                       try{
+                               CdmStore.getUserService().loadUserByUsername(newText);
+                               setPageComplete(false);
+                               return USER_EXISTS;
+                       }catch (UsernameNotFoundException e){}
                        
+                       setPageComplete(true);
                        return null;
                }
        }
        
-       private class PasswordRepetitionEqualityValidator implements IInputValidator{
+       private class PasswordValidator implements IInputValidator{
 
+               private static final int PW_MIN_LENGTH = 5;
+               
+               private static final String TO_SHORT = "Password has to have at least " + PW_MIN_LENGTH + " characters";
+               private static final String NO_MATCH = "The passwords do not match";
+               
                /* (non-Javadoc)
                 * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
                 */
                public String isValid(String newText) {
-                       // TODO Auto-generated method stub
+                       if(newText.length() < PW_MIN_LENGTH){
+                               setPageComplete(false);
+                               return TO_SHORT;
+                       }
+                       
+                       setPageComplete(true);
+                       return null;
+               }
+               
+               public String passwordsMatch(String password1, String password2){
+
+                       if(! password1.equals(password2)){
+                               setPageComplete(false);
+                               return NO_MATCH;
+                       }
+                       
+                       setPageComplete(true);
                        return null;
                }