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

HicServices / RDMP / 20714560420

05 Jan 2026 11:53AM UTC coverage: 57.198% (-0.2%) from 57.378%
20714560420

push

github

JFriel
update deps

11495 of 21585 branches covered (53.25%)

Branch coverage included in aggregate %.

32571 of 55456 relevant lines covered (58.73%)

17789.06 hits per line

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

76.71
/Rdmp.Core/DataExport/Data/ExtractableDataSet.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.Collections.Generic;
9
using System.Data.Common;
10
using System.Linq;
11
using Rdmp.Core.Curation.Data;
12
using Rdmp.Core.MapsDirectlyToDatabaseTable;
13
using Rdmp.Core.MapsDirectlyToDatabaseTable.Injection;
14
using Rdmp.Core.Repositories;
15

16
namespace Rdmp.Core.DataExport.Data;
17

18
/// <inheritdoc cref="IExtractableDataSet"/>
19
public class ExtractableDataSet : DatabaseEntity, IExtractableDataSet, IInjectKnown<ICatalogue>
20
{
21
    #region Database Properties
22

23
    private int _catalogue_ID;
24
    private bool _disableExtraction;
25
    private List<IProject> _projects;
26

27

28
    /// <inheritdoc/>
29
    public int Catalogue_ID
30
    {
31
        get => _catalogue_ID;
27,852✔
32
        set
33
        {
34
            ClearAllInjections();
3,490✔
35
            SetField(ref _catalogue_ID, value);
3,490✔
36
        }
3,490✔
37
    }
38

39
    /// <inheritdoc/>
40
    public bool DisableExtraction
41
    {
42
        get => _disableExtraction;
484✔
43
        set => SetField(ref _disableExtraction, value);
3,492✔
44
    }
45

46

47
    /// <inheritdoc/>
48
    [NoMappingToDatabase]
49
    public List<IProject> Projects
50
    {
51
        get
52
        {
53
            if (_projects != null) return _projects;
6,096✔
54
            var ids = Repository.GetAllObjectsWhere<ExtractableDataSetProject>("ExtractableDataSet_ID", this.ID).Select(edsp => edsp.Project_ID);
2,572✔
55
            Projects = Repository.GetAllObjectsInIDList<Project>(ids).Cast<IProject>().ToList();
1,636✔
56
            return _projects;
1,636✔
57

58
        }
59
        set => SetField(ref _projects, value);
1,636✔
60
    }
61

62
    #endregion
63

64
    #region Relationships
65

66
    /// <summary>
67
    /// Returns all <see cref="IExtractionConfiguration"/> in which this dataset is one of the extracted datasets
68
    /// </summary>
69
    [NoMappingToDatabase]
70
    public IExtractionConfiguration[] ExtractionConfigurations
71
    {
72
        get
73
        {
74
            return
662✔
75
                Repository.GetAllObjectsWithParent<SelectedDataSets>(this)
662✔
76
                    .Select(sds => sds.ExtractionConfiguration)
302✔
77
                    .ToArray();
662✔
78
        }
79
    }
80

81
    /// <inheritdoc/>
82
    [NoMappingToDatabase]
83
    public ICatalogue Catalogue => _catalogue.Value;
10,310✔
84

85
    #endregion
86

87

88
    public ExtractableDataSet()
2✔
89
    {
90
        ClearAllInjections();
2✔
91
    }
2✔
92

93
    /// <summary>
94
    /// Defines that the given Catalogue is extractable to researchers as a data set, this is stored in the DataExport database
95
    /// </summary>
96
    /// <returns></returns>
97
    public ExtractableDataSet(IDataExportRepository repository, ICatalogue catalogue, bool disableExtraction = false)
426✔
98
    {
99
        Repository = repository;
426✔
100
        Repository.InsertAndHydrate(this, new Dictionary<string, object>
426✔
101
        {
426✔
102
            { "DisableExtraction", disableExtraction },
426✔
103
            { "Catalogue_ID", catalogue.ID }
426✔
104
        });
426✔
105

106
        ClearAllInjections();
426✔
107
        InjectKnown(catalogue);
426✔
108
    }
426✔
109

110
    internal ExtractableDataSet(IDataExportRepository repository, DbDataReader r)
111
        : base(repository, r)
3,054✔
112
    {
113
        Catalogue_ID = Convert.ToInt32(r["Catalogue_ID"]);
3,054✔
114
        DisableExtraction = (bool)r["DisableExtraction"];
3,054✔
115

116
        ClearAllInjections();
3,054✔
117
    }
3,054✔
118

119
    /// <inheritdoc/>
120
    [NoMappingToDatabase]
121
    public bool IsCatalogueDeprecated => Catalogue == null || Catalogue.IsDeprecated;
10!
122

123
    /// <summary>
124
    /// Returns the <see cref="ICatalogue"/> behind this dataset's Name or a string describing the object state if the Catalogue is unreachable.
125
    /// </summary>
126
    /// <returns></returns>
127
    public override string ToString()
128
    {
129
        if (Catalogue == null)
1,480!
130
            return $"DELETED CATALOGUE {Catalogue_ID}";
×
131

132
        //only bother refreshing Catalogue details if we will be able to get a legit catalogue name
133
        return Catalogue.IsDeprecated ? $"DEPRECATED CATALOGUE {Catalogue.Name}" : Catalogue.Name;
1,480!
134
    }
135

136
    #region Stuff for updating our internal database records
137

138
    /// <summary>
139
    /// Deletes the dataset, this will make the <see cref="ICatalogue"/> non extractable.  This operation fails if
140
    /// the dataset is part of any <see cref="ExtractionConfigurations"/>.
141
    /// </summary>
142
    public override void DeleteInDatabase()
143
    {
144
        try
145
        {
146
            Repository.DeleteFromDatabase(this);
38✔
147
        }
38✔
148
        catch (Exception e)
×
149
        {
150
            if (e.Message.Contains("FK_SelectedDataSets_ExtractableDataSet"))
×
151
                throw new Exception(
×
152
                    $"Cannot delete {this} because it is in use by the following configurations :{Environment.NewLine}{string.Join(Environment.NewLine, ExtractionConfigurations.Select(c => $"{c.Name}({c.Project})"))}",
×
153
                    e);
×
154
            throw;
×
155
        }
156
    }
38✔
157

158
    #endregion
159

160
    /// <summary>
161
    /// Returns an object indicating whether the dataset is project specific or not
162
    /// </summary>
163
    /// <returns></returns>
164
    public CatalogueExtractabilityStatus GetCatalogueExtractabilityStatus() => new(true, Projects.Any());
648✔
165

166
    private Lazy<ICatalogue> _catalogue;
167

168
    /// <inheritdoc/>
169
    public void InjectKnown(ICatalogue instance)
170
    {
171
        if (instance.ID != Catalogue_ID)
2,834!
172
            throw new ArgumentOutOfRangeException(nameof(instance),
×
173
                $"You told us our Catalogue was '{instance}' but its ID didn't match so that is NOT our Catalogue");
×
174
        _catalogue = new Lazy<ICatalogue>(instance);
2,834✔
175
    }
2,834✔
176

177
    /// <inheritdoc/>
178
    public void ClearAllInjections()
179
    {
180
        _catalogue = new Lazy<ICatalogue>(FetchCatalogue);
6,988✔
181
    }
6,988✔
182

183
    private ICatalogue FetchCatalogue()
184
    {
185
        try
186
        {
187
            var cata = ((IDataExportRepository)Repository).CatalogueRepository.GetObjectByID<Catalogue>(Catalogue_ID);
648✔
188
            cata.InjectKnown(GetCatalogueExtractabilityStatus());
648✔
189
            return cata;
648✔
190
        }
191
        catch (KeyNotFoundException)
×
192
        {
193
            //Catalogue has been deleted!
194
            return null;
×
195
        }
196
    }
648✔
197
}
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