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

HicServices / RDMP / 12136273647

03 Dec 2024 09:03AM UTC coverage: 57.448% (+0.07%) from 57.382%
12136273647

push

github

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

11297 of 21215 branches covered (53.25%)

Branch coverage included in aggregate %.

439 of 673 new or added lines in 30 files covered. (65.23%)

5 existing lines in 4 files now uncovered.

32146 of 54407 relevant lines covered (59.08%)

17095.94 hits per line

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

65.67
/Rdmp.Core/DataLoad/Modules/Mutilators/MatchingTablesMutilatorWithDataLoadJob.cs
1
// Copyright (c) The University of Dundee 2024-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.Diagnostics;
9
using System.Linq;
10
using System.Text.RegularExpressions;
11
using FAnsi.Discovery;
12
using Rdmp.Core.Curation.Data;
13
using Rdmp.Core.Curation.Data.DataLoad;
14
using Rdmp.Core.DataLoad.Engine.Job;
15
using Rdmp.Core.DataLoad.Engine.Mutilators;
16
using Rdmp.Core.ReusableLibraryCode.Checks;
17
using Rdmp.Core.ReusableLibraryCode.Progress;
18

19
namespace Rdmp.Core.DataLoad.Modules.Mutilators;
20

21
public abstract class MatchingTablesMutilatorWithDataLoadJob : IPluginMutilateDataTables
22
{
23
    private readonly LoadStage[] _allowedStages;
24

25
    [DemandsInitialization(
26
        "All tables matching this pattern which have a TableInfo defined in the load will be affected by this mutilation",
27
        DefaultValue = ".*")]
28
    public Regex TableRegexPattern { get; set; }
98✔
29

30
    [DemandsInitialization(
31
        "Overrides TableRegexPattern.  If this is set then the tables chosen will be mutilated instead")]
32
    public TableInfo[] OnlyTables { get; set; }
42✔
33

34
    [DemandsInitialization("How long to allow for each command to execute in seconds", DefaultValue = 600)]
35
    public int Timeout { get; set; }
56✔
36

37
    protected DiscoveredDatabase DbInfo;
38
    private LoadStage _loadStage;
39

40
    protected MatchingTablesMutilatorWithDataLoadJob(params LoadStage[] allowedStages)
28✔
41
    {
42
        _allowedStages = allowedStages;
28✔
43
    }
28✔
44

45
    public virtual void LoadCompletedSoDispose(ExitCodeType exitCode, IDataLoadEventListener postLoadEventsListener)
46
    {
47
    }
14✔
48

49
    public void Initialize(DiscoveredDatabase dbInfo, LoadStage loadStage)
50
    {
51
        if (_allowedStages != null && !_allowedStages.Contains(loadStage))
28!
NEW
52
            throw new NotSupportedException($"Mutilation {GetType()} is not allowed at stage {loadStage}");
×
53

54
        _loadStage = loadStage;
28✔
55
        DbInfo = dbInfo;
28✔
56
    }
28✔
57

58
    public ExitCodeType Mutilate(IDataLoadJob job)
59
    {
60
        if (TableRegexPattern != null)
14✔
61
            TableRegexPattern = new Regex(TableRegexPattern.ToString(), RegexOptions.IgnoreCase);
14✔
62

63
        foreach (var tableInfo in job.RegularTablesToLoad)
56✔
64
            if (OnlyTables != null && OnlyTables.Length != 0)
14!
65
            {
NEW
66
                if (OnlyTables.Contains(tableInfo))
×
NEW
67
                    FireMutilate(tableInfo, job);
×
68
            }
69
            else if (TableRegexPattern == null)
14!
70
            {
NEW
71
                throw new Exception("You must specify either TableRegexPattern or OnlyTables");
×
72
            }
73
            else if (TableRegexPattern.IsMatch(tableInfo.GetRuntimeName()))
14✔
74
            {
75
                FireMutilate(tableInfo, job);
14✔
76
            }
77

78
        return ExitCodeType.Success;
14✔
79
    }
80

81
    private void FireMutilate(ITableInfo tableInfo, IDataLoadJob job)
82
    {
83
        var tbl = DbInfo.ExpectTable(tableInfo.GetRuntimeName(_loadStage, job.Configuration.DatabaseNamer));
14✔
84

85
        if (!tbl.Exists())
14!
86
        {
NEW
87
            job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error,
×
NEW
88
                $"Expected table {tbl} did not exist in RAW"));
×
89
        }
90
        else
91
        {
92
            job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information,
14✔
93
                $"About to run {GetType()} mutilation on table {tbl}"));
14✔
94
            var sw = new Stopwatch();
14✔
95
            sw.Start();
14✔
96
            MutilateTable(job, tableInfo, tbl);
14✔
97
            sw.Stop();
14✔
98
            job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information,
14✔
99
                $"{GetType()} mutilation on table {tbl} completed after {sw.ElapsedMilliseconds} ms"));
14✔
100
        }
101
    }
14✔
102

103
    protected abstract void MutilateTable(IDataLoadJob job, ITableInfo tableInfo, DiscoveredTable table);
104

105
    public virtual void Check(ICheckNotifier notifier)
106
    {
NEW
107
        if (TableRegexPattern == null && (OnlyTables == null || OnlyTables.Length == 0))
×
NEW
108
            notifier.OnCheckPerformed(new CheckEventArgs(
×
NEW
109
                "You must specify either a regex pattern (TableRegexPattern) or set OnlyTables for identifying tables which need to be processed",
×
NEW
110
                CheckResult.Fail));
×
NEW
111
    }
×
112
}
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