private void FindAllowedEntitiesToMigrate(string baseEntityName, Session cqSession) { string[] refEntities = CQConverterUtil.GetReferencedEntityDefNames (cqSession, baseEntityName, m_convParams.ConfigFile); // check against the entity defs provided in schema map xml m_cqParams.allowedEntities = new Dictionary <string, bool>(TFStringComparer.OrdinalIgnoreCase); foreach (SchemaMapping map in m_cqParams.schemaMaps) { m_cqParams.allowedEntities.Add(map.entity, false); } bool baseEntityFound = false; foreach (string entity in m_cqParams.allowedEntities.Keys) { if (baseEntityName.Equals(entity, StringComparison.OrdinalIgnoreCase)) { baseEntityFound = true; break; } } if (!baseEntityFound) { // base entity has to be migrated string errMsg = UtilityMethods.Format(CQResource.CQ_BASE_ENTITY_REQ, CurConResource.Analysis, baseEntityName, Path.GetFileName(m_convParams.SchemaMapFile)); PostMigrationReport.WriteIssue(null, null, RepStatus.Failed, ReportIssueType.Critical, String.Empty, baseEntityName, IssueGroup.Witd, errMsg); Logger.Write(LogSource.CQ, TraceLevel.Error, errMsg); throw new ConverterException(errMsg); } // for entries other than base entity // generate warning if not being selected for migration foreach (string entity in refEntities) { if (!m_cqParams.allowedEntities.ContainsKey(entity)) { string warningMsg = UtilityMethods.Format(CQResource.CQ_DROP_ENTITY, entity, m_convParams.SchemaMapFile); Logger.Write(LogSource.CQ, TraceLevel.Warning, warningMsg); PostMigrationReport.WriteIssue(null, null, RepStatus.Warning, ReportIssueType.Warning, String.Empty, entity, IssueGroup.Witd, warningMsg); m_cqParams.allowedEntities.Remove(entity); } } // remove the entries from allowed entities which // are not referened (dir/indir) from base entity // foreach (string // set the allowed entities in allowedEntities object } // end of FindAllowedEntitiesToMigrate
} // end of Initialize /// <summary> /// Starts the actual schema migration followed by data migration /// </summary> public void Convert() { Session cqSession = m_cqConnection.GetUserSession(); OAdQuerydef qryDef = m_cqConnection.QueryDefinition; // get the base entity definition to analyze string baseEntityDefName = CQWrapper.GetPrimaryEntityDefName(qryDef); Debug.Assert(baseEntityDefName != null); Logger.WritePerf(LogSource.CQ, "Start Analyze"); // set o/p directory only if it is not specified in the CQConfig file.. // otherwise its already set / created in Initialize section if (String.IsNullOrEmpty(m_convParams.OutputDirectory)) { CQConverterUtil.SetOutputDirectory(baseEntityDefName, m_convParams.ConfigFile); } if (baseEntityDefName != null) { string[] refEntities = CQConverterUtil.GetReferencedEntityDefNames(cqSession, baseEntityDefName, m_convParams.ConfigFile); StringBuilder infoMsg1 = new StringBuilder(UtilityMethods.Format(CQResource.CQ_ENTITY_MIGRATED)); foreach (string str in refEntities) { infoMsg1.Append(str); infoMsg1.Append(", "); // REVIEW - GautamG: String not localized } infoMsg1.Remove(infoMsg1.Length - 2, 1); // remove last comma infoMsg1.Append(Environment.NewLine); Logger.Write(LogSource.CQ, TraceLevel.Info, infoMsg1.ToString()); Display.DisplayMessage(infoMsg1.ToString()); // create the schema map file so that for each WITD xml generation // the entries are added in schema map WITSchemaMappings schemaMap = new WITSchemaMappings(); int reportEntityIndex = 0; ConverterMain.MigrationReport.Summary.SourceAndDestination.WorkItemTypes.WorkItemTypeTypes = new WorkItemTypeTypes[refEntities.Length]; foreach (string entityToMigrate in refEntities) { if (entityToMigrate != null) { // process the given entity definition and generate xml for each entity // one for the base entity and one for each of referenced entities OAdEntityDef entityDef = CQWrapper.GetEntityDef(cqSession, entityToMigrate); string entityDefName = entityDef.GetName(); string schemaXmlFile = entityDefName + ".xml"; // get the file name prepended with the path.. to be generated under base entity name folder schemaXmlFile = CQConverterUtil.GetFileNameWithPath(schemaXmlFile); string fieldMapXmlFile = entityDefName + CQConstants.FieldMapFileSuffix; fieldMapXmlFile = CQConverterUtil.GetFileNameWithPath(fieldMapXmlFile); // add the default map to schema schemaMap.Mappings.AddSchemaMap(entityDefName, entityDefName, schemaXmlFile, fieldMapXmlFile); ConverterMain.MigrationReport.AddOutput(CQResource.Witd, schemaXmlFile); ConverterMain.MigrationReport.AddOutput(CQResource.WitFieldMap, fieldMapXmlFile); WITDXMLGenerator currEntityXML = new WITDXMLGenerator(schemaXmlFile, fieldMapXmlFile, cqSession, entityDef, m_vstsConn); currEntityXML.GenerateSchemaXml(); // add the entity information in migration report WorkItemTypeTypes wiType = new WorkItemTypeTypes(); wiType.From = wiType.To = entityDefName; ConverterMain.MigrationReport.Summary.SourceAndDestination.WorkItemTypes.WorkItemTypeTypes[reportEntityIndex++] = wiType; // add the link type mappings MapLinkTypes(refEntities, entityToMigrate, entityDef); } } // foreach (string entityToMigrate in refEntities) Display.NewLine(); // generated the schemas and the corresponding field maps // finally serialize the schema map file string schemaMapFile = CQConverterUtil.GetFileNameWithPath(CQConstants.SchemaMapFile); string userMapFile = CQConverterUtil.GetFileNameWithPath(CQConstants.UserMapFile); ConverterMain.MigrationReport.AddOutput(CQResource.SchemaMap, schemaMapFile); ConverterMain.MigrationReport.AddOutput(CQResource.UserMap, userMapFile); schemaMap.GenerateSchemaMappings(schemaMapFile, userMapFile); GenerateDefaultUserMaps(userMapFile); ConverterMain.MigrationReport.Statistics.NumberOfItems = refEntities.Length; // generate the link type mapping file GenerateLinkTypeMappings(); } Logger.WritePerf(LogSource.CQ, "End Analyze"); } // end of Convert()