Exemplo n.º 1
0
        /// <summary>
        /// Creates a deep copy of the current container, all filters and subcontainers (recursively).  These objects will all have new IDs and be new objects
        /// in the repository database.
        /// </summary>
        /// <returns></returns>
        public FilterContainer DeepCloneEntireTreeRecursivelyIncludingFilters()
        {
            //clone ourselves
            var clonedFilterContainer = this.ShallowClone();

            //clone our filters
            foreach (var deployedExtractionFilter in GetFilters())
            {
                //clone it
                var cloneFilter = ((DeployedExtractionFilter)deployedExtractionFilter).ShallowClone(clonedFilterContainer);

                //clone parameters
                foreach (DeployedExtractionFilterParameter parameter in deployedExtractionFilter.GetAllParameters())
                {
                    parameter.ShallowClone(cloneFilter);
                }

                //change the clone to belonging to the cloned container (instead of this - the original container)
                cloneFilter.FilterContainer_ID = clonedFilterContainer.ID;
                cloneFilter.SaveToDatabase();
            }

            //now clone all subcontainers
            foreach (FilterContainer toCloneSubcontainer in this.GetSubContainers())
            {
                //clone the subcontainer recursively
                FilterContainer clonedSubcontainer = toCloneSubcontainer.DeepCloneEntireTreeRecursivelyIncludingFilters();

                //get the returned filter subcontainer and assocaite it with the cloned version of this
                clonedFilterContainer.AddChild(clonedSubcontainer);
            }

            //return the cloned version
            return(clonedFilterContainer);
        }
Exemplo n.º 2
0
        private FilterContainer ShallowClone()
        {
            var clone = new FilterContainer(DataExportRepository, Operation);

            CopyShallowValuesTo(clone);
            return(clone);
        }
Exemplo n.º 3
0
        public DeployedExtractionFilter ShallowClone(FilterContainer into)
        {
            var clone = new DeployedExtractionFilter(DataExportRepository, Name, into);

            CopyShallowValuesTo(clone);
            return(clone);
        }
