Nesting Constraints in a query
I an attempting to construct a query against the estimate archetype. My question relates to nested constraints.
My initial constraint is simple.
String[] statusConstraints = {EstimateActStatus.IN_PROGRESS, EstimateActStatus.COMPLETED, EstimateActStatus.POSTED};
setStatuses(statusConstraints);
setDefaultSortConstraint(DEFAULT_SORT);
setConstraints(or(isNull("endTime"), gt("endTime", new Date())));
This issues a normal set of values which can subsequently be filtered by status of complete, in progress or posted. Mind you the status search field displays all the values but due to the status constraint the query will never display cancelled estimates.
I wish to filter the resultset by either estimate id or customer name. So I added a searchfield to the workspace layout and utilized the returned value as:
String searchText = getWildcardedText(this.getSearchField());
if(searchText != null){
AndConstraint idConstraint = and(eq("id",searchText),getConstraints());
AndConstraint nameConstraint = and(eq("customer",searchText),getConstraints());
setConstraints(or(idConstraint,nameConstraint));
}
Unfortunately this produces the an empty result set and the error: Failed to execute query: {0}.
I assume this is because nesting constraints do not behave as sql nesting might do.
ie I expect that it would parse as
((id="*seachText*") and ((date notNull) or (date() !> endDate))) or ((name=*searchText*) and (date notNull) or (date() !> endDate)))
My createResultSet override only fails when something is written in the searchField so I can only assume its the contraint changes that are causing the error.
Any tips?
Re: Nesting Constraints in a query
You can't do like searches on id fields - you need to strip off the wildcards and convert the string to a numeric.
See AbstractIMObjectResultSet.getId() for an example of this. The CustomerResultSet does something similar.
Re: Nesting Constraints in a query
I understand Id searches, but the query still fails with the textfield search based on serching the "notes" node of the estimation archetype.
ie
searchText = "Tes*"; //set dynamically
setConstraints(eq("notes",searchText);
I am assuming it has something to do with that node being on the path /detail/notes.
For now I will just search the title node.
Re: Nesting Constraints in a query
Correct - you can't perform searches of details nodes. This was originally due to a limitation in HQL. This may not be present any longer, but it requires a different syntax which is not supported in the ArchetypeQuery -> HQL generation.