public FormSubmission processAddEmployeeRequest() {
l.info("Processing registration request from session "+req.getSession().getId());
RegistrationForm add = getRegistrationRequest();
if (!add.isValid()) {
l.info("registration form error in session "+req.getSession().getId());
add.setResultView(getAdminAddEmployeeView(null));
}
else if (service.employeeExists(add.getEmail())) {
l.info("employee exists "+req.getSession().getId());
add.setResultView(getAdminAddEmployeeView("An account for"+add.getEmail()+" already exists"));
}
else {
l.info("registration form check OK "+req.getSession().getId());
View rv = new View(getAdminHomeView());
Employee e = null;
try {
String ssn = Utilities.padStringToLength(Math.abs(new Random().nextInt())+"", "0", 9, false);
e = service.registerEmployee(add.getFirstName(), add.getLastName(), add.getEmail(), add.getPw(), new Long(1), "foo", ssn, "Employee", new Date(new java.util.Date().getTime()), "A1", new Double(100000));
RoleService rs = new RoleService();
Role role = rs.getById(new Integer(add.getRoleId()));
EmployeeRoles er = new EmployeeRoles(new Date(new java.util.Date().getTime()), e, role);
EmployeeRolesService ers = new EmployeeRolesService();
ers.store(er);
rv.setMessage("Employee addition Complete");
add.setResultMessage("Employee successfull added");
} catch (Exception e1) {
if (e != null) {
service.remove(e);
}
l.log(Level.WARNING, "", e1);
rv.setError(true);
rv = getAdminAddEmployeeView("An error occured.");
add.setResultMessage("Unable to process request");
}
add.setResultView(rv);
}
return add;
}