Skip to content

Commit 6aa1aa7

Browse files
author
irinaschubert
authored
fix(groups): make groups optional (DEV-138) (#135)
* fix error in test-data.xml * optionalize groups in ontology creation * refactor group handling * Update documentation
1 parent 605dc2f commit 6aa1aa7

4 files changed

Lines changed: 21 additions & 16 deletions

File tree

‎docs/dsp-tools-create.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,6 @@ Example:
383383
}
384384
```
385385

386-
The `groups` element is optional. If not used, it should be omitted. It is currently not recommended using it.
387-
388386
### Users
389387

390388
(optional)

‎knora/dsplib/utils/onto_create_ontology.py‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,24 @@ def create_ontology(input_file: str,
131131

132132
new_groups = {}
133133
groups = data_model["project"].get('groups')
134-
if groups is not None:
134+
if groups:
135135
for group in groups:
136136
try:
137137
new_group = Group(con=con,
138138
name=group["name"],
139139
descriptions=LangString(group["descriptions"]),
140140
project=project,
141-
status=group["status"] if group.get("status") is not None else True,
142-
selfjoin=group["selfjoin"] if group.get("selfjoin") is not None else False).create()
141+
status=group["status"] if group.get("status") else True,
142+
selfjoin=group["selfjoin"] if group.get("selfjoin") else False).create()
143+
new_groups[new_group.name] = new_group
144+
if verbose:
145+
print("Created group:")
146+
new_group.print() # project.set_default_permissions(new_group.id)
147+
143148
except BaseError as err:
144-
print("Creating group has failed: ", err.message)
145-
return False
146-
new_groups[new_group.name] = new_group
147-
if verbose:
148-
print("Groups:")
149-
new_group.print() # project.set_default_permissions(new_group.id)
149+
print(f"ERROR while trying to create group '{group.name}'. The error message was: {err.message}")
150+
except Exception as exception:
151+
print(f"ERROR while trying to create group '{group.name}'. The error message was: {exception}")
150152

151153
# create the user(s)
152154
if verbose:

‎knora/dsplib/utils/xml_upload.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class ProjectContext:
3636
_projects: list[Project]
3737
_project_map: Dict[str, str] # dictionary of (project name:project IRI) pairs
3838
_inv_project_map: Dict[str, str] # dictionary of (project IRI:project name) pairs
39-
_groups: list[Group]
40-
_group_map: Dict[str, str]
39+
_groups: Optional[list[Group]]
40+
_group_map: Optional[Dict[str, str]]
4141
_shortcode: Optional[str]
4242
_project_name: Optional[str]
4343

@@ -46,8 +46,14 @@ def __init__(self, con: Connection, shortcode: Optional[str] = None):
4646
self._projects = Project.getAllProjects(con=con)
4747
self._project_map: Dict[str, str] = {x.shortname: x.id for x in self._projects}
4848
self._inv_project_map: Dict[str, str] = {x.id: x.shortname for x in self._projects}
49-
self._groups = Group.getAllGroups(con=con)
50-
self._group_map: Dict[str, str] = {self._inv_project_map[x.project] + ':' + x.name: x.id for x in self._groups}
49+
try:
50+
self._groups = Group.getAllGroups(con=con)
51+
except BaseError:
52+
self._groups = None
53+
if self._groups:
54+
self._group_map: Dict[str, str] = {self._inv_project_map[x.project] + ':' + x.name: x.id for x in self._groups}
55+
else:
56+
self._group_map = None
5157
self._project_name = None
5258
# get the project name from the shortcode
5359
if self._shortcode:

‎testdata/test-data.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
</color-prop>
9797
<list-prop list="testlist" name=":hasListItem">
9898
<list permissions="prop-default">b2</list>
99-
<list permissions="prop-default">b2</list>
10099
</list-prop>
101100
<resptr-prop name=":hasTestThing2">
102101
<resptr permissions="prop-default">obj_0000</resptr>

0 commit comments

Comments
 (0)