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

HicServices / RDMP / 20714560420

05 Jan 2026 11:53AM UTC coverage: 57.198% (-0.2%) from 57.378%
20714560420

push

github

JFriel
update deps

11495 of 21585 branches covered (53.25%)

Branch coverage included in aggregate %.

32571 of 55456 relevant lines covered (58.73%)

17789.06 hits per line

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

57.97
/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
        }
73
        else
74
        {
75
            var opts = AggregateBuilderOptionsFactory.Create(aggregate);
6✔
76
            AggregateDimension match;
77

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

82
                if (possible.Length == 0)
×
83
                    throw new Exception($"There are no AggregateDimensions in {aggregate} that can be used as a Pivot");
×
84

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

87
                if (match == null) return;
×
88
            }
89
            else
90
            {
91
                match = aggregate.AggregateDimensions.FirstOrDefault(a => string.Equals(column, a.ToString()));
16✔
92
                if (match == null)
6✔
93
                    throw new Exception(
2✔
94
                        $"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✔
95
            }
96

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

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

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

107
            aggregate.PivotOnDimensionID = match.ID;
2✔
108
        }
109

110
        aggregate.SaveToDatabase();
4✔
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