Friday, 26 May 2017

Java code for Event Subscription (FileNet Content Engine API)

//Java code for Event Subscription (FileNet Content Engine API)

import java.util.Iterator;
import com.filenet.api.engine.EventActionHandler;
import com.filenet.api.events.ObjectChangeEvent;
import com.filenet.api.util.Id;
import com.filenet.api.property.*;
import com.filenet.api.core.*;
import com.filenet.api.constants.*;

public class MyCustomeEventHandler implements EventActionHandler
 {
public void onEvent(ObjectChangeEvent event, Id subId)
  {
try
     {
ObjectStore os = event.getObjectStore();
        Id id = event.get_SourceObjectId();
        System.out.println("Event Action Call Started");
        System.out.println("guid="+id);
        PropertyFilter pf = new PropertyFilter();
        pf.addIncludeType(0, null, Boolean.TRUE, FilteredPropertyType.ANY, null);
        Document doc = Factory.Document.fetchInstance(os,id,pf);
        doc.fetchProperties(pf);
        com.filenet.api.property.Properties props = doc.getProperties();      
        Iterator iter = props.iterator();
        System.out.println("Property" +"\t" + "Value");
 
        while (iter.hasNext() )
        {
            Property prop = (Property)iter.next();
            
            if (prop.getPropertyName().equals("DocumentTitle"))
            {
            String docTitle = prop.getStringValue();
                System.out.println("Doc title" + "\t" + docTitle );
            }

            if (prop.getPropertyName().equals("Creator"))
            {
            String createdBy = prop.getStringValue();
                System.out.println("Creator" + "\t" +createdBy );
            }
            if (prop.getPropertyName().equals("DateCreated"))
            {
            String createdOn = prop.getDateTimeValue().toString();
                System.out.println("Date Created" + "\t" +createdOn );
                
            }
        }
       
        doc.getProperties().putObjectValue("DocumentTitle", "changedtoEvent");
doc.save(RefreshMode.NO_REFRESH);
     
     }
     catch (Exception e)
     {
        throw new RuntimeException(e);
     }
  }

}

No comments:

Post a Comment