• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HicServices / RDMP / 26956212158

04 Jun 2026 01:54PM UTC coverage: 56.971% (-0.06%) from 57.032%
26956212158

push

github

web-flow
Task/rdmp 374 merge improvements (#2342)

* improve merge

* add merge view

* tidy up

* update tests

* reove bad code

* Fix typo in SQL Extraction Merge description

11571 of 21851 branches covered (52.95%)

Branch coverage included in aggregate %.

43 of 112 new or added lines in 4 files covered. (38.39%)

2 existing lines in 1 file now uncovered.

32720 of 55892 relevant lines covered (58.54%)

9014.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Rdmp.Core/DataViewing/ViewSelectedDatasetMergeSQLUICollection.cs
1
// Copyright (c) The University of Dundee 2018-2019
2
// This file is part of the Research Data Management Platform (RDMP).
3
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4
// RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
6

7
using FAnsi.Discovery.QuerySyntax;
8
using NPOI.OpenXmlFormats.Spreadsheet;
9
using Rdmp.Core.Curation.Data;
10
using Rdmp.Core.Curation.Data.Dashboarding;
11
using Rdmp.Core.DataExport.Data;
12
using Rdmp.Core.DataExport.DataExtraction.Commands;
13
using Rdmp.Core.DataExport.DataExtraction.Pipeline.Destinations;
14
using Rdmp.Core.DataExport.DataExtraction.UserPicks;
15
using Rdmp.Core.DataLoad.Triggers;
16
using Rdmp.Core.DataLoad.Triggers.Implementations;
17
using Rdmp.Core.ReusableLibraryCode.DataAccess;
18
using System;
19
using System.Collections.Generic;
20
using System.Data;
21
using System.Linq;
22

23
namespace Rdmp.Core.DataViewing;
24

25
internal class ViewSelectedDatasetMergeSQLUICollection : PersistableObjectCollection, IViewSQLAndResultsCollection
26
{
27
    private ExtractDatasetCommand _request;
28

NEW
29
    private ISelectedDataSets SelectedDataset => DatabaseObjects.OfType<ISelectedDataSets>().FirstOrDefault();
×
30

NEW
31
    public bool DisableRun => true;
×
32

NEW
33
    public ViewSelectedDatasetMergeSQLUICollection()
×
34
    {
NEW
35
    }
×
36

NEW
37
    public ViewSelectedDatasetMergeSQLUICollection(ISelectedDataSets dataset) : this()
×
38
    {
NEW
39
        DatabaseObjects.Add(dataset);
×
NEW
40
    }
×
41

42
    public string GetSql()
43
    {
NEW
44
        BuildRequest();
×
NEW
45
        var columns = _request.ColumnsToExtract;
×
NEW
46
        var table = _request.QueryBuilder.TablesUsedInQuery.FirstOrDefault().Discover(DataAccessContext.InternalDataProcessing);
×
47

48
       
49

NEW
50
        DataColumn[] pkColumns= columns.Where(c => c.ColumnInfo.ExtractionInformations.First().IsPrimaryKey).Select(c => new DataColumn() { 
×
NEW
51
            ColumnName = c.GetRuntimeName()
×
NEW
52
        }).ToArray();
×
NEW
53
        DataColumn[] nonPkColumns = columns.Where(c => !c.ColumnInfo.ExtractionInformations.First().IsPrimaryKey).Select(c => new DataColumn()
×
NEW
54
        {
×
NEW
55
            ColumnName = c.GetRuntimeName()
×
NEW
56
        }).ToArray();
×
NEW
57
        var mergeSql = MSSqlMergeDestination.GetMergeSQL(table.GetFullyQualifiedName(), "someTempTable",pkColumns,nonPkColumns,true,GetQuerySyntaxHelper());
×
NEW
58
        return mergeSql;
×
59

60
    }
61

62
    private void BuildRequest()
63
    {
NEW
64
        if (_request != null)
×
NEW
65
            return;
×
66

NEW
67
        var ec = SelectedDataset.ExtractionConfiguration;
×
68

NEW
69
        if (ec.Cohort_ID == null)
×
NEW
70
            throw new Exception("No cohort has been defined for this ExtractionConfiguration");
×
71

72
        //We are generating what the extraction SQL will be like, that only requires the dataset so empty bundle is fine
NEW
73
        _request = new ExtractDatasetCommand(ec, new ExtractableDatasetBundle(SelectedDataset.ExtractableDataSet));
×
NEW
74
        _request.GenerateQueryBuilder();
×
NEW
75
        _request.QueryBuilder.RegenerateSQL();
×
NEW
76
    }
×
77

78
    public IDataAccessPoint GetDataAccessPoint()
79
    {
NEW
80
        BuildRequest();
×
81

NEW
82
        return _request?.QueryBuilder?.TablesUsedInQuery?.FirstOrDefault();
×
83
        //return null;
84
    }
85

86
    public IEnumerable<DatabaseEntity> GetToolStripObjects()
87
    {
NEW
88
        yield return (DatabaseEntity)SelectedDataset;
×
NEW
89
    }
×
90

NEW
91
    public string GetTabName() => $"Merge SQL for {SelectedDataset}";
×
92

93
    public void AdjustAutocomplete(IAutoCompleteProvider autoComplete)
94
    {
NEW
95
    }
×
96

97
    public IQuerySyntaxHelper GetQuerySyntaxHelper()
98
    {
NEW
99
        BuildRequest();
×
100

NEW
101
        return _request.QueryBuilder.QuerySyntaxHelper;
×
102
    }
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc