It's all about the answers!

Ask a question

How to create a query from Java API to filter build definition based on project area?


Jia Jia Li (8057152192) | asked Apr 02 '15, 11:59 a.m.
edited Apr 08 '15, 3:11 a.m. by Ralph Schoon (63.1k33646)
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?

Comments
Ralph Schoon commented Apr 08 '15, 3:10 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Please at least try to tag the product

One answer



permanent link
sam detweiler (12.5k6195201) | answered Apr 08 '15, 7:38 a.m.
 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


Register or 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.