Search in sources :

Example 1 with TaskSystemException

use of org.mifos.framework.components.batchjobs.exceptions.TaskSystemException 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)

Example 2 with TaskSystemException

use of org.mifos.framework.components.batchjobs.exceptions.TaskSystemException in project head by mifos.

the class StandardTestingService method runAllBatchJobs.

@Override
public void runAllBatchJobs(final ServletContext ctx) {
    logger.info("running all batch jobs");
    MifosScheduler mifosScheduler = (MifosScheduler) ctx.getAttribute(MifosScheduler.class.getName());
    try {
        mifosScheduler.runAllTasks();
    } catch (TaskSystemException se) {
        throw new MifosRuntimeException("Scheduler's inner exception while running all batch jobs!", se);
    }
}
Also used : TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 3 with TaskSystemException

use of org.mifos.framework.components.batchjobs.exceptions.TaskSystemException in project head by mifos.

the class StandardTestingService method runIndividualBatchJob.

@Override
public void runIndividualBatchJob(final String requestedJob, final ServletContext ctx) throws MifosException {
    logger.info("running batch job with name: " + requestedJob);
    boolean jobFound = false;
    String jobToRun = null;
    final MifosScheduler mifosScheduler = (MifosScheduler) ctx.getAttribute(MifosScheduler.class.getName());
    try {
        for (String taskName : mifosScheduler.getTaskNames()) {
            if (taskName.equals(requestedJob)) {
                jobFound = true;
                jobToRun = taskName;
                break;
            }
        }
        if (!jobFound) {
            throw new IllegalArgumentException(requestedJob + " is unknown and will not be executed.");
        }
        mifosScheduler.runIndividualTask(jobToRun);
    } catch (TaskSystemException se) {
        throw new MifosException("Scheduler's inner exception while running individual batch job!", se);
    }
}
Also used : TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) MifosException(org.mifos.core.MifosException) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler)

Example 4 with TaskSystemException

use of org.mifos.framework.components.batchjobs.exceptions.TaskSystemException in project head by mifos.

the class MifosScheduler method initialize.

public void initialize() throws TaskSystemException {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse(getTaskConfigurationResource().getURI().toString());
        NodeList rootElement = document.getElementsByTagName(SchedulerConstants.SPRING_BEANS_FILE_ROOT_TAG);
        if (rootElement.getLength() > 0) {
            // new Quartz scheduler
            springTaskContext = ApplicationContextFactory.createApplicationContext(getTaskConfigurationResource());
            scheduler = (Scheduler) springTaskContext.getBean(SchedulerConstants.SPRING_SCHEDULER_BEAN_NAME);
            jobExplorer = (JobExplorer) springTaskContext.getBean(SchedulerConstants.JOB_EXPLORER_BEAN_NAME);
            jobRepository = (JobRepository) springTaskContext.getBean(SchedulerConstants.JOB_REPOSITORY_BEAN_NAME);
            jobLauncher = (JobLauncher) springTaskContext.getBean(SchedulerConstants.JOB_LAUNCHER_BEAN_NAME);
            jobLocator = (JobLocator) springTaskContext.getBean(SchedulerConstants.JOB_LOCATOR_BEAN_NAME);
        } else {
            // old legacy Mifos Scheduler
            throw new MifosRuntimeException("The legacy custom Mifos format for task.xml is no longer supported.  Please convert your custom tasks.xml file to the new format.  The tasks.xml that ships with Mifos can be used as an example.");
        }
    } catch (Exception e) {
        throw new TaskSystemException(e);
    }
}
Also used : TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) SchedulerException(org.quartz.SchedulerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) IOException(java.io.IOException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 5 with TaskSystemException

use of org.mifos.framework.components.batchjobs.exceptions.TaskSystemException in project head by mifos.

the class MifosScheduler method schedule.

@Deprecated
public void schedule(final String jobName, Date initialTime, long delay, JobRegistry jobRegistry, final JobRepository jobRepository, Map<String, Object> jobData, ResourcelessTransactionManager transactionManager) throws TaskSystemException {
    try {
        final TaskletStep step = new TaskletStep();
        step.setName(jobName);
        Tasklet tasklet = (Tasklet) Class.forName(BATCH_JOB_CLASS_PATH_PREFIX + getHelperName(jobName)).newInstance();
        step.setTasklet(tasklet);
        step.setJobRepository(jobRepository);
        step.setTransactionManager(transactionManager);
        step.afterPropertiesSet();
        jobRegistry.register(new JobFactory() {

            @Override
            public Job createJob() {
                SimpleJob job = new SimpleJob(jobName + "Job");
                job.setJobRepository(jobRepository);
                job.setRestartable(true);
                job.registerJobExecutionListener(new BatchJobListener());
                job.addStep(step);
                return job;
            }

            @Override
            public String getJobName() {
                return jobName + "Job";
            }
        });
    } catch (Exception e) {
        throw new TaskSystemException(e);
    }
    JobDetailBean jobDetailBean = new JobDetailBean();
    jobDetailBean.setJobDataAsMap(jobData);
    try {
        jobDetailBean.setJobClass(Class.forName(BATCH_JOB_CLASS_PATH_PREFIX + jobName));
    } catch (ClassNotFoundException cnfe) {
        throw new TaskSystemException(cnfe);
    }
    jobDetailBean.setName(jobName + "Job");
    jobDetailBean.setGroup(Scheduler.DEFAULT_GROUP);
    jobDetailBean.afterPropertiesSet();
    SimpleTrigger trigger = new SimpleTrigger();
    trigger.setName(jobName + "Job");
    trigger.setGroup(Scheduler.DEFAULT_GROUP);
    trigger.setStartTime(initialTime);
    trigger.setRepeatInterval(delay);
    trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
    try {
        scheduler.scheduleJob(jobDetailBean, trigger);
    } catch (SchedulerException se) {
        throw new TaskSystemException(se);
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) JobDetailBean(org.springframework.scheduling.quartz.JobDetailBean) Tasklet(org.springframework.batch.core.step.tasklet.Tasklet) TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) SchedulerException(org.quartz.SchedulerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) IOException(java.io.IOException) JobFactory(org.springframework.batch.core.configuration.JobFactory) TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) SimpleJob(org.springframework.batch.core.job.SimpleJob) TaskletStep(org.springframework.batch.core.step.tasklet.TaskletStep) Job(org.springframework.batch.core.Job) SimpleJob(org.springframework.batch.core.job.SimpleJob) SimpleTrigger(org.quartz.SimpleTrigger)

Aggregations

TaskSystemException (org.mifos.framework.components.batchjobs.exceptions.TaskSystemException)8 SchedulerException (org.quartz.SchedulerException)5 IOException (java.io.IOException)4 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 SimpleTrigger (org.quartz.SimpleTrigger)3 ArrayList (java.util.ArrayList)2 MifosScheduler (org.mifos.framework.components.batchjobs.MifosScheduler)2 Job (org.springframework.batch.core.Job)2 JobFactory (org.springframework.batch.core.configuration.JobFactory)2 SimpleJob (org.springframework.batch.core.job.SimpleJob)2 TaskletStep (org.springframework.batch.core.step.tasklet.TaskletStep)2 JobDetailBean (org.springframework.scheduling.quartz.JobDetailBean)2 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 FinancialException (org.mifos.accounts.financial.exceptions.FinancialException)1 CustomJDBCService (org.mifos.application.servicefacade.CustomJDBCService)1 MifosConfigurationManager (org.mifos.config.business.MifosConfigurationManager)1 ConfigurationException (org.mifos.config.exceptions.ConfigurationException)1