It's all about the answers!

Ask a question

Catching newly added child workitems before save


geetu garg (81312) | asked Oct 15 '12, 4:33 p.m.
edited Oct 15 '12, 4:33 p.m.
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);
                            }
                        }
                    }
                }
            }
        }
    }


Comments
Ralph Schoon commented Oct 16 '12, 12:59 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

  Hi, I am not clear what the question is.


geetu garg commented 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.

Accepted answer


permanent link
Ralph Schoon (59.7k23643) | answered Oct 16 '12, 2:17 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Oct 16 '12, 2:20 a.m.
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.
geetu garg selected this answer as the correct answer

Your answer


Register or to post your answer.