Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/rdmp 190 offer change to depricated catalogue #1848

Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


# Changelog
All notable changes to this project will be documented in this file.

Expand All @@ -11,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add Key-Value store for instance settings
- Allow for Re-extractions of projects to a database, see [ExecuteFullExtractionToDatabaseMSSql](Documentation\DataExtractions\ExecuteFullExtractionToDatabaseMSSql.md)
- When cloning an ExtractionConfiguration with a deprecated catalogue, the GUI will ask if you want to replace the deprecated catalogue with the known replacement
- Add ability to customise LoadMetdata Folder Location. See [LoadMetadata](Documentation\DataLoadEngine\LoadMetadata.md)
- Add ability to point a catalogue to a new data source [Documentation](./Documentation/Catalogues/UpdateCatalogueDataLocation.md)
- Allow DQE graphs to be scrollable and scalable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright (c) The University of Dundee 2018-2019
// Copyright (c) The University of Dundee 2018-2024
// 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 System.Linq;
using Rdmp.Core.Curation.Data;
using Rdmp.Core.DataExport.Data;
Expand All @@ -17,12 +19,53 @@ namespace Rdmp.Core.CommandExecution.AtomicCommands;
public class ExecuteCommandCloneExtractionConfiguration : BasicCommandExecution, IAtomicCommand
{
private readonly ExtractionConfiguration _extractionConfiguration;
private readonly IBasicActivateItems _activeItems;
private readonly List<IExtractableDataSet> toRemove = [];
private readonly List<Catalogue> toAdd = [];
private void CheckForDeprecatedCatalogues()
{
if (_extractionConfiguration.SelectedDataSets.Any(sd => sd.GetCatalogue().IsDeprecated) && _activeItems.IsInteractive)
{
if (YesNo("There are Deprecated catalogues in this Extraction Configuration. Would you like to replace them with their replacement (where available)?", "Replace Deprecated Catalogues"))
{
var repo = _activeItems.RepositoryLocator.CatalogueRepository;
var DeprecatedDatasets = _extractionConfiguration.SelectedDataSets.Where(sd => sd.GetCatalogue().IsDeprecated).ToList();
var replacedBy = repo.GetExtendedProperties(ExtendedProperty.ReplacedBy);
foreach (ISelectedDataSets ds in DeprecatedDatasets)
{
var replacement = replacedBy.Where(rb => rb.ReferencedObjectID == ds.GetCatalogue().ID).FirstOrDefault();
if (replacement is not null)
{
var replacementCatalogue = repo.GetObjectByID<Catalogue>(Int32.Parse(replacement.Value));
while (replacementCatalogue.IsDeprecated)
{
var replacementCatalogueIsReplacedBy = replacedBy.Where(rb => rb.ReferencedObjectID == replacementCatalogue.ID).FirstOrDefault();
if(replacementCatalogueIsReplacedBy is not null)
{
//have found further down the tree
replacementCatalogue = repo.GetObjectByID<Catalogue>(Int32.Parse(replacementCatalogueIsReplacedBy.Value));
}
else
{
//there is no replacement
break;
}
}
toRemove.Add(ds.ExtractableDataSet);
toAdd.Add(replacementCatalogue);
}
}


}
}
}

public ExecuteCommandCloneExtractionConfiguration(IBasicActivateItems activator,
ExtractionConfiguration extractionConfiguration) : base(activator)
{
_extractionConfiguration = extractionConfiguration;

_activeItems = activator;
if (!_extractionConfiguration.SelectedDataSets.Any())
SetImpossible("ExtractionConfiguration does not have any selected datasets");
}
Expand All @@ -36,9 +79,24 @@ public override Image<Rgba32> GetImage(IIconProvider iconProvider) =>
public override void Execute()
{
base.Execute();
CheckForDeprecatedCatalogues();

var clone = _extractionConfiguration.DeepCloneWithNewIDs();

foreach (ExtractableDataSet ds in toRemove)
{
clone.RemoveDatasetFromConfiguration(ds);
}
foreach (Catalogue c in toAdd)
{
//check if the eds already exis
var eds = _activeItems.RepositoryLocator.DataExportRepository.GetAllObjectsWhere<ExtractableDataSet>("Catalogue_ID", c.ID).FirstOrDefault();
if (eds is null)
{
eds = new ExtractableDataSet(_activeItems.RepositoryLocator.DataExportRepository, c);
eds.SaveToDatabase();
}
clone.AddDatasetToConfiguration(eds);
}
Publish((DatabaseEntity)clone.Project);
Emphasise(clone);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
using Rdmp.Core.Curation.Data;
using Rdmp.Core.MapsDirectlyToDatabaseTable;
using Rdmp.Core.Repositories.Construction;
using System.Linq;

namespace Rdmp.Core.CommandExecution.AtomicCommands;

public class ExecuteCommandDeprecate : BasicCommandExecution
{
private readonly IMightBeDeprecated[] _o;
private readonly bool _desiredState;
private readonly IBasicActivateItems _activeItems;


[UseWithObjectConstructor]
public ExecuteCommandDeprecate(IBasicActivateItems itemActivator,
Expand All @@ -24,6 +27,7 @@ public ExecuteCommandDeprecate(IBasicActivateItems itemActivator,
{
_o = o;
_desiredState = desiredState;
_activeItems = itemActivator;
}

public override string GetCommandName() => !string.IsNullOrEmpty(OverrideCommandName) ? OverrideCommandName :
Expand All @@ -45,8 +49,17 @@ private void ExecuteImpl()
{
o.IsDeprecated = _desiredState;
o.SaveToDatabase();
if (!_desiredState && o.GetType() == typeof(Catalogue))//false is not-depricated
{
var c = (Catalogue) o;
var replacedBy = _activeItems.RepositoryLocator.CatalogueRepository.GetExtendedProperties(ExtendedProperty.ReplacedBy);
var replacement = replacedBy.Where(rb => rb.ReferencedObjectID == c.ID).FirstOrDefault();
replacement.DeleteInDatabase();
}
}



if (!BasicActivator.IsInteractive || _o.Length != 1 || _o[0] is not Catalogue || !_desiredState ||
!BasicActivator.YesNo("Do you have a replacement Catalogue you want to link?", "Replacement")) return;
var cmd = new ExecuteCommandReplacedBy(BasicActivator, _o[0], null)
Expand Down