Pages

Thursday, October 1, 2015

How to create a custom component to update metadata in bulk?







Purpose : This component is used for mass update . List all the contents based on query then it will update it.

This is training material . all  versions of java class and final versions of  all the templates are available at the bottom of page 


for detailed steps to add service , template etc in component


Basic Steps

1.Create form templates to provide the query for contents
2.Create java class which runs the GET_SEARCH_RESULT
3.Create template to display contents 
4.Create java method ,to run the UPDATE_DOCINFO in a loop 

Detailed Steps


1. Add component using component wizard

































2.Add service: MASS_UPDATE_FORM

3. Type Template as : mass_update_form
4.Add Template : mass_update_form
5.Copy paste the contents from bottom of the page : mass_update_form.htm
6.Create new service to handle List the contents : LIST_CONTENTS
7.Type Template : list_contents_submit
8. Add : toListContentsMain as Java Method in Service Creation Tab
9. Add new Resoure , (use option 1) , select Static html

a.Name : custom_finish_layout_init
b.In Text box :


navBuilder.addChildNodeTo(“ADMINISTRATION”, “item”, 'id==MASS_UPDATE_FORM”, “label==MASSUPDATE”, “url==<$HttpCgiPath$>?IdcService=MASS_UPDATE_FORM&idcToken=<$idcToken$>");


10.In File system , Create a folder structure like this :
in Custome component dir : classes/simpleJava
Example : <UCM domain>/ucm/cs/custom/simpleJava/classes/simpleJava
11.Copy the attached java class to there( ToListContent.class)
12.Add new resource :3r (Html Table)



13.Select service handler and save it











































14. Edit it :
from <td>ServiceHandler</td><td>MyServiceHandler </td><td>MysearchOrder</td>
<td>Service</td><td>simpleJava.ToListContent</td><td>MysearchOrder</td>
15.Add Component class from Build --> Build settings






































16.Advanced Settings of build












































17,Build and install The new component



Make sure that : java class is compiled using 1.6 JDK for 1.6 JDK WCC instance

To test the issue , call the idcservice , MASS_UPDATE_FORM ,Provide the details like
dDocAuthor <matches> weblogic

To verify everything :

Add simpleJava as Trace section in system audit info page and provide any value . After that below entry should in system trace :
simpleJava” is mention in the class file


>simpleJava/6   06.21 13:58:15.489      IdcServer-139   Data 2 is dDocAuthor <matches> `weblogic`


So this shows java class is referred by idcservice .



Part 2 :

19.Create a template name: list_contents_submit

Like step 4 :

Test the component again.

Part 3:


20. Create new idcservice : BULKUPDATE_CONTENTS
21. In the service Use the Template : conformation_massupdate
22: Use the java method : toUpdateContentsMain
23 . Update : ToListContent .java with new method toUpdateContentsMain()
24. Verify UpdateQuery on system audit info page:
it will fail there .
We need to add java script to calculate the dID and Need to update the htm file

Part 4 :
25. Modify list_contents_submit.htm with latest version 3
26.Restart the WCC

27.Now list_contents_submit.htm will send list of dID to BULKUPDATE_CONTENTS
28. update conformation_massupdate with latest version 3


Screen shots of the flow


call : IdcService=MASS_UPDATE_FORM 
provides : dDocAuthor <matches> `weblogic`






It will list all the contents . Provide update query
like : xComments=NEW coments from custom component






All the contents will be updated


P.S : To compile the java file , you need to add idcserver.jar in the class path


Version 1 of ToListContent.java


package simpleJava;

import java.util.*;
import java.io.*;
import intradoc.common.*;
import intradoc.data.*;
import intradoc.server.*;
import intradoc.shared.*;

/**
 * This is the code that can be executed by any Idc service that has a 
 * service type of "NewCheckinFolderService".
 */
 



public class ToListContent extends DocServiceHandler
{
   
    /**
     * This code will create a html page based on the data in the databinder,
     * and email it to the list of addresses specified by the user.
     */
    public void toListContentsMain() throws DataException, ServiceException
    {
                 String Fquery;



                        
                  Fquery = m_binder.getLocal("Fquery");

                     traceVerbose( "Data 2 is " + Fquery) ;






                  
        
   
    }
   
   


private void executeService(final DataBinder serviceBinder, final String serviceName) throws ServiceException 

                  {


                       traceVerbose("Start executeService");


                           try {
                                trace("Calling service " + serviceName + ": " + serviceBinder.getLocalData().toString());
                                // Execute service
                                m_service.getRequestImplementor().executeServiceTopLevelSimple(serviceBinder, serviceName, m_service.getUserData());
                               trace("Finished calling service");

                               } catch (final DataException e) {
                                     trace("Something went wrong executing service " + serviceName);
                                       e.printStackTrace(System.out);
                                   throw new ServiceException("Something went wrong executing service " + serviceName, e);
                               } finally {
                                         traceVerbose("End executeService");
                               }
                } 






private static void trace(final String message)

              {
                           Report.trace("simpleJava", message, null);
              }        


 private static void traceVerbose(final String message) 

                  {
                
                if (Report.m_verbose) 
                         {
                        trace(message);
                         }
                   }


}




Version 2 of  ToListContent.java

package simpleJava;

import java.util.*;
import java.io.*;
import intradoc.common.*;
import intradoc.data.*;
import intradoc.server.*;
import intradoc.shared.*;

/**
 * This is the code that can be executed by any Idc service that has a 
 * service type of "NewCheckinFolderService".
 */


public class ToListContent extends DocServiceHandler
{
   
    /**
     * This code will create a html page based on the data in the databinder,
     * and email it to the list of addresses specified by the user.
     */ 


    public void toListContentsMain() throws DataException, ServiceException
    {
                 String Fquery;



                        
                  Fquery = m_binder.getLocal("Fquery");

                     traceVerbose( "Data 2 is " + Fquery) ;

                                               
 

                                      m_binder.putLocal("QueryText",Fquery );

                                  
                                              
                              this.executeService(m_binder,"GET_SEARCH_RESULTS");
                                 

                               intradoc.data.ResultSet conteninfo = m_binder.getResultSet("SearchResults");
                             //      traceResultSet(conteninfo, "SearchResults");


                  
       
   
    }
   
    public void toUpdateContentsMain() throws DataException, ServiceException { 

     String Uquery,ListdID,ListdDocName;
      
             Uquery = m_binder.getLocal("Uquery");
             ListdID = m_binder.getLocal("ListdID");
              ListdDocName = m_binder.getLocal("ListdDocName");
                traceVerbose( "Uquery is  " + Uquery) ;
                 traceVerbose( "ListdID is  " + ListdID) ;
                  traceVerbose( "ListdDocName is  " + ListdDocName) ;
               
}


private void executeService(final DataBinder serviceBinder, final String serviceName) throws ServiceException 

                  {


                       traceVerbose("Start executeService");


                           try {
                                trace("Calling service " + serviceName + ": " + serviceBinder.getLocalData().toString());
                                // Execute service
                                m_service.getRequestImplementor().executeServiceTopLevelSimple(serviceBinder, serviceName, m_service.getUserData());
                               trace("Finished calling service");

                               } catch (final DataException e) {
                                     trace("Something went wrong executing service " + serviceName);
                                       e.printStackTrace(System.out);
                                   throw new ServiceException("Something went wrong executing service " + serviceName, e);
                               } finally {
                                         traceVerbose("End executeService");
                               }
                } 






private static void trace(final String message)

              {
                           Report.trace("simpleJava", message, null);
              }        


 private static void traceVerbose(final String message) 

                  {
                
                if (Report.m_verbose) 
                         {
                        trace(message);
                         }
                   }


private void traceResultSet (final intradoc.data.ResultSet rs, final String name) {

                                                          int rowCount = 0;
                                                           int columsize = rs.getNumFields(); 


                                       for(rs.first(); rs.isRowPresent(); rs.next())

                                          {

                                                for (int j=0;j< columsize ; j++)

                                                  {
                                                     String   key = rs.getFieldName(j);
                                                     String   value = rs.getStringValueByName(key);
                                                     traceVerbose( key + "  " + value);

                                                  }
                                          
                                          rowCount++; 
                                           traceVerbose("Going to Next Row ---");           
                                   
                                          }
           }

}



Version 3  of  ToListContent.java 
update the  toUpdateContentsMain()


    public void toUpdateContentsMain()
        throws DataException, ServiceException
    {
        String s = m_binder.getLocal("Uquery");
        String s1 = m_binder.getLocal("ListdID");
        String s2 = m_binder.getLocal("ListdDocName");
        traceVerbose((new StringBuilder()).append("Data 2 is ").append(s).toString());
        traceVerbose((new StringBuilder()).append("ListdID ").append(s1).toString());
        traceVerbose((new StringBuilder()).append("ListdDocName ").append(s2).toString());
        String as[] = s1.split("\\s+");
        String as1[] = s.split("=");
        String as2[] = s2.split("\\s+");
        int i = -1;
        String s3 = "";
        String as3[] = as;
        int j = as3.length;
        for(int k = 0; k < j; k++)
        {
            String s4 = as3[k];
            i++;
            m_binder.putLocal("dID", s4);
            m_binder.putLocal(as1[0], as1[1]);
            m_binder.putLocal("IdcService", "UPDATE_DOCINFO");
            m_binder.putLocal("dDocName", as2[i]);
            executeService(m_binder, "UPDATE_DOCINFO");
            s3 = (new StringBuilder()).append(" \n\n").append(s3).append(" ContentID ").append(as2[i]).append(" is updated with new ").append(as1[0]).append(" value is ").append(as1[1]).append(" \n").toString();
        }

        m_binder.putLocal("messageFromCode", s3);
        traceVerbose((new StringBuilder()).append("messageFromCode ").append(s3).toString());
    }
 




Final version of list_contents_submit.htm



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
List the Contents</title>
<$include std_html_head_declarations$>
<script type="text/javascript">
var ListdID="";
var ListdDocName="";
</script>
</head>
<$include body_def$> 

<$include std_page_begin$> 

<$include std_header$> 
<body>
<input type=hidden name=idcToken value="<$ idcToken $>"> 

<td class="xuiPageHeadingText" align=center width="30%" style="font-weight:bold;"><strong>List of contents </strong></td> 
<table class="xuiPageHeadingCell" width="100%" cellpadding="0" cellspacing="0" summary="" border="2"> 
<tr> 
<td class="xuiPageHeadingText" align=center width="30%" style="font-weight:bold;"><strong>ContentID</strong></td>
<td class="xuiPageHeadingText" align=center width="30%" style="font-weight:bold;"><strong>dID</strong></td>
<td class="xuiPageHeadingText" align=center width=auto  style="font-weight:bold;"><strong>User</strong></td> 
<td class="xuiPageHeadingText" align=center width=auto  style="font-weight:bold;"><strong>Release Date</strong></td> 
</tr> 


<$loop SearchResults$> 
<script type="text/javascript">
  ListdID = ListdID + <$dID$> + ' ' ;
  ListdDocName = ListdDocName + "<$dDocName$>"  + ' ';
</script>

<tr> 
<td class="xuiPageHeadingText" align=center width="30%"><strong><$dDocName$><strong></td> 
<td class="xuiPageHeadingText" align=center width="30%"><strong><$dID$><strong></td>
<td class="xuiPageHeadingText" align=center width=auto><strong><$dUser$></strong></td> 
<td class="xuiPageHeadingText" align=center width=auto><strong><$dDocCreatedDate$></strong></td> 
</tr> 


<$endloop$> 

</table> 

<script type="text/javascript">
 document.write(ListdID);
 document.write(ListdDocName);
</script>

<br style="line-height:10px"> 
<tr> 
</tr>
<tr> 
</tr>
<tr> 
</tr>

<table border=0 cellpadding=2 cellspacing=0 width=400>
<caption align=top><h4 class=pageTitle>Provide new metadata for bulk update </h4></caption>
<form name="updateform"  action="<$HttpCgiPath$>" method="POST">

<input type=hidden name=IdcService value="BULKUPDATE_CONTENTS">
<input type=hidden name=ListdID >
<input type=hidden name=ListdDocName >
<tr>
 <td><span class=tableEntry>Update Query:</span></td>
 <td><input type=text size=50 name="Uquery"></td>
</tr>
<tr>
 <td colspan=2>&nbsp;</td>
</tr>
 <tr>
 <td align=center colspan=2>
 <input type=submit name=submit value="Submit"   onclick="intialize()" />
 <input type=reset name=reset value=" Reset "/>
 </td>
<script type="text/javascript">
function intialize(){  

 document.updateform.ListdID.value = ListdID;
 document.updateform.ListdDocName.value = ListdDocName;
 }  
</script>


</tr>
</tr>
</form>
</table>


<$include std_page_end$> 

</body>
</html>


No comments:

Post a Comment