Get teamAreaList attribute with RTC Java API
Hi All,
I would like to extract custom field type; "teamAreaList", using RTC Java API.
Team Area List:
"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");Thanks in advance.
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());
}
Regards.
Accepted answer
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.
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"; }
2 other answers
Last time I tried, I casted it to List and then accessed the element and casted that to the desired Object.
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
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