-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathExecuteCommandLinkColumnInfoToDataset.cs
More file actions
41 lines (35 loc) · 2.01 KB
/
ExecuteCommandLinkColumnInfoToDataset.cs
File metadata and controls
41 lines (35 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) The University of Dundee 2018-2023
// This file is part of the Research Data Management Platform (RDMP).
// 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.
// 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.
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
using System;
using Rdmp.Core.Curation.Data;
using System.Linq;
namespace Rdmp.Core.CommandExecution.AtomicCommands;
public sealed class ExecuteCommandLinkColumnInfoToDataset : BasicCommandExecution
{
private readonly ColumnInfo _columnInfo;
private readonly Curation.Data.Datasets.Dataset _dataset;
private readonly bool _linkAll;
public ExecuteCommandLinkColumnInfoToDataset(IBasicActivateItems activator, [DemandsInitialization("The column to link")] ColumnInfo columnInfo, [DemandsInitialization("The dataset to link to")] Curation.Data.Datasets.Dataset dataset, bool linkAllOtherColumns = true) : base(activator)
{
_columnInfo = columnInfo;
_dataset = dataset;
_linkAll = linkAllOtherColumns;
}
public override void Execute()
{
base.Execute();
_columnInfo.Dataset_ID = _dataset.ID;
_columnInfo.SaveToDatabase();
if (!_linkAll) return;
var databaseName = _columnInfo.Name[.._columnInfo.Name.LastIndexOf('.')];
var catalogueItems = _columnInfo.CatalogueRepository.GetAllObjects<ColumnInfo>().Where(ci => ci.Name[..ci.Name.LastIndexOf(".", StringComparison.Ordinal)] == databaseName);
foreach (var ci in catalogueItems)
{
ci.Dataset_ID = _dataset.ID;
ci.SaveToDatabase();
}
}
}