Pages

Sunday, September 27, 2015

How to create custom filter in UCM ?

How to create custom filter in UCM ?




Purpose : This will explain how to use filter in Checkin . In this example, to stop the checkin UCM based on the size of the content . If the size is more than 2 MB, then UCM will stop the check in

Basic

1. Find out the method during check in process
2. Create custom component , which use the filter the process
3. Create java method for comparing the size
4. Throw the exception to stop checkin

Detailed steps

1. Add services,requestaudit in trace section during checkin

serarch after
requestaudit/6 09.27 14:21:36.624 IdcServer-887 CHECKIN_NEW_FORM “



















search for “Called Filter Event “ . And here we use validateStandard

2.Create new custom component (BeforeCheckin)

3. Go to java code section of component .

4. We can't add using GUI , you need to edit the hda file ( BeforeCheckin.hda)

Add below resultset after @end

@ResultSet Filters
4
type
location
parameter
loadOrder
validateStandard
BeforeCheckin.BeforCheckinFilter
null
1
@end


5.Save and reopen it .
6.In component wizard , go to java code and it should show like







































7. Now create a class file in <ComponentFolder>/classes/<PackageName>/BeforeChecinFilter
(check the bottom of page for java file )



8.Add build settings in component wizard
Component class from Build settings



9.In adavacned class settings add the custom class location



10 add MaxAllowSizeinMB=5 in config.cfg ( this is new variable to specify the MaxSize)



11. Build and Enable and Restart WCC


12. Verify be checkin new content and verify the server output

>BeforCheckin/6 09.27 15:18:50.247      IdcServer-11    Custom Filter starts  
>BeforCheckin/6 09.27 15:18:50.247      IdcServer-11    Size in MB is  0
>(internal)/6   09.27 15:18:50.254      IdcServer-11    Did not find sufficient params to be processed as App adapter
>(internal)/6   09.27 15:18:50.387      IdcServer-11    File to be removed: /home/oracle/fmw/ps7/user_projects/domains/dell/ucm/cs/vault/~temp/259275539.doc


















Java class : ( it should be compiled and place it on classes location )




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


public class BeforCheckinFilter    extends ServiceHandler  implements FilterImplementor
{

static int filesizeinMB; // to assign the file size in MB


     public int  doFilter(Workspace ws, DataBinder m_binder ,  ExecutionContext cxt)
              throws DataException, ServiceException
              {

                       traceVerbose("Custom Filter starts  ");
                                                       
                       String tempFilepath=m_binder.getLocal("primaryFile:path");

                       int sizeallowed = Integer.valueOf(SharedObjects.getEnvironmentValue("MaxAllowSizeinMB"));
                        // to get  value from config.cfg
                                                   filesizeinMB=-1;

                                          if ( filesizeCheck(tempFilepath,sizeallowed))
                                           
                                            {
                                             throw new ServiceException("Max Allowed size is "+ sizeallowed+ " MB" + "Checking file size is " + filesizeinMB);

                                           }
                      

                return 1;
              }



private static boolean filesizeCheck ( String tempFilepath  , int sizeallowed )

{

  boolean Bfilesize =false;

                                            try  {
                              

                                    FileInputStream      FI =  new FileInputStream(tempFilepath);   // To open inputstream of the content

                                     int        filesize = FI.available();
                                      filesizeinMB =  filesize/(1024*1024);

                                          traceVerbose("Size in MB is  " + filesizeinMB);

                                              if ( filesizeinMB > sizeallowed)

                                                                  Bfilesize=true;

                                                             
                                               
                                  

                               }
                                                       catch (IOException e)
                            {
                               e.printStackTrace(System.out);
                             }



return Bfilesize;




} // end of filesizeCheck





private static void trace(final String message)

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


 private static void traceVerbose(final String message)

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



}

2 comments:

  1. getting this error : The content item was not successfully checked in. Unable to do filter 'BeforeCheckin.BeforCheckinFilter' for type 'validateStandard'. Unable to instantiate java class code for 'BeforeCheckin.BeforCheckinFilter' at location 'BeforeCheckin.BeforCheckinFilter'.
    Could you please help me out ?

    ReplyDelete
    Replies
    1. 1. Check BeforeCheckin.BeforCheckinFilter class in the correct location
      2. Check the jdk version of wcc server and jdk used for compiling the custom class . it should be same or lesser version

      Delete