cancel
Showing results for 
Search instead for 
Did you mean: 

How to retrieve the description of a role

detlev_beutner
Active Contributor
0 Kudos

Hi there,

does anybody know how to retrieve the description of a role? IRole.getDescription in fact returns the Role Name of the the role (for example for the Java Dev Role: Role Name is "Java Development" when you look within the PCD, Description is "Role for Portal Development Kit (PDK)"; we want to get the last, but get "Java Development" when calling getDescription()).

This is tested on 6.0 SP2 P2.

Thanks in advance

Detlev

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

The description of a role that you see in the PCD can only be retrieved by the interface com.sapportals.portal.pcd.pcm.roles.IPortalRole.

We have several role concepts in the portal. One in the usermanagment role (IRole) and the other is the portal semantic role object (IPortalRole). You have to use the 2nd one to retrieve the description. I'm not sure whether this PCD API is public. Have a look at the published PDK javadocs.

Regards,

Stefan

detlev_beutner
Active Contributor
0 Kudos

Hi Stefan,

this is quite obvious, but the question stays - how to retrieve the description? In fact, the IPortalRole does no offer the description, it is the AbstractPcmObject.

So two points are open:

1.) I insist that this is a bug. If I ask for the description and get the name, there must be something wrong...

2.) Anyhow, even without having this corrected, there should (will) be a way to retrieve the attributes of the role as a PcmObject; the way would be to search for the role (for it's unique name) within the pcd and with this at hand, just to retrieve the attribute "com.sap.portal.pcm.Description". This would be very useful in general for having access to all other attributes defined there, too.

Any help offered in this direction?

Thanks in advance,

Detlev

Former Member
0 Kudos

Hi Detlev,

1) I'm pretty shure that there is no bug. When calling getDescription() you'll get the description and not the title. What does the property editor of the portal display? If you think there might be a bug, please create a CSN message.

2) It's all well documented in the javadocs. IPcmObject.getAttributes() offers you access to all persited attributes of this specific object.

Regards,

Stefan

Former Member
0 Kudos

Hi Detlev,

this code snipped shows you how to get from the user management roles to the portal roles and how to display attributes (here e.g. the description):

package org.sb.test;

import java.util.Enumeration;

import java.util.Hashtable;

import javax.naming.Context;

import javax.naming.NamingException;

import com.sap.portal.pcd.pcm.roles.IPortalBasicRole;

import com.sap.portal.pcd.pcm.roles.IPortalBasicRoleFactory;

import com.sap.portal.pcd.pcm.roles.IPortalBasicRoleFactoryService;

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

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

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

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

import com.sapportals.portal.pcd.umwrapper.IPortalPrincipal;

import com.sapportals.portal.pcd.umwrapper.IPortalPrincipalFactory;

import com.sapportals.portal.pcd.umwrapper.IPortalPrincipalFactoryService;

import com.sapportals.portal.pcd.umwrapper.PortalPrincipalType;

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

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

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

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

import com.sapportals.portal.prt.event.IPortalRequestEvent;

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

public class Test extends AbstractPortalComponent

