Search in sources :

Example 6 with MifosUser

use of org.mifos.security.MifosUser in project head by mifos.

the class ClientServiceFacadeWebTier method transferClientToGroup.

@Override
public String transferClientToGroup(Integer groupId, String clientGlobalCustNum, Integer previousClientVersionNo) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    ClientBO client;
    try {
        client = this.customerService.transferClientTo(userContext, groupId, clientGlobalCustNum, previousClientVersionNo);
        return client.getGlobalCustNum();
    } catch (CustomerException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) BusinessRuleException(org.mifos.service.BusinessRuleException) UserContext(org.mifos.security.util.UserContext) ClientBO(org.mifos.customers.client.business.ClientBO) MifosUser(org.mifos.security.MifosUser)

Example 7 with MifosUser

use of org.mifos.security.MifosUser in project head by mifos.

the class ClientServiceFacadeWebTier method getClientInformationDto.

@Override
public ClientInformationDto getClientInformationDto(String globalCustNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    ClientBO client = customerDao.findClientBySystemId(globalCustNum);
    if (client == null) {
        throw new MifosRuntimeException("Client not found for globalCustNum, levelId: " + globalCustNum);
    }
    try {
        personnelDao.checkAccessPermission(userContext, client.getOfficeId(), client.getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    ClientDisplayDto clientDisplay = this.customerDao.getClientDisplayDto(client.getCustomerId(), userContext);
    Integer clientId = client.getCustomerId();
    CustomerAccountSummaryDto customerAccountSummary = this.customerDao.getCustomerAccountSummaryDto(clientId);
    ClientPerformanceHistoryDto clientPerformanceHistory = assembleClientPerformanceHistoryDto(client.getClientPerformanceHistory(), clientId);
    CustomerAddressDto clientAddress = this.customerDao.getCustomerAddressDto(client);
    List<CustomerNoteDto> recentCustomerNotes = customerDao.getRecentCustomerNoteDto(clientId);
    List<CustomerFlagDto> customerFlags = customerDao.getCustomerFlagDto(client.getCustomerFlags());
    List<LoanDetailDto> loanDetail = customerDao.getLoanDetailDto(client.getOpenLoanAccounts());
    List<LoanDetailDto> groupLoanDetail = customerDao.getLoanDetailDto(client.getOpenGroupLoanAccounts());
    List<SavingsDetailDto> savingsDetail = customerDao.getSavingsDetailDto(clientId, userContext);
    CustomerMeetingDto customerMeeting = customerDao.getCustomerMeetingDto(client.getCustomerMeeting(), userContext);
    List<AccountBO> allClosedLoanAndSavingsAccounts = customerDao.retrieveAllClosedLoanAndSavingsAccounts(clientId);
    List<LoanDetailDto> closedLoanAccounts = new ArrayList<LoanDetailDto>();
    List<SavingsDetailDto> closedSavingsAccounts = new ArrayList<SavingsDetailDto>();
    for (AccountBO closedAccount : allClosedLoanAndSavingsAccounts) {
        if (closedAccount.getAccountType().getAccountTypeId() == AccountTypes.LOAN_ACCOUNT.getValue().intValue()) {
            closedLoanAccounts.add(new LoanDetailDto(closedAccount.getGlobalAccountNum(), ((LoanBO) closedAccount).getLoanOffering().getPrdOfferingName(), closedAccount.getAccountState().getId(), closedAccount.getAccountState().getName(), ((LoanBO) closedAccount).getLoanSummary().getOutstandingBalance().toString(), closedAccount.getTotalAmountDue().toString(), closedAccount.getTotalAmountInArrears().toString()));
        } else {
            closedSavingsAccounts.add(new SavingsDetailDto(closedAccount.getGlobalAccountNum(), ((SavingsBO) closedAccount).getSavingsOffering().getPrdOfferingName(), closedAccount.getAccountState().getId(), closedAccount.getAccountState().getName(), ((SavingsBO) closedAccount).getSavingsBalance().toString()));
        }
    }
    Boolean activeSurveys = Boolean.FALSE;
    //        Boolean activeSurveys = new SurveysPersistence().isActiveSurveysForSurveyType(SurveyType.CLIENT);
    List<SurveyDto> customerSurveys = new ArrayList<SurveyDto>();
    List<LoanDetailDto> guarantedLoanAccounts = new ArrayList<LoanDetailDto>();
    try {
        List<GuarantyEntity> guaranties = legacyAccountDao.getGuarantyByGurantorId(clientId);
        if (guaranties != null && guaranties.size() > 0) {
            for (GuarantyEntity guaranty : guaranties) {
                if (guaranty != null && guaranty.getState() != null && guaranty.getState()) {
                    LoanBO loan = loanDao.findById(guaranty.getLoanId());
                    guarantedLoanAccounts.add(new LoanDetailDto(loan.getGlobalAccountNum(), loan.getLoanOffering().getPrdOfferingName(), loan.getAccountState().getId(), loan.getAccountState().getName(), loan.getLoanSummary().getOutstandingBalance().toString(), loan.getTotalAmountDue().toString(), loan.getAccountType().getAccountTypeId(), loan.getTotalAmountInArrears().toString()));
                }
            }
        }
    } catch (PersistenceException e) {
        throw new MifosRuntimeException("Can not get guaranted loan accounts", e);
    }
    return new ClientInformationDto(clientDisplay, customerAccountSummary, clientPerformanceHistory, clientAddress, recentCustomerNotes, customerFlags, loanDetail, groupLoanDetail, savingsDetail, customerMeeting, activeSurveys, customerSurveys, closedLoanAccounts, closedSavingsAccounts, guarantedLoanAccounts);
}
Also used : CustomerAccountSummaryDto(org.mifos.dto.domain.CustomerAccountSummaryDto) SurveyDto(org.mifos.dto.domain.SurveyDto) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) CustomerAddressDto(org.mifos.dto.domain.CustomerAddressDto) GuarantyEntity(org.mifos.accounts.loan.business.GuarantyEntity) AccountBO(org.mifos.accounts.business.AccountBO) CustomerMeetingDto(org.mifos.dto.domain.CustomerMeetingDto) CustomerNoteDto(org.mifos.dto.domain.CustomerNoteDto) ClientPerformanceHistoryDto(org.mifos.dto.screen.ClientPerformanceHistoryDto) SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) ClientDisplayDto(org.mifos.dto.screen.ClientDisplayDto) UserContext(org.mifos.security.util.UserContext) LoanDetailDto(org.mifos.dto.domain.LoanDetailDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) CustomerFlagDto(org.mifos.dto.domain.CustomerFlagDto) AccountException(org.mifos.accounts.exceptions.AccountException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ClientInformationDto(org.mifos.dto.screen.ClientInformationDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 8 with MifosUser

use of org.mifos.security.MifosUser in project head by mifos.

the class CollectionSheetServiceFacadeWebTier method getCollectionSheet.

@Override
public CollectionSheetDto getCollectionSheet(Integer customerId, LocalDate meetingDate) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    CustomerBO customerBO = this.customerDao.findCustomerById(customerId);
    try {
        personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    return collectionSheetService.retrieveCollectionSheet(customerId, meetingDate);
}
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 9 with MifosUser

use of org.mifos.security.MifosUser in project head by mifos.

the class AdminServiceFacadeWebTier method createProductCategory.

@Override
public void createProductCategory(CreateOrUpdateProductCategory productCategoryDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    this.loanProductDao.validateNameIsAvailableForCategory(productCategoryDto.getProductCategoryName(), productCategoryDto.getProductTypeEntityId());
    HibernateTransactionHelper transactionHelper = new HibernateTransactionHelperForStaticHibernateUtil();
    try {
        // FIXME - delegate to globalNumberGenerationStrategy
        StringBuilder globalPrdOfferingNum = new StringBuilder();
        globalPrdOfferingNum.append(userContext.getBranchId());
        globalPrdOfferingNum.append("-");
        Short maxPrdID = legacyProductCategoryDao.getMaxPrdCategoryId();
        globalPrdOfferingNum.append(StringUtils.leftPad(String.valueOf(maxPrdID != null ? maxPrdID + 1 : ProductDefinitionConstants.DEFAULTMAX), 3, '0'));
        String globalNumber = globalPrdOfferingNum.toString();
        ProductTypeEntity productType = new ProductTypeEntity(productCategoryDto.getProductTypeEntityId());
        ProductCategoryBO productCategoryBO = new ProductCategoryBO(productType, productCategoryDto.getProductCategoryName(), productCategoryDto.getProductCategoryDesc(), globalNumber);
        transactionHelper.startTransaction();
        this.loanProductDao.save(productCategoryBO);
        transactionHelper.commitTransaction();
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    } 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) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) 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) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ProductTypeEntity(org.mifos.accounts.productdefinition.business.ProductTypeEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 10 with MifosUser

use of org.mifos.security.MifosUser in project head by mifos.

the class AdminServiceFacadeWebTier method createLoanProduct.

@Override
public PrdOfferingDto createLoanProduct(LoanProductRequest loanProductRequest) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    LoanOfferingBO loanProduct = this.loanProductAssembler.fromDto(user, loanProductRequest);
    HibernateTransactionHelper transactionHelper = new HibernateTransactionHelperForStaticHibernateUtil();
    try {
        transactionHelper.startTransaction();
        this.loanProductDao.save(loanProduct);
        transactionHelper.commitTransaction();
        return loanProduct.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) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) MifosUser(org.mifos.security.MifosUser) 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)

Aggregations

MifosUser (org.mifos.security.MifosUser)205 UserContext (org.mifos.security.util.UserContext)134 MifosRuntimeException (org.mifos.core.MifosRuntimeException)88 BusinessRuleException (org.mifos.service.BusinessRuleException)74 ArrayList (java.util.ArrayList)52 AccountException (org.mifos.accounts.exceptions.AccountException)52 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)49 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)44 PersistenceException (org.mifos.framework.exceptions.PersistenceException)43 ServiceException (org.mifos.framework.exceptions.ServiceException)43 CustomerBO (org.mifos.customers.business.CustomerBO)38 Authentication (org.springframework.security.core.Authentication)38 SecurityContext (org.springframework.security.core.context.SecurityContext)38 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)38 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)36 Money (org.mifos.framework.util.helpers.Money)35 LocalDate (org.joda.time.LocalDate)33 LoanBO (org.mifos.accounts.loan.business.LoanBO)33 MifosUserBuilder (org.mifos.builders.MifosUserBuilder)29 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)26