Catching newly added child workitems before save
I am writing a precondition on workitem save.
When I add a child and try saving a workitem, my precondition should be fired and also check if this newly added child (but has not been saved) is also verified but its not fetched.
On the other hand, if I do "set parent" from the child side , then this precondition is triggered fine.
I use the code below:
private void findOffspring2(List<IWorkItemHandle> offSpring,
AdvisableOperation operation, boolean isFactoryItemOnly,
boolean recurse) throws TeamRepositoryException {
auditableCommon = getService(IAuditableCommon.class);
Object data = operation.getOperationData();
if (data instanceof ISaveParameter) // from Workitem -> save operation
{
ISaveParameter saveParameter = (ISaveParameter) data;
IWorkItemReferences ref = saveParameter.getNewReferences();
List<IEndPointDescriptor> types = ref.getTypes();
for (IEndPointDescriptor desc : types) {
if (desc.getId().equalsIgnoreCase(CHILDREN)) // "children" is
// an RTC/Jazz
// string ID
{
List<IReference> refList = ref.getReferences(desc);
if (refList.size() > 0) {
IReference iRef = refList.get(0); // Only one parent
Object obj = iRef.resolve();
if (obj instanceof IWorkItemHandle) // Only looking for
// Workitems.
{
IWorkItemHandle childHandle = (IWorkItemHandle) obj;
IWorkItem childWorkItem = auditableCommon
.resolveAuditable(childHandle,
IWorkItem.FULL_PROFILE, null);
if (!isFactoryItemOnly
|| (isFactoryItemOnly && isFactoryWorkItem(childWorkItem))) {
offSpring.add(childHandle);
}
if (recurse) {
findOffspring(offSpring, childWorkItem,
isFactoryItemOnly, recurse);
}
}
}
}
}
}
}
When I add a child and try saving a workitem, my precondition should be fired and also check if this newly added child (but has not been saved) is also verified but its not fetched.
On the other hand, if I do "set parent" from the child side , then this precondition is triggered fine.
I use the code below:
private void findOffspring2(List<IWorkItemHandle> offSpring,
AdvisableOperation operation, boolean isFactoryItemOnly,
boolean recurse) throws TeamRepositoryException {
auditableCommon = getService(IAuditableCommon.class);
Object data = operation.getOperationData();
if (data instanceof ISaveParameter) // from Workitem -> save operation
{
ISaveParameter saveParameter = (ISaveParameter) data;
IWorkItemReferences ref = saveParameter.getNewReferences();
List<IEndPointDescriptor> types = ref.getTypes();
for (IEndPointDescriptor desc : types) {
if (desc.getId().equalsIgnoreCase(CHILDREN)) // "children" is
// an RTC/Jazz
// string ID
{
List<IReference> refList = ref.getReferences(desc);
if (refList.size() > 0) {
IReference iRef = refList.get(0); // Only one parent
Object obj = iRef.resolve();
if (obj instanceof IWorkItemHandle) // Only looking for
// Workitems.
{
IWorkItemHandle childHandle = (IWorkItemHandle) obj;
IWorkItem childWorkItem = auditableCommon
.resolveAuditable(childHandle,
IWorkItem.FULL_PROFILE, null);
if (!isFactoryItemOnly
|| (isFactoryItemOnly && isFactoryWorkItem(childWorkItem))) {
offSpring.add(childHandle);
}
if (recurse) {
findOffspring(offSpring, childWorkItem,
isFactoryItemOnly, recurse);
}
}
}
}
}
}
}
Accepted answer
Hi,
I was always under the impression you should be able to get the new references using saveParameter .getNewReferences().getReferences()
For example
List<IReference> blockingDependencies = saveParameter
.getNewReferences().getReferences(
WorkItemEndPoints.DEPENDS_ON_WORK_ITEM);
If this is not working, you might have to use a participant instead of a precondition.
I was always under the impression you should be able to get the new references using saveParameter .getNewReferences().getReferences()
For example
List<IReference> blockingDependencies = saveParameter
.getNewReferences().getReferences(
WorkItemEndPoints.DEPENDS_ON_WORK_ITEM);
If this is not working, you might have to use a participant instead of a precondition.
Comments
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Oct 16 '12, 12:59 a.m.Hi, I am not clear what the question is.
geetu garg
Oct 16 '12, 1:17 a.m.Hi,
When I add children to a workitem and click save, my precondition is fired but is not able to find this new child reference, since the child is not saved yet.
Please help me catch this new child reference before save.