From d4e81d47521226b3b877d4d4682e4837450d8d55 Mon Sep 17 00:00:00 2001 From: Bruno Sinou Date: Mon, 14 Sep 2015 13:42:23 +0000 Subject: [PATCH] Introduce commands to manage user transaction git-svn-id: https://svn.argeo.org/commons/trunk@8390 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../META-INF/spring/commands.xml | 20 +- .../META-INF/spring/editors.xml | 3 - .../META-INF/spring/osgi.xml | 5 +- .../META-INF/spring/views.xml | 7 - org.argeo.security.ui.admin/icons/begin.gif | Bin 0 -> 210 bytes org.argeo.security.ui.admin/icons/commit.gif | Bin 0 -> 583 bytes .../icons/rollback.gif | Bin 0 -> 376 bytes org.argeo.security.ui.admin/plugin.xml | 228 ++++++++---------- .../commands/UserTransactionHandler.java | 82 +++++++ .../security/ui/admin/editors/UserEditor.java | 10 +- .../security/ui/admin/views/UsersView.java | 12 +- 11 files changed, 204 insertions(+), 163 deletions(-) create mode 100755 org.argeo.security.ui.admin/icons/begin.gif create mode 100755 org.argeo.security.ui.admin/icons/commit.gif create mode 100755 org.argeo.security.ui.admin/icons/rollback.gif create mode 100644 org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/UserTransactionHandler.java diff --git a/org.argeo.security.ui.admin/META-INF/spring/commands.xml b/org.argeo.security.ui.admin/META-INF/spring/commands.xml index e83440376..24c0ac274 100644 --- a/org.argeo.security.ui.admin/META-INF/spring/commands.xml +++ b/org.argeo.security.ui.admin/META-INF/spring/commands.xml @@ -4,22 +4,13 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - - - @@ -29,4 +20,11 @@ /> --> + + + + + diff --git a/org.argeo.security.ui.admin/META-INF/spring/editors.xml b/org.argeo.security.ui.admin/META-INF/spring/editors.xml index 263cfccb4..e9cf5ac8d 100644 --- a/org.argeo.security.ui.admin/META-INF/spring/editors.xml +++ b/org.argeo.security.ui.admin/META-INF/spring/editors.xml @@ -15,7 +15,4 @@ - diff --git a/org.argeo.security.ui.admin/META-INF/spring/osgi.xml b/org.argeo.security.ui.admin/META-INF/spring/osgi.xml index 9d1d4645c..02a63748f 100644 --- a/org.argeo.security.ui.admin/META-INF/spring/osgi.xml +++ b/org.argeo.security.ui.admin/META-INF/spring/osgi.xml @@ -10,9 +10,8 @@ - - + + \ No newline at end of file diff --git a/org.argeo.security.ui.admin/META-INF/spring/views.xml b/org.argeo.security.ui.admin/META-INF/spring/views.xml index 6b0970e41..18a7b8881 100644 --- a/org.argeo.security.ui.admin/META-INF/spring/views.xml +++ b/org.argeo.security.ui.admin/META-INF/spring/views.xml @@ -14,11 +14,4 @@ scope="prototype"> - - - diff --git a/org.argeo.security.ui.admin/icons/begin.gif b/org.argeo.security.ui.admin/icons/begin.gif new file mode 100755 index 0000000000000000000000000000000000000000..feb8e94a74f14633174999f46b00c5fea61f11ce GIT binary patch literal 210 zcmZ?wbhEHb6krfwIKsd%uV?<8?j^0QTNqTcpPZj^a8=#!J?VcR?f-po_Dp~2nL$dk zql{)J+RjLEo}Cr&9}E~s0g69a7#V<8>3}qW>||i|S5WC&^1~)I%ZztbpMSDM&+22x z8g1h{UcG=1Rx&Cu+mXt$?wL-F5KlvW;h#Z9KDJ?WxWwYdfZ_ zU9j#{=hU^!HlOL3y0&}D()XW#HFZvT{QAeM55GQr{nbBn#l08bAHMqW`1SYa?|$5S z`Qz!^A76j`nKXOZy_etLeERYE`|qzme*gIOXZpNFrB$`F=g-e6$X~E{&Z2#}Q&vVT zT|V>AubZDfTwJws+P}Z=et+8j`|HsueL1@}cW>X=w|U*f4QnQS|8!~Fx{lv(R{egv zZts@v<@0NPKbgL_MQlTv(2hEhEmgw18%1|DitcU_TahcUrciKok>Hv_q1A;#%d!Pl z#j0_Ck3_2h;g5rdMeMy6NQ*%pelT}A&M_ap6U%z>ew-p2PG-ig0 zJw`H$iZTnVy=`qg43??4+mX*la4GamYaX=rL{kCS7^W zv-;;RoVRrF))GFXVPSLoj*VTDx}?rycUKQL_uKBxs?xk{?CjEN-d;8?Ey_Z_g(QSj syeFw>UU|sG#KJ8Q)1k1kiJezYr{cp0he=H=JTe9z6C4;9J1|%S0M7>4$N&HU literal 0 HcmV?d00001 diff --git a/org.argeo.security.ui.admin/icons/rollback.gif b/org.argeo.security.ui.admin/icons/rollback.gif new file mode 100755 index 0000000000000000000000000000000000000000..c75399599d43dfb24941415a96ae81de26f7bedf GIT binary patch literal 376 zcmZ?wbhEHb6krfwxN61_SGM@)iz!d89sB)q-oL-^uWYD(^y<{O!+%DO)~%{xx&{!XxwYk1r~^u%=@Brrwn+r)^j}@!;&7_~L1&mX@q- z4B9s%`^|@+KhMU0{r+Z^fx(PH z2c!h#CkD2u4zmj~s%7~27X{sLP*CeQcFAlur@|yJSEj&Nmcx;&O|AFXtT$N|Akd{L zQk3J@zvXE2pN2ODSIo^!n;02GjZO3!7z|aEolUv9P4%Ws)l(De=ixCmF%j-$kXP00 zXJlb9)mgnpO3B4|Ig2D?2ZOAFq6<^gUbg*gGU_g@O!JN(m(X_MG&* + - + - - - + - - - + + + - - + - + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + --> + + - - + - - - - - - - - \ No newline at end of file + + + + + + + + \ 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 index 000000000..158fae24d --- /dev/null +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/UserTransactionHandler.java @@ -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 diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/UserEditor.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/UserEditor.java index af6f5748e..485956b9a 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/UserEditor.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/UserEditor.java @@ -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 diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/views/UsersView.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/views/UsersView.java index 989b1975e..6604e6106 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/views/UsersView.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/views/UsersView.java @@ -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 { -- 2.30.2