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

HicServices / RDMP / 15020927240

14 May 2025 12:40PM UTC coverage: 57.504% (-0.03%) from 57.535%
15020927240

push

github

JFriel
update tests

11401 of 21378 branches covered (53.33%)

Branch coverage included in aggregate %.

32343 of 54693 relevant lines covered (59.14%)

17532.33 hits per line

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

64.81
/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandMakeProjectSpecificCatalogueNormalAgain.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.Linq;
8
using Rdmp.Core.Curation.Data;
9
using Rdmp.Core.DataExport.Data;
10
using Rdmp.Core.Icons.IconProvision;
11
using Rdmp.Core.Repositories;
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 ExecuteCommandMakeProjectSpecificCatalogueNormalAgain : BasicCommandExecution, IAtomicCommand
19
{
20
    private Catalogue _catalogue;
21
    private Project _project;
22
    private ExtractableDataSet _extractableDataSet;
23

24
    public ExecuteCommandMakeProjectSpecificCatalogueNormalAgain(IBasicActivateItems activator, Catalogue catalogue, Project project) :
25
        base(activator)
14✔
26
    {
27
        _catalogue = catalogue;
14✔
28
        _project = project;
14✔
29

30
        var dataExportRepository = BasicActivator.RepositoryLocator.DataExportRepository;
14✔
31
        if (dataExportRepository == null)
14!
32
        {
33
            SetImpossible("Data Export functionality is not available");
×
34
            return;
×
35
        }
36

37
        _extractableDataSet = dataExportRepository.GetAllObjectsWithParent<ExtractableDataSet>(catalogue).Where(eds => eds.Project_ID == project.ID)
36✔
38
            .SingleOrDefault();
14✔
39

40
        if (_extractableDataSet == null)
14!
41
        {
42
            SetImpossible("Catalogue is not extractable");
×
43
            return;
×
44
        }
45

46
        if (_extractableDataSet.Project_ID == null)
14!
47
        {
48
            SetImpossible("Catalogue is not a project specific Catalogue");
×
49
            return;
×
50
        }
51

52

53
        if (dataExportRepository.GetAllObjectsWithParent<ExtractableDataSet>(catalogue).Length > 1)
14✔
54
        {
55
            var associatedProjects = dataExportRepository.GetAllObjectsWithParent<ExtractableDataSet>(catalogue).Where(eds => eds.Project_ID == _project.ID);
22✔
56
            foreach (var eds in associatedProjects)
30✔
57
            {
58
                var sds = dataExportRepository.GetAllObjectsWhere<SelectedDataSets>("ExtractableDataSet_ID", eds.ID);
8✔
59
                if (sds.Any())
8✔
60
                {
61
                    //used in an extraction
62
                    SetImpossible($"Catalogue is used in extractions within Prject {_project.Name}. Remove the Catalogue from these extractions.");
2✔
63
                    return;
2✔
64
                }
65
            }
66
        }
67
    }
14✔
68

69
    public override string GetCommandHelp() =>
70
        "Take a dataset that was previously only usable with extractions of a specific project and make it free for use in any extraction project";
×
71

72
    public override void Execute()
73
    {
74
        base.Execute();
14✔
75
        if(BasicActivator.RepositoryLocator.DataExportRepository.GetAllObjectsWithParent<ExtractableDataSet>(_catalogue).Length > 1)
12✔
76
        {
77
            _extractableDataSet.DeleteInDatabase();
6✔
78
        }
79
        else {
80
            _extractableDataSet.Project_ID = null;
6✔
81
            _extractableDataSet.SaveToDatabase();
6✔
82
        }        
83
        if (BasicActivator.RepositoryLocator.DataExportRepository.GetAllObjectsWithParent<ExtractableDataSet>(_catalogue).Any()) return;
24!
84

85
        foreach (var ei in _catalogue.GetAllExtractionInformation(ExtractionCategory.ProjectSpecific))
×
86
        {
87
            ei.ExtractionCategory = ExtractionCategory.Core;
×
88
            ei.SaveToDatabase();
×
89
        }
90

91
        Publish(_catalogue);
×
92
    }
×
93

94
    public override Image<Rgba32> GetImage(IIconProvider iconProvider) =>
95
        Image.Load<Rgba32>(CatalogueIcons.MakeProjectSpecificCatalogueNormalAgain);
×
96
}
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