In my current project using Filenet P8 Content Platform Engine 5.2.1 with WebSphere 8.5.5.3, Eclipse Mars 4.5.2 and Apache Maven 3.3.1
I'm trying to insert programmatically some where condition properties values in a Stored Search (starting from this example provided by IBM), but I can't figure out the strategy to add them. Following is the method I use:
public void searchObjectsByStoredSearch(String storedSearchId, ObjectStore objectStore) {
// Create a SearchScope instance. (Assumes you have the object store
// object.)
SearchScope search = new SearchScope(objectStore);
// Get the StoredSearch object.
StoredSearch ss = Factory.StoredSearch.fetchInstance(objectStore, new Id(storedSearchId), null);
// Set the search parameters. Search template parameters only need to be
// provided if the persisted stored search needs to be modified at
// runtime.
SearchTemplateParameters searchParams = new SearchTemplateParameters();
searchParams.setContent(null);
searchParams.setMaximumRecords(50);
SearchTemplateWhereProperty whereProp = new SearchTemplateWhereProperty();
whereProp.setLiteral("application/pdf");
whereProp.setItemId("35");
ArrayList alWhereProps = new ArrayList();
alWhereProps.add(whereProp);
searchParams.setWhereProperties(alWhereProps);
SearchTemplateSelectProperty selectProp = new SearchTemplateSelectProperty();
selectProp.setSymbolicName("DocumentTitle");
selectProp.setItemId("1");
selectProp.setSortLevel(0);
selectProp.setSortOrder(SortOrder.DESCENDING);
ArrayList alSelectProps = new ArrayList();
alSelectProps.add(selectProp);
searchParams.setSelectProperties(alSelectProps);
// Set the page size (Long) to use for a page of query result data. This
// value is passed
// in the pageSize parameter. If null, this defaults to the value of
// ServerCacheConfiguration.QueryPageDefaultSize.
Integer myPageSize = new Integer(100);
// Specify a property filter to use for the filter parameter, if needed.
// This can be null if you are not filtering properties.
PropertyFilter myFilter = new PropertyFilter();
myFilter.setMaxRecursion(1);
myFilter.addIncludeType(new FilterElement(null, null, null, FilteredPropertyType.SINGLETON_STRING, null));
// Set the (Boolean) value for the continuable parameter. This indicates
// whether to iterate requests for subsequent pages of result data when
// the end of the
// first page of results is reached. If null or false, only a single
// page of results is
// returned.
Boolean continuable = Boolean.TRUE;
// Execute the fetchObjects method using the specified parameters.
IndependentObjectSet myObjects = search.fetchObjects(ss, "document", searchParams, myPageSize, myFilter,
continuable);
// You can then iterate through the collection of objects to access the
// properties.
Iterator iterObjects = myObjects.iterator();
int cont = 0;
while (iterObjects.hasNext()) {
cont++;
logger.info("Documento " + cont);
logger.info("-------------------");
IndependentObject object = (IndependentObject) iterObjects.next();
Properties props = object.getProperties();
Iterator iterProps = props.iterator();
while (iterProps.hasNext()) {
Property prop = (Property) iterProps.next();
logger.info("Proprieta': " + prop.getPropertyName());
if (prop.getObjectValue() != null)
logger.info(" Valore: " + prop.getObjectValue().toString());
if (prop.getPropertyName().equalsIgnoreCase("FoldersFiledIn")) {
if (prop.getObjectValue() != null) {
FolderSet fs = (FolderSet) prop.getIndependentObjectSetValue();
Iterator iterFs = fs.iterator();
while (iterFs.hasNext()) {
Folder folder = (Folder) iterFs.next();
logger.info("\r\tFolder Name: " + folder.get_FolderName() + " Folder Path: "
+ folder.get_PathName());
}
}
}
}
}
logger.info(" Documenti trovati:" + cont);
}
I would like you to concentrate on the SearchTemplateWhere property fragment:
SearchTemplateWhereProperty whereProp = new SearchTemplateWhereProperty();
whereProp.setLiteral("application/pdf");
whereProp.setItemId("35");
ArrayList alWhereProps = new ArrayList();
alWhereProps.add(whereProp);
searchParams.setWhereProperties(alWhereProps);
It seems that for stored search you cannot define your custom SQL statement but you can only refer to existing properties providing a proper value for them.
As far as can I understand each property in a stored search has its own Id and the only methods I can use are to set the value (setLiteral) and to set the Id of the property.
I tried with some Id values but I got this error:
com.filenet.api.exception.EngineRuntimeException: FNRCA0109E: RETRIEVE_SEARCH_REQUIRED_MERGE_DATA_NOT_PRESENT: The templateData parameter for the SearchScope method to execute the stored search is invalid. The SearchTemplateParameters instance did not contain the required value itemId in the SearchTemplateWhereProperty object.
My question is: how can I (programmatically) find the properties Id of the stored search in order to give them a value?
EDIT: on another Q&A site I got the suggestion of take a look to stored search's Content Element property, which contains its XML definition comprised of various items among which you can find these ItemIDs. How can programmatically get these ItemId properties out of this Content Element?