Esempio n. 1
0
        /// <summary>
        /// Makes the given <paramref name="column"/> SELECT Sql part of the query for linking and extracting the provided <paramref name="forDataSet"/>
        /// for this <see cref="IExtractionConfiguration"/>.
        /// </summary>
        /// <param name="forDataSet"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        public ExtractableColumn AddColumnToExtraction(IExtractableDataSet forDataSet, IColumn column)
        {
            if (string.IsNullOrWhiteSpace(column.SelectSQL))
            {
                throw new ArgumentException("IColumn (" + column.GetType().Name + ") " + column + " has a blank value for SelectSQL, fix this in the CatalogueManager", "item");
            }

            string query = "";

            query = column.SelectSQL;

            ExtractableColumn addMe;

            if (column is ExtractionInformation)
            {
                addMe = new ExtractableColumn((IDataExportRepository)Repository, forDataSet, this, column as ExtractionInformation, -1, query);
            }
            else
            {
                addMe = new ExtractableColumn((IDataExportRepository)Repository, forDataSet, this, null, -1, query); // its custom column of some kind, not tied to a catalogue entry
            }
            addMe.UpdateValuesToMatch(column);

            return(addMe);
        }
Esempio n. 2
0
        public ExtractableColumn ShallowClone()
        {
            var eds    = DataExportRepository.GetObjectByID <ExtractableDataSet>(ExtractableDataSet_ID);
            var config = DataExportRepository.GetObjectByID <ExtractionConfiguration>(ExtractionConfiguration_ID);

            var clone = new ExtractableColumn(DataExportRepository, eds, config, CatalogueExtractionInformation, Order, SelectSQL);

            CopyShallowValuesTo(clone);
            return(clone);
        }
Esempio n. 3
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;
                }
            }
        }