Search in sources :

Example 51 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException in project head by mifos.

the class WebTierFundServiceFacade method createFund.

@Override
public void createFund(FundDto fundDto) {
    List<FundCodeEntity> fundCodeEntities = fundDao.findAllFundCodes();
    Short fundCodeId = Short.valueOf(fundDto.getCode().getId());
    FundCodeEntity fundCode = null;
    for (FundCodeEntity fundCodeEntity : fundCodeEntities) {
        if (fundCodeEntity.getFundCodeId().equals(fundCodeId)) {
            fundCode = fundCodeEntity;
            break;
        }
    }
    FundBO fundBO = new FundBO(fundCode, fundDto.getName());
    if (this.fundDao.countOfFundByName(fundDto.getName().trim()) > 0) {
        throw new org.mifos.service.BusinessRuleException(FundConstants.DUPLICATE_FUNDNAME_EXCEPTION);
    }
    try {
        StaticHibernateUtil.startTransaction();
        this.fundDao.save(fundBO);
        StaticHibernateUtil.commitTransaction();
    } catch (Exception e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new MifosRuntimeException(e.getMessage(), e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : FundCodeEntity(org.mifos.application.master.business.FundCodeEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) FundBO(org.mifos.accounts.fund.business.FundBO) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 52 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException in project head by mifos.

the class FeeServiceImpl method remove.

@Override
public void remove(FeeBO fee, boolean isInProducts, boolean isFeeInUsedLoan, boolean remove) {
    try {
        hibernateTransactionHelper.startTransaction();
        this.feeDao.remove(fee, isInProducts, isFeeInUsedLoan, remove);
        hibernateTransactionHelper.commitTransaction();
    } catch (MifosRuntimeException e) {
        throw new MifosRuntimeException(e.getMessage());
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : FeeException(org.mifos.accounts.fees.exceptions.FeeException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 53 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException in project head by mifos.

the class ImportClientsServiceFacadeWebTier method save.

@Override
public ParsedClientsDto save(ParsedClientsDto parsedClientsDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
    userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
    DateTimeService dateTimeService = new DateTimeService();
    /* Construct ClientBO objects */
    List<NewClientDto> newClients = new ArrayList<NewClientDto>();
    for (ImportedClientDetail importedClient : parsedClientsDto.getSuccessfullyParsedRows()) {
        String secondMiddleName = null;
        ClientCreationDetail clientCreationDetail = importedClient.getClientCreationDetail();
        PersonnelBO formedBy = null;
        /* Client name details */
        ClientNameDetailDto clientNameDetails = clientCreationDetail.getClientNameDetailDto();
        ClientNameDetailEntity clientNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientNameDetails);
        ClientDetailEntity clientDetailEntity = new ClientDetailEntity();
        clientDetailEntity.updateClientDetails(clientCreationDetail.getClientPersonalDetailDto());
        String clientFirstName = clientNameDetails.getFirstName();
        String clientLastName = clientNameDetails.getLastName();
        String secondLastName = clientNameDetails.getSecondLastName();
        /* Spouse/father name details */
        ClientNameDetailEntity spouseFatherNameDetailEntity = null;
        if (clientCreationDetail.getSpouseFatherName() != null) {
            spouseFatherNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientCreationDetail.getSpouseFatherName());
        }
        /* Data conversion */
        DateTime dateOfBirth = new DateTime(clientCreationDetail.getDateOfBirth());
        DateTime mfiJoiningDate = new DateTime(clientCreationDetail.getMfiJoiningDate());
        DateTime trainedDateTime = null;
        if (clientCreationDetail.getTrainedDate() != null) {
            trainedDateTime = new DateTime(clientCreationDetail.getTrainedDate());
        }
        /* Status */
        CustomerStatus clientStatus = CustomerStatus.fromInt(clientCreationDetail.getClientStatus());
        CustomerStatus finalStatus = clientStatus;
        if (clientStatus == CustomerStatus.CLIENT_ACTIVE && clientCreationDetail.getActivationDate() == null) {
            clientStatus = CustomerStatus.CLIENT_PENDING;
        }
        /* Address */
        Address address = null;
        if (clientCreationDetail.getAddress() != null) {
            AddressDto dto = clientCreationDetail.getAddress();
            address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
        }
        // empty list
        List<ClientInitialSavingsOfferingEntity> associatedOfferings = new ArrayList<ClientInitialSavingsOfferingEntity>();
        // client object
        ClientBO client;
        if (clientCreationDetail.getGroupFlag() == 1) {
            CustomerBO group = customerDao.findCustomerBySystemId(clientCreationDetail.getParentGroupId());
            if (clientCreationDetail.getFormedBy() != null) {
                formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
            } else {
                formedBy = group.getPersonnel();
            }
            client = ClientBO.createNewInGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, mfiJoiningDate, group, formedBy, clientNameDetailEntity, dateOfBirth, clientCreationDetail.getGovernmentId(), clientCreationDetail.isTrained(), trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, associatedOfferings, clientCreationDetail.getExternalId(), address, clientCreationDetail.getActivationDate());
        } else {
            Short officeId = clientCreationDetail.getOfficeId();
            Short officerId = clientCreationDetail.getLoanOfficerId();
            PersonnelBO loanOfficer = personnelDao.findPersonnelById(officerId);
            OfficeBO office = this.officeDao.findOfficeById(officeId);
            if (clientCreationDetail.getFormedBy() != null) {
                formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
            } else {
                formedBy = loanOfficer;
            }
            int lastSearchIdCustomerValue = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
            /* meeting */
            final MeetingDto meetingDto = importedClient.getMeeting();
            MeetingBO clientMeeting = null;
            if (meetingDto != null) {
                clientMeeting = new MeetingFactory().create(meetingDto);
                clientMeeting.setUserContext(userContext);
            }
            client = ClientBO.createNewOutOfGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, mfiJoiningDate, office, loanOfficer, clientMeeting, formedBy, clientNameDetailEntity, dateOfBirth, clientCreationDetail.getGovernmentId(), clientCreationDetail.isTrained(), trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, associatedOfferings, clientCreationDetail.getExternalId(), address, lastSearchIdCustomerValue);
            if (clientCreationDetail.getActivationDate() != null) {
                client.setCustomerActivationDate(clientCreationDetail.getActivationDate().toDateMidnight().toDate());
            }
        }
        // global id
        if (importedClient.getClientGlobalNum() != null) {
            client.setGlobalCustNum(importedClient.getClientGlobalNum());
        }
        NewClientDto newClient = new NewClientDto(client, finalStatus);
        newClients.add(newClient);
    }
    /* Validate client data */
    for (NewClientDto newClient : newClients) {
        ClientBO client = newClient.getClientBO();
        try {
            client.validate();
            customerDao.validateClientForDuplicateNameOrGovtId(client.getDisplayName(), client.getDateOfBirth(), client.getGovernmentId());
        } catch (CustomerException ex) {
            throw new MifosRuntimeException(ex);
        }
    }
    /* Save clients */
    // empty list
    List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
    try {
        hibernateTransactionHelper.startTransaction();
        for (NewClientDto newClient : newClients) {
            ClientBO client = newClient.getClientBO();
            CustomerStatus finalStatus = newClient.getCustomerStatus();
            // status to pending approval if active
            MeetingBO meeting = client.getCustomerMeetingValue();
            customerDao.save(client);
            hibernateTransactionHelper.flushSession();
            CalendarEvent applicableCalendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(client.getOfficeId());
            CustomerAccountBO customerAccount = customerAccountFactory.create(client, accountFees, meeting, applicableCalendarEvents);
            client.addAccount(customerAccount);
            customerDao.save(client);
            hibernateTransactionHelper.flushSession();
            if (client.getParentCustomer() != null) {
                customerDao.save(client.getParentCustomer());
            }
            if (client.getGlobalCustNum() == null) {
                client.generateGlobalCustomerNumber();
            }
            client.generateSearchId();
            customerDao.save(client);
            hibernateTransactionHelper.flushSession();
            if (client.getParentCustomer() != null) {
                customerDao.save(client.getParentCustomer());
            }
            /* activate client */
            if (finalStatus == CustomerStatus.CLIENT_ACTIVE) {
                hibernateTransactionHelper.flushSession();
                hibernateTransactionHelper.beginAuditLoggingFor(client);
                client.clearCustomerFlagsIfApplicable(client.getStatus(), finalStatus);
                client.updateCustomerStatus(finalStatus);
                // changeStatus(client, oldStatus, newStatus);
                if (client.getParentCustomer() != null) {
                    CustomerHierarchyEntity hierarchy = new CustomerHierarchyEntity(client, client.getParentCustomer());
                    client.addCustomerHierarchy(hierarchy);
                }
                if (client.getCustomerActivationDate() != null) {
                    client.setCustomerActivationDate(client.getCustomerActivationDate());
                } else {
                    client.setCustomerActivationDate(dateTimeService.getCurrentJavaDateTime());
                }
                customerAccount.createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(client, accountFees, meeting, applicableCalendarEvents, new DateTime(client.getCustomerActivationDate()));
                customerDao.save(client);
            }
        }
        hibernateTransactionHelper.commitTransaction();
    } catch (Exception ex) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(ex);
    }
    return parsedClientsDto;
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) Address(org.mifos.framework.business.util.Address) NewClientDto(org.mifos.customers.client.util.helpers.NewClientDto) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ClientBO(org.mifos.customers.client.business.ClientBO) ArrayList(java.util.ArrayList) ClientInitialSavingsOfferingEntity(org.mifos.customers.client.business.ClientInitialSavingsOfferingEntity) MeetingFactory(org.mifos.application.meeting.business.MeetingFactory) DateTime(org.joda.time.DateTime) ClientCreationDetail(org.mifos.dto.domain.ClientCreationDetail) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientNameDetailEntity(org.mifos.customers.client.business.ClientNameDetailEntity) ClientDetailEntity(org.mifos.customers.client.business.ClientDetailEntity) CustomerBO(org.mifos.customers.business.CustomerBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) DateTimeService(org.mifos.framework.util.DateTimeService) CustomerException(org.mifos.customers.exceptions.CustomerException) CustomerHierarchyEntity(org.mifos.customers.business.CustomerHierarchyEntity) UserContext(org.mifos.security.util.UserContext) CalendarEvent(org.mifos.calendar.CalendarEvent) MifosUser(org.mifos.security.MifosUser) AddressDto(org.mifos.dto.domain.AddressDto) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) MeetingDto(org.mifos.dto.domain.MeetingDto) CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus) ImportedClientDetail(org.mifos.dto.domain.ImportedClientDetail) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 54 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException in project head by mifos.

