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.

10 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
    • mm
      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
    • mm
      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
    • mm
      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
  4. Mukesh
    Mukesh says:

    Hi Pedro,

    Thanks a lot for this article. I was able to make slight changes using the MDS customization as you explained.
    Now I need to change the default Home Page into Browse instead of Search results.
    I have tried to change codes under globalLinks.jsf like below.

    When we click on search it shows the Browse, however default home page is with search results only.
    Is there any way to make search results page empty unless the user performs a search using the search field in the top..

    Regards,
    -Mukesh

    Reply
    • mm
      Pedro Gabriel says:

      Hi Mukesh,

      You are able to control everything that is available on the page fragments, for example: hiding controls, add new ones, etc.
      Within your custom java code you are able to intercept data collections, internal operations and page variables that are used/invoked in the fragments.
      The use case that you are detailing seems doable as you find the right page where the list is rendered. Try to set the list/table as rendered=”false” instead of visible=”false” in order to avoid the default initial query. Check twice if this works because you might hide the results but waste time retrieving the data.

      Best Regards,
      Pedro Gabriel

      Reply
      • Mukesh
        Mukesh says:

        Thanks Pedro for the response.
        I was able to make the default Home page by modifying method getHomePage in the PersonalizationBean class.
        I don’t know how do we achieve by custom class since there is no guide lines from Oracle to extend the existing class for customization.

        I don’t have much experience in ADF. I tried changing the rendered property of Results section. But it disable even when I perform a search from the search above.
        I couldn’t get any idea how to make this rendered only when user click on Search icon in the search box.

        Regards,
        -Mukesh

        Reply
        • mm
          Pedro Gabriel says:

          Hi Mukesh,

          Yes you do not find documentation for that.

          When you click on the “Search” button you need to change the “rendered” attribute. For that you need to map the rendered attribute to a managed on your side.

          Basically you can map the attribute with rendered=”#{pageFlowScope.MyCustomManagedBean.isTableRendered}”. Map as well the “action” and/or “actionListener” attributes to your custom managed bean “MyCustomManagedBean” and execute the same methods as defined there, for example:

          Imagine that the “Search” button has the following attributes configured:
          action=”#{pageFlowScope.wccDocuments.action}”
          actionListener=”#{pageFlowScope.wccDocuments.actionListener}”

          and the “wccDocuments” is the managed bean used internally.

          Change it to:
          action=”#{pageFlowScope.MyCustomManagedBean.myAction}”
          actionListener=”#{pageFlowScope.MyCustomManagedBean.myActionListener}”

          and the “MyCustomManagedBean” is your managed bean.

          Inside of “myAction” and “myActionListener” methods call the “wccDocuments.action” and “wccDocuments.actionListener” with your new logic.

          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 *