Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Vera_Gutbrod
Product and Topic Expert
Product and Topic Expert
0 Kudos

Business Scenario

In this blog we want to highlight a new feature in SAP NetWeaver 7.3 which is called "User Content Directory" (UCD). This is a new solution for applications that stores user specific data by using the Portal Content Directory (PCD).

Background Information

Some applications have the need to store user specific information that the PCD's personalization mechanism does not fully support - or doesn't support in an easy-to-use fashion. Examples of such information are: user history, search history, “Don’t ask me again” popups, etc. But now the User Content Directory is available to support such kind of use cases.
The User Content Directory (UCD) provides a storage location for applications which need to store and access user data. UCD is persisted and accessed using regular PCD APIs (i.e. JNDI) while not allowing text and binary attributes to be stored and it does not use delta links. Since the UCD's API is the same as the PCD's API, the stored data is managed by the application.
Another very important feature of the UCD is that since it is in fact a part of the PCD, its data is transportable.

Step-by-Step Procedure

You access and manage the UCD by using the JNDI API. The provided infrastructure is an UCD tree root that contains a separate context (folder) for each user. The name of the context is based on the principal ID of the user. Each user context contains application data relevant for that user only.

When storing data in the UCD, we recommend creating below each user context a separate namespace context for each application type, for example Admin Studio or Navigation. The namespace context is a semantic object of the type "com.sap.portal.ns.namespaceservice.NamespaceManager", which enables saving data within one unit. This facilitates the handling of transports, memory management, and enables loading all application-specific information to the memory with one simple lookup.

Under each namespace context, we recommend to use a separate context for each application for saving the application-specific data:

 

Differences from Regular Personalization

 

Appendix

Appendix A – Code Sample: Getting the UCD context
private IPcdContext getUcdContext() throws NamingException {
           Hashtableenv = new Hashtable();
           env.put(Context.INITIAL_CONTEXT_FACTORY,      IPcdContext.UCD_INITIAL_CONTEXT_FACTORY);
           env.put(Context.SECURITY_PRINCIPAL, user);
           InitialContext ctx = new InitialContext(env);
          return (IPcdContext) ctx.lookup(""); 
}

Appendix B – Code Sample: Checking Whether a Namespace Exists
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;
 }
}

Appendix C – Code Sample: Getting a Namespace
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;
}

Appendix D – Code Sample: Creating a Namespace
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);
}

 

 

1 Comment