Пример #1
0
        public ClearQuestAttachmentItem(
            OAdEntity aHostRecord,
            OAdAttachmentField aHostField,
            OAdAttachment aAttachment,
            ClearQuestConnectionConfig connectionConfiguration)
        {
            // gather info to query for the record
            EntityDefName  = CQWrapper.GetEntityDefName(aHostRecord);
            EntityDispName = CQWrapper.GetEntityDisplayName(aHostRecord);

            // gather info to query for attachment field
            FieldName = CQWrapper.GetAttachmentFieldName(aHostField);

            string name;
            string comment;
            string dispName;
            int    fileSize;

            CQWrapper.GetAttachmentMetadata(aAttachment,
                                            out name,
                                            out comment,
                                            out dispName,
                                            out fileSize);

            Name                    = name;
            Comment                 = comment;
            DisplayName             = dispName;
            Length                  = (long)fileSize; // fileSize returned by CQ API is in bytes
            ConnectionConfiguration = connectionConfiguration;
        }
Пример #2
0
        public CQRecordStoredQueryQuery(
            Session userSession,
            CQRecordFilter recordFilter,
            string hwmStr,
            IServiceProvider serviceProvider)
            : base(userSession, recordFilter, serviceProvider)
        {
            if (!(recordFilter is CQRecordStoredQueryFilter))
            {
                throw new ArgumentException("recordFilter is not CQRecordStoredQueryFilter");
            }

            m_queryDef = CQWrapper.GetQueryDef(
                CQWrapper.GetWorkSpace(m_userSession), ((CQRecordStoredQueryFilter)m_recordFilter).StoredQueryName);

            string originalQueryString = NormalizeSqlQuery(m_queryDef.SQL);

            if (string.IsNullOrEmpty(hwmStr))
            {
                m_queryStr = originalQueryString;
            }
            else
            {
                m_queryStr = UtilityMethods.Format(QueryBase, originalQueryString, hwmStr);
            }

            Query();
        }
Пример #3
0
        public CQRecordStoredQueryQuery(
            Session userSession,
            CQRecordFilter recordFilter,
            string hwmStr,
            IServiceProvider serviceProvider)
            : base(userSession, recordFilter, serviceProvider)
        {
            if (!(recordFilter is CQRecordStoredQueryFilter))
            {
                throw new ArgumentException("recordFilter is not CQRecordStoredQueryFilter");
            }

            ClearQuestMigrationContext cqContext = serviceProvider.GetService(typeof(ClearQuestMigrationContext)) as ClearQuestMigrationContext;

            m_queryTimeDelimiter = (cqContext == null) ? ClearQuestConstants.CQQueryDefaultTimeDelimiter : cqContext.CQQueryTimeDelimiter;

            m_queryDef = CQWrapper.GetQueryDef(
                CQWrapper.GetWorkSpace(m_userSession), ((CQRecordStoredQueryFilter)m_recordFilter).StoredQueryName);

            string originalQueryString = NormalizeSqlQuery(m_queryDef.SQL);

            if (string.IsNullOrEmpty(hwmStr))
            {
                m_queryStr = originalQueryString;
            }
            else
            {
                m_queryStr = UtilityMethods.Format(QueryBase, originalQueryString, m_queryTimeDelimiter, hwmStr, m_queryTimeDelimiter);
            }

            Query();
        }
Пример #4
0
        /// <summary>
        /// Enumerate the diff items found based on the query passed in as well as the filterString and version passed
        /// to InitializeForDiff.  The return type is IEnumerable<> so that adapter implementations do not need download and keep
        /// all of the IWITDiffItems in memory at once.
        /// </summary>
        /// <param name="queryCondition">A string that specifies a query used to select a subset of the work items defined by
        /// the set that the filter string identified.</param>
        /// <returns>An enumeration of IWITDiffItems each representing a work item to be compared by the WIT Diff operation</returns>
        public IEnumerable <IWITDiffItem> GetWITDiffItems(string queryCondition)
        {
            if (m_getWITDiffItemsDone)
            {
                yield break;
            }

            if (m_cqRecordFilter is CQRecordStoredQueryFilter)
            {
                if (!string.IsNullOrEmpty(queryCondition))
                {
                    throw new NotImplementedException("Query conditions on the ServerDiff operation are not supported with ClearQuest stored queries are used");
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(queryCondition))
                {
                    m_cqRecordFilter = new CQRecordFilter(m_cqRecordFilter.RecordType, m_cqRecordFilter.SelectFromTable, queryCondition);
                }
            }

            CQRecordQueryBase recordQuery = CQRecordQueryFactory.CreateQuery(m_userSession, m_cqRecordFilter, null, this);

            foreach (OAdEntity record in recordQuery)
            {
                if (record != null) // this if check is HACK
                {
                    OAdHistoryFields histFields = CQWrapper.GetHistoryFields(record);
                    int historyFldCount         = CQWrapper.HistoryFieldsCount(histFields);
                    yield return(new CQWITDiffItem(this, record, historyFldCount - 1));
                }
            }
            m_getWITDiffItemsDone = true;
        }
