Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
887d98a4
Commit
887d98a4
authored
4 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
f-check-datamodel -> dev
parent
fe47fac1
No related branches found
No related tags found
1 merge request
!22
Release 0.3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+2
-0
2 additions, 0 deletions
CHANGELOG.md
src/caosadvancedtools/serverside/helper.py
+22
-7
22 additions, 7 deletions
src/caosadvancedtools/serverside/helper.py
with
24 additions
and
7 deletions
CHANGELOG.md
+
2
−
0
View file @
887d98a4
...
@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
...
@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ###
### Changed ###
*
`caosadvancedtools.serverside.helper.init_data_model`
also checks the role
and data type of entities.
*
The
`caosadvancedtools.table_importer.date_converter`
now actually returns
*
The
`caosadvancedtools.table_importer.date_converter`
now actually returns
`datetime.date`
instance. A new
`datetime.date`
instance. A new
`caosadvancedtools.table_importer.datetime_converter`
replaces the old
`caosadvancedtools.table_importer.datetime_converter`
replaces the old
...
...
This diff is collapsed.
Click to expand it.
src/caosadvancedtools/serverside/helper.py
+
22
−
7
View file @
887d98a4
...
@@ -147,13 +147,13 @@ def print_error(text):
...
@@ -147,13 +147,13 @@ def print_error(text):
class
DataModelError
(
RuntimeError
):
class
DataModelError
(
RuntimeError
):
"""
DataModelError indicates that the server-side script cannot work as
"""
DataModelError indicates that the server-side script cannot work as
intended due to missing data
t
model entities or an otherwise incompatible
intended due to missing data model entities or an otherwise incompatible
data model.
"""
data model.
"""
def
__init__
(
self
,
rt
):
def
__init__
(
self
,
rt
,
info
=
""
):
super
().
__init__
(
super
().
__init__
(
"
This script expects certain RecordTypes and Properties to exist
"
"
This script expects certain RecordTypes and Properties to exist
"
"
in the data model. There is a problem with {}
.
"
.
format
(
rt
))
"
in the data model. There is a problem with {}.
{}
"
.
format
(
rt
,
info
))
def
recordtype_is_child_of
(
rt
,
parent
):
def
recordtype_is_child_of
(
rt
,
parent
):
...
@@ -183,7 +183,11 @@ def recordtype_is_child_of(rt, parent):
...
@@ -183,7 +183,11 @@ def recordtype_is_child_of(rt, parent):
def
init_data_model
(
entities
):
def
init_data_model
(
entities
):
"""
Return True if all entities exist.
"""
Return True iff all entities exist and their role and possibly their
data type is correct.
This implementation follows a fail-fast approach. The first entity with
problems will raise an exception.
Parameters
Parameters
----------
----------
...
@@ -194,18 +198,29 @@ def init_data_model(entities):
...
@@ -194,18 +198,29 @@ def init_data_model(entities):
Raises
Raises
------
------
DataModelError
DataModelError
If any entity in `entities` does not exists.
If any entity in `entities` does not exist or the role or data type is
not matching.
Returns
Returns
-------
-------
bool
bool
True if all entities exist.
True if all entities exist
and their role and data type are matching
.
"""
"""
try
:
try
:
for
e
in
entities
:
for
e
in
entities
:
local_datatype
=
e
.
datatype
local_role
=
e
.
role
e
.
retrieve
()
e
.
retrieve
()
if
local_datatype
is
not
None
and
local_datatype
!=
e
.
datatype
:
info
=
(
"
The remote entity has a {} data type while it should
"
"
have a {}.
"
.
format
(
e
.
datatype
,
local_datatype
))
raise
DataModelError
(
e
.
name
,
info
)
if
local_role
is
not
None
and
local_role
!=
e
.
role
:
info
=
(
"
The remote entity has is a {} while it should
"
"
be a {}.
"
.
format
(
e
.
role
,
local_role
))
raise
DataModelError
(
e
.
name
,
info
)
except
db
.
exceptions
.
EntityDoesNotExistError
:
except
db
.
exceptions
.
EntityDoesNotExistError
:
raise
DataModelError
(
e
.
name
)
raise
DataModelError
(
e
.
name
,
"
This entity does not exist.
"
)
return
True
return
True
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment