Loading Items

I am using the following method to load Items. I got this method straight out of API Recommendations document on Page7.

public static PSCoreItem loadItem(String contentId, IPSGuidManager gmgr){
System.out.println();
PSCoreItem item=null;
initServices();
IPSGuid cid = gmgr.makeGuid(new PSLocator(contentId));
try{
List<IPSGuid> glist = Collections.<IPSGuid>singletonList(cid);
List<PSItemStatus> statusList = cws.prepareForEdit(glist);
List<PSCoreItem> items = cws.loadItems(glist, true, false, false, false);
item=items.get(0);
}catch(PSErrorResultsException pre){
//Do Something to handle the Exception
}
return item;
}

Although there are some modifications that I made in it. For instance some of the methods which use obsolete versions have been replaced by the current ones.

When I run the extension, I get the following error:
com.sun.jdi.InvocationException occurred invoking method.

This error is happening after the cws.loadItems method.
Anyone any clue??

thanks
Manvinder

I think we need to know a little more about exactly how you are running this to know what the problem is. Are you sure that the content id refers to an item that exists? What workflow state is that item in?

Dave

Yes, the content id belongs to an existing item. Do I need to check out the item even for doing a simple read? The item is in the public state.

Does not the call cws.prepareForEdit(glist);

takes care of switching the workflow state of the content Item from public state to the required state?

Do we need to pass in the user and session in the loadItems call? This is what it says in the API Recommendations document. However, that method call is now obsolete, so I used the version that works without taking the session and user. Could this be the issue causing the failure to load the item?

manvinder

Hi Dave,

Just to add more information, the status seen from the call to:
List<PSItemStatus> statusList = cws.prepareForEdit(glist);

is as follows:
[com.percussion.services.content.data.PSItemStatus@529b74[contentId=703,didCheckout=true,didTransition=true,fromState=Public,fromStateId=3,toState=QuickEdit,toStateId=4]]

Also another thing I noticed is that this method call loadItem, it asks for the content Id but not the Revision ID. Could that be the issue?

thanks
Manvinder

Just to reiterate again, the error I am getting is:
com.sun.jdi.InvocationException occurred invoking method.

This error occurs after the call:
List<PSCoreItem> items = cws.loadItems(glist, true, false, false,false, session, user);

manvinder

A few answers to your various questions:

  1. Yes, prepareForEdit does transition the item to Quick Edit (as you can see from the user status object), but it might be a good idea to try this on a draft item first, just to cut down on the number of moving parts.

  2. The GUID without revision (actually it’s revision is -1) should work for a load item, and return the currently checked out revision. We did have some issues with this a very long time ago, but modern (6.5+) systems should not have this difficulty.

  3. In 6.6 and later, the user and session parameters are no longer required. The API recommendations document was written for 6.1, so this requirement was still in place at that time. The old methods are still there (just deprecated) and they will work if you call them. That is almost certainly NOT your problem.

What is required is that the request that calls the Java code must pass through the Security Filter. If this is an action menu or a JSP in /Rhythmyx/user/pages then that will always be true. If you’re calling the extension some other way, then this could be part of the problem.

How are you invoking this code?

The way I am invoking this extension is as follows:

a). I go to Rhythmyx Content Explorer
b). Click on to create a new content Item of testContentType
c). After filling all the fields, I click on Update button
d). The registered testExtension gets invoked.
e). I have eclipse setup in Debug mode, and I start stepping thru code.
f). Over there I see this problem after the loadItems method gets invoked.

I am able to retreive the value by using the following method, and there are no problems with it:

public static String findPropertyValue(IPSGuid guid, String fieldname)
{
try{
initServices();
List<IPSGuid> guids = Collections.<IPSGuid>singletonList(guid);
List<Node> nodes = cmgr.findItemsByGUID(guids, null);
if(nodes.size() > 0)
{
Node node = nodes.get(0);
if(node.hasProperty(fieldname))
{
return node.getProperty(fieldname).getString();
}
}
}catch(RepositoryException re){

      }
      return null;
   }

However, I wanted to still find out what the issue could be in the first approach. Also you mentioned about the security filter that all Java code should pass thru. What is this security filter?

thanks
Manvinder

That’s interesting. If you are able to use the Content Manager Service but not the Content Editor service, then perhaps there is a permissions issue someplace. I have not tried this on 6.7, so perhaps something has changed.

Because you are executing the extension as part of a content type, you are already going through the security filter.

Dave