use of org.mifos.dto.screen.ListElement in project head by mifos.
the class PersonAction method update.
@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
PersonActionForm actionForm = (PersonActionForm) form;
try {
CreateOrUpdatePersonnelInformation perosonnelInfo = translateFormToCreatePersonnelInformationDto(request, actionForm);
UserDetailDto userDetails = this.personnelServiceFacade.updatePersonnel(perosonnelInfo);
String globalPersonnelNum = userDetails.getSystemId();
Name name = new Name(actionForm.getFirstName(), actionForm.getMiddleName(), actionForm.getSecondLastName(), actionForm.getLastName());
request.setAttribute("displayName", name.getDisplayName());
request.setAttribute("globalPersonnelNum", globalPersonnelNum);
//refresh user context roles if active
Set<Short> roles = new HashSet<Short>();
for (ListElement userNewRole : perosonnelInfo.getRoles()) {
roles.add(userNewRole.getId().shortValue());
}
refreshUserContextIfActive(request, perosonnelInfo.getId(), perosonnelInfo.getUserName(), roles);
return mapping.findForward(ActionForwards.update_success.toString());
} catch (BusinessRuleException e) {
throw new PersonnelException(e.getMessageKey(), e.getMessageValues());
}
}
use of org.mifos.dto.screen.ListElement in project head by mifos.
the class OfficeServiceFacadeWebTier method createOffice.
@Override
public ListElement createOffice(Short operationMode, OfficeDto officeDto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
OfficeLevel level = OfficeLevel.getOfficeLevel(officeDto.getLevelId());
OfficeBO parentOffice = officeDao.findOfficeById(officeDto.getParentId());
AddressDto addressDto = officeDto.getAddress();
Address address = new Address(addressDto.getLine1(), addressDto.getLine2(), addressDto.getLine3(), addressDto.getCity(), addressDto.getState(), addressDto.getCountry(), addressDto.getZip(), addressDto.getPhoneNumber());
try {
OfficeBO officeBO = new OfficeBO(userContext, level, parentOffice, officeDto.getCustomFields(), officeDto.getName(), officeDto.getOfficeShortName(), address, OperationMode.fromInt(operationMode.intValue()));
OfficePersistence officePersistence = new OfficePersistence();
if (officePersistence.isOfficeNameExist(officeDto.getName())) {
throw new OfficeValidationException(OfficeConstants.OFFICENAMEEXIST);
}
if (officePersistence.isOfficeShortNameExist(officeDto.getOfficeShortName())) {
throw new OfficeValidationException(OfficeConstants.OFFICESHORTNAMEEXIST);
}
String searchId = generateSearchId(parentOffice);
officeBO.setSearchId(searchId);
String globalOfficeNum = generateOfficeGlobalNo();
officeBO.setGlobalOfficeNum(globalOfficeNum);
StaticHibernateUtil.startTransaction();
this.officeDao.save(officeBO);
StaticHibernateUtil.commitTransaction();
//Shahid - this is hackish solution to return officeId and globalOfficeNum via ListElement, it should be fixed, at least
//a proper data storage class can be created
ListElement element = new ListElement(new Integer(officeBO.getOfficeId()), officeBO.getGlobalOfficeNum());
// if we are here it means office created sucessfully
// we need to update hierarchy manager cache
OfficeSearch os = new OfficeSearch(officeBO.getOfficeId(), officeBO.getSearchId(), officeBO.getParentOffice().getOfficeId());
List<OfficeSearch> osList = new ArrayList<OfficeSearch>();
osList.add(os);
EventManger.postEvent(Constants.CREATE, osList, SecurityConstants.OFFICECHANGEEVENT);
return element;
} catch (OfficeValidationException e) {
StaticHibernateUtil.rollbackTransaction();
throw new BusinessRuleException(e.getMessage());
} catch (PersistenceException e) {
StaticHibernateUtil.rollbackTransaction();
throw new MifosRuntimeException(e);
} catch (OfficeException e) {
StaticHibernateUtil.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} finally {
StaticHibernateUtil.closeSession();
}
}
use of org.mifos.dto.screen.ListElement in project head by mifos.
the class PersonnelServiceFacadeWebTier method retrieveInfoForNewUserDefinition.
@Override
public DefinePersonnelDto retrieveInfoForNewUserDefinition(Short officeId) {
String officeName = "";
if (officeId != null) {
OfficeBO office = officeDao.findOfficeById(officeId);
officeName = office.getOfficeName();
}
List<ValueListElement> titles = customerDao.retrieveTitles();
List<ListElement> titleList = new ArrayList<ListElement>();
for (ValueListElement element : titles) {
ListElement listElement = new ListElement(element.getId(), element.getName());
titleList.add(listElement);
}
List<PersonnelLevelEntity> personnelLevels = customerDao.retrievePersonnelLevels();
List<ListElement> personnelLevelList = new ArrayList<ListElement>();
for (PersonnelLevelEntity level : personnelLevels) {
String name = level.getLookUpValue().getLookUpName();
String localisedName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(name);
ListElement listElement = new ListElement(new Integer(level.getId()), localisedName);
personnelLevelList.add(listElement);
}
List<ValueListElement> genders = customerDao.retrieveGenders();
List<ListElement> genderList = new ArrayList<ListElement>();
for (ValueListElement element : genders) {
ListElement listElement = new ListElement(element.getId(), element.getName());
genderList.add(listElement);
}
List<ValueListElement> maritalStatuses = customerDao.retrieveMaritalStatuses();
List<ListElement> maritalStatusList = new ArrayList<ListElement>();
for (ValueListElement element : maritalStatuses) {
ListElement listElement = new ListElement(element.getId(), element.getName());
maritalStatusList.add(listElement);
}
List<RoleBO> roles = new ArrayList<RoleBO>();
try {
roles = rolesPermissionsPersistence.getRoles();
} catch (PersistenceException e) {
throw new MifosRuntimeException(e);
}
List<ListElement> roleList = new ArrayList<ListElement>();
for (RoleBO element : roles) {
ListElement listElement = new ListElement(new Integer(element.getId()), element.getName());
roleList.add(listElement);
}
List<ListElement> languageList = Localization.getInstance().getLocaleList();
DefinePersonnelDto defineUserDto = new DefinePersonnelDto(officeName, titleList, personnelLevelList, genderList, maritalStatusList, languageList, roleList);
return defineUserDto;
}
use of org.mifos.dto.screen.ListElement 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();
}
}
use of org.mifos.dto.screen.ListElement in project head by mifos.
the class RolesPermissionServiceFacadeWebTier method retrieveAllRoles.
@Override
public List<ListElement> retrieveAllRoles() {
try {
List<RoleBO> roles = new RolesPermissionsBusinessService().getRoles();
if (!roles.isEmpty()) {
List<ListElement> roleList = new ArrayList<ListElement>();
for (RoleBO role : roles) {
ListElement element = new ListElement(new Integer(role.getId()), role.getName());
roleList.add(element);
}
return roleList;
}
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
}
return null;
}
Aggregations