After work item type update/attribute sync the new attributes are not visible on work item object
Hi
I have developed a tool for synchronizing the work item attributes. For that I am using the class listed at the end of this post.
If I run my (plain java) application that synchronizes work items in order to show up some new attributes it works fine if I run the tool and then open the browser for looking at the work items. That means the new work item attributes are appearing then in the browser.
But this is not what I want/need. I am running the below listed operation on a bunch of work items. In the same application session I want to access the newly appearing attributes. But these attributes are not available via API. When I ask the project area for the new attributes they are found. But when I then fetch the synchronized work items and call IWorkItem.hasAttribute(xyz) the new attributes are not found. I could imagine that the work item objet ct (before the sync) is somehow cached and then returned instead of work item with the new custom attributes.
Code for running the work item attribute synch:
import org.apache.logging.log4j.LogManager;
import org.eclipse.core.runtime.IProgressMonitor;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.workitem.client.IWorkItemClient;
import com.ibm.team.workitem.client.WorkItemOperation;
import com.ibm.team.workitem.client.WorkItemWorkingCopy;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.common.model.IWorkItemType;
public class SynchronizeWorkItemOperation extends WorkItemOperation {
private IWorkItemClient fWorkItemClient = null;
/**
* Parameterised constructor.
*
* @param workItemClient , {@link IWorkItemClient} instance , must not be null
*/
public SynchronizeWorkItemOperation(final IWorkItemClient workItemClient) {
super("Synchronize Attribute Schema of Work Items", IWorkItem.FULL_PROFILE);
this.fWorkItemClient = workItemClient;
}
@Override
public void execute(final WorkItemWorkingCopy workingCopy, final IProgressMonitor mon)
throws TeamRepositoryException {
IWorkItem workItem = workingCopy.getWorkItem();
IWorkItemType type =
this.fWorkItemClient.findWorkItemType(workItem.getProjectArea(), workItem.getWorkItemType(), mon);
if (type != null) {
this.fWorkItemClient.updateWorkItemType(workItem, type, type, mon);
}
}
}
I have developed a tool for synchronizing the work item attributes. For that I am using the class listed at the end of this post.
If I run my (plain java) application that synchronizes work items in order to show up some new attributes it works fine if I run the tool and then open the browser for looking at the work items. That means the new work item attributes are appearing then in the browser.
But this is not what I want/need. I am running the below listed operation on a bunch of work items. In the same application session I want to access the newly appearing attributes. But these attributes are not available via API. When I ask the project area for the new attributes they are found. But when I then fetch the synchronized work items and call IWorkItem.hasAttribute(xyz) the new attributes are not found. I could imagine that the work item objet ct (before the sync) is somehow cached and then returned instead of work item with the new custom attributes.
Code for running the work item attribute synch:
import org.apache.logging.log4j.LogManager;
import org.eclipse.core.runtime.IProgressMonitor;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.workitem.client.IWorkItemClient;
import com.ibm.team.workitem.client.WorkItemOperation;
import com.ibm.team.workitem.client.WorkItemWorkingCopy;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.common.model.IWorkItemType;
public class SynchronizeWorkItemOperation extends WorkItemOperation {
private IWorkItemClient fWorkItemClient = null;
/**
* Parameterised constructor.
*
* @param workItemClient , {@link IWorkItemClient} instance , must not be null
*/
public SynchronizeWorkItemOperation(final IWorkItemClient workItemClient) {
super("Synchronize Attribute Schema of Work Items", IWorkItem.FULL_PROFILE);
this.fWorkItemClient = workItemClient;
}
@Override
public void execute(final WorkItemWorkingCopy workingCopy, final IProgressMonitor mon)
throws TeamRepositoryException {
IWorkItem workItem = workingCopy.getWorkItem();
IWorkItemType type =
this.fWorkItemClient.findWorkItemType(workItem.getProjectArea(), workItem.getWorkItemType(), mon);
if (type != null) {
this.fWorkItemClient.updateWorkItemType(workItem, type, type, mon);
}
}
}
Accepted answer
I partially found a solution for it.
In the end the reason for this is that the call ProcessClientService.refreshProcessCache() is not happening in my application when the project area working copy object is saved. In the save() method implementation of ProcessAreaWorkingCopy the above mentioned call is executed not in all scenarios though.
If I manually invoke the refresh... call in my code then it works fine.
I will be investigating why this call is not done automatically.
In the end the reason for this is that the call ProcessClientService.refreshProcessCache() is not happening in my application when the project area working copy object is saved. In the save() method implementation of ProcessAreaWorkingCopy the above mentioned call is executed not in all scenarios though.
If I manually invoke the refresh... call in my code then it works fine.
I will be investigating why this call is not done automatically.
One other answer
Marco,
I am unsure what your requirement really is. The code above seems to be identical to https://rsjazz.wordpress.com/2012/11/19/using-an-expression-to-synchronize-attributes-for-work-items-of-a-specific-type/ and has worked for me.
If you want to access the new Attributes after the synchronize, I would suggest to exit the operation, use the work item handle to resolve the updated work item again with a refresh.
IWorkItem itemm = (IWorkItem) teamRepository.itemManager() .fetchCompleteItem(handle, IItemManager.REFRESH, monitor);
Comments
That is what I was trying. But still the new attribute did not appear when calling IWorkItem.hasAttribute().
Actually the problem is happening in relation to the WCL tool.
We have integrated WCL into a framework that in this scenario:
1. Switches the master project area
2. Runs the synchronization
3. Wants to set some dedicated values to the new attributes.
But in step 3 WCL complains (correctly) that the attribute to be set is not existing in the work item.
I don't know the answer, unfortunately. I looked at com.ibm.team.workitem.rcp.ui.internal.actions.SynchronizeAttributesAction and the code is really identical.
Comments
Marko Tomljenovic
Nov 29 '16, 12:01 a.m.I have some more details on the root cause.
When debugging the method I can see that this method actually does nothing since the new custom attributes (introduced by new master pa) are not available in the "type" instance. Therefore actually nothing is done.The root cause is the synchronization done by the method
So it must have something to do with how the type instance is retrieved.
I am really out of ideas now.
Marko Tomljenovic
Nov 25 '16, 12:04 p.m.When debugging the same code in Eclipse client the method gets the updated work item type with the new attributes whereas in my plain java world it is not working.