Long living Dynamic Business Components

Recently I came across an interesting post from Juan Oropeza (Oracle) in an internal wiki, the code was illustrating dynamic ViewObject creation which lives beyond user sessions. Thanks to Steve Muench who did help me to understand this thing better. Today's post is on this topic.

What is so great about this concept? Well, there are few good stuff for you. Read on...

In one of my previous post, I blogged about building dynamic UI -Model driven approach for building Dynamic UI. There the life of a dynamically created view object or entity object were limited to a user session in which they were created. What if you need the dynamically created ADF business components to be available across all user, beyond a specific user session. A real life use case may be adding couple of more attributes or validations on an existing View Object definition at run time which needs be reflected across all users. Well this is quite possible by getting the personalization definition of the ViewObject - PDefViewObject and performing the alteration on it. Later, When an meta data for view object or entity definition is loaded, it checks for corresponding PDef object and, if present, superimpose the PDef on existing meta data. The end-user sees a definition that is the union of the base definition plus the additional personalizations. The below shown code snippet may help you to understand the API to be used for altering view object which needs to live beyond the user session. Please note that pDefVO.saveXMLContents() makes use of MDS to store the altered definition. To make this thing to work, you may need to have right entries added in your adf-config.xml.

 private boolean addLocAttributeToDeptView() {  
      ViewDefImpl viewDef = ViewDefImpl.findDefObject("sessiondef.dynamic.DynamicDeptViewDef");  
      PDefViewObject pDefVO = (PDefViewObject)viewDef.getPersDef();  
      if (pDefVO == null) {  
           pDefVO = new PDefViewObject();  
           pDefVO.setFullName(viewDef.getFullName());  
      }  
      if (pDefVO.getAttributeIndexOf(ATTRIB_LOC_ID) != -1) {  
           return false;  
      }  
      pDefVO.setEditable(true);  
      pDefVO.addEntityAttribute(ATTRIB_LOC_ID, "DynamicDeptUsage", ATTRIB_LOC_ID, true);  
      pDefVO.applyPersonalization(findViewObject(DYNAMIC_DETP_VO_INSTANCE));  
      pDefVO.writeXMLContents();  
      pDefVO.saveXMLContents();  
      return true;  
 }  

Download

You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11.1.2.0.0 (11g R2) + HR Schema]

A glance at the implementation

This example uses personalizedbc-sample-task-flow-definition to create a dynamic entity object and view Object. The second step in the task flow alter the dynamic view object to add location id right before displaying the dynamically created VO to end user.


The adf-config.xml used for this example has been configured to use file based MDS store to keep the dynamic business component definitions.
 <persistence-config>  
      <metadata-namespaces>  
           <namespace path="/sessiondef" metadata-store-usage="mdsRepos"/>  
           <namespace path="/persdef" metadata-store-usage="mdsRepos"/>  
           <namespace path="/xliffBundles" metadata-store-usage="mdsRepos"/>  
      </metadata-namespaces>  
      <metadata-store-usages>  
           <metadata-store-usage id="mdsRepos" deploy-target="true" default-cust-store="true"/>  
           <!-- <property name="metadata-path" value="/tmp"/> -->  
      </metadata-store-usages>  
 </persistence-config>  

How to run this sample?

1. Run main.jspx
2. This sample is security enabled. Key in user name/password as developer1/developer1, when asked for.
3. The above mentioned task flow generates DynamicDeptEntityDef and DynamicDeptViewDef at runtime and saves the definition to MDS store. The DynamicDeptVO1 is exposed to client for use.
4. Run the main.jsf once again and this time enter username/password as developer2/developer2. You may notice that previously created VO definition is available to the second user as well.


Learn More ...

There are a lot more points like this. If  you are curious to learn the internals of the ADF Business Components and ADF Binding Layer,  the following book is for you - Oracle ADF Real World Developer’s Guide.
More details about this book can be found in this post- http://jobinesh.blogspot.in/2012/07/pre-order-your-copy-of-oracle-adf-real.html





Comments

  1. Hi Jobinesh,

    What does the oracle.jbo.server.EntityDefImpl.DEF_SCOPE_SESSION indicates in the below code EntityDefImpl entDef =
    new EntityDefImpl(oracle.jbo.server.EntityDefImpl.DEF_SCOPE_SESSION, "DynamicDeptEntityDef");. Thanks.

    ReplyDelete
  2. Hi Jobinesh,

    When i am trying to test the method buildDynamicDeptComp in the AMImpl class i am getting MDSConfiguration exception as below namespace "/sessiondef" mapped to metadata-store-usage "mdsRepos" but its definition was not found in MDS configuration.

    ReplyDelete
  3. Shobith,
    Pls read this post http://www.jobinesh.com/2013/07/mds-setting-for-testing-pdef-business.html

    ReplyDelete
  4. Hi Jobinesh,

    I am getting a 'NameClashException: JBO-25001: Object COURSE_ID of type Attribute already exists' exception while trying to append one more attribute to existing PDef.(as below)

    PDefViewObject pDefVO = PDefViewObject)viewDef.getPersDef();

    pDefVO.setEditable(true);
    pDefVO.addEntityAttribute(attrName, "DynamicDeptUsage1",attrName, true);

    and the same exception is reoccurring while removing attributes from PDef.

    Could you please help me in this regard.

    ReplyDelete

Post a Comment