Skip to Content
avatar image
Former Member

Display iViews, pages, roles

Hi All,

We have a requirement in Webdynpro. Here is the requirement.

1) We need to get the list of available iViews, roles, pages, and worksets from the server.

2)We need to display those.

My question is how to get the list of available iViews, roles, pages, and worksets. I am able to get the availabale roles using the code given by sap, but I am not able to get others. Is anybody have the code related to the above requirement.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Mar 22, 2007 at 06:31 AM

    Hi

    Try this code.. hope it helps u.

    package co.ust.browserole;

    import java.util.Hashtable;

    import java.util.Iterator;

    import javax.naming.Context;

    import javax.naming.NameClassPair;

    import javax.naming.NamingEnumeration;

    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.Form;

    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.IPcdContext;

    import com.sapportals.portal.pcd.pcm.builder.IPcmEditObject;

    import com.sapportals.portal.pcd.pcm.builder.IPcmObjectBuilder;

    import com.sapportals.portal.pcd.pcm.builder.IPcmObjectService;

    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.

    */

    public void doInitialization() {

    }

    /**

    • 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....

    IPortalComponentResponse response =

    (IPortalComponentResponse) this.getResponse();

    IPortalComponentRequest request =

    (IPortalComponentRequest) this.getRequest();

    IPcmObjectService pcdFactory =

    (IPcmObjectService) PortalRuntime

    .getRuntimeResources()

    .getService(

    IPcmObjectService.KEY);

    Hashtable env = new Hashtable();

    env.put(

    Context.INITIAL_CONTEXT_FACTORY,

    IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);

    env.put(

    Context.SECURITY_PRINCIPAL,

    this.getServiceUser("pcd_service"));

    IUser user = request.getUser();

    Iterator role = user.getRoles(true);

    String root;

    while (role.hasNext()) {

    try {

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

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

    root = r.getUniqueName();

    response.write(

    "<b>" + r.getDisplayName() + "</b>" + "<br>");

    recursive_role_content(root, pcdFactory, env);

    } catch (Exception e) {

    response.write(e.getMessage());

    }

    }

    }

    public void recursive_role_content(

    String root,

    IPcmObjectService pcdFactory,

    Hashtable env)

    throws Exception {

    IPortalComponentResponse response =

    (IPortalComponentResponse) this.getResponse();

    IPcmObjectBuilder pcmSrv = pcdFactory.getInitialContext(env);

    NamingEnumeration names = pcmSrv.list(root);

    while (names.hasMore()) {

    NameClassPair nameclass = (NameClassPair) names.next();

    String pcdurl = root + "/" + nameclass.getName();

    IPcmEditObject pcmObj = (IPcmEditObject) pcmSrv.lookup(pcdurl);

    response.write(

    "Title: " + pcmObj.getTitle() + " Class Name" + pcmObj.getClass() + "<br>");

    NamingEnumeration newnames = pcmSrv.list(pcdurl);

    if (newnames.hasMore()) {

    recursive_role_content(pcdurl,pcdFactory,env);

    }

    }

    }

    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;

    }

    }

    }

    Portalapp.xml should look following.

    <?xml version="1.0" encoding="utf-8"?>

    <application>

    <application-config>

    <property name="PrivateSharingReference" value="com.sap.portal.htmlb,com.sap.portal.pcd.glservice,com.sap.portal.pcmbuilderservice"/>

    </application-config>

    <components>

    <component name="display">

    <component-config>

    <property name="ClassName" value="com.ust.browserole.display"/>

    <property name="SecurityZone" value="com.ust.browserole/high_safety"/>

    </component-config>

    <component-profile/>

    </component>

    </components>

    <services/>

    </application>

    [/nobr]

    Reward points if it helps you.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 22, 2007 at 06:38 AM
    package co.ust.browserole;
     
    import java.util.Hashtable;
    import java.util.Iterator;
     
    import javax.naming.Context;
    import javax.naming.NameClassPair;
    import javax.naming.NamingEnumeration;
     
    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.Form;
    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.IPcdContext;
    import com.sapportals.portal.pcd.pcm.builder.IPcmEditObject;
    import com.sapportals.portal.pcd.pcm.builder.IPcmObjectBuilder;
    import com.sapportals.portal.pcd.pcm.builder.IPcmObjectService;
    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.
    		 */
    		public void doInitialization() {
    		}
     
    		/**
     * 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....
    			IPortalComponentResponse response =
    				(IPortalComponentResponse) this.getResponse();
    			IPortalComponentRequest request =
    				(IPortalComponentRequest) this.getRequest();
     
    			IPcmObjectService pcdFactory =
    				(IPcmObjectService) PortalRuntime
    					.getRuntimeResources()
    					.getService(
    					IPcmObjectService.KEY);
    			Hashtable env = new Hashtable();
    			env.put(
    				Context.INITIAL_CONTEXT_FACTORY,
    				IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
    			env.put(
    				Context.SECURITY_PRINCIPAL,
    				this.getServiceUser("pcd_service"));
     
    			IUser user = request.getUser();
    			Iterator role = user.getRoles(true);
    			String root;
    			while (role.hasNext()) {
    				try {
    					String rolestr = (String) role.next();
    					IRole r = UMFactory.getRoleFactory().getRole(rolestr);
    					root = r.getUniqueName();
    					response.write(
    						"<b>" + r.getDisplayName() + "</b>" + "<br>");
    					recursive_role_content(root, pcdFactory, env);
     
    				} catch (Exception e) {
    					response.write(e.getMessage());
    				}
    			}
     
    		}
    		public void recursive_role_content(
    			String root,
    			IPcmObjectService pcdFactory,
    			Hashtable env)
    			throws Exception {
     
    			IPortalComponentResponse response =
    				(IPortalComponentResponse) this.getResponse();
    			IPcmObjectBuilder pcmSrv = pcdFactory.getInitialContext(env);
    			NamingEnumeration names = pcmSrv.list(root);
    			while (names.hasMore()) {
    				NameClassPair nameclass = (NameClassPair) names.next();
    				String pcdurl = root + "/" + nameclass.getName();
    				IPcmEditObject pcmObj = (IPcmEditObject) pcmSrv.lookup(pcdurl);
    				response.write(
    					"Title: " + pcmObj.getTitle() + " Class Name" + pcmObj.getClass() + "<br>");
    				NamingEnumeration newnames = pcmSrv.list(pcdurl);
    				if (newnames.hasMore()) {
    					recursive_role_content(pcdurl,pcdFactory,env);
    				}
    			}
     
    		}
    		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;
     
    		}
     
    	}
    }
    
    
    
    
    Portalapp.xml should look following.
    
    <?xml version="1.0" encoding="utf-8"?>
    <application>
      <application-config>
        <property name="PrivateSharingReference" value="com.sap.portal.htmlb,com.sap.portal.pcd.glservice,com.sap.portal.pcmbuilderservice"/>
      </application-config>
      <components>
        <component name="display">
          <component-config>
            <property name="ClassName" value="com.ust.browserole.display"/>
            <property name="SecurityZone" value="com.ust.browserole/high_safety"/>
          </component-config>
          <component-profile/>
        </component>
      </components>
      <services/>
    </application>
    
    [/nobr]
    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      Thanks for your code. I already have this code from one blog. But the requirement is in webdynpro. I am able run the application in webdynpro also, I am facing the issue with usermanagement engine code, here is the code

      IUserManagementEngine ume = (IUserManagementEngine) PortalRuntime

      .getRuntimeResources().getService( IUserManagementEngine.KEY);

      How can I achieve this one in webdynpro.

  • avatar image
    Former Member
    Mar 22, 2007 at 06:54 AM

    Hi EP Developer,

    Alternatively, you can go through <a href="/people/prakash.singh4/blog/2005/07/28/browse-roles-folders-pages-iviews-assigned-to-a-user-ep6-sp9-and-higher weblog for your reference.

    Thanks and Regards,

    Mausam

    Add comment
    10|10000 characters needed characters exceeded