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

HicServices / RDMP / 20714560420

05 Jan 2026 11:53AM UTC coverage: 57.198% (-0.2%) from 57.378%
20714560420

push

github

JFriel
update deps

11495 of 21585 branches covered (53.25%)

Branch coverage included in aggregate %.

32571 of 55456 relevant lines covered (58.73%)

17789.06 hits per line

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

55.26
/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandSetColumnSettingBase.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 Rdmp.Core.Curation.Data;
8
using Rdmp.Core.DataExport.Data;
9
using Rdmp.Core.Providers;
10
using System;
11
using System.Linq;
12

13
namespace Rdmp.Core.CommandExecution.AtomicCommands;
14

15
public abstract class ExecuteCommandSetColumnSettingBase : BasicCommandExecution, IAtomicCommand
16
{
17
    private ICatalogue _catalogue;
18
    private ExtractionInformation[] _extractionInformations;
19
    private ExtractionInformation[] _alreadyMarked;
20

21
    private readonly IExtractionConfiguration _inConfiguration;
22
    private readonly string _commandName;
23
    private ConcreteColumn[] _selectedDataSetColumns;
24
    private ConcreteColumn[] _alreadyMarkedInConfiguration;
25

26
    /// <summary>
27
    /// Explicit columns to pick rather than prompting to choose at runtime
28
    /// </summary>
29
    private string[] toPick;
30

31
    private readonly string _commandProperty;
32

33
    /// <summary>
34
    /// 
35
    /// </summary>
36
    /// <param name="activator"></param>
37
    /// <param name="catalogue">The dataset you want to change the setting for</param>
38
    /// <param name="inConfiguration">Optional - If setting should only be applied to a specific extraction or Null for the Catalogue itself (will affect all future extractions)</param>
39
    /// <param name="column">"Optional - The Column name(s) you want to select as the new selection(s).  Comma separate multiple entries if needed"</param>
40
    /// <param name="commandName">Describe what is being changed from user perspective e.g. "Set IsExtractionIdentifier"</param>
41
    /// <param name="commandProperty">Name of property being changed by this command e.g "Extraction Identifier"</param>
42
    public ExecuteCommandSetColumnSettingBase(
43
        IBasicActivateItems activator, ICatalogue catalogue, IExtractionConfiguration inConfiguration, string column,
44
        string commandName, string commandProperty
45
    ) : base(activator)
8✔
46
    {
47
        _catalogue = catalogue;
8✔
48
        _inConfiguration = inConfiguration;
8✔
49
        _commandName = commandName;
8✔
50
        _catalogue.ClearAllInjections();
8✔
51
        _commandProperty = commandProperty;
8✔
52

53

54
        if (inConfiguration != null)
8✔
55
        {
56
            SetImpossibleIfReadonly(_inConfiguration);
2✔
57

58
            var allEds = inConfiguration.GetAllExtractableDataSets();
2✔
59
            var eds = allEds.FirstOrDefault(sds => sds.Catalogue_ID == _catalogue.ID);
4✔
60
            if (eds == null)
2!
61
            {
62
                SetImpossible($"Catalogue '{_catalogue}' is not part of ExtractionConfiguration '{inConfiguration}'");
×
63
                return;
×
64
            }
65

66
            _selectedDataSetColumns = inConfiguration.GetAllExtractableColumnsFor(eds);
2✔
67

68
            if (_selectedDataSetColumns.Length == 0)
2!
69
            {
70
                SetImpossible($"Catalogue '{_catalogue}' in '{inConfiguration}' does not have any extractable columns");
×
71
                return;
×
72
            }
73

74
            _alreadyMarkedInConfiguration = _selectedDataSetColumns.Where(Getter).ToArray();
2✔
75
        }
76
        else
77
        {
78
            _extractionInformations = _catalogue.GetAllExtractionInformation(ExtractionCategory.Any);
6✔
79

80
            if (_extractionInformations.Length == 0)
6!
81
            {
82
                SetImpossible("Catalogue does not have any extractable columns");
×
83
                return;
×
84
            }
85

86
            _alreadyMarked = _extractionInformations.Where(Getter).ToArray();
6✔
87
        }
88

89
        if (!string.IsNullOrWhiteSpace(column)) toPick = column.Split(',', StringSplitOptions.RemoveEmptyEntries);
16✔
90
    }
8✔
91

92

93
    public override string GetCommandName()
94
    {
95
        if (!string.IsNullOrWhiteSpace(OverrideCommandName))
×
96
            return OverrideCommandName;
×
97

98
        var cols = _alreadyMarked ?? _alreadyMarkedInConfiguration;
×
99

100
        return cols == null || cols.Length == 0
×
101
            ? _commandName
×
102
            : $"{_commandName} ({string.Join(",", cols.Select(e => e.GetRuntimeName()))})";
×
103
    }
104

105
    public override void Execute()
106
    {
107
        base.Execute();
8✔
108

109
        var oldCols = _alreadyMarked ?? _alreadyMarkedInConfiguration;
8✔
110

111
        var initialSearchText = oldCols.Length == 1 ? oldCols[0].GetRuntimeName() : null;
8✔
112

113
        if (_inConfiguration != null)
8✔
114
        {
115
            ChangeFor(initialSearchText, _selectedDataSetColumns);
2✔
116
            Publish(_inConfiguration);
2✔
117
        }
118
        else
119
        {
120
            ChangeFor(initialSearchText, _extractionInformations);
6✔
121
            Publish(_catalogue);
4✔
122
        }
123
    }
4✔
124

125
    private void ChangeFor(string initialSearchText, ConcreteColumn[] allColumns)
126
    {
127
        ConcreteColumn[] selected = null;
8✔
128

129
        if (toPick is { Length: > 0 })
8!
130
        {
131
            selected = allColumns.Where(a => toPick.Contains(a.GetRuntimeName())).ToArray();
18✔
132

133
            if (selected.Length != toPick.Length)
8✔
134
                throw new Exception(
2✔
135
                    $"Could not find column(s) {string.Join(',', toPick)} amongst available columns ({string.Join(',', allColumns.Select(c => c.GetRuntimeName()))})");
4✔
136
        }
137
        else
138
        {
139
            if (SelectMany(new DialogArgs
×
140
            {
×
141
                InitialObjectSelection = _alreadyMarked ?? _alreadyMarkedInConfiguration,
×
142
                AllowSelectingNull = true,
×
143
                WindowTitle = $"Set {_commandProperty}",
×
144
                TaskDescription =
×
145
                        $"Choose which columns will make up the new {_commandProperty}.  Or select null to clear"
×
146
            }, allColumns, out selected))
×
147
            {
148
                if (selected == null || selected.Length == 0)
×
149
                    if (!YesNo($"Do you want to clear the {_commandProperty}?", $"Clear {_commandProperty}?"))
×
150
                        return;
×
151
                if (!IsValidSelection(selected))
×
152
                    return;
×
153
            }
154
            else
155
            {
156
                return;
×
157
            }
158
        }
159

160
        foreach (var ec in allColumns)
28✔
161
        {
162
            var newValue = selected != null && selected.Contains(ec);
8!
163

164
            if (Getter(ec) != newValue)
8✔
165
            {
166
                Setter(ec, newValue);
8✔
167
                ec.SaveToDatabase();
8✔
168
            }
169
        }
170
    }
6✔
171

172
    /// <summary>
173
    /// Value getter to determine if a given <see cref="ConcreteColumn"/> is included in the current selection for your setting
174
    /// </summary>
175
    /// <param name="c"></param>
176
    /// <returns></returns>
177
    protected abstract bool Getter(ConcreteColumn c);
178

179
    /// <summary>
180
    /// Value setter to assign new inclusion/exclusion status for the column (if command is executed and a new selection confirmed)
181
    /// </summary>
182
    /// <param name="c"></param>
183
    /// <param name="newValue">New status, true = include in selection, false = exclude</param>
184
    protected abstract void Setter(ConcreteColumn c, bool newValue);
185

186
    /// <summary>
187
    /// Show any warnings if applicable and then return false if user changes their mind about <paramref name="selected"/>
188
    /// </summary>
189
    /// <param name="selected"></param>
190
    /// <returns></returns>
191
    protected abstract bool IsValidSelection(ConcreteColumn[] selected);
192
}
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