Search in sources :

Example 1 with ConfigurationException

use of org.mifos.config.exceptions.ConfigurationException in project head by mifos.

the class LoanAccountServiceFacadeWebTier method retrieveCustomersThatQualifyForLoans.

@Override
public List<CustomerSearchResultDto> retrieveCustomersThatQualifyForLoans(CustomerSearchDto customerSearchDto, boolean isNewGLIMCreation) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        List<CustomerSearchResultDto> pagedDetails = new ArrayList<CustomerSearchResultDto>();
        QueryResult customerForSavings = customerPersistence.searchGroupClient(customerSearchDto.getSearchTerm(), userContext.getId(), isNewGLIMCreation);
        int position = (customerSearchDto.getPage() - 1) * customerSearchDto.getPageSize();
        List<AccountSearchResultsDto> pagedResults = customerForSavings.get(position, customerSearchDto.getPageSize());
        int i = 1;
        for (AccountSearchResultsDto customerBO : pagedResults) {
            CustomerSearchResultDto customer = new CustomerSearchResultDto();
            customer.setCustomerId(customerBO.getClientId());
            customer.setBranchName(customerBO.getOfficeName());
            customer.setGlobalId(customerBO.getGlobelNo());
            customer.setSearchIndex(i);
            customer.setCenterName(StringUtils.defaultIfEmpty(customerBO.getCenterName(), "--"));
            customer.setGroupName(StringUtils.defaultIfEmpty(customerBO.getGroupName(), "--"));
            customer.setClientName(customerBO.getClientName());
            pagedDetails.add(customer);
            i++;
        }
        return pagedDetails;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    } catch (HibernateSearchException e) {
        throw new MifosRuntimeException(e);
    } catch (ConfigurationException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) AccountSearchResultsDto(org.mifos.accounts.util.helpers.AccountSearchResultsDto) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerSearchResultDto(org.mifos.dto.domain.CustomerSearchResultDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with ConfigurationException

use of org.mifos.config.exceptions.ConfigurationException in project head by mifos.

the class ChartOfAccountsConfig method load.

/**
     * Factory method which loads the Chart of Accounts configuration from the
     * given filename. Given XML filename will be validated against
     * {@link FilePaths#CHART_OF_ACCOUNTS_SCHEMA}.
     *
     * @param chartOfAccountsXml
     *            a relative path to the Chart of Accounts configuration file.
     */
public static ChartOfAccountsConfig load(String chartOfAccountsXml) throws ConfigurationException {
    ChartOfAccountsConfig instance = null;
    Document document = null;
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder parser = dbf.newDocumentBuilder();
        if (FilePaths.CHART_OF_ACCOUNTS_DEFAULT.equals(chartOfAccountsXml)) {
            // default chart of accounts
            document = parser.parse(MifosResourceUtil.getClassPathResourceAsStream(chartOfAccountsXml));
        } else {
            // custom chart of accounts
            document = parser.parse(MifosResourceUtil.getFile(chartOfAccountsXml));
        }
        // create a SchemaFactory capable of understanding XML schemas
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        // load an XML schema
        ClassPathResource schemaFileResource = new ClassPathResource(FilePaths.CHART_OF_ACCOUNTS_SCHEMA);
        Source schemaFile = null;
        if (schemaFileResource.exists()) {
            InputStream in = ChartOfAccountsConfig.class.getClassLoader().getResourceAsStream(FilePaths.CHART_OF_ACCOUNTS_SCHEMA);
            schemaFile = new StreamSource(in);
        } else {
            schemaFile = new StreamSource(MifosResourceUtil.getFile(FilePaths.CHART_OF_ACCOUNTS_SCHEMA));
        }
        Schema schema = factory.newSchema(schemaFile);
        // create a Validator instance and validate document
        Validator validator = schema.newValidator();
        validator.validate(new DOMSource(document));
    } catch (IOException e) {
        throw new ConfigurationException(e);
    } catch (SAXException e) {
        throw new ConfigurationException(e);
    } catch (ParserConfigurationException e) {
        throw new ConfigurationException(e);
    }
    instance = new ChartOfAccountsConfig();
    instance.coaDocument = document;
    return instance;
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Schema(javax.xml.validation.Schema) IOException(java.io.IOException) Document(org.w3c.dom.Document) ClassPathResource(org.springframework.core.io.ClassPathResource) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Validator(javax.xml.validation.Validator)

Example 3 with ConfigurationException

use of org.mifos.config.exceptions.ConfigurationException in project head by mifos.

the class ClientRules method getMinimumAge.

/*
     * reads the maximum age specified in the application configuration file,
     * Also Checks if its in the range of 0 to 150
     */
public static int getMinimumAge() throws ConfigurationException {
    int minimumAge = 0;
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    if (configMgr.containsKey(ClientRules.MinimumAgeForNewClients)) {
        minimumAge = Integer.parseInt(configMgr.getString(ClientRules.MinimumAgeForNewClients));
    } else {
        throw new ConfigurationException("The Minimum Age for a client is not defined in " + MifosConfigurationManager.DEFAULT_CONFIG_PROPS_FILENAME);
    }
    if (minimumAge < 0 || minimumAge > 150) {
        throw new ConfigurationException("The Minimum Age defined in the " + MifosConfigurationManager.DEFAULT_CONFIG_PROPS_FILENAME + "is not within the acceptable range (0 to 150)");
    }
    return minimumAge;
}
Also used : ConfigurationException(org.mifos.config.exceptions.ConfigurationException) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager)

