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

HicServices / RDMP / 8200928920

08 Mar 2024 08:52AM UTC coverage: 56.917% (+0.02%) from 56.895%
8200928920

Pull #1754

github

web-flow
Merge branch 'develop' into feature/RDMP-117-multiple-loads-per-catalogue
Pull Request #1754: Feature/rdmp 117 multiple loads per catalogue

10827 of 20497 branches covered (52.82%)

Branch coverage included in aggregate %.

69 of 84 new or added lines in 14 files covered. (82.14%)

5 existing lines in 3 files now uncovered.

30853 of 52733 relevant lines covered (58.51%)

7364.12 hits per line

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

52.27
/Rdmp.Core/CommandExecution/GoToCommandFactory.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.Linq;
10
using Rdmp.Core.CommandExecution.AtomicCommands;
11
using Rdmp.Core.Curation.Data;
12
using Rdmp.Core.Curation.Data.Aggregation;
13
using Rdmp.Core.Curation.Data.Cohort;
14
using Rdmp.Core.Curation.Data.Dashboarding;
15
using Rdmp.Core.Curation.Data.DataLoad;
16
using Rdmp.Core.Curation.Data.Governance;
17
using Rdmp.Core.Curation.Data.ImportExport;
18
using Rdmp.Core.DataExport.Data;
19
using Rdmp.Core.Icons.IconProvision;
20
using Rdmp.Core.MapsDirectlyToDatabaseTable;
21
using Rdmp.Core.MapsDirectlyToDatabaseTable.Injection;
22
using Rdmp.Core.Providers;
23
using SixLabors.ImageSharp;
24
using SixLabors.ImageSharp.PixelFormats;
25

26
namespace Rdmp.Core.CommandExecution;
27

