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

HicServices / RDMP / 11978888584

22 Nov 2024 07:27PM UTC coverage: 57.383% (-0.002%) from 57.385%
11978888584

push

github

jas88
Fix up redundant type inheritance

11206 of 21050 branches covered (53.24%)

Branch coverage included in aggregate %.

65 of 249 new or added lines in 42 files covered. (26.1%)

17 existing lines in 14 files now uncovered.

31718 of 53752 relevant lines covered (59.01%)

8290.69 hits per line

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

66.67
/Rdmp.Core/DataExport/Data/Project.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.CommandExecution;
12
using Rdmp.Core.Curation.Data;
13
using Rdmp.Core.Curation.Data.Cohort;
14
using Rdmp.Core.DataExport.Checks;
15
using Rdmp.Core.MapsDirectlyToDatabaseTable;
16
using Rdmp.Core.MapsDirectlyToDatabaseTable.Attributes;
17
using Rdmp.Core.Providers;
18
using Rdmp.Core.Repositories;
19
using Rdmp.Core.ReusableLibraryCode;
20
using Rdmp.Core.ReusableLibraryCode.Annotations;
21
using Rdmp.Core.ReusableLibraryCode.Checks;
22

23
namespace Rdmp.Core.DataExport.Data;
24

25
/// <inheritdoc cref="IProject"/>
26
public class Project : DatabaseEntity, IProject, ICustomSearchString, ICheckable
27
{
28
    #region Database Properties
29

30
    private string _name;
31
    private string _masterTicket;
32
    private string _extractionDirectory;
33
    private int? _projectNumber;
34
    private string _folder;
35

36
    /// <inheritdoc/>
37
    [NotNull]
38
    [Unique]
39
    public string Name
40
    {
41
        get => _name;
1,414✔
42
        set => SetField(ref _name, value);
2,100✔
43
    }
44

45
    /// <inheritdoc/>
46
    public string MasterTicket
47
    {
48
        get => _masterTicket;
966✔
49
        set => SetField(ref _masterTicket, value);
1,916✔
50
    }
51

52
    /// <inheritdoc/>
53
    [AdjustableLocation]
54
    public string ExtractionDirectory
55
    {
56
        get => _extractionDirectory;
1,428✔
57
        set => SetField(ref _extractionDirectory, value);
2,106✔
58
    }
59

60
    /// <inheritdoc/>
61
    [UsefulProperty]
62
    public int? ProjectNumber
63
    {
64
        get => _projectNumber;
3,452✔
65
        set => SetField(ref _projectNumber, value);
2,142✔
66
    }
67

68
    /// <inheritdoc/>
69
    [UsefulProperty]
70
    public string Folder
71
    {
72
        get => _folder;
1,668✔
73
        set => SetField(ref _folder, FolderHelper.Adjust(value));
2,094✔
74
    }
75

76
    #endregion
77

78
    #region Relationships
79

80
    /// <inheritdoc/>
81
    [NoMappingToDatabase]
82
    public IExtractionConfiguration[] ExtractionConfigurations =>
83
        Repository.GetAllObjectsWithParent<ExtractionConfiguration>(this)
48✔
84
            .Cast<IExtractionConfiguration>()
48✔
85
            .ToArray();
48✔
86

87

88
    /// <inheritdoc/>
89
    [NoMappingToDatabase]
90
    public IProjectCohortIdentificationConfigurationAssociation[]
91
        ProjectCohortIdentificationConfigurationAssociations =>
92
        Repository.GetAllObjectsWithParent<ProjectCohortIdentificationConfigurationAssociation>(this);
18✔
93

94
    #endregion
95

96
    public Project()
×
97
    {
98
    }
×
99

100
    /// <summary>
101
    /// Defines a new extraction project this is stored in the Data Export database
102
    /// </summary>
103
    public Project(IDataExportRepository repository, string name)
420✔
104
    {
105
        Repository = repository;
420✔
106

107
        try
108
        {
109
            Repository.InsertAndHydrate(this, new Dictionary<string, object>
420✔
110
            {
420✔
111
                { "Name", name },
420✔
112
                { "Folder", FolderHelper.Root }
420✔
113
            });
420✔
114
        }
420✔
115
        catch (Exception ex)
×
116
        {
117
            //sometimes the user tries to create multiple Projects without fully populating the last one (with a project number)
NEW
118
            if (!ex.Message.Contains("idx_ProjectNumberMustBeUnique")) throw;
×
119

NEW
120
            var offender =
×
NEW
121
                //find the one with the unset project number
×
NEW
122
                Repository.GetAllObjects<Project>().Single(static p => p.ProjectNumber == null);
×
123

NEW
124
            throw new Exception(
×
NEW
125
                $"Could not create a new Project because there is already another Project in the system ({offender}) which is missing a Project Number.  All projects must have a ProjectNumber, there can be 1 Project at a time which does not have a number and that is one that is being built by the user right now.  Either delete Project {offender} or give it a project number",
×
NEW
126
                ex);
×
127
        }
128
    }
420✔
129

130
    internal Project(IDataExportRepository repository, DbDataReader r)
131
        : base(repository, r)
1,674✔
132
    {
133
        MasterTicket = r["MasterTicket"].ToString();
1,674✔
134
        Name = r["Name"] as string;
1,674✔
135
        ExtractionDirectory = r["ExtractionDirectory"] as string;
1,674✔
136

137
        ProjectNumber = ObjectToNullableInt(r["ProjectNumber"]);
1,674✔
138

139
        Folder = r["Folder"] as string ?? FolderHelper.Root;
1,674!
140
    }
1,674✔
141

142
    /// <summary>
143
    /// Returns <see cref="Name"/>
144
    /// </summary>
145
    /// <returns></returns>
146
    public override string ToString() => Name;
54✔
147

148
    public void Check(ICheckNotifier notifier)
149
    {
150
        new ProjectChecker(new ThrowImmediatelyActivator(new RepositoryProvider(DataExportRepository), notifier), this)
×
151
            .Check(notifier);
×
152
    }
×
153

154
    /// <summary>
155
    /// Returns <see cref="ProjectNumber"/> (if any), <see cref="Name"/> and <see cref="MasterTicket"/>
156
    /// </summary>
157
    /// <returns></returns>
158
    public string GetSearchString() => ProjectNumber == null ? Name : $"{ProjectNumber}_{Name}_{MasterTicket}";
42!
159

160
    /// <summary>
161
    /// Returns all <see cref="CohortIdentificationConfiguration"/> which are associated with the <see cref="IProject"/> (usually because
162
    /// they have been used to create <see cref="ExtractableCohort"/> used by the <see cref="IProject"/>).
163
    /// </summary>
164
    /// <returns></returns>
165
    public CohortIdentificationConfiguration[] GetAssociatedCohortIdentificationConfigurations()
166
    {
167
        var associations =
840✔
168
            Repository.GetAllObjectsWithParent<ProjectCohortIdentificationConfigurationAssociation>(this);
840✔
169
        return associations.Select(static a => a.CohortIdentificationConfiguration).Where(static c => c != null).ToArray();
1,404✔
170
    }
171

172
    /// <summary>
173
    /// Associates the <paramref name="cic"/> with the <see cref="IProject"/>.  This is usually done after generating an <see cref="IExtractableCohort"/>.
174
    /// You can associate a <see cref="CohortIdentificationConfiguration"/> with multiple <see cref="IProject"/> (M to M relationship).
175
    /// </summary>
176
    /// <param name="cic"></param>
177
    /// <returns></returns>
178
    public ProjectCohortIdentificationConfigurationAssociation
179
        AssociateWithCohortIdentification(CohortIdentificationConfiguration cic) =>
180
        new((IDataExportRepository)Repository, this, cic);
2✔
181

182
    /// <inheritdoc/>
183
    public ICatalogue[] GetAllProjectCatalogues()
184
    {
185
        return Repository.GetAllObjectsWithParent<ExtractableDataSet>(this).Select(static eds => eds.Catalogue).ToArray();
34✔
186
    }
187

188
    /// <inheritdoc/>
189
    public ExtractionInformation[] GetAllProjectCatalogueColumns(ExtractionCategory c)
190
    {
191
        return GetAllProjectCatalogues().SelectMany(pc => pc.GetAllExtractionInformation(c)).ToArray();
×
192
    }
193

194
    /// <inheritdoc/>
195
    public ExtractionInformation[] GetAllProjectCatalogueColumns(ICoreChildProvider childProvider, ExtractionCategory c)
196
    {
197
        return childProvider is DataExportChildProvider dx
14!
198
            ? dx.ExtractableDataSets.Where(eds => eds.Project_ID == ID)
34✔
199
                .Select(e => dx.AllCataloguesDictionary[e.Catalogue_ID])
×
200
                .SelectMany(cata => cata.GetAllExtractionInformation(c)).ToArray()
×
201
            : GetAllProjectCatalogueColumns(c);
14✔
202
    }
203

204
    /// <inheritdoc/>
205
    public IHasDependencies[] GetObjectsThisDependsOn() => Array.Empty<IHasDependencies>();
×
206

207
    /// <inheritdoc/>
208
    public IHasDependencies[] GetObjectsDependingOnThis() => ExtractionConfigurations;
12✔
209
}
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