It's all about the answers!

Ask a question

Update a Work Item Attribute using its Operation Participant


Arun Batra (14612225) | asked Sep 14 '11, 10:29 a.m.
Hi,

I am trying to update a custom attribute of string type from a save triggered operation participant using java.
My code is as follows

saveParameter = (ISaveParameter) data;
IWorkItem newState = (IWorkItem) saveParameter.getNewState();

newState.setValue(attributeID, StringValue);


It doesn't give an exception or anything. It just doesn't work. Where am i going wrong here.
I am new at this and lost.

Please Help.

6 answers



permanent link
Laurence Caraccio (9166) | answered Sep 15 '11, 4:48 a.m.
The code below should edit a work item for you, you will need to change the id of the work item you are getting, change the identifier of the attribute you are getting and put a value in.

Hope this helps.

 ItemProfile<IWorkItem> profile = IWorkItem.DEFAULT_PROFILE;


IWorkItem workItem = workItemClient.findWorkItemById(2000,profile, null);
if (workItem == null) {
System.out.println("Work Item not found.");
return false;
}

IWorkItemHandle handle = (IWorkItemHandle) workItem.getItemHandle();
IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
wcm.connect(handle, IWorkItem.FULL_PROFILE, null);
WorkItemWorkingCopy wc = wcm.getWorkingCopy(handle);
IWorkItem copiedWorkItem = wc.getWorkItem();

try {

IAttribute customAttribute = workItemClient.findAttribute(projectArea, "attributeIdentifier", null);

copiedWorkItem.setValue(customAttribute, "yourValue");

wc.save(null);

permanent link
Arun Batra (14612225) | answered Sep 20 '11, 3:22 a.m.
Hi,

Thank you for your reply. It was very useful. However could you please tell me how to get workItemClient.

I am trying to get it using

IWorkItemClient wiclient = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);


If this is correct, how do i get the ITeamRepository repo.


Thanks
Arun

permanent link
Laurence Caraccio (9166) | answered Sep 20 '11, 4:30 a.m.
That is indeed correct for getting the work item client, the code to log in to the repository is
 ITeamRepository teamRepository= TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryURI);

teamRepository.registerLoginHandler(new LoginHandler(userId, password));
teamRepository.login(null);


Where repositoryURI is the address of your jazz repository, for example: https://jazz705.hursley.ibm.com:9443/ccm

and then put your user name and password in, the login handler is an internal class
 private static class LoginHandler implements ILoginHandler, ILoginInfo {


private String fUserId;
private String fPassword;

private LoginHandler(String userId, String password) {
fUserId= userId;
fPassword= password;
}

public String getUserId() {
return fUserId;
}

public String getPassword() {
return fPassword;
}

public ILoginInfo challenge(ITeamRepository repository) {
return this;
}
}


Then
 IWorkItemClient workItemClient= (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class); 
will get the work item client for you.

permanent link
radhika bandari (10675) | answered Dec 02 '11, 4:22 a.m.
Hi Arun,

I think you have used com.ibm.team.workitem.client.IWorkItemClient API in your OperationParticipant plug-in. I am also trying to use client libraries in my OperationAdvisor but when I import client related libraries, the plug-in is not deployed on the server.
Could you please let me know the solution?
I did not find any solution for this since some weeks.
I have to use com.ibm.team.repository.client.ITeamRepository as well in my current development Item.

Thanks in Advance

Regards,
Radhika B

permanent link
sam detweiler (12.4k6180201) | answered Dec 02 '11, 8:31 a.m.
the IWorkItem u have in the OperationAdvisor is a READ ONLY instance..

you must get the WorkingCopy to modify it..

in my OperationAdvisor , I assume something similar is done in a Participant.

// reference the right object type (cast)
IWorkItem workItem = (IWorkItem) auditable;
IWorkItem rr = (IWorkItem)workItem.getWorkingCopy();


you should always assume it is read only unless YOU just created the workitem.

---- edit.. you are in an OperationParticipant, and so shouldn't have a data overlay problem..

Sam

permanent link
Michele Pegoraro (1.8k12114101) | answered Dec 05 '11, 8:10 a.m.
Hi,
why do you use Client API on OperationAdvisor?

I suggest you to use server side API. In order to save a work-item you can use IWorkItemServer instead of IWorkItemClient. Methods are quite similar. You are already logged in as you run Advisor, you don't need to re-login.

Michele.

Hi Arun,

I think you have used com.ibm.team.workitem.client.IWorkItemClient
API in your OperationParticipant plug-in. I am also trying to use client libraries in my OperationAdvisor but when I import client related libraries, the plug-in is not deployed on the server.
Could you please let me know the solution?
I did not find any solution for this since some weeks.
I have to use com.ibm.team.repository.client.ITeamRepository as well in my current development Item.

Thanks in Advance

Regards,
Radhika B

Your answer


Register or to post your answer.