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

HicServices / RDMP / 13235788803

10 Feb 2025 07:36AM UTC coverage: 57.402% (+0.01%) from 57.389%
13235788803

push

github

web-flow
Task/rdmp 265 version data loads (#2125)

* basic versions

* add basic versioning

* add versioning

* rename file

* update changelog

* fix catalogue

* fix sql

* fix up sql

* update delete

* add tests

* tidy up

* fiz clone

* fix up tree structure

* clone version

* tidy up

11338 of 21302 branches covered (53.23%)

Branch coverage included in aggregate %.

966 of 1168 new or added lines in 8 files covered. (82.71%)

3 existing lines in 3 files now uncovered.

32238 of 54612 relevant lines covered (59.03%)

17067.33 hits per line

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

0.0
/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandCreateNewFileBasedProcessTask.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 Rdmp.Core.Curation;
11
using Rdmp.Core.Curation.Data.DataLoad;
12
using Rdmp.Core.Icons.IconOverlays;
13
using Rdmp.Core.Icons.IconProvision;
14
using Rdmp.Core.Repositories;
15
using Rdmp.Core.ReusableLibraryCode.Icons.IconProvision;
16
using SixLabors.ImageSharp;
17
using SixLabors.ImageSharp.PixelFormats;
18

19
namespace Rdmp.Core.CommandExecution.AtomicCommands;
20

21
public class ExecuteCommandCreateNewFileBasedProcessTask : BasicCommandExecution
22
{
23
    private readonly ProcessTaskType _taskType;
24
    private readonly LoadMetadata _loadMetadata;
25
    private readonly LoadStage _loadStage;
26
    private readonly LoadDirectory _loadDirectory;
27
    private FileInfo _file;
28

29
    public ExecuteCommandCreateNewFileBasedProcessTask(IBasicActivateItems activator, ProcessTaskType taskType,
30
        LoadMetadata loadMetadata, LoadStage loadStage, FileInfo file = null) : base(activator)
×
31
    {
32
        _taskType = taskType;
×
33
        _loadMetadata = loadMetadata;
×
34
        _loadStage = loadStage;
×
35

36
        try
37
        {
38
            _loadDirectory = new LoadDirectory(_loadMetadata.LocationOfForLoadingDirectory, _loadMetadata.LocationOfForArchivingDirectory, _loadMetadata.LocationOfExecutablesDirectory, _loadMetadata.LocationOfCacheDirectory );
×
39
        }
×
40
        catch (Exception e )
×
41
        {
42
            Console.WriteLine(e.Message);
×
43
            SetImpossible("Could not construct LoadDirectory");
×
44
        }
×
45

46
        ProcessTaskType[] AcceptedProcessTaskTypes = { ProcessTaskType.SQLFile, ProcessTaskType.Executable, ProcessTaskType.SQLBakFile };
×
47
        if (!AcceptedProcessTaskTypes.Contains(taskType))
×
48
            SetImpossible("Only SQLFile, SqlBakFile and Executable task types are supported by this command");
×
49

50
        if (!ProcessTask.IsCompatibleStage(taskType, loadStage))
×
51
            SetImpossible($"You cannot run {taskType} in {loadStage}");
×
52

53
        _file = file;
×
54
    }
×
55

56
    public override void Execute()
57
    {
58
        base.Execute();
×
59

60
        if (_file == null)
×
61
        {
62
            if (_taskType == ProcessTaskType.SQLBakFile)
×
63
            {
64
                _file = BasicActivator.SelectFile("Enter the .bak file's path", "*.bak", "*.bak");
×
65
            }
66
            else if (_taskType == ProcessTaskType.SQLFile)
×
67
            {
68
                if (!BasicActivator.TypeText("Enter a name for the SQL file", "File name", 100, "myscript.sql",
×
69
                        out var selected, false)) return;
×
70

71
                var target = Path.Combine(_loadDirectory.ExecutablesPath.FullName, selected);
×
72

73
                if (!target.EndsWith(".sql"))
×
74
                    target += ".sql";
×
75

76
                //create it if it doesn't exist
77
                if (!File.Exists(target))
×
78
                    File.WriteAllText(target, "/*todo Type some SQL*/");
×
79

80
                _file = new FileInfo(target);
×
81

82
            }
83
            else if (_taskType == ProcessTaskType.Executable)
×
84
            {
85
                _file = BasicActivator.SelectFile("Enter executable's path", "Executables", "*.exe");
×
86

87
                // they didn't pick one
88
                if (_file == null)
×
89
                    return;
×
90

91
                if (!_file.Exists)
×
92
                    throw new FileNotFoundException("File did not exist");
×
93
            }
94
            else
95
            {
96
                throw new ArgumentOutOfRangeException($"Unexpected _taskType:{_taskType}");
×
97
            }
98
        }
UNCOV
99
        var task = new ProcessTask((ICatalogueRepository)_loadMetadata.Repository, _loadMetadata, _loadStage)
×
100
        {
×
101
            ProcessTaskType = _taskType,
×
102
            Path = _file.FullName
×
103
        };
×
104
        SaveAndShow(task);
×
105
    }
×
106

107
    private void SaveAndShow(ProcessTask task)
108
    {
109
        task.Name = $"Run '{Path.GetFileName(task.Path)}'";
×
110
        task.SaveToDatabase();
×
111

112
        Publish(_loadMetadata);
×
113
        Activate(task);
×
114
    }
×
115

116
    public override string GetCommandName()
117
    {
118
        return _taskType switch
×
119
        {
×
120
            ProcessTaskType.Executable => "Add Run .exe File Task",
×
121
            ProcessTaskType.SQLFile => "Add Run SQL Script Task",
×
122
            ProcessTaskType.SQLBakFile => "Add SQL backup File Task",
×
123
            _ => throw new ArgumentOutOfRangeException()
×
124
        };
×
125
    }
126

127
    public override Image<Rgba32> GetImage(IIconProvider iconProvider)
128
    {
129
        return _taskType switch
×
130
        {
×
131
            ProcessTaskType.SQLFile => iconProvider.GetImage(RDMPConcept.SQL, OverlayKind.Add),
×
132
            ProcessTaskType.SQLBakFile => iconProvider.GetImage(RDMPConcept.SQL, OverlayKind.Add), //todo maybe better
×
133
            ProcessTaskType.Executable => IconOverlayProvider.GetOverlayNoCache(
×
134
                Image.Load<Rgba32>(CatalogueIcons.Exe), OverlayKind.Add),
×
135
            _ => null
×
136
        };
×
137
    }
138
}
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