Skip to content

Commit

Permalink
Merge pull request #2075 from HicServices/task/RDMP-267-depricate-on-…
Browse files Browse the repository at this point in the history
…import

Task/rdmp 267 Optionally deprecate Cohorts on import
  • Loading branch information
bpeacock001 authored Nov 26, 2024
2 parents 87ff689 + 53609ab commit 9bdb337
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix Delta Load off by one issue
- Update Migration strategy to account for all Primary Keys when moving from staging -> live
- Fix UI issue with viewing cross-database SQL results
- Add UI Steps to deprecate old cohorts when importing a cohort

## [8.3.1] - 2024-10-22

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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.
Expand All @@ -14,6 +14,8 @@
using Rdmp.Core.Logging;
using Rdmp.Core.Logging.Listeners;
using Rdmp.Core.Providers;
using Rdmp.Core.Providers.Nodes.UsedByNodes;
using Rdmp.Core.Providers.Nodes.UsedByProject;

namespace Rdmp.Core.CommandExecution.AtomicCommands.CohortCreationCommands;

Expand Down Expand Up @@ -163,9 +165,9 @@ protected IPipelineRunner GetConfigureAndExecuteControl(ICohortCreationRequest r
var logManager = new LogManager(loggingServer);
logManager.CreateNewLoggingTaskIfNotExists(ExtractableCohort.CohortLoggingTask);

//create a db listener
var toDbListener = new ToLoggingDatabaseDataLoadEventListener(this, logManager,
ExtractableCohort.CohortLoggingTask, description);
//create a db listener
var toDbListener = new ToLoggingDatabaseDataLoadEventListener(this, logManager,
ExtractableCohort.CohortLoggingTask, description);

//make all messages go to both the db and the UI
pipelineRunner.SetAdditionalProgressListener(toDbListener);
Expand All @@ -182,5 +184,41 @@ private void OnCohortCreatedSuccessfully(ICohortCreationRequest request)

Publish(request.CohortCreatedIfAny);
Emphasise(request.CohortCreatedIfAny);
if (BasicActivator.IsInteractive)
DeprecateExistingCohorts(BasicActivator, request.CohortCreatedIfAny);
}

protected void DeprecateExistingCohorts(IBasicActivateItems activator, ExtractableCohort newCohort)
{
var cohorts = activator.CoreChildProvider.GetAllChildrenRecursively(Project).Where(obj => obj.GetType() == typeof(ObjectUsedByOtherObjectNode<CohortSourceUsedByProjectNode, ExtractableCohort>))
.Select(obj => ((ObjectUsedByOtherObjectNode<CohortSourceUsedByProjectNode, ExtractableCohort>)obj).ObjectBeingUsed).Where(o => o.ID != newCohort.ID);
var cohortsWithoutDeprecation = cohorts.Where(o => !o.IsDeprecated);
var cohortsThatAreDeprecatedOrHaveBeenDeprecated = cohorts.Where(c => c.IsDeprecated).ToList();
if (cohortsWithoutDeprecation.Any())
{
if (activator.YesNo("Would you like to deprecate all other cohorts?", "Deprecate Other Cohorts"))
{
foreach (var cohort in cohortsWithoutDeprecation)
{
cohort.IsDeprecated = true;
cohort.SaveToDatabase();
activator.Publish(cohort);
cohortsThatAreDeprecatedOrHaveBeenDeprecated.Add(cohort);
}
}
}

Check notice

Code scanning / CodeQL

Nested 'if' statements can be combined Note

These 'if' statements can be combined.
var cohortIDs = cohortsThatAreDeprecatedOrHaveBeenDeprecated.Select(c => c.ID).ToList();
var extractionConfigurations = activator.RepositoryLocator.DataExportRepository.GetAllObjects<ExtractionConfiguration>().Where(ei => ei.Cohort_ID is not null && cohortIDs.Contains((int)ei.Cohort_ID));
if (extractionConfigurations.Any() && activator.YesNo("Would you like to replace all uses of a deprecated cohort in this project with this cohort?", "Replace Deprecated Cohorts"))
{
foreach (var config in extractionConfigurations)
{
config.Cohort_ID = newCohort.ID;
config.SaveToDatabase();
activator.Publish(config);
}
}


}
}

0 comments on commit 9bdb337

Please sign in to comment.