Пример #5
0
        public static string[] FindAllActionNameByTypeAndSourceState(
            OAdEntityDef entityDef,
            string srcState,
            int matchingActionDefType)
        {
            List <string> retVal = new List <string>();

            // find all possible destination state
            object[] allStateObjs = CQWrapper.GetStateDefNames(entityDef) as object[];

            if (null != allStateObjs)
            {
                foreach (object destStateObj in allStateObjs)
                {
                    string destState = destStateObj as string;
                    if (!string.IsNullOrEmpty(destState))
                    {
                        object[] transitions    = CQWrapper.DoesTransitionExist(entityDef, srcState, destState) as object[];
                        string[] actionDefNames = FindActionNameByType(entityDef, transitions, matchingActionDefType);
                        retVal.AddRange(actionDefNames.AsEnumerable());
                    }
                }
            }

            return(retVal.ToArray());
        }
        private void EditRecord(IMigrationAction action, ConversionResult convRslt)
        {
            string ownerRecordDisplayName = FindTargetWorkItemId(action);
            string ownerRecordType        = UtilityMethods.ExtractRecordType(action);
            string changeAuthor           = UtilityMethods.ExtractAuthor(action);

            // find the entity
            OAdEntity entity = CQWrapper.GetEntity(m_userSession, ownerRecordType, ownerRecordDisplayName);

            XmlNodeList columns = action.MigrationActionDescription.SelectNodes("/WorkItemChanges/Columns/Column");

            if (null == columns)
            {
                throw new MigrationException(ClearQuestResource.ClearQuest_Error_InvalidActionDescription, action.ActionId);
            }

            string  stateField            = m_migrationContext.GetStateField(ownerRecordType);
            XmlNode stateTransitFieldNode = UtilityMethods.ExtractSingleFieldNodeFromMigrationDescription(
                action.MigrationActionDescription, stateField);
            bool containsStateTransit = (stateTransitFieldNode != null);

            if (containsStateTransit)
            {
                // change contains state transition
                List <string> skipFields;
                if (ChangeRecordState(entity, action, convRslt, stateTransitFieldNode, out skipFields))
                {
                    ModifyRecordContent(entity, action, convRslt, skipFields);
                }
            }
            else
            {
                ModifyRecordContent(entity, action, convRslt, null);
            }
        }
        protected OAdEntity GetCurrentRecord()
        {
            OAdEntity entity = null;

            do
            {
                try
                {
                    TraceManager.TraceInformation(
                        "DEBUG: GetCurrentRecord dbid : {0}",
                        m_resultSetDbIds[m_currResultSetDbIdIndex]);
                    entity = CQWrapper.GetEntityByDbId(
                        m_userSession, m_recordFilter.RecordType, m_resultSetDbIds[m_currResultSetDbIdIndex]);
                }
                catch (Exception ex)
                {
                    if (m_currResultSetDbIdIndex < m_resultSetDbIds.Length)
                    {
                        TraceManager.TraceInformation(
                            "Failed to get the current record {0}, {1}",
                            m_resultSetDbIds[m_currResultSetDbIdIndex], ex.Message);
                        MoveNext();
                    }
                    else
                    {
                        break;
                    }
                }
            } while (entity == null);

            return(entity);
        }
Пример #8
0
        public static Session GetUserSession(ClearQuestConnectionConfig connConfig)
        {
            string idStr = GenerateSessionIdStr(connConfig);

            lock (s_userSessionLock)
            {
                if (s_userSessions.ContainsKey(idStr))
                {
                    return(s_userSessions[idStr]);
                }

                // create and initialize session object
                Session userSession = CQWrapper.CreateSession();
                TraceManager.TraceInformation("Connecting to CQ User Session");
                CQWrapper.UserLogon(userSession,
                                    connConfig.User,
                                    connConfig.Password,
                                    connConfig.UserDB,
                                    (int)CQConstants.SessionType.PRIVATE,
                                    connConfig.DBSet);
                TraceManager.TraceInformation("Connected to CQ User Session");

                s_userSessions.Add(idStr, userSession);

                return(userSession);
            }
        }
