It's all about the answers!

Ask a question

Programaticly appending comments to work items


jmilam (111) | asked Jan 19 '09, 4:08 p.m.
I've been using the Plain-Java API to fetch work items from an RTC team area. I then try to append a comment to the work item. When doing so a com.ibm.team.repository.common.internal.ImmutablePropertyException is thrown.

I followed the example here to connect to the repository https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation#Plain_Java_Client and the comments here https://jazz.net/forums/viewtopic.php?t=2959&highlight=api+comments to try and append a comment.

Below is the relevant code snippet:

TeamPlatform.startup();
ITeamRepository teamRepository= TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryURI);
teamRepository.registerLoginHandler(new LoginHandler(userId, password));
teamRepository.login(null);

IProcessClientService processClient= (IProcessClientService) teamRepository.getClientLibrary(IProcessClientService.class);
IWorkItemClient workItemClient= (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);

URI uri= URI.create( "My Project Area".replaceAll(" ", "%20") );
IProjectArea projectArea= (IProjectArea) processClient.findProcessArea(uri, null, null);
if (projectArea == null) {
System.out.println("Project area not found.");
}

IWorkItem workingCopy = workItemClient.findWorkItemById(456, IWorkItem.FULL_PROFILE, null);
System.out.println("State: " + workingCopy.getState2().getStringIdentifier());
System.out.println("Resolution: " + workingCopy.getResolution2().getStringIdentifier());
IComments comments= workingCopy.getComments();
System.out.println("Listing Comments: ");
for(IComment c: comments.getContents() ){
System.out.println(" " + c.getHTMLContent().getPlainText());
}
IComment comment= comments.createComment( teamRepository.loggedInContributor(),
XMLString.createFromPlainText( "This is my new commend from the java api"));
comments.append(comment);


Any ideas as to why I'm unable to modify the work item?

2 answers



permanent link
Hiroki Kondo (2642) | answered Jan 20 '09, 1:48 a.m.
Hi jmilam,

Now I got an answer about this!I suffer from same thing.
IWorkItem workingCopy =
workItemClient.findWorkItemById(456,IWorkItem.FULL_PROFILE, null);


You got *Immutable* WorkItem at this line.
If you momdify workitem, you get WorkingCopy from WorkItem.
WorkingCopy has same interface from that Object.so I'll show you the statements.

IWorkItem workitem = workItemClient.findWorkItemById(456,IWorkItem.FULL_PROFILE,
null);
IWorkItem workingCopy = (IWorkItem)workitem.getWorkingCopy();

Regards,
Hiroki Kondo

jmilam wrote:
I've been using the Plain-Java API to fetch work items from an RTC
team area. I then try to append a comment to the work item. When
doing so a
com.ibm.team.repository.common.internal.ImmutablePropertyException is
thrown.

I followed the example here to connect to the repository
https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation#Plain_Java_Client
and the comments here
https://jazz.net/forums/viewtopic.php?t=2959&highlight=api+comments
to try and append a comment.

Below is the relevant code snippet:

TeamPlatform.startup();
ITeamRepository teamRepository=
TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryURI);
teamRepository.registerLoginHandler(new
LoginHandler(userId, password));
teamRepository.login(null);

IProcessClientService processClient=
(IProcessClientService)
teamRepository.getClientLibrary(IProcessClientService.class);
IWorkItemClient workItemClient= (IWorkItemClient)
teamRepository.getClientLibrary(IWorkItemClient.class);

URI uri= URI.create( "My Project
Area".replaceAll(" ", "%20") );
IProjectArea projectArea= (IProjectArea)
processClient.findProcessArea(uri, null, null);
if (projectArea == null) {
System.out.println("Project area not found.");
}

IWorkItem workingCopy = workItemClient.findWorkItemById(456,
IWorkItem.FULL_PROFILE, null);
System.out.println("State: " +
workingCopy.getState2().getStringIdentifier());
System.out.println("Resolution: " +
workingCopy.getResolution2().getStringIdentifier());
IComments comments= workingCopy.getComments();
System.out.println("Listing Comments: ");
for(IComment c: comments.getContents() ){
System.out.println(" " +
c.getHTMLContent().getPlainText());
}
IComment comment= comments.createComment(
teamRepository.loggedInContributor(),
XMLString.createFromPlainText( "This is my new commend
from the java api"));
comments.append(comment);


Any ideas as to why I'm unable to modify the work item?

permanent link
Patrick Streule (4.9k21) | answered Jan 20 '09, 3:28 a.m.
JAZZ DEVELOPER
The Wiki page
https://jazz.net:443/wiki/bin/view/Main/ProgrammaticWorkItemCreation

also has some examples of how to create work items in a plain Java context.

--
Regards,
Patrick
Jazz Work Item Team

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.