Skip to content

Commit

Permalink
add versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
JFriel committed Jan 27, 2025
1 parent afa6b6a commit 24b3377
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 47 deletions.
68 changes: 42 additions & 26 deletions Rdmp.Core/CommandExecution/AtomicCommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,39 +502,55 @@ public IEnumerable<IAtomicCommand> CreateCommands(object o)

if (Is(o, out LoadMetadata lmd))
{
yield return new ExecuteCommandExportObjectsToFile(_activator, new IMapsDirectlyToDatabaseTable[] { lmd });

yield return new ExecuteCommandOverrideRawServer(_activator, lmd);
yield return new ExecuteCommandCreateNewLoadMetadata(_activator);
var reservedTest = lmd.AllowReservedPrefix ? "Drop" : "Allow";
yield return new ExecuteCommandToggleAllowReservedPrefixForLoadMetadata(lmd)
if (lmd.RootLoadMetadata_ID is null)
{
OverrideCommandName=$"{reservedTest} Reserved Prefix Columns"
};
yield return new ExecuteCommandExportObjectsToFile(_activator, new IMapsDirectlyToDatabaseTable[] { lmd });

yield return new ExecuteCommandSetGlobalDleIgnorePattern(_activator) { SuggestedCategory = Advanced };
yield return new ExecuteCommandSetIgnoredColumns(_activator, lmd) { SuggestedCategory = Advanced };
yield return new ExecuteCommandSetIgnoredColumns(_activator, lmd, null)
{ OverrideCommandName = "Clear Ignored Columns", SuggestedCategory = Advanced };
yield return new ExecuteCommandOverrideRawServer(_activator, lmd);
yield return new ExecuteCommandCreateNewLoadMetadata(_activator);
var reservedTest = lmd.AllowReservedPrefix ? "Drop" : "Allow";
yield return new ExecuteCommandToggleAllowReservedPrefixForLoadMetadata(lmd)
{
OverrideCommandName = $"{reservedTest} Reserved Prefix Columns"
};
yield return new ExecuteCommandCreateLoadMetadataVersion(_activator, lmd)
{
OverrideCommandName = "Save Version"
};
yield return new ExecuteCommandCloneLoadMetadata(_activator, lmd)
{
OverrideCommandName = "Clone Load Metadata"
};

yield return new ExecuteCommandSetExtendedProperty(_activator, new[] { lmd },
ExtendedProperty.PersistentRaw, null)
{
OverrideCommandName = "Persistent RAW",
PromptForValue = true,
PromptForValueTaskDescription = ExtendedProperty.PersistentRawDescription,
SuggestedCategory = Advanced
};
yield return new ExecuteCommandSetGlobalDleIgnorePattern(_activator) { SuggestedCategory = Advanced };
yield return new ExecuteCommandSetIgnoredColumns(_activator, lmd) { SuggestedCategory = Advanced };
yield return new ExecuteCommandSetIgnoredColumns(_activator, lmd, null)
{ OverrideCommandName = "Clear Ignored Columns", SuggestedCategory = Advanced };

yield return new ExecuteCommandSet(_activator, lmd,
typeof(LoadMetadata).GetProperty(nameof(LoadMetadata.IgnoreTrigger)))
yield return new ExecuteCommandSetExtendedProperty(_activator, new[] { lmd },
ExtendedProperty.PersistentRaw, null)
{
OverrideCommandName = "Persistent RAW",
PromptForValue = true,
PromptForValueTaskDescription = ExtendedProperty.PersistentRawDescription,
SuggestedCategory = Advanced
};

yield return new ExecuteCommandSet(_activator, lmd,
typeof(LoadMetadata).GetProperty(nameof(LoadMetadata.IgnoreTrigger)))
{
OverrideCommandName = $"Ignore Trigger (Current value:{lmd.IgnoreTrigger})",
SuggestedCategory = Advanced
};
}
else
{
OverrideCommandName = $"Ignore Trigger (Current value:{lmd.IgnoreTrigger})",
SuggestedCategory = Advanced
};
yield return new ExecuteCommandRestoreLoadMetadataVersion(_activator, lmd)
{
OverrideCommandName = "Restore Version"};
}
}