Пример #9
0
        public void UpdateAttachment(int workItemId, WITAttachmentChangeAction action)
        {
            // find the entity
            OAdEntity entity = GetEntityByDBId(workItemId);

            // mark entity to be editable
            CQWrapper.EditEntity(m_session, entity, "Modify");

            foreach (WITAttachment attachment in action.Attachments)
            {
                if (attachment.ActionType == AttachmentChangeActionType.Add)
                {
                    AddAttachment(entity, attachment.FileName, attachment.Comment);
                }
                else if (attachment.ActionType == AttachmentChangeActionType.Delete)
                {
                    throw new NotImplementedException("DeleteAttachment is not supported yet");
                }
                // Update attachment comment
                else if (attachment.ActionType == AttachmentChangeActionType.Edit)
                {
                    throw new NotImplementedException("EditAttachment is not supported yet");
                }
            }

            SaveWorkItem(entity);
        }
        /// <summary>
        /// Download the XML document describing this CQ record
        /// </summary>
        /// <remarks>
        /// EntityDisplayName, EntityDefName and CQSession properties are needed to retrieve record details
        /// </remarks>
        /// <param name="localPath"></param>
        public void Download(string localPath)
        {
            if (null == CQSession)
            {
                throw new InvalidOperationException("CQSession == NULL");
            }

            if (File.Exists(localPath))
            {
                File.Delete(localPath);
            }

            if (IsRecordHistory)
            {
                // download the record history
                OAdEntity   record         = CQWrapper.GetEntity(CQSession, EntityDefName, EntityDispName);
                XmlDocument recordHistDesc = CreateRecordHistoryDesc(record, HistoryValue, HistoryFieldName + "::" + Version, false);
                recordHistDesc.Save(localPath);
            }
            else
            {
                // download the *complete* record content (field + value)
                OAdEntity   record     = CQWrapper.GetEntity(CQSession, EntityDefName, EntityDispName);
                XmlDocument recordDesc = CreateRecordDesc(record, Version, null, false);
                recordDesc.Save(localPath);
            }
        }
        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);
        }
        ReadOnlyCollection <string> GetUserNames(Guid migrationSourceId)
        {
            lock (m_userNamesLock)
            {
                if (m_cqSessions.ContainsKey(migrationSourceId))
                {
                    return(new List <string>().AsReadOnly());
                }

                if (null == m_userNames && null != m_cqSessions[migrationSourceId])
                {
                    m_userNames = new List <string>();

                    object[] userNameObjs = CQWrapper.GetAllUsers(m_cqSessions[migrationSourceId], (int)CQConstants.ExtendedNameOption._NAME_EXTEND_WHEN_NEEDED);

                    foreach (object userNameObj in userNameObjs)
                    {
                        string userName = (string)userNameObj;
                        m_userNames.Add(userName);
                    }
                }

                return(m_userNames.AsReadOnly());
            }
        }
        private void SetRecordEditable(OAdEntity cqEntity)
        {
            string       entityDefName       = CQWrapper.GetEntityDefName(cqEntity);
            OAdEntityDef entityDef           = CQWrapper.GetEntityDef(m_userSession, entityDefName);
            string       modifyActionDefName = FindCQActionDefName(entityDef, CQConstants.ACTION_MODIFY);

            // open the record with the modify action
            CQWrapper.EditEntity(m_userSession, cqEntity, modifyActionDefName);
        }
        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);
        }
        public ClearQuestRecordItem(OAdEntity aRecord, string version)
        {
            Initialize(CQWrapper.GetEntityDefName(aRecord),
                       CQWrapper.GetEntityDisplayName(aRecord),
                       string.Empty,
                       false);

            Version = version;
        }
