Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
SandipAgarwalla
Active Contributor

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

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

6 Comments
Labels in this area