It's all about the answers!

Ask a question

How to get the user which team area belong to?


chen fengmiao (7032932) | asked Dec 18 '13, 7:17 a.m.
edited Apr 15 '14, 2:53 a.m. by Ralph Schoon (63.4k33646)
I want to get the user's team area in java code. Has any example?

Comments
sam detweiler commented Dec 18 '13, 8:24 a.m.

far as I can see you have to go the other direction, given a team area, is this user in it or not. 


project->getteamareas()->getMembers(). I think you will have to write a special compare function 
using item1.sameitemId(item2) to compare the handles. 

thanks for asking, as I have to do something similar soon. 

2 answers



permanent link
K M (38325251) | answered Jan 02 '14, 3:30 p.m.
ResourcePlanningService.java has this, it might be helpful  


 private void getTeamAreas(final ItemCollection<IContributorHandle> contributors, final ItemAwareMap<IContributorHandle, ItemCollection<IProcessArea>> result) throws TeamRepositoryException {
        final IRepositoryItemService repositoryService= getService(IRepositoryItemService.class);
        final IQueryService queryService= getService(IQueryService.class);
        IItemQuery query= IItemQuery.FACTORY.newInstance(ProcessAreaQueryModel.ROOT);
        IPredicate contributorPredicate= ProcessAreaQueryModel.ROOT.contributors()._contains(query.newItemHandleArg());
        for (int index= 0; index < contributors.size() - 1; index++)
            contributorPredicate= contributorPredicate._or(ProcessAreaQueryModel.ROOT.contributors()._contains(query.newItemHandleArg()));
        query= (IItemQuery) query.filter(contributorPredicate).distinct();
        final ItemQueryIterator<IProcessArea> iterator= new ItemQueryIterator<IProcessArea>(queryService, repositoryService, query, contributors.toArray(new IContributorHandle[contributors.size()]));
        while (iterator.hasNext()) {
            final List<IProcessArea> areas= iterator.next();
            for (final IProcessArea area : areas) {
                final IContributorHandle[] members= area.getMembers();
                for (final IContributorHandle member : members) {
                    ItemCollection<IProcessArea> collection= result.get(member);
                    if (collection == null) {
                        collection= new ItemHashSet<IProcessArea>(AVERAGE_TEAMS);
                        result.put(member, collection);
                    }
                    collection.add(area);
                }
            }
        }
    }

permanent link
K M (38325251) | answered Jan 08 '14, 9:19 a.m.
A better way
        IProcessItemService processItemService = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
        List processAreasOfUser= processItemService.findProcessAreas(repo.loggedInContributor(), null, IProcessClientService.ALL_PROPERTIES , MONITOR);
        Iterator b = processAreasOfUser.iterator();
        while (b.hasNext()) {               
            IProcessArea processArea = (IProcessArea) b.next();
            if (processArea.getItemType().getName().equals("TeamArea")) {
                System.out.println(processArea.getName());
            }
        }

this link is useful
http://rsjazz.wordpress.com/2012/12/09/analyzing-a-aroject-areas-members-and-roles-using-the-plain-java-client-libraries/


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.