use of org.mifos.customers.office.persistence.OfficePersistence in project head by mifos.
the class OfficeServiceFacadeWebTier method retrieveOfficeFormInformation.
@Override
public OfficeFormDto retrieveOfficeFormInformation(Short officeLevelId) {
try {
List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
OfficeLevel officeLevel = OfficeLevel.HEADOFFICE;
if (officeLevelId != null) {
officeLevel = OfficeLevel.getOfficeLevel(officeLevelId);
}
List<OfficeDto> parents = this.officeDao.findActiveParents(officeLevel);
for (OfficeDto office : parents) {
String levelName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(office.getLookupNameKey());
office.setLevelName(levelName);
}
List<OfficeDetailsDto> officeLevels = new OfficePersistence().getActiveLevels();
for (OfficeDetailsDto officeDetailsDto : officeLevels) {
String levelName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(officeDetailsDto.getLevelNameKey());
officeDetailsDto.setLevelName(levelName);
}
return new OfficeFormDto(customFields, parents, officeLevels);
} catch (PersistenceException e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.customers.office.persistence.OfficePersistence in project head by mifos.
the class OfficeServiceFacadeWebTier method generateOfficeGlobalNo.
private String generateOfficeGlobalNo() throws OfficeException {
try {
/*
* TODO: Why not auto-increment? Fetching the max and adding one would seem to have a race condition.
*/
String officeGlobelNo = String.valueOf(new OfficePersistence().getMaxOfficeId().intValue() + 1);
if (officeGlobelNo.length() > 4) {
throw new OfficeException(OfficeConstants.MAXOFFICELIMITREACHED);
}
StringBuilder temp = new StringBuilder("");
for (int i = officeGlobelNo.length(); i < 4; i++) {
temp.append("0");
}
return officeGlobelNo = temp.append(officeGlobelNo).toString();
} catch (PersistenceException e) {
throw new OfficeException(e);
}
}
use of org.mifos.customers.office.persistence.OfficePersistence 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.customers.office.persistence.OfficePersistence in project head by mifos.
the class OfficeListTag method doStartTag.
@Override
public int doStartTag() throws JspException {
try {
String officeListString = "";
OnlyBranchOfficeHierarchyDto officeHierarchyDto = (OnlyBranchOfficeHierarchyDto) pageContext.getAttribute(OnlyBranchOfficeHierarchyDto.IDENTIFIER);
if (officeHierarchyDto != null) {
officeListString = getOfficeList(officeHierarchyDto);
} else {
// FIXME - #00006 - keithw - personnel creation use this still
UserContext userContext = (UserContext) pageContext.getSession().getAttribute(Constants.USERCONTEXT);
OfficePersistence officePersistence = new OfficePersistence();
OfficeBO officeBO = officePersistence.getOffice(userContext.getBranchId());
List<OfficeDetailsDto> levels = officePersistence.getActiveLevels();
OfficeBO loggedInOffice = officePersistence.getOffice(userContext.getBranchId());
List<OfficeBO> branchParents = officePersistence.getBranchParents(officeBO.getSearchId());
List<OfficeHierarchyDto> officeHierarchy = OfficeBO.convertToBranchOnlyHierarchyWithParentsOfficeHierarchy(branchParents);
List<OfficeBO> officesTillBranchOffice = officePersistence.getOfficesTillBranchOffice(officeBO.getSearchId());
officeListString = getOfficeList(userContext.getPreferredLocale(), levels, loggedInOffice.getSearchId(), officeHierarchy, officesTillBranchOffice);
}
TagUtils.getInstance().write(pageContext, officeListString);
} catch (Exception e) {
/**
* This turns into a (rather ugly) error 500. TODO: make it more reasonable.
*/
throw new JspException(e);
}
return EVAL_PAGE;
}
use of org.mifos.customers.office.persistence.OfficePersistence in project head by mifos.
the class PersonAction method manage.
@TransactionDemarcate(joinToken = true)
public ActionForward manage(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
PersonActionForm actionform = (PersonActionForm) form;
actionform.clear();
PersonnelBO personnelInSession = (PersonnelBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
PersonnelBO personnel = this.personnelDao.findPersonnelById(personnelInSession.getPersonnelId());
List<ValueListElement> titles = this.customerDao.retrieveTitles();
List<ValueListElement> genders = this.customerDao.retrieveGenders();
List<ValueListElement> maritalStatuses = this.customerDao.retrieveMaritalStatuses();
List<ValueListElement> languages = Localization.getInstance().getLocaleForUI();
List<RoleBO> roles = legacyRolesPermissionsDao.getRoles();
List<PersonnelLevelEntity> personnelLevels = this.customerDao.retrievePersonnelLevels();
for (PersonnelLevelEntity personnelLevelEntity : personnelLevels) {
String messageTextLookup = ApplicationContextProvider.getBean(MessageLookup.class).lookup(personnelLevelEntity.getLookUpValue().getPropertiesKey());
personnelLevelEntity.setName(messageTextLookup);
}
SessionUtils.setCollectionAttribute(PersonnelConstants.TITLE_LIST, titles, request);
SessionUtils.setCollectionAttribute(PersonnelConstants.PERSONNEL_LEVEL_LIST, personnelLevels, request);
SessionUtils.setCollectionAttribute(PersonnelConstants.GENDER_LIST, genders, request);
SessionUtils.setCollectionAttribute(PersonnelConstants.MARITAL_STATUS_LIST, maritalStatuses, request);
SessionUtils.setCollectionAttribute(PersonnelConstants.LANGUAGE_LIST, languages, request);
SessionUtils.setCollectionAttribute(PersonnelConstants.ROLES_LIST, roles, request);
SessionUtils.setCollectionAttribute(PersonnelConstants.ROLEMASTERLIST, roles, request);
List<CustomFieldDefinitionEntity> customFieldDefs = new ArrayList<CustomFieldDefinitionEntity>();
SessionUtils.setCollectionAttribute(CustomerConstants.CUSTOM_FIELDS_LIST, customFieldDefs, request);
UserContext userContext = getUserContext(request);
List<PersonnelStatusEntity> statuses = legacyMasterDao.findMasterDataEntitiesWithLocale(PersonnelStatusEntity.class);
for (PersonnelStatusEntity personnelStatusEntity : statuses) {
String messageTextLookup = ApplicationContextProvider.getBean(MessageLookup.class).lookup(personnelStatusEntity.getLookUpValue().getPropertiesKey());
personnelStatusEntity.setName(messageTextLookup);
}
SessionUtils.setCollectionAttribute(PersonnelConstants.STATUS_LIST, statuses, request);
OfficeBO loggedInOffice = this.officeDao.findOfficeById(userContext.getBranchId());
List<OfficeDetailsDto> officeHierarchy = new OfficePersistence().getChildOffices(loggedInOffice.getSearchId());
SessionUtils.setCollectionAttribute(PersonnelConstants.OFFICE_LIST, officeHierarchy, request);
actionform.setPersonnelId(personnel.getPersonnelId().toString());
if (personnel.getOffice() != null) {
actionform.setOfficeId(personnel.getOffice().getOfficeId().toString());
}
if (personnel.getTitle() != null) {
actionform.setTitle(personnel.getTitle().toString());
}
if (personnel.getLevel() != null) {
actionform.setLevel(personnel.getLevelEnum().getValue().toString());
}
if (personnel.getStatus() != null) {
actionform.setStatus(personnel.getStatus().getId().toString());
}
actionform.setLoginName(personnel.getUserName());
actionform.setGlobalPersonnelNum(personnel.getGlobalPersonnelNum());
actionform.setCustomFields(new ArrayList<CustomFieldDto>());
if (personnel.getPersonnelDetails() != null) {
PersonnelDetailsEntity personnelDetails = personnel.getPersonnelDetails();
actionform.setFirstName(personnelDetails.getName().getFirstName());
actionform.setMiddleName(personnelDetails.getName().getMiddleName());
actionform.setSecondLastName(personnelDetails.getName().getSecondLastName());
actionform.setLastName(personnelDetails.getName().getLastName());
if (personnelDetails.getGender() != null) {
actionform.setGender(personnelDetails.getGender().toString());
}
if (personnelDetails.getMaritalStatus() != null) {
actionform.setMaritalStatus(personnelDetails.getMaritalStatus().toString());
}
actionform.setAddress(personnelDetails.getAddress());
if (personnelDetails.getDateOfJoiningMFI() != null) {
actionform.setDateOfJoiningMFI(DateUtils.makeDateAsSentFromBrowser(personnelDetails.getDateOfJoiningMFI()));
}
if (personnelDetails.getDob() != null) {
actionform.setDob(DateUtils.makeDateAsSentFromBrowser(personnelDetails.getDob()));
}
}
actionform.setEmailId(personnel.getEmailId());
if (personnel.getPreferredLocale() != null) {
actionform.setPreferredLocale(personnel.getPreferredLocale());
}
if (personnel.getPasswordExpirationDate() != null) {
actionform.setPasswordExpirationDate(DateUtils.makeDateAsSentFromBrowser(personnel.getPasswordExpirationDate()));
}
List<RoleBO> selectList = new ArrayList<RoleBO>();
for (PersonnelRoleEntity personnelRole : personnel.getPersonnelRoles()) {
selectList.add(personnelRole.getRole());
}
SessionUtils.setCollectionAttribute(PersonnelConstants.PERSONNEL_ROLES_LIST, selectList, request);
SessionUtils.setAttribute(Constants.BUSINESS_KEY, personnel, request);
return mapping.findForward(ActionForwards.manage_success.toString());
}
Aggregations