account.setType(AccountType.valueOf(interestPlan));
/* The customerId is empty, which means we must create the Customer */
if (customerId.isEmpty())
{
final Person customer = (Person) request.getSession().getAttribute("customer");
PasswordGenerator generator = Generator.newPasswordGenerator(8, true, true, true, true);
try {
final String password = generator.generate();
HashFunction hf = Hashing.sha1();
HashCode hc = hf.newHasher()
.putString(password)
.hash();
customer.setPassword(hc.toString());
customer.addAccount(account);
customerService.processCustomer(customer, password);
response.sendRedirect(getServletContext().getContextPath() +
String.format("/auth/admin/customer?id=%d", customer.getId()));
} catch (GenerationException ex) {
}
}
else
{
try {
final Long id = Long.parseLong(customerId);
final Person customer = customerDao.findCustomerById(id);
if (customer != null) {
customer.addAccount(account);
accountDao.addAccount(account);
response.sendRedirect(getServletContext().getContextPath() +
String.format("/auth/admin/customer?id=%d", id));
}
else