Skip to content

Commit be359b2

Browse files
authored
Bugfix/rdmp 362 dupe list project cic (#2313)
* remove duplicate folder * add changelog * fix test * add delete function * update perl
1 parent a9e01b4 commit be359b2

13 files changed

+118
-174
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,4 @@ jobs:
308308
file: dist/*
309309
tag: ${{ github.ref }}
310310
overwrite: true
311-
file_glob: true
311+
file_glob: true

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
- Add Internal Note to Catalogue
99
- Fix issue where project associations were not copied when a CIC was cloned
1010
- Fix issue with using Internal Catalogues in Cohort Identification Configurations
11+
- Simplify Project Cohorts tree
1112
- Fix bug with copying project specific Catalogues between Projects when committing a Cohort
1213
- Remove Tree filters from UI
1314
- Fix issue with Web File Downloader not releasing files after download complete
1415
- Fix Extraction primary Key case sensitivity issue
15-
16-
## [9.1.2] - Unreleased
1716
- Automatically fetch user settings from previous versions of RDMP when installing the latest version
1817
- Allow new columns to be added to archive extractions
1918
- Simplify use of Extraction Progress

Rdmp.Core.Tests/DataExport/ProjectCohortIdentificationConfigurationAssociationTests.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,5 @@ public void TestOrphanCic()
5757
//relationship from p should resolve to the cic
5858
Assert.That(p.GetAssociatedCohortIdentificationConfigurations(), Is.Empty);
5959
});
60-
61-
//error should be reported in top right of program
62-
var ex = Assert.Throws<Exception>(() =>
63-
new DataExportChildProvider(new RepositoryProvider(memory), null, ThrowImmediatelyCheckNotifier.Quiet,
64-
null));
65-
Assert.That(
66-
ex.Message, Does.Match(@"Failed to find Associated Cohort Identification Configuration with ID \d+ which was supposed to be associated with my proj"));
67-
68-
//but UI should still respond
69-
var childProvider = new DataExportChildProvider(new RepositoryProvider(memory), null,
70-
IgnoreAllErrorsCheckNotifier.Instance, null);
71-
72-
//the orphan cic should not appear in the tree view under Project=>Cohorts=>Associated Cics
73-
var cohorts = childProvider.GetChildren(p).OfType<ProjectCohortsNode>().Single();
74-
var cics = childProvider.GetChildren(cohorts).OfType<ProjectCohortIdentificationConfigurationAssociationsNode>()
75-
.First();
76-
77-
Assert.That(childProvider.GetChildren(cics), Is.Empty);
7860
}
7961
}

Rdmp.Core/CommandExecution/AtomicCommandFactory.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ public IEnumerable<IAtomicCommand> CreateCommands(object o)
509509
//associate with project
510510
yield return new ExecuteCommandAssociateCohortIdentificationConfigurationWithProject(_activator)
511511
{ Weight = -50.3f, OverrideCommandName = "Associate with Project" }.SetTarget(cic);
512+
yield return new ExecuteCommandRemoveCohortIdentificationConfigurationProjectAssociation(_activator)
513+
{ Weight = -50.2f, OverrideCommandName = "Remove Association with Project" }.SetTarget(pcic != null?pcic:cic);
512514

513515
}
514516

@@ -842,15 +844,6 @@ public IEnumerable<IAtomicCommand> CreateCommands(object o)
842844
{ OverrideCommandName = "Add New Cohort From Table", Weight = -4.6f }.SetTarget(projCohorts.Project);
843845
}
844846

845-
if (Is(o, out ProjectCohortIdentificationConfigurationAssociationsNode pccan))
846-
{
847-
yield return new ExecuteCommandCreateNewCohortIdentificationConfiguration(_activator)
848-
{ OverrideCommandName = "Add New Cohort Builder Query", Weight = -5.1f }.SetTarget(pccan.Project);
849-
yield return new ExecuteCommandAssociateCohortIdentificationConfigurationWithProject(_activator)
850-
{ OverrideCommandName = "Add Existing Cohort Builder Query (link to)", Weight = -5f }
851-
.SetTarget(pccan.Project);
852-
}
853-
854847
if (Is(o, out ProjectSavedCohortsNode savedCohortsNode))
855848
{
856849
yield return
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright (c) The University of Dundee 2018-2019
2+
// This file is part of the Research Data Management Platform (RDMP).
3+
// 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.
4+
// 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.
5+
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
6+
7+
using System;
8+
using System.Linq;
9+
using Rdmp.Core.Curation.Data;
10+
using Rdmp.Core.Curation.Data.Cohort;
11+
using Rdmp.Core.DataExport.Data;
12+
using Rdmp.Core.Icons.IconProvision;
13+
using Rdmp.Core.Providers;
14+
using Rdmp.Core.ReusableLibraryCode.Icons.IconProvision;
15+
using SixLabors.ImageSharp;
16+
using SixLabors.ImageSharp.PixelFormats;
17+
18+
namespace Rdmp.Core.CommandExecution.AtomicCommands;
19+
20+
public sealed class ExecuteCommandRemoveCohortIdentificationConfigurationProjectAssociation : BasicCommandExecution,
21+
IAtomicCommandWithTarget
22+
{
23+
private Project _project;
24+
private CohortIdentificationConfiguration _cic;
25+
private ProjectCohortIdentificationConfigurationAssociation[] _existingAssociations;
26+
private ProjectCohortIdentificationConfigurationAssociation _associationToDelete;
27+
private IBasicActivateItems _activator;
28+
public ExecuteCommandRemoveCohortIdentificationConfigurationProjectAssociation(IBasicActivateItems activator) :
29+
base(activator)
30+
{
31+
_activator = activator;
32+
if (!activator.CoreChildProvider.AllCohortIdentificationConfigurations.Any())
33+
SetImpossible("There are no Cohort Identification Configurations yet");
34+
35+
}
36+
37+
public override string GetCommandHelp() =>
38+
"Specifies that the Cohort Identification Configuration (query) is only for use generating cohorts for extractions of the specified project";
39+
40+
public override void Execute()
41+
{
42+
if (_project is null && _cic is null && _associationToDelete is null)
43+
{
44+
_cic = (CohortIdentificationConfiguration)_activator.SelectOne("Select a Cohort Identification Configuration", _activator.RepositoryLocator.CatalogueRepository.GetAllObjects<CohortIdentificationConfiguration>().ToArray());
45+
if (_cic is null) return;
46+
}
47+
if (_cic is not null && _project is null && _associationToDelete is null)
48+
{
49+
50+
_existingAssociations = _activator.RepositoryLocator.DataExportRepository.GetAllObjectsWhere<ProjectCohortIdentificationConfigurationAssociation>("CohortIdentificationConfiguration_ID", _cic.ID);
51+
}
52+
if (_cic is null && _project is not null && _associationToDelete is null)
53+
{
54+
55+
_existingAssociations = _activator.RepositoryLocator.DataExportRepository.GetAllObjectsWhere<ProjectCohortIdentificationConfigurationAssociation>("Project_ID", _project.ID);
56+
}
57+
if (_cic != null && _project != null && _associationToDelete is null)
58+
{
59+
_associationToDelete = _activator.RepositoryLocator.DataExportRepository.GetAllObjectsWhere<ProjectCohortIdentificationConfigurationAssociation>("Project_ID", _project.ID).Where(pac => pac.CohortIdentificationConfiguration_ID == _cic.ID).First();
60+
}
61+
if (_associationToDelete is null)
62+
{
63+
if (_cic is not null && _project is null)
64+
{
65+
var projects = _existingAssociations.Select(a => a.Project).ToArray();
66+
var selectedProject = (Project)_activator.SelectOne("Select the project to remove the association with", projects);
67+
_associationToDelete = _existingAssociations.Where(pac => pac.Project_ID == selectedProject.ID).First();
68+
69+
}
70+
else if (_cic is null && _project is not null)
71+
{
72+
var cics = _existingAssociations.Select(a => a.CohortIdentificationConfiguration).ToArray();
73+
var selectedCic = (CohortIdentificationConfiguration)_activator.SelectOne("Select the cohort to remove the association with", cics);
74+
_associationToDelete = _existingAssociations.Where(pac => pac.CohortIdentificationConfiguration_ID == selectedCic.ID).First();
75+
76+
}
77+
else
78+
{
79+
_associationToDelete = (ProjectCohortIdentificationConfigurationAssociation)_activator.SelectOne("Select the association to remove", _existingAssociations);
80+
}
81+
}
82+
if (_associationToDelete is null) return;
83+
84+
_associationToDelete.DeleteInDatabase();
85+
Publish(_project);
86+
Publish(_cic);
87+
base.Execute();
88+
}
89+
90+
public override Image<Rgba32> GetImage(IIconProvider iconProvider) =>
91+
//if we know the cic the context is 'pick a project'
92+
_cic != null
93+
? iconProvider.GetImage(RDMPConcept.Project, OverlayKind.Delete)
94+
:
95+
//if we know the _project the context is 'pick a cic' (or if we don't know either then just use this icon too)
96+
iconProvider.GetImage(RDMPConcept.CohortIdentificationConfiguration, OverlayKind.Delete);
97+
98+
public IAtomicCommandWithTarget SetTarget(DatabaseEntity target)
99+
{
100+
switch (target)
101+
{
102+
case Project project:
103+
_project = project;
104+
break;
105+
case CohortIdentificationConfiguration configuration:
106+
_cic = configuration;
107+
break;
108+
case ProjectCohortIdentificationConfigurationAssociation association:
109+
_associationToDelete = association;
110+
break;
111+
}
112+
return this;
113+
}
114+
}

Rdmp.Core/Icons/IconProvision/CatalogueIcons.Designer.cs

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rdmp.Core/Icons/IconProvision/CatalogueIcons.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,6 @@
508508
<data name="AllCohortsNode" type="System.Resources.ResXFileRef, System.Windows.Forms">
509509
<value>..\AllCohortsNode.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
510510
</data>
511-
<data name="ProjectCohortIdentificationConfigurationAssociationsNode" type="System.Resources.ResXFileRef, System.Windows.Forms">
512-
<value>..\ProjectCohortIdentificationConfigurationAssociationsNode.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
513-
</data>
514511
<data name="ProjectSavedCohortsNode" type="System.Resources.ResXFileRef, System.Windows.Forms">
515512
<value>..\ProjectSavedCohortsNode.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
516513
</data>

Rdmp.Core/Icons/IconProvision/RDMPConcept.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public enum RDMPConcept
9898

9999
AllCohortsNode,
100100
ProjectsNode,
101-
ProjectCohortIdentificationConfigurationAssociationsNode,
102101
ProjectSavedCohortsNode,
103102
ExtractableDataSetsNode,
104103
ExtractionDirectoryNode,

Rdmp.Core/Providers/DataExportChildProvider.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,6 @@ private void AddChildren(ProjectCataloguesNode projectCataloguesNode, Descendanc
356356
private void AddChildren(ProjectCohortsNode projectCohortsNode, DescendancyList descendancy)
357357
{
358358
var children = new HashSet<object>();
359-
var projectCiCsNode = new ProjectCohortIdentificationConfigurationAssociationsNode(projectCohortsNode.Project);
360-
children.Add(projectCiCsNode);
361-
AddChildren(projectCiCsNode, descendancy.Add(projectCiCsNode));
362359

363360
var savedCohortsNode = new ProjectSavedCohortsNode(projectCohortsNode.Project);
364361
children.Add(savedCohortsNode);
@@ -405,38 +402,6 @@ private void AddChildren(ProjectSavedCohortsNode savedCohortsNode, DescendancyLi
405402
AddToDictionaries(children, descendancy);
406403
}
407404

408-
private void AddChildren(ProjectCohortIdentificationConfigurationAssociationsNode projectCiCsNode,
409-
DescendancyList descendancy)
410-
{
411-
//add the associations
412-
var children = new HashSet<object>();
413-
foreach (var association in AllProjectAssociatedCics.Where(assoc =>
414-
assoc.Project_ID == projectCiCsNode.Project.ID))
415-
{
416-
var matchingCic = AllCohortIdentificationConfigurations.SingleOrDefault(cic =>
417-
cic.ID == association.CohortIdentificationConfiguration_ID) ?? AllTemplateCohortIdentificationConfigurations.SingleOrDefault(cic =>
418-
cic.ID == association.CohortIdentificationConfiguration_ID);
419-
420-
if (matchingCic == null)
421-
{
422-
_errorsCheckNotifier.OnCheckPerformed(
423-
new CheckEventArgs(
424-
$"Failed to find Associated Cohort Identification Configuration with ID {association.CohortIdentificationConfiguration_ID} which was supposed to be associated with {association.Project}",
425-
CheckResult
426-
.Fail)); //inject knowledge of what the cic is so it doesn't have to be fetched during ToString
427-
}
428-
else
429-
{
430-
association.InjectKnown(matchingCic);
431-
432-
//document that it is a child of the project cics node
433-
children.Add(association);
434-
}
435-
}
436-
437-
AddToDictionaries(children, descendancy);
438-
}
439-
440405
private void AddChildren(ExtractionConfigurationsNode extractionConfigurationsNode, DescendancyList descendancy)
441406
{
442407
var children = new HashSet<object>();

Rdmp.Core/Providers/DescendancyList.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public class DescendancyList
4040
typeof(LoadStageNode),
4141
typeof(PreLoadDiscardedColumnsNode),
4242
typeof(ProjectCataloguesNode),
43-
typeof(ProjectCohortIdentificationConfigurationAssociationsNode)
4443
});
4544

4645
/// <summary>

0 commit comments

Comments
 (0)