Пример #16
0
        public ChangeSummary GetSummaryOfChangesSince(string lastProcessedChangeItemId, List <string> filterStrings)
        {
            // lastProcessedChangeItemId is in a form such as "Defect:UCM0100019437:history:0"
            // Parse it and query for the record with that Id to get the time is was last changed
            string[]  identity            = UtilityMethods.ParseCQRecordMigrationItemId(lastProcessedChangeItemId);
            OAdEntity lastProcessedRecord = CQWrapper.GetEntity(m_userSession, identity[0], identity[1]);
            string    lastProcessedRecordAuthor;
            DateTime  lastProcessedRecordChangeDate;

            ClearQuestRecordItem.FindLastRevDtls(lastProcessedRecord, out lastProcessedRecordAuthor, out lastProcessedRecordChangeDate);

            string lastProcessedRecordChangeDateStr = lastProcessedRecordChangeDate.ToString("u").Replace("Z", ""); // using "ISO 8601" DateTime string format

            if (lastProcessedRecordChangeDateStr.LastIndexOf('.') >= 0)
            {
                lastProcessedRecordChangeDateStr = lastProcessedRecordChangeDateStr.Substring(0, lastProcessedRecordChangeDateStr.LastIndexOf('.')); // drop the millisec
            }

            ChangeSummary changeSummary = new ChangeSummary();

            changeSummary.ChangeCount = 0;
            changeSummary.FirstChangeModifiedTimeUtc = DateTime.MinValue;

            foreach (CQRecordFilter filter in m_filters)
            {
                CQRecordQueryBase recordQuery =
                    CQRecordQueryFactory.CreatQuery(m_userSession, filter, lastProcessedRecordChangeDateStr, this);

                foreach (OAdEntity record in recordQuery)
                {
                    // HACK HACK
                    if (record != null) // this if check is HACK
                    {
                        DateTime lastChangeDate;
                        string   lastAuthor;
                        ClearQuestRecordItem.FindLastRevDtls(record, out lastAuthor, out lastChangeDate);

                        // Make sure the lastChangeDate on this record is after the lastProcessedRecordChangeDate before counting it in the backclog
                        // because the query issued above is imprecise because the milliseconds are dropped
                        if (lastChangeDate > lastProcessedRecordChangeDate)
                        {
                            changeSummary.ChangeCount++;
                            DateTime lastChangeDateUtc = lastChangeDate.ToUniversalTime();
                            if (changeSummary.FirstChangeModifiedTimeUtc == DateTime.MinValue ||
                                lastChangeDateUtc < changeSummary.FirstChangeModifiedTimeUtc)
                            {
                                changeSummary.FirstChangeModifiedTimeUtc = lastChangeDateUtc;
                            }
                        }
                    }
                }
            }

            return(changeSummary);
        }
Пример #17
0
        public CQRecordStoredQueryFilter(string storedQueryName, ClearQuestOleServer.Session userSession)
            : base(string.Empty)
        {
            StoredQueryName = storedQueryName;

            if (null != userSession)
            {
                OAdQuerydef qryDef = CQWrapper.GetQueryDef(CQWrapper.GetWorkSpace(userSession), StoredQueryName);
                base.RecordType = CQWrapper.GetPrimaryEntityDefName(qryDef);
            }
        }
