Quantcast
Viewing all articles
Browse latest Browse all 3876

Unable to set/read data in UCD in Portal 7.31

Hello,

 

I have followed the links below to create AbstractPortalComponent to store user data in UCD, I was able to create the namespace but unable to bind the object to context

http://help.sap.com/saphelp_nw73ehp1/helpdata/en/4A/8E1BCE28E24DD8ABD9F4DE05E5587D/content.htm

https://help.sap.com/saphelp_nw73/helpdata/en/45/410faabe6140a3adc65df56b7d43bb/content.htm?frameset=/en/f3/c703388929464ba24caf7e8135ce4f/frameset.htm

 

Here is my sample code. Error is object of TestClass is not supported. Whenever I tried to bind the object context, I am getting either Naming exception or Obj is not supported.

 

Any idea?

 

public class TestUCD extends AbstractPortalComponent

{

 

 

 

          public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)

    {

              String namespace = "TestNamespace";

              if(!namespaceExists(namespace))

              {

                        try {

                                  INamespace ns = createNamespace(namespace);

                                  IPcdContext defaulContext = ns.getContext();

                                  TestClass obj = new TestCalss();

                                  obj.setName("hello");

                                  defaulContext.bind("Test123", obj);

 

 

                              } catch (NamingException e) {

                                        // TODO Auto-generated catch block

                                        e.printStackTrace();

                              }

              }

 

 

    }

  

          private IPcdContext getUcdContext() throws NamingException

    {

 

                     Hashtable<Object, Object> env = new Hashtable<Object, Object>();

                  env.put(Context.INITIAL_CONTEXT_FACTORY, IPcdContext.UCD_INITIAL_CONTEXT_FACTORY);

                  env.put(Context.SECURITY_PRINCIPAL, UMFactory.getAuthenticator().getLoggedInUser());

                  env.put(Constants.REQUESTED_ASPECT, IPcdAttribute.PERSISTENCY_ASPECT);

                  InitialContext ctx = new InitialContext(env);

                  return (IPcdContext) ctx.lookup("pcd:portal_content/TestUCD");

    }

    private INamespace createNamespace(String myNamespace) throws NamingException

    {

   

              IPcdContext ucdContext = getUcdContext();

            INamespaceManager namespaceManager = (INamespaceManager) PortalRuntime.getRuntimeResources().getService (INamespaceManager.KEY);

            INamespaceDescriptor myNamespaceDesc = (INamespaceDescriptor) namespaceManager.instantiateDescriptor(myNamespace);

            ucdContext.bind(myNamespace, myNamespaceDesc);

            return getNamespace(myNamespace);

    }

    private INamespace getNamespace(String myNamespace) throws NamingException

    {

            IPcdContext ucdContext = getUcdContext();

            ucdContext.addToEnvironment(Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS);

            INamespace namespace = (INamespace) ucdContext.lookup(myNamespace);

            return namespace;

    }

    private boolean namespaceExists(String myNamespace)

    {

            try

            {

                    IPcdContext ucdContext = getUcdContext();

                    ucdContext.addToEnvironment(Constants.REQUESTED_ASPECT, IPcdAttribute.ASPECT_EXISTENCE);

                    Boolean exists = (Boolean) ucdContext.lookup(myNamespace);

                    return exists.booleanValue();

            }

            catch (NamingException e)

            {

                    return false;

            }

    }

 

 

   

}


Viewing all articles
Browse latest Browse all 3876

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>