-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ExecuteCommandRefreshBrokenCohorts
Fixes #1094
- Loading branch information
Showing
4 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
Rdmp.Core.Tests/CommandExecution/ExecuteCommandRefreshBrokenCohortsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// 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 NUnit.Framework; | ||
using Rdmp.Core.CommandExecution.AtomicCommands; | ||
using Rdmp.Core.CommandLine.Interactive; | ||
using Rdmp.Core.DataExport.Data; | ||
using Rdmp.Core.Providers; | ||
using Rdmp.Core.Repositories; | ||
using ReusableLibraryCode.Checks; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Rdmp.Core.Tests.CommandExecution | ||
{ | ||
internal class ExecuteCommandRefreshBrokenCohortsTests | ||
{ | ||
|
||
[Test] | ||
public void TestBrokenCohort() | ||
{ | ||
var repo = new MemoryDataExportRepository(); | ||
|
||
var ect = new ExternalCohortTable(repo, "yarg", FAnsi.DatabaseType.MicrosoftSQLServer); | ||
ect.Server = "IDontExist"; | ||
ect.Database = "fff"; | ||
ect.PrivateIdentifierField = "haha"; | ||
ect.ReleaseIdentifierField = "haha"; | ||
ect.SaveToDatabase(); | ||
|
||
var cohort = new ExtractableCohort(); | ||
cohort.Repository = repo; | ||
cohort.ExternalCohortTable_ID = ect.ID; | ||
cohort.OriginID = 123; | ||
cohort.SaveToDatabase(); | ||
|
||
var repoLocator = new RepositoryProvider(repo); | ||
|
||
var activator = new ConsoleInputManager(repoLocator, new ThrowImmediatelyCheckNotifier()) { | ||
DisallowInput = true | ||
}; | ||
|
||
Assert.AreEqual(1,((DataExportChildProvider)activator.CoreChildProvider).ForbidListedSources.Count); | ||
|
||
var cmd = new ExecuteCommandRefreshBrokenCohorts(activator) | ||
{ | ||
// suppress publishing so we don't just go back into a refresh | ||
// and find it missing again | ||
NoPublish = true, | ||
}; | ||
|
||
Assert.IsFalse(cmd.IsImpossible); | ||
cmd.Execute(); | ||
|
||
//now no forbidden cohorts | ||
Assert.IsEmpty(((DataExportChildProvider)activator.CoreChildProvider).ForbidListedSources); | ||
|
||
|
||
cmd = new ExecuteCommandRefreshBrokenCohorts(activator); | ||
Assert.IsTrue(cmd.IsImpossible); | ||
Assert.AreEqual("There are no broken ExternalCohortTable to clear status on", cmd.ReasonCommandImpossible); | ||
|
||
cmd = new ExecuteCommandRefreshBrokenCohorts(activator,ect); | ||
Assert.IsTrue(cmd.IsImpossible); | ||
Assert.AreEqual("'yarg' is not broken", cmd.ReasonCommandImpossible); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandRefreshBrokenCohorts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// 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 Rdmp.Core.Curation.Data; | ||
using Rdmp.Core.DataExport.Data; | ||
using Rdmp.Core.Providers; | ||
using Rdmp.Core.Repositories.Construction; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Rdmp.Core.CommandExecution.AtomicCommands | ||
{ | ||
/// <summary> | ||
/// Clears the <see cref="DataExportChildProvider.ForbidListedSources"/> list and triggers a refresh | ||
/// which results in all previously broken cohort sources to be re-evaluated for existence | ||
/// </summary> | ||
public class ExecuteCommandRefreshBrokenCohorts : BasicCommandExecution | ||
{ | ||
private readonly ExternalCohortTable _ect; | ||
|
||
[UseWithObjectConstructor] | ||
public ExecuteCommandRefreshBrokenCohorts(IBasicActivateItems activator, | ||
[DemandsInitialization("The specific ExternalCohortTable to attempt to refresh connections to or null to refresh all ExternalCohortTables")] | ||
ExternalCohortTable ect = null):base(activator) | ||
{ | ||
_ect = ect; | ||
|
||
if (!(activator.CoreChildProvider is DataExportChildProvider dx)) | ||
{ | ||
SetImpossible($"{nameof(activator.CoreChildProvider)} is not a {nameof(DataExportChildProvider)}"); | ||
return; | ||
} | ||
|
||
// if we only want to clear one | ||
if(ect != null) | ||
{ | ||
if(!dx.ForbidListedSources.Contains(ect)) | ||
{ | ||
SetImpossible($"'{ect}' is not broken"); | ||
} | ||
} | ||
else | ||
{ | ||
// we want to clear all of them | ||
if (!dx.ForbidListedSources.Any()) | ||
{ | ||
SetImpossible("There are no broken ExternalCohortTable to clear status on"); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
public override void Execute() | ||
{ | ||
base.Execute(); | ||
|
||
var dx = (DataExportChildProvider)BasicActivator.CoreChildProvider; | ||
var toPublish = _ect ?? dx.ForbidListedSources.FirstOrDefault(); | ||
|
||
// theres nothing to clear now anyway | ||
if (toPublish == null) | ||
return; | ||
|
||
if (_ect != null) | ||
{ | ||
dx.ForbidListedSources.Remove(_ect); | ||
} | ||
else | ||
{ | ||
dx.ForbidListedSources.Clear(); | ||
} | ||
|
||
|
||
Publish(toPublish); | ||
} | ||
} | ||
} |