• 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

82.0
/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandSetExtendedProperty.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.Linq;
9
using Rdmp.Core.Curation.Data;
10
using Rdmp.Core.MapsDirectlyToDatabaseTable;
11
using Rdmp.Core.Repositories.Construction;
12

13
namespace Rdmp.Core.CommandExecution.AtomicCommands;
14

15
/// <summary>
16
/// Creates or Updates an <see cref="ExtendedProperty"/> declaration on any RDMP object.
17
/// </summary>
18
public sealed class ExecuteCommandSetExtendedProperty : BasicCommandExecution, IAtomicCommand
19
{
20
    private readonly IMapsDirectlyToDatabaseTable[] _setOn;
21
    private readonly string _propertyName;
22
    private readonly string _value;
23

24
    /// <summary>
25
    /// Set to true to prompt user for the <see cref="_value"/> at execution time (e.g. for interactive UIs)
26
    /// </summary>
27
    internal bool PromptForValue { get; init; }
10✔
28

29
    /// <summary>
30
    /// If <see cref="PromptForValue"/> is set to true then this is the description to show to the user
31
    /// that explains what they should be entering as a <see cref="_value"/>
32
    /// </summary>
33
    internal string PromptForValueTaskDescription { get; init; }
×
34

35
    [UseWithObjectConstructor]
36
    public ExecuteCommandSetExtendedProperty(IBasicActivateItems activator,
37
        [DemandsInitialization("The object(s) that you want to set the property on")]
38
        IMapsDirectlyToDatabaseTable[] setOn,
39
        [DemandsInitialization("The property you want to set")]
40
        string propertyName,
41
        [DemandsInitialization("The value to store")]
42
        string value,
43
        [DemandsInitialization(
44
            "True to validate propertyName against known properties.  False to allow custom named properties.  Defaults to true.",
45
            DefaultValue = true)]
46
        bool strict = true
47
    )
48
        : base(activator)
8✔
49
    {
50
        if (strict && !ExtendedProperty.KnownProperties.Contains(propertyName))
8✔
51
            SetImpossible(
2✔
52
                $"{propertyName} is not a known property.  Known properties are: {Environment.NewLine}{string.Join(Environment.NewLine, ExtendedProperty.KnownProperties)}");
2✔
53
        _setOn = setOn;
8✔
54
        _propertyName = propertyName;
8✔
55
        _value = value;
8✔
56
    }
8✔
57

58
    public override string GetCommandName() => !string.IsNullOrWhiteSpace(OverrideCommandName)
×
59
        ? OverrideCommandName
×
60
        : $"Set {_propertyName}";
×
61

62
    public override void Execute()
63
    {
64
        base.Execute();
6✔
65

66
        var catRepo = BasicActivator.RepositoryLocator.CatalogueRepository;
6✔
67
        var newValue = _value;
6✔
68

69
        foreach (var o in _setOn)
32✔
70
        {
71
            var props = catRepo.GetExtendedProperties(_propertyName, o).ToArray();
10✔
72
            var oldValue = props.FirstOrDefault()?.Value;
10✔
73

74
            if (PromptForValue && !BasicActivator.TypeText(new DialogArgs
10!
75
            {
10✔
76
                WindowTitle = _propertyName,
10✔
77
                TaskDescription = PromptForValueTaskDescription
10✔
78
            }, int.MaxValue, oldValue, out newValue, false))
10✔
79
                // user cancelled entering some text
80
                return;
×
81

82
            // delete any old versions
83
            foreach (var d in props) d.DeleteInDatabase();
32✔
84

85
            // Creates the new property into the db
86
            // If the Value passed was null just leave it deleted
87
            if (!string.IsNullOrWhiteSpace(newValue)) _ = new ExtendedProperty(catRepo, o, _propertyName, newValue);
16✔
88
        }
89

90
        if (_setOn.Any())
6✔
91
            Publish(_setOn.First());
6✔
92
    }
6✔
93
}
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