the class ImportTransactionsServiceFacadeWebTier method confirmImport.

@Override
public ParseResultDto confirmImport(String importPluginClassname, String tempFileName) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    FileInputStream fileInput = null;
    try {
        final TransactionImport transactionImport = getInitializedImportPlugin(importPluginClassname, userContext.getId());
        fileInput = new FileInputStream(tempFileName);
        final ParseResultDto importResult = transactionImport.parse(fileInput);
        fileInput.close();
        fileInput = new FileInputStream(tempFileName);
        if (importPluginClassname.equalsIgnoreCase("org.almajmoua.AudiBankXlsImporter")) {
            importResult.setTrxIdsToUndo(transactionImport.storeForUndoImport(fileInput));
        } else {
            transactionImport.store(fileInput);
        }
        return importResult;
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    } finally {
        if (fileInput != null) {
            try {
                fileInput.close();
            } catch (Exception e2) {
                throw new MifosRuntimeException(e2);
            }
        }
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) ParseResultDto(org.mifos.dto.domain.ParseResultDto) FileInputStream(java.io.FileInputStream) TransactionImport(org.mifos.accounts.api.TransactionImport) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 55 with MifosRuntimeException

use of org.mifos.core.MifosRuntimeException in project head by mifos.

the class ImportTransactionsServiceFacadeWebTier method undoFullImport.

