Skip to Content

Introduction

In this weblog i am going to present a Dynpage that display content assigned to a user in a nice htmlb tree display. This code is for portal version EP6 SP9 or higher.

image

Jar files required

com.sap.portal.usermanagementapi.jar,com.sap.portal.pcd.glserviceapi.jar

Step1

Create a Dynpage project using NWDS or Eclipse wizard. Add the following source code to your

dynpage

component.

package com.ust.browserole;

/* Built By: Prakash Singh

  • Universal System Technologies, Inc

  • M 407-474-2216

*/

import java.util.Hashtable;

import java.util.Iterator;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.NameClassPair;

import javax.naming.NamingEnumeration;

import javax.naming.NamingException;

import com.sap.ip.portal.service.ume.IUserManagementEngine;

import com.sap.security.api.IRole;

import com.sap.security.api.IUser;

import com.sap.security.api.UMException;

import com.sap.security.api.UMFactory;

import com.sap.security.api.srvUser.IServiceUserFactory;

import com.sapportals.htmlb.Button;

import com.sapportals.htmlb.Form;

import com.sapportals.htmlb.GridLayout;

import com.sapportals.htmlb.Group;

import com.sapportals.htmlb.InputField;

import com.sapportals.htmlb.Label;

import com.sapportals.htmlb.Tree;

import com.sapportals.htmlb.TreeNode;

import com.sapportals.htmlb.enum.GroupDesign;

import com.sapportals.htmlb.event.Event;

import com.sapportals.htmlb.page.DynPage;

import com.sapportals.htmlb.page.PageException;

import com.sapportals.portal.htmlb.page.PageProcessorComponent;

import com.sapportals.portal.pcd.gl.IPcdAttribute;

import com.sapportals.portal.pcd.gl.IPcdContext;

import com.sapportals.portal.prt.component.IPortalComponentRequest;

import com.sapportals.portal.prt.component.IPortalComponentResponse;

import com.sapportals.portal.prt.runtime.PortalRuntime;

public class display extends PageProcessorComponent {

     public DynPage getPage() {

          return new displayDynPage();

     }

     public static class displayDynPage extends DynPage {

          /**

          

  • Initialization code executed once per user.

           */

          String userid;

          private final String PCDCONTEXT =

               “com.sapportals.portal.pcd.gl.IPcdContext”;

          private final String PCDIVIEW =

               “com.sapportals.portal.ivs.iviews.IPortalIview”;

          private final String PCDPAGE =

               “com.sapportals.portal.ivs.iviews.IPortalPage”;

          private final String PCDROLE =

               “com.sapportals.portal.pcd.pcm.roles.IRoleDescriptor”;

          private final String PCDWORKSET =

               “com.sapportals.portal.pcd.pcm.roles.IWorksetDescriptor”;

          private final String PCDSYSTEM =

               “com.sapportals.iviewserver.systemlandscape.service.ISystemObject”;

          private final String PCDLAYOUT =

               “com.sapportals.portal.ivs.iviews.ILayout”;

          private final String PCDFOLDER =

               “com.sapportals.portal.pcd.pcm.roles.IRoleFolderDescriptor”;

          public void doInitialization() {

               userid = “”;

          }

          /**

          

  • Input handling code. In general called the first time with the second page request from the user.

           */

          public void doProcessAfterInput() throws PageException {

          }

          /**

          

  • Create output. Called once per request.

           */

