Search in sources :

Example 1 with ApplicationInitializer

use of org.mifos.framework.ApplicationInitializer in project head by mifos.

the class DataSetUpgradeUtil method upgrade.

private void upgrade(String fileName, ApplicationContext applicationContext) throws Exception {
    System.out.println("Upgrading: " + fileName);
    dbUnitUtilities = new DbUnitUtilities();
    IDataSet dataSet = null;
    try {
        dataSet = dbUnitUtilities.getDataSetFromFile(fileName);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Class.forName("com.mysql.jdbc.Driver");
    Connection jdbcConnection = null;
    try {
        // TODO use same db cxn info that Mifos uses! (local.properties)
        jdbcConnection = DriverManager.getConnection(getUrl(databaseName, port, params), user, password);
        jdbcConnection.setAutoCommit(false);
        resetDatabase(databaseName, jdbcConnection);
        SqlExecutor.execute(new FileInputStream(schemaFileName), jdbcConnection);
        jdbcConnection.commit();
        jdbcConnection.setAutoCommit(true);
        IDatabaseConnection databaseConnection = new DatabaseConnection(jdbcConnection);
        databaseConnection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, Boolean.FALSE);
        DatabaseOperation.CLEAN_INSERT.execute(databaseConnection, dataSet);
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
    }
    System.setProperty(TestingService.TEST_MODE_SYSTEM_PROPERTY, "acceptance");
    ApplicationInitializer applicationInitializer = new ApplicationInitializer();
    applicationInitializer.dbUpgrade(applicationContext);
    applicationContext.getBean(DatabaseUpgradeSupport.class).contraction();
    applicationInitializer.setAttributesOnContext(null);
    StaticHibernateUtil.closeSession();
    System.out.println(" upgrade done!");
}
Also used : Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) ApplicationInitializer(org.mifos.framework.ApplicationInitializer) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) DatabaseUpgradeSupport(org.mifos.db.upgrade.DatabaseUpgradeSupport) IOException(java.io.IOException) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet) FileInputStream(java.io.FileInputStream)

Example 2 with ApplicationInitializer

use of org.mifos.framework.ApplicationInitializer in project head by mifos.

the class PPITestDataGenerator method loadData.

private void loadData(String filename, ApplicationContext applicationContext) throws TaskSystemException, PersistenceException, ConfigurationException, FinancialException, FileNotFoundException, IOException {
    System.setProperty(TestingService.TEST_MODE_SYSTEM_PROPERTY, "acceptance");
    ApplicationInitializer applicationInitializer = new ApplicationInitializer();
    applicationInitializer.dbUpgrade(applicationContext);
    applicationInitializer.setAttributesOnContext(null);
    CustomerBO customer = customerDao.findClientBySystemId(clientGlobalId);
    if (customer == null) {
        fail("Could not find customer for global id: " + clientGlobalId);
    }
    System.out.println("Found: " + customer.getDisplayName());
    Properties properties = new Properties();
    properties.load(new FileReader(filename));
    System.out.println("Loading data for: " + properties.getProperty("questionGroup.name"));
    questionnaireServiceFacade.uploadPPIQuestionGroup(properties.getProperty("questionGroup.xml.filename"));
    QuestionGroupDetail qg = findQuestionGroup(properties.getProperty("questionGroup.name"));
    int surveyCount = Integer.parseInt(properties.getProperty("survey.count"));
    for (int surveyNum = 1; surveyNum <= surveyCount; ++surveyNum) {
        createSurveyInstance(customer, properties, qg, surveyNum);
    }
    System.out.println("done!");
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ApplicationInitializer(org.mifos.framework.ApplicationInitializer) CustomerBO(org.mifos.customers.business.CustomerBO) FileReader(java.io.FileReader) Properties(java.util.Properties)

Aggregations

ApplicationInitializer (org.mifos.framework.ApplicationInitializer)2 FileInputStream (java.io.FileInputStream)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 Properties (java.util.Properties)1 DatabaseConnection (org.dbunit.database.DatabaseConnection)1 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)1 IDataSet (org.dbunit.dataset.IDataSet)1 CustomerBO (org.mifos.customers.business.CustomerBO)1 DatabaseUpgradeSupport (org.mifos.db.upgrade.DatabaseUpgradeSupport)1 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)1