Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
Hi All,
I have custom IBA on one of the WTDocument softype, I want to retrieve all the document with this IBA value. Please suggest how to add searchCondition in QuerySpec?
Thanks,
Vishvanatha
Solved! Go to Solution.
I've created a method to do what you need.
searchIBA is a name of IBA attribute
searchVALUE is a search key what you need to search
searchClass is a object class what you want to search example> WTDocument.class or WTPart.class atc.
public static List searchObjectByIBAValue(String searchIBA, String seachVALUE, Class searchClass)
{
List retValue = new ArrayList<>();
QuerySpec queryspec;
try
{
queryspec = new QuerySpec();
queryspec.setAdvancedQueryEnabled(true);
int indexObjectEPM = queryspec.appendClassList(searchClass, true);
int indexObjectSTRV = queryspec.appendClassList(StringValue.class, true);
int indexObjectIBA = queryspec.appendClassList(StringDefinition.class, true);
SearchCondition condition17 = new SearchCondition(
searchClass, WTAttributeNameIfc.ID_NAME,
StringValue.class, "theIBAHolderReference.key.id");
condition17.setOuterJoin(SearchCondition.LEFT_OUTER_JOIN);
queryspec.appendWhere(condition17,
new int[]{indexObjectEPM,
indexObjectSTRV});
queryspec.appendAnd();
condition17 = new SearchCondition(
StringValue.class, "definitionReference.key.id",
StringDefinition.class, WTAttributeNameIfc.ID_NAME);
condition17.setOuterJoin(SearchCondition.LEFT_OUTER_JOIN);
queryspec.appendWhere(condition17,
new int[]{indexObjectSTRV,
indexObjectIBA});
queryspec.appendAnd();
CompositeWhereExpression andCondition = new CompositeWhereExpression(LogicalOperator.AND);
andCondition.append(new SearchCondition(StringDefinition.class,
StringDefinition.NAME,
SearchCondition.LIKE,
searchIBA), new int[]{indexObjectIBA});
queryspec.appendWhere(andCondition, new int[]{indexObjectIBA, indexObjectIBA});
queryspec.appendAnd();
andCondition = new CompositeWhereExpression(LogicalOperator.AND);
andCondition.append(new SearchCondition(StringValue.class,
StringValue.VALUE,
SearchCondition.LIKE,
seachVALUE), new int[]{indexObjectIBA});
queryspec.appendWhere(andCondition, new int[]{indexObjectSTRV, indexObjectSTRV});
queryspec.appendAnd();
andCondition = new CompositeWhereExpression(LogicalOperator.AND);
andCondition.append(new SearchCondition(searchClass,
"iterationInfo.latest",
"TRUE"), new int[]{indexObjectEPM});
queryspec.appendWhere(andCondition, new int[]{indexObjectEPM});
queryspec.appendOrderBy(new OrderBy(new ClassAttribute(searchClass, "master>number"), false), new int[]{0});
queryspec.appendOrderBy(new OrderBy(new ClassAttribute(searchClass, "versionInfo.identifier.versionSortId"), false), new int[]{0});
QueryResult queryRes = PersistenceServerHelper.manager.query(queryspec);
if (queryRes.hasMoreElements())
{
while (queryRes.hasMoreElements())
{
Object[] obj = (Object[]) queryRes.nextElement();
retValue.add(obj[0]);
}
}
System.out.println("SearchObjectByIBAValue fnished.");
} catch (WTException e)
{
e.printStackTrace();
} catch (WTPropertyVetoException e)
{
e.printStackTrace();
}
return retValue;
}
PetrH
I've created a method to do what you need.
searchIBA is a name of IBA attribute
searchVALUE is a search key what you need to search
searchClass is a object class what you want to search example> WTDocument.class or WTPart.class atc.
public static List searchObjectByIBAValue(String searchIBA, String seachVALUE, Class searchClass)
{
List retValue = new ArrayList<>();
QuerySpec queryspec;
try
{
queryspec = new QuerySpec();
queryspec.setAdvancedQueryEnabled(true);
int indexObjectEPM = queryspec.appendClassList(searchClass, true);
int indexObjectSTRV = queryspec.appendClassList(StringValue.class, true);
int indexObjectIBA = queryspec.appendClassList(StringDefinition.class, true);
SearchCondition condition17 = new SearchCondition(
searchClass, WTAttributeNameIfc.ID_NAME,
StringValue.class, "theIBAHolderReference.key.id");
condition17.setOuterJoin(SearchCondition.LEFT_OUTER_JOIN);
queryspec.appendWhere(condition17,
new int[]{indexObjectEPM,
indexObjectSTRV});
queryspec.appendAnd();
condition17 = new SearchCondition(
StringValue.class, "definitionReference.key.id",
StringDefinition.class, WTAttributeNameIfc.ID_NAME);
condition17.setOuterJoin(SearchCondition.LEFT_OUTER_JOIN);
queryspec.appendWhere(condition17,
new int[]{indexObjectSTRV,
indexObjectIBA});
queryspec.appendAnd();
CompositeWhereExpression andCondition = new CompositeWhereExpression(LogicalOperator.AND);
andCondition.append(new SearchCondition(StringDefinition.class,
StringDefinition.NAME,
SearchCondition.LIKE,
searchIBA), new int[]{indexObjectIBA});
queryspec.appendWhere(andCondition, new int[]{indexObjectIBA, indexObjectIBA});
queryspec.appendAnd();
andCondition = new CompositeWhereExpression(LogicalOperator.AND);
andCondition.append(new SearchCondition(StringValue.class,
StringValue.VALUE,
SearchCondition.LIKE,
seachVALUE), new int[]{indexObjectIBA});
queryspec.appendWhere(andCondition, new int[]{indexObjectSTRV, indexObjectSTRV});
queryspec.appendAnd();
andCondition = new CompositeWhereExpression(LogicalOperator.AND);
andCondition.append(new SearchCondition(searchClass,
"iterationInfo.latest",
"TRUE"), new int[]{indexObjectEPM});
queryspec.appendWhere(andCondition, new int[]{indexObjectEPM});
queryspec.appendOrderBy(new OrderBy(new ClassAttribute(searchClass, "master>number"), false), new int[]{0});
queryspec.appendOrderBy(new OrderBy(new ClassAttribute(searchClass, "versionInfo.identifier.versionSortId"), false), new int[]{0});
QueryResult queryRes = PersistenceServerHelper.manager.query(queryspec);
if (queryRes.hasMoreElements())
{
while (queryRes.hasMoreElements())
{
Object[] obj = (Object[]) queryRes.nextElement();
retValue.add(obj[0]);
}
}
System.out.println("SearchObjectByIBAValue fnished.");
} catch (WTException e)
{
e.printStackTrace();
} catch (WTPropertyVetoException e)
{
e.printStackTrace();
}
return retValue;
}
PetrH