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

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

        

  1.     try
  2.           IUser usr = UMFactory.getUserFactory().getUserByLogonID("Test_Admin");           
  3.           Hashtable env = new Hashtable(); 
  4.           env.put(Context.INITIAL_CONTEXT_FACTORY,IPcdContext.PCD_INITIAL_CONTEXT_FACTORY); 
  5.           env.put(Context.SECURITY_PRINCIPAL, usr); 
  6.           env.put(Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS);           
  7.  
  8.           InitialContext ctx = null;           
  9.           List<String> iViewList =null;         
  10.           DirContext dirCtx = null
  11.  
  12.           ctx = new InitialContext(env); 
  13.           //IAdminBase result =(IAdminBase)ctx.lookup(objectName); 
  14.           dirCtx = (DirContext) ctx.lookup("pcd:portal_content/test_pcd"); 
  15.  
  16.           //set the search controls to find only the iviews           
  17.           PcdSearchControls pcs = new PcdSearchControls(); 
  18.           pcs.setReturningObjFlag(false); 
  19.           pcs.setSearchScope(PcdSearchControls.SUBTREE_WITH_UNIT_ROOTS_SCOPE);           
  20.           dirCtx.addToEnvironment(Constants.APPLY_ASPECT_TO_CONTEXTS,Constants.APPLY_ASPECT_TO_CONTEXTS); 
  21.  
  22.           NamingEnumeration<SearchResult> ne;         
  23.           //ne = dirCtx.search("","(com.sapportals.portal.pcd.gl.IPcdName=com.sapportals.portal.iview)",pcs);           
  24.           ne = dirCtx.search("","(com.sap.portal.pcd.gl.ObjectClass=com.sapportals.portal.iview)",pcs); 
  25.  
  26.          // fetching iviews         
  27.           iViewList = new ArrayList<String>(); 
  28.  
  29.           while(ne.hasMoreElements()) 
  30.           { 
  31.               IPcdSearchResult searchResult = (IPcdSearchResult)ne.nextElement();  
  32.               String location = "pcd:portal_content/test_pcd/" + searchResult.getName(); 
  33.               //Get the full pcd path of the iview.  
  34.               wdComponentAPI.getMessageManager().reportSuccess("-->iView::"+location); 
  35.               //iViewList.add(location); 
  36.           }  
  37.           } catch (NamingException e) { 
  38. //            // TODO Auto-generated catch block 
  39.               wdComponentAPI.getMessageManager().reportSuccess("Look Up Error::"+e.getMessage()); 
  40.          } 
  41.           catch (Exception e1){ 
  42.              wdComponentAPI.getMessageManager().reportSuccess("Error2::"+e1.getMessage()); 
  43.        }

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. Maruthi Purnachandra Rao

    Hi Sandip,

    I am trying to run the code in NWDS 7.3 SP07 with Portal 7.3 , But I have got some problem with the code at line

    PcdSearchControls pcs = new PcdSearchControls(); 

    So I have also opend a blog http://scn.sap.com/thread/3245283,

    Can you please help. I would like to see your program works for me.

    I am actually trying to retrieve the worksets, Pages assigned to any given Portal role.

    Appreciate you help with code so I can use.

    Thank you

    Regards

    Maruti

    (0) 
  2. Patrick S

    Hi Sandip,

    thank you for this article!

    I tried your code in an Abstract Portal Component, but have currently several problems:

    I can’t use IPcdContext, PcdSearchControls and IPcdSearchResult, due to missing/ not recognized class-file.

    Which JAR have you imported to use these classes?

    I thought they are part of gl_api.jar (when I unzip it, there are such class-files inside), but NWDS cannot resolve it..

    When i try to import the classes I get the following errors:

    import com.sapportals.portal.pcd.gl.IPcdContext cannot be resolved

    import com.sapportals.portal.pcd.gl.PcdSearchControls cannot be resolved

    import com.sapportals.portal.pcd.gl.IPcdSearchResult cannot be resolved

    Why can’t they be resolved? Any ideas?

    Regards,
    Patrick

    (0) 
    1. Sandip Agarwalla Post author

      Patrick

      which versiion of server you are using? Also have you created a local project (versions older to 7.3) or DC based project

      if its a DC based development – you need the dc tc\epbc\pcd\gl\api

      Thanks

      Sandip

      (0) 
      1. Patrick S

        Hi Sandip,

        thx for reply.

        I am using 7.3 and want to deploy the project as an Abstract Portal Component. Might this be the problem?

        Regards,

        Patrick

        (0) 
        1. Sandip Agarwalla Post author

          Patrick

          You can create an APC as well, shouldnt be a problem..

          Just make sure you reference the correct DCs..with 7.3 – you need to use dc based projects..

          (0) 
  3. Bilel OTHMAN

    Thanks for this great tutorial,

    but when I use this code under a webDynPro application to display all folders under portal_content directory: I haven’t all folders just few of them>

    can you tell me why please

    thanks in advance

    Cheers

    Bilel

    (0) 

Leave a Reply