use of eu.bcvsolutions.idm.core.scheduler.api.dto.AbstractTaskTrigger 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.AbstractTaskTrigger 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.AbstractTaskTrigger in project CzechIdMng by bcvsolutions.
the class AbstractScheduledTaskInitializer method createAndSaveTriggers.
/**
* Create and save trigger from {@link IdmScheduledTaskType}.
*
* @param task
* @param type
*/
private void createAndSaveTriggers(Task task, IdmScheduledTaskType type) {
Assert.notNull(task);
Assert.notNull(task.getId());
// triggers
if (type.getTriggers() != null && type.getTriggers().getTriggers() != null) {
for (IdmScheduledTaskTriggerType trigger : type.getTriggers().getTriggers()) {
AbstractTaskTrigger newTrigger = null;
try {
newTrigger = getTrigger(trigger);
} catch (ClassNotFoundException e) {
LOG.error("Trigger type: [{}], not exist. Skip init this trigger for task id: [{}]. Error message: [{}]", trigger.getType(), task.getId(), e.getMessage());
continue;
}
if (newTrigger != null) {
LOG.info("Create new trigger for task id: [{}]. Trigger type: [{}].", task.getId(), trigger.getType());
schedulerService.createTrigger(task.getId(), newTrigger);
}
}
}
}
Aggregations