use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class RolesPermissionServiceFacadeWebTier method createRole.
@Override
public void createRole(Short userId, String name, List<Short> ActivityIds) throws RolesPermissionException {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
List<ActivityEntity> activityEntities = getActivityEntities(ActivityIds);
RoleBO roleBO = new RoleBO(userContext, name, activityEntities);
try {
validateRole(name, activityEntities, roleBO);
StaticHibernateUtil.startTransaction();
legacyRolesPermissionsDao.save(roleBO);
StaticHibernateUtil.flushSession();
for (ActivityEntity ae : activityEntities) {
StaticHibernateUtil.getSessionTL().refresh(ae);
}
StaticHibernateUtil.commitTransaction();
} catch (PersistenceException e) {
StaticHibernateUtil.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
StaticHibernateUtil.closeSession();
}
}
use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class LoanAccountServiceFacadeWebTier method retrieveLoanRepaymentSchedule.
@Override
public List<LoanRepaymentScheduleItemDto> retrieveLoanRepaymentSchedule(String globalAccountNum, Date viewDate) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
LoanBO loanBO = this.loanDao.findByGlobalAccountNum(globalAccountNum);
try {
personnelDao.checkAccessPermission(userContext, loanBO.getOfficeId(), loanBO.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException(e.getMessage(), e);
}
Errors errors = loanBusinessService.computeExtraInterest(loanBO, viewDate);
if (errors.hasErrors()) {
throw new MifosRuntimeException(errors.getErrorEntries().get(0).getDefaultMessage());
}
List<LoanRepaymentScheduleItemDto> loanSchedule = new ArrayList<LoanRepaymentScheduleItemDto>();
for (AccountActionDateEntity accountAction : loanBO.getAccountActionDates()) {
LoanScheduleEntity loanAccountAction = (LoanScheduleEntity) accountAction;
Set<AccountFeesActionDetailEntity> feeEntities = loanAccountAction.getAccountFeesActionDetails();
List<AccountFeeScheduleDto> feeDtos = new ArrayList<AccountFeeScheduleDto>();
for (AccountFeesActionDetailEntity feeEntity : feeEntities) {
feeDtos.add(convertToDto(feeEntity));
}
loanSchedule.add(new LoanRepaymentScheduleItemDto(loanAccountAction.getInstallmentId(), loanAccountAction.getActionDate(), loanAccountAction.getPaymentStatus(), loanAccountAction.getPaymentDate(), loanAccountAction.getPrincipal().toString(), loanAccountAction.getPrincipalPaid().toString(), loanAccountAction.getInterest().toString(), loanAccountAction.getInterestPaid().toString(), loanAccountAction.getPenalty().toString(), loanAccountAction.getPenaltyPaid().toString(), loanAccountAction.getExtraInterest().toString(), loanAccountAction.getExtraInterestPaid().toString(), loanAccountAction.getMiscFee().toString(), loanAccountAction.getMiscFeePaid().toString(), loanAccountAction.getMiscPenalty().toString(), loanAccountAction.getMiscPenaltyPaid().toString(), feeDtos));
}
return loanSchedule;
}
use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class SavingsServiceFacadeWebTier method retrieveSavingsAccountDetails.
@Override
public SavingsAccountDetailDto retrieveSavingsAccountDetails(Long savingsId) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
SavingsBO savingsAccount = this.savingsDao.findById(savingsId);
try {
personnelDao.checkAccessPermission(userContext, savingsAccount.getOfficeId(), savingsAccount.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
return savingsAccount.toDto();
}
use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class WebTierPenaltyServiceFacade method updatePenalty.
@Override
public void updatePenalty(PenaltyFormDto dto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
PenaltyBO penaltyBO = this.penaltyDao.findPenaltyById(dto.getId());
penaltyBO.updateDetails(userContext);
try {
PenaltyFrequency penaltyFrequency = dto.getPenaltyFrequency() != null ? PenaltyFrequency.getPenaltyFrequencyType(dto.getPenaltyFrequency()) : null;
PenaltyPeriod penaltyPeriod = dto.getPenaltyPeriod() != null ? PenaltyPeriod.getPenaltyPeriod(dto.getPenaltyPeriod()) : null;
PenaltyFormula penaltyFormula = dto.getPenaltyFormula() != null ? PenaltyFormula.getPenaltyFormula(dto.getPenaltyFormula()) : null;
PenaltyStatus penaltyStatus = dto.getPenaltyStatus() != null ? PenaltyStatus.getPenaltyStatus(dto.getPenaltyStatus()) : null;
penaltyBO.setPeriodType(this.penaltyDao.findPenaltyPeriodEntityByType(penaltyPeriod));
penaltyBO.setPenaltyFrequency(this.penaltyDao.findPenaltyFrequencyEntityByType(penaltyFrequency));
penaltyBO.setPenaltyName(dto.getPenaltyName());
penaltyBO.setPeriodDuration(dto.getDuration());
penaltyBO.setMinimumLimit(dto.getMin());
penaltyBO.setMaximumLimit(dto.getMax());
penaltyBO.setStatus(this.penaltyDao.findPenaltyStatusEntityByType(penaltyStatus));
penaltyBO.setGlCode(this.generalLedgerDao.findGlCodeById(dto.getGlCode()));
if (dto.isRatePenalty()) {
RatePenaltyBO ratePenaltyBO = (RatePenaltyBO) penaltyBO;
ratePenaltyBO.setRate(dto.getRate());
ratePenaltyBO.setFormula(this.penaltyDao.findPenaltyFormulaEntityByType(penaltyFormula));
} else {
AmountPenaltyBO amountPenaltyBO = (AmountPenaltyBO) penaltyBO;
amountPenaltyBO.setAmount(new Money(getCurrency(dto.getCurrencyId()), dto.getAmount()));
}
try {
StaticHibernateUtil.startTransaction();
this.penaltyDao.save(penaltyBO);
StaticHibernateUtil.commitTransaction();
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
StaticHibernateUtil.closeSession();
}
} catch (ApplicationException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
Aggregations