Example 4 with ConfigurationException

use of org.mifos.config.exceptions.ConfigurationException in project head by mifos.

the class DatabaseConfiguration method readVCAPConfiguration.

private void readVCAPConfiguration() throws ConfigurationException {
    final String vcapServicesVar = System.getenv(VCAP_SERVICES_VAR);
    if (vcapServicesVar != null) {
        // use database configuration from the system variable to replace the default config
        final JSONObject json = (JSONObject) JSONSerializer.toJSON(vcapServicesVar);
        String mysqlKey = null;
        @SuppressWarnings("rawtypes") final Iterator iterator = json.keys();
        while (iterator.hasNext()) {
            final String key = (String) iterator.next();
            if (key.startsWith("mysql")) {
                mysqlKey = key;
                break;
            }
        }
        if (mysqlKey == null) {
            throw new ConfigurationException(INVALID_STRUCTURE);
        }
        final JSON mysqlJson = (JSON) json.get(mysqlKey);
        JSONObject dbJson;
        if (mysqlJson.isArray()) {
            final JSONArray mysqlJsonArray = (JSONArray) mysqlJson;
            if (mysqlJsonArray.size() < 1) {
                throw new ConfigurationException(INVALID_STRUCTURE);
            }
            dbJson = (JSONObject) mysqlJsonArray.get(0);
        } else {
            dbJson = (JSONObject) mysqlJson;
        }
        final JSONObject credentialsJson = (JSONObject) dbJson.get("credentials");
        this.dbName = credentialsJson.getString("name");
        this.host = credentialsJson.getString("host");
        this.port = credentialsJson.getString("port");
        this.user = credentialsJson.getString("user");
        this.password = credentialsJson.getString("password");
        this.dbPentahoDW = credentialsJson.getString("dbPentahoDW");
    }
}
Also used : JSONObject(net.sf.json.JSONObject) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) Iterator(java.util.Iterator) JSONArray(net.sf.json.JSONArray) JSON(net.sf.json.JSON)

Example 5 with ConfigurationException

use of org.mifos.config.exceptions.ConfigurationException in project head by mifos.

the class ApplicationInitializer method dbUpgrade.

