Search in sources :

Example 6 with UserContextFactory

use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.

the class CollectionSheetServiceFacadeWebTier method saveCollectionSheet.

@Override
public CollectionSheetErrorsDto saveCollectionSheet(final SaveCollectionSheetDto saveCollectionSheet) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    final SaveCollectionSheetDto saveCollectionSheetDto = saveCollectionSheet;
    UserContext userContext = new UserContextFactory().create(user);
    int customerId = saveCollectionSheetDto.getSaveCollectionSheetCustomers().get(0).getCustomerId();
    CustomerBO customerBO = this.customerDao.findCustomerById(customerId);
    try {
        personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    CollectionSheetErrorsDto collectionSheetErrorsDto = null;
    try {
        collectionSheetErrorsDto = collectionSheetService.saveCollectionSheet(saveCollectionSheet);
    } catch (SaveCollectionSheetException e) {
        throw new MifosRuntimeException(e.printInvalidSaveCollectionSheetReasons());
    }
    return collectionSheetErrorsDto;
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) UserContext(org.mifos.security.util.UserContext) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 7 with UserContextFactory

use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.

the class AdminServiceFacadeWebTier method updateSavingsProduct.

@Override
public PrdOfferingDto updateSavingsProduct(SavingsProductDto savingsProductRequest) {
    SavingsOfferingBO savingsProductForUpdate = this.savingsProductDao.findById(savingsProductRequest.getProductDetails().getId());
    // enforced by integrity constraints on table also.
    if (savingsProductForUpdate.isDifferentName(savingsProductRequest.getProductDetails().getName())) {
        this.savingsProductDao.validateProductWithSameNameDoesNotExist(savingsProductRequest.getProductDetails().getName());
    }
    if (savingsProductForUpdate.isDifferentShortName(savingsProductRequest.getProductDetails().getShortName())) {
        this.savingsProductDao.validateProductWithSameShortNameDoesNotExist(savingsProductRequest.getProductDetails().getShortName());
    }
    // domain rule validation - put on domain entity
    if (savingsProductForUpdate.isDifferentStartDate(savingsProductRequest.getProductDetails().getStartDate())) {
        validateStartDateIsNotBeforeToday(savingsProductRequest.getProductDetails().getStartDate());
        validateStartDateIsNotOverOneYearFromToday(savingsProductRequest.getProductDetails().getStartDate());
        validateEndDateIsPastStartDate(savingsProductRequest.getProductDetails().getStartDate(), savingsProductRequest.getProductDetails().getEndDate());
    }
    boolean activeOrInactiveSavingsAccountExist = this.savingsProductDao.activeOrInactiveSavingsAccountsExistForProduct(savingsProductRequest.getProductDetails().getId());
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    SavingsOfferingBO newSavingsDetails = new SavingsProductAssembler(this.loanProductDao, this.savingsProductDao, this.generalLedgerDao).fromDto(user, savingsProductRequest);
    savingsProductForUpdate.updateDetails(userContext);
    HibernateTransactionHelper transactionHelper = new HibernateTransactionHelperForStaticHibernateUtil();
    try {
        transactionHelper.startTransaction();
        transactionHelper.beginAuditLoggingFor(savingsProductForUpdate);
        if (activeOrInactiveSavingsAccountExist) {
            LocalDate updateDate = new LocalDate();
            savingsProductForUpdate.updateProductDetails(newSavingsDetails.getPrdOfferingName(), newSavingsDetails.getPrdOfferingShortName(), newSavingsDetails.getDescription(), newSavingsDetails.getPrdCategory(), newSavingsDetails.getStartDate(), newSavingsDetails.getEndDate(), newSavingsDetails.getPrdStatus());
            savingsProductForUpdate.updateSavingsDetails(newSavingsDetails.getRecommendedAmount(), newSavingsDetails.getRecommendedAmntUnit(), newSavingsDetails.getMaxAmntWithdrawl(), newSavingsDetails.getInterestRate(), newSavingsDetails.getMinAmntForInt(), updateDate);
        } else {
            savingsProductForUpdate.updateDetailsOfProductNotInUse(newSavingsDetails.getPrdOfferingName(), newSavingsDetails.getPrdOfferingShortName(), newSavingsDetails.getDescription(), newSavingsDetails.getPrdCategory(), newSavingsDetails.getStartDate(), newSavingsDetails.getEndDate(), newSavingsDetails.getPrdApplicableMaster(), newSavingsDetails.getPrdStatus());
            savingsProductForUpdate.updateDetailsOfSavingsProductNotInUse(newSavingsDetails.getSavingsType(), newSavingsDetails.getRecommendedAmount(), newSavingsDetails.getRecommendedAmntUnit(), newSavingsDetails.getMaxAmntWithdrawl(), newSavingsDetails.getInterestRate(), newSavingsDetails.getInterestCalcType(), newSavingsDetails.getTimePerForInstcalc(), newSavingsDetails.getFreqOfPostIntcalc(), newSavingsDetails.getMinAmntForInt());
        }
        this.savingsProductDao.save(savingsProductForUpdate);
        transactionHelper.commitTransaction();
        return savingsProductForUpdate.toDto();
    } catch (Exception e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        transactionHelper.closeSession();
    }
}
Also used : HibernateTransactionHelper(org.mifos.framework.hibernate.helper.HibernateTransactionHelper) HibernateTransactionHelperForStaticHibernateUtil(org.mifos.framework.hibernate.helper.HibernateTransactionHelperForStaticHibernateUtil) UserContext(org.mifos.security.util.UserContext) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) LocalDate(org.joda.time.LocalDate) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 8 with UserContextFactory

