• 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

53.97
/Rdmp.Core/Repositories/RepositoryProvider.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 Rdmp.Core.MapsDirectlyToDatabaseTable;
10

11
namespace Rdmp.Core.Repositories;
12

13
/// <summary>
14
/// Use when you have an already initialized set of repositories and only want to fetch objects from the catalogue/data export repositories
15
/// </summary>
16
public class RepositoryProvider : IRDMPPlatformRepositoryServiceLocator
17
{
18
    public ICatalogueRepository CatalogueRepository { get; protected init; }
23,320✔
19
    public IDataExportRepository DataExportRepository { get; protected init; }
11,238✔
20

21
    /// <summary>
22
    /// Use when you have an already initialized set of repositories.  Sets up the class to fetch objects from the Catalogue/Data export databases only.
23
    /// 
24
    /// <para>If possible consider using LinkedRepositoryProvider or Startup (these support plugin repositories, DQE repository etc)</para>
25
    /// 
26
    /// </summary>
27
    /// <param name="dataExportRepository"></param>
28
    public RepositoryProvider(IDataExportRepository dataExportRepository)
1,164✔
29
    {
30
        CatalogueRepository = dataExportRepository.CatalogueRepository;
1,164✔
31
        DataExportRepository = dataExportRepository;
1,164✔
32
    }
1,164✔
33

34
    protected RepositoryProvider()
348✔
35
    {
36
    }
348✔
37

38
    public IMapsDirectlyToDatabaseTable GetArbitraryDatabaseObject(string repositoryTypeName,
39
        string databaseObjectTypeName, int objectId)
40
    {
41
        var repository = GetRepository(repositoryTypeName);
100✔
42
        var objectType = GetTypeByName(databaseObjectTypeName, typeof(IMapsDirectlyToDatabaseTable));
100✔
43

44
        return !repository.StillExists(objectType, objectId) ? null : repository.GetObjectByID(objectType, objectId);
100✔
45
    }
46

47
    public bool ArbitraryDatabaseObjectExists(string repositoryTypeName, string databaseObjectTypeName, int objectID)
48
    {
49
        //if the repository/object type is unknown then it doesn't exist
50
        if (string.IsNullOrWhiteSpace(repositoryTypeName) || string.IsNullOrWhiteSpace(databaseObjectTypeName))
98!
51
            return false;
×
52

53
        var repository = GetRepository(repositoryTypeName);
98✔
54
        var objectType = GetTypeByName(databaseObjectTypeName, typeof(IMapsDirectlyToDatabaseTable));
98✔
55

56
        return repository.StillExists(objectType, objectID);
98✔
57
    }
58

59
    protected virtual IRepository GetRepository(string s)
60
    {
61
        var repoType = GetTypeByName(s, typeof(IRepository));
198✔
62

63
        if (typeof(ICatalogueRepository).IsAssignableFrom(repoType))
198✔
64
            return CatalogueRepository;
196✔
65

66
        return typeof(IDataExportRepository).IsAssignableFrom(repoType)
2!
67
            ? (IRepository)DataExportRepository
2✔
68
            : throw new NotSupportedException(
2✔
69
                $"Did not know what instance of IRepository to use for IRepository Type '{repoType}' , expected it to either be CatalogueRepository or DataExportRepository");
2✔
70
    }
71

72
    private static Type GetTypeByName(string s, Type expectedBaseClassType) => MEF.GetType(s, expectedBaseClassType) ??
396!
73
                                                                               throw new TypeLoadException(
396✔
74
                                                                                   $"Could not find Type called '{s}'");
396✔
75

76
    /// <inheritdoc/>
77
    public IMapsDirectlyToDatabaseTable GetObjectByID<T>(int value) where T : IMapsDirectlyToDatabaseTable
78
    {
79
        if (CatalogueRepository.SupportsObjectType(typeof(T)))
×
80
            return CatalogueRepository.GetObjectByID<T>(value);
×
81
        return DataExportRepository.SupportsObjectType(typeof(T))
×
82
            ? (IMapsDirectlyToDatabaseTable)DataExportRepository.GetObjectByID<T>(value)
×
83
            : throw new ArgumentException(
×
84
                $"Did not know what repository to use to fetch objects of Type '{typeof(T)}'");
×
85
    }
86

87
    /// <inheritdoc/>
88
    public IMapsDirectlyToDatabaseTable GetObjectByID(Type t, int value)
89
    {
90
        if (CatalogueRepository.SupportsObjectType(t))
×
91
            return CatalogueRepository.GetObjectByID(t, value);
×
92
        return DataExportRepository.SupportsObjectType(t)
×
93
            ? DataExportRepository.GetObjectByID(t, value)
×
94
            : throw new ArgumentException($"Did not know what repository to use to fetch objects of Type '{t}'");
×
95
    }
96

97
    public virtual IEnumerable<IRepository> GetAllRepositories()
98
    {
99
        yield return CatalogueRepository;
252✔
100

101
        if (DataExportRepository != null)
×
102
            yield return DataExportRepository;
×
103
    }
×
104
}
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