Search in sources :

Example 1 with MifosScheduler

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

the class BatchjobsServiceFacadeWebTier method getBatchjobs.

@Override
public List<BatchjobsDto> getBatchjobs(ServletContext context) throws TaskSystemException, FileNotFoundException, IOException, SchedulerException {
    List<BatchjobsDto> batchjobs = new ArrayList<BatchjobsDto>();
    MifosScheduler mifosScheduler = (MifosScheduler) context.getAttribute(MifosScheduler.class.getName());
    Scheduler scheduler = mifosScheduler.getScheduler();
    for (String groupName : scheduler.getJobGroupNames()) {
        for (String jobName : scheduler.getJobNames(groupName)) {
            Trigger[] triggers = scheduler.getTriggersOfJob(jobName, groupName);
            Trigger trigger = triggers.length > 0 ? triggers[0] : null;
            JobDetail jobDetail = scheduler.getJobDetail(jobName, groupName);
            if (trigger != null && jobDetail != null) {
                Date nextFire = trigger.getNextFireTime() != null ? trigger.getNextFireTime() : new Date(0);
                Date lastFire = mifosScheduler.getJobsPreviousRunTime(jobName);
                Date lastSuccessfulRun = mifosScheduler.getJobsLastSuccessfulRunTime(jobName);
                int priority = trigger.getPriority();
                String frequency = "";
                String taskType = "";
                if (trigger instanceof CronTrigger) {
                    frequency = ((CronTrigger) trigger).getCronExpression();
                    taskType = CRON_TRIGGER;
                }
                if (trigger instanceof SimpleTrigger) {
                    frequency = Long.toString(((SimpleTrigger) trigger).getRepeatInterval());
                    taskType = SIMPLE_TRIGGER;
                }
                String previousRunStatus = mifosScheduler.getJobsPreviousRunStatus(jobName);
                int triggerState = scheduler.getTriggerState(trigger.getName(), groupName);
                String failDescription = mifosScheduler.getJobFailDescription(jobName);
                batchjobs.add(new BatchjobsDto(jobName, frequency, taskType, priority, previousRunStatus, lastFire, lastSuccessfulRun, nextFire, triggerState, failDescription));
            }
        }
    }
    return batchjobs;
}
Also used : CronTrigger(org.quartz.CronTrigger) Scheduler(org.quartz.Scheduler) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler) ArrayList(java.util.ArrayList) BatchjobsDto(org.mifos.application.admin.servicefacade.BatchjobsDto) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler) Date(java.util.Date) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) SimpleTrigger(org.quartz.SimpleTrigger)

Example 2 with MifosScheduler

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

the class BatchjobsServiceFacadeWebTier method getBatchjobsScheduler.

@Override
public BatchjobsSchedulerDto getBatchjobsScheduler(ServletContext context) throws SchedulerException {
    MifosScheduler mifosScheduler = (MifosScheduler) context.getAttribute(MifosScheduler.class.getName());
    Scheduler scheduler = mifosScheduler.getScheduler();
    BatchjobsSchedulerDto batchjobsScheduler = new BatchjobsSchedulerDto(!scheduler.isInStandbyMode());
    return batchjobsScheduler;
}
Also used : Scheduler(org.quartz.Scheduler) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler) BatchjobsSchedulerDto(org.mifos.application.admin.servicefacade.BatchjobsSchedulerDto) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler)

Example 3 with MifosScheduler

use of org.mifos.framework.components.batchjobs.MifosScheduler 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 4 with MifosScheduler

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

the class LoanArrearsTaskIntegrationTest method getMifosScheduler.

private MifosScheduler getMifosScheduler(String taskConfigurationPath) throws TaskSystemException, IOException, FileNotFoundException {
    ConfigurationLocator mockConfigurationLocator = createMock(ConfigurationLocator.class);
    expect(mockConfigurationLocator.getResource(SchedulerConstants.CONFIGURATION_FILE_NAME)).andReturn(MifosResourceUtil.getClassPathResourceAsResource(taskConfigurationPath));
    expectLastCall().times(2);
    replay(mockConfigurationLocator);
    MifosScheduler mifosScheduler = new MifosScheduler();
    mifosScheduler.setConfigurationLocator(mockConfigurationLocator);
    mifosScheduler.initialize();
    return mifosScheduler;
}
Also used : ConfigurationLocator(org.mifos.framework.util.ConfigurationLocator) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler)

Example 5 with MifosScheduler

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

the class LoanArrearsAndPortfolioAtRiskIntegrationTest method getMifosScheduler.

private MifosScheduler getMifosScheduler(String taskConfigurationPath) throws TaskSystemException, IOException, FileNotFoundException {
    ConfigurationLocator mockConfigurationLocator = createMock(ConfigurationLocator.class);
    expect(mockConfigurationLocator.getResource(SchedulerConstants.CONFIGURATION_FILE_NAME)).andReturn(MifosResourceUtil.getClassPathResourceAsResource(taskConfigurationPath));
    expectLastCall().times(2);
    replay(mockConfigurationLocator);
    MifosScheduler mifosScheduler = new MifosScheduler();
    mifosScheduler.setConfigurationLocator(mockConfigurationLocator);
    mifosScheduler.initialize();
    return mifosScheduler;
}
Also used : ConfigurationLocator(org.mifos.framework.util.ConfigurationLocator) MifosScheduler(org.mifos.framework.components.batchjobs.MifosScheduler)

Aggregations

MifosScheduler (org.mifos.framework.components.batchjobs.MifosScheduler)10 TaskSystemException (org.mifos.framework.components.batchjobs.exceptions.TaskSystemException)3 ConfigurationLocator (org.mifos.framework.util.ConfigurationLocator)3 Scheduler (org.quartz.Scheduler)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 ServletContext (javax.servlet.ServletContext)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 FinancialException (org.mifos.accounts.financial.exceptions.FinancialException)1 BatchjobsDto (org.mifos.application.admin.servicefacade.BatchjobsDto)1 BatchjobsSchedulerDto (org.mifos.application.admin.servicefacade.BatchjobsSchedulerDto)1 PersonnelServiceFacade (org.mifos.application.admin.servicefacade.PersonnelServiceFacade)1 ShutdownManager (org.mifos.application.admin.system.ShutdownManager)1 MessageLookup (org.mifos.application.master.MessageLookup)1 LocaleSetting (org.mifos.config.LocaleSetting)1 UserLocale (org.mifos.config.UserLocale)1 ConfigurationException (org.mifos.config.exceptions.ConfigurationException)1 MifosException (org.mifos.core.MifosException)1