Example #1
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);
                    }
                }
            }
        }
Example #2
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;
                }
            }
        }