• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
You are now the owner of this repo.

HicServices / RDMP / 6245535001

20 Sep 2023 07:44AM UTC coverage: 57.013%. First build
6245535001

push

github

web-flow
8.1.0 Release (#1628)

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 13.0.1 to 13.0.2.
- [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases)
- [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/13.0.1...13.0.2)

---
updated-dependencies:
- dependency-name: Newtonsoft.Json
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump NLog from 5.0.5 to 5.1.0

Bumps [NLog](https://github.com/NLog/NLog) from 5.0.5 to 5.1.0.
- [Release notes](https://github.com/NLog/NLog/releases)
- [Changelog](https://github.com/NLog/NLog/blob/dev/CHANGELOG.md)
- [Commits](https://github.com/NLog/NLog/compare/v5.0.5...v5.1.0)

---
updated-dependencies:
- dependency-name: NLog
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump NLog from 5.0.5 to 5.1.0

* Fix -r flag - should have been --results-directory all along

* Bump Newtonsoft.Json from 13.0.1 to 13.0.2

* Bump YamlDotNet from 12.0.2 to 12.1.0

Bumps [YamlDotNet](https://github.com/aaubry/YamlDotNet) from 12.0.2 to 12.1.0.
- [Release notes](https://github.com/aaubry/YamlDotNet/releases)
- [Commits](https://github.com/aaubry/YamlDotNet/compare/v12.0.2...v12.1.0)

---
updated-dependencies:
- dependency-name: YamlDotNet
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump Moq from 4.18.2 to 4.18.3

Bumps [Moq](https://github.com/moq/moq4) from 4.18.2 to 4.18.3.
- [Release notes](https://github.com/moq/moq4/releases)
- [Changelog](https://github.com/moq/moq4/blob/main/CHANGELOG.md)
- [Commits](https://github.com/moq/moq4/compare/v4.18.2...v4.18.3)

---
updated-dependencies:
- dependency-name: Moq
... (continued)

10732 of 20257 branches covered (0.0%)

Branch coverage included in aggregate %.

48141 of 48141 new or added lines in 1086 files covered. (100.0%)

30685 of 52388 relevant lines covered (58.57%)

7387.88 hits per line

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

0.0
/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandQueryPlatformDatabase.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.IO;
9
using System.Linq;
10
using FAnsi.Discovery;
11
using Rdmp.Core.Curation.Data;
12
using Rdmp.Core.Databases;
13
using Rdmp.Core.DataViewing;
14
using Rdmp.Core.MapsDirectlyToDatabaseTable;
15
using Rdmp.Core.MapsDirectlyToDatabaseTable.Versioning;
16
using Rdmp.Core.Repositories;
17
using Rdmp.Core.Repositories.Construction;
18
using Rdmp.Core.ReusableLibraryCode.DataAccess;
19

20
namespace Rdmp.Core.CommandExecution.AtomicCommands;
21

22
/// <summary>
23
/// Runs a query on a one of the RDMP platform databases and returns the results
24
/// </summary>
25
public class ExecuteCommandQueryPlatformDatabase : ExecuteCommandViewDataBase
26
{
27
    private string _query;
28
    private readonly FileInfo _toFile;
29
    private DiscoveredTable _table;
30

31
    [UseWithObjectConstructor]
32
    public ExecuteCommandQueryPlatformDatabase(IBasicActivateItems activator,
33
        [DemandsInitialization(
34
            "Database type e.g. DataExport, Catalogue, QueryCaching, LoggingDatabase etc (See all IPatcher implementations)")]
35
        string databaseType,
36
        [DemandsInitialization(
37
            "Optional SQL query to execute on the database.  Or null to query the first table in the db.")]
38
        string query = null,
39
        [DemandsInitialization(ToFileDescription)]
40
        FileInfo toFile = null) : base(activator, toFile)
×
41
    {
42
        _query = query;
×
43
        _toFile = toFile;
×
44

45
        var patcherType = MEF.GetTypes<IPatcher>().FirstOrDefault(t => t.Name.Equals(databaseType) || t.Name.Equals(
×
46
            $"{databaseType}Patcher"));
×
47

48
        if (patcherType == null)
×
49
        {
50
            SetImpossible($"Could not find Type called {databaseType} or {databaseType}Patcher");
×
51
            return;
×
52
        }
53

54
        DiscoveredDatabase db;
55

56
        if (patcherType == typeof(DataExportPatcher))
×
57
        {
58
            db = GetDatabase(BasicActivator.RepositoryLocator.DataExportRepository);
×
59

60
            _query ??= "Select * from Project";
×
61
            _table = db?.ExpectTable("Project");
×
62
            return;
×
63
        }
64

65
        if (patcherType == typeof(CataloguePatcher))
×
66
        {
67
            db = GetDatabase(BasicActivator.RepositoryLocator.CatalogueRepository);
×
68

69
            _query ??= "Select * from Catalogue";
×
70
            _table = db?.ExpectTable("Catalogue");
×
71
            return;
×
72
        }
73

74
        var eds = BasicActivator.RepositoryLocator.CatalogueRepository.GetAllObjects<ExternalDatabaseServer>();
×
75

76
        var patcher = (IPatcher)Activator.CreateInstance(patcherType);
×
77
        db = GetDatabase(eds.Where(e => e.WasCreatedBy(patcher)).ToArray());
×
78

79
        if (db == null) return;
×
80

81
        SetTargetDatabase(db);
×
82
    }
×
83

84
    public ExecuteCommandQueryPlatformDatabase(IBasicActivateItems activator,
85
        ExternalDatabaseServer eds) : base(activator, null)
×
86
    {
87
        DiscoveredDatabase db;
88

89
        try
90
        {
91
            db = eds.Discover(DataAccessContext.InternalDataProcessing);
×
92
        }
×
93
        catch (Exception)
×
94
        {
95
            SetImpossible("Not a queryable SQL database");
×
96
            return;
×
97
        }
98

99
        SetTargetDatabase(db);
×
100
    }
×
101

102

103
    private DiscoveredDatabase GetDatabase(IRepository repository)
104
    {
105
        if (repository is TableRepository tableRepo) return tableRepo.DiscoveredServer?.GetCurrentDatabase();
×
106

107
        SetImpossible("Repository was not a database repo");
×
108
        return null;
×
109
    }
110

111
    private DiscoveredDatabase GetDatabase(ExternalDatabaseServer[] eds)
112
    {
113
        if (eds.Length == 0)
×
114
        {
115
            SetImpossible("Could not find any databases of the requested Type");
×
116
            return null;
×
117
        }
118

119
        if (eds.Length > 1)
×
120
        {
121
            SetImpossible($"Found {eds.Length} databases of the requested Type");
×
122
            return null;
×
123
        }
124

125
        return eds[0].Discover(DataAccessContext.InternalDataProcessing);
×
126
    }
127

128

129
    private void SetTargetDatabase(DiscoveredDatabase database)
130
    {
131
        _table = database.DiscoverTables(false).FirstOrDefault();
×
132

133
        if (_table == null) SetImpossible("Database was empty");
×
134
    }
×
135

136

137
    protected override IViewSQLAndResultsCollection GetCollection() =>
138
        new ArbitraryTableExtractionUICollection(_table)
×
139
        {
×
140
            OverrideSql = _query
×
141
        };
×
142
}
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

© 2025 Coveralls, Inc