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

How can I get a list of the root build folders of a project area from API?

Team,
trying to retrieve a list of the root build folders from a given project area in order to script build definition creation and moving the build definition into the correct folder via script as well.

What I found so far only returns only a single folder, however (the first one I created, regardless on what level it is now). I also only found an IBuildFolderEntryQueryModel rather than an IBuildFolderQueryModel so trying this code:

        IBuildFolderEntryQueryModel bfQueryModel = IBuildFolderEntryQueryModel.ROOT;        
        try {
            IItemQuery itemQuery = IItemQuery.FACTORY.newInstance(bfQueryModel);
            IItemQueryPage itemPage = ClientFactory.getTeamBuildClient(repo).queryItems(itemQuery, IQueryService.EMPTY_PARAMETERS, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, null);
            buildFolderEntryHandles = itemPage.getItemHandles();
            for (IBuildFolderEntryHandle bfeHandle : buildFolderEntryHandles) {
                IBuildFolderEntry buildFolderEntry = (IBuildFolderEntry) repo.itemManager().fetchCompleteItem(bfeHandle, IItemManager.DEFAULT, null);
                IBuildFolderHandle buildFolderHandle = buildFolderEntry.getFolder();
                IBuildFolder buildFolder = (IBuildFolder) repo.itemManager().fetchCompleteItem(buildFolderHandle, IItemManager.DEFAULT, null);
                System.out.println("Found folder: "+buildFolder.getName());
            }
        } catch (TeamRepositoryException e) {
        e.printStackTrace();
        }

Any better ideas on how to achieve this? Actually if there is a method such as BuildWhateverClient.getBuildFolderByPath() I would gladly settle for that but I am willing to implement it if I could just get a complete list of root folders.

0 votes


Accepted answer

Permanent link
 Hi Arne,

You can use TeamBuildClient.getChildrenOfFolder call to get the folders. 

public IBuildItemNamePair[] getChildrenOfFolder(final IBuildFolderHandle buildViewFolderHandle, final IProcessAreaHandle[] processAreaHandles, final IProgressMonitor progressMonitor)

The first parameter to the call is the handle to the parent folder, it this is null then the top level folders are returned.

If you want to use the query model directly, some think like the below code snippet should work

IBuildFolderHandle buildFolderHandle;// either null for top level folders or handle of the parent folder 
IProcessAreaHandle[] processAreaHandles; // process area handles to retrieve the folders for.


BuildFolderQueryModel buildFolderQueryModel = BuildFolderQueryModel.ROOT;

//create instance of the query
IItemQuery folderQuery = IItemQuery.FACTORY.newInstance(buildFolderQueryModel);

// First predicate: the process area of the folder must be in processAreaHandles
List queryParameters = new ArrayList<IItemHandle>(processAreaHandles.length);
IPredicate processAreas = QueryPredicateHelper.getProcessAreaInPredicate(folderQuery, buildFolderQueryModel.processArea(), processAreaHandles, queryParameters);
                    
// Second predicate: the parent of the folder must be buildFolderHandle (or null if top level folders)
IPredicate parent;
if (buildFolderHandle == null) {
    //top level folders
    parent = buildFolderQueryModel.parent()._isNull();
} else {
    //child folders
    parent = buildFolderQueryModel.parent()._eq(folderQuery.newItemHandleArg());
    queryParameters.add(buildFolderHandle);
}

//apply the filter on the process areas
folderQuery.filter(parent._and(processAreas));

//get the folder items
IItem[] folderItems = queryHelper.queryItems(folderQuery, queryParameters.toArray());

Thanks,
Kishore

Arne Bister selected this answer as the correct answer

0 votes

Comments

Great, thanks!

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,939
× 562
× 14

Question asked: May 11 '15, 10:15 a.m.

Question was seen: 3,319 times

Last updated: May 12 '15, 5:02 a.m.

Confirmation Cancel Confirm