          public void doProcessBeforeOutput() throws PageException {

               Form myForm = this.getForm(); // get the form from DynPage

               // create your GUI here….     

               Group myGroup = new Group();

               myForm.addComponent(myGroup);

               myGroup.setWidth(“350”);

               myGroup.setDesign(GroupDesign.SAPCOLOR);

               myGroup.setTitle(“Browse assigned content for a user”);

               GridLayout gl = new GridLayout();

               myGroup.addComponent(gl);

               gl.setCellSpacing(5);

               GridLayout gl1 = new GridLayout();

               gl.addComponent(1, 1, gl1);

               Label lbluserid = new Label(“Userid”);

               gl1.addComponent(1, 1, lbluserid);

               InputField inpuserid = new InputField(“userid”);

               inpuserid.setValue(userid);

               gl1.addComponent(1, 2, inpuserid);

               Button buttondisplay = new Button(“Display”);

               buttondisplay.setText(“Display”);

               buttondisplay.setOnClick(“Display”);

               gl1.addComponent(2, 1, buttondisplay);

               if (!userid.equals(“”)) {

                    Tree tree = new Tree(“S_Tree”, “”);

                    tree.setRootNodeIsVisible(false);

                    TreeNode root = new TreeNode(“e_root”, “Role Content”);

                    root.setOpen(true);

                    tree.setRootNode(root);

                    IPortalComponentResponse response =

                         (IPortalComponentResponse) this.getResponse();

                    IPortalComponentRequest request =

                         (IPortalComponentRequest) this.getRequest();

                    try {

                         IUser user =

                              UMFactory.getUserFactory().getUserByLogonID(userid);

                         Iterator role = user.getRoles(true);

                         String roleroot;

                         String imgrolepath =

                              request.getWebResourcePath() + “/images/role.gif”;

                         while (role.hasNext()) {

                              String rolestr = (String) role.next();

                              IRole r = UMFactory.getRoleFactory().getRole(rolestr);

                              roleroot = r.getUniqueName();

                              //roleroot = “portal_content/administrator/super_admin/super_admin_role/com.sap.portal.system_administration”;

                              String text =

                                   “!!”

                                        + r.getDescription();

                              TreeNode name =

                                   new TreeNode(r.getDisplayName(), text, root);

                              //response.write(“

” + r.getDisplayName() + “


“);
name.setEncode(false);
list_context(
request,
response,
getEnvironment(request),
roleroot,
name);
}
} catch (Exception e) {
try {
e.printStackTrace(
request.getServletResponse(true).getWriter());
} catch (Exception e1) {
}
}
gl.addComponent(2, 1, tree);
}

}

public void onDisplay(Event event) throws PageException {
InputField useridfld = (InputField) getComponentByName(“userid”);
userid = useridfld.getValueAsDataType().toString().toUpperCase();

}

private void list_context(
IPortalComponentRequest request,
IPortalComponentResponse response,
Context initialContext,
String browsing_root,
TreeNode name) {

try {
NamingEnumeration names = initialContext.list(browsing_root);

if (names.hasMoreElements()) {
NameClassPair nameClass;
while (names.hasMore()) {
nameClass = (NameClassPair) names.next();
String img = “”;
String new_root =
browsing_root + “/” + nameClass.getName();
//new_root = new_root.trim();
if (nameClass.getClassName().equals(PCDWORKSET))
img =
request.getWebResourcePath()
+ “/images/workset.gif”;
else if (nameClass.getClassName().equals(PCDFOLDER))
img =
request.getWebResourcePath()
+ “/images/folder.gif”;
else if (nameClass.getClassName().equals(PCDPAGE))
img =
request.getWebResourcePath()
+ “/images/page.gif”;
else if (nameClass.getClassName().equals(PCDIVIEW))
img =
request.getWebResourcePath()
+ “/images/iView.gif”;
else if (nameClass.getClassName().equals(PCDLAYOUT))
img =
request.getWebResourcePath()
+ “/images/page_layout.gif”;

String objtitle = “”;
try {

IPcdContext targetobject =
(IPcdContext) initialContext.lookup(new_root);
Object object =
targetobject.getAttributes(“”).get(
“com.sap.portal.pcm.Title”);
if (object instanceof IPcdAttribute) {
IPcdAttribute att = (IPcdAttribute) object;
objtitle = att.get(request.getLocale());
}

} catch (Exception e) {
response.write(e.getMessage() + “
“);
}

String text = “!!” + objtitle;
TreeNode name1 =
new TreeNode(nameClass.getName(), text, name);

if (nameClass.getClassName().equals(PCDWORKSET)
|| nameClass.getClassName().equals(PCDFOLDER)
|| nameClass.getClassName().equals(PCDPAGE)) {
list_context(
request,
response,
initialContext,
new_root,
name1);
}
}
}
} catch (Exception e) {
response.write(e.getMessage());
}
}

public InitialContext getEnvironment(IPortalComponentRequest request) {
String methodName = “getEnvironment”;
InitialContext initialContext = null;
try {
IUser principalObj = null;

// set the security principal
principalObj = this.getServiceUser(“pcd_service”);

Hashtable env = new Hashtable();

env.put(
Context.INITIAL_CONTEXT_FACTORY,
“com.sapportals.portal.pcd.gl.PcdInitialContextFactory”);

if (principalObj != null) {
env.put(Context.SECURITY_PRINCIPAL, principalObj);
}

env.put(
“com.sap.portal.jndi.requested_aspect”,
“com.sap.portal.pcd.gl.PersistencyAspect”);
env.put(“java.naming.factory.object”, “__IPcdContext__”);

initialContext = new InitialContext(env);

} catch (NamingException e) {
}
return initialContext;
}

public IUser getServiceUser(String username) {
IPortalComponentResponse response =
(IPortalComponentResponse) this.getResponse();

IUser serviceUser = null;

IUserManagementEngine ume =
(IUserManagementEngine) PortalRuntime
.getRuntimeResources()
.getService(
IUserManagementEngine.KEY);

IServiceUserFactory sufactory = ume.getServiceUserFactory();
try {
serviceUser = sufactory.getServiceUser(username);
} catch (UMException e) {
response.write(e.getMessage());
}

return serviceUser;

}

}
}

