Search in sources :

Example 21 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class PersonnelServiceFacadeWebTier method unLockUserAccount.

@Override
public void unLockUserAccount(String globalAccountNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    PersonnelBO personnel = this.personnelDao.findByGlobalPersonnelNum(globalAccountNum);
    personnel.updateDetails(userContext);
    try {
        this.transactionHelper.startTransaction();
        personnel.unlockPersonnel();
        this.personnelDao.save(personnel);
        this.transactionHelper.commitTransaction();
    } catch (Exception e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    }
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) ValidationException(org.mifos.framework.exceptions.ValidationException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 22 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class GroupLoanAccountServiceFacadeWebTier method retrieveLoanInformation.

@Override
public LoanInformationDto retrieveLoanInformation(String globalAccountNum) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNum);
    try {
        personnelDao.checkAccessPermission(userContext, loan.getOfficeId(), loan.getCustomer().getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    String fundName = null;
    if (loan.getFund() != null) {
        fundName = loan.getFund().getFundName();
    }
    boolean activeSurveys = false;
    List<SurveyDto> accountSurveys = loanDao.getAccountSurveyDto(loan.getAccountId());
    LoanSummaryDto loanSummary = generateGroupLoanSummaryDto(new ArrayList<LoanBO>(loan.getMemberAccounts()));
    LoanPerformanceHistoryEntity performanceHistory = loan.getPerformanceHistory();
    LoanPerformanceHistoryDto loanPerformanceHistory = new LoanPerformanceHistoryDto(performanceHistory.getNoOfPayments(), performanceHistory.getTotalNoOfMissedPayments(), performanceHistory.getDaysInArrears(), performanceHistory.getLoanMaturityDate());
    Set<AccountFeesDto> accountFeesDtos = new HashSet<AccountFeesDto>();
    if (!loan.getAccountFees().isEmpty()) {
        for (AccountFeesEntity accountFeesEntity : loan.getAccountFees()) {
            AccountFeesDto accountFeesDto = new AccountFeesDto(accountFeesEntity.getFees().getFeeFrequency().getFeeFrequencyType().getId(), (accountFeesEntity.getFees().getFeeFrequency().getFeePayment() != null ? accountFeesEntity.getFees().getFeeFrequency().getFeePayment().getId() : null), accountFeesEntity.getFeeStatus(), accountFeesEntity.getFees().getFeeName(), accountFeesEntity.getAccountFeeAmount().toString(), getMeetingRecurrence(accountFeesEntity.getFees().getFeeFrequency().getFeeMeetingFrequency(), userContext), accountFeesEntity.getFees().getFeeId());
            accountFeesDtos.add(accountFeesDto);
        }
    }
    Set<AccountPenaltiesDto> accountPenaltiesDtos = new HashSet<AccountPenaltiesDto>();
    if (!loan.getAccountPenalties().isEmpty()) {
        for (AccountPenaltiesEntity accountPenaltiesEntity : loan.getAccountPenalties()) {
            accountPenaltiesDtos.add(new AccountPenaltiesDto(accountPenaltiesEntity.getPenalty().getPenaltyFrequency().getId(), accountPenaltiesEntity.getPenaltyStatus(), accountPenaltiesEntity.getPenalty().getPenaltyName(), accountPenaltiesEntity.getAccountPenaltyAmount().toString(), accountPenaltiesEntity.getPenalty().getPenaltyFrequency().getName(), accountPenaltiesEntity.getPenalty().getPenaltyId()));
        }
    }
    Set<String> accountFlagNames = getAccountStateFlagEntityNames(loan.getAccountFlags());
    Short accountStateId = loan.getAccountState().getId();
    String accountStateName = getAccountStateName(accountStateId);
    boolean disbursed = AccountState.isDisbursed(accountStateId);
    String gracePeriodTypeName = getGracePeriodTypeName(loan.getGracePeriodType().getId());
    Short interestType = loan.getInterestType().getId();
    String interestTypeName = getInterestTypeName(interestType);
    List<CustomerNoteDto> recentNoteDtos = new ArrayList<CustomerNoteDto>();
    List<AccountNotesEntity> recentNotes = loan.getRecentAccountNotes();
    for (AccountNotesEntity accountNotesEntity : recentNotes) {
        recentNoteDtos.add(new CustomerNoteDto(accountNotesEntity.getCommentDate(), accountNotesEntity.getComment(), accountNotesEntity.getPersonnelName()));
    }
    CustomValueDto customValueDto = legacyMasterDao.getLookUpEntity(MasterConstants.COLLATERAL_TYPES);
    List<CustomValueListElementDto> collateralTypes = customValueDto.getCustomValueListElements();
    String collateralTypeName = null;
    for (CustomValueListElementDto collateralType : collateralTypes) {
        if (collateralType.getId() == loan.getCollateralTypeId()) {
            collateralTypeName = collateralType.getName();
            break;
        }
    }
    Boolean groupLoanWithMembers = AccountingRules.isGroupLoanWithMembers();
    return new LoanInformationDto(loan.getLoanOffering().getPrdOfferingName(), globalAccountNum, accountStateId, accountStateName, disbursed, accountFlagNames, loan.getDisbursementDate(), loan.isRedone(), loan.getBusinessActivityId(), loan.getAccountId(), gracePeriodTypeName, interestType, interestTypeName, loan.getCustomer().getCustomerId(), loan.getAccountType().getAccountTypeId(), loan.getOffice().getOfficeId(), loan.getPersonnel().getPersonnelId(), loan.getNextMeetingDate(), loan.getTotalAmountDue().toString(), loan.getTotalAmountInArrears().toString(), loanSummary, loan.getLoanActivityDetails().isEmpty() ? false : true, loan.getInterestRate(), loan.isInterestDeductedAtDisbursement(), loan.getLoanOffering().getLoanOfferingMeeting().getMeeting().getMeetingDetails().getRecurAfter(), loan.getLoanOffering().getLoanOfferingMeeting().getMeeting().getMeetingDetails().getRecurrenceType().getRecurrenceId(), loan.getLoanOffering().isPrinDueLastInst(), loan.getNoOfInstallments(), loan.getMaxMinNoOfInstall().getMinNoOfInstall(), loan.getMaxMinNoOfInstall().getMaxNoOfInstall(), loan.getGracePeriodDuration(), fundName, loan.getCollateralTypeId(), collateralTypeName, loan.getCollateralNote(), loan.getExternalId(), accountFeesDtos, loan.getCreatedDate(), loanPerformanceHistory, loan.getCustomer().isGroup(), getRecentActivityView(globalAccountNum), activeSurveys, accountSurveys, loan.getCustomer().getDisplayName(), loan.getCustomer().getGlobalCustNum(), loan.getOffice().getOfficeName(), recentNoteDtos, accountPenaltiesDtos, groupLoanWithMembers);
}
Also used : AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity) SurveyDto(org.mifos.dto.domain.SurveyDto) CustomValueListElementDto(org.mifos.application.master.business.CustomValueListElementDto) ArrayList(java.util.ArrayList) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) AccountFeesDto(org.mifos.dto.screen.AccountFeesDto) CustomerNoteDto(org.mifos.dto.domain.CustomerNoteDto) LoanPerformanceHistoryDto(org.mifos.dto.screen.LoanPerformanceHistoryDto) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) LoanPerformanceHistoryEntity(org.mifos.accounts.loan.business.LoanPerformanceHistoryEntity) HashSet(java.util.HashSet) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) AccountPenaltiesDto(org.mifos.dto.screen.AccountPenaltiesDto) AccountException(org.mifos.accounts.exceptions.AccountException) LoanSummaryDto(org.mifos.dto.screen.LoanSummaryDto) LoanInformationDto(org.mifos.dto.screen.LoanInformationDto) CustomValueDto(org.mifos.application.master.business.CustomValueDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 23 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class GroupServiceFacadeWebTier method createNewGroup.

@Override
public CustomerDetailsDto createNewGroup(GroupCreationDetail groupCreationDetail, MeetingDto meetingDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
    userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
    GroupBO group;
    try {
        List<AccountFeesEntity> feesForCustomerAccount = convertFeeViewsToAccountFeeEntities(groupCreationDetail.getFeesToApply());
        PersonnelBO formedBy = this.personnelDao.findPersonnelById(groupCreationDetail.getLoanOfficerId());
        Short officeId;
        String groupName = groupCreationDetail.getDisplayName();
        CustomerStatus customerStatus = CustomerStatus.fromInt(groupCreationDetail.getCustomerStatus());
        String externalId = groupCreationDetail.getExternalId();
        boolean trained = groupCreationDetail.isTrained();
        DateTime trainedOn = groupCreationDetail.getTrainedOn();
        DateTime mfiJoiningDate = groupCreationDetail.getMfiJoiningDate();
        DateTime activationDate = groupCreationDetail.getActivationDate();
        AddressDto dto = groupCreationDetail.getAddressDto();
        Address address = null;
        if (dto != null) {
            address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
        }
        MeetingBO groupMeeting = null;
        if (meetingDto != null) {
            groupMeeting = new MeetingFactory().create(meetingDto);
            groupMeeting.setUserContext(userContext);
        }
        if (ClientRules.getCenterHierarchyExists()) {
            CenterBO parentCustomer = this.customerDao.findCenterBySystemId(groupCreationDetail.getParentSystemId());
            //                loanOfficerId = parentCustomer.getPersonnel().getPersonnelId();
            officeId = parentCustomer.getOffice().getOfficeId();
            groupMeeting = parentCustomer.getCustomerMeetingValue();
            group = GroupBO.createGroupWithCenterAsParent(userContext, groupName, formedBy, parentCustomer, address, externalId, trained, trainedOn, customerStatus, mfiJoiningDate, activationDate);
        } else {
            // create group without center as parent
            Short loanOfficerId = groupCreationDetail.getLoanOfficerId() != null ? groupCreationDetail.getLoanOfficerId() : userContext.getId();
            officeId = groupCreationDetail.getOfficeId();
            OfficeBO office = this.officeDao.findOfficeById(groupCreationDetail.getOfficeId());
            PersonnelBO loanOfficer = this.personnelDao.findPersonnelById(loanOfficerId);
            int numberOfCustomersInOfficeAlready = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
            group = GroupBO.createGroupAsTopOfCustomerHierarchy(userContext, groupName, formedBy, groupMeeting, loanOfficer, office, address, externalId, trained, trainedOn, customerStatus, numberOfCustomersInOfficeAlready, mfiJoiningDate, activationDate);
        }
        try {
            personnelDao.checkAccessPermission(userContext, group.getOfficeId(), group.getLoanOfficerId());
        } catch (AccountException e) {
            throw new MifosRuntimeException("Access denied!", e);
        }
        this.customerService.createGroup(group, groupMeeting, feesForCustomerAccount);
        return new CustomerDetailsDto(group.getCustomerId(), group.getGlobalCustNum());
    } catch (CustomerException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) Address(org.mifos.framework.business.util.Address) UserContext(org.mifos.security.util.UserContext) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CenterBO(org.mifos.customers.center.business.CenterBO) MifosUser(org.mifos.security.MifosUser) CustomerAddressDto(org.mifos.dto.domain.CustomerAddressDto) AddressDto(org.mifos.dto.domain.AddressDto) MeetingFactory(org.mifos.application.meeting.business.MeetingFactory) DateTime(org.joda.time.DateTime) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus) GroupBO(org.mifos.customers.group.business.GroupBO) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 24 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class GroupServiceFacadeWebTier method retrieveGroupDetailsForUpdate.

@Override
public CenterDto retrieveGroupDetailsForUpdate(String globalCustNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    List<PersonnelDto> activeLoanOfficersForBranch = new ArrayList<PersonnelDto>();
    GroupBO group = this.customerDao.findGroupBySystemId(globalCustNum);
    Short officeId = group.getOffice().getOfficeId();
    String searchId = group.getSearchId();
    Short loanOfficerId = extractLoanOfficerId(group);
    boolean isCenterHierarchyExists = ClientRules.getCenterHierarchyExists();
    if (!isCenterHierarchyExists) {
        CenterCreation centerCreation = new CenterCreation(officeId, userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
        activeLoanOfficersForBranch = personnelDao.findActiveLoanOfficersForOffice(centerCreation);
    }
    List<CustomerDto> customerList = customerDao.findClientsThatAreNotCancelledOrClosed(searchId, officeId);
    List<CustomerPositionDto> customerPositionDtos = generateCustomerPositionViews(group, userContext.getLocaleId());
    DateTime mfiJoiningDate = new DateTime();
    String mfiJoiningDateAsString = "";
    if (group.getMfiJoiningDate() != null) {
        mfiJoiningDate = new DateTime(group.getMfiJoiningDate());
        mfiJoiningDateAsString = DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), group.getMfiJoiningDate().toString());
    }
    AddressDto address = null;
    if (group.getAddress() != null) {
        address = Address.toDto(group.getAddress());
    }
    return new CenterDto(loanOfficerId, group.getCustomerId(), group.getGlobalCustNum(), mfiJoiningDate, mfiJoiningDateAsString, group.getExternalId(), address, customerPositionDtos, customerList, activeLoanOfficersForBranch, isCenterHierarchyExists);
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) CustomerDto(org.mifos.dto.domain.CustomerDto) PersonnelDto(org.mifos.dto.domain.PersonnelDto) CenterDto(org.mifos.dto.domain.CenterDto) MifosUser(org.mifos.security.MifosUser) CustomerAddressDto(org.mifos.dto.domain.CustomerAddressDto) AddressDto(org.mifos.dto.domain.AddressDto) DateTime(org.joda.time.DateTime) CenterCreation(org.mifos.dto.domain.CenterCreation) GroupBO(org.mifos.customers.group.business.GroupBO) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto)

