Advertisement
psi_mmobile

Untitled

Jan 19th, 2021
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. public void duplicateSelectedUser() {
  2. AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
  3. DCIteratorBinding guiUsersIterator = ADFUtils.findIterator("GuiUsersView2Iterator");
  4. if (null != guiUsersIterator) {
  5. Row selectedUser = guiUsersIterator.getCurrentRow();
  6. if (null != selectedUser) {
  7. String procedureCopyUserSetting = "of_owner.p_gui_user.copy_settings(?,?)";
  8. String copyGuiUserSettings = "begin " + procedureCopyUserSetting + "; end;";
  9.  
  10. String procedureCopyGuiUser = "of_owner.p_gui_user.copy_gui_user(?,?,?)";
  11. String copyGuiUser = "begin " + procedureCopyGuiUser + "; end;";
  12.  
  13. String procedureCopyVoRights = "of_owner.p_gui_user.copy_vo_rights(?,?)";
  14. String copyVoRights = "begin " + procedureCopyVoRights + "; end;";
  15.  
  16. String procedureAddUserAccessRight = "of_owner.p_gui_user.add_user_right_access(?)";
  17. String addUserAccessRight = "begin " + procedureAddUserAccessRight + "; end;";
  18.  
  19. CallableStatement copyGuiUserSettingsStmt = am.getDBTransaction().createCallableStatement(copyGuiUserSettings, 0);
  20. CallableStatement copyGuiUserStmt = am.getDBTransaction().createCallableStatement(copyGuiUser, 0);
  21. CallableStatement copyVoRightsStmt = am.getDBTransaction().createCallableStatement(copyVoRights, 0);
  22. CallableStatement addUserAccessRightStmt = am.getDBTransaction().createCallableStatement(addUserAccessRight, 0);
  23.  
  24. Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone(UserBean.getCurrent().getUserTimeZone()));
  25. long timeInMillis = calendar.getTimeInMillis();
  26. String bufferUserName = String.valueOf(timeInMillis);
  27.  
  28. log.debug("Temp username is : " + bufferUserName);
  29.  
  30. Integer selectedGuiUserId = (Integer)selectedUser.getAttribute("GuiUserId");
  31. Integer selectedGuiUserOcId = (Integer)selectedUser.getAttribute("OperationCenterId");
  32.  
  33. try {
  34.  
  35. copyGuiUserStmt.setInt(1, selectedGuiUserId);
  36. copyGuiUserStmt.setInt(2, selectedGuiUserOcId);
  37. copyGuiUserStmt.setString(3, bufferUserName);
  38. copyGuiUserStmt.executeUpdate();
  39.  
  40. Integer newGuiUserId = null;
  41. String retrieveNewUserIdQuery = "select gui_user_id from gui_users where loginname='" + bufferUserName +"' and lm_name='copy_gui_user' and operation_center_id=" + selectedGuiUserOcId;
  42. ViewObject retrieveNewUser = am.createViewObjectFromQueryStmt("RetrieveNewUserIdView", retrieveNewUserIdQuery);
  43. retrieveNewUser.executeQuery();
  44.  
  45. Row newUserRow = retrieveNewUser.first();
  46. if (null == newUserRow) {
  47. return;
  48. } else {
  49. newGuiUserId = ((BigDecimal)newUserRow.getAttribute(0)).intValueExact();
  50. }
  51. retrieveNewUser.remove();
  52.  
  53. copyGuiUserSettingsStmt.setInt(1, (Integer)selectedUser.getAttribute("GuiUserId"));
  54. copyGuiUserSettingsStmt.setInt(2, newGuiUserId);
  55. copyGuiUserSettingsStmt.executeUpdate();
  56.  
  57. copyVoRightsStmt.setInt(1, selectedGuiUserId);
  58. copyVoRightsStmt.setInt(2, newGuiUserId);
  59. copyVoRightsStmt.executeUpdate();
  60.  
  61. addUserAccessRightStmt.setInt(1, newGuiUserId);
  62. addUserAccessRightStmt.executeUpdate();
  63. } catch (SQLException e) {
  64. log.error(e.getMessage(), e);
  65. } finally {
  66. if (copyGuiUserSettingsStmt != null) {
  67. try {
  68. copyGuiUserSettingsStmt.close();
  69. } catch (SQLException e) {
  70. log.error(e.getMessage(), e);
  71. }
  72. }
  73. if (copyGuiUserStmt != null) {
  74. try {
  75. copyGuiUserStmt.close();
  76. } catch (SQLException e) {
  77. log.error(e.getMessage(), e);
  78. }
  79. }
  80. if (copyVoRightsStmt != null) {
  81. try {
  82. copyVoRightsStmt.close();
  83. } catch (SQLException e) {
  84. log.error(e.getMessage(), e);
  85. }
  86. }
  87. if (addUserAccessRightStmt != null) {
  88. try {
  89. addUserAccessRightStmt.close();
  90. } catch (SQLException e) {
  91. log.error(e.getMessage(), e);
  92. }
  93. }
  94. }
  95. refreshUserList();
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement