Bug in Synchronize Attributes feature?
In the Eclipse client there is the menu “Synchronize Attributes” that is used to update the attributes of existing work items in case the process template has changed and some new attributes have been added or old attributes are not available any more.
Looking at the invoked code it comes down to WorkItemCommon.updateWorkItemType(...) where the newType and oldType parameter are the same instance and this instance is the work item type of the current (meaning new) process template.
The method implementation is this:
public boolean updateWorkItemType(IWorkItem workItem, IWorkItemType newType, IWorkItemType oldType, IProgressMonitor monitor) throws TeamRepositoryException {Looking at the code it seems to me that attributes that are available in the work item but not any more in the work item type (of the new process template) are never removed. Removal of attributes only work if newType and oldType are different.
Assert.isTrue(workItem.isWorkingCopy());
((WorkItem) workItem).setWorkItemType(newType.getIdentifier());
boolean changed= false;
ItemHandleAwareHashSet<IAttributeHandle> customAttributes= new ItemHandleAwareHashSet<IAttributeHandle>(newType.getCustomAttributes());
for (IAttributeHandle customAttribute: customAttributes) {
IAttribute attribute= fAuditableCommon.resolveAuditable(customAttribute, IAttribute.FULL_PROFILE, monitor);
if (!workItem.hasAttribute(attribute)) {
workItem.addCustomAttribute(attribute);
workItem.setValue(attribute, attribute.getDefaultValue(fAuditableCommon, workItem, monitor));
changed= true;
} else if (AttributeTypes.isEnumerationAttributeType(attribute.getAttributeType())) {
if (workItem.getValue(attribute) == null) {
workItem.setValue(attribute, attribute.getDefaultValue(fAuditableCommon, workItem, monitor));
}
}
}
if (oldType != null) {
for (IAttributeHandle customAttribute: oldType.getCustomAttributes()) {
if (!customAttributes.contains(customAttribute)) {
if (workItem.hasCustomAttribute(customAttribute)) {
IAttribute attribute= fAuditableCommon.resolveAuditable(customAttribute, IAttribute.FULL_PROFILE, monitor);
workItem.removeCustomAttribute(attribute);
changed= true;
}
}
}
}
return changed;
}
This could be solved by replacing line
for (IAttributeHandle customAttribute: oldType.getCustomAttributes()) {by
for (IAttributeHandle customAttribute: workItem.getCustomAttributes()) {Am I missing something here?
Marko
2 answers
Marco, I would submit an enhancement request. I am not sure if this is as planned or not. There might be reasons.
Comments
There is a defect on this:
Defect 431460: Javadoc for IWorkItemCommon updateWorkItemType is incomplete
This is working as designed. The way it works is:
1) If the old type is not provided, no attributes are removed.
2) If the old type is provided, attributes that are in the old type and not in the new type are removed.
3) Attributes in the new type are added.
4) Attributes that are not in the old type and not in the new type are not removed. These are inherited from base.
A tech note will appear here: http://g01zciwas018.ahe.pok.ibm.com/support/dcf/preview.wss?host=g01zcidbs003.ahe.pok.ibm.com&db=support/swg/rattech.nsf&unid=D130D8EB15505231852581630040E3F9&taxOC=SSC9M9F&MD=2017/07/20%2014:07:38&sid=
(currently it is a placeholder)