{

protected boolean do_load = false;

protected void doContent( IPortalComponentRequest pRequest,

IPortalComponentResponse pResponse )

{

IPortalComponentURI uri_load = pRequest.createPortalComponentURI();

uri_load.setPortalRequestEvent(pRequest.createRequestEvent("loadUser"));

IPortalBasicRoleFactoryService rfsrv =

(IPortalBasicRoleFactoryService) PortalRuntime.getRuntimeResources().getService(IPortalBasicRoleFactoryService.KEY);

Hashtable environment = new Hashtable();

environment.put( IPcdContext.SECURITY_PRINCIPAL,

pRequest.getUser());

environment.put( IPcdContext.INITIAL_CONTEXT_FACTORY,

IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);

environment.put( IPcdContext.OBJECT_FACTORIES,

IPcdContext.PCD_GL_OBJECT_FACTORY );

IPortalBasicRoleFactory fact = rfsrv.getRoleFactory(environment);

String username = "";

try

{

username = pRequest.getUser().getUniqueName();

}

catch (Exception e)

{

}

pResponse.write("<b>Test component for search of roles<p></b>");

pResponse.write("<form class=\"gSAPForm\" action=\"" + uri_load + "\">");

pResponse.write("<table class=\"gsaptable\" border=\"0\" frame=\"box\">");

pResponse.write("<tr><td>User name</td><td>" + username + "</td></tr>");

pResponse.write("<tr><td colspan=\"2\"><input class=\"gSAPInputButton\" type=\"submit\" name=\"Newbutton\" value=\"Load it\"></td></tr>");

pResponse.write("</table>");

pResponse.write("</form>");

if (this.do_load)

{

this.do_load = false;

pResponse.write("<br>Roles assigned to user: " + username + "<p></b>");

try

{

IPortalPrincipal actuser = this.getPrincipalFactory(pRequest).getPrincipalByUmObject(pRequest.getUser());

Enumeration rolenames = actuser.getMemberIds(PortalPrincipalType.ROLE, true);

if (rolenames.hasMoreElements())

{

while (rolenames.hasMoreElements())

{

String rolename = (String) rolenames.nextElement();

IPortalPrincipal role = this.getPrincipalFactory(pRequest).getPrincipalById(rolename);

IPortalBasicRole result = fact.getRole( role.getName(),

pRequest.getUser());

String pcdUrl = result.getPcdName();

pResponse.write("<p><b>----


Role URL: " + pcdUrl + "</b>");

try

{

IPcmObject pcdrole = this.getPcdObject( pRequest,

pcdUrl );

String desc = pcdrole.getDescription();

pResponse.write("<p><b>----


Role Description: " + desc + "</b>");

}

catch (NamingException pEx)

{

pResponse.write("<p><b>----


Error getting role: " + pEx.getMessage() + "</b>");

}

}

}

else

{

pResponse.write("<p>No roles assigned");

}

}

catch (NamingException ne)

{

pResponse.write("<p>Error getting roles: " + ne.toString());

}

}

}

public void doLoadUser(IPortalComponentRequest request, IPortalRequestEvent event)

{

this.do_load = true;

}

private IPortalPrincipalFactory getPrincipalFactory(IPortalComponentRequest request)

{

Hashtable environment = new Hashtable();

environment.put(IPcdContext.SECURITY_PRINCIPAL, request.getUser());

IPortalPrincipalFactoryService srv =

(IPortalPrincipalFactoryService) PortalRuntime.getRuntimeResources().getService(

IPortalPrincipalFactoryService.KEY);

return srv.getPortalPrincipalFactory();

}

private IPcmObject getPcdObject( IPortalComponentRequest pRequest,

String pPcdUrl ) throws NamingException

{

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,

pRequest.getUser() );

IPcmObjectBuilder pcmSrv = pcdFactory.getInitialContext(env);

try

{

return( (IPcmObject)pcmSrv.lookup(pPcdUrl) );

}

catch (NamingException e)

{

throw e;

}

}

}

If you want to run this iView the portalapp.xml have to look the following (concerning the private sharing references):

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

<application>

<application-config>

<property name="PrivateSharingReference" value="com.sap.portal.pcd.glservice,

com.sap.portal.pcmbuilderservice,

com.sap.portal.pcd.roleservice,

com.sap.portal.pcd.umwrapperservice,

com.sap.portal.pcd.basicrolefactory"/>

</application-config>

<components>

<component name="Test">

<component-config>

<property name="ClassName" value="org.sb.test.Test"/>

<property name="SecurityZone" value="com.sap.portal/high_safety"/>

</component-config>

<component-profile/>

</component>

</components>

<services/>

</application>

Hope this helps!

If you have the correct pcd url you can simply call the getPcdObject() method.

Regards,

Stefan

Former Member
0 Kudos

Hi,

Even I am working on fetching the PCD roles, but the code sniplet helps if we are using servlet program.

But now i need to fetch the pcd roles from java standalone program. If you have sample sniplet kindly pls share with me.

regards

Prashanth

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi there,

Can somebody advise me how to include the portal runtime into the deployment of a Web DynPro app?

I get the exception (below) when I try to call PortalRuntime.getRuntimeResources()

Many thanks,

Adomas

System info:

Web Dynpro Runtime Vendor: SAP, build ID: 7.0007.20060104142243.0000 (release=645_SP_REL, buildtime=2006-01-04:20:51:45[UTC], changelist=383287, host=pwdfm093), build date: Mon Apr 03 04:52:06 EEST 2006

J2EE Engine No information available

Java VM Java HotSpot(TM) Server VM, version:1.4.2_08-b03, vendor: Sun Microsystems Inc.

Operating system Windows 2000, version: 5.0, architecture: x86

<b>java.lang.NoClassDefFoundError: com/sapportals/portal/prt/runtime/PortalRuntime

</b> at com.sap.portaltest.PortalTestView.onActionTestButton(PortalTestView.java:169)

at com.sap.portaltest.wdp.InternalPortalTestView.wdInvokeEventHandler(InternalPortalTestView.java:141)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)

at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)

