Introduce commands to manage user transaction
authorBruno Sinou <bsinou@argeo.org>
Mon, 14 Sep 2015 13:42:23 +0000 (13:42 +0000)
committerBruno Sinou <bsinou@argeo.org>
Mon, 14 Sep 2015 13:42:23 +0000 (13:42 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@8390 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.security.ui.admin/META-INF/spring/commands.xml
org.argeo.security.ui.admin/META-INF/spring/editors.xml
org.argeo.security.ui.admin/META-INF/spring/osgi.xml
org.argeo.security.ui.admin/META-INF/spring/views.xml
org.argeo.security.ui.admin/icons/begin.gif [new file with mode: 0755]
org.argeo.security.ui.admin/icons/commit.gif [new file with mode: 0755]
org.argeo.security.ui.admin/icons/rollback.gif [new file with mode: 0755]
org.argeo.security.ui.admin/plugin.xml
org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/UserTransactionHandler.java [new file with mode: 0644]
org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/UserEditor.java
org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/views/UsersView.java

index e83440376b2bdc22dd7ec6b7009aaa1ff4a4510b..24c0ac274a719c0130a5a4cdc8197e845093f495 100644 (file)
@@ -4,22 +4,13 @@
        xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd">
 
-       <!-- <bean id="openArgeoUserEditor" class="org.argeo.security.ui.admin.commands.OpenArgeoUserEditor" 
-               scope="prototype" /> -->
-
        <!-- USERS -->
        <bean id="newUser" class="org.argeo.security.ui.admin.commands.NewUser"
                scope="prototype">
                <property name="userAdmin" ref="userAdmin" />
        </bean>
-       <!-- <bean id="newUser" class="org.argeo.security.ui.admin.commands.NewUser" 
-               scope="prototype"> <property name="repository" ref="nodeRepository" /> <property 
-               name="userAdminService" ref="userAdminService" /> </bean> <bean id="refreshUsersList" 
-               class="org.argeo.security.ui.admin.commands.RefreshUsersList" scope="prototype"> 
-               <property name="userAdminService" ref="userAdminService" /> <property name="repository" 
-               ref="nodeRepository" /> </bean> <bean id="deleteUser" class="org.argeo.security.ui.admin.commands.DeleteUser" 
-               scope="prototype"> <property name="userAdminService" ref="userAdminService" 
-               /> </bean> <bean id="userBatchUpdate" class="org.argeo.security.ui.admin.commands.UserBatchUpdate" 
+
+       <!-- <bean id="userBatchUpdate" class="org.argeo.security.ui.admin.commands.UserBatchUpdate" 
                scope="prototype"> <property name="repository" ref="nodeRepository" /> <property 
                name="userAdminService" ref="userAdminService" /> </bean> -->
        <!-- ROLES -->
                /> </bean> <bean id="deleteRole" class="org.argeo.security.ui.admin.commands.DeleteRole" 
                scope="prototype"> <property name="userAdminService" ref="userAdminService" 
                /> </bean> -->
+
+       <!-- TRANSACTIONS -->
+       <bean id="userTransactionHandler"
+               class="org.argeo.security.ui.admin.commands.UserTransactionHandler"
+               scope="prototype">
+               <property name="userTransaction" ref="userTransaction" />
+       </bean>
 </beans>
index 263cfccb4cae787b57fe905588d48adaefffaea9..e9cf5ac8d94052c5ee4fa7143447aa825de21164 100644 (file)
@@ -15,7 +15,4 @@
        <!-- <bean id="groupEditor" class="org.argeo.security.ui.admin.editors.GroupEditor" 
                scope="prototype"> <property name="userAdmin" ref="userAdmin" /> </bean> -->
        <!-- LEGACY -->
-       <!-- <bean id="adminArgeoUserEditor" class="org.argeo.security.ui.admin.editors.JcrArgeoUserEditor" 
-               scope="prototype"> <property name="userAdminService" ref="userAdminService" 
-               /> <property name="repository" ref="nodeRepository" /> </bean> -->
 </beans>
index 9d1d4645c66f20cef8f413e0b05a61c6e5c3e9e1..02a63748f8d81c717b4b0462c54c9aabdee6593b 100644 (file)
@@ -10,9 +10,8 @@
 \r
        <reference id="nodeRepository" interface="javax.jcr.Repository"\r
                filter="(argeo.jcr.repository.alias=node)" />\r
-       <!-- <reference id="userAdminService" interface="org.argeo.security.UserAdminService" \r
-               /> -->\r
-       <!-- new useradmin -->\r
+               \r
+       <!-- New user admin -->\r
        <reference id="userAdmin" interface="org.osgi.service.useradmin.UserAdmin" />\r
        <reference id="userTransaction" interface="javax.transaction.UserTransaction" />\r
 </beans:beans>
\ No newline at end of file
index 6b0970e414323d1c4f6de3fd1152e0b00aa627a6..18a7b888141410f3cc60d7f0af23e972ff84a57b 100644 (file)
                scope="prototype">
                <property name="userAdmin" ref="userAdmin" />
        </bean>
-
-       <!-- LEGACY. TODO: Remove -->
-       <!-- <bean id="jcrUsersView" class="org.argeo.security.ui.admin.views.JcrUsersView" 
-               scope="prototype"> <property name="repository" ref="nodeRepository" /> </bean> 
-               <bean id="adminRolesView" class="org.argeo.security.ui.admin.views.RolesView" 
-               scope="prototype"> <property name="userAdminService" ref="userAdminService" 
-               /> </bean> -->
 </beans>
diff --git a/org.argeo.security.ui.admin/icons/begin.gif b/org.argeo.security.ui.admin/icons/begin.gif
new file mode 100755 (executable)
index 0000000..feb8e94
Binary files /dev/null and b/org.argeo.security.ui.admin/icons/begin.gif differ
diff --git a/org.argeo.security.ui.admin/icons/commit.gif b/org.argeo.security.ui.admin/icons/commit.gif
new file mode 100755 (executable)
index 0000000..876f3eb
Binary files /dev/null and b/org.argeo.security.ui.admin/icons/commit.gif differ
diff --git a/org.argeo.security.ui.admin/icons/rollback.gif b/org.argeo.security.ui.admin/icons/rollback.gif
new file mode 100755 (executable)
index 0000000..c753995
Binary files /dev/null and b/org.argeo.security.ui.admin/icons/rollback.gif differ
index b8ad0300024b8ec28ca15fff96f9b5bff22ccdd9..6bdfd6d8b4b8e923a44f42749fd57e3ab3158818 100644 (file)
@@ -11,6 +11,7 @@
       </perspective>
    </extension>
    
+   <!-- VIEWS -->
    <extension
                point="org.eclipse.ui.views">
       <view
@@ -29,7 +30,7 @@
       </view>
     </extension> 
        
-       <!-- Editors -->
+       <!-- EDITORS -->
        <extension
                point="org.eclipse.ui.editors">
                <editor
             icon="icons/user.gif"
             default="false">
                </editor>
-               <!-- Legacy -->
-               <!--<editor
-                       class="org.argeo.eclipse.spring.SpringExtensionFactory"
-            id="org.argeo.security.ui.admin.adminArgeoUserEditor"
-            name="User"
-            icon="icons/user.gif"
-                       default="false">
-               </editor> -->
        </extension>
     
     <extension
          point="org.eclipse.ui.commands">
-       <command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+               <!-- User CRUD -->
+               <command
             id="org.argeo.security.ui.admin.newUser"
+            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
             name="New User">
        </command>
-      <command
-            defaultHandler="org.argeo.security.ui.admin.commands.DeleteUsers"
-            id="org.argeo.security.ui.admin.deleteUsers"
-            name="Delete User">
-      </command>
-      <command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.admin.newGroup"
+               <command
+                       id="org.argeo.security.ui.admin.deleteUsers"
+                       defaultHandler="org.argeo.security.ui.admin.commands.DeleteUsers"
+                       name="Delete User">
+               </command>
+               <!-- Group CRUD -->
+               <command
+                       id="org.argeo.security.ui.admin.newGroup"
+                       defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
             name="New Group">
-      </command>
-      <command
-            defaultHandler="org.argeo.security.ui.admin.commands.DeleteGroups"
+               </command>
+               <command
             id="org.argeo.security.ui.admin.deleteGroups"
+            defaultHandler="org.argeo.security.ui.admin.commands.DeleteGroups"
             name="Delete Group">
-      </command>
+               </command>
+               <!-- Transaction -->
+               <command
+                   id="org.argeo.security.ui.admin.userTransactionHandler"
+            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+               name="Manage a user transaction">
+                       <commandParameter
+                                       id="param.commandId"
+                                       name="begin, commit or rollback">
+                       </commandParameter>
+               </command>
 
          <!-- Force the refresh when the various listener are not enough -->
       <command
             id="org.argeo.security.ui.admin.forceRefresh"
             name="Force Refresh">
       </command>
-      <!--<command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.admin.openArgeoUserEditor"
-            name="OpenArgeoUserEditor">
-                       <commandParameter
-                       id="org.argeo.security.ui.admin.username"
-                       name="Username">
-                       </commandParameter>
-      </command>
-      <command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.admin.refreshUsersList"
-            name="refreshUsersList">
-      </command>
-      <command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.admin.newUser"
-            name="New User">
-      </command>
-      <command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.admin.deleteUser"
-            name="deleteUser">
-      </command>
-      <command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.admin.refreshRoles"
-            name="refreshRoles">
-      </command>
-      <command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.admin.addRole"
-            name="AddRole">
-      </command>
-      <command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.admin.deleteRole"
-            name="deleteRole">
-      </command>
+      <!-- 
       <command
             defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
             id="org.argeo.security.ui.admin.userBatchUpdate"
             name="User batch update">
       </command> -->
-    </extension>
-     <extension
-         point="org.eclipse.ui.menus">
-         <menuContribution
+       </extension>
+       
+       <!-- MENU CONTRIBUTIONS -->
+       <extension
+               point="org.eclipse.ui.menus">
+               <menuContribution
+                       locationURI="toolbar:org.argeo.security.ui.rap.userToolbar?after=org.eclipse.ui.file.saveAll"> 
+                       <!-- Transaction management --> 
+                       <command
+                               commandId="org.argeo.security.ui.admin.userTransactionHandler"
+                               icon="icons/begin.gif"
+                               label="Begin Transaction"
+                               style="push"
+                               tooltip="Begin a user transaction">
+<!--                           <visibleWhen>
+                                       <and>
+                                               <with variable="activePart">
+                                                       <instanceof value="org.argeo.cms.CmsEditable" />
+                                               </with>
+                                               <with variable="org.argeo.connect.people.rap.editingState">
+                                                       <equals value="notEditing" />
+                                               </with> -->
+                                               <!-- FIXME : never true, the role condition does not work -->
+                                               <!-- <with variable="roles">
+                                               <iterate ifEmpty="false" operator="or">
+                                                       <equals value="ROLE_BUSINESS_ADMIN" />
+                                               </iterate>
+                                       </with> -->
+<!--                           </and>
+                               </visibleWhen> -->
+                               <parameter name="param.commandId" value="transaction.begin" />
+                       </command>
+                       <command
+                               commandId="org.argeo.security.ui.admin.userTransactionHandler"
+                               icon="icons/commit.gif"
+                               label="Commit Transaction"
+                               style="push"
+                               tooltip="Commit a user transaction">
+                               <parameter name="param.commandId" value="transaction.commit" />
+                       </command>
+                       <command
+                               commandId="org.argeo.security.ui.admin.userTransactionHandler"
+                               icon="icons/rollback.gif"
+                               label="Rollback Transaction"
+                               style="push"
+                               tooltip="Abandon current changes and rollback to the latest commited version">
+                               <parameter name="param.commandId" value="transaction.rollback" />
+                       </command>
+               </menuContribution>
+    
+       <!-- UsersView specific toolbar menu -->
+               <menuContribution
             locationURI="toolbar:org.argeo.security.ui.admin.usersView">
             <command
                   commandId="org.argeo.security.ui.admin.deleteUsers"
                   tooltip="Perform maintenance activities on a list of chosen users">
             </command>-->
         </menuContribution>
+
+       <!-- GroupsView specific toolbar menu -->
         <menuContribution
             locationURI="toolbar:org.argeo.security.ui.admin.groupsView">
             <command
             </command>
         </menuContribution>
          
-<!--           <menuContribution
+               <!--            <menuContribution
             locationURI="toolbar:org.argeo.security.ui.admin.adminRolesView">
-            <command
-                  commandId="org.argeo.security.ui.admin.deleteRole"
-                  icon="icons/remove.gif"
-                  label="Delete Role"
-                  tooltip="Delete selected roles">
-            </command>
-            <command
-                  commandId="org.argeo.security.ui.admin.addRole"
-                  icon="icons/add.gif"
-                  label="Add Role"
-                  tooltip="Add new role">
-            </command>
             <command
                   commandId="org.argeo.security.ui.admin.refreshRoles"
                   icon="icons/sync.gif"
                   label="LDAP Roles Sync"
                   tooltip="Synchronize roles from LDAP">
             </command>
-        </menuContribution>
-       <menuContribution
-            locationURI="toolbar:org.argeo.security.ui.admin.adminUsersView">
-            <command
-                  commandId="org.argeo.security.ui.admin.refreshUsersList"
-                  icon="icons/refresh.png"
-                  label="Refresh list"
-                  tooltip="Force the full refresh of the user list">
-            </command>
-            <command
-                  commandId="org.argeo.security.ui.admin.deleteUser"
-                  icon="icons/remove.gif"
-                  label="Delete User"
-                  tooltip="Delete selected users">
-            </command>
-            <command
-                  commandId="org.argeo.security.ui.admin.newUser"
-                  icon="icons/add.gif"
-                  label="Add User"
-                  tooltip="Add new user">
-            </command>
-            <command
-                  commandId="org.argeo.security.ui.admin.userBatchUpdate"
-                  icon="icons/batch.gif"
-                  label="Update users"
-                  tooltip="Perform maintenance activities on a list of chosen users">
-            </command>
-            <command
-                  commandId="org.argeo.security.ui.admin.refreshUsersList"
-                  icon="icons/sync.gif"
-                  label="LDAP Users Sync"
-                  tooltip="Synchronize users from LDAP">
-            </command>
         </menuContribution> -->
-  </extension>
+       </extension>
   
-  <extension
-           point="org.eclipse.ui.activities">
-       <activityPatternBinding
-              activityId="org.argeo.security.ui.userAdminActivity"
-              isEqualityPattern="true"
-              pattern="org.argeo.security.ui.admin/org.argeo.security.ui.admin.adminSecurityPerspective">
-        </activityPatternBinding>
-        <activityPatternBinding
-              activityId="org.argeo.security.ui.groupAdminActivity"
-              isEqualityPattern="true"
-              pattern="org.argeo.security.ui.admin/org.argeo.security.ui.admin.adminRolesView">
-        </activityPatternBinding>
-     </extension>
- </plugin>
\ No newline at end of file
+       <!-- ACTIVITIES -->
+       <extension
+               point="org.eclipse.ui.activities">
+               <activityPatternBinding
+                       activityId="org.argeo.security.ui.userAdminActivity"
+                       isEqualityPattern="true"
+                       pattern="org.argeo.security.ui.admin/org.argeo.security.ui.admin.adminSecurityPerspective">
+               </activityPatternBinding>
+               <activityPatternBinding
+                       activityId="org.argeo.security.ui.groupAdminActivity"
+                       isEqualityPattern="true"
+                       pattern="org.argeo.security.ui.admin/org.argeo.security.ui.admin.adminRolesView">
+               </activityPatternBinding>
+       </extension>
+</plugin>
\ No newline at end of file
diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/UserTransactionHandler.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/UserTransactionHandler.java
new file mode 100644 (file)
index 0000000..158fae2
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.security.ui.admin.commands;
+
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+
+import org.argeo.ArgeoException;
+import org.argeo.security.ui.admin.SecurityAdminPlugin;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+
+/** Manage the transaction that is bound to the current perspective */
+public class UserTransactionHandler extends AbstractHandler {
+       public final static String ID = SecurityAdminPlugin.PLUGIN_ID
+                       + ".userTransactionHandler";
+
+       public final static String PARAM_COMMAND_ID = "param.commandId";
+
+       public final static String TRANSACTION_BEGIN = "transaction.begin";
+       public final static String TRANSACTION_COMMIT = "transaction.commit";
+       public final static String TRANSACTION_ROLLBACK = "transaction.rollback";
+
+       private UserTransaction userTransaction;
+
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+
+               String commandId = event.getParameter(PARAM_COMMAND_ID);
+               try {
+                       if (TRANSACTION_BEGIN.equals(commandId)) {
+                               if (userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION)
+                                       throw new ArgeoException("A transaction already exists");
+                               else
+                                       userTransaction.begin();
+                       } else if (TRANSACTION_COMMIT.equals(commandId)) {
+                               if (userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION)
+                                       throw new ArgeoException("No transaction.");
+                               else
+                                       userTransaction.commit();
+                       } else if (TRANSACTION_ROLLBACK.equals(commandId)) {
+                               if (userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION)
+                                       throw new ArgeoException("No transaction to rollback.");
+                               else
+                                       userTransaction.rollback();
+                       }
+               } catch (ArgeoException e) {
+                       throw e;
+               } catch (Exception e) {
+                       throw new ArgeoException("Unable to call " + commandId + " on "
+                                       + userTransaction, e);
+               }
+               //
+               // IWorkbenchWindow iww = HandlerUtil.getActiveWorkbenchWindow(event);
+               // if (iww == null)
+               // return null;
+               // IWorkbenchPage activePage = iww.getActivePage();
+               // IWorkbenchPart part = activePage.getActivePart();
+               // if (part instanceof UsersView)
+               // ((UsersView) part).refresh();
+               // else if (part instanceof GroupsView)
+               // ((GroupsView) part).refresh();
+               return null;
+       }
+
+       public void setUserTransaction(UserTransaction userTransaction) {
+               this.userTransaction = userTransaction;
+       }
+}
\ No newline at end of file
index af6f5748e84a6c59c9d779bde6a23f852e28decd..485956b9a3cb504f046cb6c278992e6e8be8d8d3 100644 (file)
@@ -120,11 +120,11 @@ public class UserEditor extends FormEditor implements UserAdminConstants {
                commitPages(true);
                firePropertyChange(PROP_DIRTY);
                // FIXME transaction should be managed at a higher level
-               try {
-                       userTransaction.commit();
-               } catch (Exception e) {
-                       throw new ArgeoException("Could not save user editor", e);
-               }
+               // try {
+               // userTransaction.commit();
+               // } catch (Exception e) {
+               // throw new ArgeoException("Could not save user editor", e);
+               // }
        }
 
        @Override
index 989b1975e84278b8cb8bab0aac3dd8225fda0063..6604e61061421e6d2f07df6a36d30b9e8b70ede2 100644 (file)
@@ -82,12 +82,12 @@ public class UsersView extends ViewPart implements ArgeoNames {
                // Really?
                userTableViewerCmp.refresh();
 
-               try {
-                       if (userTransaction != null)
-                               userTransaction.begin();
-               } catch (Exception e) {
-                       throw new ArgeoException("Cannot begin transaction", e);
-               }
+//             try {
+//                     if (userTransaction != null)
+//                             userTransaction.begin();
+//             } catch (Exception e) {
+//                     throw new ArgeoException("Cannot begin transaction", e);
+//             }
        }
 
        private class MyUserTableViewer extends UserTableViewer {