Pre-processor Extension - how can it update Active Assembly relationships?

I am developing an extension to take a list of content IDs and use that list to populate an Active Assembly slot with the corresponding content items. I was considering making this a pre-processor extension, because I want it to run when the item is being saved. However, the pre-processor class only seems to provide access to the IPSRequestContext, so I’m not sure how to use it to modify slot contents. From my observation of URLs and tracing the rcsupport XML application, I don’t think that relationship changes are handled via the request that happens when an item is saved.

Can anyone point me to classes that will help with modifying relationships? Do I need to call Web Services from the pre-processor in order to delete or add relationships?

Thanks for any and all suggestions.

Kmbailey, it should be possible to initiate IPSContentWs and add [content relations](http://code.percussion.com/javadoc/cmsystem/7.0.3/com/percussion/webservices/content/IPSContentWs.html#addContentRelations(com.percussion.utils.guid.IPSGuid, java.util.List, java.lang.String, java.lang.String, int)). You can obtain the ContentWebService by using this helper class/method.

IPSContentWs IPSContentWs = PSContentWsLocator.getContentWebservice();

You would also need to obtain the sys_contentid from IPSRequestContext.getParameter(‘sys_contentid’). The sys_contentid and list of content IDs would need to be converted into an IPSGuid object in order to focus IPSContentWs on the content item and to add content items to the slot. This may all be a bit confusing but let me know where I can help. There are other routes for adding content relations, but it really depends on what you’re familiar with using.

Just keep in mind that when you are using the pre-processor, the item may not have a content id (i.e. if the item is about to be created). Without this content id, it would be difficult for you to add items to a slot…

Good thing to keep in mind.

Riley - Thanks for the suggestion and details about using the Content Web Service. I am going to give that a try.

Also, Jitendra, thank you for pointing out that I may not have the content ID when I’m in the pre-processor context - good catch. I wonder if this would be better implemented a post-processor extension instead. It’s not really altering the result document, but instead having a side-effect of adding relationships. I do need the item to exist in order to add those relationships, so the post-processor may be a better place to hook this in. The signature of the method in that interface is:

processResultDocument(Object[] params,
IPSRequestContext request,
Document resultDoc)

so I assume I can get the content ID of the item I’m editing (for the owner of the new relationships) from the resultDoc parameter of that method.

Let me know if you have any additional ideas - I will post a note in here on my results.

Thanks,
Kathleen

I’ve gotten the basic structure working here, populating the slot in a post-processor extension. Thanks for the advice on how to do this - so far, so good.

I am now stuck on another aspect of this - does anyone know how to get child table values in the context of a Post-Processor extension? In the post-processor method (processResultDocument) I have access to the IPSRequestContext and the Document (result document) objects, but I haven’t yet figured out how to get the child table entries from either of those objects.

I tried using the GUID for the item to call IPSContentWs.loadChildEntries method, but that sent me into an infinite loop, since it ends up calling the pre-processor extension as part of the load (oops!).

Right now I’m trying to use com.percussion.pso.validation.PSOItemXMLSupport to get the child table rows from the result document, but I’m not sure that’s going to work.

Anyone have experience with this? Any pointers to how to approach it?

When I created the nas file extension, I had a check in place that created a session object with a counter (to make sure that the processor only ran once). You may be able to do the same thing to ensure that the code in the pre-processor is only being run once for that contentid per session (You could even clear this value out at the end of the pre-processor… the basic idea here is to prevent an infinite loop)…

I added a private session object (used your NAS code as an example), and no more infinite loop…awesome. Many thanks for that!

Now I can (finally) work on getting the child rows in order to populate my slot…