@RequestMapping(value = "/staffcreatenewusersubmit", method = RequestMethod.POST) public ModelAndView createUserSubmit( @ModelAttribute("form") UserForm userForm, BindingResult result) { log.debug("Entering...."); ModelAndView modelAndView = new ModelAndView("staffcreatenewuser"); boolean isSuccess = true; validateUserForm(userForm, result); if (userForm.getDateOfBirth() != null) { if (!AppUtil.isAValidDDMMYYYYDate(userForm.getDateOfBirth())) { log.error("Invalid date format " + userForm.getDateOfBirth()); isSuccess = false; result.addError( new ObjectError( "dateOfBirth", "Invalid dateOfBirth. Please use the format " + DATE_FORMAT)); } } if (isSuccess && !result.hasErrors()) { String tenantId = userForm.getTenantId(); Profile staffProfile = profileService.getProfileById(userForm.getStaffProfileId(), tenantId); if (staffProfile != null) { userForm.setStaffFirstName(staffProfile.getFirstName()); userForm.setStaffLastName(staffProfile.getLastName()); } // Create Profile String profileId = profileService.saveProfile(createProfile(userForm)); try { // Create Use Account loginService.CreateUser(createUser(userForm, profileId)); } catch (Exception e) { log.error("Error Creating User {} ", e); isSuccess = false; profileService.deleteProfile(profileId, tenantId); } if (isSuccess) { modelAndView.addObject( "successMessage", "User '" + userForm.getUserName() + "' successfully created !!!"); resetForm(userForm); } else { result.addError(new ObjectError("userAccount", "Error creating new user")); } } modelAndView.addObject("roleType", loadRoleMap()); modelAndView.addObject("form", userForm); log.debug("Existing.........."); return modelAndView; }
@RequestMapping(value = "/staffcreateaccount", method = RequestMethod.POST) public ModelAndView createAccountFormSubmit( @ModelAttribute("form") CreateAccountForm createAccountForm, BindingResult result) { log.debug("Entering - CreateAccountForm : {}", createAccountForm.toString()); ModelAndView modelAndView = new ModelAndView("staffcreateaccount"); boolean isSuccess = true; validate(createAccountForm, result); if (createAccountForm.getDateOfBirth() != null) { if (!AppUtil.isAValidDDMMYYYYDate(createAccountForm.getDateOfBirth())) { log.error("Invalid date format " + createAccountForm.getDateOfBirth()); isSuccess = false; result.addError( new ObjectError( "dateOfBirth", "Invalid dateOfBirth. Please use the format " + DATE_FORMAT)); } } if (isSuccess && !result.hasErrors()) { String tenantId = createAccountForm.getTenantId(); Profile staffProfile = profileService.getProfileById(createAccountForm.getStaffProfileId(), tenantId); if (staffProfile != null) { createAccountForm.setStaffFirstName(staffProfile.getFirstName()); createAccountForm.setStaffLastName(staffProfile.getLastName()); } // Create Profile String profileId = profileService.saveProfile(createProfile(createAccountForm)); String accountNo = null; try { // Create Use Account loginService.CreateUser(createUser(createAccountForm, profileId)); } catch (Exception e) { log.error("Error Creating User {} ", e); isSuccess = false; profileService.deleteProfile(profileId, tenantId); } try { // Create Account accountNo = accountService.saveAccount(createAccount(createAccountForm, profileId)); log.debug("Account No. " + accountNo); } catch (Exception e) { log.error("Error Creating Account {} ", e); isSuccess = false; loginService.deleteUser(createAccountForm.getUserName(), tenantId); profileService.deleteProfile(profileId, tenantId); } if (isSuccess) { modelAndView.addObject( "successMessage", "Account '" + accountNo + "' successfully created !!!"); resetForm(createAccountForm); } else { result.addError(new ObjectError("account", "Error Opening new account")); } } modelAndView.addObject("form", createAccountForm); modelAndView.addObject("accountTypeList", loadAccountTypeMap()); log.debug("Existing.........."); return modelAndView; }