use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveCustomerThatQualifyForSavings.
@Override
public List<CustomerSearchResultDto> retrieveCustomerThatQualifyForSavings(CustomerSearchDto customerSearchDto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
try {
List<CustomerSearchResultDto> pagedDetails = new ArrayList<CustomerSearchResultDto>();
QueryResult customerForSavings = new CustomerPersistence().searchCustForSavings(customerSearchDto.getSearchTerm(), userContext.getId());
int position = this.resultsetOffset(customerSearchDto.getPage(), customerSearchDto.getPageSize());
List<AccountSearchResultsDto> pagedResults = customerForSavings.get(position, customerSearchDto.getPageSize());
int i = 1;
for (AccountSearchResultsDto customerBO : pagedResults) {
CustomerSearchResultDto customer = new CustomerSearchResultDto();
customer.setCustomerId(customerBO.getClientId());
customer.setBranchName(customerBO.getOfficeName());
customer.setGlobalId(customerBO.getGlobelNo());
customer.setSearchIndex(i);
customer.setCenterName(StringUtils.defaultIfEmpty(customerBO.getCenterName(), "--"));
customer.setGroupName(StringUtils.defaultIfEmpty(customerBO.getGroupName(), "--"));
customer.setClientName(customerBO.getClientName());
pagedDetails.add(customer);
i++;
}
return pagedDetails;
} catch (PersistenceException e) {
throw new MifosRuntimeException(e);
} catch (HibernateSearchException e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.
the class SavingsServiceFacadeWebTier method createSavingsAccount.
@Override
public Long createSavingsAccount(SavingsAccountCreationDto savingsAccountCreation, List<QuestionGroupDetail> questionGroups) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
LocalDate createdDate = new LocalDate();
Integer createdById = user.getUserId();
PersonnelBO createdBy = this.personnelDao.findPersonnelById(createdById.shortValue());
CustomerBO customer = this.customerDao.findCustomerById(savingsAccountCreation.getCustomerId());
SavingsOfferingBO savingsProduct = this.savingsProductDao.findById(savingsAccountCreation.getProductId());
Money recommendedOrMandatory = new Money(savingsProduct.getCurrency(), savingsAccountCreation.getRecommendedOrMandatoryAmount());
AccountState savingsAccountState = AccountState.fromShort(savingsAccountCreation.getAccountState());
CalendarEvent calendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
SavingsAccountTypeInspector savingsAccountWrapper = new SavingsAccountTypeInspector(customer, savingsProduct.getRecommendedAmntUnit());
try {
SavingsBO savingsAccount = null;
if (savingsAccountWrapper.isIndividualSavingsAccount()) {
savingsAccount = SavingsBO.createIndividalSavingsAccount(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, createdDate, createdById, calendarEvents, createdBy);
} else if (savingsAccountWrapper.isJointSavingsAccountWithClientTracking()) {
List<CustomerBO> activeAndOnHoldClients = new CustomerPersistence().getActiveAndOnHoldChildren(customer.getSearchId(), customer.getOfficeId(), CustomerLevel.CLIENT);
savingsAccount = SavingsBO.createJointSavingsAccount(customer, savingsProduct, recommendedOrMandatory, savingsAccountState, createdDate, createdById, calendarEvents, createdBy, activeAndOnHoldClients);
}
try {
personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
this.transactionHelper.startTransaction();
this.savingsDao.save(savingsAccount);
this.transactionHelper.flushSession();
savingsAccount.generateSystemId(createdBy.getOffice().getGlobalOfficeNum());
this.savingsDao.save(savingsAccount);
this.transactionHelper.flushSession();
// save question groups
if (!questionGroups.isEmpty()) {
Integer eventSourceId = questionnaireServiceFacade.getEventSourceId("Create", "Savings");
QuestionGroupDetails questionGroupDetails = new QuestionGroupDetails(Integer.valueOf(user.getUserId()).shortValue(), savingsAccount.getAccountId(), eventSourceId, questionGroups);
questionnaireServiceFacade.saveResponses(questionGroupDetails);
}
this.transactionHelper.commitTransaction();
return savingsAccount.getAccountId().longValue();
} catch (BusinessRuleException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getMessageKey(), e);
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.
the class CustSearchAction method search.
/**
* FIXME: KEITHW - When replacing search functionality for customers with spring/ftl implementation,
* find cleaner way of implementing search that returns a non domain related class (data only object)
*/
@Override
@TransactionDemarcate(joinToken = true)
public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
if (request.getParameter("perspective") != null) {
request.setAttribute("perspective", request.getParameter("perspective"));
}
ActionForward actionForward = super.search(mapping, form, request, response);
CustSearchActionForm actionForm = (CustSearchActionForm) form;
UserContext userContext = getUserContext(request);
String searchString = actionForm.getSearchString();
if (searchString == null) {
throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
}
String officeName = this.centerServiceFacade.retrieveOfficeName(userContext.getBranchId());
addSeachValues(searchString, userContext.getBranchId().toString(), officeName, request);
searchString = SearchUtils.normalizeSearchString(searchString);
if (StringUtils.isBlank(searchString)) {
throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
}
if (actionForm.getInput() != null && actionForm.getInput().equals("loan")) {
QueryResult groupClients = new CustomerPersistence().searchGroupClient(searchString, userContext.getId(), false);
SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, groupClients, request);
} else if (actionForm.getInput() != null && actionForm.getInput().equals("savings")) {
QueryResult customerForSavings = new CustomerPersistence().searchCustForSavings(searchString, userContext.getId());
SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, customerForSavings, request);
}
return actionForward;
}
use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.
the class EditCustomerStatusAction method previewStatus.
@TransactionDemarcate(joinToken = true)
public ActionForward previewStatus(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
logger.debug("In EditCustomerStatusAction:preview()");
CustomerBO customerBO = (CustomerBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
EditCustomerStatusActionForm statusActionForm = (EditCustomerStatusActionForm) form;
statusActionForm.setCommentDate(DateUtils.getCurrentDate(getUserContext(request).getPreferredLocale()));
if (StringUtils.isNotBlank(statusActionForm.getNewStatusId())) {
CustomerStatusDetailDto customerStatusDetail = this.centerServiceFacade.retrieveCustomerStatusDetails(statusActionForm.getNewStatusIdValue(), statusActionForm.getFlagIdValue(), customerBO.getLevel().getValue());
SessionUtils.setAttribute(SavingsConstants.NEW_STATUS_NAME, customerStatusDetail.getStatusName(), request);
SessionUtils.setAttribute(SavingsConstants.FLAG_NAME, customerStatusDetail.getFlagName(), request);
} else {
SessionUtils.setAttribute(SavingsConstants.NEW_STATUS_NAME, null, request);
SessionUtils.setAttribute(SavingsConstants.FLAG_NAME, null, request);
}
Short newStatusId = statusActionForm.getNewStatusIdValue();
Short customerLevelId = statusActionForm.getLevelIdValue();
List<CustomerCheckListBO> checklist = new CustomerPersistence().getStatusChecklist(newStatusId, customerLevelId);
SessionUtils.setCollectionAttribute(SavingsConstants.STATUS_CHECK_LIST, checklist, request);
if (statusActionForm.getNewStatusIdValue().equals(CustomerStatus.CLIENT_CLOSED.getValue())) {
return createClientQuestionnaire.fetchAppliedQuestions(mapping, statusActionForm, request, ActionForwards.previewStatus_success);
}
return mapping.findForward(ActionForwards.previewStatus_success.toString());
}
use of org.mifos.customers.persistence.CustomerPersistence in project head by mifos.
the class ApplyCustomerFeeChangesHelper method execute.
@Override
public void execute(@SuppressWarnings("unused") long timeInMillis) throws BatchJobException {
List<String> errorList = new ArrayList<String>();
List<Short> updatedFeeIds = new ArrayList<Short>();
try {
updatedFeeIds = getFeeDao().getUpdatedFeesForCustomer();
} catch (Exception e) {
errorList.add(e.getMessage());
throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
}
for (Short feeId : updatedFeeIds) {
try {
FeeBO hydratedFee = getFeeDao().findById(feeId);
if (!hydratedFee.getFeeChangeType().equals(FeeChangeType.NOT_UPDATED)) {
List<AccountBO> accounts = new CustomerPersistence().getCustomerAccountsForFee(hydratedFee.getFeeId());
if (accounts != null && accounts.size() > 0) {
for (AccountBO account : accounts) {
updateAccountFee(account, hydratedFee);
}
}
}
hydratedFee.updateFeeChangeType(FeeChangeType.NOT_UPDATED);
UserContext userContext = new UserContext();
userContext.setId(PersonnelConstants.SYSTEM_USER);
hydratedFee.setUserContext(userContext);
hydratedFee.save();
StaticHibernateUtil.commitTransaction();
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
errorList.add("feeId: " + feeId);
}
}
if (errorList.size() > 0) {
throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
}
}
Aggregations