Search in sources :

Example 11 with TaskDefinition

use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.

the class WebModuleUtil method stopTasks.

/**
 * Stops all tasks started by given module
 * @param mod
 */
private static void stopTasks(Module mod) {
    SchedulerService schedulerService = Context.getSchedulerService();
    String modulePackageName = mod.getPackageName();
    for (TaskDefinition task : schedulerService.getRegisteredTasks()) {
        String taskClass = task.getTaskClass();
        if (isModulePackageNameInTaskClass(modulePackageName, taskClass)) {
            try {
                schedulerService.shutdownTask(task);
            } catch (SchedulerException e) {
                log.error("Couldn't stop task:" + task + " for module: " + mod);
            }
        }
    }
}
Also used : SchedulerService(org.openmrs.scheduler.SchedulerService) TaskDefinition(org.openmrs.scheduler.TaskDefinition) SchedulerException(org.openmrs.scheduler.SchedulerException)

Example 12 with TaskDefinition

use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.

the class SchedulerFormValidatorTest method validate_shouldFailValidationIfClassCannotBeInstantiated.

/**
 * @see SchedulerFormValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfClassCannotBeInstantiated() {
    TaskDefinition def = new TaskDefinition();
    def.setName("Chores");
    def.setRepeatInterval(3600000L);
    def.setTaskClass("org.openmrs.BaseOpenmrsData");
    Errors errors = new BindException(def, "def");
    new SchedulerFormValidator().validate(def, errors);
    Assert.assertTrue(errors.hasFieldErrors("taskClass"));
    Assert.assertEquals("Scheduler.taskForm.instantiationException", errors.getFieldError("taskClass").getCode());
}
Also used : Errors(org.springframework.validation.Errors) TaskDefinition(org.openmrs.scheduler.TaskDefinition) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 13 with TaskDefinition

use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.

the class SchedulerFormValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.

/**
 * @see SchedulerFormValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
    TaskDefinition def = new TaskDefinition();
    def.setName("Chores");
    def.setRepeatInterval(3600000L);
    def.setTaskClass("org.openmrs.scheduler.tasks.HelloWorldTask");
    Errors errors = new BindException(def, "def");
    new SchedulerFormValidator().validate(def, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) TaskDefinition(org.openmrs.scheduler.TaskDefinition) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 14 with TaskDefinition

use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.

the class SchedulerFormValidatorTest method validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace.

/**
 * @see SchedulerFormValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace() {
    TaskDefinition def = new TaskDefinition();
    def.setName(null);
    def.setRepeatInterval(3600000L);
    def.setTaskClass("org.openmrs.scheduler.tasks.HelloWorldTask");
    Errors errors = new BindException(def, "def");
    new SchedulerFormValidator().validate(def, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    def.setName("");
    errors = new BindException(def, "def");
    new SchedulerFormValidator().validate(def, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    def.setName(" ");
    errors = new BindException(def, "def");
    new SchedulerFormValidator().validate(def, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
}
Also used : Errors(org.springframework.validation.Errors) TaskDefinition(org.openmrs.scheduler.TaskDefinition) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with TaskDefinition

use of org.openmrs.scheduler.TaskDefinition in project openmrs-core by openmrs.

the class SchedulerFormValidatorTest method validate_shouldFailValidationIfClassNotFound.

/**
 * @see SchedulerFormValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfClassNotFound() {
    TaskDefinition def = new TaskDefinition();
    def.setName("Chores");
    def.setRepeatInterval(3600000L);
    def.setTaskClass("org.openmrs.ScaryRobot");
    Errors errors = new BindException(def, "def");
    new SchedulerFormValidator().validate(def, errors);
    Assert.assertTrue(errors.hasFieldErrors("taskClass"));
    Assert.assertEquals("Scheduler.taskForm.classNotFoundException", errors.getFieldError("taskClass").getCode());
}
Also used : Errors(org.springframework.validation.Errors) TaskDefinition(org.openmrs.scheduler.TaskDefinition) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

TaskDefinition (org.openmrs.scheduler.TaskDefinition)30 Test (org.junit.Test)12 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)11 BindException (org.springframework.validation.BindException)10 Errors (org.springframework.validation.Errors)10 SchedulerException (org.openmrs.scheduler.SchedulerException)9 SchedulerService (org.openmrs.scheduler.SchedulerService)7 Date (java.util.Date)6 APIException (org.openmrs.api.APIException)3 ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)3 HashSet (java.util.HashSet)2 Task (org.openmrs.scheduler.Task)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Criteria (org.hibernate.Criteria)1 MarkAppointmentsAsMissedOrCompletedTask (org.openmrs.module.mirebalais.task.MarkAppointmentsAsMissedOrCompletedTask)1 CloseStaleCreateRequestsTask (org.openmrs.module.paperrecord.CloseStaleCreateRequestsTask)1 CloseStalePullRequestsTask (org.openmrs.module.paperrecord.CloseStalePullRequestsTask)1 PihCloseStaleVisitsTask (org.openmrs.module.pihcore.task.PihCloseStaleVisitsTask)1 UpdateProviderRetiredStatesBasedOnAssociatedUserAccounts (org.openmrs.module.pihcore.task.UpdateProviderRetiredStatesBasedOnAssociatedUserAccounts)1