Thursday, 12 May 2016

Searching or Retriving Documents from Multiple Object stores in FileNet Content Engine

//Searching or Retriving Documents from Multiple Object stores in FileNet Content Engine

import java.util.Iterator;
import javax.security.auth.Subject;

import com.filenet.api.collection.DocumentSet;
import com.filenet.api.constants.MergeMode;
import com.filenet.api.core.Connection;
import com.filenet.api.core.Document;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.property.FilterElement;
import com.filenet.api.property.PropertyFilter;
import com.filenet.api.query.SearchSQL;
import com.filenet.api.query.SearchScope;
import com.filenet.api.util.UserContext;


public class ceUtil {


public static void main(String[] args) {
ceUtil obj = new ceUtil();
obj.FetchCEObjects(obj.getCEConnection());


}

public Connection getCEConnection() {

Connection conn = null;
try {

String ceURI = "http://localhost:9080/wsi/FNCEWS40MTOM/";

String userName = "username";
String password = "password";
conn = Factory.Connection.getConnection(ceURI);
Subject subject = UserContext.createSubject(conn, userName,
password, null);
UserContext uc = UserContext.get();
uc.pushSubject(subject);
} catch (Exception e1) {
e1.printStackTrace();
}
System.out.println("CE Connection" + conn);
return conn;
}

public void FetchCEObjects(Connection conn) {

try {
Domain domain = Factory.Domain.fetchInstance(conn, null, null);

ObjectStore objectStores[] = new ObjectStore[2];
objectStores[0] = Factory.ObjectStore.fetchInstance(domain,"DESIGNOS", null);
objectStores[1] = Factory.ObjectStore.fetchInstance(domain,"TARGETOS", null);
System.out.println("Object Store 1 : "+objectStores[0].get_DisplayName());
System.out.println("Object Store 2 : "+objectStores[1].get_DisplayName());

PropertyFilter pf= new PropertyFilter();
pf.addIncludeProperty(new FilterElement(Integer.getInteger("2"),null, Boolean.valueOf(true),"Name"));
SearchScope search = new SearchScope(objectStores, MergeMode.UNION);
SearchSQL sql= new SearchSQL("Select * from docClass where Creator='p8admin'");
DocumentSet documents = (DocumentSet)search.fetchObjects(sql,Integer.getInteger("50"),pf, Boolean.valueOf(true));

Document doc;
Iterator it = documents.iterator();
while (it.hasNext()){doc = (Document)it.next();
System.out.println("document="+doc.get_Name());
}

} catch (Exception e) {
e.printStackTrace();
}
}
}

No comments:

Post a Comment