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

HicServices / RDMP / 6237307473

19 Sep 2023 04:02PM UTC coverage: 57.015% (-0.4%) from 57.44%
6237307473

push

github

web-flow
Feature/rc4 (#1570)

* Syntax tidying
* Dependency updates
* Event handling singletons (ThrowImmediately and co)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: James A Sutherland <>
Co-authored-by: James Friel <jfriel001@dundee.ac.uk>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

10734 of 20259 branches covered (0.0%)

Branch coverage included in aggregate %.

5922 of 5922 new or added lines in 565 files covered. (100.0%)

30687 of 52390 relevant lines covered (58.57%)

7361.8 hits per line

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

64.71
/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, IHasFolder
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;
988✔
42
        set => SetField(ref _name, value);
1,336✔
43
    }
44

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

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

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

68
    /// <inheritdoc/>
69
    [UsefulProperty]
70
    public string Folder
71
    {
72
        get => _folder;
914✔
73
        set => SetField(ref _folder, FolderHelper.Adjust(value));
1,330✔
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)
374✔
104
    {
105
        Repository = repository;
374✔
106

107
        try
108
        {
109
            Repository.InsertAndHydrate(this, new Dictionary<string, object>
374✔
110
            {
374✔
111
                { "Name", name },
374✔
112
                { "Folder", FolderHelper.Root }
374✔
113
            });
374✔
114
        }
374✔
115
        catch (Exception ex)
×
116
        {
117
            //sometimes the user tries to create multiple Projects without fully populating the last one (with a project number)
118
            if (ex.Message.Contains("idx_ProjectNumberMustBeUnique"))
×
119
            {
120
                Project offender;
121
                try
122
                {
123
                    //find the one with the unset project number
124
                    offender = Repository.GetAllObjects<Project>().Single(p => p.ProjectNumber == null);
×
125
                }
×
126
                catch (Exception)
×
127
                {
128
                    throw;
×
129
                }
130

131
                throw new Exception(
×
132
                    $"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",
×
133
                    ex);
×
134
            }
135

136
            throw;
×
137
        }
138
    }
374✔
139

140
    internal Project(IDataExportRepository repository, DbDataReader r)
141
        : base(repository, r)
956✔
142
    {
143
        MasterTicket = r["MasterTicket"].ToString();
956✔
144
        Name = r["Name"] as string;
956✔
145
        ExtractionDirectory = r["ExtractionDirectory"] as string;
956✔
146

147
        ProjectNumber = ObjectToNullableInt(r["ProjectNumber"]);
956✔
148

149
        Folder = r["Folder"] as string ?? FolderHelper.Root;
956!
150
    }
956✔
151

152
    /// <summary>
153
    /// Returns <see cref="Name"/>
154
    /// </summary>
155
    /// <returns></returns>
156
    public override string ToString() => Name;
52✔
157

158
    public void Check(ICheckNotifier notifier)
159
    {
160
        new ProjectChecker(new ThrowImmediatelyActivator(new RepositoryProvider(DataExportRepository), notifier), this)
×
161
            .Check(notifier);
×
162
    }
×
163

164
    /// <summary>
165
    /// Returns <see cref="ProjectNumber"/> (if any), <see cref="Name"/> and <see cref="MasterTicket"/>
166
    /// </summary>
167
    /// <returns></returns>
168
    public string GetSearchString() => ProjectNumber == null ? Name : $"{ProjectNumber}_{Name}_{MasterTicket}";
42!
169

170
    /// <summary>
171
    /// Returns all <see cref="CohortIdentificationConfiguration"/> which are associated with the <see cref="IProject"/> (usually because
172
    /// they have been used to create <see cref="ExtractableCohort"/> used by the <see cref="IProject"/>).
173
    /// </summary>
174
    /// <returns></returns>
175
    public CohortIdentificationConfiguration[] GetAssociatedCohortIdentificationConfigurations()
176
    {
177
        var associations =
4✔
178
            Repository.GetAllObjectsWithParent<ProjectCohortIdentificationConfigurationAssociation>(this);
4✔
179
        return associations.Select(a => a.CohortIdentificationConfiguration).Where(c => c != null).ToArray();
12✔
180
    }
181

182
    /// <summary>
183
    /// Associates the <paramref name="cic"/> with the <see cref="IProject"/>.  This is usually done after generating an <see cref="IExtractableCohort"/>.
184
    /// You can associate a <see cref="CohortIdentificationConfiguration"/> with multiple <see cref="IProject"/> (M to M relationship).
185
    /// </summary>
186
    /// <param name="cic"></param>
187
    /// <returns></returns>
188
    public ProjectCohortIdentificationConfigurationAssociation
189
        AssociateWithCohortIdentification(CohortIdentificationConfiguration cic) =>
190
        new((IDataExportRepository)Repository, this, cic);
2✔
191

192
    /// <inheritdoc/>
193
    public ICatalogue[] GetAllProjectCatalogues()
194
    {
195
        return Repository.GetAllObjectsWithParent<ExtractableDataSet>(this).Select(eds => eds.Catalogue).ToArray();
34✔
196
    }
197

198
    /// <inheritdoc/>
199
    public ExtractionInformation[] GetAllProjectCatalogueColumns(ExtractionCategory c)
200
    {
201
        return GetAllProjectCatalogues().SelectMany(pc => pc.GetAllExtractionInformation(c)).ToArray();
×
202
    }
203

204
    /// <inheritdoc/>
205
    public ExtractionInformation[] GetAllProjectCatalogueColumns(ICoreChildProvider childProvider, ExtractionCategory c)
206
    {
207
        return childProvider is DataExportChildProvider dx
7!
208
            ? dx.ExtractableDataSets.Where(eds => eds.Project_ID == ID)
17✔
209
                .Select(e => dx.AllCataloguesDictionary[e.Catalogue_ID])
×
210
                .SelectMany(cata => cata.GetAllExtractionInformation(c)).ToArray()
×
211
            : GetAllProjectCatalogueColumns(c);
7✔
212
    }
213

214
    /// <inheritdoc/>
215
    public IHasDependencies[] GetObjectsThisDependsOn() => Array.Empty<IHasDependencies>();
×
216

217
    /// <inheritdoc/>
218
    public IHasDependencies[] GetObjectsDependingOnThis() => ExtractionConfigurations;
12✔
219
}
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