use of org.mifos.framework.exceptions.ValidationException in project head by mifos.
the class PersonnelServiceFacadeWebTier method createPersonnelInformation.
@Override
public UserDetailDto createPersonnelInformation(CreateOrUpdatePersonnelInformation personnel) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
try {
PersonnelBusinessService personnelBusinessService = new PersonnelBusinessService();
List<RoleBO> roles = new ArrayList<RoleBO>();
for (ListElement element : personnel.getRoles()) {
RoleBO role = personnelBusinessService.getRoleById(new Short(element.getId().shortValue()));
roles.add(role);
}
AddressDto addressDto = personnel.getAddress();
Address address = new Address(addressDto.getLine1(), addressDto.getLine2(), addressDto.getLine3(), addressDto.getCity(), addressDto.getState(), addressDto.getCountry(), addressDto.getZip(), addressDto.getPhoneNumber());
OfficeBO office = officeDao.findOfficeById(personnel.getOfficeId());
Name name = new Name(personnel.getFirstName(), personnel.getMiddleName(), personnel.getSecondLastName(), personnel.getLastName());
verifyFields(personnel.getUserName(), personnel.getGovernmentIdNumber(), personnel.getDob().toDate(), name.getDisplayName());
PersonnelBO newPersonnel = new PersonnelBO(PersonnelLevel.fromInt(personnel.getPersonnelLevelId().intValue()), office, personnel.getTitle(), personnel.getPreferredLocale(), personnel.getPassword(), personnel.getUserName(), personnel.getEmailId(), roles, personnel.getCustomFields(), name, personnel.getGovernmentIdNumber(), personnel.getDob().toDate(), personnel.getMaritalStatus(), personnel.getGender(), personnel.getDateOfJoiningMFI().toDate(), personnel.getDateOfJoiningBranch().toDate(), address, Integer.valueOf(user.getUserId()).shortValue(), personnel.getPasswordExpirationDate().toDate(), null);
transactionHelper.startTransaction();
this.personnelDao.save(newPersonnel);
transactionHelper.flushSession();
newPersonnel.generateGlobalPersonnelNum();
this.personnelDao.save(newPersonnel);
transactionHelper.commitTransaction();
return newPersonnel.toDto();
} catch (PersistenceException e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} catch (ValidationException e) {
transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e.getValues(), e);
} catch (ServiceException e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
transactionHelper.closeSession();
}
}
Aggregations