use of eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger in project CzechIdMng by bcvsolutions.
the class AbstractScheduledTaskInitializer method getTrigger.
/**
* Method return {@link AbstractTaskTrigger} from
* {@link IdmScheduledTaskTriggerType}
*
* @param triggerType
* @return
* @throws ClassNotFoundException
*/
protected AbstractTaskTrigger getTrigger(IdmScheduledTaskTriggerType triggerType) throws ClassNotFoundException {
@SuppressWarnings("unchecked") Class<AbstractTaskTrigger> triggerClass = (Class<AbstractTaskTrigger>) Class.forName(triggerType.getType());
if (triggerClass.isAssignableFrom(SimpleTaskTrigger.class)) {
SimpleTaskTrigger simpleTrigger = new SimpleTaskTrigger();
simpleTrigger = (SimpleTaskTrigger) setTriggerDefaultValues(simpleTrigger, triggerType);
simpleTrigger.setFireTime(new DateTime(triggerType.getFireTime()));
return simpleTrigger;
} else if (triggerClass.isAssignableFrom(CronTaskTrigger.class)) {
CronTaskTrigger cronTrigger = new CronTaskTrigger();
cronTrigger = (CronTaskTrigger) setTriggerDefaultValues(cronTrigger, triggerType);
cronTrigger.setCron(triggerType.getCron());
return cronTrigger;
} else {
LOG.error("Trigger type: [{}] is not implemented, please override method getTrigger from AbstractScheduledTaskInitializer. " + "This trigger will be skipped.", triggerType.getType());
return null;
}
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger in project CzechIdMng by bcvsolutions.
the class AbstractScheduledTaskInitializerTest method testInitTask.
@Test
public void testInitTask() {
List<Task> tasks = schedulerService.getAllTasks();
// found test task, other will be skip
for (Task task : tasks) {
if (task.getTaskType().equals(TestTaskExecutor.class)) {
assertEquals(TEST_DESCRIPTION, task.getDescription());
assertEquals(TEST_INSTANCE, task.getInstanceId());
// assertEquals(InitTestScheduledTask.TEST_MODULE, task.getModule()); // module not working in Task
Map<String, String> parameters = task.getParameters();
assertEquals(3, parameters.size());
String value1 = parameters.get(KEY_1);
assertEquals(VALUE_1, value1);
String value2 = parameters.get(KEY_2);
assertEquals(VALUE_2, value2);
String value3 = parameters.get(KEY_3);
assertEquals(VALUE_3, value3);
List<AbstractTaskTrigger> triggers = task.getTriggers();
assertEquals(2, triggers.size());
for (AbstractTaskTrigger trigger : triggers) {
assertEquals(TaskTriggerState.ACTIVE, trigger.getState());
if (trigger.getClass().equals(CronTaskTrigger.class)) {
CronTaskTrigger cronTrigger = (CronTaskTrigger) trigger;
assertEquals(TEST_CRON, cronTrigger.getCron());
} else if (trigger.getClass().equals(SimpleTaskTrigger.class)) {
SimpleTaskTrigger simpleTrigger = (SimpleTaskTrigger) trigger;
assertEquals(TEST_FIRE_TIME, simpleTrigger.getFireTime());
} else {
fail();
}
}
// success
return;
}
}
// test task is not initialized
fail();
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger in project CzechIdMng by bcvsolutions.
the class DefaultSchedulerManager method createTrigger.
@Override
public AbstractTaskTrigger createTrigger(String taskId, AbstractTaskTrigger trigger, boolean dryRun) {
Assert.notNull(taskId, "Task identifier is required.");
Assert.notNull(trigger, "Trigger is required.");
//
// task has to support dry run mode
Task task = getTask(taskId);
Assert.notNull(task, "Task is required.");
if (dryRun && !task.isSupportsDryRun()) {
throw new DryRunNotSupportedException(task.getTaskType().getCanonicalName());
}
//
String triggerId = Key.createUniqueName(taskId);
trigger.setId(triggerId);
trigger.setTaskId(taskId);
// TODO use of visitor pattern may be good
if (trigger instanceof SimpleTaskTrigger) {
createTriggerInternal(taskId, (SimpleTaskTrigger) trigger, dryRun);
} else if (trigger instanceof CronTaskTrigger) {
createTriggerInternal(taskId, (CronTaskTrigger) trigger, dryRun);
} else if (trigger instanceof DependentTaskTrigger) {
createTriggerInternal(taskId, (DependentTaskTrigger) trigger);
} else {
throw new SchedulerException(CoreResultCode.SCHEDULER_UNSUPPORTED_TASK_TRIGGER, ImmutableMap.of("trigger", trigger.getClass()));
}
return trigger;
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger in project CzechIdMng by bcvsolutions.
the class AbstractScheduledTaskInitializerTest method testInitTask.
@Test
public void testInitTask() {
List<Task> tasks = schedulerService.getAllTasks();
// found test task, other will be skip
for (Task task : tasks) {
if (task.getTaskType().equals(TestTaskExecutor.class)) {
assertEquals(TEST_DESCRIPTION, task.getDescription());
assertEquals(TEST_INSTANCE, task.getInstanceId());
// assertEquals(InitTestScheduledTask.TEST_MODULE, task.getModule()); // module not working in Task
Map<String, String> parameters = task.getParameters();
assertEquals(4, parameters.size());
String value1 = parameters.get(KEY_1);
assertEquals(VALUE_1, value1);
String value2 = parameters.get(KEY_2);
assertEquals(VALUE_2, value2);
String value3 = parameters.get(KEY_3);
assertEquals(VALUE_3, value3);
Assert.assertNotNull(parameters.get(SchedulableTaskExecutor.PARAMETER_MODIFIED));
List<AbstractTaskTrigger> triggers = task.getTriggers();
assertEquals(2, triggers.size());
for (AbstractTaskTrigger trigger : triggers) {
assertEquals(TaskTriggerState.ACTIVE, trigger.getState());
if (trigger.getClass().equals(CronTaskTrigger.class)) {
CronTaskTrigger cronTrigger = (CronTaskTrigger) trigger;
assertEquals(TEST_CRON, cronTrigger.getCron());
} else if (trigger.getClass().equals(SimpleTaskTrigger.class)) {
SimpleTaskTrigger simpleTrigger = (SimpleTaskTrigger) trigger;
assertEquals(TEST_FIRE_TIME, simpleTrigger.getFireTime());
} else {
fail();
}
}
// success
return;
}
}
// test task is not initialized
fail();
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger in project CzechIdMng by bcvsolutions.
the class DefaultSchedulerManagerIntegrationTest method testMisfireHandlingSimpleTrigger.
@Test
public void testMisfireHandlingSimpleTrigger() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identityOne = identityService.get(identity);
Assert.assertNotEquals(identityOne.getUsername(), identityOne.getLastName());
//
Task createTask = new Task();
//
createTask.setInstanceId(configurationService.getInstanceId());
createTask.setTaskType(TestUpdateIdentityTask.class);
createTask.setDescription("test");
createTask.getParameters().put(ObserveLongRunningTaskEndProcessor.RESULT_PROPERTY, identityOne.getUsername());
//
Task taskOne = manager.createTask(createTask);
Task task = manager.getTask(taskOne.getId());
Function<String, Boolean> continueFunction = res -> {
return !identityService.get(identity.getId()).getLastName().equals(identity.getUsername());
};
SimpleTaskTrigger trigger = new SimpleTaskTrigger();
trigger.setTaskId(task.getId());
trigger.setFireTime(ZonedDateTime.now().minusMinutes(10));
manager.createTrigger(task.getId(), trigger);
//
getHelper().waitForResult(continueFunction);
//
identityOne = identityService.get(identityOne);
Assert.assertEquals(identityOne.getUsername(), identityOne.getLastName());
}
Aggregations