@Override
public void undoFullImport(String importTransactionsFileName) {
    MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(mifosUser);
    TreeSet<String> accountsWithAdjustedPayments = new TreeSet<String>();
    try {
        ImportedFilesEntity filesEntity = this.importedFilesService.getImportedFileByName(importTransactionsFileName);
        List<AccountTrxnEntity> trxUndo = new ArrayList<AccountTrxnEntity>(filesEntity.getImportedTrxn());
        List<ImportedAccPaymentDto> accPaymentList = new ArrayList<ImportedAccPaymentDto>();
        for (AccountTrxnEntity trxn : trxUndo) {
            try {
                validateForAdjustedPayments(trxn, accountsWithAdjustedPayments);
                accPaymentList.add(new ImportedAccPaymentDto(trxn.getAccount().getGlobalAccountNum(), trxn.getAccountPayment().getPaymentId()));
            } catch (BusinessRuleException e) {
            //nothing to do   
            }
        }
        for (ImportedAccPaymentDto accDto : accPaymentList) {
            try {
                this.accountServiceFacade.applyHistoricalAdjustment(accDto.getGlobalNum(), accDto.getPaymentId(), IMPORT_UNDONE, userContext.getId(), null);
            } catch (MifosRuntimeException e) {
            // TODO: validation will be added with MIFOS-5779
            }
        }
        this.importedFilesService.saveImportedFileName(filesEntity.getFileName(), filesEntity.getSubmittedBy(), null, Boolean.TRUE, filesEntity.getUndoable());
    } catch (Exception e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) ImportedFilesEntity(org.mifos.application.importexport.business.ImportedFilesEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) AccountTrxnEntity(org.mifos.accounts.business.AccountTrxnEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) TreeSet(java.util.TreeSet) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

MifosRuntimeException (org.mifos.core.MifosRuntimeException)305 PersistenceException (org.mifos.framework.exceptions.PersistenceException)136 ArrayList (java.util.ArrayList)102 BusinessRuleException (org.mifos.service.BusinessRuleException)95 UserContext (org.mifos.security.util.UserContext)94 MifosUser (org.mifos.security.MifosUser)87 AccountException (org.mifos.accounts.exceptions.AccountException)79 ServiceException (org.mifos.framework.exceptions.ServiceException)69 ApplicationException (org.mifos.framework.exceptions.ApplicationException)48 LoanBO (org.mifos.accounts.loan.business.LoanBO)41 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)39 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)37 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)36 LocalDate (org.joda.time.LocalDate)35 CustomerBO (org.mifos.customers.business.CustomerBO)29 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)28 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)27 CustomerException (org.mifos.customers.exceptions.CustomerException)27 Money (org.mifos.framework.util.helpers.Money)27 AccountBO (org.mifos.accounts.business.AccountBO)25