protected override void SetUp() { base.SetUp(); _c = new Catalogue(CatalogueRepository, "AggregateBuilderTests"); _cataItem1 = new CatalogueItem(CatalogueRepository, _c, "Col1"); _cataItem2 = new CatalogueItem(CatalogueRepository, _c, "Col2"); _ti = new TableInfo(CatalogueRepository, "T1"); _columnInfo1 = new ColumnInfo(CatalogueRepository, "Col1", "varchar(100)", _ti); _columnInfo2 = new ColumnInfo(CatalogueRepository, "Col2", "date", _ti); _ei1 = new ExtractionInformation(CatalogueRepository, _cataItem1, _columnInfo1, _columnInfo1.Name); _ei2 = new ExtractionInformation(CatalogueRepository, _cataItem2, _columnInfo2, _columnInfo2.Name); _configuration = new AggregateConfiguration(CatalogueRepository, _c, "MyConfig"); _dimension1 = new AggregateDimension(CatalogueRepository, _ei1, _configuration); _dimension2 = new AggregateDimension(CatalogueRepository, _ei2, _configuration); _dimension1.Order = 1; _dimension1.SaveToDatabase(); _dimension2.Order = 2; _dimension2.SaveToDatabase(); }
private void EnsurePivotHasAlias(AggregateDimension dimension) { if (string.IsNullOrWhiteSpace(dimension.Alias)) { dimension.Alias = dimension.GetRuntimeName(); dimension.SaveToDatabase(); } }
/// <summary> /// Defines a PIVOT on the values in a given column. This is only valid for <see cref="AggregateConfiguration"/> which are graphs /// <see cref="AggregateBuilderBasicOptions"/> which must also have an axis configured /// </summary> /// <param name="pivot"></param> public void SetPivotToDimensionID(AggregateDimension pivot) { //ensure it has an alias if (string.IsNullOrWhiteSpace(pivot.Alias)) { pivot.Alias = "MyPivot"; pivot.SaveToDatabase(); } _pivotID = pivot.ID; }
public override void Execute() { base.Execute(); var opts = new AggregateBuilderOptionsFactory().Create(aggregate); ExtractionInformation match = null; var possible = opts.GetAvailableSELECTColumns(aggregate).OfType <ExtractionInformation>().ToArray(); if (askAtRuntime) { if (!possible.Any()) { throw new Exception($"There are no ExtractionInformation that can be added as new dimensions to {aggregate}"); } match = (ExtractionInformation)BasicActivator.SelectOne("Choose dimension to add", possible); if (match == null) { return; } } else { match = possible.FirstOrDefault(a => string.Equals(column, a.ToString())); if (match == null) { throw new Exception($"Could not find ExtractionInformation {column} in as an addable column to {aggregate}"); } } var dim = new AggregateDimension(BasicActivator.RepositoryLocator.CatalogueRepository, match, aggregate); dim.SaveToDatabase(); Publish(aggregate); }
private AggregateConfiguration CreateCloneOfAggregateConfigurationPrivate(AggregateConfiguration toClone, ChooseWhichExtractionIdentifierToUseFromManyHandler resolveMultipleExtractionIdentifiers) { var cataRepo = CatalogueRepository; //two cases here either the import has a custom freaky CHI column (dimension) or it doesn't reference CHI at all if it is freaky we want to preserve it's freakyness ExtractionInformation underlyingExtractionInformation; IColumn extractionIdentifier = GetExtractionIdentifierFrom(toClone, out underlyingExtractionInformation, resolveMultipleExtractionIdentifiers); //clone will not have axis or pivot or dimensions other than extraction identifier var newConfiguration = toClone.ShallowClone(); //make it's name follow the naming convention e.g. cic_105_LINK103_MyAggregate EnsureNamingConvention(newConfiguration); //now clear it's pivot dimension, make it not extratcable and make it's countSQL basic/sane newConfiguration.PivotOnDimensionID = null; newConfiguration.IsExtractable = false; newConfiguration.CountSQL = null;//clear the count sql //clone parameters foreach (AnyTableSqlParameter toCloneParameter in toClone.Parameters) { var newParam = new AnyTableSqlParameter((ICatalogueRepository)newConfiguration.Repository, newConfiguration, toCloneParameter.ParameterSQL); newParam.Value = toCloneParameter.Value; newParam.Comment = toCloneParameter.Comment; newParam.SaveToDatabase(); } //now clone it's AggregateForcedJoins foreach (var t in cataRepo.AggregateForcedJoinManager.GetAllForcedJoinsFor(toClone)) { cataRepo.AggregateForcedJoinManager.CreateLinkBetween(newConfiguration, t); } //now give it 1 dimension which is the only IsExtractionIdentifier column var newDimension = new AggregateDimension(cataRepo, underlyingExtractionInformation, newConfiguration); //the thing we were cloning had a freaky CHI column (probably had a collate or something involved in it or a masterchi) if (extractionIdentifier is AggregateDimension) { //preserve it's freakyness newDimension.Alias = extractionIdentifier.Alias; newDimension.SelectSQL = extractionIdentifier.SelectSQL; newDimension.Order = extractionIdentifier.Order; newDimension.SaveToDatabase(); } //now rewire all it's filters if (toClone.RootFilterContainer_ID != null) //if it has any filters { //get the tree AggregateFilterContainer oldRootContainer = toClone.RootFilterContainer; //clone the tree var newRootContainer = oldRootContainer.DeepCloneEntireTreeRecursivelyIncludingFilters(); newConfiguration.RootFilterContainer_ID = newRootContainer.ID; } newConfiguration.SaveToDatabase(); return(newConfiguration); }