Пример #18
0
        private void SaveWorkItem(OAdEntity entity)
        {
            string retVal = CQWrapper.Validate(entity);

            Trace.WriteIf(!string.IsNullOrEmpty(retVal), "retVal = " + retVal);
            Assert.IsTrue(string.IsNullOrEmpty(retVal), "retVal is not empty after validate");

            retVal = CQWrapper.Commmit(entity);
            Trace.WriteIf(!string.IsNullOrEmpty(retVal), "retVal = " + retVal);
            Assert.IsTrue(string.IsNullOrEmpty(retVal), "retVal is not empty after commit");
        }
        internal ChangeGroup CreateChangeGroup(
            ChangeGroupService changeGroupService,
            ClearQuestMigrationContext migrationContext,
            bool isLastRevOfThisSyncCycle)
        {
            ChangeGroup changeGroup = changeGroupService.CreateChangeGroupForDeltaTable(ChangeGroupName);
            OAdEntity   record      = CQWrapper.GetEntity(CQSession, EntityDefName, EntityDispName);

            if (IsRecordHistory)
            {
                XmlDocument recordHistDesc = CreateRecordHistoryDesc(record, HistoryValue, HistoryFieldName + "::" + Version, isLastRevOfThisSyncCycle);

                changeGroup.CreateAction(WellKnownChangeActionId.Edit,
                                         this,
                                         MigrationRecordId,
                                         "",
                                         Version,
                                         "",
                                         WellKnownContentType.WorkItem.ReferenceName,
                                         recordHistDesc);
            }
            else
            {
                XmlDocument recordDesc = CreateRecordDesc(record, Version, migrationContext, isLastRevOfThisSyncCycle);

                if (Version.Equals(NewRecordVersion, StringComparison.InvariantCulture))
                {
                    changeGroup.CreateAction(WellKnownChangeActionId.Add,
                                             this,
                                             MigrationRecordId,
                                             "",
                                             Version,
                                             "",
                                             WellKnownContentType.WorkItem.ReferenceName,
                                             recordDesc);
                }
                else
                {
                    changeGroup.CreateAction(WellKnownChangeActionId.Edit,
                                             this,
                                             MigrationRecordId,
                                             "",
                                             Version,
                                             "",
                                             WellKnownContentType.WorkItem.ReferenceName,
                                             recordDesc);
                }
            }


            return(changeGroup);
        }
        private bool SetMandatoryFields(IMigrationAction action, ref OAdEntity newRecord, out List <string> processedFields)
        {
            XmlNodeList columns = action.MigrationActionDescription.SelectNodes("/WorkItemChanges/Columns/Column");

            if (null == columns)
            {
                throw new MigrationException(ClearQuestResource.ClearQuest_Error_InvalidActionDescription, action.ActionId);
            }

            StringBuilder updateLog = new StringBuilder();

            PrintUpdateLogHeader(action, updateLog);
            processedFields = new List <string>();

            foreach (XmlNode columnData in columns)
            {
                string stringVal = columnData.FirstChild.InnerText;
                string fieldName = columnData.Attributes["ReferenceName"].Value;

                Debug.Assert(!string.IsNullOrEmpty(fieldName),
                             "Field ReferenceName is absent in the Migration Description");


                OAdFieldInfo aFieldInfo        = CQWrapper.GetEntityFieldValue(newRecord, fieldName);
                int          fieldRequiredness = CQWrapper.GetRequiredness(aFieldInfo);
                if (fieldRequiredness != CQConstants.MANDATORY)
                {
                    // skipping all non-mandatory fields
                    continue;
                }

                string originalFieldValue = CQWrapper.GetFieldValue(aFieldInfo);

                int attempt1Count = 0;
                if (!SetFieldValue(action, newRecord, fieldName, stringVal, ref attempt1Count))
                {
                    return(false);
                }
                AddFieldToUpdateLog(fieldName, stringVal, updateLog);
                processedFields.Add(fieldName);
            }

            AddLineToUpdateLog(updateLog);
            int attempt2Count = 0;

            if (!SetFieldValue(action, newRecord, NoteEntryFieldName, updateLog.ToString(), ref attempt2Count))
            {
                return(false);
            }

            return(true);
        }
Пример #21
0
        public void BatchSubmitLinkChange(LinkChangeGroup linkChanges)
        {
            if (linkChanges.Actions.Count == 0)
            {
                linkChanges.Status = LinkChangeGroup.LinkChangeGroupStatus.Completed;
                return;
            }

            // group changes by work item Id
            Dictionary <string, List <LinkChangeAction> > perRecordLinkChanges = RegroupLinkChangeActions(linkChanges);

            WorkItemLinkStore relatedArtifactsStore = new WorkItemLinkStore(m_configurationService.SourceId);

            // batch-submit links of each cq record
            bool successForAllActions = true;

            foreach (var perWorkItemLinkChange in perRecordLinkChanges)
            {
                string[]  identity   = UtilityMethods.ParseCQRecordMigrationItemId(perWorkItemLinkChange.Key);
                OAdEntity hostEntity = CQWrapper.GetEntity(m_userSession, identity[0], identity[1]);

                foreach (LinkChangeAction linkChangeAction in perWorkItemLinkChange.Value)
                {
                    if (linkChangeAction.Status != LinkChangeAction.LinkChangeActionStatus.ReadyForMigration ||
                        linkChangeAction.IsConflicted)
                    {
                        continue;
                    }

                    var handler = linkChangeAction.Link.LinkType as ILinkHandler;
                    Debug.Assert(null != handler, "linktype is not an ILinkHandler");
                    if (!handler.Update(m_migrationContext, m_userSession, hostEntity, linkChangeAction))
                    {
                        successForAllActions = false;
                        // [teyang] todo conflict handling
                        linkChangeAction.Status       = LinkChangeAction.LinkChangeActionStatus.Completed;
                        linkChangeAction.IsConflicted = true;
                        TraceManager.TraceError("Failed processing link change action: {0} linked to {1}",
                                                linkChangeAction.Link.SourceArtifact.Uri,
                                                linkChangeAction.Link.TargetArtifact.Uri);
                    }
                    else
                    {
                        MarkLinkChangeActionCompleted(linkChangeAction, relatedArtifactsStore);
                    }
                }
            }

            linkChanges.Status = successForAllActions
                                 ? LinkChangeGroup.LinkChangeGroupStatus.Completed
                                 : LinkChangeGroup.LinkChangeGroupStatus.ReadyForMigration;
        }
