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

HicServices / RDMP / 21252979012

22 Jan 2026 02:53PM UTC coverage: 57.182% (-0.01%) from 57.196%
21252979012

push

github

web-flow
Task/rdmp 353 delta extractions (#2303)

* allow the addition of new columns to extraction archives

* update changelog

* allow extraction progess with no dqe set

* add option to no clone extraction progress

* update changelog

* fix typo

11497 of 21599 branches covered (53.23%)

Branch coverage included in aggregate %.

5 of 23 new or added lines in 2 files covered. (21.74%)

2 existing lines in 2 files now uncovered.

32576 of 55476 relevant lines covered (58.72%)

17872.11 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 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
        if (_activeItems.IsInteractive && clone.SelectedDataSets.Any(sds => sds.ExtractionProgressIfAny != null))
×
84
        {
NEW
85
            if(!_activeItems.YesNo("Do you want to include this extraction's extraction progress in this clone?", "Include Extraction Progress?")) {
×
NEW
86
                foreach (var ep in clone.SelectedDataSets.Where(sds => sds.ExtractionProgressIfAny != null).Select(sds => sds.ExtractionProgressIfAny))
×
87
                {
NEW
88
                    ep.DeleteInDatabase();
×
89
                }
90
            }
91
        }
UNCOV
92
        foreach (var ds in _toRemove.Cast<ExtractableDataSet>())
×
93
        {
94
            clone.RemoveDatasetFromConfiguration(ds);
×
95
        }
96

97
        foreach (var c in _toAdd)
×
98
        {
99
            //check if the eds already exis
100
            var eds = _activeItems.RepositoryLocator.DataExportRepository.GetAllObjectsWhere<ExtractableDataSet>("Catalogue_ID", c.ID).FirstOrDefault();
×
101
            if (eds is null)
×
102
            {
103
                eds = new ExtractableDataSet(_activeItems.RepositoryLocator.DataExportRepository, c);
×
104
                eds.SaveToDatabase();
×
105
            }
106

107
            clone.AddDatasetToConfiguration(eds);
×
108
        }
109

110
        Publish((DatabaseEntity)clone.Project);
×
111
        Emphasise(clone);
×
112
    }
×
113
}
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