It's all about the answers!

Ask a question

Get teamAreaList attribute with RTC Java API


Gustavo Leyva (3345) | asked Apr 02 '13, 3:22 p.m.
edited Apr 02 '13, 7:42 p.m.
Hi All,

I would like to extract custom field type; "teamAreaList", using RTC Java API.

Team Area List:

AffTeamArea

"Affected Team Area" is a custom field; "com.test.issue.attribute.affectedTeam", type;"teamAreaList"

 I am able to extract the Team Area Hierarchy, nevertheless I do not know how to obtain expected data from that customized field.

To extract the Team Area Hierarchy, I do the following:
IProjectArea projectArea = getProjectArea(repo, "Sandbox");
   System.out.println(projectArea);
   listTeams = projectArea.getTeamAreaHierarchy().getTeamAreas();
   for (int i=0;i<listTeams.size();i++) { 
        ITeamAreaHandle defaultTeamArea2 = (ITeamAreaHandle)listTeams.get(i);
ITeamArea teamArea = (ITeamArea)repo.itemManager().fetchCompleteItem(defaultTeamArea2, 0, null);
System.out.println(teamArea.getName());
Thanks in advance.

Regards.

Accepted answer


permanent link
Ralph Schoon (63.1k33646) | answered Apr 03 '13, 2:36 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Gustavo,

I would suggest to setup your development environment to be able to debug. This makes it so much easier to look at objects and to understand what they are. Please consider to read the following http://rsjazz.wordpress.com/2013/02/28/setting-up-rational-team-concert-for-api-development/ and the liked posts to set up PlainJava.

Code I have used looks like below. It casts the ItemList attribute value to a collection and then iterates the enclosed handles.
	private String convertItemListAttributeType(IWorkItem workItem,
			IAttribute iAttribute, Object value) {

		String displayValue = "ITEM LIST: " + iAttribute.getAttributeType();
		if (null != value && value instanceof Collection) {
			Collection values = (Collection) value;
			for (Iterator iterator = values.iterator(); iterator.hasNext();) {
				Object object = (Object) iterator.next();
				if (null != object && object instanceof IItemHandle) {
					IItemHandle itemHandle = (IItemHandle) object;
					// do something
					// for example resolve the item and identify it as a teamArea.
					return itemHandle.toString();
				} else if (null != object && object instanceof IItemHandle) {
					IItem item = (IItem) object;
					return item.toString();
				}
				displayValue += " " + object.toString();
			}
		}
		return displayValue + " Item List Not yet implemented";
	}




 
Gustavo Leyva selected this answer as the correct answer

Comments
Gustavo Leyva commented Apr 03 '13, 5:53 p.m.

Hi Ralph,


I implemented the code you mentioned and it works!
Thank you so much! Have an excellent day.

2 other answers



permanent link
Susan Hanson (1.6k2201194) | answered Apr 02 '13, 7:20 p.m.
I do something similar:
        IProjectArea projectArea = rtcm.getProjectArea();
        String name = "";
        if (projectArea != null) {
            List teamAreas = projectArea.getTeamAreas();
            ITeamAreaHierarchy hierarchy = projectArea.getTeamAreaHierarchy();
            for (int i=0;i<teamAreas.size();i++) {
                String ILNames = "";
                String parentName = "Not Yet Set";
                ITeamAreaHandle teamAreaHandle = (ITeamAreaHandle)teamAreas.get(i);
                ITeamAreaHandle teamParent = hierarchy.getParent(teamAreaHandle);
                if (teamParent != null) {
                    ITeamArea parentTeamArea = (ITeamArea)rtcm.getRepository().itemManager().fetchCompleteItem(teamParent,0,null);
                    parentName = parentTeamArea.getName();
                }
                else {
                    //System.out.println("I have a null parent for " + teamAreaHandle.toString());
                }
                ITeamArea teamArea = (ITeamArea)rtcm.getRepository().itemManager().fetchCompleteItem(teamAreaHandle,0,null);
                if (!teamArea.isArchived()) {
                        ITeamData teamData = teamArea.getTeamData();
                        name = teamArea.getName();
                        IDescription desc=  teamArea.getDescription();
                        IContent content = desc.getDetails();
                        String descriptionString="";
                        if (content != null) {
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                rtcm.getRepository().contentManager().retrieveContent(content, stream,null);
                                try {
                                    descriptionString = stream.toString(HttpConstants.ENCODING_UTF8);
                                } catch (UnsupportedEncodingException exception) {
                                    descriptionString = stream.toString();
                                }
                            }
.....


I do alot more "stuff" below that, but this should at least give you an idea of what I do to get the name and description. 

Susa

Comments
Gustavo Leyva commented Apr 02 '13, 7:45 p.m.

 Hi Susan,

Thank you for your comment!
I am able to extract Team Area Hierarchy  I think I was not clear, I updated my question with more details, sorry for the inconvinient.
Thank you and have a nice day.


permanent link
Ralph Schoon (63.1k33646) | answered Apr 02 '13, 3:57 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
 Last time I tried, I casted it to List and then accessed the element and casted that to the desired Object.

Comments
Gustavo Leyva commented Apr 02 '13, 4:15 p.m.

  Hi Ralp,

Thank you for comment.
I did not mentioned "listTeams" is a list "List<iteamareahandle> listTeams=null;"
Can you please add more details to your comment? I did not get which element did you cast.
Thanks in advance.

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.