Change WI state by client plain java library.
I'm looking for a method how to work around the problem I get in this code.
WorkItemWorkingCopy wc = wcm.getWorkingCopy(workItem);
wc.setWorkflowAction(newState);
wc.save(monitor);
When I run this code (standalone Java application) I get serious error message:
--
com.ibm.team.repository.client.util.ThreadCheck checkLongOpsAllowed
Long-running operations prohibited on this thread
at com.ibm.team.repository.client.util.ThreadCheck.checkLongOpsAllowed(ThreadCheck.java:118)
--
Note that workitem state is actually changed to expected state. I searched previous post in the forum which is suggesting to run in back ground using Job class. so I tried like this:
Job job = new Job("Workitem Save") {
@Override
protected IStatus run(IProgressMonitor monitor) {
System.out.println("Workitem Save operation start");
wc.save(monitor);
return Status.OK_STATUS;
}
};
job.schedule();
Still I get the the same error message. Previous posts have no conclusive answer for this problem.
Do you have any suggestion how to work around this problem ?
WorkItemWorkingCopy wc = wcm.getWorkingCopy(workItem);
wc.setWorkflowAction(newState);
wc.save(monitor);
When I run this code (standalone Java application) I get serious error message:
--
com.ibm.team.repository.client.util.ThreadCheck checkLongOpsAllowed
Long-running operations prohibited on this thread
at com.ibm.team.repository.client.util.ThreadCheck.checkLongOpsAllowed(ThreadCheck.java:118)
--
Note that workitem state is actually changed to expected state. I searched previous post in the forum which is suggesting to run in back ground using Job class. so I tried like this:
Job job = new Job("Workitem Save") {
@Override
protected IStatus run(IProgressMonitor monitor) {
System.out.println("Workitem Save operation start");
wc.save(monitor);
return Status.OK_STATUS;
}
};
job.schedule();
Still I get the the same error message. Previous posts have no conclusive answer for this problem.
Do you have any suggestion how to work around this problem ?
5 answers
Hi Takehiko-san,
did you solve this?
Partly. I've raised as a defect, because repository should defect whether this is under UI or command line.
"201976: Change state result in "Long-running operations prohibited on this thread" exception in client plain java library. "
The work around that customer used was to absorb stack trace to NULL stream which is like this:
PrintStream normalErr = System.err;
System.setErr(new PrintStream(new FileOutputStream("NUL:")));
// Change state
System.setErr(normalErr);
State is actually changed to expected one, so we assume absorbing message during state change is harmless.
Please let me know if there is any better way.
Have a look at the following code...
"New" Status -> "In Progress" Status by "Start Working" Action
-------------------------------------------------------------------------
IWorkItemClient workItemClient = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager copyManager = workItemClient.getWorkItemWorkingCopyManager();
IWorkItemHandle workItemHandle = workItemClient.findWorkItemById(workItemNumber, IWorkItem.FULL_PROFILE, null);
copyManager.connect(workItemHandle, IWorkItem.FULL_PROFILE, null);
WorkItemWorkingCopy workItemCopy = copyManager.getWorkingCopy(workItemHandle);
IWorkItem workItem = workItemCopy.getWorkItem();
IWorkflowInfo workflowInfo = workItemClient.findWorkflowInfo(workItem, null);
Identifier<IWorkflowAction> actionIds[] = workflowInfo.getAllActionIds();
String actionString = null;
for(Identifier<IWorkflowAction> actionId : actionIds)
{
if(workflowInfo.getActionName(actionId).equalsIgnoreCase("Start Working"))
{
//System.out.println(actionId.getStringIdentifier());
actionString = actionId.getStringIdentifier();
}
}
workItemCopy.setWorkflowAction(actionString);
IDetailedStatus detailedStatus = workItemCopy.save(null);
copyManager.disconnect(workItemHandle);
if (!detailedStatus.isOK()) {
throw new TeamRepositoryException(detailedStatus.getDetails());
//System.out.println("Save Fail = " + detailedStatus.getDetails());
}
"New" Status -> "In Progress" Status by "Start Working" Action
-------------------------------------------------------------------------
IWorkItemClient workItemClient = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager copyManager = workItemClient.getWorkItemWorkingCopyManager();
IWorkItemHandle workItemHandle = workItemClient.findWorkItemById(workItemNumber, IWorkItem.FULL_PROFILE, null);
copyManager.connect(workItemHandle, IWorkItem.FULL_PROFILE, null);
WorkItemWorkingCopy workItemCopy = copyManager.getWorkingCopy(workItemHandle);
IWorkItem workItem = workItemCopy.getWorkItem();
IWorkflowInfo workflowInfo = workItemClient.findWorkflowInfo(workItem, null);
Identifier<IWorkflowAction> actionIds[] = workflowInfo.getAllActionIds();
String actionString = null;
for(Identifier<IWorkflowAction> actionId : actionIds)
{
if(workflowInfo.getActionName(actionId).equalsIgnoreCase("Start Working"))
{
//System.out.println(actionId.getStringIdentifier());
actionString = actionId.getStringIdentifier();
}
}
workItemCopy.setWorkflowAction(actionString);
IDetailedStatus detailedStatus = workItemCopy.save(null);
copyManager.disconnect(workItemHandle);
if (!detailedStatus.isOK()) {
throw new TeamRepositoryException(detailedStatus.getDetails());
//System.out.println("Save Fail = " + detailedStatus.getDetails());
}