bool HasDuplicateRecord(
            OAdEntity hostRecord,
            string childRecordEntityTypeName,
            string childRecordDisplayName)
        {
            // check if hostRecord already has a duplicate of this childRecord
            if (!CQWrapper.HasDuplicates(hostRecord))
            {
                return(false);
            }

            object[] dupRecObjs = CQWrapper.GetDuplicates(hostRecord) as object[];
            foreach (object dupRecObj in dupRecObjs)
            {
                OAdLink aLink = dupRecObj as OAdLink;
                if (null != aLink)
                {
                    OAdEntity record = CQWrapper.GetChildEntity(aLink) as OAdEntity;
                    if (null != record)
                    {
                        string recDispName      = CQWrapper.GetEntityDisplayName(record);
                        string recEntityDefName = CQWrapper.GetEntityDefName(record);
                        if (CQStringComparer.EntityName.Equals(recEntityDefName, childRecordEntityTypeName) &&
                            CQStringComparer.RecordName.Equals(recDispName, childRecordDisplayName))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        public void ExtractLinkChangeActions(
            Session session,
            OAdEntity hostRecord,
            List <LinkChangeGroup> linkChangeGroups)
        {
            string hostRecDispName      = CQWrapper.GetEntityDisplayName(hostRecord);
            string hostRecEntityDefName = CQWrapper.GetEntityDefName(hostRecord);
            string hostRecMigrItemId    = UtilityMethods.CreateCQRecordMigrationItemId(hostRecEntityDefName, hostRecDispName);

            var linkChangeGroup = new LinkChangeGroup(hostRecMigrItemId, LinkChangeGroup.LinkChangeGroupStatus.Created, false);

            if (!CQWrapper.HasDuplicates(hostRecord))
            {
                return;
            }

            object[] dupRecObjs = CQWrapper.GetDuplicates(hostRecord) as object[];

            foreach (object dupRecObj in dupRecObjs)
            {
                OAdLink aLink = dupRecObj as OAdLink;

                if (null != aLink)
                {
                    OAdEntity childRecord = CQWrapper.GetChildEntity(aLink) as OAdEntity;
                    if (null != childRecord)
                    {
                        string childRecDispName      = CQWrapper.GetEntityDisplayName(childRecord);
                        string childRecEntityDefName = CQWrapper.GetEntityDefName(childRecord);
                        string childRecMigrItemId    = UtilityMethods.CreateCQRecordMigrationItemId(childRecEntityDefName, childRecDispName);

                        ILink dupLink = new ArtifactLink(hostRecDispName,
                                                         new Artifact(hostRecMigrItemId, new ClearQuestRecordArtifactType()),
                                                         new Artifact(childRecMigrItemId, new ClearQuestRecordArtifactType()),
                                                         string.Empty,
                                                         this);
                        LinkChangeAction action = new LinkChangeAction(WellKnownChangeActionId.Add,
                                                                       dupLink,
                                                                       LinkChangeAction.LinkChangeActionStatus.Created,
                                                                       false);
                        linkChangeGroup.AddChangeAction(action);
                    }
                    else
                    {
                        // [teyang] TODO replace debug assertion with a conflict?
                        Debug.Assert(false, "null == childRecord");
                    }
                }
                else
                {
                    // [teyang] TODO replace debug assertion with a conflict?
                    Debug.Assert(false, "null == aLink");
                }
            }

            linkChangeGroups.Add(linkChangeGroup);
        }