Hi Team,

If you have any idea please help.

Scheduler:
I have created a scheduler which will run every minute & create a data node 
under data repository.
My Scheduler config:

Scheduler
-config
---jobs
------myjobs
--------|-params
--------|--|-path-/MyXml
--------|--|-repository-data
--------|-active  - true
--------|-catalog - categorization
--------|-command - myCategorization
--------|-cron    - 0 0/1 * * * ?
--------|-description - my command

categorization
-commands
---categorization
-----myCategorization
---------|class-com.mycommand.NodeCreate

The command class code snippet which is successfully creating node is:

public class NodeCreate extends MgnlCommand{
        @Override
        public boolean execute(Context context) throws Exception {
                Content myXml = 
MgnlContext.getHierarchyManager("data").getContent("/MyXml");
                Content styleContent = myXml.createContent("Style");
                NodeDataUtil.getOrCreateAndSet(styleContent, "id", "1001");
                myXml.save();
                return true;
        }
}

My problem:
I do not want to use the Content class as it is deprecated. In magnolia API 
they have suggested to use jcr.Node instead. I am trying the code below for 
this:

public boolean execute(Context context) throws Exception {
System.out.println("My Command Class is getting called");
Session session = MgnlContext.getJCRSession("data");
Node node = MgnlContext.getJCRSession("data").getNode("/MyXml");
System.out.println(node.getName());
Node myNode = node.addNode("myNode");
myNode.setProperty("value", "myPropVal");
session.save();
}

It’s throwing the following exception below as the getJCRSession method returns 
null:

2012-07-27 16:52:00,000 INFO  info.magnolia.module.scheduler.CommandJob         
: Starting job [myJobs]...
My Command Class is getting called
2012-07-27 16:52:00,000 ERROR info.magnolia.module.scheduler.CommandJob         
: Can't execute command categorization-myCat
gorization
org.apache.commons.lang.exception.NestableException: exception during executing 
command
        at 
info.magnolia.commands.MgnlCommand.executePooledOrSynchronized(MgnlCommand.java:178)
        at info.magnolia.commands.MgnlCommand.execute(MgnlCommand.java:161)
        at info.magnolia.module.scheduler.CommandJob.execute(CommandJob.java:93)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:223)
        at 
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: java.lang.NullPointerException
        at 
info.magnolia.context.AbstractContext.getJCRSession(AbstractContext.java:134)
        at info.magnolia.context.MgnlContext.getJCRSession(MgnlContext.java:511)
        at com.mindtree.command.NodeCreate.execute(NodeCreate.java:19)
        at 
info.magnolia.commands.MgnlCommand.executePooledOrSynchronized(MgnlCommand.java:174)

Please do suggest me if I am doing anything wrong in configuration or anywhere.

-- 
Context is everything: 
http://forum.magnolia-cms.com/forum/thread.html?threadId=45380f8c-f516-4c03-b3fe-054255eb067e


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to