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

HicServices / RDMP / 13332661093

14 Feb 2025 03:47PM UTC coverage: 57.416%. Remained the same
13332661093

Pull #2135

github

jas88
Redundant string interpolations
Pull Request #2135: Feature/fixusings

11358 of 21338 branches covered (53.23%)

Branch coverage included in aggregate %.

41 of 47 new or added lines in 13 files covered. (87.23%)

5 existing lines in 1 file now uncovered.

32286 of 54676 relevant lines covered (59.05%)

17435.23 hits per line

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

59.15
/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandSetPivot.cs
1
// Copyright (c) The University of Dundee 2018-2021
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.Aggregation;
10
using Rdmp.Core.QueryBuilding.Options;
11
using Rdmp.Core.Repositories.Construction;
12

13
namespace Rdmp.Core.CommandExecution.AtomicCommands;
14

15
/// <summary>
16
/// Changes the pivot dimension of an aggregate graph
17
/// </summary>
18
public class ExecuteCommandSetPivot : BasicCommandExecution
19
{
20
    private readonly AggregateConfiguration aggregate;
21
    private readonly string column;
22
    private readonly bool askAtRuntime;
23

24
    public ExecuteCommandSetPivot(IBasicActivateItems basicActivator, AggregateConfiguration aggregate) : base(
×
25
        basicActivator)
×
26
    {
27
        this.aggregate = aggregate;
×
28

29
        // don't let them try to set a pivot on a cohort aggregate configuration but do let them clear it if it somehow ended up with one
30
        if (aggregate.IsCohortIdentificationAggregate)
×
31
        {
32
            SetImpossible(
×
33
                $"AggregateConfiguration {aggregate} is a cohort identification aggregate and so cannot have a pivot");
×
34
            return;
×
35
        }
36

37
        askAtRuntime = true;
×
38
    }
×
39

40

41
    [UseWithObjectConstructor]
42
    public ExecuteCommandSetPivot(IBasicActivateItems basicActivator, AggregateConfiguration aggregate, string column) :
43
        base(basicActivator)
8✔
44
    {
45
        this.aggregate = aggregate;
8✔
46
        this.column = column;
8✔
47

48
        if (!string.IsNullOrWhiteSpace(column))
8✔
49
        {
50
            // don't let them try to set a pivot on a cohort aggregate configuration but do let them clear it if it somehow ended up with one
51
            if (aggregate.IsCohortIdentificationAggregate)
6!
52
            {
53
                SetImpossible(
×
54
                    $"AggregateConfiguration {aggregate} is a cohort identification aggregate and so cannot have a pivot");
×
55
                return;
×
56
            }
57
        }
58
        else
59
        {
60
            if (aggregate.PivotOnDimensionID == null)
2!
61
                SetImpossible($"AggregateConfiguration {aggregate} does not have a pivot to clear");
×
62
        }
63
    }
8✔
64

65
    public override void Execute()
66
    {
67
        base.Execute();
8✔
68

69
        if (string.IsNullOrWhiteSpace(column) && !askAtRuntime)
8✔
70
        {
71
            aggregate.PivotOnDimensionID = null;
2✔
72
            aggregate.SaveToDatabase();
2✔
73
        }
74
        else
75
        {
76
            var opts = AggregateBuilderOptionsFactory.Create(aggregate);
6✔
77
            AggregateDimension match = null;
6✔
78

79
            if (askAtRuntime)
6!
80
            {
UNCOV
81
                var possible = aggregate.AggregateDimensions.Where(d => !d.IsDate()).ToArray();
×
82

83
                if (!possible.Any())
×
UNCOV
84
                    throw new Exception($"There are no AggregateDimensions in {aggregate} that can be used as a Pivot");
×
85

UNCOV
86
                match = (AggregateDimension)BasicActivator.SelectOne("Choose pivot dimension", possible);
×
87

UNCOV
88
                if (match == null) return;
×
89
            }
90
            else
91
            {
92
                match = aggregate.AggregateDimensions.FirstOrDefault(a => string.Equals(column, a.ToString()));
16✔
93
                if (match == null)
6✔
94
                    throw new Exception(
2✔
95
                        $"Could not find AggregateDimension {column} in Aggregate {aggregate} so could not set it as a pivot dimension.  Try adding the column to the aggregate first");
2✔
96
            }
97

98
            if (match.IsDate())
4✔
99
                throw new Exception(
2✔
100
                    $"AggregateDimension {match} is a Date so cannot set it as a Pivot for Aggregate {aggregate}");
2✔
101

102
            var enable = opts.ShouldBeEnabled(AggregateEditorSection.PIVOT, aggregate);
2✔
103

104
            if (!enable)
2!
105
                throw new Exception(
×
UNCOV
106
                    $"Current state of Aggregate {aggregate} does not support having a Pivot Dimension");
×
107

108
            aggregate.PivotOnDimensionID = match.ID;
2✔
109
            aggregate.SaveToDatabase();
2✔
110
        }
111

112
        Publish(aggregate);
4✔
113
    }
4✔
114
}
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