Monday, May 23, 2011

Example of using native Webcenter page service API

Recently I received a request to create a task flow, which would be able to programmatically set security permissions to a (Spaces) group space page.  Of course WebCenter Spaces OOTB already has a supporting UI (from the Manage Page Link) for this task.  However, whatever the requirement is for enabling this functionality, it is good to know that there is a public API to code against.  You can view the documentation here.

In this example, since I need to interact with the Page Service, I need to create an instance of the Service:

      Scope mScope = ServiceContext.getContext().getScope();
      String scopeToUse = "defaultScope";
      if (mScope != null){
        scopeToUse = mScope.getName();
      }
      PageService mPageService =
          PageServiceFactory.createInstance(new PageServiceConfig((MDSSession)ADFContext.getCurrent().getMDSSessionAsObject(),
                                                                  scopeToUse));


In this code fragment mScope contains the MDS based information of the particular group space.  For example, in this example:

 Scope[name=MyGroupSpace, guid=s6dbba758_c69f_4602_af4d_0834b84b3dde]

There are also 2 methods that will enable the extraction of useful information about the scope itself. One is the getName(), which return the group space name, and the other getGUID(), which returns the unique id of the group space location in MDS.  These methods are great for deriving code, which can be use to pass as parameters of certain methods. Later on I will give an example of this to find the "path" of the page I want to add security on.  Once I have established the page service, I can now create code to complete my use case:

      mPageService.invalidateUserCache(getUserName());
      String grantee = "martin";
      String permisssions = "edit, view";
      String initPath = "/oracle/webcenter/page/scopedMD/";
      String testPath = initPath + mScope.getGUID() + Page2.jspx;
      PageDef pageDef = mPageService.getPage(testPath);
      // This get page in MDS at location:
      // oracle/webcenter/page/scopedMD/s6dbba758_c69f_4602_af4d_0834b84b3dde/Page2.jspx
      mPageService.changePagePermission(CustomPagePermission.class.getCanonicalName(),
                                        pageDef.getContentMRef(), true);
      mPageService.grantPagePermission(pageDef.getContentMRef(), grantee, 
      permissions);
      mPageService.saveChanges();
      mPageService.invalidateScopeCache();


There are 2 steps actually in getting this to work correctly.  The first step is that the page permission must be set to use "CustomPagePermission" page security.  The default is "PagePermission".  This is achieved by using the changePagePermisssion().  The next step is to set the new grants by using the grantPagePermission().  This method takes as its parameters, the page "path" (notice how I use the scope methods to help me create the page path), and grantee name (either a user or group, which has been defined in ldap provider, for example) , and the new permission(s), a String that has the values separated by commas.  Valid values are: manage, update, delete, personalize, view.

After invoking the code, I can query the PageSecurity Manager to check my policy updates:

page policy oracle.webcenter.page.model.security.PagePolicy@137fa30
Page : /oracle/webcenter/page/scopedMD/s6dbba758_c69f_4602_af4d_0834b84b3dde/Page2.jspx
 granted to martin

    with permission(s) [edit, view]



 Well there you have it.  A simple example showing how easy it is to use the WebCenter APIs!

5 comments:

  1. Hi Martin,

    Thanks for the post. I need some information on WebCenter Spaces.

    By default there are couple of parameters such as Space name, description, tag, url, status (Public, Private) etc. is required to create the Space with the Out-of-the-box screen in Spaces. But we have a requirement to create Group Space with some additional parameters too.

    I am finding a solution for that. Can we build a task flow with all the parameters that we need to create the Spaces ? If that is possible, can we use Spaces API to create the space and then deploy that task flow in Spaces ?

    ReplyDelete
  2. I have a requirement to create custom post/discussion in Spaces. The post component will have post name, document to attach, and other business related parameters to add there. I can't use the Out-of-the-box discussion service for this custom component. Can I use any APIs to create the discussion through the program ?

    ReplyDelete
  3. Hi Bikram,

    "we have a requirement to create Group Space with some additional parameters...". Yes, you can build your own taskflow using the Spaces API to achieve this. The createGroupSpace method has a (Map) parameter for adding custom attributes. These attributes are included in the meta-data for the created space. The procedure is documented here : http://docs.oracle.com/cd/E25178_01/webcenter.1111/e10148/jpsdg_spaces.htm#CIHIJBIG

    The Spaces API reference can be found here: http://docs.oracle.com/cd/E23943_01/apirefs.1111/e15995/toc.htm

    ReplyDelete
  4. Hi Bikram,

    Currently, there are no public APIs for the discussion service that will enable your request. If this is a urgent requirement, an enhancement request will need to be logged with support.

    ReplyDelete
  5. Hi.

    i am stuck with some thing similar issue.

    i need to create dynamic pages and set permissions to the page in webcenter portal.

    if possible could you please help me with the sample code. or any us-full documents.

    Can you please attach your sample code or send me a mail sundarakrishna@gmail.com.

    Thank you.
    Sundara.

    ReplyDelete

Note: Only a member of this blog may post a comment.