Skip to content
Permalink
Browse files
fix(groups): make groups optional (DEV-138) (#135)
* fix error in test-data.xml

* optionalize groups in ontology creation

* refactor group handling

* Update documentation
  • Loading branch information
irinaschubert committed Dec 14, 2021
1 parent 605dc2f commit 6aa1aa78a81dc22d7c04ed17a705458f727dcc07
Showing with 21 additions and 16 deletions.
  1. +0 −2 docs/dsp-tools-create.md
  2. +11 −9 knora/dsplib/utils/onto_create_ontology.py
  3. +10 −4 knora/dsplib/utils/xml_upload.py
  4. +0 −1 testdata/test-data.xml
@@ -383,8 +383,6 @@ Example:
}
```

The `groups` element is optional. If not used, it should be omitted. It is currently not recommended using it.

### Users

(optional)
@@ -131,22 +131,24 @@ def create_ontology(input_file: str,

new_groups = {}
groups = data_model["project"].get('groups')
if groups is not None:
if groups:
for group in groups:
try:
new_group = Group(con=con,
name=group["name"],
descriptions=LangString(group["descriptions"]),
project=project,
status=group["status"] if group.get("status") is not None else True,
selfjoin=group["selfjoin"] if group.get("selfjoin") is not None else False).create()
status=group["status"] if group.get("status") else True,
selfjoin=group["selfjoin"] if group.get("selfjoin") else False).create()
new_groups[new_group.name] = new_group
if verbose:
print("Created group:")
new_group.print() # project.set_default_permissions(new_group.id)

except BaseError as err:
print("Creating group has failed: ", err.message)
return False
new_groups[new_group.name] = new_group
if verbose:
print("Groups:")
new_group.print() # project.set_default_permissions(new_group.id)
print(f"ERROR while trying to create group '{group.name}'. The error message was: {err.message}")
except Exception as exception:
print(f"ERROR while trying to create group '{group.name}'. The error message was: {exception}")

# create the user(s)
if verbose:
@@ -36,8 +36,8 @@ class ProjectContext:
_projects: list[Project]
_project_map: Dict[str, str] # dictionary of (project name:project IRI) pairs
_inv_project_map: Dict[str, str] # dictionary of (project IRI:project name) pairs
_groups: list[Group]
_group_map: Dict[str, str]
_groups: Optional[list[Group]]
_group_map: Optional[Dict[str, str]]
_shortcode: Optional[str]
_project_name: Optional[str]

@@ -46,8 +46,14 @@ def __init__(self, con: Connection, shortcode: Optional[str] = None):
self._projects = Project.getAllProjects(con=con)
self._project_map: Dict[str, str] = {x.shortname: x.id for x in self._projects}
self._inv_project_map: Dict[str, str] = {x.id: x.shortname for x in self._projects}
self._groups = Group.getAllGroups(con=con)
self._group_map: Dict[str, str] = {self._inv_project_map[x.project] + ':' + x.name: x.id for x in self._groups}
try:
self._groups = Group.getAllGroups(con=con)
except BaseError:
self._groups = None
if self._groups:
self._group_map: Dict[str, str] = {self._inv_project_map[x.project] + ':' + x.name: x.id for x in self._groups}
else:
self._group_map = None
self._project_name = None
# get the project name from the shortcode
if self._shortcode:
@@ -96,7 +96,6 @@
</color-prop>
<list-prop list="testlist" name=":hasListItem">
<list permissions="prop-default">b2</list>
<list permissions="prop-default">b2</list>
</list-prop>
<resptr-prop name=":hasTestThing2">
<resptr permissions="prop-default">obj_0000</resptr>

0 comments on commit 6aa1aa7

Please sign in to comment.