Search in sources :

Example 6 with TaskSystemException

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

the class MifosScheduler method runAllTasks.

@SuppressWarnings("unchecked")
public void runAllTasks() throws TaskSystemException {
    try {
        List<String> triggerNames;
        List<Trigger> triggers = new ArrayList<Trigger>();
        String[] groupNames = scheduler.getTriggerGroupNames();
        for (String group : groupNames) {
            triggerNames = new ArrayList<String>(Arrays.asList(scheduler.getTriggerNames(group)));
            for (String triggerName : triggerNames) {
                triggers.add(scheduler.getTrigger(triggerName, group));
            }
        }
        Collections.sort(triggers, new Comparator<Trigger>() {

            @Override
            public int compare(Trigger trigger1, Trigger trigger2) {
                if (trigger1.getPriority() < trigger2.getPriority()) {
                    return -1;
                } else if (trigger1.getPriority() > trigger2.getPriority()) {
                    return 1;
                } else {
                    return 0;
                }
            }
        });
        for (Trigger trigger : triggers) {
            scheduler.triggerJob(trigger.getJobName(), trigger.getJobGroup());
        }
    } catch (SchedulerException se) {
        throw new TaskSystemException(se);
    }
}
Also used : TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) SchedulerException(org.quartz.SchedulerException) ArrayList(java.util.ArrayList)

Example 7 with TaskSystemException

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

the class MifosScheduler method getTaskNames.

public List<String> getTaskNames() throws TaskSystemException {
    try {
        List<String> taskNames = new ArrayList<String>();
        String[] groupNames = scheduler.getJobGroupNames();
        for (String group : groupNames) {
            Collections.addAll(taskNames, scheduler.getJobNames(group));
        }
        return taskNames;
    } catch (SchedulerException e) {
        throw new TaskSystemException(e);
    }
}
Also used : TaskSystemException(org.mifos.framework.components.batchjobs.exceptions.TaskSystemException) SchedulerException(org.quartz.SchedulerException) ArrayList(java.util.ArrayList)

Example 8 with TaskSystemException

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

the class MifosScheduler method scheduleLoanArrearsAndPortfolioAtRisk.

@Deprecated
public void scheduleLoanArrearsAndPortfolioAtRisk(Date initialTime, long delay, JobRegistry jobRegistry, final JobRepository jobRepository, Map<String, Object> jobData, ResourcelessTransactionManager transactionManager) throws TaskSystemException {
    final String jobName = "LoanArrearsAndPortfolioAtRiskTask";
    try {
        final TaskletStep step1 = new TaskletStep();
        step1.setName("LoanArrearsAndPortfolioAtRiskTask-step-1");
        step1.setTasklet((Tasklet) Class.forName(BATCH_JOB_CLASS_PATH_PREFIX + getHelperName("LoanArrearsTask")).newInstance());
        step1.setJobRepository(jobRepository);
        step1.setTransactionManager(transactionManager);
        step1.afterPropertiesSet();
        final TaskletStep step2 = new TaskletStep();
        step2.setName("LoanArrearsAndPortfolioAtRiskTask-step-2");
        step2.setTasklet((Tasklet) Class.forName(BATCH_JOB_CLASS_PATH_PREFIX + getHelperName("PortfolioAtRiskTask")).newInstance());
        step2.setJobRepository(jobRepository);
        step2.setTransactionManager(transactionManager);
        step2.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(step1);
                job.addStep(step2);
                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 + "PortfolioAtRiskTask"));
    } 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) 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