• 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

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 System;
8
using System.Linq;
9
using Rdmp.Core.Curation.Data;
10
using Rdmp.Core.DataExport.Data;
11

12
namespace Rdmp.Core.CommandExecution.AtomicCommands;
13

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

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

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

30
    private readonly string _commandProperty;
31

32
    /// <summary>
33
    /// 
34
    /// </summary>
35
    /// <param name="activator"></param>
36
    /// <param name="catalogue">The dataset you want to change the setting for</param>
37
    /// <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>
38
    /// <param name="column">"Optional - The Column name(s) you want to select as the new selection(s).  Comma seperate multiple entries if needed"</param>
39
    /// <param name="commandName">Describe what is being changed from user perspective e.g. "Set IsExtractionIdentifier"</param>
40
    /// <param name="commandProperty">Name of property being changed by this command e.g "Extraction Identifier"</param>
41
    public ExecuteCommandSetColumnSettingBase(
42
        IBasicActivateItems activator, ICatalogue catalogue, IExtractionConfiguration inConfiguration, string column,
43
        string commandName, string commandProperty
44
    ) : base(activator)
8✔
45
    {
46
        _catalogue = catalogue;
8✔
47
        _inConfiguration = inConfiguration;
8✔
48
        _commandName = commandName;
8✔
49
        _catalogue.ClearAllInjections();
8✔
50
        _commandProperty = commandProperty;
8✔
51

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

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

64
            _selectedDataSetColumns = inConfiguration.GetAllExtractableColumnsFor(eds);
2✔
65

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

72
            _alreadyMarkedInConfiguration = _selectedDataSetColumns.Where(c => Getter(c)).ToArray();
4✔
73
        }
74
        else
75
        {
76
            _extractionInformations = _catalogue.GetAllExtractionInformation(ExtractionCategory.Any);
6✔
77

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

84
            _alreadyMarked = _extractionInformations.Where(c => Getter(c)).ToArray();
14✔
85
        }
86

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

90

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

96
        var cols = _alreadyMarked ?? _alreadyMarkedInConfiguration;
×
97

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

103
    public override void Execute()
104
    {
105
        base.Execute();
8✔
106

107
        var oldCols = _alreadyMarked ?? _alreadyMarkedInConfiguration;
8✔
108

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

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

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

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

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

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

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

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

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

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

© 2025 Coveralls, Inc