Search in sources :

Example 16 with MifosUser

use of org.mifos.security.MifosUser 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 17 with MifosUser

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

the class CustomerServiceFacadeWebTier method search.

@Override
public CustomerSearch search(String searchString) throws ApplicationException {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    if (searchString == null) {
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    String normalisedSearchString = org.mifos.framework.util.helpers.SearchUtils.normalizeSearchString(searchString);
    if (normalisedSearchString.equals("")) {
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    String officeId = userContext.getBranchId().toString();
    String officeName = this.officeDao.findOfficeDtoById(userContext.getBranchId()).getName();
    PersonnelBO loggedInUser = personnelDao.findPersonnelById(userContext.getId());
    QueryResult searchResult = customerDao.search(normalisedSearchString, loggedInUser);
    return new CustomerSearch(searchResult, searchString, officeId, officeName);
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser)

Example 18 with MifosUser

use of org.mifos.security.MifosUser 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 19 with MifosUser

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

the class ClientServiceFacadeWebTier method retrieveMfiInfoForEdit.

@Override
public ClientMfiInfoDto retrieveMfiInfoForEdit(String clientSystemId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    ClientBO client = this.customerDao.findClientBySystemId(clientSystemId);
    String groupDisplayName = "";
    String centerDisplayName = "";
    if (client.getParentCustomer() != null) {
        groupDisplayName = client.getParentCustomer().getDisplayName();
        if (client.getParentCustomer().getParentCustomer() != null) {
            centerDisplayName = client.getParentCustomer().getParentCustomer().getDisplayName();
        }
    }
    List<PersonnelDto> loanOfficersList = new ArrayList<PersonnelDto>();
    if (!client.isClientUnderGroup()) {
        CenterCreation centerCreation = new CenterCreation(client.getOffice().getOfficeId(), userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
        loanOfficersList = this.personnelDao.findActiveLoanOfficersForOffice(centerCreation);
    }
    CustomerDetailDto customerDetail = client.toCustomerDetailDto();
    ClientDetailDto clientDetail = client.toClientDetailDto(ClientRules.isFamilyDetailsRequired());
    return new ClientMfiInfoDto(groupDisplayName, centerDisplayName, loanOfficersList, customerDetail, clientDetail);
}
Also used : UserContext(org.mifos.security.util.UserContext) CenterCreation(org.mifos.dto.domain.CenterCreation) ClientBO(org.mifos.customers.client.business.ClientBO) ClientDetailDto(org.mifos.dto.screen.ClientDetailDto) ArrayList(java.util.ArrayList) CustomerDetailDto(org.mifos.dto.domain.CustomerDetailDto) PersonnelDto(org.mifos.dto.domain.PersonnelDto) MifosUser(org.mifos.security.MifosUser) ClientMfiInfoDto(org.mifos.dto.screen.ClientMfiInfoDto)

Example 20 with MifosUser

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

the class ClientServiceFacadeWebTier method removeGroupMembership.

@Override
public void removeGroupMembership(String globalCustNum, Short loanOfficerId, String comment) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(mifosUser);
    ClientBO client = this.customerDao.findClientBySystemId(globalCustNum);
    client.updateDetails(userContext);
    PersonnelBO loanOfficer = null;
    if (loanOfficerId != null) {
        loanOfficer = this.personnelDao.findPersonnelById(loanOfficerId);
    }
    PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
    java.sql.Date commentDate = new DateTimeService().getCurrentJavaSqlDate();
    CustomerNoteEntity accountNotesEntity = new CustomerNoteEntity(comment, commentDate, loggedInUser, client);
    customerService.removeGroupMembership(client, loanOfficer, accountNotesEntity, userContext.getLocaleId());
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) ClientBO(org.mifos.customers.client.business.ClientBO) MifosUser(org.mifos.security.MifosUser) DateTimeService(org.mifos.framework.util.DateTimeService)

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