示例#1
0
        /// <summary>
        /// This mehtod returns a list of entity definition names that are referenced (to any level)
        /// with the baseEntityDef.
        /// </summary>
        /// <param name="cqSession">A valid Clear Quest Session object</param>
        /// <param name="baseEntityDefName">
        /// Entity Definition name to start with.
        /// This entity has to be a submit type entity
        /// </param>
        /// <returns>
        /// List of (non system) entity definition names that are connected (referenced) with the
        /// entity name passed as parameter. Also includes the starting entity definition name.
        /// </returns>
        public static string[] GetReferencedEntityDefNames(Session cqSession, string baseEntityDefName, string configFile)
        {
            Logger.EnteredMethod(LogSource.CQ, cqSession, baseEntityDefName);

            // fetch the submit type entities from CQ DB
            object[] allSubmitEntities = (object[])CQWrapper.GetSubmitEntityDefNames(cqSession);

            List <string> allSubmitEntitiesList = new List <string>();

            foreach (object obEntity in allSubmitEntities)
            {
                allSubmitEntitiesList.Add((string)obEntity);
            }

            // ensure that the passed entity is part of Submit Entity Types
            if (!allSubmitEntitiesList.Contains(baseEntityDefName))
            {
                // log the problem
                string errMsg = UtilityMethods.Format(CQResource.CQ_NOT_SUBMIT_ENTITY,
                                                      CurConResource.Analysis);
                Logger.Write(LogSource.CQ, TraceLevel.Error, errMsg);
                Microsoft.TeamFoundation.Converters.WorkItemTracking.Common.ConverterMain.MigrationReport.WriteIssue(String.Empty,
                                                                                                                     errMsg, string.Empty /* no item */, null, IssueGroup.Witd.ToString(), ReportIssueType.Critical);

                throw new ConverterException(errMsg);
            }

            // create a list for storing all entities name
            List <string> refEntities = new List <string>();

            // add the base entity name to start with
            refEntities.Add(baseEntityDefName);

            int noOfEntitesDone = 0;

            while (noOfEntitesDone < refEntities.Count)
            {
                OAdEntityDef cqEntityDef = CQWrapper.GetEntityDef(cqSession, refEntities[noOfEntitesDone]);

                // we processed one entity
                noOfEntitesDone++;

                // process all the fields and find out the names for other entities
                object[] cqFields = (object[])cqEntityDef.GetFieldDefNames();
                if (cqFields.Length > 0)
                {
                    foreach (object ob in cqFields)
                    {
                        string cqFldName = ob as String;
                        Debug.Assert(cqFldName != null);
                        // get field type
                        int  fieldType = CQWrapper.GetFieldDefType(cqEntityDef, cqFldName);
                        bool isSystem  = cqEntityDef.IsSystemOwnedFieldDefName(cqFldName);

                        // count the field only if it is not internal to CQ and is a reference field
                        if ((fieldType == CQConstants.FIELD_REFERENCE || fieldType == CQConstants.FIELD_REFERENCE_LIST) &&
                            isSystem == false)
                        {
                            // add the referenced entity in the list (if it is not already there)
                            OAdEntityDef refEntity = CQWrapper.GetFieldReferenceEntityDef(cqEntityDef, cqFldName);

                            // the scanned entities should also be ther submit type entities only
                            if ((allSubmitEntitiesList.Contains(refEntity.GetName())) == true &&
                                refEntities.Contains(refEntity.GetName()) == false)
                            {
                                refEntities.Add(refEntity.GetName());
                            }
                        }
                    }   //foreach (object ob in cqFields)
                } //if (cqFields.Length > 0)
            } //while (noOfEntitesDone != refEntities.Count)

            Logger.ExitingMethod(LogSource.CQ);
            return(refEntities.ToArray());
        }
示例#2
0
        } // end of FindAllowedEntitiesToMigrate

        /// <summary>
        /// Validate all the Entity Types on Clear Quest
        /// Followed by the respective Field Mappings
        /// </summary>
        /// <returns>true if successful, false in case of some error</returns>
        private void ValidateSchemaMapOnCQ()
        {
            Session cqSession = m_cqConnection.GetUserSession();

            object[] cqEntities = (object[])CQWrapper.GetSubmitEntityDefNames(cqSession);
            Display.NewLine();

            foreach (SchemaMapping schMap in m_convParams.SchemaMaps)
            {
                string infoMsg = UtilityMethods.Format(CQResource.SchemaValidation, schMap.WITDFile);
                Logger.Write(LogSource.CQ, TraceLevel.Verbose, infoMsg);

                bool entityFoundInCQ = false;
                foreach (object obj in cqEntities)
                {
                    if (schMap.entity.Equals(obj.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        entityFoundInCQ = true;
                        break;
                    }
                }

                if (!entityFoundInCQ)
                {
                    try
                    {
                        Display.StartProgressDisplay(infoMsg);
                        string errMsg = UtilityMethods.Format(CQResource.CQ_ENTITY_NOT_EXIST,
                                                              CurConResource.Analysis,
                                                              schMap.entity,
                                                              Path.GetFileName(m_convParams.SchemaMapFile));

                        PostMigrationReport.WriteIssue(null, null, RepStatus.Failed,
                                                       ReportIssueType.Critical, String.Empty,
                                                       schMap.entity, IssueGroup.Witd, errMsg);

                        throw new ConverterException(errMsg);
                    }
                    finally
                    {
                        Display.StopProgressDisplay();
                    }
                }
                else
                {
                    OAdEntityDef currEntityDef = CQWrapper.GetEntityDef(cqSession, schMap.entity);
                    // can validate the fields at CQ also, for this entity
                    string fieldMapFile = schMap.fieldMapFile;
                    if (fieldMapFile != null)
                    {
                        UtilityMethods.ValidateFile(fieldMapFile, schMap.schemaMapFile);
                        FieldMaps fldMaps = WITFieldMappings.CreateFromFile(fieldMapFile);
                        ValidateFieldMapOnCQ(currEntityDef, fldMaps.FieldMap, fieldMapFile);

                        // add the predefined/internal field maps
                        FieldMapsFieldMap[] internalFldMaps = GetInternalFieldMaps(fldMaps);

                        fldMaps.FieldMap.CopyTo(internalFldMaps, 0);
                        fldMaps.FieldMap = internalFldMaps;

                        // add the loaded field map in Schema Field Map for future use
                        m_schemaFieldMap.Add(schMap.entity, fldMaps);
                    }
                }
            } // end of foreach SchemaMappings
        }     // end of ValidateSchemaMapOnCQ