Workitem's owner is set null when using client library.
Hi folks,
We use client library to update some workitems continuously.The other day,I ran
to update workitems, the last one's owner was lost(set null).I'll show you owr
WorkitemUpdater class.Is it correct to use WorkItemOperation?
public class WorkItemUpdater extends WorkItemOperation {
private final IWorkItem workItem;
private ITeamRepository teamRepository;
private String statusIdenfier;
WorkItemUpdater(ITeamRepository teamRepository, IWorkItem workItem, String
statusIdenfier) {
super("Update work item", IWorkItem.FULL_PROFILE);
this.teamRepository = teamRepository;
this.workItem = workItem;
this.statusIdenfier = statusIdenfier;
}
@Override
protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor
monitor)
throws TeamRepositoryException {
IWorkItem workItemTemp = workingCopy.getWorkItem();
IWorkflowInfo info = getIWorkItemInfo(monitor);
workItem().setStatus(workItemTemp, info);
workItem().addCustomAttribute(workItemTemp,
WorkItemCustomAttributes.ATTR_KEY_X);
workItem().addCustomAttribute(workItemTemp,
WorkItemCustomAttributes.ATTR_KEY_Y);
}
private WorkItemUpdater workItem() {
return this;
}
private void addCustomAttribute(IWorkItem workItemTemp, String attributeName) {
WorkItemCustomAttributes attrs =
new WorkItemCustomAttributes(getTeamRepository(),
workItem.getProjectArea());
attrs.addCustomAttribute(
workItemTemp,
attributeName);
}
private void setStatus(IWorkItem workItemTemp, IWorkflowInfo info) {
for(Identifier<IState> status : info.getAllStateIds()){
if((status.getStringIdentifier()).equals(this.statusIdenfier)){
workItemTemp.setState2(status);
}
}
}
private IWorkflowInfo getIWorkItemInfo(IProgressMonitor monitor) throws
TeamRepositoryException {
// get IWorkItemCommon
IWorkItemCommon client =
ClientLibraryUtil.getIWorkItemCommon(getTeamRepository());
IWorkflowInfo info = client.findWorkflowInfo(workItem, monitor);
return info;
}
public ITeamRepository getTeamRepository() {
return teamRepository;
}
public void setTeamRepository(ITeamRepository teamRepository) {
this.teamRepository = teamRepository;
}
}
Best regards,
- Hiroki
We use client library to update some workitems continuously.The other day,I ran
to update workitems, the last one's owner was lost(set null).I'll show you owr
WorkitemUpdater class.Is it correct to use WorkItemOperation?
public class WorkItemUpdater extends WorkItemOperation {
private final IWorkItem workItem;
private ITeamRepository teamRepository;
private String statusIdenfier;
WorkItemUpdater(ITeamRepository teamRepository, IWorkItem workItem, String
statusIdenfier) {
super("Update work item", IWorkItem.FULL_PROFILE);
this.teamRepository = teamRepository;
this.workItem = workItem;
this.statusIdenfier = statusIdenfier;
}
@Override
protected void execute(WorkItemWorkingCopy workingCopy, IProgressMonitor
monitor)
throws TeamRepositoryException {
IWorkItem workItemTemp = workingCopy.getWorkItem();
IWorkflowInfo info = getIWorkItemInfo(monitor);
workItem().setStatus(workItemTemp, info);
workItem().addCustomAttribute(workItemTemp,
WorkItemCustomAttributes.ATTR_KEY_X);
workItem().addCustomAttribute(workItemTemp,
WorkItemCustomAttributes.ATTR_KEY_Y);
}
private WorkItemUpdater workItem() {
return this;
}
private void addCustomAttribute(IWorkItem workItemTemp, String attributeName) {
WorkItemCustomAttributes attrs =
new WorkItemCustomAttributes(getTeamRepository(),
workItem.getProjectArea());
attrs.addCustomAttribute(
workItemTemp,
attributeName);
}
private void setStatus(IWorkItem workItemTemp, IWorkflowInfo info) {
for(Identifier<IState> status : info.getAllStateIds()){
if((status.getStringIdentifier()).equals(this.statusIdenfier)){
workItemTemp.setState2(status);
}
}
}
private IWorkflowInfo getIWorkItemInfo(IProgressMonitor monitor) throws
TeamRepositoryException {
// get IWorkItemCommon
IWorkItemCommon client =
ClientLibraryUtil.getIWorkItemCommon(getTeamRepository());
IWorkflowInfo info = client.findWorkflowInfo(workItem, monitor);
return info;
}
public ITeamRepository getTeamRepository() {
return teamRepository;
}
public void setTeamRepository(ITeamRepository teamRepository) {
this.teamRepository = teamRepository;
}
}
Best regards,
- Hiroki