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

HicServices / RDMP / 19828552558

01 Dec 2025 03:47PM UTC coverage: 57.056% (+0.3%) from 56.721%
19828552558

push

github

JFriel
add missing file

11461 of 21599 branches covered (53.06%)

Branch coverage included in aggregate %.

32073 of 54702 relevant lines covered (58.63%)

17749.37 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;
22
    private readonly List<IExtractableDataSet> _toRemove = [];
×
23
    private readonly List<Catalogue> _toAdd = [];
×
24

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

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

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

57
            _toRemove.Add(ds.ExtractableDataSet);
×
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 void Execute()
75
    {
76
        base.Execute();
×
77
        CheckForDeprecatedCatalogues();
×
78

79
        var clone = _extractionConfiguration.DeepCloneWithNewIDs();
×
80
        foreach (var ds in _toRemove.Cast<ExtractableDataSet>())
×
81
        {
82
            clone.RemoveDatasetFromConfiguration(ds);
×
83
        }
84

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

95
            clone.AddDatasetToConfiguration(eds);
×
96
        }
97

98
        Publish((DatabaseEntity)clone.Project);
×
99
        Emphasise(clone);
×
100
    }
×
101
}
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