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

HicServices / RDMP / 11457925069

pending completion
11457925069

push

github

JFriel
Merge branch 'develop' of https://github.com/HicServices/RDMP

11207 of 21044 branches covered (53.26%)

Branch coverage included in aggregate %.

25 of 51 new or added lines in 3 files covered. (49.02%)

705 existing lines in 27 files now uncovered.

31728 of 53779 relevant lines covered (59.0%)

4115.97 hits per line

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

52.17
/Rdmp.Core/CommandExecution/GoToCommandFactory.cs
1
// Copyright (c) The University of Dundee 2018-2024
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)
192✔
37
    {
38
        _activator = activator;
192✔
39
    }
192✔
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))
192✔
45
            ii.ClearAllInjections();
86✔
46

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

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

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

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

67

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

71
        // cic => associated projects
72
        if (Is(forObject, out CohortIdentificationConfiguration cic))
192✔
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))
192✔
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))
192✔
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))
192✔
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))
192!
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))
192✔
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))
192!
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))
192✔
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))
192!
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)
192!
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))
192✔
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))
192✔
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))
192✔
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))
192✔
266
        {
267
            foreach (var lmd in catalogue.LoadMetadatas())
64!
268
            {
269
                yield return new ExecuteCommandShow(_activator, lmd.ID, typeof(LoadMetadata))
×
270
                { OverrideCommandName = $"Data Load ({lmd.Name})", OverrideIcon = GetImage(RDMPConcept.LoadMetadata) };
×
271
            }
272
            if (catalogue.LoadMetadatas().Length == 0)
32✔
273
            {
274
                yield return new ExecuteCommandShow(_activator, null, typeof(LoadMetadata))
32✔
275
                { OverrideCommandName = $"No Data Load", OverrideIcon = GetImage(RDMPConcept.LoadMetadata) };
32✔
276
            }
277

278

279
            if (_activator.CoreChildProvider is DataExportChildProvider exp)
32✔
280
            {
281
                var cataEds = exp.ExtractableDataSets.SingleOrDefault(d => d.Catalogue_ID == catalogue.ID);
230✔
282

283
                if (cataEds != null)
32!
284
                {
285
                    if (cataEds.Project_ID != null)
×
286
                    {
287
                        yield return new ExecuteCommandShow(_activator,
×
288
                            () =>
×
289
                            {
×
290
                                return new[]
×
291
                                {
×
292
                                    _activator.RepositoryLocator.DataExportRepository.GetObjectByID<Project>(
×
293
                                        cataEds.Project_ID.Value)
×
294
                                };
×
295
                            }
×
296
                        )
×
297
                        {
×
298
                            OverrideCommandName = "Associated Project",
×
299
                            OverrideIcon = GetImage(RDMPConcept.Project)
×
300
                        };
×
301
                    }
302
                    else
303
                    {
304
                        yield return new ExecuteCommandShow(_activator,
×
305
                          () =>
×
306
                          {
×
307
                              return new Project[]
×
308
                              {
×
309
                              };
×
310
                          }
×
311
                      )
×
312
                        {
×
313
                            OverrideCommandName = "No Associated Project",
×
314
                            OverrideIcon = GetImage(RDMPConcept.Project)
×
315
                        };
×
316
                    }
317

318
                    yield return new ExecuteCommandShow(_activator,
×
319
                        () => cataEds.ExtractionConfigurations.Select(c => c.Project).Distinct())
×
320
                    {
×
321
                        OverrideCommandName = "Extracted In (Project)",
×
322
                        OverrideIcon = GetImage(RDMPConcept.Project)
×
323
                    };
×
324
                    yield return new ExecuteCommandShow(_activator, () => cataEds.ExtractionConfigurations)
×
325
                    {
×
326
                        OverrideCommandName = "Extracted In (Extraction Configuration)",
×
327
                        OverrideIcon = GetImage(RDMPConcept.ExtractionConfiguration)
×
328
                    };
×
329
                }
330
                else
331
                {
332
                    //no values, show disabled options
333
                    yield return new ExecuteCommandShow(_activator,
32✔
334
                          () =>
32✔
335
                          {
32✔
336
                              return new Project[] { };
×
337
                          }
32✔
338
                      )
32✔
339
                    {
32✔
340
                        OverrideCommandName = "No Associated Project",
32✔
341
                        OverrideIcon = GetImage(RDMPConcept.Project)
32✔
342
                    };
32✔
343
                    yield return new ExecuteCommandShow(_activator,
32✔
344
                                             () =>
32✔
345
                                             {
32✔
346
                                                 return new Project[] { };
×
347
                                             }
32✔
348
                                         )
32✔
349
                    {
32✔
350
                        OverrideCommandName = "Not Extracted In (Project)",
32✔
351
                        OverrideIcon = GetImage(RDMPConcept.Project)
32✔
352
                    };
32✔
353
                    yield return new ExecuteCommandShow(_activator,
32✔
354
                        () =>
32✔
355
                        {
32✔
356
                            return new ExtractionConfiguration[] { };
×
357
                        }
32✔
358
                    )
32✔
359
                    {
32✔
360
                        OverrideCommandName = "Not Extracted In (Extraction Configuration)",
32✔
361
                        OverrideIcon = GetImage(RDMPConcept.ExtractionConfiguration)
32✔
362
                    };
32✔
363
                }
364
            }
32✔
365

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

369
            yield return new ExecuteCommandShow(_activator,
32✔
370
                () =>
32✔
371
                    _activator
×
372
                        .CoreChildProvider
×
373
                        .AllAggregateConfigurations.Where(ac =>
×
374
                            ac.IsCohortIdentificationAggregate && ac.Catalogue_ID == catalogue.ID)
×
375
                        .Select(ac => ac.GetCohortIdentificationConfigurationIfAny())
×
376
                        .Where(cataCic => cataCic != null)
×
377
                        .Distinct())
×
378
            {
32✔
379
                OverrideCommandName = "Cohort Identification Configuration(s)",
32✔
380
                OverrideIcon = GetImage(RDMPConcept.CohortIdentificationConfiguration)
32✔
381
            };
32✔
382

383

384
            yield return new ExecuteCommandShow(_activator,
32✔
385
                () => _activator.CoreChildProvider.AllGovernancePeriods.Where(p =>
×
386
                    p.GovernedCatalogues.Contains(catalogue)))
×
387
            {
32✔
388
                OverrideCommandName = "Governance",
32✔
389
                OverrideIcon = GetImage(RDMPConcept.GovernancePeriod)
32✔
390
            };
32✔
391
        }
392

393
        if (Is(forObject, out ExtractableCohort cohort))
192!
394
        {
395
            yield return new ExecuteCommandShow(_activator, () =>
×
396
            {
×
397
                return _activator.CoreChildProvider is DataExportChildProvider dx
×
398
                    ? dx.ExtractionConfigurations.Where(ec => ec.Cohort_ID == cohort.ID)
×
399
                    : (IEnumerable<IMapsDirectlyToDatabaseTable>)Array.Empty<ExtractionConfiguration>();
×
400
            })
×
401
            {
×
402
                OverrideCommandName = "Extraction Configuration(s)",
×
403
                OverrideIcon = GetImage(RDMPConcept.ExtractionConfiguration)
×
404
            };
×
405

406
            yield return new ExecuteCommandShow(_activator, () =>
×
407
            {
×
408
                return _activator.CoreChildProvider is DataExportChildProvider dx
×
409
                    ? dx.Projects.Where(p => p.ProjectNumber == cohort.ExternalProjectNumber)
×
410
                    : (IEnumerable<IMapsDirectlyToDatabaseTable>)Array.Empty<Project>();
×
411
            })
×
412
            {
×
413
                OverrideCommandName = "Project(s)",
×
414
                OverrideIcon = GetImage(RDMPConcept.Project)
×
415
            };
×
416

UNCOV
417
            var obj = ExtractableCohortAuditLogBuilder.GetObjectIfAny(cohort, _activator.RepositoryLocator);
×
UNCOV
418
            if (obj is not null && obj is CohortIdentificationConfiguration configuration)
×
419
            {
420
                yield return new ExecuteCommandShow(_activator, () =>
×
421
                {
×
422
                    return [configuration];
×
UNCOV
423
                })
×
UNCOV
424
                {
×
UNCOV
425
                    OverrideCommandName = "Cohort Identification Configuration(s)",
×
UNCOV
426
                    OverrideIcon = GetImage(RDMPConcept.CohortIdentificationConfiguration)
×
UNCOV
427
                };
×
428
            }
429

430
        }
×
431

432
        //if it is a masquerader and masquerading as a DatabaseEntity then add a goto the object
433
        if (forObject is IMasqueradeAs masqueraderIfAny)
192!
434
            if (masqueraderIfAny.MasqueradingAs() is DatabaseEntity m)
×
435
                yield return new ExecuteCommandShow(_activator, m, 0, true)
×
UNCOV
436
                { OverrideIcon = _activator.CoreIconProvider.GetImage(m) };
×
437
    }
192✔
438

439
    private static bool SupportsReplacement(object o) => o is not DashboardLayout;
186✔
440

441
    private IEnumerable<IMapsDirectlyToDatabaseTable> GetReplacementIfAny(IMapsDirectlyToDatabaseTable mt)
442
    {
UNCOV
443
        var replacement = _activator.RepositoryLocator.CatalogueRepository
×
UNCOV
444
            .GetAllObjectsWhere<ExtendedProperty>("Name", ExtendedProperty.ReplacedBy)
×
UNCOV
445
            .FirstOrDefault(r => r.IsReferenceTo(mt));
×
446

UNCOV
447
        return replacement == null
×
UNCOV
448
            ? Enumerable.Empty<IMapsDirectlyToDatabaseTable>()
×
UNCOV
449
            : new[] { mt.Repository.GetObjectByID(mt.GetType(), int.Parse(replacement.Value)) };
×
450
    }
451

452
    private Image<Rgba32> GetImage(RDMPConcept concept) => _activator.CoreIconProvider.GetImage(concept);
344✔
453
}
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