Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to query in server plug-in?

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?

0 votes



2 answers

Permanent link
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;
}

}

0 votes


Permanent link
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;
}

}

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,944

Question asked: Mar 24 '11, 2:05 a.m.

Question was seen: 6,061 times

Last updated: Mar 24 '11, 2:05 a.m.

Confirmation Cancel Confirm