Skip to content

Commit

Permalink
add bugfix for deleting depricated extended properties
Browse files Browse the repository at this point in the history
  • Loading branch information
JFriel committed Jun 18, 2024
1 parent 51b7b8b commit 4659d7e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@ private void CheckForDeprecatedCatalogues()
{
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 = _activeItems.RepositoryLocator.CatalogueRepository.GetExtendedProperties(ExtendedProperty.ReplacedBy);
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 = _activeItems.RepositoryLocator.CatalogueRepository.GetObjectByID<Catalogue>(Int32.Parse(replacement.Value));
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 = _activeItems.RepositoryLocator.CatalogueRepository.GetObjectByID<Catalogue>(Int32.Parse(replacementCatalogueIsReplacedBy.Value));
replacementCatalogue = repo.GetObjectByID<Catalogue>(Int32.Parse(replacementCatalogueIsReplacedBy.Value));
}
else
{
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

0 comments on commit 4659d7e

Please sign in to comment.