public void dbUpgrade(ApplicationContext applicationContext) throws ConfigurationException, PersistenceException, FinancialException, TaskSystemException {
    logger.info("Logger has been initialised");
    initializeHibernate(applicationContext);
    logger.info(getDatabaseConnectionInfo());
    // if a database upgrade loads an instance of Money then MoneyCompositeUserType needs the default
    // currency
    MoneyCompositeUserType.setDefaultCurrency(AccountingRules.getMifosCurrency(new ConfigurationPersistence()));
    // load the additional currencies
    AccountingRules.init();
    Money.setDefaultCurrency(AccountingRules.getMifosCurrency(new ConfigurationPersistence()));
    final MifosConfigurationManager configuration = MifosConfigurationManager.getInstance();
    final String imageStorageConfig = configuration.getString(IMAGESTORE_CONFIG_KEY);
    if (imageStorageConfig == null || !imageStorageConfig.equals(DB_CONFIG)) {
        ImageStorageManager.initStorage();
    }
    DatabaseMigrator migrator = new DatabaseMigrator();
    initializeDBConnectionForHibernate(migrator);
    if (!databaseError.isError) {
        try {
            migrator.upgrade(applicationContext);
        } catch (Throwable t) {
            setDatabaseError(DatabaseErrorCode.UPGRADE_FAILURE, "Failed to upgrade database.", t);
        }
    }
    if (databaseError.isError) {
        databaseError.logError();
    } else {
        initializeDB(applicationContext);
        /*
             * John W - Added in G Release and back patched to F Release.
             * Related to jira issue MIFOS-4948
             *
             * Can find all code and the related query by searching for mifos4948
             *
            */
        CustomJDBCService customJdbcService = applicationContext.getBean(CustomJDBCService.class);
        boolean keyExists = customJdbcService.mifos4948IssueKeyExists();
        if (!keyExists) {
            try {
                StaticHibernateUtil.startTransaction();
                applyMifos4948Fix();
                customJdbcService.insertMifos4948Issuekey();
                StaticHibernateUtil.commitTransaction();
            } catch (AccountException e) {
                StaticHibernateUtil.rollbackTransaction();
                e.printStackTrace();
            } finally {
                StaticHibernateUtil.closeSession();
            }
        }
        boolean key5722Exists = customJdbcService.mifos5722IssueKeyExists();
        if (!key5722Exists) {
            try {
                applyMifos5722Fix();
                customJdbcService.insertMifos5722Issuekey();
            } catch (Exception e) {
                logger.error("Could not apply Mifos-5692 and mifos-5722 fix");
                e.printStackTrace();
            } finally {
                StaticHibernateUtil.closeSession();
            }
        }
        boolean key5763Exists = customJdbcService.mifos5763IssueKeyExists();
        if (!key5763Exists) {
            try {
                applyMifos5763Fix();
                customJdbcService.insertMifos5763Issuekey();
            } catch (Exception e) {
                logger.info("Failed to apply Mifos-5763 fix");
                e.printStackTrace();
            } finally {
                StaticHibernateUtil.closeSession();
            }
        }
        boolean key5632Exists = customJdbcService.mifos5632IssueKeyExists();
        if (!key5632Exists) {
            try {
                applyMifos5632();
                customJdbcService.insertMifos5632IssueKey();
            } catch (Exception e) {
                logger.info("Failed to apply Mifos-5632 fix");
                e.printStackTrace();
            } finally {
                StaticHibernateUtil.closeSession();
            }
        }
    }
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) DatabaseMigrator(org.mifos.framework.persistence.DatabaseMigrator) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) CustomJDBCService(org.mifos.application.servicefacade.CustomJDBCService) SystemException(org.mifos.framework.exceptions.SystemException) TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) XMLReaderException(org.mifos.framework.exceptions.XMLReaderException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) AppNotConfiguredException(org.mifos.framework.exceptions.AppNotConfiguredException) AccountException(org.mifos.accounts.exceptions.AccountException) FinancialException(org.mifos.accounts.financial.exceptions.FinancialException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) HibernateStartUpException(org.mifos.framework.exceptions.HibernateStartUpException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager)

Aggregations

ConfigurationException (org.mifos.config.exceptions.ConfigurationException)18 MifosConfigurationManager (org.mifos.config.business.MifosConfigurationManager)8 IOException (java.io.IOException)3 LegacyAccountDao (org.mifos.accounts.persistence.LegacyAccountDao)3 PersistenceException (org.mifos.framework.exceptions.PersistenceException)3 ArrayList (java.util.ArrayList)2 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)2 FinancialException (org.mifos.accounts.financial.exceptions.FinancialException)2 LegacyLoanDao (org.mifos.accounts.loan.persistance.LegacyLoanDao)2 AccountSearchResultsDto (org.mifos.accounts.util.helpers.AccountSearchResultsDto)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 CustomerStatusEntity (org.mifos.customers.business.CustomerStatusEntity)2 CustomerDao (org.mifos.customers.persistence.CustomerDao)2 CustomerSearchResultDto (org.mifos.dto.domain.CustomerSearchResultDto)2 HibernateSearchException (org.mifos.framework.exceptions.HibernateSearchException)2 QueryResult (org.mifos.framework.hibernate.helper.QueryResult)2 InputStream (java.io.InputStream)1 Iterator (java.util.Iterator)1 Locale (java.util.Locale)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1