Search in sources :

Example 11 with MifosUser

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

the class CenterServiceFacadeWebTier method updateCenter.

@Override
public void updateCenter(CenterUpdate centerUpdate) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        customerService.updateCenter(userContext, centerUpdate);
    } 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)

Example 12 with MifosUser

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

the class CenterServiceFacadeWebTier method getCenterInformationDto.

@Override
public CenterInformationDto getCenterInformationDto(String globalCustNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    CenterBO center = customerDao.findCenterBySystemId(globalCustNum);
    if (center == null) {
        throw new MifosRuntimeException("Center not found for globalCustNum" + globalCustNum);
    }
    try {
        personnelDao.checkAccessPermission(userContext, center.getOfficeId(), center.getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    CenterDisplayDto centerDisplay = customerDao.getCenterDisplayDto(center.getCustomerId(), userContext);
    Integer centerId = center.getCustomerId();
    String searchId = center.getSearchId();
    Short branchId = centerDisplay.getBranchId();
    CustomerAccountSummaryDto customerAccountSummary = customerDao.getCustomerAccountSummaryDto(centerId);
    CenterPerformanceHistoryDto centerPerformanceHistory = customerDao.getCenterPerformanceHistory(searchId, branchId);
    CustomerAddressDto centerAddress = customerDao.getCustomerAddressDto(center);
    List<CustomerDetailDto> groups = customerDao.getGroupsOtherThanClosedAndCancelledForGroup(searchId, branchId);
    List<CustomerNoteDto> recentCustomerNotes = customerDao.getRecentCustomerNoteDto(centerId);
    List<CustomerPositionOtherDto> customerPositions = customerDao.getCustomerPositionDto(centerId, userContext);
    List<SavingsDetailDto> savingsDetail = customerDao.getSavingsDetailDto(centerId, userContext);
    CustomerMeetingDto customerMeeting = customerDao.getCustomerMeetingDto(center.getCustomerMeeting(), userContext);
    List<AccountBO> allClosedLoanAndSavingsAccounts = customerDao.retrieveAllClosedLoanAndSavingsAccounts(centerId);
    List<SavingsDetailDto> closedSavingsAccounts = new ArrayList<SavingsDetailDto>();
    for (AccountBO closedAccount : allClosedLoanAndSavingsAccounts) {
        if (closedAccount.getAccountType().getAccountTypeId() == AccountTypes.SAVINGS_ACCOUNT.getValue().intValue()) {
            closedSavingsAccounts.add(new SavingsDetailDto(closedAccount.getGlobalAccountNum(), ((SavingsBO) closedAccount).getSavingsOffering().getPrdOfferingName(), closedAccount.getAccountState().getId(), closedAccount.getAccountState().getName(), ((SavingsBO) closedAccount).getSavingsBalance().toString()));
        }
    }
    //new SurveysPersistence().isActiveSurveysForSurveyType(SurveyType.CENTER);
    Boolean activeSurveys = Boolean.FALSE;
    List<SurveyDto> customerSurveys = new ArrayList<SurveyDto>();
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    return new CenterInformationDto(centerDisplay, customerAccountSummary, centerPerformanceHistory, centerAddress, groups, recentCustomerNotes, customerPositions, savingsDetail, customerMeeting, activeSurveys, customerSurveys, customFields, closedSavingsAccounts);
}
Also used : CustomerAccountSummaryDto(org.mifos.dto.domain.CustomerAccountSummaryDto) SurveyDto(org.mifos.dto.domain.SurveyDto) ArrayList(java.util.ArrayList) CenterBO(org.mifos.customers.center.business.CenterBO) CustomerAddressDto(org.mifos.dto.domain.CustomerAddressDto) CenterPerformanceHistoryDto(org.mifos.dto.domain.CenterPerformanceHistoryDto) AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) CustomerMeetingDto(org.mifos.dto.domain.CustomerMeetingDto) CustomerNoteDto(org.mifos.dto.domain.CustomerNoteDto) CustomerDetailDto(org.mifos.dto.domain.CustomerDetailDto) CustomerPositionOtherDto(org.mifos.dto.domain.CustomerPositionOtherDto) CenterInformationDto(org.mifos.dto.domain.CenterInformationDto) SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) MifosUser(org.mifos.security.MifosUser) AccountException(org.mifos.accounts.exceptions.AccountException) CenterDisplayDto(org.mifos.dto.domain.CenterDisplayDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 13 with MifosUser

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

the class CenterServiceFacadeWebTier method createNewCenter.

@Override
public CustomerDetailsDto createNewCenter(CenterCreationDetail createCenterDetail, MeetingDto meetingDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
    userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
    String centerName = createCenterDetail.getDisplayName();
    String externalId = createCenterDetail.getExternalId();
    AddressDto addressDto = createCenterDetail.getAddressDto();
    Address centerAddress = new Address(addressDto.getLine1(), addressDto.getLine2(), addressDto.getLine3(), addressDto.getCity(), addressDto.getState(), addressDto.getCountry(), addressDto.getZip(), addressDto.getPhoneNumber());
    PersonnelBO loanOfficer = this.personnelDao.findPersonnelById(createCenterDetail.getLoanOfficerId());
    OfficeBO centerOffice = this.officeDao.findOfficeById(createCenterDetail.getOfficeId());
    List<AccountFeesEntity> feesForCustomerAccount = createAccountFeeEntities(createCenterDetail.getFeesToApply());
    DateTime mfiJoiningDate = null;
    if (createCenterDetail.getMfiJoiningDate() != null) {
        mfiJoiningDate = createCenterDetail.getMfiJoiningDate().toDateMidnight().toDateTime();
    }
    MeetingBO meeting = new MeetingFactory().create(meetingDto);
    meeting.setUserContext(userContext);
    CenterBO center = CenterBO.createNew(userContext, centerName, mfiJoiningDate, meeting, loanOfficer, centerOffice, centerAddress, externalId, new DateMidnight().toDateTime());
    try {
        personnelDao.checkAccessPermission(userContext, center.getOfficeId(), center.getLoanOfficerId());
    } catch (AccountException e) {
        throw new MifosRuntimeException("Access denied!", e);
    }
    this.customerService.createCenter(center, meeting, feesForCustomerAccount);
    return new CustomerDetailsDto(center.getCustomerId(), center.getGlobalCustNum());
}
Also used : 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) AccountException(org.mifos.accounts.exceptions.AccountException) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) DateMidnight(org.joda.time.DateMidnight) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 14 with MifosUser

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