Пример #22
0
        private void SetFieldValue(OAdEntity entity, string fieldName, string fieldValue)
        {
            if (string.IsNullOrEmpty(fieldValue))
            {
                return;
            }

            string retVal = CQWrapper.SetFieldValue(entity, fieldName, fieldValue);

            Trace.WriteIf(!string.IsNullOrEmpty(retVal), "retVal = " + retVal);
            Assert.IsTrue(string.IsNullOrEmpty(retVal),
                          string.Format("SetFiledValue returned non-empty result : {0}, {1}", fieldName, fieldValue));
        }
        public ClearQuestRecordItem(
            OAdEntity aRecord,
            OAdHistory aHistory,
            string historyFieldName,
            string historyIndex)
        {
            Initialize(CQWrapper.GetEntityDefName(aRecord),
                       CQWrapper.GetEntityDisplayName(aRecord),
                       CQWrapper.HistoryValue(aHistory),
                       true);

            Version          = historyIndex;
            HistoryFieldName = historyFieldName;
        }
Пример #24
0
        private void AddAttachment(OAdEntity entity, string filePath, string comment)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            string path   = CreateAttachment(filePath);
            string retVal = CQWrapper.AddAttachmentFieldValue(entity, "Attachments", path, comment);

            Trace.WriteIf(!string.IsNullOrEmpty(retVal), "retVal = " + retVal);
            Assert.IsTrue(string.IsNullOrEmpty(retVal),
                          string.Format("AddAttachmentFieldValue returned non-empty result : {0}, {1}", filePath, comment));
        }
Пример #25
0
        public static string[] FindAllChangeActionNamesByType(
            Session userSession,
            OAdEntity entity,
            int changeType)
        {
            // find the entity type
            OAdEntityDef entityDef = CQWrapper.GetEntityDef(userSession, CQWrapper.GetEntityDefName(entity));

            // find the MODIFY action def name to open the record
            object[] actionDefNames      = CQWrapper.GetActionDefNames(entityDef) as object[];
            string[] allValidActionNames = CQUtilityMethods.FindActionNameByType(entityDef, actionDefNames, changeType);

            return(allValidActionNames);
        }
        protected virtual void Query()
        {
            TraceManager.TraceInformation("CQ Query: {0}", m_queryStr);

            // prepare result set
            OAdResultset result = CQWrapper.BuildResultSet(m_userSession, m_queryStr);

            // enable record count before execute so that no of records can be fetched
            CQWrapper.EnableRecordCount(result);

            // execute the query
            CQWrapper.ExecuteResultSet(result);

            // lookup for dbid column
            bool dbidExist       = false;
            int  dbidColumnIndex = 0;
            int  columnCount     = CQWrapper.GetResultSetColumnCount(result);

            for (int colIter = 1; colIter <= columnCount; colIter++)
            {
                if (string.Equals(CQWrapper.GetColumnLabel(result, colIter), "dbid", StringComparison.OrdinalIgnoreCase))
                {
                    dbidExist       = true;
                    dbidColumnIndex = colIter;
                    break;
                }
            }
            Debug.Assert(dbidExist, "dbid does not exist in resultset");

            int recordCount = CQWrapper.GetRecordCount(result);

            TraceManager.TraceInformation("CQ Query: returned {0} record(s)", recordCount);

            // cache dbids
            m_resultSetDbIds = new int[recordCount];
            int index = 0;

            while (CQWrapper.ResultSetMoveNext(result) == CQConstants.SUCCESS)
            {
                string dbid = (string)CQWrapper.GetColumnValue(result, dbidColumnIndex);
                m_resultSetDbIds[index++] = int.Parse(dbid);

                Trace.TraceInformation("DEBUG: dbid : {0}", int.Parse(dbid));
            }

            MakeSureDBIDsAreUnique();

            Trace.TraceInformation("Total number of records after removing the duplicate dbids: {0}", m_resultSetDbIds.Length);
        }
        private OAdEntity CreateTestEntity(OAdEntity record, ClearQuestMigrationContext migrationContext)
        {
            string entityName = CQWrapper.GetEntityDefName(record);

            if (m_perEntityTypeTestEntities.ContainsKey(entityName))
            {
                return(m_perEntityTypeTestEntities[entityName]);
            }

            var aTestEntity = CQWrapper.BuildEntity(migrationContext.UserSession, entityName);

            m_perEntityTypeTestEntities.Add(entityName, aTestEntity);

            return(aTestEntity);
        }
