Programaticly appending comments to work items
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:
Any ideas as to why I'm unable to modify the work item?
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
Hi jmilam,
Now I got an answer about this!I suffer from same thing.
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:
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?