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

HicServices / RDMP / 12427673626

20 Dec 2024 07:55AM UTC coverage: 57.448%. Remained the same
12427673626

push

github

web-flow
Fix up some codeql/inspection code issues (#2087)

* Update OverviewModel.cs

Fix up some .Dispose/using issues, make finding most recent load ID more efficient

* LINQ tidying

* CodeQL fixups

* Update Catalogue.cs

Add Hashcode, Equals methods.

* Update Catalogue.cs

Tweak equality semantics for RDMP DB oddities

11301 of 21223 branches covered (53.25%)

Branch coverage included in aggregate %.

35 of 95 new or added lines in 13 files covered. (36.84%)

5 existing lines in 2 files now uncovered.

32153 of 54417 relevant lines covered (59.09%)

8580.89 hits per line

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

0.0
/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandCloneExtractionConfiguration.cs
1
// Copyright (c) The University of Dundee 2018-2024
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.Collections.Generic;
8
using System.Linq;
9
using Rdmp.Core.Curation.Data;
10
using Rdmp.Core.DataExport.Data;
11
using Rdmp.Core.Icons.IconProvision;
12
using Rdmp.Core.ReusableLibraryCode.Icons.IconProvision;
13
using SixLabors.ImageSharp;
14
using SixLabors.ImageSharp.PixelFormats;
15

16
namespace Rdmp.Core.CommandExecution.AtomicCommands;
17

18
public class ExecuteCommandCloneExtractionConfiguration : BasicCommandExecution
19
{
20
    private readonly ExtractionConfiguration _extractionConfiguration;
21
    private readonly IBasicActivateItems _activeItems;
NEW
22
    private readonly List<IExtractableDataSet> _toRemove = [];
×
NEW
23
    private readonly List<Catalogue> _toAdd = [];
×
24

25
    private void CheckForDeprecatedCatalogues()
26
    {
NEW
27
        if (!_extractionConfiguration.SelectedDataSets.Any(static sd => sd.GetCatalogue().IsDeprecated) ||
×
NEW
28
            !_activeItems.IsInteractive) return;
×
NEW
29
        if (!YesNo(
×
NEW
30
                "There are Deprecated catalogues in this Extraction Configuration. Would you like to replace them with their replacement (where available)?",
×
NEW
31
                "Replace Deprecated Catalogues")) return;
×
32

NEW
33
        var repo = _activeItems.RepositoryLocator.CatalogueRepository;
×
NEW
34
        var deprecatedDatasets = _extractionConfiguration.SelectedDataSets.Where(static sd => sd.GetCatalogue().IsDeprecated).ToList();
×
NEW
35
        var replacedBy = repo.GetExtendedProperties(ExtendedProperty.ReplacedBy).ToArray();
×
NEW
36
        foreach (var ds in deprecatedDatasets)
×
37
        {
NEW
38
            var replacement = replacedBy.FirstOrDefault(rb => rb.ReferencedObjectID == ds.GetCatalogue().ID);
×
NEW
39
            if (replacement is null) continue;
×
40

NEW
41
            var replacementCatalogue = repo.GetObjectByID<Catalogue>(int.Parse(replacement.Value));
×
NEW
42
            while (replacementCatalogue.IsDeprecated)
×
43
            {
NEW
44
                var replacementCatalogueIsReplacedBy = replacedBy.FirstOrDefault(rb => rb.ReferencedObjectID == replacementCatalogue.ID);
×
NEW
45
                if (replacementCatalogueIsReplacedBy is not null)
×
46
                {
47
                    //have found further down the tree
NEW
48
                    replacementCatalogue = repo.GetObjectByID<Catalogue>(int.Parse(replacementCatalogueIsReplacedBy.Value));
×
49
                }
50
                else
51
                {
52
                    //there is no replacement
53
                    break;
54
                }
55
            }
56

NEW
57
            _toRemove.Add(ds.ExtractableDataSet);
×
NEW
58
            _toAdd.Add(replacementCatalogue);
×
59
        }
60
    }
×
61

62
    public ExecuteCommandCloneExtractionConfiguration(IBasicActivateItems activator,
63
        ExtractionConfiguration extractionConfiguration) : base(activator)
×
64
    {
65
        _extractionConfiguration = extractionConfiguration;
×
66
        _activeItems = activator;
×
67
        if (!_extractionConfiguration.SelectedDataSets.Any())
×
68
            SetImpossible("ExtractionConfiguration does not have any selected datasets");
×
69
    }
×
70

71
    public override string GetCommandHelp() =>
72
        "Creates an exact copy of the Extraction Configuration including the cohort selection, all selected datasets, parameters, filter containers, filters etc";
×
73

74
    public override Image<Rgba32> GetImage(IIconProvider iconProvider) =>
75
        Image.Load<Rgba32>(CatalogueIcons.CloneExtractionConfiguration);
×
76

77
    public override void Execute()
78
    {
79
        base.Execute();
×
80
        CheckForDeprecatedCatalogues();
×
81

82
        var clone = _extractionConfiguration.DeepCloneWithNewIDs();
×
NEW
83
        foreach (var ds in _toRemove.Cast<ExtractableDataSet>())
×
84
        {
85
            clone.RemoveDatasetFromConfiguration(ds);
×
86
        }
87

NEW
88
        foreach (var c in _toAdd)
×
89
        {
90
            //check if the eds already exis
91
            var eds = _activeItems.RepositoryLocator.DataExportRepository.GetAllObjectsWhere<ExtractableDataSet>("Catalogue_ID", c.ID).FirstOrDefault();
×
92
            if (eds is null)
×
93
            {
94
                eds = new ExtractableDataSet(_activeItems.RepositoryLocator.DataExportRepository, c);
×
95
                eds.SaveToDatabase();
×
96
            }
97

UNCOV
98
            clone.AddDatasetToConfiguration(eds);
×
99
        }
100

101
        Publish((DatabaseEntity)clone.Project);
×
102
        Emphasise(clone);
×
103
    }
×
104
}
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