• 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

45.23
/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandCreateNewFilter.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.CommandLine.Interactive.Picking;
10
using Rdmp.Core.Curation;
11
using Rdmp.Core.Curation.Data;
12
using Rdmp.Core.Curation.Data.Aggregation;
13
using Rdmp.Core.Curation.FilterImporting;
14
using Rdmp.Core.Curation.FilterImporting.Construction;
15
using Rdmp.Core.Icons.IconProvision;
16
using Rdmp.Core.Repositories.Construction;
17
using Rdmp.Core.ReusableLibraryCode.Icons.IconProvision;
18
using SixLabors.ImageSharp;
19
using SixLabors.ImageSharp.PixelFormats;
20

21
namespace Rdmp.Core.CommandExecution.AtomicCommands;
22

23
public class ExecuteCommandCreateNewFilter : BasicCommandExecution, IAtomicCommand
24
{
25
    private IFilterFactory _factory;
26
    private IContainer _container;
27
    private IRootFilterContainerHost _host;
28
    private const float DEFAULT_WEIGHT = 0.1f;
29

30
    public IFilter BasedOn { get; set; }
6✔
31
    public ExtractionFilterParameterSet ParameterSet { get; set; }
×
32
    public string Name { get; }
8✔
33
    public string WhereSQL { get; }
8✔
34

35
    private IFilter[] _offerFilters;
36
    private bool offerCatalogueFilters;
37

38
    public bool OfferCatalogueFilters
39
    {
40
        get => offerCatalogueFilters;
6✔
41
        set
42
        {
43
            if (value)
×
44
            {
45
                var c = GetCatalogue();
×
46
                _offerFilters = c?.GetAllFilters();
×
47

48
                if (_offerFilters == null || !_offerFilters.Any())
×
49
                    SetImpossible($"There are no Filters declared in Catalogue '{c?.ToString() ?? "NULL"}'");
×
50
            }
51

52

53
            offerCatalogueFilters = value;
×
54
        }
×
55
    }
56

57

58
    private ExecuteCommandCreateNewFilter(IBasicActivateItems activator) : base(activator)
6✔
59
    {
60
        Weight = DEFAULT_WEIGHT;
6✔
61
    }
6✔
62

63
    [UseWithCommandLine(
64
        ParameterHelpList = "<into> <basedOn> <name> <where>",
65
        ParameterHelpBreakdown =
66
            @"into        A WHERE filter container or IRootFilterContainerHost (e.g. AggregateConfiguration)
67
basedOn    Optional ExtractionFilter to copy or ExtractionFilterParameterSet
68
name    Optional name to set for the new filter
69
where    Optional SQL to set for the filter.  If <basedOn> is not null this will overwrite it")]
70
    public ExecuteCommandCreateNewFilter(IBasicActivateItems activator,
71
        CommandLineObjectPicker picker) : this(activator)
6✔
72
    {
73
        if (picker.Length == 0)
6!
74
            throw new ArgumentException(
×
75
                "You must supply at least one argument to this command (where you want to create the filter)");
×
76

77
        if (picker.Length > 0)
6✔
78
        {
79
            if (picker[0].HasValueOfType(typeof(ExtractionInformation)))
6✔
80
            {
81
                // create a top level Catalogue level filter for reuse later on
82
                var ei = (ExtractionInformation)picker[0].GetValueForParameterOfType(typeof(ExtractionInformation));
2✔
83
                _factory = new ExtractionFilterFactory(ei);
2✔
84
            }
85
            else if (picker[0].HasValueOfType(typeof(IContainer)))
4!
86
            {
87
                // create a filter in this container
88
                _container = (IContainer)picker[0].GetValueForParameterOfType(typeof(IContainer));
×
89
                SetImpossibleIfReadonly(_container);
×
90
            }
91
            else if (picker[0].HasValueOfType(typeof(IRootFilterContainerHost)))
4!
92
            {
93
                // create a container (if none) then add filter to root container of the object
94
                _host = (IRootFilterContainerHost)picker[0]
4✔
95
                    .GetValueForParameterOfType(typeof(IRootFilterContainerHost));
4✔
96
                SetImpossibleIfReadonly(_host);
4✔
97
            }
98
            else
99
            {
100
                throw new ArgumentException(
×
101
                    $"First argument must be {nameof(IContainer)} or  {nameof(IRootFilterContainerHost)} but it was '{picker[0].RawValue}'");
×
102
            }
103

104

105
            _factory ??= _container?.GetFilterFactory() ?? _host?.GetFilterFactory();
6!
106

107
            if (_factory == null)
6!
108
                throw new Exception("It was not possible to work out a FilterFactory from the container/host");
×
109
        }
110

111
        // the index that string arguments begin at (Name and WhereSql)
112
        var stringArgsStartAt = 2;
6✔
113

114
        if (picker.Length > 1)
6✔
115
        {
116
            if (IsImpossible)
2!
117
                return;
×
118

119
            if (picker[1].HasValueOfType(typeof(IFilter)))
2!
120
                BasedOn = (IFilter)picker[1].GetValueForParameterOfType(typeof(IFilter));
×
121
            else if (picker[1].HasValueOfType(typeof(ExtractionFilterParameterSet)))
2!
122
                ParameterSet =
×
123
                    (ExtractionFilterParameterSet)picker[1]
×
124
                        .GetValueForParameterOfType(typeof(ExtractionFilterParameterSet));
×
125
            else if (!picker[1].ExplicitNull) stringArgsStartAt = 1;
4✔
126
        }
127

128
        if (picker.Length > stringArgsStartAt) Name = picker[stringArgsStartAt].RawValue;
8✔
129
        if (picker.Length > stringArgsStartAt + 1) WhereSQL = picker[stringArgsStartAt + 1].RawValue;
8✔
130
    }
6✔
131

132

133
    public ExecuteCommandCreateNewFilter(IBasicActivateItems activator, IRootFilterContainerHost host) : this(activator)
×
134
    {
135
        _factory = host.GetFilterFactory();
×
136
        _container = host.RootFilterContainer;
×
137
        _host = host;
×
138

139
        if (_container == null && _host is AggregateConfiguration ac)
×
140
        {
141
            if (ac.Catalogue.IsApiCall())
×
142
                SetImpossible(ExecuteCommandAddNewFilterContainer.FiltersCannotBeAddedToApiCalls);
×
143

144
            if (ac.OverrideFiltersByUsingParentAggregateConfigurationInstead_ID != null)
×
145
                SetImpossible("Aggregate is set to use another's filter container tree");
×
146
        }
147

148
        SetImpossibleIfReadonly(host);
×
149
    }
×
150

151

152
    public ExecuteCommandCreateNewFilter(IBasicActivateItems activator, CatalogueItem ci) : this(activator)
×
153
    {
154
        if (ci.ExtractionInformation == null)
×
155
        {
156
            SetImpossible(
×
157
                "CatalogueItem is not extractable so cannot have filters. Make this CatalogueItem extractable to add filters.");
×
158
            return;
×
159
        }
160

161
        _factory = new ExtractionFilterFactory(ci.ExtractionInformation);
×
162
    }
×
163

164
    public ExecuteCommandCreateNewFilter(IBasicActivateItems activator, IFilterFactory factory,
165
        IContainer container = null)
166
        : this(activator)
×
167
    {
168
        _factory = factory;
×
169
        _container = container;
×
170

171
        SetImpossibleIfReadonly(container);
×
172
    }
×
173

174
    public ExecuteCommandCreateNewFilter(IBasicActivateItems activator, IContainer container, IFilter basedOn) :
175
        this(activator)
×
176
    {
177
        _container = container;
×
178
        BasedOn = basedOn;
×
179

180
        SetImpossibleIfReadonly(container);
×
181
    }
×
182

183

184
    private ICatalogue GetCatalogue() => _host?.GetCatalogue() ?? _container?.GetCatalogueIfAny();
×
185

186
    public override Image<Rgba32> GetImage(IIconProvider iconProvider) =>
187
        OfferCatalogueFilters
×
188
            ? iconProvider.GetImage(RDMPConcept.Filter, OverlayKind.Import)
×
189
            : iconProvider.GetImage(RDMPConcept.Filter, OverlayKind.Add);
×
190

191
    public override void Execute()
192
    {
193
        base.Execute();
6✔
194

195
        IFilter f;
196
        var container = _container;
6✔
197

198
        if (_host != null && container == null)
6✔
199
        {
200
            if (_host.RootFilterContainer_ID == null)
4✔
201
                _host.CreateRootContainerIfNotExists();
4✔
202

203
            container = _host.RootFilterContainer;
4✔
204
        }
205

206
        // if importing an existing filter instead of creating blank
207
        if (BasedOn != null)
6!
208
        {
209
            var wizard = new FilterImportWizard(BasicActivator);
×
210
            f = wizard.Import(container, BasedOn, ParameterSet);
×
211
        }
212
        else if (OfferCatalogueFilters)
6!
213
        {
214
            // we want user to make decision about what to import
215
            ImportExistingFilter(container);
×
216
            return;
×
217
        }
218
        else
219
        {
220
            f = _factory.CreateNewFilter($"New Filter {Guid.NewGuid()}");
6✔
221
        }
222

223
        container?.AddChild(f);
6✔
224

225
        if (!string.IsNullOrWhiteSpace(Name)) f.Name = Name;
8✔
226
        if (!string.IsNullOrWhiteSpace(WhereSQL)) f.WhereSQL = WhereSQL;
8✔
227

228
        f.SaveToDatabase();
6✔
229

230
        if (f is ExtractionFilter ef)
6✔
231
            Publish(ef.ExtractionInformation);
2✔
232
        else
233
            Publish((DatabaseEntity)container ?? (DatabaseEntity)f);
4!
234

235
        Emphasise(f);
6✔
236
        Activate((DatabaseEntity)f);
6✔
237
    }
6✔
238

239
    private void ImportExistingFilter(IContainer container)
240
    {
241
        var wizard = new FilterImportWizard(BasicActivator);
×
242

243
        var import = wizard.ImportManyFromSelection(container, _offerFilters).ToArray();
×
244

245
        foreach (var f in import) container.AddChild(f);
×
246

247
        if (import.Length > 0)
×
248
        {
249
            Publish((DatabaseEntity)container);
×
250
            Emphasise((DatabaseEntity)import.Last());
×
251
        }
252
    }
×
253
}
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