Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void duplicateSelectedUser() {
- AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl");
- DCIteratorBinding guiUsersIterator = ADFUtils.findIterator("GuiUsersView2Iterator");
- if (null != guiUsersIterator) {
- Row selectedUser = guiUsersIterator.getCurrentRow();
- if (null != selectedUser) {
- String procedureCopyUserSetting = "of_owner.p_gui_user.copy_settings(?,?)";
- String copyGuiUserSettings = "begin " + procedureCopyUserSetting + "; end;";
- String procedureCopyGuiUser = "of_owner.p_gui_user.copy_gui_user(?,?,?)";
- String copyGuiUser = "begin " + procedureCopyGuiUser + "; end;";
- String procedureCopyVoRights = "of_owner.p_gui_user.copy_vo_rights(?,?)";
- String copyVoRights = "begin " + procedureCopyVoRights + "; end;";
- String procedureAddUserAccessRight = "of_owner.p_gui_user.add_user_right_access(?)";
- String addUserAccessRight = "begin " + procedureAddUserAccessRight + "; end;";
- CallableStatement copyGuiUserSettingsStmt = am.getDBTransaction().createCallableStatement(copyGuiUserSettings, 0);
- CallableStatement copyGuiUserStmt = am.getDBTransaction().createCallableStatement(copyGuiUser, 0);
- CallableStatement copyVoRightsStmt = am.getDBTransaction().createCallableStatement(copyVoRights, 0);
- CallableStatement addUserAccessRightStmt = am.getDBTransaction().createCallableStatement(addUserAccessRight, 0);
- Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone(UserBean.getCurrent().getUserTimeZone()));
- long timeInMillis = calendar.getTimeInMillis();
- String bufferUserName = String.valueOf(timeInMillis);
- log.debug("Temp username is : " + bufferUserName);
- Integer selectedGuiUserId = (Integer)selectedUser.getAttribute("GuiUserId");
- Integer selectedGuiUserOcId = (Integer)selectedUser.getAttribute("OperationCenterId");
- try {
- copyGuiUserStmt.setInt(1, selectedGuiUserId);
- copyGuiUserStmt.setInt(2, selectedGuiUserOcId);
- copyGuiUserStmt.setString(3, bufferUserName);
- copyGuiUserStmt.executeUpdate();
- Integer newGuiUserId = null;
- String retrieveNewUserIdQuery = "select gui_user_id from gui_users where loginname='" + bufferUserName +"' and lm_name='copy_gui_user' and operation_center_id=" + selectedGuiUserOcId;
- ViewObject retrieveNewUser = am.createViewObjectFromQueryStmt("RetrieveNewUserIdView", retrieveNewUserIdQuery);
- retrieveNewUser.executeQuery();
- Row newUserRow = retrieveNewUser.first();
- if (null == newUserRow) {
- return;
- } else {
- newGuiUserId = ((BigDecimal)newUserRow.getAttribute(0)).intValueExact();
- }
- retrieveNewUser.remove();
- copyGuiUserSettingsStmt.setInt(1, (Integer)selectedUser.getAttribute("GuiUserId"));
- copyGuiUserSettingsStmt.setInt(2, newGuiUserId);
- copyGuiUserSettingsStmt.executeUpdate();
- copyVoRightsStmt.setInt(1, selectedGuiUserId);
- copyVoRightsStmt.setInt(2, newGuiUserId);
- copyVoRightsStmt.executeUpdate();
- addUserAccessRightStmt.setInt(1, newGuiUserId);
- addUserAccessRightStmt.executeUpdate();
- } catch (SQLException e) {
- log.error(e.getMessage(), e);
- } finally {
- if (copyGuiUserSettingsStmt != null) {
- try {
- copyGuiUserSettingsStmt.close();
- } catch (SQLException e) {
- log.error(e.getMessage(), e);
- }
- }
- if (copyGuiUserStmt != null) {
- try {
- copyGuiUserStmt.close();
- } catch (SQLException e) {
- log.error(e.getMessage(), e);
- }
- }
- if (copyVoRightsStmt != null) {
- try {
- copyVoRightsStmt.close();
- } catch (SQLException e) {
- log.error(e.getMessage(), e);
- }
- }
- if (addUserAccessRightStmt != null) {
- try {
- addUserAccessRightStmt.close();
- } catch (SQLException e) {
- log.error(e.getMessage(), e);
- }
- }
- }
- refreshUserList();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement