{
HierarchyManager hm = MgnlContext.getSystemContext().getHierarchyManager(ContentRepository.CONFIG);
try
{
Content root = hm.getContent(SchedulerConsts.ROOT_PATH_FOR_JOBS);
Content jobNode = ContentUtil.getOrCreateContent(root, definition.getName(), ItemType.CONTENTNODE);
NodeDataUtil.getOrCreateAndSet(jobNode, "active", definition.isActive());
if (StringUtils.isNotBlank(definition.getCatalog()))
NodeDataUtil.getOrCreateAndSet(jobNode, "catalog", definition.getCatalog());
if (StringUtils.isNotBlank(definition.getCommand()))
NodeDataUtil.getOrCreateAndSet(jobNode, "command", definition.getCommand());
if (StringUtils.isNotBlank(definition.getGroovyScript()))
NodeDataUtil.getOrCreateAndSet(jobNode, "groovyScript", definition.getGroovyScript());
NodeDataUtil.getOrCreateAndSet(jobNode, "cron", definition.getCron());
if (definition.getStartTime() != 0)
NodeDataUtil.getOrCreateAndSet(jobNode, "startTime", definition.getStartTime());
if (definition.getEndTime() != 0)
NodeDataUtil.getOrCreateAndSet(jobNode, "endTime", definition.getEndTime());
if (definition.getLastFireTime() != 0)
NodeDataUtil.getOrCreateAndSet(jobNode, "lastFireTime", definition.getLastFireTime());
if (definition.getNextFireTime() != 0
&& (definition.getEndTime() == 0 || (definition.getEndTime() != 0 && definition.getNextFireTime() < definition
.getEndTime())))
NodeDataUtil.getOrCreateAndSet(jobNode, "nextFireTime", definition.getNextFireTime());
NodeDataUtil.getOrCreateAndSet(jobNode, "terminatedWithError", definition.isTerminatedWithError());
if (StringUtils.isNotBlank(definition.getDescription()))
NodeDataUtil.getOrCreateAndSet(jobNode, "description", definition.getDescription());
if (definition.getParams() != null && !definition.getParams().isEmpty())
{
Content paramNode = ContentUtil.getOrCreateContent(jobNode, "params", ItemType.CONTENTNODE);
Iterator children = paramNode.getNodeDataCollection().iterator();
while (children.hasNext())
{
NodeData node = (NodeData) children.next();
log.debug("deleting node {}", node.getHandle());
node.delete();