Search in sources :

Example 21 with MifosUser

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

the class ClientServiceFacadeWebTier method previewClient.

@Override
public ProcessRulesDto previewClient(String governmentId, DateTime dateOfBirth, String clientName, boolean defaultFeeRemoval, Short officeId, Short loanOfficerId) {
    try {
        MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        UserContext userContext = toUserContext(user);
        boolean clientPendingApprovalStateEnabled = ProcessFlowRules.isClientPendingApprovalStateEnabled();
        boolean governmentIdValidationFailing = false;
        boolean duplicateNameOnClosedClient = false;
        boolean duplicateNameOnBlackListedClient = false;
        boolean governmentIdValidationUnclosedFailing = false;
        boolean duplicateNameOnClient = false;
        List<ClientBO> matchedClients = new ArrayList<ClientBO>();
        List<ClientBO> temp;
        if (defaultFeeRemoval) {
            customerDao.checkPermissionForDefaultFeeRemoval(userContext, officeId, loanOfficerId);
        }
        if (StringUtils.isNotBlank(governmentId)) {
            temp = this.customerDao.validateGovernmentIdForUnclosedClient(governmentId);
            if (temp != null) {
                matchedClients.addAll(temp);
            }
            governmentIdValidationUnclosedFailing = temp != null && temp.size() > 0;
            if (!governmentIdValidationUnclosedFailing) {
                temp = this.customerDao.validateGovernmentIdForClient(governmentId);
                if (temp != null) {
                    matchedClients.addAll(temp);
                }
                governmentIdValidationFailing = temp != null && temp.size() > 0;
            }
        }
        if (!governmentIdValidationFailing && !governmentIdValidationUnclosedFailing) {
            temp = this.customerDao.validateForBlackListedClientsOnNameAndDob(clientName, dateOfBirth);
            if (temp != null) {
                matchedClients.addAll(temp);
            }
            duplicateNameOnBlackListedClient = temp != null && temp.size() > 0;
            if (!duplicateNameOnBlackListedClient) {
                temp = this.customerDao.validateForClosedClientsOnNameAndDob(clientName, dateOfBirth);
                if (temp != null) {
                    matchedClients.addAll(temp);
                }
                duplicateNameOnClosedClient = temp != null && temp.size() > 0;
                if (!duplicateNameOnClosedClient) {
                    temp = this.customerDao.validateForClientsOnName(clientName);
                    if (temp != null) {
                        matchedClients.addAll(temp);
                    }
                    duplicateNameOnClient = temp != null && temp.size() > 0;
                }
            }
        }
        List<MatchedClientDto> matched = new ArrayList<MatchedClientDto>();
        for (ClientBO client : matchedClients) {
            matched.add(new MatchedClientDto(client.getGlobalCustNum(), client.getDisplayName(), client.getAddress().getPhoneNumber(), client.getGovernmentId(), client.getDisplayAddress(), client.getOffice().getOfficeName(), client.getOffice().getGlobalOfficeNum()));
        }
        return new ProcessRulesDto(clientPendingApprovalStateEnabled, governmentIdValidationFailing, duplicateNameOnClosedClient, duplicateNameOnBlackListedClient, governmentIdValidationUnclosedFailing, duplicateNameOnClient, matched);
    } catch (CustomerException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : ProcessRulesDto(org.mifos.dto.domain.ProcessRulesDto) CustomerException(org.mifos.customers.exceptions.CustomerException) BusinessRuleException(org.mifos.service.BusinessRuleException) UserContext(org.mifos.security.util.UserContext) ClientBO(org.mifos.customers.client.business.ClientBO) MatchedClientDto(org.mifos.dto.domain.MatchedClientDto) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser)

Example 22 with MifosUser

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

the class ClientServiceFacadeWebTier method updateFamilyInfo.

@Override
public void updateFamilyInfo(ClientFamilyInfoUpdate clientFamilyInfoUpdate) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        this.customerService.updateClientFamilyInfo(userContext, clientFamilyInfoUpdate);
    } 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) MifosUser(org.mifos.security.MifosUser)

Example 23 with MifosUser

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

the class ClientServiceFacadeWebTier method retreiveClientDetailsForRemovalFromGroup.

@Override
public ClientRemovalFromGroupDto retreiveClientDetailsForRemovalFromGroup(String globalCustNum) {
    try {
        MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        UserContext userContext = toUserContext(user);
        ClientBO client = this.customerDao.findClientBySystemId(globalCustNum);
        client.updateDetails(userContext);
        client.checkIfClientIsATitleHolder();
        List<OfficeDetailsDto> activeBranches = this.officeDao.findActiveBranches(userContext.getBranchId());
        boolean isCenterHierarchyExists = ClientRules.getCenterHierarchyExists();
        boolean isActive = client.isActive();
        Short loanOfficerId = client.getPersonnel().getPersonnelId();
        CenterCreation clientDetails = new CenterCreation(client.getOfficeId(), userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
        List<PersonnelDto> loanOfficers = this.personnelDao.findActiveLoanOfficersForOffice(clientDetails);
        return new ClientRemovalFromGroupDto(client.getGlobalCustNum(), isActive, isCenterHierarchyExists, loanOfficerId, loanOfficers, activeBranches);
    } catch (CustomerException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : ClientRemovalFromGroupDto(org.mifos.dto.screen.ClientRemovalFromGroupDto) CustomerException(org.mifos.customers.exceptions.CustomerException) UserContext(org.mifos.security.util.UserContext) ClientBO(org.mifos.customers.client.business.ClientBO) PersonnelDto(org.mifos.dto.domain.PersonnelDto) MifosUser(org.mifos.security.MifosUser) OfficeDetailsDto(org.mifos.dto.domain.OfficeDetailsDto) BusinessRuleException(org.mifos.service.BusinessRuleException) CenterCreation(org.mifos.dto.domain.CenterCreation)

Example 24 with MifosUser

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

the class OfficeServiceFacadeWebTier method retrieveAllNonBranchOfficesApplicableToLoggedInUser.

@Override
public List<OfficeDto> retrieveAllNonBranchOfficesApplicableToLoggedInUser() {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    OfficeDto office = officeDao.findOfficeDtoById(user.getBranchId());
    return officeDao.findNonBranchesOnlyWithParentsMatching(office.getSearchId());
}
Also used : OfficeDto(org.mifos.dto.domain.OfficeDto) MifosUser(org.mifos.security.MifosUser)

Example 25 with MifosUser

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

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