Пример #28
0
        public List <ILink> GetLinks(
            IArtifact sourceArtifact,
            LinkType linkType)
        {
            string id;
            bool   idExtractionRslt = TryExtractArtifactId(sourceArtifact, out id);

            Debug.Assert(idExtractionRslt);

            string[]  identity   = UtilityMethods.ParseCQRecordMigrationItemId(id);
            OAdEntity hostEntity = CQWrapper.GetEntity(m_userSession, identity[0], identity[1]);

            var links = new List <ILink>();

            if (null == ExtractLinkChangeActionsCallback)
            {
                return(links);
            }

            var perWorkItemlinkChangeGroups = new List <LinkChangeGroup>();

            ExtractLinkChangeActionsCallback(m_userSession, hostEntity, perWorkItemlinkChangeGroups);

            foreach (LinkChangeGroup group in perWorkItemlinkChangeGroups)
            {
                foreach (LinkChangeAction action in group.Actions)
                {
                    if (!CQStringComparer.LinkType.Equals(action.Link.LinkType.ReferenceName, linkType.ReferenceName))
                    {
                        continue;
                    }

                    string mappedLinkType = m_linkConfigLookupService.FindMappedLinkType(m_configurationService.SourceId, action.Link.LinkType.ReferenceName);
                    if (!m_linkTranslationService.LinkTypeSupportedByOtherSide(mappedLinkType))
                    {
                        continue;
                    }

                    if (!links.Contains(action.Link))
                    {
                        links.Add(action.Link);
                    }
                }
            }

            return(links);
        }
        private void BuildRecordHistoryCountCache(
            OAdEntity aRecord,
            Dictionary <string, int> recordHistoryCountCache)
        {
            OAdHistoryFields aHistFields = CQWrapper.GetHistoryFields(aRecord);
            int historyFldCount          = CQWrapper.HistoryFieldsCount(aHistFields);

            for (int histFldIndex = 0; histFldIndex < historyFldCount; histFldIndex++)
            {
                object          ob               = (object)histFldIndex;
                OAdHistoryField aHistoryField    = CQWrapper.HistoryFieldsItem(aHistFields, ref ob);
                string          historyFieldName = CQWrapper.GetHistoryFieldName(aHistoryField);

                int historyCount = CQWrapper.HistoryFieldHistoriesCount(aHistoryField);
                recordHistoryCountCache.Add(historyFieldName, historyCount);
            }
        }
        public void ExtractLinkChangeActions(ClearQuestOleServer.Session session, ClearQuestOleServer.OAdEntity hostRecord, List <LinkChangeGroup> linkChangeGroups)
        {
            string recordId = CQWrapper.GetFieldValue(CQWrapper.GetEntityFieldValue(hostRecord, CQIdFieldName));
            string url      = string.Format(m_urlFormat, recordId);

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

            string hostEntityDefName  = CQWrapper.GetEntityDefName(hostRecord);
            string hostEntityDispName = CQWrapper.GetEntityDisplayName(hostRecord);
            string hostRecordId       = UtilityMethods.CreateCQRecordMigrationItemId(hostEntityDefName, hostEntityDispName);

            ArtifactLink     link   = new ArtifactLink(hostRecordId, new Artifact(hostRecordId, s_sourceArtifactType), new Artifact(url, s_targetArtifactType), string.Empty, this);
            LinkChangeAction action = new LinkChangeAction(WellKnownChangeActionId.Add, link, LinkChangeAction.LinkChangeActionStatus.Created, false);

            linkChangeGroup.AddChangeAction(action);
            linkChangeGroups.Add(linkChangeGroup);
        }