Step2

Step 3

Save the following images and add it to your

dist->images

folder.

image

image

image

image

image

image

Step 4

Deploy your application in your portal. h5. BAM! you got yourself a nice utility iView that display all the content assigned to a user.

image

To report this post you need to login first.

29 Comments

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

  1. Fernando. Urzedo
    Hello Prakash,

    Very nice weblog! I am wondering if this can be used as a kind of “inteligent site map”, where for each single user, it will always display the Roles, Worksets and Pages available…

    Congrats!

    (0) 
    1. Viswanath Naidu
      You know that would probably be one of the most useful tools for the SAP Portal.  I recall back in my days at TransAlta, that we did not have that ability in Ep5, so TransAlta chose to combine both SAP Portal and IBM WebSphere, with IBM WebSphere as the front end (I know, I know – what were they thinking).  This way, they could leverage functionality such as IBM WebSphere’s built-in SiteMap generation capabilities.  I love the idea, and this would be so useful for users that often complain about ‘getting lost in the Portal’.  Prakash, I know you can do your magic, as you always do, so I’d love to see this – ’cause I can definitely see value in having it in our Portal at Suncor.  Good luck to you, and I guess I can expecte a sweet weblog by you with the code in the near future (nudge, nudge, wink, wink, hint, hint).  Thanks, again – keep up the great work, Prakash!

      -Vis-

      (0) 
  2. Frank Neumann
    Hi,
    I modified your code slightly to use it in a Portal Service. Everythings works great except that I’m getting always null when I execute

    objtitle = att.get(request.getLocale())

    I exchanged request.getLocale() with the locale of the current portal user (IUser.getLocale()).

    Any idea?

    Thanks,
    Frank

    (0) 
  3. Narayanaswamy Balasubramaniam
    hi prakash

    i got the jars …….but not the latest one 

    this jar does not has the (com.sap.portal.pcd.glserviceapi.jar) following class files

    IPcdContext
    IPcdAttribute

    so please send the latest jar files

    com.sap.portal.pcd.glserviceapi.jar

    Thanks in Advance
    Swamy.B

    (0) 
  4. Neeraj Gaumber
    Hi Prakash,
    Could you please explain me the use of following tag:

    If the same code is run with some “Standard User”, then it is throwing me an exception for the above line.

    Also, What all are the privileges required for the Standard User for do the PCD look up.

    Regards,
    Neeraj

    (0) 
  5. PK G
    HI It was working on this EP version

    #Fri May 21 21:00:24 CEST 2004
    Creation-Date=20040521
    Creation-Time=1912
    Manifest-Version=1.0
    Implementation-Title=Portal version.info
    JDK-Version=1.3.1
    Creation-User=makefact
    Implementation-Vendor=SAP AG
    Sync-Changelist=204112
    Implementation-Vendor-Id=com.sap
    version=6.0.2.4.1
    Specification-Vendor=SAP AG
    Implementation-Version=6.2.0.4.200405212100
    Make-Release=60_SP2_REL
    Sync-Timestamp=200405211839

    Version History
    6.0.2.4.8_ContentManagement_Collaboration
    6.0.2.4.1.Enterprise_Portal_Service_Pack_2

    BUT NOT WORKING ON THIS VERSION
    #Wed Oct 20 02:55:46 CEST 2004
    Creation-Date=20041020
    Creation-Time=0255
    Manifest-Version=1.0
    Implementation-Title=@package-description@
    JDK-Version=${jdk.version}
    Creation-User=jointadm
    Implementation-Vendor=SAP AG
    Sync-Changelist=19348
    Implementation-Vendor-Id=com.sap
    version=6.0.9.0.0
    Specification-Vendor=SAP AG
    Implementation-Version=@package-version@
    Make-Release=60NW_VAL_REL
    Sync-Timestamp=${sync.time}

    Version History
    6.0.9.0.0.Enterprise_Portal_Support_Release

    What would be the reason.. It displays only the first role . then it throws the null exception on the dynpage.

    IS it possible to make it work even on this .

    thanks

    PK

    (0) 
    1. PK G
      Sorry it is working working on this .. some code is missing.

      Is it possible to make the iviews as live links I mean after clicking this iview I should be able to get the actual iview should open in a new window.

      pk

      (0) 
  6. Santhosh Manchala
    Hi Prakash,

    I dont have to say anything abt your great work.

    I have one requirement where I think I can use this code.
      I need to have a program which runs everyday to see what a user roles are in backend and checks to see if it has corresponding roles in Portal. If not it changes the roles of the user to match that of backend roles. If user doesnt exist in portal then it should create the user and then assign the roles.

    Can you please suggest me a solution in this case?

    Thanks in advance
    Santhosh

    (0) 
  7. Anonymous
    com.sap.ip.portal.service.ume.IUserManagementEngine;
    com.sapportals.portal.pcd.gl.IPcdAttribute;
    com.sapportals.portal.pcd.gl.IPcdContext;

    could you please send them to me to (lcalderonz@gmail.com)or maybe you know about a site where I can download directly.

    Thanks!
    Very Good Weblog, it will be very useful to me 🙂

    Leslie

    (0) 
  8. Sandeep Kumar Bonam
    Hi Prakash,
    I have one application with the same requrement. I was able to meet the requirements.
    Now I have one problem in displaying the title of a selected role. In your code you have used role.getDescription() and role.getDisplayName() which nowhere realted with title of the role.
    Coudl you please suggest me how can we get the title of a role?
    Thank you,
    Sandeep Kumar B
    (0) 
  9. Suresh Kumar
    Hi Prakash,

    It is really nice tool. We can get evrything using your code. We have the same requirement, but we need to seperate those and display. My question is I want to diplay iViews in one dropdownlist, pages in one list and so on. Can please guide me how can I seperate those.

    Regards
    Suresh

    (0) 
  10. Bruno Ambrozio
    Hi Prakash,

    I need to use your application on a Web Dynpro Application… I saw that use IPortalComponentRequest. I didn´t get to use IPortalComponentRequest on Web Dynpro.

    Can u help me?

    Thanks,
    Bruno

    (0) 
    1. Sayan Ghosh
      Hi Bruno,

      Did you find the method to implement the displaying of roles, worksets, iviews, etc as per the portal user using webdynpro ?

      I have an urgent requirement on that. Please let me know if you have found the solution.

      Thanks in advance.
      Regards,
      Sayan Ghosh

      (0) 
      1. Vivek Mishra
        Hi Aparna

        Hope you are doing good
        I have the same requirement ie I have to do the same thing in Web DynPro.

        Can you please let me know that how you did that and if possible can you send me the code to my ID ie vivek571@gmail.com

        Thanks & regards
        Vivek Kumar Mishar

        (0) 
  11. Miklos Palfi
    I know, I know, this blog entry is 5 years old.

    But for everyone, who perhaps needs it: the jar files are the c:\usr\sap\J2E\JC00\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\WEB-INF\portal\portalapps\com.sap.portal.pcd.glservice\lib\gl_api.jar and c:\usr\sap\J2E\JC00\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\WEB-INF\portal\portalapps\com.sap.portal.usermanagement\lib\com.sap.portal.usermanagementapi.jar

    Best regards,
    Miklos

    (0) 

Leave a Reply