Exemplo n.º 4
0
 public void CreateRootContainerIfNotExists()
 {
     if (RootFilterContainer_ID == null)
     {
         var container = new FilterContainer(DataExportRepository, FilterContainerOperation.AND);
         RootFilterContainer_ID = container.ID;
         SaveToDatabase();
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Makes the provided <paramref name="extractableDataSet"/> extractable in the current <see cref="IExtractionConfiguration"/>.  This
        /// includes selecting it (<see cref="ISelectedDataSets"/>) and replicating any mandatory filters.
        /// </summary>
        /// <param name="extractableDataSet"></param>
        public void AddDatasetToConfiguration(IExtractableDataSet extractableDataSet)
        {
            //it is already part of the configuration
            if (SelectedDataSets.Any(s => s.ExtractableDataSet_ID == extractableDataSet.ID))
            {
                return;
            }

            var dataExportRepo = (IDataExportRepository)Repository;

            var selectedDataSet = new SelectedDataSets(dataExportRepo, this, extractableDataSet, null);

            ExtractionFilter[] mandatoryExtractionFiltersToApplyToDataset = extractableDataSet.Catalogue.GetAllMandatoryFilters();

            //add mandatory filters
            if (mandatoryExtractionFiltersToApplyToDataset.Any())
            {
                //first we need a root container e.g. an AND container
                //add the AND container and set it as the root container for the dataset configuration
                FilterContainer rootFilterContainer = new FilterContainer(dataExportRepo);
                rootFilterContainer.Operation = FilterContainerOperation.AND;
                rootFilterContainer.SaveToDatabase();

                selectedDataSet.RootFilterContainer_ID = rootFilterContainer.ID;
                selectedDataSet.SaveToDatabase();

                var globals  = GlobalExtractionFilterParameters;
                var importer = new FilterImporter(new DeployedExtractionFilterFactory(dataExportRepo), globals);

                var mandatoryFilters = importer.ImportAllFilters(mandatoryExtractionFiltersToApplyToDataset, null);

                foreach (DeployedExtractionFilter filter in mandatoryFilters.Cast <DeployedExtractionFilter>())
                {
                    filter.FilterContainer_ID = rootFilterContainer.ID;
                    filter.SaveToDatabase();
                }
            }

            var legacyColumns = GetAllExtractableColumnsFor(extractableDataSet).Cast <ExtractableColumn>().ToArray();

            //add Core or ProjectSpecific columns
            foreach (var all in extractableDataSet.Catalogue.GetAllExtractionInformation(ExtractionCategory.Any))
            {
                if (all.ExtractionCategory == ExtractionCategory.Core || all.ExtractionCategory == ExtractionCategory.ProjectSpecific)
                {
                    if (legacyColumns.All(l => l.CatalogueExtractionInformation_ID != all.ID))
                    {
                        AddColumnToExtraction(extractableDataSet, all);
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Declares in the <paramref name="repository"/> database that the given <paramref name="dataSet"/> should be extracted as part of the given <paramref name="configuration"/>.
        /// </summary>
        /// <param name="repository"></param>
        /// <param name="configuration"></param>
        /// <param name="dataSet"></param>
        /// <param name="rootContainerIfAny">Adds the restriction that the extraction SQL should include the WHERE logic in this container</param>
        public SelectedDataSets(IDataExportRepository repository, ExtractionConfiguration configuration, IExtractableDataSet dataSet, FilterContainer rootContainerIfAny)
        {
            repository.InsertAndHydrate(this, new Dictionary <string, object>()
            {
                { "ExtractionConfiguration_ID", configuration.ID },
                { "ExtractableDataSet_ID", dataSet.ID },
                { "RootFilterContainer_ID", rootContainerIfAny != null?(object)rootContainerIfAny.ID:DBNull.Value }
            });

            ClearAllInjections();
            InjectKnown(dataSet);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a complete copy of the <see cref="IExtractionConfiguration"/>, all selected datasets, filters etc.  The copy is created directly into
        /// the <see cref="DatabaseEntity.Repository"/> database using a transaction (to prevent a half succesful clone being generated).
        /// </summary>
        /// <returns></returns>
        public ExtractionConfiguration DeepCloneWithNewIDs()
        {
            var repo = (DataExportRepository)Repository;

            using (repo.BeginNewTransactedConnection())
            {
                try
                {
                    //clone the root object (the configuration) - this includes cloning the link to the correct project and cohort
                    ExtractionConfiguration clone = this.ShallowClone();

                    //find each of the selected datasets for ourselves and clone those too
                    foreach (SelectedDataSets selected in SelectedDataSets)
                    {
                        //clone the link meaning that the dataset is now selected for the clone configuration too
                        var newSelectedDataSet = new SelectedDataSets(repo, clone, selected.ExtractableDataSet, null);

                        // now clone each of the columns for each of the datasets that we just created links to (make them the same as the old configuration
                        foreach (IColumn extractableColumn in GetAllExtractableColumnsFor(selected.ExtractableDataSet))
                        {
                            ExtractableColumn cloneExtractableColumn = ((ExtractableColumn)extractableColumn).ShallowClone();
                            cloneExtractableColumn.ExtractionConfiguration_ID = clone.ID;
                            cloneExtractableColumn.SaveToDatabase();
                        }

                        //clone should copy accross the forced joins (if any)
                        foreach (SelectedDataSetsForcedJoin oldForcedJoin in Repository.GetAllObjectsWithParent <SelectedDataSetsForcedJoin>(selected))
                        {
                            new SelectedDataSetsForcedJoin((IDataExportRepository)Repository, newSelectedDataSet, oldForcedJoin.TableInfo);
                        }


                        try
                        {
                            //clone the root filter container
                            var rootContainer = (FilterContainer)GetFilterContainerFor(selected.ExtractableDataSet);

                            //turns out there wasn't one to clone at all
                            if (rootContainer == null)
                            {
                                continue;
                            }

                            //there was one to clone so clone it recursively (all subcontainers) including filters then set the root filter to the new clone
                            FilterContainer cloneRootContainer = rootContainer.DeepCloneEntireTreeRecursivelyIncludingFilters();
                            newSelectedDataSet.RootFilterContainer_ID = cloneRootContainer.ID;
                            newSelectedDataSet.SaveToDatabase();
                        }
                        catch (Exception e)
                        {
                            clone.DeleteInDatabase();
                            throw new Exception("Problem occurred during cloning filters, problem was " + e.Message + " deleted the clone configuration successfully", e);
                        }
                    }

                    clone.dtCreated     = DateTime.Now;
                    clone.IsReleased    = false;
                    clone.Username      = Environment.UserName;
                    clone.Description   = "TO" + "DO:Populate change log here";
                    clone.ReleaseTicket = null;

                    //wire up some changes
                    clone.ClonedFrom_ID = this.ID;
                    clone.SaveToDatabase();

                    repo.EndTransactedConnection(true);

                    return(clone);
                }
                catch (Exception)
                {
                    repo.EndTransactedConnection(false);
                    throw;
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a new empty WHERE filter in the given <paramref name="container"/> that will be used when
 /// extracting the dataset.
 ///
 /// <para>This object is created into the data export metadata database</para>
 /// </summary>
 /// <param name="repository"></param>
 /// <param name="name"></param>
 /// <param name="container"></param>
 public DeployedExtractionFilter(IDataExportRepository repository, string name, FilterContainer container)
 {
     Repository = repository;
     Repository.InsertAndHydrate(this, new Dictionary <string, object>
     {
         { "Name", name != null ? (object)name : DBNull.Value },
         { "FilterContainer_ID", container != null ? (object)container.ID : DBNull.Value }
     });
 }