Skip to content

Commit 434b07b

Browse files
committed
Enhance node addition logic in Collection class
Added 'AbortIfNodeExists' option to node addition methods and improved handling of controlled term instances based on preferences. Subnodes are now added before the main node, and code comments were updated to reflect new functionality.
1 parent 1987e0c commit 434b07b

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

code/+openminds/@Collection/Collection.m

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
% Todo: Validation.
3838
% - Linked subject states should have same subject
39+
% - Add method to update links for specified instances
3940

4041
% Need mechanism to check if embedded nodes are added to the collection
4142

@@ -190,12 +191,15 @@ function add(obj, instance, options)
190191
end
191192
arguments
192193
options.AddSubNodesOnly = false;
194+
options.AbortIfNodeExists = true;
193195
end
194196

195197
for i = 1:numel(instance)
196198
thisInstance = instance{i};
197199
for j = 1:numel(thisInstance) % If thisInstance is an array
198-
obj.addNode(thisInstance(j), "AddSubNodesOnly", options.AddSubNodesOnly);
200+
obj.addNode(thisInstance(j), ...
201+
"AddSubNodesOnly", options.AddSubNodesOnly, ...
202+
"AbortIfNodeExists", options.AbortIfNodeExists);
199203
end
200204
end
201205
end
@@ -498,9 +502,13 @@ function load(obj, loadPath, options)
498502
instance.id = obj.getBlankNodeIdentifier();
499503
end
500504

501-
% Do not add openminds controlled term instances
502-
if startsWith(instance.id, "https://openminds.ebrains.eu/instances/")
503-
return
505+
% Do not add openminds controlled term instances if disabled in
506+
% preferences
507+
if startsWith(instance.id, "https://openminds.ebrains.eu/instances/") ...
508+
|| startsWith(instance.id, "https://openminds.om-i.org/instances/")
509+
if ~openminds.getpref('AddControlledInstanceToCollection')
510+
return
511+
end
504512
end
505513

506514
if obj.NumNodes > 0
@@ -511,6 +519,10 @@ function load(obj, loadPath, options)
511519
end
512520
end
513521
end
522+
523+
% Add subnodes first
524+
obj.addSubNodes(instance)
525+
514526

515527
if ~options.AddSubNodesOnly
516528
obj.Nodes(instance.id) = {instance};
@@ -530,7 +542,6 @@ function load(obj, loadPath, options)
530542
end
531543
end
532544

533-
obj.addSubNodes(instance)
534545
if ~nargout
535546
clear wasAdded
536547
end

code/+openminds/getpref.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
[ ...
2121
"PropertyDisplayMode", ...
2222
"DocLinkTarget", ...
23+
"AddControlledInstanceToCollection", ...
2324
"" ...
2425
])...
2526
} = ""

code/internal/+openminds/+utility/Preferences.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
% - "help" : MATLAB docstrings
1111
% - "online" : Online ReadTheDocs
1212
% documentation
13+
% AddControlledInstanceToCollection (logical): Whether to add
14+
% openMINDS controlled instances to a
15+
% collection
1316

1417
properties (SetObservable)
1518
PropertyDisplayMode (1,1) string ...
1619
{mustBeMember(PropertyDisplayMode, ["all", "non-empty"])} = "all"
1720
DocLinkTarget (1,1) string ...
1821
{mustBeMember(DocLinkTarget, ["help", "online"])} = "online"
22+
AddControlledInstanceToCollection (1,1) logical = true
1923
end
2024

2125
properties (Constant, Access = private)

0 commit comments

Comments
 (0)