28
/// <summary>
29
/// Builds the "Go To" submenu for travelling between objects in an RDMP database (e.g. Catalogue to extractions using the Catalogue)
30
/// </summary>
31
public class GoToCommandFactory : CommandFactoryBase
32
{
33
    private readonly IBasicActivateItems _activator;
34
    public const string GoTo = "Go To";
35

36
    public GoToCommandFactory(IBasicActivateItems activator)
190✔
37
    {
38
        _activator = activator;
190✔
39
    }
190✔
40

41
    public IEnumerable<IAtomicCommand> GetCommands(object forObject)
42
    {
43
        //forget old values, get them up to the minute
44
        if (Is(forObject, out IInjectKnown ii))
190✔
45
            ii.ClearAllInjections();
86✔
46

47
        if (Is(forObject, out IMapsDirectlyToDatabaseTable mt))
190✔
48
        {
49
            // Go to import / export definitions
50
            var export = _activator.RepositoryLocator.CatalogueRepository.GetReferencesTo<ObjectExport>(mt)
184✔
51
                .FirstOrDefault();
184✔
52

53
            if (export != null)
184!
54
                yield return new ExecuteCommandShow(_activator, export, 0, true)
×
55
                { OverrideCommandName = "Show Export Definition" };
×
56

57
            var import = _activator.RepositoryLocator.CatalogueRepository.GetReferencesTo<ObjectImport>(mt)
184✔
58
                .FirstOrDefault();
184✔
59
            if (import != null)
184!
60
                yield return new ExecuteCommandShow(_activator, import, 0)
×
61
                { OverrideCommandName = "Show Import Definition" };
×
62

63
            if (SupportsReplacement(forObject))
184✔
64
                yield return new ExecuteCommandShow(_activator, () => GetReplacementIfAny(mt))
182✔
65
                { OverrideCommandName = "Replacement" };
182✔
66

67

68
            yield return new ExecuteCommandSimilar(_activator, mt, false) { GoTo = true };
184✔
69
        }
70

71
        // cic => associated projects
72
        if (Is(forObject, out CohortIdentificationConfiguration cic))
190✔
73
            yield return new ExecuteCommandShow(_activator, () =>
2✔
74
            {
2✔
75
                return _activator.CoreChildProvider is DataExportChildProvider { AllProjectAssociatedCics: not null } dx
×
76
                    ? dx.AllProjectAssociatedCics.Where(a => a.CohortIdentificationConfiguration_ID == cic.ID)
×
77
                        .Select(a => a.Project).Distinct()
×
78
                    : Array.Empty<CohortIdentificationConfiguration>();
×
79
            })
2✔
80
            {
2✔
81
                OverrideCommandName = "Project(s)",
2✔
82
                OverrideIcon = GetImage(RDMPConcept.Project)
2✔
83
            };
2✔
84

85
        if (Is(forObject, out ColumnInfo columnInfo))
190✔
86
        {
87
            yield return new ExecuteCommandSimilar(_activator, columnInfo, true)
4✔
88
            {
4✔
89
                OverrideCommandName = "Different",
4✔
90
                GoTo = true,
4✔
91
                OverrideIcon = GetImage(RDMPConcept.ColumnInfo)
4✔
92
            };
4✔
93

94
            yield return new ExecuteCommandShow(_activator, columnInfo.TableInfo_ID, typeof(TableInfo))
4✔
95
            {
4✔
96
                OverrideCommandName = "Table Info",
4✔
97
                OverrideIcon = GetImage(RDMPConcept.TableInfo)
4✔
98
            };
4✔
99
            yield return new ExecuteCommandShow(_activator,
4✔
100
                () => _activator.CoreChildProvider.AllCatalogueItems.Where(catItem =>
×
101
                    catItem.ColumnInfo_ID == columnInfo.ID))
×
102
            {
4✔
103
                OverrideCommandName = "Catalogue Item(s)",
4✔
104
                OverrideIcon = GetImage(RDMPConcept.CatalogueItem)
4✔
105
            };
4✔
106

107
            yield return new ExecuteCommandShow(_activator, columnInfo.ANOTable_ID, typeof(ANOTable))
4✔
108
            {
4✔
109
                OverrideCommandName = "ANO Table",
4✔
110
                OverrideIcon = GetImage(RDMPConcept.ANOTable)
4✔
111
            };
4✔
112
        }
113

114
        if (Is(forObject, out ExtractionInformation ei))
190✔
115
        {
116
            yield return new ExecuteCommandShow(_activator, ei.CatalogueItem?.Catalogue_ID, typeof(Catalogue))
2!
117
            {
2✔
118
                OverrideCommandName = "Catalogue",
2✔
119
                OverrideIcon = GetImage(RDMPConcept.Catalogue)
2✔
120
            };
2✔
121
            yield return new ExecuteCommandShow(_activator, ei.CatalogueItem_ID, typeof(CatalogueItem))
2✔
122
            {
2✔
123
                OverrideCommandName = "Catalogue Item",
2✔
124
                OverrideIcon = GetImage(RDMPConcept.CatalogueItem)
2✔
125
            };
2✔
126
            yield return new ExecuteCommandShow(_activator, ei.ColumnInfo, 0, true)
2✔
127
            {
2✔
128
                OverrideCommandName = "Column Info",
2✔
129
                OverrideIcon = GetImage(RDMPConcept.ColumnInfo)
2✔
130
            };
2✔
131
        }
132

133
        if (Is(forObject, out CatalogueItem ci))
190✔
134
        {
135
            yield return new ExecuteCommandShow(_activator, ci.Catalogue_ID, typeof(Catalogue))
14✔
136
            {
14✔
137
                OverrideCommandName = "Catalogue",
14✔
138
                OverrideIcon = GetImage(RDMPConcept.Catalogue)
14✔
139
            };
14✔
140
            yield return new ExecuteCommandShow(_activator, ci.ExtractionInformation, 0, true)
14✔
141
            {
14✔
142
                OverrideCommandName = "Extraction Information",
14✔
143
                OverrideIcon = GetImage(RDMPConcept.ExtractionInformation)
14✔
144
            };
14✔
145
            yield return new ExecuteCommandShow(_activator, ci.ColumnInfo, 0, true)
14✔
146
            {
14✔
147
                OverrideCommandName = "Column Info",
14✔
148
                OverrideIcon = GetImage(RDMPConcept.ColumnInfo)
14✔
149
            };
14✔
150
        }
151

152
        if (Is(forObject, out ExtractableDataSet eds))
190!
153
        {
154
            yield return new ExecuteCommandShow(_activator, eds.Catalogue_ID, typeof(Catalogue))
×
155
            {
×
156
                OverrideCommandName = "Catalogue",
×
157
                OverrideIcon = GetImage(RDMPConcept.Catalogue)
×
158
            };
×
159

160
            yield return new ExecuteCommandShow(_activator, () =>
×
161
            {
×
162
                return _activator.CoreChildProvider is DataExportChildProvider dx
×
163
                    ? dx.SelectedDataSets.Where(s => s.ExtractableDataSet_ID == eds.ID)
×
164
                        .Select(s => s.ExtractionConfiguration)
×
165
                    : Array.Empty<SelectedDataSets>();
×
166
            })
×
167
            {
×
168
                OverrideCommandName = "Extraction Configuration(s)",
×
169
                OverrideIcon = GetImage(RDMPConcept.ExtractionConfiguration)
×
170
            };
×
171
        }
172

173
        if (Is(forObject, out GovernancePeriod period))
190✔
174
            yield return new ExecuteCommandShow(_activator, () => period.GovernedCatalogues)
2✔
175
            { OverrideCommandName = "Catalogue(s)", OverrideIcon = GetImage(RDMPConcept.Catalogue) };
2✔
176

177
        if (Is(forObject, out JoinInfo j))
190!
178
            yield return new ExecuteCommandShow(_activator, j.ForeignKey_ID, typeof(ColumnInfo))
×
179
            { OverrideCommandName = "Foreign Key", OverrideIcon = GetImage(RDMPConcept.ColumnInfo) };
×
180

181
        if (Is(forObject, out Lookup lookup))
190✔
182
        {
183
            yield return new ExecuteCommandShow(_activator, lookup.Description.TableInfo_ID, typeof(TableInfo));
6✔
184
            yield return new ExecuteCommandShow(_activator, lookup.ForeignKey_ID, typeof(ColumnInfo))
6✔
185
            { OverrideCommandName = "Foreign Key", OverrideIcon = GetImage(RDMPConcept.ColumnInfo) };
6✔
186
        }
187

188
        if (Is(forObject, out ExtractionFilter masterFilter))
190!
189
        {
190
            yield return new ExecuteCommandShow(_activator, () =>
×
191
                _activator.RepositoryLocator.CatalogueRepository
×
192
                    .GetAllObjectsWhere<AggregateFilter>("ClonedFromExtractionFilter_ID", masterFilter.ID)
×
193
                    .Select(f => f.GetAggregate())
×
194
                    .Where(a => a != null).Distinct()
×
195
            )
×
196
            { OverrideCommandName = "Usages (in Cohort Builder)" };
×
197

198

199
            yield return new ExecuteCommandShow(_activator, () =>
×
200
                _activator.RepositoryLocator.DataExportRepository
×
201
                    .GetAllObjectsWhere<DeployedExtractionFilter>("ClonedFromExtractionFilter_ID", masterFilter.ID)
×
202
                    .Select(f => f.GetDataset()?.ExtractionConfiguration)
×
203
                    .Where(c => c != null).Distinct()
×
204
            )
×
205
            { OverrideCommandName = "Usages (in Extractions)" };
×
206
        }
207

208
        if (Is(forObject, out IFilter filter) && filter.ClonedFromExtractionFilter_ID.HasValue)
190!
209
        {
210
            ExtractionFilter parent = null;
×
211

212
            try
213
            {
214
                parent = _activator.RepositoryLocator.CatalogueRepository.GetObjectByID<ExtractionFilter>(
×
215
                    filter.ClonedFromExtractionFilter_ID.Value);
×
216
            }
×
217
            catch (KeyNotFoundException)
×
218
            {
219
                // new ImpossibleCommand("Parent filter has been deleted") { OverrideCommandName = "Parent Filter" };
220
            }
×
221

222
            if (parent != null)
×
223
                yield return new ExecuteCommandShow(_activator, parent, 0)
×
224
                { OverrideCommandName = "Parent Filter", OverrideIcon = GetImage(RDMPConcept.Filter) };
×
225
        }
226

227
        if (Is(forObject, out SelectedDataSets selectedDataSet))
190✔
228
        {
229
            yield return new ExecuteCommandShow(_activator, selectedDataSet.ExtractableDataSet.Catalogue_ID,
14✔
230
                typeof(Catalogue))
14✔
231
            {
14✔
232
                OverrideCommandName = "Catalogue",
14✔
233
                OverrideIcon = GetImage(RDMPConcept.Catalogue)
14✔
234
            };
14✔
235

236
            var ep = selectedDataSet.ExtractionProgressIfAny;
14✔
237
            if (ep != null) yield return new ExecuteCommandShow(_activator, ep, 0, true);
14!
238
        }
239

240
        if (Is(forObject, out TableInfo tableInfo))
190✔
241
            yield return new ExecuteCommandShow(_activator,
4✔
242
                () => tableInfo.ColumnInfos.SelectMany(c =>
×
243
                    _activator.CoreChildProvider.AllCatalogueItems.Where(catItem => catItem.ColumnInfo_ID == c.ID)
×
244
                        .Select(catItem => catItem.Catalogue)).Distinct())
×
245
            {
4✔
246
                OverrideCommandName = "Catalogue(s)",
4✔
247
                OverrideIcon = GetImage(RDMPConcept.Catalogue)
4✔
248
            };
4✔
249

250
        if (Is(forObject, out AggregateConfiguration aggregate))
190✔
251
        {
252
            yield return new ExecuteCommandShow(_activator, aggregate.GetCohortIdentificationConfigurationIfAny()?.ID,
14!
253
                typeof(CohortIdentificationConfiguration))
14✔
254
            {
14✔
255
                OverrideCommandName = "Cohort Identification Configuration",
14✔
256
                OverrideIcon = GetImage(RDMPConcept.CohortIdentificationConfiguration)
14✔
257
            };
14✔
258
            yield return new ExecuteCommandShow(_activator, aggregate.Catalogue_ID, typeof(Catalogue))
14✔
259
            {
14✔
260
                OverrideCommandName = "Catalogue",
14✔
261
                OverrideIcon = GetImage(RDMPConcept.Catalogue)
14✔
262
            };
14✔
263
        }
264

265
        if (Is(forObject, out Catalogue catalogue))
190✔
266
        {
267
            foreach(var lmd in catalogue.LoadMetadatas())
64!
268
            {
NEW
269
                yield return new ExecuteCommandShow(_activator, lmd.ID, typeof(LoadMetadata))
×
NEW
270
                { OverrideCommandName = $"Data Load ({lmd.Name})", OverrideIcon = GetImage(RDMPConcept.LoadMetadata) };
×
271
            }
272

273

274
            if (_activator.CoreChildProvider is DataExportChildProvider exp)
32✔
275
            {
276
                var cataEds = exp.ExtractableDataSets.SingleOrDefault(d => d.Catalogue_ID == catalogue.ID);
230✔
277

278
                if (cataEds != null)
32!
279
                {
280
                    if (cataEds.Project_ID != null)
×
281
                        yield return new ExecuteCommandShow(_activator,
×
282
                            () =>
×
283
                            {
×
284
                                return new[]
×
285
                                {
×
286
                                    _activator.RepositoryLocator.DataExportRepository.GetObjectByID<Project>(
×
287
                                        cataEds.Project_ID.Value)
×
288
                                };
×
289
                            }
×
290
                        )
×
291
                        {
×
292
                            OverrideCommandName = "Associated Project",
×
293
                            OverrideIcon = GetImage(RDMPConcept.Project)
×
294
                        };
×
295

296
                    yield return new ExecuteCommandShow(_activator,
×
297
                        () => cataEds.ExtractionConfigurations.Select(c => c.Project).Distinct())
×
298
                    {
×
299
                        OverrideCommandName = "Extracted In (Project)",
×
300
                        OverrideIcon = GetImage(RDMPConcept.Project)
×
301
                    };
×
302
                    yield return new ExecuteCommandShow(_activator, () => cataEds.ExtractionConfigurations)
×
303
                    {
×
304
                        OverrideCommandName = "Extracted In (Extraction Configuration)",
×
305
                        OverrideIcon = GetImage(RDMPConcept.ExtractionConfiguration)
×
306
                    };
×
307
                }
308
            }
32✔
309

310
            yield return new ExecuteCommandShow(_activator, () => catalogue.GetTableInfoList(true))
32✔
311
            { OverrideCommandName = "Table(s)", OverrideIcon = GetImage(RDMPConcept.TableInfo) };
32✔
312

313
            yield return new ExecuteCommandShow(_activator,
32✔
314
                () =>
32✔
315
                    _activator
×
316
                        .CoreChildProvider
×
317
                        .AllAggregateConfigurations.Where(ac =>
×
318
                            ac.IsCohortIdentificationAggregate && ac.Catalogue_ID == catalogue.ID)
×
319
                        .Select(ac => ac.GetCohortIdentificationConfigurationIfAny())
×
320
                        .Where(cataCic => cataCic != null)
×
321
                        .Distinct())
×
322
            {
32✔
323
                OverrideCommandName = "Cohort Identification Configuration(s)",
32✔
324
                OverrideIcon = GetImage(RDMPConcept.CohortIdentificationConfiguration)
32✔
325
            };
32✔
326

327

328
            yield return new ExecuteCommandShow(_activator,
32✔
329
                () => _activator.CoreChildProvider.AllGovernancePeriods.Where(p =>
×
330
                    p.GovernedCatalogues.Contains(catalogue)))
×
331
            {
32✔
332
                OverrideCommandName = "Governance",
32✔
333
                OverrideIcon = GetImage(RDMPConcept.GovernancePeriod)
32✔
334
            };
32✔
335
        }
336

337
        if (Is(forObject, out ExtractableCohort cohort))
190!
338
        {
339
            yield return new ExecuteCommandShow(_activator, () =>
×
340
            {
×
341
                return _activator.CoreChildProvider is DataExportChildProvider dx
×
342
                    ? dx.ExtractionConfigurations.Where(ec => ec.Cohort_ID == cohort.ID)
×
343
                    : (IEnumerable<IMapsDirectlyToDatabaseTable>)Array.Empty<ExtractionConfiguration>();
×
344
            })
×
345
            {
×
346
                OverrideCommandName = "Extraction Configuration(s)",
×
347
                OverrideIcon = GetImage(RDMPConcept.ExtractionConfiguration)
×
348
            };
×
349

350
            yield return new ExecuteCommandShow(_activator, () =>
×
351
            {
×
352
                return _activator.CoreChildProvider is DataExportChildProvider dx
×
353
                    ? dx.Projects.Where(p => p.ProjectNumber == cohort.ExternalProjectNumber)
×
354
                    : (IEnumerable<IMapsDirectlyToDatabaseTable>)Array.Empty<Project>();
×
355
            })
×
356
            {
×
357
                OverrideCommandName = "Project(s)",
×
358
                OverrideIcon = GetImage(RDMPConcept.Project)
×
359
            };
×
360
        }
361

362
        //if it is a masquerader and masquerading as a DatabaseEntity then add a goto the object
363
        if (forObject is IMasqueradeAs masqueraderIfAny)
190!
364
            if (masqueraderIfAny.MasqueradingAs() is DatabaseEntity m)
×
365
                yield return new ExecuteCommandShow(_activator, m, 0, true)
×
366
                { OverrideIcon = _activator.CoreIconProvider.GetImage(m) };
×
367
    }
190✔
368

369
    private static bool SupportsReplacement(object o) => o is not DashboardLayout;
184✔
370

371
    private IEnumerable<IMapsDirectlyToDatabaseTable> GetReplacementIfAny(IMapsDirectlyToDatabaseTable mt)
372
    {
373
        var replacement = _activator.RepositoryLocator.CatalogueRepository
×
374
            .GetAllObjectsWhere<ExtendedProperty>("Name", ExtendedProperty.ReplacedBy)
×
375
            .FirstOrDefault(r => r.IsReferenceTo(mt));
×
376

377
        return replacement == null
×
378
            ? Enumerable.Empty<IMapsDirectlyToDatabaseTable>()
×
379
            : new[] { mt.Repository.GetObjectByID(mt.GetType(), int.Parse(replacement.Value)) };
×
380
    }
381

382
    private Image<Rgba32> GetImage(RDMPConcept concept) => _activator.CoreIconProvider.GetImage(concept);
216✔
383
}
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