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

HicServices / RDMP / 6245535001

20 Sep 2023 07:44AM UTC coverage: 57.013%. First build
6245535001

push

github

web-flow
8.1.0 Release (#1628)

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 13.0.1 to 13.0.2.
- [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases)
- [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/13.0.1...13.0.2)

---
updated-dependencies:
- dependency-name: Newtonsoft.Json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump NLog from 5.0.5 to 5.1.0

Bumps [NLog](https://github.com/NLog/NLog) from 5.0.5 to 5.1.0.
- [Release notes](https://github.com/NLog/NLog/releases)
- [Changelog](https://github.com/NLog/NLog/blob/dev/CHANGELOG.md)
- [Commits](https://github.com/NLog/NLog/compare/v5.0.5...v5.1.0)

---
updated-dependencies:
- dependency-name: NLog
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump NLog from 5.0.5 to 5.1.0

* Fix -r flag - should have been --results-directory all along

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

* Bump YamlDotNet from 12.0.2 to 12.1.0

Bumps [YamlDotNet](https://github.com/aaubry/YamlDotNet) from 12.0.2 to 12.1.0.
- [Release notes](https://github.com/aaubry/YamlDotNet/releases)
- [Commits](https://github.com/aaubry/YamlDotNet/compare/v12.0.2...v12.1.0)

---
updated-dependencies:
- dependency-name: YamlDotNet
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump Moq from 4.18.2 to 4.18.3

Bumps [Moq](https://github.com/moq/moq4) from 4.18.2 to 4.18.3.
- [Release notes](https://github.com/moq/moq4/releases)
- [Changelog](https://github.com/moq/moq4/blob/main/CHANGELOG.md)
- [Commits](https://github.com/moq/moq4/compare/v4.18.2...v4.18.3)

---
updated-dependencies:
- dependency-name: Moq
... (continued)

10732 of 20257 branches covered (0.0%)

Branch coverage included in aggregate %.

48141 of 48141 new or added lines in 1086 files covered. (100.0%)

30685 of 52388 relevant lines covered (58.57%)

7387.88 hits per line

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

25.98
/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandViewData.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 System;
8
using System.IO;
9
using System.Linq;
10
using NLog;
11
using Rdmp.Core.Curation.Data;
12
using Rdmp.Core.Curation.Data.Aggregation;
13
using Rdmp.Core.Curation.Data.Cohort;
14
using Rdmp.Core.DataExport.Data;
15
using Rdmp.Core.DataViewing;
16
using Rdmp.Core.MapsDirectlyToDatabaseTable;
17
using Rdmp.Core.Repositories.Construction;
18

19
namespace Rdmp.Core.CommandExecution.AtomicCommands;
20

21
public class ExecuteCommandViewData : ExecuteCommandViewDataBase, IAtomicCommand
22
{
23
    private readonly IViewSQLAndResultsCollection _collection;
24
    private readonly ViewType _viewType;
25
    private readonly IMapsDirectlyToDatabaseTable _obj;
26
    private readonly bool _useCache;
27

28
    #region Constructors
29

30
    /// <summary>
31
    /// Provides a view of a sample of records in a column/table
32
    /// </summary>
33
    /// <param name="activator"></param>
34
    /// <param name="viewType"></param>
35
    /// <param name="toFile"></param>
36
    /// <param name="useCache"></param>
37
    /// <param name="obj"></param>
38
    /// <exception cref="ArgumentException"></exception>
39
    [UseWithObjectConstructor]
40
    public ExecuteCommandViewData(IBasicActivateItems activator,
41
        [DemandsInitialization("The object (ColumnInfo, TableInfo etc) you want to view a sample of")]
42
        IMapsDirectlyToDatabaseTable obj,
43
        [DemandsInitialization(
44
            "Optional. The view mode you want to see.  Options include 'TOP_100', 'Aggregate', 'Distribution' or 'All'",
45
            DefaultValue = ViewType.TOP_100)]
46
        ViewType viewType = ViewType.TOP_100,
47
        [DemandsInitialization(ToFileDescription)]
48
        FileInfo toFile = null,
49
        [DemandsInitialization(
50
            "Applies only to CohortIdentificationConfigurations.  Defaults to true.  Set to false to disable query cache use.")]
51
        bool useCache = true) : base(activator, toFile)
10✔
52
    {
53
        _viewType = viewType;
10✔
54
        _obj = obj;
10✔
55
        _useCache = useCache;
10!
56

57
        switch (obj)
58
        {
59
            case TableInfo ti:
60
                ThrowIfNotSimpleSelectViewType();
×
61
                _collection = new ViewTableInfoExtractUICollection(ti, _viewType);
×
62
                break;
×
63
            case ColumnInfo col:
64
                _collection = CreateCollection(col);
×
65
                break;
×
66
            case ExtractionInformation ei:
67
                _collection = CreateCollection(ei);
×
68
                break;
×
69
            case Catalogue cata:
70
                ThrowIfNotSimpleSelectViewType();
×
71
                _collection = CreateCollection(cata);
×
72
                break;
×
73
            case CohortIdentificationConfiguration cic:
74
                ThrowIfNotSimpleSelectViewType();
×
75
                _collection = CreateCollection(cic);
×
76
                break;
×
77
            case ExtractableCohort ec:
78
                ThrowIfNotSimpleSelectViewType();
×
79
                _collection = CreateCollection(ec);
×
80
                break;
×
81
            case AggregateConfiguration ac:
82
                ThrowIfNotSimpleSelectViewType();
10✔
83
                _collection = CreateCollection(ac);
10✔
84
                break;
10✔
85
            default:
86
                throw new ArgumentException($"Object '{obj}' was not an object type compatible with this command");
×
87
        }
88
    }
89

90
    private IViewSQLAndResultsCollection CreateCollection(AggregateConfiguration ac)
91
    {
92
        var cic = ac.GetCohortIdentificationConfigurationIfAny();
10✔
93

94
        var collection = new ViewAggregateExtractUICollection(ac);
10✔
95

96
        //if it has a cic with a query cache AND it uses joinables.  Since this is a TOP 100 select * from dataset the cache on CHI is useless only patient index tables used by this query are useful if cached
97
        if (cic is { QueryCachingServer_ID: not null } && ac.PatientIndexJoinablesUsed.Any())
10!
98
            collection.UseQueryCache = _useCache;
×
99

100
        collection.TopX = _viewType == ViewType.TOP_100 ? 100 : null;
10!
101

102
        return collection;
10✔
103
    }
104

105
    private IViewSQLAndResultsCollection CreateCollection(ExtractableCohort ec) =>
106
        new ViewCohortExtractionUICollection(ec)
×
107
        {
×
108
            Top = _viewType == ViewType.TOP_100 ? 100 : -1,
×
109
            IncludeCohortID = false
×
110
        };
×
111

112
    private IViewSQLAndResultsCollection CreateCollection(CohortIdentificationConfiguration cic)
113
    {
114
        if (_viewType == ViewType.TOP_100)
×
115
            LogManager.GetCurrentClassLogger()
×
116
                .Warn(
×
117
                    $"'{ViewType.TOP_100}' is not supported on '{nameof(CohortIdentificationConfiguration)}', '{ViewType.All}' will be used");
×
118

119
        return new ViewCohortIdentificationConfigurationSqlCollection(cic)
×
120
        {
×
121
            UseQueryCache = _useCache
×
122
        };
×
123
    }
124

125
    private void ThrowIfNotSimpleSelectViewType()
126
    {
127
        if (_viewType != ViewType.TOP_100 && _viewType != ViewType.All)
10!
128
            throw new ArgumentException(
×
129
                $"Only '{nameof(ViewType.TOP_100)}' or '{nameof(ViewType.All)}' can be used for this object Type");
×
130
    }
10✔
131

132
    private IViewSQLAndResultsCollection CreateCollection(Catalogue cata) =>
133
        new ViewCatalogueDataCollection(cata)
×
134
        {
×
135
            TopX = _viewType == ViewType.All ? null : 100
×
136
        };
×
137

138
    /// <summary>
139
    /// Fetches the <paramref name="viewType"/> of the data in <see cref="ColumnInfo"/> <paramref name="c"/>
140
    /// </summary>
141
    /// <param name="activator"></param>
142
    /// <param name="viewType"></param>
143
    /// <param name="c"></param>
144
    public ExecuteCommandViewData(IBasicActivateItems activator, ViewType viewType, ColumnInfo c) : base(activator,
×
145
        null)
×
146
    {
147
        _viewType = viewType;
×
148
        _collection = CreateCollection(c);
×
149
    }
×
150

151
    public ExecuteCommandViewData(IBasicActivateItems activator, ViewType viewType, ExtractionInformation ei) : base(
×
152
        activator, null)
×
153
    {
154
        _viewType = viewType;
×
155
        _collection = CreateCollection(ei);
×
156
    }
×
157

158
    /// <summary>
159
    /// Views the top 100 records of the <paramref name="tableInfo"/>
160
    /// </summary>
161
    /// <param name="activator"></param>
162
    /// <param name="tableInfo"></param>
163
    public ExecuteCommandViewData(IBasicActivateItems activator, TableInfo tableInfo) : base(activator, null)
×
164
    {
165
        _viewType = ViewType.TOP_100;
×
166
        _collection = new ViewTableInfoExtractUICollection(tableInfo, _viewType);
×
167
    }
×
168

169
    #endregion
170

171
    private IViewSQLAndResultsCollection CreateCollection(ColumnInfo c)
172
    {
173
        var toReturn = new ViewColumnExtractCollection(c, _viewType);
×
174

175
        if (!c.IsNumerical() && _viewType == ViewType.Distribution)
×
176
            SetImpossible("Column is not numerical");
×
177

178
        return toReturn;
×
179
    }
180

181
    private IViewSQLAndResultsCollection CreateCollection(ExtractionInformation ei)
182
    {
183
        var toReturn = new ViewColumnExtractCollection(ei, _viewType);
×
184
        if ((!ei.ColumnInfo?.IsNumerical() ?? false) && _viewType == ViewType.Distribution)
×
185
            SetImpossible("Column is not numerical");
×
186

187
        return toReturn;
×
188
    }
189

190
    public override string GetCommandName()
191
    {
192
        // if user has set an override, respect it
193
        if (!string.IsNullOrWhiteSpace(OverrideCommandName))
10!
194
            return OverrideCommandName;
×
195

196
        return _obj is CohortIdentificationConfiguration
10!
197
            ? _useCache ? "Query Builder SQL/Results" : "Query Builder SQL/Results (No Cache)"
10✔
198
            : $"View {_viewType.ToString().Replace("_", " ")}";
10✔
199
    }
200

201
    protected override IViewSQLAndResultsCollection GetCollection() => _collection;
×
202
}
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