taxeditor part of fix for #4121 (Changing password does not work)
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / password / PasswordWizard.java
index 552388243c882357d311c4ea9fe6bc39c2690549..8240bfe5279b9e27e47bb0e4033e0c1a2a95937f 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -30,46 +30,58 @@ import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 public class PasswordWizard extends Wizard implements IConversationEnabled{
 
        private PasswordWizardPage passwordPage;
-       private User user;
-       private ConversationHolder conversation;
-       
-       public PasswordWizard(ConversationHolder conversation, User user){
+       private final User user;
+       private final ConversationHolder conversation;
+
+       /**
+        * @param user the user to change the password for
+        * @param conversation this optional parameter can be null. Only supply conversation if you
+        * need to run this wizard is a nested conversation
+        */
+       public PasswordWizard(User user, ConversationHolder conversation){
                this.conversation = conversation;
                this.user = user;
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.jface.wizard.Wizard#addPages()
         */
        @Override
        public void addPages() {
                CdmFormFactory formFactory = new CdmFormFactory(Display.getDefault());
-               
+
                passwordPage = new PasswordWizardPage(formFactory, getConversationHolder(), user);
                addPage(passwordPage);
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.jface.wizard.Wizard#performFinish()
         */
        @Override
        public boolean performFinish() {
-               String userName = user.getUsername();
-               ConversationHolder internalConversation = CdmStore.getLoginManager().getConversationHolder();
-               internalConversation.bind();
+
+               ConversationHolder internalConversation = CdmStore.getCurrentApplicationConfiguration().NewConversation();
+           internalConversation.bind();
+           internalConversation.startTransaction();
                try{
-                       if(CdmStore.getLoginManager().isAdmin()){
-                               CdmStore.getService(IUserService.class).changePasswordForUser(userName, passwordPage.getNewPassword());
-                       }else{
+                       if(passwordPage.isChangingOwnPassword()){
+                           // change own password with validating of old one
                                CdmStore.getService(IUserService.class).changePassword(passwordPage.getOldPassword(), passwordPage.getNewPassword());
+                       }else{
+                           // change others passwords
+                           CdmStore.getService(IUserService.class).changePasswordForUser(user.getUsername(), passwordPage.getNewPassword());
                        }
-                       internalConversation.commit();
+                   internalConversation.commit(false);
+                   internalConversation.unbind();
+                   internalConversation.close();
                        return true;
                }catch(Exception e){
                        StoreUtil.errorDialog("Error while changing password", getClass(), "There was a problem changing the password.", e);
                        return false;
                }finally{
-                       conversation.bind();
+                   if(conversation != null){
+                       conversation.bind();
+                   }
                }
        }
 
@@ -79,7 +91,7 @@ public class PasswordWizard extends Wizard implements IConversationEnabled{
        @Override
        public void update(CdmDataChangeMap arg0) {
                // TODO Auto-generated method stub
-               
+
        }
 
        /* (non-Javadoc)