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

HicServices / RDMP / 6237307473

19 Sep 2023 04:02PM UTC coverage: 57.015% (-0.4%) from 57.44%
6237307473

push

github

web-flow
Feature/rc4 (#1570)

* Syntax tidying
* Dependency updates
* Event handling singletons (ThrowImmediately and co)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: James A Sutherland <>
Co-authored-by: James Friel <jfriel001@dundee.ac.uk>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

10734 of 20259 branches covered (0.0%)

Branch coverage included in aggregate %.

5922 of 5922 new or added lines in 565 files covered. (100.0%)

30687 of 52390 relevant lines covered (58.57%)

7361.8 hits per line

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

0.0
/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandViewFilterMatchData.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 Rdmp.Core.Curation.Data;
11
using Rdmp.Core.DataViewing;
12
using Rdmp.Core.Icons.IconProvision;
13
using Rdmp.Core.ReusableLibraryCode.Icons.IconProvision;
14
using SixLabors.ImageSharp;
15
using SixLabors.ImageSharp.PixelFormats;
16

17
namespace Rdmp.Core.CommandExecution.AtomicCommands;
18

19
public class ExecuteCommandViewFilterMatchData : ExecuteCommandViewDataBase, IAtomicCommand
20
{
21
    private readonly IFilter _filter;
22
    private readonly IContainer _container;
23

24
    private readonly ViewType _viewType;
25
    private ColumnInfo _columnInfo;
26
    private ColumnInfo[] _candidates;
27

28
    /// <summary>
29
    /// Views an extract of data from a column that matches a given <paramref name="filter"/>
30
    /// </summary>
31
    /// <param name="activator"></param>
32
    /// <param name="filter"></param>
33
    /// <param name="viewType"></param>
34
    /// <param name="columnName"></param>
35
    /// <param name="toFile"></param>
36
    public ExecuteCommandViewFilterMatchData(IBasicActivateItems activator,
37
        [DemandsInitialization("The filter you want to view matching data on (e.g. an AggregateFilter)")]
38
        IFilter filter,
39
        [DemandsInitialization("What kind of data do you want to fetch")]
40
        ViewType viewType = ViewType.TOP_100,
41
        [DemandsInitialization(
42
            "If filter is not implicitly tied to a specific column, pass the name of the column for whom you want to view data.")]
43
        string columnName = null,
44
        [DemandsInitialization(ToFileDescription)]
45
        FileInfo toFile = null) : this(activator, viewType, toFile)
×
46
    {
47
        _filter = filter;
×
48

49
        if (!string.IsNullOrWhiteSpace(columnName))
×
50
        {
51
            var c = filter.GetCatalogue();
×
52
            var candidates = GetCandidates(c);
×
53

54
            // match on exact name?
55
            _columnInfo = candidates.FirstOrDefault(c =>
×
56
                c.GetRuntimeName().Equals(columnName, StringComparison.CurrentCultureIgnoreCase));
×
57
            if (_columnInfo == null)
×
58
                throw new Exception($"Could not find a ColumnInfo called '{columnName}' in Catalogue '{c}'");
×
59
        }
60
        else
61
        {
62
            _columnInfo = filter.GetColumnInfoIfExists();
×
63

64
            //there is a single column associated with the filter?
65
            if (_columnInfo != null)
×
66
                return;
×
67
        }
68

69
        // there is no single column associated with the filter so get user to pick one of them
70
        PopulateCandidates(filter.GetCatalogue(), filter);
×
71
    }
×
72

73
    public ExecuteCommandViewFilterMatchData(IBasicActivateItems activator, IContainer container,
74
        ViewType viewType = ViewType.TOP_100) : this(activator, viewType, null)
×
75
    {
76
        _container = container;
×
77

78
        PopulateCandidates(container.GetCatalogueIfAny(), container);
×
79
    }
×
80

81
    private void PopulateCandidates(Catalogue catalogue, object rootObj)
82
    {
83
        _candidates = GetCandidates(catalogue);
×
84

85
        if (!_candidates.Any())
×
86
            SetImpossible($"No ColumnInfo is associated with '{rootObj}'");
×
87
    }
×
88

89
    private ColumnInfo[] GetCandidates(Catalogue catalogue)
90
    {
91
        if (catalogue == null)
×
92
        {
93
            SetImpossible("Filter has no Catalogue");
×
94
            return null;
×
95
        }
96

97
        return catalogue.GetAllExtractionInformation(ExtractionCategory.Any).Select(e => e.ColumnInfo)
×
98
            .Where(c => c != null).Distinct().ToArray();
×
99
    }
100

101
    protected ExecuteCommandViewFilterMatchData(IBasicActivateItems activator, ViewType viewType, FileInfo toFile) :
102
        base(activator, toFile)
×
103
    {
104
        _viewType = viewType;
×
105
    }
×
106

107
    public override string GetCommandName()
108
    {
109
        return _viewType switch
×
110
        {
×
111
            ViewType.TOP_100 => "View Extract",
×
112
            ViewType.Aggregate => "View Aggregate",
×
113
            _ => throw new ArgumentOutOfRangeException()
×
114
        };
×
115
    }
116

117
    protected override IViewSQLAndResultsCollection GetCollection()
118
    {
119
        _columnInfo ??= SelectOne(_candidates, _columnInfo != null ? _columnInfo.Name : "");
×
120

121
        if (_columnInfo == null)
×
122
            return null;
×
123

124
        ViewColumnExtractCollection collection = null;
×
125

126
        if (_filter != null)
×
127
            collection = new ViewColumnExtractCollection(_columnInfo, _viewType, _filter);
×
128
        if (_container != null)
×
129
            collection = new ViewColumnExtractCollection(_columnInfo, _viewType, _container);
×
130

131
        return collection == null
×
132
            ? throw new Exception("ViewFilterMatchData Command had no filter or container")
×
133
            : (IViewSQLAndResultsCollection)collection;
×
134
    }
135

136
    public override Image<Rgba32> GetImage(IIconProvider iconProvider) =>
137
        iconProvider.GetImage(RDMPConcept.ColumnInfo, OverlayKind.Filter);
×
138
}
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