Tuesday, 10 February 2015

Search CE Object using SearchSQL (Content Engine API)

Search CE Object

  Note* : first fetch the Object Store 
 

 public ArrayList getCEObjects(String filterParams, String[] resultParams, String ObjectClassName, boolean includeSubClass)
  {
    log.debug("ENTRY ");
    String searchClassScope = includeSubClass ? "INCLUDESUBCLASSES" : "EXCLUDESUBCLASSES";
    String searchQuery = "";

    for (int i = 0; i < resultParams.length; i++) {
      if (i == 0)
        searchQuery = resultParams[i];
      else {
        searchQuery = searchQuery + "," + resultParams[i];
      }
    }
    String searchQ = "SELECT " + searchQuery + " FROM " + ObjectClassName + " WITH " +
      searchClassScope + " WHERE " + filterParams;

    log.debug("CE Search Query " + searchQ);
    SearchSQL sqlObject = new SearchSQL(searchQ);
    SearchScope searchScope = new SearchScope(this.objectStore);

    IndependentObjectSet objectSet = searchScope.fetchObjects(sqlObject, null, null, new Boolean(true));
    Iterator iter = objectSet.iterator();

    ArrayList coList = new ArrayList();
    while (iter.hasNext())
    {
      Hashtable htResult = new Hashtable();
      CustomObject customObject = (CustomObject)iter.next();
      coList.add(customObject);
    }
    if ((coList.size() != 0) && (coList != null))
    {
      log.info(coList.size() + " Custom Objects fetched ");
    }
    log.debug("EXIT");
    return coList;
  }




1 comment:

  1. I have that message error:
    java.lang.ClassCastException: com.filenet.apiimpl.core.DocumentImpl cannot be cast to com.filenet.api.core.CustomObject
    in this line:
    CustomObject customObject = (CustomObject)iter.next();
    Please Ineed your help.

    ReplyDelete