Search in sources :

Example 16 with TaskDefinition

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

the class SchedulerFormValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see SchedulerFormValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    TaskDefinition def = new TaskDefinition();
    def.setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    def.setRepeatInterval(3600000L);
    def.setTaskClass("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    def.setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    def.setStartTimePattern("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    Errors errors = new BindException(def, "def");
    new SchedulerFormValidator().validate(def, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    Assert.assertTrue(errors.hasFieldErrors("taskClass"));
    Assert.assertTrue(errors.hasFieldErrors("description"));
    Assert.assertTrue(errors.hasFieldErrors("startTimePattern"));
}
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 17 with TaskDefinition

use of org.openmrs.scheduler.TaskDefinition in project openmrs-module-mirebalais by PIH.

the class MirebalaisHospitalActivatorComponentTest method verifyCloseStaleCreateRequestsTaskScheduledAndStarted.

private void verifyCloseStaleCreateRequestsTaskScheduledAndStarted() {
    TaskDefinition taskDefinition = schedulerService.getTaskByName(PaperRecordConstants.TASK_CLOSE_STALE_CREATE_REQUESTS);
    assertNotNull(taskDefinition);
    assertTrue(taskDefinition.getStarted());
    assertTrue(taskDefinition.getStartOnStartup());
    assertEquals(new Long(3600), taskDefinition.getRepeatInterval());
}
Also used : TaskDefinition(org.openmrs.scheduler.TaskDefinition)

Example 18 with TaskDefinition

use of org.openmrs.scheduler.TaskDefinition in project openmrs-module-mirebalais by PIH.

the class MirebalaisHospitalActivatorComponentTest method verifyMarkAppointmentsAsMissedOrCompletedScheduledAndStarted.

private void verifyMarkAppointmentsAsMissedOrCompletedScheduledAndStarted() {
    TaskDefinition taskDefinition = schedulerService.getTaskByName(MirebalaisConstants.TASK_MARK_APPOINTMENTS_AS_MISSED_OR_COMPLETED);
    assertNotNull(taskDefinition);
    assertTrue(taskDefinition.getStarted());
    assertTrue(taskDefinition.getStartOnStartup());
    assertEquals(MirebalaisConstants.TASK_MARK_APPOINTMENTS_AS_MISSED_OR_COMPLETED_REPEAT_INTERVAL, taskDefinition.getRepeatInterval());
}
Also used : TaskDefinition(org.openmrs.scheduler.TaskDefinition)

Example 19 with TaskDefinition

use of org.openmrs.scheduler.TaskDefinition in project openmrs-module-mirebalais by PIH.

the class ArchivesSetup method setupCloseStalePullRequestsTask.

public static void setupCloseStalePullRequestsTask() {
    SchedulerService schedulerService = Context.getSchedulerService();
    TaskDefinition task = schedulerService.getTaskByName(PaperRecordConstants.TASK_CLOSE_STALE_PULL_REQUESTS);
    if (task == null) {
        task = new TaskDefinition();
        task.setName(PaperRecordConstants.TASK_CLOSE_STALE_PULL_REQUESTS);
        task.setDescription(PaperRecordConstants.TASK_CLOSE_STALE_PULL_REQUESTS_DESCRIPTION);
        task.setTaskClass(CloseStalePullRequestsTask.class.getName());
        task.setStartTime(DateUtils.addMinutes(new Date(), 5));
        // once an hour
        task.setRepeatInterval(new Long(3600));
        task.setStartOnStartup(true);
        try {
            schedulerService.scheduleTask(task);
        } catch (SchedulerException e) {
            throw new RuntimeException("Failed to schedule close stale pull requests task", e);
        }
    } else {
        boolean anyChanges = GeneralUtils.setPropertyIfDifferent(task, "description", PaperRecordConstants.TASK_CLOSE_STALE_PULL_REQUESTS_DESCRIPTION);
        anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "taskClass", CloseStalePullRequestsTask.class.getName());
        anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "repeatInterval", new Long(3600));
        anyChanges |= GeneralUtils.setPropertyIfDifferent(task, "startOnStartup", true);
        if (anyChanges) {
            schedulerService.saveTaskDefinition(task);
        }
        if (!task.getStarted()) {
            task.setStarted(true);
            try {
                schedulerService.scheduleTask(task);
            } catch (SchedulerException e) {
                throw new RuntimeException("Failed to schedule close stale pull requests task", e);
            }
        }
    }
}
Also used : SchedulerService(org.openmrs.scheduler.SchedulerService) TaskDefinition(org.openmrs.scheduler.TaskDefinition) CloseStalePullRequestsTask(org.openmrs.module.paperrecord.CloseStalePullRequestsTask) SchedulerException(org.openmrs.scheduler.SchedulerException) Date(java.util.Date)

Example 20 with TaskDefinition

use of org.openmrs.scheduler.TaskDefinition in project openmrs-module-mirebalais by PIH.

the class MirebalaisHospitalActivatorComponentTest method verifyCloseStalePullRequestsTaskScheduledAndStarted.

private void verifyCloseStalePullRequestsTaskScheduledAndStarted() {
    TaskDefinition taskDefinition = schedulerService.getTaskByName(PaperRecordConstants.TASK_CLOSE_STALE_PULL_REQUESTS);
    assertNotNull(taskDefinition);
    assertTrue(taskDefinition.getStarted());
    assertTrue(taskDefinition.getStartOnStartup());
    assertEquals(new Long(3600), taskDefinition.getRepeatInterval());
}
Also used : TaskDefinition(org.openmrs.scheduler.TaskDefinition)

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