Skip to Content

This blog shows how to retrieve PCD Objects (iViews/Pages/Roles etc) from a PCD Folder on the Portal 7.3 version using Custom Java Code.

First some Concepts – The Portal Content Directory (PCD) is the main repository for portal content, both delivered with the portal and created by administrators. The PCD contains a hierarchy of folders, each of which can contain semantic objects, such as iViews, pages and roles. The PCD is stored in the portal database and is accessed via the PCD Generic Layer (GL), and provides APIs to enable applications to perform look ups and modify the PCD Objects.

Each provider defines the logic for returning Java objects when querying a specific portal semantic object. A semantic object is defined by its com.sap.portal.pcd.gl.ObjectClass property.  When a lookup is performed on an object, the PCD checks the object class attribute to determine which object provider to use for creating/Editing a Java object from the set of attributes.Below table shows the respective GL property for different Semantic Objects like iViews, Pages etc

PCD Object GL Property Name
iViews com.sapportals.portal.iview
Pages com.sapportals.portal.page
Roles com.sapportals.portal.role

The below diagram shows the Process Flow when you do a look up on the PCD

18-Jul-12 1-52-35 PM.jpg

Source for the Above Section**: SAP Materials and SAP Help Web Sites

Ok then, enough of Concepts. Lets straight way dive into the source code. Here are the steps.

1) Create the custom DC project

     Create and set up a custom DC thru NWDS. In my case, its a WD Java DC, but you can very well use PDK/JAVA EE DC


    

         
2) Add the DC dependency for JAR files for PCD GL, JNDI etc APIs

     Open up Development Infrastructure Perspective, locate your DC and open up the DC Component Properties. Then Click on “Dependecies” Tab.

     Add the required DCs by clicking on ADD button. The JAR DCs you would need for referencing the PCD GL, JNDI etc are highlighted in the right hand side Image.

     

         


3) Source Code to retrieve Objects

     Add the following source code in the Java class

         

    try{
          IUser usr = UMFactory.getUserFactory().getUserByLogonID("Test_Admin");         
          Hashtable env = new Hashtable();
          env.put(Context.INITIAL_CONTEXT_FACTORY,IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
          env.put(Context.SECURITY_PRINCIPAL, usr);
          env.put(Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS);         
          InitialContext ctx = null;         
          List<String> iViewList =null;       
          DirContext dirCtx = null;
          ctx = new InitialContext(env);
          //IAdminBase result =(IAdminBase)ctx.lookup(objectName);
          dirCtx = (DirContext) ctx.lookup("pcd:portal_content/test_pcd");
          //set the search controls to find only the iviews         
          PcdSearchControls pcs = new PcdSearchControls();
          pcs.setReturningObjFlag(false);
          pcs.setSearchScope(PcdSearchControls.SUBTREE_WITH_UNIT_ROOTS_SCOPE);         
          dirCtx.addToEnvironment(Constants.APPLY_ASPECT_TO_CONTEXTS,Constants.APPLY_ASPECT_TO_CONTEXTS);
          NamingEnumeration<SearchResult> ne;       
          //ne = dirCtx.search("","(com.sapportals.portal.pcd.gl.IPcdName=com.sapportals.portal.iview)",pcs);         
          ne = dirCtx.search("","(com.sap.portal.pcd.gl.ObjectClass=com.sapportals.portal.iview)",pcs);
         // fetching iviews       
          iViewList = new ArrayList<String>();
          while(ne.hasMoreElements())
          {
              IPcdSearchResult searchResult = (IPcdSearchResult)ne.nextElement();
              String location = "pcd:portal_content/test_pcd/" + searchResult.getName();
              //Get the full pcd path of the iview.
              wdComponentAPI.getMessageManager().reportSuccess("-->iView::"+location);
              //iViewList.add(location);
          }
          } catch (NamingException e) {
//            // TODO Auto-generated catch block
              wdComponentAPI.getMessageManager().reportSuccess("Look Up Error::"+e.getMessage());
         }
          catch (Exception e1){
             wdComponentAPI.getMessageManager().reportSuccess("Error2::"+e1.getMessage());
       }

4) Validation of Results

    A quick check to see if the code really gets all the iViews from the specified folder including sub folders as well

                

And, here we go – we could successfully fetch the iViews from the specified Folder. The Source Code can be extended to fetch Pages/Roles as well by modifying the ObjectClass property to Page or Role

com.sap.portal.pcd.gl.ObjectClass=com.sapportals.portal.page

Hope the blog would be useful to you. Comments/Suggestions are welcome…

Sandip Agarwalla

To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

  1. Simon Kemp

    Thanks for taking the time to share Sandip. Just one question, what have you used this for in the past? Can you imagine what you might do once you have read the data from the PCD?

    Btw… did you mean to create this as a document or a blog post?

    Cheers,
    Simon

    (0) 
    1. Sandip Agarwalla Post author

      Hey Simon

      Initially, I wanted to create this as a Wiki link. However found it difficult to navigate to the proper wiki page where it should be created. so finally created as a blog (simple and easy).

      On the use case – well I didnt have any scenario when I wrote this. In the past, there have occasions where Clients had asked for such functionality to build custom Portal Content Admin screens (dnt exactly remember the scenario). I know there are alternates, this is just one of them..

      Regards

      Sandip

      (0) 
      1. Simon Kemp

        Hi Sandip… I guess I was just a bit confused why your “blog” wasn’t showing up in the blog stream http://scn.sap.com/community/netweaver-portal/blog I think it is because you created a “document” not a “blog post”. No big deal, just wondering if that is what you intended 🙂

        Again thanks for sharing and also for giving some context as to why someone might want to do this. I guess another scenario might be if you wanted to be able to programmatically create PCD content – basically automating the job of the portal admin – OMG!… now I am out of a job! 😛

        Thanks again,

        Simon

        (0) 
        1. Sandip Agarwalla Post author

          Mate, Well – we will not share the code to create/editing/permission objects 😉 ..And introduce few bugs in the code…There by Securing our Jobs !!! Mine is also at stake, am with you 😎

          Ya now I realized what you mean. Looks like I published it as a document instead of a blog..Thats why its not showing in the blog stream..Wondering should I re-create it as a blog again..Or can the moderator move it to the blog section.

          By any chance, are you the Moderator 😕

          Jason Lax – Hey Jason, can you help on this? I intended to post this as a blog but end up doing a document (Tell you man this new SCN Platform)…Is there a way we can migrate this as a Blog..Who is the moderator of this Group?

          Regards

          Sandip

          (0) 
          1. Simon Kemp

            Leave it where it is, no big deal. Not really sure of the difference between a Blog Post and a Document on this new SCN anyway 😆 . I just reflected on the fact that I didn’t see it in the Blog stream which I follow.

            (0) 

Leave a Reply