It's all about the answers!

Ask a question

How to query in server plug-in?


Jaegon Yoo (9611314) | asked Mar 24 '11, 2:05 a.m.
Dear

I'm trying to develope a server plug-in that runs a query to find an workitem that matches a condition and links it with current workitem when saved.

I'm trying to find a API for this.

Can you provide a API for this purpose?

2 answers



permanent link
Eduardo Bello (4401821) | answered Mar 24 '11, 11:02 a.m.
I can find useful information here: https://jazz.net/wiki/bin/view/Main/QueryDevGuide

Here is an example that I made to find a workitem with summary starting with given string



public List<IWorkItem> findWorkItemBySummary(String name, IProjectAreaHandle projectHandler) {
try {

IWorkItemServer workItemServer = getService(IWorkItemServer.class);
IQueryCommon queryService= getService(IQueryCommon.class);

IQueryableAttributeFactory factory = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE);

IQueryableAttribute projectAreaAttribute = factory.findAttribute(projectHandler, IWorkItem.PROJECT_AREA_PROPERTY, workItemServer.getAuditableServer(), null);
IQueryableAttribute workItemNameAttribute = factory.findAttribute(projectHandler, IWorkItem.SUMMARY_PROPERTY, workItemServer.getAuditableServer(), null);
AttributeExpression projectExpression = new AttributeExpression(projectAreaAttribute, AttributeOperation.EQUALS, projectHandler);
AttributeExpression summaryExpression = new AttributeExpression(workItemNameAttribute, AttributeOperation.STARTS_WITH, XMLString.createFromPlainText(name));

Term term= new Term(Operator.AND);
term.add(projectExpression);
term.add(summaryExpression);

SortCriteria[] sortCriteria= new SortCriteria[] { new SortCriteria(IWorkItem.SUMMARY_PROPERTY, true) };
Statement statement = new Statement(new SelectClause(), (Expression) term, sortCriteria);

IQueryResult<IResolvedResult<IWorkItem>> qryResult = queryService.getResolvedExpressionResults( projectHandler, (Expression) statement, IWorkItem.FULL_PROFILE);
List<IWorkItem> matchingWorkItems = new ArrayList<IWorkItem>(qryResult.getResultSize(null).getTotalAvailable());
while (qryResult.hasNext(null)) {
matchingWorkItems.add(qryResult.next(null).getItem());
}
return matchingWorkItems;
} catch (IllegalArgumentException e) {
return null;
} catch (TeamRepositoryException e) {
return null;
}

}


permanent link
Jaegon Yoo (9611314) | answered Mar 25 '11, 2:29 a.m.
Thanks for your help.

I'll try to implement it.

I can find useful information here: https://jazz.net/wiki/bin/view/Main/QueryDevGuide

Here is an example that I made to find a workitem with summary starting with given string



public List<IWorkItem> findWorkItemBySummary(String name, IProjectAreaHandle projectHandler) {
try {

IWorkItemServer workItemServer = getService(IWorkItemServer.class);
IQueryCommon queryService= getService(IQueryCommon.class);

IQueryableAttributeFactory factory = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE);

IQueryableAttribute projectAreaAttribute = factory.findAttribute(projectHandler, IWorkItem.PROJECT_AREA_PROPERTY, workItemServer.getAuditableServer(), null);
IQueryableAttribute workItemNameAttribute = factory.findAttribute(projectHandler, IWorkItem.SUMMARY_PROPERTY, workItemServer.getAuditableServer(), null);
AttributeExpression projectExpression = new AttributeExpression(projectAreaAttribute, AttributeOperation.EQUALS, projectHandler);
AttributeExpression summaryExpression = new AttributeExpression(workItemNameAttribute, AttributeOperation.STARTS_WITH, XMLString.createFromPlainText(name));

Term term= new Term(Operator.AND);
term.add(projectExpression);
term.add(summaryExpression);

SortCriteria[] sortCriteria= new SortCriteria[] { new SortCriteria(IWorkItem.SUMMARY_PROPERTY, true) };
Statement statement = new Statement(new SelectClause(), (Expression) term, sortCriteria);

IQueryResult<IResolvedResult<IWorkItem>> qryResult = queryService.getResolvedExpressionResults( projectHandler, (Expression) statement, IWorkItem.FULL_PROFILE);
List<IWorkItem> matchingWorkItems = new ArrayList<IWorkItem>(qryResult.getResultSize(null).getTotalAvailable());
while (qryResult.hasNext(null)) {
matchingWorkItems.add(qryResult.next(null).getItem());
}
return matchingWorkItems;
} catch (IllegalArgumentException e) {
return null;
} catch (TeamRepositoryException e) {
return null;
}

}

Your answer


Register or to post your answer.