the class CenterServiceFacadeWebTier method retrieveCustomerNote.

@Override
public CustomerNoteFormDto retrieveCustomerNote(String globalCustNum) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    CustomerBO customer = this.customerDao.findCustomerBySystemId(globalCustNum);
    PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
    Integer customerLevel = customer.getCustomerLevel().getId().intValue();
    String globalNum = customer.getGlobalCustNum();
    String displayName = customer.getDisplayName();
    LocalDate commentDate = new LocalDate();
    String commentUser = loggedInUser.getDisplayName();
    return new CustomerNoteFormDto(globalNum, displayName, customerLevel, commentDate, commentUser, "");
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) CustomerBO(org.mifos.customers.business.CustomerBO) MifosUser(org.mifos.security.MifosUser) CustomerNoteFormDto(org.mifos.dto.screen.CustomerNoteFormDto) LocalDate(org.joda.time.LocalDate)

Example 15 with MifosUser

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

the class CenterServiceFacadeWebTier method addNoteToPersonnel.

@Override
public void addNoteToPersonnel(Short personnelId, String comment) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        PersonnelBO personnel = this.personnelDao.findPersonnelById(personnelId);
        PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
        if (personnel != null) {
            checkPermissionForAddingNotesToPersonnel(userContext, personnel.getOffice().getOfficeId(), personnel.getPersonnelId());
        }
        this.transactionHelper.startTransaction();
        PersonnelNotesEntity personnelNote = new PersonnelNotesEntity(comment, loggedInUser, personnel);
        personnel.addNotes(userContext.getId(), personnelNote);
        this.personnelDao.save(personnel);
        this.transactionHelper.commitTransaction();
    } catch (Exception e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : PersonnelNotesEntity(org.mifos.customers.personnel.business.PersonnelNotesEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) ServiceException(org.mifos.framework.exceptions.ServiceException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) 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