Example 25 with UserContext

use of org.mifos.security.util.UserContext in project head by mifos.

the class GroupServiceFacadeWebTier method transferGroupToCenter.

@Override
public CustomerDetailDto transferGroupToCenter(String groupSystemId, String centerSystemId, Integer previousGroupVersionNo) {
    try {
        MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        UserContext userContext = toUserContext(user);
        CenterBO transferToCenter = this.customerDao.findCenterBySystemId(centerSystemId);
        transferToCenter.updateDetails(userContext);
        GroupBO group = this.customerDao.findGroupBySystemId(groupSystemId);
        group.updateDetails(userContext);
        checkVersionMismatch(previousGroupVersionNo, group.getVersionNo());
        String groupGlobalCustNum = this.customerService.transferGroupTo(group, transferToCenter);
        GroupBO transferedGroup = this.customerDao.findGroupBySystemId(groupGlobalCustNum);
        return transferedGroup.toCustomerDetailDto();
    } 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) CenterBO(org.mifos.customers.center.business.CenterBO) GroupBO(org.mifos.customers.group.business.GroupBO) MifosUser(org.mifos.security.MifosUser)

Aggregations

UserContext (org.mifos.security.util.UserContext)369 MifosUser (org.mifos.security.MifosUser)134 MifosRuntimeException (org.mifos.core.MifosRuntimeException)102 ArrayList (java.util.ArrayList)97 Test (org.junit.Test)81 BusinessRuleException (org.mifos.service.BusinessRuleException)75 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)72 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)65 AccountException (org.mifos.accounts.exceptions.AccountException)55 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)49 Money (org.mifos.framework.util.helpers.Money)46 LoanBO (org.mifos.accounts.loan.business.LoanBO)45 LocalDate (org.joda.time.LocalDate)44 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)43 ServiceException (org.mifos.framework.exceptions.ServiceException)43 PersistenceException (org.mifos.framework.exceptions.PersistenceException)38 CustomerBO (org.mifos.customers.business.CustomerBO)37 MeetingBO (org.mifos.application.meeting.business.MeetingBO)34 Date (java.util.Date)31 CustomerException (org.mifos.customers.exceptions.CustomerException)31