if (Is(o, out LoadMetadataScheduleNode scheduleNode))
yield return new ExecuteCommandCreateNewLoadProgress(_activator, scheduleNode.LoadMetadata);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Rdmp.Core.Curation.Data.DataLoad;
using Rdmp.Core.Curation.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rdmp.Core.CommandExecution.AtomicCommands;

public class ExecuteCommandCloneLoadMetadata : BasicCommandExecution
{
private LoadMetadata _loadMetadata;
private IBasicActivateItems _activator;
public ExecuteCommandCloneLoadMetadata(IBasicActivateItems activator,[DemandsInitialization("The LoadMetadata to clone")] LoadMetadata loadMetadata)
{

_loadMetadata = loadMetadata;
_activator = activator;
}

public override void Execute()
{
base.Execute();
var lmd = _loadMetadata.Clone();
lmd.Name = lmd.Name + " (Clone)";
lmd.SaveToDatabase();
_activator.Publish(lmd);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ namespace Rdmp.Core.CommandExecution.AtomicCommands;
public class ExecuteCommandCreateLoadMetadataVersion: BasicCommandExecution
{
private LoadMetadata _loadMetadata;
public ExecuteCommandCreateLoadMetadataVersion([DemandsInitialization("The LoadMetadata to update")] LoadMetadata loadMetadata)
private IBasicActivateItems _activator;
public ExecuteCommandCreateLoadMetadataVersion(IBasicActivateItems activator,[DemandsInitialization("The LoadMetadata to version")] LoadMetadata loadMetadata)
{

_loadMetadata = loadMetadata;
_activator = activator;
}

public override void Execute()
Expand All @@ -24,7 +26,8 @@ public override void Execute()
{
throw new Exception("Must Use Root LoadMetadata to create Version");
}
var lmd = _loadMetadata.Clone();
var lmd = _loadMetadata.SaveNewVersion();
lmd.SaveToDatabase();
_activator.Publish(lmd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public override void Execute()
else
return;
}
_loadMetadata.Clone();
var newTask = new ProcessTask(BasicActivator.RepositoryLocator.CatalogueRepository, _loadMetadata, _loadStage)
{
Path = _type.FullName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public override void Execute()
throw new ArgumentOutOfRangeException($"Unexpected _taskType:{_taskType}");
}
}
_loadMetadata.Clone();
var task = new ProcessTask((ICatalogueRepository)_loadMetadata.Repository, _loadMetadata, _loadStage)
{
ProcessTaskType = _taskType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,8 @@ public override void Execute()

foreach (var d in _targets)
{
var x = d.GetType();
if (d.GetType() == typeof(ProcessTask))
{
var newVersion = (IDisableable)((IVersionable)d).SaveNewVersion();
newVersion.IsDisabled = true;
newVersion.SaveToDatabase();
}
else
{
d.IsDisabled = !d.IsDisabled;
d.SaveToDatabase();
}
d.IsDisabled = !d.IsDisabled;
d.SaveToDatabase();
}

var toRefresh = _targets.FirstOrDefault();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Rdmp.Core.Curation.Data.DataLoad;
using Rdmp.Core.Curation.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Org.BouncyCastle.Pqc.Crypto.Lms;

namespace Rdmp.Core.CommandExecution.AtomicCommands;

public class ExecuteCommandRestoreLoadMetadataVersion : BasicCommandExecution
{
private LoadMetadata _loadMetadata;
private IBasicActivateItems _activator;
public ExecuteCommandRestoreLoadMetadataVersion(IBasicActivateItems activator, [DemandsInitialization("The LoadMetadata to version")] LoadMetadata loadMetadata)
{

_loadMetadata = loadMetadata;
_activator = activator;
}

public override void Execute()
{
if (!_activator.YesNo("Replace root Load Metadata with this configuration?","Resotre Load Metadata Version")) return;
base.Execute();
if (_loadMetadata.RootLoadMetadata_ID is null)
{
throw new Exception("Must Use a versioned LoadMetadata to create Version");
}
LoadMetadata lmd = (LoadMetadata)_activator.RepositoryLocator.CatalogueRepository.GetObjectByID(typeof(LoadMetadata), (int)_loadMetadata.RootLoadMetadata_ID);
if (lmd is null)
{
throw new Exception("Could not find root load metadata");

}
foreach (ProcessTask task in lmd.ProcessTasks)
{
task.DeleteInDatabase();
}
foreach(ProcessTask task in _loadMetadata.ProcessTasks)
{
task.Clone(lmd);
}
lmd.SaveToDatabase();
_activator.Publish(lmd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public ExecuteCommandToggleAllowReservedPrefixForLoadMetadata([DemandsInitializa
public override void Execute()
{
base.Execute();
_loadMetadata.Clone();
_loadMetadata.AllowReservedPrefix = !_loadMetadata.AllowReservedPrefix;
_loadMetadata.SaveToDatabase();
}
Expand Down
5 changes: 5 additions & 0 deletions Rdmp.Core/Curation/Data/DataLoad/LoadMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ public LoadMetadata Clone()
};
lmd.SaveToDatabase();
//link to catalogue
foreach(var catalogue in this.GetAllCatalogues())
{
lmd.LinkToCatalogue(catalogue);
}
//process task
var pts = CatalogueRepository.GetAllObjectsWhere<ProcessTask>("LoadMetadata_ID", this.ID);
foreach(ProcessTask pt in pts)
Expand Down Expand Up @@ -510,6 +514,7 @@ public DatabaseEntity SaveNewVersion()
{
var lmd = this.Clone();
lmd.RootLoadMetadata_ID = this.RootLoadMetadata_ID != null ? this.RootLoadMetadata_ID : this.ID;
lmd.Name = $"{this.Name} - {DateTime.Now}";
lmd.SaveToDatabase();
return lmd;
}
Expand Down
2 changes: 0 additions & 2 deletions Rdmp.Core/Curation/Data/DataLoad/ProcessTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public ProcessTask(ICatalogueRepository repository, ILoadMetadata parent, LoadSt
repository.InsertAndHydrate(this, new Dictionary<string, object>
{
{ "LoadMetadata_ID", parent.RootLoadMetadata_ID??parent.ID },
{ "LoadMetadataVersion", parent.RootLoadMetadata_ID != null?parent.ID:0 },
{ "ProcessTaskType", ProcessTaskType.Executable.ToString() },
{ "LoadStage", stage },
{ "Name", $"New Process{Guid.NewGuid()}" },
Expand All @@ -186,7 +185,6 @@ public ProcessTask(ICatalogueRepository repository, ILoadMetadata parent, LoadSt
repository.InsertAndHydrate(this, new Dictionary<string, object>
{
{ "LoadMetadata_ID", parent.RootLoadMetadata_ID??parent.ID },
{ "LoadMetadataVersion", parent.RootLoadMetadata_ID != null?parent.ID:0 },
{ "ProcessTaskType", ProcessTaskType.Executable.ToString() },
{ "LoadStage", stage },
{ "Name", $"New Process{Guid.NewGuid()}" },
Expand Down
3 changes: 3 additions & 0 deletions Rdmp.Core/Icons/IconProvision/CatalogueIcons.resx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@
<data name="CatalogueFolder" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\CatalogueFolder.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="LoadMetadataVersionNode" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\CatalogueFolder.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="CatalogueItem" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\CatalogueItem.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions Rdmp.Core/Icons/IconProvision/RDMPConcept.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public enum RDMPConcept
AllProcessTasksUsedByLoadMetadataNode,
AllCataloguesUsedByLoadMetadataNode,
LoadMetadataScheduleNode,
LoadMetadataVersionNode,
Logging,

GetFilesStage,
Expand Down
14 changes: 12 additions & 2 deletions Rdmp.Core/Providers/CatalogueChildProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public CatalogueChildProvider(ICatalogueRepository repository, IChildProvider[]

ReportProgress("Build Catalogue Folder Root");

LoadMetadataRootFolder = FolderHelper.BuildFolderTree(AllLoadMetadatas);
LoadMetadataRootFolder = FolderHelper.BuildFolderTree(AllLoadMetadatas.Where(lmd => lmd.RootLoadMetadata_ID is null).ToArray());
AddChildren(LoadMetadataRootFolder, new DescendancyList(LoadMetadataRootFolder));

CohortIdentificationConfigurationRootFolder =
Expand Down Expand Up @@ -856,7 +856,7 @@ private void AddChildren(FolderNode<LoadMetadata> folder, DescendancyList descen
AddChildren(child, descendancy.Add(child));

//add loads in folder
foreach (var lmd in folder.ChildObjects) AddChildren(lmd, descendancy.Add(lmd));
foreach (var lmd in folder.ChildObjects.Where(lmd => lmd.RootLoadMetadata_ID == null).ToArray()) AddChildren(lmd, descendancy.Add(lmd));
// Children are the folders + objects
AddToDictionaries(new HashSet<object>(
folder.ChildFolders.Cast<object>()
Expand Down Expand Up @@ -929,6 +929,10 @@ private void AddChildren(LoadMetadata lmd, DescendancyList descendancy)
AddChildren(processTasksNode, descendancy.Add(processTasksNode));
childObjects.Add(processTasksNode);

var versionsNode = new LoadMetadataVersionNode(lmd);
AddChildren(versionsNode, descendancy.Add(versionsNode));
childObjects.Add(versionsNode);

childObjects.Add(new LoadDirectoryNode(lmd));

AddToDictionaries(new HashSet<object>(childObjects), descendancy);
Expand Down Expand Up @@ -1017,6 +1021,12 @@ private void AddChildren(ProcessTask procesTask, DescendancyList descendancy)
AddToDictionaries(new HashSet<object>(args), descendancy);
}

private void AddChildren(LoadMetadataVersionNode LoadMetadataVersionNode, DescendancyList descendancy)
{
LoadMetadataVersionNode.LoadMetadataVersions = AllLoadMetadatas.Where(lmd => lmd.RootLoadMetadata_ID == LoadMetadataVersionNode.LoadMetadata.ID).ToList();
AddToDictionaries(LoadMetadataVersionNode.LoadMetadataVersions.Cast<object>().ToHashSet(), descendancy);
}

private void AddChildren(AllCataloguesUsedByLoadMetadataNode allCataloguesUsedByLoadMetadataNode,
DescendancyList descendancy)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) The University of Dundee 2018-2019
// 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 System.Collections.Generic;
using Rdmp.Core.Curation.Data;
using Rdmp.Core.Curation.Data.Cohort;
using Rdmp.Core.Curation.Data.DataLoad;

namespace Rdmp.Core.Providers.Nodes.LoadMetadataNodes;

/// <summary>
/// Collection of all the <see cref="Catalogue"/>s which are currently associated with a given <see cref="Curation.Data.DataLoad.LoadMetadata"/>. This governs
/// which tables are created in RAW=>STAGING=>LIVE.
/// </summary>
public class LoadMetadataVersionNode : Node, IOrderable
{
public LoadMetadata LoadMetadata { get; }

public int Order
{
get => 1;
set { }
}

public List<LoadMetadata> LoadMetadataVersions { get; set; }

public LoadMetadataVersionNode(LoadMetadata lmd)
{
LoadMetadata = lmd;
}

public override string ToString() => "Versions";

protected bool Equals(LoadMetadataVersionNode other) => Equals(LoadMetadata, other.LoadMetadata);

public override bool Equals(object obj)
{
if (obj is null) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != GetType()) return false;
return Equals((LoadMetadataVersionNode)obj);
}

public override int GetHashCode() => HashCode.Combine(LoadMetadata);
}
18 changes: 18 additions & 0 deletions Rdmp.Core/ReusableLibraryCode/IVersionable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Rdmp.Core.Curation.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rdmp.Core.ReusableLibraryCode;

internal interface IVersionable
{

/// <summary>
///
/// </summary>
/// <returns></returns>
DatabaseEntity SaveNewVersion();
}

0 comments on commit 24b3377

Please sign in to comment.