use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.

the class OfficeServiceFacadeWebTier method updateOffice.

@Override
public boolean updateOffice(Short officeId, Integer versionNum, OfficeUpdateRequest officeUpdateRequest) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    try {
        boolean isParentOfficeChanged = false;
        OfficeBO office = officeDao.findOfficeById(officeId);
        office.validateVersion(versionNum);
        OfficeBO parentOffice = null;
        if (officeUpdateRequest.getParentOfficeId() != null) {
            parentOffice = officeDao.findOfficeById(officeUpdateRequest.getParentOfficeId());
            if (office.isDifferentParentOffice(parentOffice)) {
                holidayDao.validateNoExtraFutureHolidaysApplicableOnParentOffice(office.getParentOffice().getOfficeId(), officeUpdateRequest.getParentOfficeId());
            }
        }
        if (office.isNameDifferent(officeUpdateRequest.getOfficeName())) {
            officeDao.validateOfficeNameIsNotTaken(officeUpdateRequest.getOfficeName());
        }
        if (office.isShortNameDifferent(officeUpdateRequest.getShortName())) {
            officeDao.validateOfficeShortNameIsNotTaken(officeUpdateRequest.getShortName());
        }
        OfficeStatus newStatus = OfficeStatus.getOfficeStatus(officeUpdateRequest.getNewStatus());
        if (!office.isStatusDifferent(newStatus)) {
            if (OfficeStatus.INACTIVE.equals(officeUpdateRequest.getNewStatus())) {
                officeDao.validateNoActiveChildrenExist(office.getOfficeId());
                officeDao.validateNoActivePeronnelExist(office.getOfficeId());
            }
            if (parentOffice != null) {
                if (parentOffice.isInActive()) {
                    throw new OfficeException(OfficeConstants.KEYPARENTNOTACTIVE);
                }
            }
        }
        StaticHibernateUtil.startTransaction();
        office.update(userContext, officeUpdateRequest, parentOffice);
        StaticHibernateUtil.commitTransaction();
        return isParentOfficeChanged;
    } catch (OfficeException e1) {
        throw new BusinessRuleException(e1.getKey(), e1);
    } catch (ApplicationException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (Exception e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new MifosRuntimeException(e.getMessage(), e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : OfficeException(org.mifos.customers.office.exceptions.OfficeException) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) OfficeBO(org.mifos.customers.office.business.OfficeBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) OfficeStatus(org.mifos.customers.office.util.helpers.OfficeStatus) OfficeValidationException(org.mifos.customers.office.exceptions.OfficeValidationException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) OfficeException(org.mifos.customers.office.exceptions.OfficeException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 9 with UserContextFactory

use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.

the class FeeServiceFacadeWebTier method updateFee.

@Override
public void updateFee(FeeUpdateRequest feeUpdateRequest) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    try {
        this.feeService.update(feeUpdateRequest, userContext);
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory)

Example 10 with UserContextFactory

use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.

the class ImportTransactionsServiceFacadeWebTier method confirmImport.

@Override
public ParseResultDto confirmImport(String importPluginClassname, String tempFileName) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    FileInputStream fileInput = null;
    try {
        final TransactionImport transactionImport = getInitializedImportPlugin(importPluginClassname, userContext.getId());
        fileInput = new FileInputStream(tempFileName);
        final ParseResultDto importResult = transactionImport.parse(fileInput);
        fileInput.close();
        fileInput = new FileInputStream(tempFileName);
        if (importPluginClassname.equalsIgnoreCase("org.almajmoua.AudiBankXlsImporter")) {
            importResult.setTrxIdsToUndo(transactionImport.storeForUndoImport(fileInput));
        } else {
            transactionImport.store(fileInput);
        }
        return importResult;
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    } finally {
        if (fileInput != null) {
            try {
                fileInput.close();
            } catch (Exception e2) {
                throw new MifosRuntimeException(e2);
            }
        }
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) ParseResultDto(org.mifos.dto.domain.ParseResultDto) FileInputStream(java.io.FileInputStream) TransactionImport(org.mifos.accounts.api.TransactionImport) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)49 MifosUser (org.mifos.security.MifosUser)49 UserContext (org.mifos.security.util.UserContext)49 MifosRuntimeException (org.mifos.core.MifosRuntimeException)37 BusinessRuleException (org.mifos.service.BusinessRuleException)26 AccountException (org.mifos.accounts.exceptions.AccountException)18 PersistenceException (org.mifos.framework.exceptions.PersistenceException)17 ArrayList (java.util.ArrayList)13 LoanBO (org.mifos.accounts.loan.business.LoanBO)12 ServiceException (org.mifos.framework.exceptions.ServiceException)12 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)9 ApplicationException (org.mifos.framework.exceptions.ApplicationException)9 Money (org.mifos.framework.util.helpers.Money)8 LocalDate (org.joda.time.LocalDate)7 SystemException (org.mifos.framework.exceptions.SystemException)6 CustomerBO (org.mifos.customers.business.CustomerBO)5 OfficeBO (org.mifos.customers.office.business.OfficeBO)5 Date (java.util.Date)4 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)4 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)4