Tuesday, January 5, 2016

IBM WCM 8.0 - virtual-portal-scoped actions

A challenge we came across when building our REST service for using WCM as a document library was: how do I target a virtual portal? WCM content libraries are created in a virtual portal. This means that, while you're working on the same VP as your content library, you can happily access WCM content via the Java API (see my example code in an earlier article). The problem comes in when you want to access content in a library on one VP, while your client code sits on another VP or are completely run outside of the Portal (as is the case in a REST client).

To make it possible to access content across virtual portals, IBM released a fixpack (CF13) that includes something called a VirtualPortalScopedAction and some additions to the Repository. This API comes standard with Portal 8.5, but for Portal 8.0/WCM 8.0 you need to upgrade to the right fixpack.

Diving in to a sample

I've created a Gist with some sample code, which is listed here.

The code uses the WCM Query API to fetch Category items (from the WCM API) on another virtual portal and library, using a hypothetical portlet. The main players in the code are:
  • VirtualPortalScopedAction interface to implement. In the run() method you can access the WCM API as if you are running in the correct virtual portal.
  • Repository.generateVPContextFromContextPath which is a CF13+ method to generate/get a context for a virtual portal different than the one you're currently on.
  • Repository.executeInVP(VirtualPortalContext, VirtualPortalScopedAction) executes your implementation of VirtualPortalScopedAction on the required virtual portal.