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

HicServices / RDMP / 20057586828

09 Dec 2025 08:56AM UTC coverage: 57.193% (-0.2%) from 57.422%
20057586828

Pull #2182

github

JFriel
Merge branch 'develop' of https://github.com/HicServices/RDMP into task/RDMP-33-dataset-integration-interface
Pull Request #2182: [Datasets] Task/rdmp 33 dataset integration interface

11510 of 21615 branches covered (53.25%)

Branch coverage included in aggregate %.

1226 of 2024 new or added lines in 85 files covered. (60.57%)

35 existing lines in 15 files now uncovered.

32654 of 55604 relevant lines covered (58.73%)

8854.02 hits per line

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

0.0
/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandAddDatasetsToConfiguration.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.CommandExecution.Combining;
10
using Rdmp.Core.DataExport.Data;
11
using Rdmp.Core.Icons.IconProvision;
12
using Rdmp.Core.Providers;
13
using Rdmp.Core.Repositories.Construction;
14
using Rdmp.Core.ReusableLibraryCode.Icons.IconProvision;
15
using SixLabors.ImageSharp;
16
using SixLabors.ImageSharp.PixelFormats;
17

18
namespace Rdmp.Core.CommandExecution.AtomicCommands;
19

20
public class ExecuteCommandAddDatasetsToConfiguration : BasicCommandExecution
21
{
22
    private readonly ExtractionConfiguration _targetExtractionConfiguration;
23

24
    private IExtractableDataSet[] _toadd;
25

26
    /// <summary>
27
    /// True if <see cref="_toadd"/> is a suggestion of available datasets from which the user must pick.
28
    /// False if <see cref="_toadd"/> reflects an already made selection (e.g. a drag and drop operation).
29
    /// </summary>
30
    private bool _userMustPick;
31

32
    public ExecuteCommandAddDatasetsToConfiguration(IBasicActivateItems activator,
33
        ExtractableDataSetCombineable sourceExtractableDataSetCombineable,
34
        ExtractionConfiguration targetExtractionConfiguration)
35
        : this(activator, targetExtractionConfiguration)
×
36
    {
37
        SetExtractableDataSets(false, sourceExtractableDataSetCombineable.ExtractableDataSets);
×
38
    }
×
39

40
    [UseWithObjectConstructor]
41
    public ExecuteCommandAddDatasetsToConfiguration(IBasicActivateItems itemActivator,
42
        ExtractableDataSet extractableDataSet, ExtractionConfiguration targetExtractionConfiguration)
43
        : this(itemActivator, targetExtractionConfiguration)
×
44
    {
45
        SetExtractableDataSets(false, extractableDataSet);
×
46
    }
×
47

48
    public ExecuteCommandAddDatasetsToConfiguration(IBasicActivateItems itemActivator,
49
        ExtractionConfiguration targetExtractionConfiguration) : base(itemActivator)
×
50
    {
51
        _targetExtractionConfiguration = targetExtractionConfiguration;
×
52

53
        if (_targetExtractionConfiguration.IsReleased)
×
54
            SetImpossible("Extraction is Frozen because it has been released and is readonly, try cloning it instead");
×
55

56
        //if we don't yet know what datasets to add (i.e. haven't called SetExtractableDataSets)
57
        if (_toadd == null)
×
58
            if (itemActivator.CoreChildProvider is DataExportChildProvider childProvider)
×
59
            {
60
                //use the ones that are not already in the ExtractionConfiguration
61
                var _datasets = childProvider.GetDatasets(targetExtractionConfiguration)
×
62
                    .Select(n => n.ExtractableDataSet).ToArray();
×
63
                var _importableDataSets = childProvider.ExtractableDataSets.Except(_datasets)
×
64

×
65
                    //where it can be used in any Project OR this project only
×
NEW
66
                    .Where(ds =>
×
NEW
67
                    {
×
NEW
68
                        try
×
NEW
69
                        {
×
NEW
70
                            return (!ds.Projects.Any() || ds.Projects.Select(p => p.ID).Contains(targetExtractionConfiguration.Project_ID)) && !ds.Catalogue.IsInternalDataset;
×
NEW
71
                        }
×
NEW
72
                        catch (Exception)
×
NEW
73
                        { 
×
NEW
74
                            return false;
×
NEW
75
                        }
×
NEW
76
                    })
×
UNCOV
77
                    .ToArray();
×
78

79
                SetExtractableDataSets(true, _importableDataSets);
×
80
            }
81
            else
82
            {
83
                SetImpossible("CoreChildProvider was not DataExportChildProvider");
×
84
            }
85
    }
×
86

87
    private void SetExtractableDataSets(bool userMustPick, params IExtractableDataSet[] toAdd)
88
    {
89
        _userMustPick = userMustPick;
×
90
        var alreadyInConfiguration = _targetExtractionConfiguration.GetAllExtractableDataSets().ToArray();
×
91
        _toadd = toAdd.Except(alreadyInConfiguration).ToArray();
×
92

93
        if (!_toadd.Any())
×
94
            SetImpossible("ExtractionConfiguration already contains this dataset(s)");
×
95
    }
×
96

97
    public override void Execute()
98
    {
99
        base.Execute();
×
100

101
        if (_userMustPick)
×
102
        {
103
            if (!SelectMany(new DialogArgs
×
104
            {
×
105
                WindowTitle = "Select Datasets",
×
106
                TaskDescription =
×
107
                        "Select the Datasets you would like to be exported as part of your Extraction Configuration."
×
108
            }, _toadd.Cast<ExtractableDataSet>().ToArray(), out var selected))
×
109
                return;
×
110

NEW
111
            foreach (var ds in selected.Where(ds => !ds.Catalogue.IsDeprecated || (BasicActivator.IsInteractive && ds.Catalogue.IsDeprecated && YesNo($"{ds.Catalogue.Name} is deprecated. Are you sure you wish to extract it?", "Confirm use of Deprecated Catalogue"))))
×
112
            {
UNCOV
113
                _targetExtractionConfiguration.AddDatasetToConfiguration(ds);
×
114
            }
115
        }
116
        else
117
        {
118
            foreach (var ds in _toadd)
×
119
                _targetExtractionConfiguration.AddDatasetToConfiguration(ds);
×
120
        }
121

122
        Publish(_targetExtractionConfiguration);
×
123
    }
×
124

125
    public override Image<Rgba32> GetImage(IIconProvider iconProvider) =>
126
        iconProvider.GetImage(RDMPConcept.ExtractableDataSet, OverlayKind.Import);
×
127
}
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