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-100 Allow project specific extraction updates #1733

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Changed

- Add ability to use Extraction Category with Project Specific Catalogues
- Allow arbitrary MDF files from foreign file systems to work with the MDF Attacher, see [MDFAttacher](Documentation\DataLoadEngine\MDFAttacher.md)
- Update Excel Attacher to read data from arbitrary start points within sheets
- Add Time based filtering of remote table and database attachers
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) The University of Dundee 2024-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 NUnit.Framework;
using Rdmp.Core.CommandExecution;
using Rdmp.Core.CommandExecution.AtomicCommands;
using Rdmp.Core.Curation.Data;
using Tests.Common;
namespace Rdmp.Core.Tests.CommandExecution;

public class ExecuteCommandChangeExtractionCategoryTests : DatabaseTests
{
private Catalogue _cata1;
private TableInfo _t1;
private ColumnInfo _c1;
private CatalogueItem _ci1;

private ExtractionInformation _extractionInfo1;

[Test]
public void TestProjectSpecificCatalogueChangeToSuplemental()
{
//change project specific to supplemental
_cata1 =new Catalogue(CatalogueRepository, "Dataset1");
_t1 = new TableInfo(CatalogueRepository, "T1");

_c1 = new ColumnInfo(CatalogueRepository, "PrivateIdentifierA", "varchar(10)", _t1);

_ci1 = new CatalogueItem(CatalogueRepository, _cata1, "PrivateIdentifierA");

_extractionInfo1 = new ExtractionInformation(CatalogueRepository, _ci1, _c1, _c1.ToString())
{
Order = 123,
ExtractionCategory = ExtractionCategory.ProjectSpecific,
IsExtractionIdentifier = true
};
_extractionInfo1.CatalogueItem.Catalogue.InjectKnown(new CatalogueExtractabilityStatus(true, true));

ExtractionInformation[] eid = { _extractionInfo1 };
var cmd = new ExecuteCommandChangeExtractionCategory(new ThrowImmediatelyActivator(RepositoryLocator), eid, ExtractionCategory.Supplemental);
Assert.DoesNotThrow(() => cmd.Execute());
Assert.That(_extractionInfo1.ExtractionCategory, Is.EqualTo(ExtractionCategory.Supplemental));
}

[Test]
public void TestExtractionCategoryCatalogueChangeFromSupplementalToCore()
{
//change a project specific column to core
_cata1 = new Catalogue(CatalogueRepository, "Dataset1");
_t1 = new TableInfo(CatalogueRepository, "T1");

_c1 = new ColumnInfo(CatalogueRepository, "PrivateIdentifierA", "varchar(10)", _t1);

_ci1 = new CatalogueItem(CatalogueRepository, _cata1, "PrivateIdentifierA");

_extractionInfo1 = new ExtractionInformation(CatalogueRepository, _ci1, _c1, _c1.ToString())
{
Order = 123,
ExtractionCategory = ExtractionCategory.Supplemental,
IsExtractionIdentifier = true
};
_extractionInfo1.CatalogueItem.Catalogue.InjectKnown(new CatalogueExtractabilityStatus(true, true));

ExtractionInformation[] eid = { _extractionInfo1 };
var cmd = new ExecuteCommandChangeExtractionCategory(new ThrowImmediatelyActivator(RepositoryLocator), eid, ExtractionCategory.Core);
Assert.DoesNotThrow(() => cmd.Execute());
Assert.That(_extractionInfo1.ExtractionCategory, Is.EqualTo(ExtractionCategory.ProjectSpecific));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ public ExecuteCommandChangeExtractionCategory(IBasicActivateItems activator, Ext
if (cata.Length == 1)
_isProjectSpecific = cata[0].IsProjectSpecific(BasicActivator.RepositoryLocator.DataExportRepository);

// if project specific only let them set to project specific
if (_category != null && _isProjectSpecific && _category != ExtractionCategory.ProjectSpecific)
{
// user is trying to set to Core
if (_category == ExtractionCategory.Core)
// surely they meant project specific!
_category = ExtractionCategory.ProjectSpecific;
else
SetImpossible("CatalogueItems can only be ProjectSpecific extraction category");
}
}

public override string GetCommandName() =>
Expand All @@ -64,18 +54,20 @@ public override void Execute()
base.Execute();

var c = _category;

if (c == null && BasicActivator.SelectValueType("New Extraction Category", typeof(ExtractionCategory),
ExtractionCategory.Core, out var category))
{
c = (ExtractionCategory)category;
}

if (c == null)
return;

// if project specific only let them set to project specific
if (_isProjectSpecific && c != ExtractionCategory.ProjectSpecific)
throw new Exception(
"All CatalogueItems in ProjectSpecific Catalogues must have ExtractionCategory of 'ProjectSpecific'");
if (_isProjectSpecific && c == ExtractionCategory.Core)
{
// Don't allow project specific catalogue items to become core
c = ExtractionCategory.ProjectSpecific;
Show("Cannot set the Extraction Category to 'Core' for a Project Specific Catalogue item. It will be saved as 'Project Specific'.");
}

if (ExecuteWithCommit(() => ExecuteImpl(c.Value), $"Set ExtractionCategory to '{c}'", _extractionInformations))
//publish the root Catalogue
Expand Down