at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.doHandleActionEvent(WindowPhaseModel.java:420)

at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.processRequest(WindowPhaseModel.java:132)

at com.sap.tc.webdynpro.clientserver.window.WebDynproWindow.processRequest(WebDynproWindow.java:344)

at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:143)

at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.doProcessing(ApplicationSession.java:297)

at com.sap.tc.webdynpro.clientserver.session.ClientSession.doApplicationProcessingStandalone(ClientSession.java:696)

at com.sap.tc.webdynpro.clientserver.session.ClientSession.doApplicationProcessing(ClientSession.java:650)

at com.sap.tc.webdynpro.clientserver.session.ClientSession.doProcessing(ClientSession.java:223)

at com.sap.tc.webdynpro.clientserver.session.RequestManager.doProcessing(RequestManager.java:151)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:56)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:47)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:390)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:264)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:347)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:325)

at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:887)

at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:241)

at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)

at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)

at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)

Former Member
0 Kudos

I am getting a class cast exception at the following line on executing the code in a Portal Application.

IPortalBasicRoleFactoryService rfsrv = (IPortalBasicRoleFactoryService) PortalRuntime

.getRuntimeResources().getService

(IPortalBasicRoleFactoryService.KEY);

Error is - Caused by: java.lang.ClassCastException: com.sap.portal.pcd.pcm.roles.PortalBasicRoleFactoryService

at RolePortlet.doContent(RolePortlet.java:60)

Funny thing is this implementation class is not present in the jar file. Also the interface IPortalBasicRoleFactoryService doesnot extend from IService which is what the portal runtime resources.getService(KEY) returns.

Is this code valid for a later version of EP stack? We are using EP 6.0, UME 4.0, PDK 6.0

Please advise.

Cheers

Saby

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

Hi All,

Since, unfortunately, none of PCM is public, and neither are the semantics for role, workset and role folder, I prefer to use the PCD API -- not as elegant and too low-level, but it works.

To get the description of a role you can do the following:

Hashtable env = new Hashtable();
 
env.put(Context.INITIAL_CONTEXT_FACTORY, IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
env.put(Constants.REQUESTED_ASPECT, IPcdAttribute.PERSISTENCY_ASPECT);
env.put(Context.SECURITY_PRINCIPAL, request.getUser());
 
InitialContext iCtx = null;
String roleID = "pcd:portal_content/DanielContent/DanRole";

try{
    iCtx = new InitialContext(env);
    IPcdContext attrSet = (IPcdContext) iCtx.lookup(roleID);
		  
    response.write(attrSet.getAttributes("").get("com.sap.portal.pcm.Description").get());
}

Daniel