Document metadata Set/Get

WebCenter Content User Interface – Get and Set Document’s Metadata

Hi all,

In my previous post about WebCenter Content User Interface I have written an overview about the available features of this new UI as well as how to start customizing it, and my experience and important milestones regarding installation. You can find my previous post here.

Today I’m going a little further and focus the attention on how to get and set document’s current properties and metadata attributes using the API available in the “WccAdfCustomization” application.

In my last post I’ve dragged-and-dropped a button to the “docInfoTabs.jsff” page that you can find inside of the “WccAdfLibrary.jar” library of the ViewController project. This is how it looks like:MyCustomButton

Now what we want is to get both document’s properties and metadata, and then set the comments for this same document when we click on the button. To do this we need to perform the following steps:

  1. Open the JDeveloper with “Default Role”. Then go to the ViewController project and create “MyCustomClass” java class. Create an action event listener method to be used by our button.MyCustomClass
  2. Assign “MyCustomClass” java class to the managed beans of “adfc-config.xml” file. From now on this class is available in the context of the “docInfoTabs.jsff” page.ManagedBean
  3. Go to your “docInfoTabs.jsff.xml” file and set the actionListener property like is shown in the next image:ActionListener
  4. Our “docInfoTabs.jsff” page is invoked inside “wccdoc.xml” bounded task flow. If you go to Managed Beans tab you can see the available classes inside it. We will take advantage of “DocInfoBean” class.WccdocTaskFlow
  5. Let’s return to our “MyCustomClass” java class and insert the following code inside “myCustomButtonAction”.
package wcc.custom.view;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import oracle.wcc.adf.model.Attachment;
import oracle.wcc.adf.model.Revision;
import oracle.wcc.adf.model.form.Field;
import oracle.wcc.adf.model.form.Form;
import oracle.wcc.adf.model.form.Item;
import oracle.wcc.adf.vc.DocInfoBean;
import oracle.wcc.adf.vc.DocumentOperationHelper;
import oracle.wcc.adf.vc.DynamicFormBean;

public class MyCustomClass {
    public MyCustomClass() {
        super();
    }
    
    public void myCustomButtonAction(javax.faces.event.ActionEvent p1) {
        
        //Getting document's properties
        
        //Getting the instance of 'DocInfoBean' class.
        DocInfoBean docInfoBean = (DocInfoBean)ADFUtils.getValueFromViewScope("wccDocInfoBean");
        //Getting the current revision of the selected document.
        Revision revision = docInfoBean.getRevision();
        System.out.println("Document Title:" + revision.getDDocTitle());
        System.out.println("Document Author: " + revision.getDDocAuthor());
        System.out.println("Document Last Modified Date: " + revision.getDReleaseDate());
        System.out.println("Document Status: " + revision.getLocalizedDStatus());
        System.out.println("Document Revision Number:" + revision.getDRevLabel());
        System.out.println("Document Comments: " + revision.getXComments());
        System.out.println("Document Profile: " + revision.getXIdcProfile());
        System.out.println("Document Type: " + revision.getDDocType());
        System.out.println("Document Format: " + revision.getDFormat());
        System.out.println("Document File Size: " + revision.getDFileSize());
        
        //Getting all metadata of the current revision of the selected document.
        DynamicFormBean dynamicFormBean = docInfoBean.getMetadataFormBean();
        Form form = dynamicFormBean.getForm();
        HashMap<String, Serializable> fieldValues = form.getFieldValues();
                
        Iterator iter = fieldValues.entrySet().iterator();
        while (iter.hasNext())
        {
            Map.Entry pair = (Map.Entry)iter.next();
            System.out.println(pair.getKey() + " = " + pair.getValue());
        }
        
        revision.setXComments("My Custom Comment");
        docInfoBean.setRevision(revision);
        //Set document's metadata for the current revision.
        DocumentOperationHelper.updateRevision(revision);
    }
}

6. The “getValueFromViewScope” method in my ADFUtils class look likes this:

public static Object getValueFromViewScope(String variable) {
      return AdfFacesContext.getCurrentInstance().getViewScope().get(variable);
}

7. Finally run your application and test the button.

 

Cheers,

Pedro Gabriel

@PedrohnGabriel

Post image by Cross Duck with small changes.

6 replies
  1. Nick Klomp
    Nick Klomp says:

    Thanks for this interesting article. I tested it on my integrated weblogic server and the custom button and Java method works fine. However, as the official documentation notes that customisations to the ADF WEB UI in a production environment should be deployed as Seeded customisations using MAR files it is doubtful your custom Java code can be included this way as we don’t redeploy a full EAR/WAR to the managed server.

    Have you any idea if we can make use of custom code/taskflows and how we can do this in a production environment?

    Reply
    • Pedro Gabriel
      Pedro Gabriel says:

      Hi Nick,

      I’m sorry my late reply but work has not helped me 😛

      You can make use of custom code or task flows in UCM ADF UI.

      From my experience the best approach would be to create an ADF View Controller that collects all your reusable code (task flows, java utilities, etc). Generate the jar for this project and import it in the main UCM ADF project that oracle provides.

      Then you can drag and drop your task flows to wherever you want them.

      With this approach you are able to:

      You have further control over your code in your own library.
      You can test your own code, task flows in separate.
      In future migration of UCM ADF UI you may have less changes to do.
      With Oracle changes their pages in future versions you can refactor more easily.

      Best Regards,
      Pedro Gabriel

      Reply
  2. Nick Klomp
    Nick Klomp says:

    Hi Pedro,

    Thanks for the reply. I created a JAR file of the classes created in this Blog and added them to the classpath of the ADF server. In the uploaded MAR file I included the adfc-config.xml with the reference to the customclass. However, clicking the button results in a:

    javax.el.PropertyNotFoundException: /wcc/docInfoTabs.jsff @358,209 actionListener=”#{pageFlowScope.MyCustomClass.myCustomButtonAction}”: Target Unreachable, ‘null’ returned null

    Any idea’s on this?

    Thanks Nick

    Reply
    • Pedro Gabriel
      Pedro Gabriel says:

      Hi Nick,

      I am sorry for my very late reply.

      It seems that you might have missed the configuration for the “customerCustomizationLayerValues” variable inside “adf-config.xml” file while running the application. Take a look at “Where can I create a customization layer?” section in my previous post “http://redmavericks.com/blog/2016/04/01/webcenter-content-user-interface-overviewinstallationcustomization/”

      Best Regards,
      Pedro Gabriel

      Reply
  3. Murty Veeraghanta
    Murty Veeraghanta says:

    Hi Pedro,

    Thanks for this interesting article. Where can I find the API of oracle.wcc.adf.model.form.Field etc? oracle.wcc package?

    Thanks,
    Murty

    Reply
    • Pedro Gabriel
      Pedro Gabriel says:

      Hi Murty,

      The “Field” class is inside “WccAdfLibrary.jar” in
      the package “oracle.wcc.adf.model.form”

      Best Regards,
      Pedro Gabriel

      Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *