diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c1844435e..bcfe63e72c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ + # Changelog All notable changes to this project will be documented in this file. @@ -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 diff --git a/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandCloneExtractionConfiguration.cs b/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandCloneExtractionConfiguration.cs index 5715ae412a..2fcb3707f1 100644 --- a/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandCloneExtractionConfiguration.cs +++ b/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandCloneExtractionConfiguration.cs @@ -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 . +using System; +using System.Collections.Generic; using System.Linq; using Rdmp.Core.Curation.Data; using Rdmp.Core.DataExport.Data; @@ -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 toRemove = []; + private readonly List 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(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(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"); } @@ -36,9 +79,24 @@ public override Image 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("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); } diff --git a/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandDeprecate.cs b/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandDeprecate.cs index 86851ecc09..acdd6f89f0 100644 --- a/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandDeprecate.cs +++ b/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandDeprecate.cs @@ -7,6 +7,7 @@ using Rdmp.Core.Curation.Data; using Rdmp.Core.MapsDirectlyToDatabaseTable; using Rdmp.Core.Repositories.Construction; +using System.Linq; namespace Rdmp.Core.CommandExecution.AtomicCommands; @@ -14,6 +15,8 @@ public class ExecuteCommandDeprecate : BasicCommandExecution { private readonly IMightBeDeprecated[] _o; private readonly bool _desiredState; + private readonly IBasicActivateItems _activeItems; + [UseWithObjectConstructor] public ExecuteCommandDeprecate(IBasicActivateItems itemActivator, @@ -24,6 +27,7 @@ public ExecuteCommandDeprecate(IBasicActivateItems itemActivator, { _o = o; _desiredState = desiredState; + _activeItems = itemActivator; } public override string GetCommandName() => !string.IsNullOrEmpty(OverrideCommandName) ? OverrideCommandName : @@ -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)