How to create a query from Java API to filter build definition based on project area?
Jia Jia Li (805●8●157●192)
| asked Apr 02 '15, 11:59 a.m.
edited Apr 08 '15, 3:11 a.m. by Ralph Schoon (63.6k●3●36●47)
I can fetch all build definition for the repository, but I only want the special project area build definition.
How can query it by JAVA API?
|
One answer
here is a routine I wrote to do that
private static ArrayList<IBuildDefinition> getBuildDefinitionsforProjectArea(
IProjectAreaHandle iprja)
{
Boolean allProperties = true;
// allocate space for results
ArrayList<IBuildDefinition> allbd = new ArrayList<IBuildDefinition>();
ITeamRepository repo = (ITeamRepository) iprja.getOrigin();
// get the data interface
ITeamBuildClient buildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);
try
{
IBuildDefinitionQueryModel queryModel = IBuildDefinitionQueryModel.ROOT;
// create a query for build engines
IItemQuery query = IItemQuery.FACTORY.newInstance(queryModel);
// objects of build engine type
IPredicate isBuildDefType = queryModel._isTypeOf(IBuildDefinition.ITEM_TYPE);
// allocate space for the parameter
IItemHandleInputArg[] itemHandleArgs = new IItemHandleInputArg[] { query.newItemHandleArg() };
// the query filter
IPredicate filter = ((BuildDefinitionQueryModel) queryModel).processArea()._in(itemHandleArgs);
// set the combined filter
query.filter(filter._and(isBuildDefType));
// no parameters required
IItemQueryPage queryPage = buildClient.queryItems(query,
// com.ibm.team.repository.common.service.IQueryService.EMPTY_PARAMETERS,
new Object[] { iprja }, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, null);
// if there are build definitions defined
if (queryPage.getResultSize() != 0)
{
while (queryPage != null)
{
IFetchResult fetchResult = null;
if (allProperties == true)
{
fetchResult = repo.itemManager().fetchCompleteItemsPermissionAware(queryPage.getItemHandles(), IItemManager.DEFAULT, null);
}
else
{
// print out a page of IDs of the retrieved build definitions
// needs to be fixed for build defs
final String[] all_properties = new String[] {
IBuildEngine.PROPERTY_BUILD_ENGINE_ACTIVITY,
IBuildEngine.PROPERTY_DESCRIPTION,
IBuildEngine.PROPERTY_ENGINE_CONTACT_INTERVAL,
IBuildEngine.PROPERTY_ID,
IBuildEngine.PROPERTY_PROCESS_AREA,
IBuildEngine.PROPERTY_SUPPORTED_BUILD_DEFINITIONS,
IBuildEngine.PROPERTY_SUPPORTS_CANCELLATION,
IBuildEngine.PROPERTY_USE_TEAM_SCHEDULER,
IBuildEngine.PROPERTY_PROPERTIES,
IBuildEngine.PROPERTY_CONFIGURATION_ELEMENTS };
fetchResult = repo.itemManager().fetchPartialItemsPermissionAware(queryPage.getItemHandles(), IItemManager.DEFAULT, Arrays.asList(all_properties), null);
}
// add these to the list
allbd.addAll(fetchResult.getRetrievedItems());
if (queryPage.hasNext())
{
queryPage = (IItemQueryPage) buildClient.fetchPage(queryPage.getToken(), queryPage.getNextStartPosition(), queryPage.getSize(), null);
}
else
{
queryPage = null;
}
}
}
}
catch (Exception ex)
{
System.out.println("build exception=" + ex.getMessage());
}
return allbd;
}
|
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.
Comments
Please at least try to tag the product