Search in sources :

Example 1 with IdmScheduledTaskType

use of eu.bcvsolutions.idm.core.scheduler.jaxb.IdmScheduledTaskType in project CzechIdMng by bcvsolutions.

the class AbstractScheduledTaskInitializer method initScheduledTask.

/**
 * Method initial default long running tasks. Task will be loaded from
 * resources.
 *
 * @param tasksInputStream
 */
protected void initScheduledTask(InputStream tasksInputStream) {
    if (tasksInputStream == null) {
        LOG.warn("For module: [{}] is empty parameter 'tasksInputStream', skip init tasks for this module.", getModule());
    }
    Unmarshaller jaxbUnmarshaller = null;
    // 
    try {
        jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    } catch (JAXBException e) {
        throw new ResultCodeException(CoreResultCode.XML_JAXB_INIT_ERROR, e);
    }
    try {
        IdmScheduledTasksType tasks = (IdmScheduledTasksType) jaxbUnmarshaller.unmarshal(tasksInputStream);
        List<Task> allExistingTasks = schedulerService.getAllTasks();
        if (tasks != null) {
            for (IdmScheduledTaskType taskType : tasks.getTasks()) {
                try {
                    Task task = typeToTask(taskType);
                    LOG.debug("Task with type [{}] is successfully initialized. Try to save.", taskType.getTaskType());
                    if (existSimilarTask(task, allExistingTasks)) {
                        LOG.debug("Task with type [{}] already exist, skip save this task.", taskType.getTaskType());
                        continue;
                    }
                    LOG.info("Create new task with type [{}].", taskType.getTaskType());
                    task = schedulerService.createTask(task);
                    createAndSaveTriggers(task, taskType);
                } catch (ClassNotFoundException e) {
                    LOG.error("Scheduled task with task type [{}] can't be init. Skip this task. Error message: [{}]", taskType.getTaskType(), e.getMessage());
                }
            }
        }
    } catch (JAXBException e) {
        LOG.error("Scheduled task type validation failed, file name: {}, module: {}, error message: {}", getTasksXmlPath(), getModule(), e.getLocalizedMessage());
    }
}
Also used : Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) IdmScheduledTaskType(eu.bcvsolutions.idm.core.scheduler.jaxb.IdmScheduledTaskType) IdmScheduledTasksType(eu.bcvsolutions.idm.core.scheduler.jaxb.IdmScheduledTasksType) JAXBException(javax.xml.bind.JAXBException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 2 with IdmScheduledTaskType

use of eu.bcvsolutions.idm.core.scheduler.jaxb.IdmScheduledTaskType in project CzechIdMng by bcvsolutions.

the class BaseScheduledTaskInitializer method initScheduledTask.

/**
 * Method initial default long running tasks. Task will be loaded from
 * resources.
 *
 * @param tasksInputStream
 */
protected void initScheduledTask(InputStream tasksInputStream) {
    if (tasksInputStream == null) {
        LOG.warn("For module: [{}] is empty parameter 'tasksInputStream', skip init tasks for this module.", getModule());
    }
    Unmarshaller jaxbUnmarshaller = null;
    // 
    try {
        jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    } catch (JAXBException e) {
        throw new ResultCodeException(CoreResultCode.XML_JAXB_INIT_ERROR, e);
    }
    try {
        IdmScheduledTasksType tasks = (IdmScheduledTasksType) jaxbUnmarshaller.unmarshal(tasksInputStream);
        List<Task> allExistingTasks = schedulerService.getAllTasks();
        if (tasks != null) {
            for (IdmScheduledTaskType taskType : tasks.getTasks()) {
                try {
                    Task task = typeToTask(taskType);
                    LOG.debug("Task with type [{}] is successfully initialized. Try to save.", taskType.getTaskType());
                    if (existSimilarTask(task, allExistingTasks)) {
                        LOG.debug("Task with type [{}] already exist, skip save this task.", taskType.getTaskType());
                        continue;
                    }
                    LOG.info("Create new task with type [{}].", taskType.getTaskType());
                    task = schedulerService.createTask(task);
                    createAndSaveTriggers(task, taskType);
                } catch (ClassNotFoundException e) {
                    LOG.error("Scheduled task with task type [{}] can't be init. Skip this task. Error message: [{}]", taskType.getTaskType(), e.getMessage());
                }
            }
        }
    } catch (JAXBException e) {
        LOG.error("Scheduled task type validation failed, file name: {}, module: {}, error message: {}", getTasksXmlPath(), getModule(), e.getLocalizedMessage());
    }
}
Also used : Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) IdmScheduledTaskType(eu.bcvsolutions.idm.core.scheduler.jaxb.IdmScheduledTaskType) IdmScheduledTasksType(eu.bcvsolutions.idm.core.scheduler.jaxb.IdmScheduledTasksType) JAXBException(javax.xml.bind.JAXBException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 Task (eu.bcvsolutions.idm.core.scheduler.api.dto.Task)2 IdmScheduledTaskType (eu.bcvsolutions.idm.core.scheduler.jaxb.IdmScheduledTaskType)2 IdmScheduledTasksType (eu.bcvsolutions.idm.core.scheduler.jaxb.IdmScheduledTasksType)2 JAXBException (javax.xml.bind.JAXBException)2 Unmarshaller (javax.xml.bind.Unmarshaller)2