Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-julialib
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-julialib
Commits
5d70acf8
Commit
5d70acf8
authored
3 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
DRAFT: Fix roles and datatypes, add TODOS
parent
fff83ed9
No related branches found
Branches containing commit
No related tags found
1 merge request
!7
ENH: Implement queries and entity retrieval
Pipeline
#12342
passed
3 years ago
Stage: info
Stage: code-style
Stage: setup
Stage: test
Stage: deploy
Pipeline: CaosDB Julia Integration Tests
#12343
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Entity.jl
+55
-11
55 additions, 11 deletions
src/Entity.jl
test/runtests.jl
+12
-7
12 additions, 7 deletions
test/runtests.jl
with
67 additions
and
18 deletions
src/Entity.jl
+
55
−
11
View file @
5d70acf8
...
...
@@ -69,6 +69,17 @@ export has_errors, has_warnings
using
CaosDB
# TODO(henrik, daniel) How much do we want to help the users when
# setting/getting the values? Should it only be allowed if the
# datatype of the entity/property is set? This might be too strong,
# especially in case of a property which I might want to specify by
# name, add a value, append it to a Record, and then insert it and
# might expect the server to care for the datatype.
#
# Also, how much do we want to support them with typos. Currently, C
# and C++ only understand all-capital strings for datatypes,
# importances, roles. What about user input like "record_type",
# "RecordType", "recordtype"?
"""
Struct containing a pointer to the wrapped cpp entity
object. Meant for internal use; use `CaosDB.Entity.create_entity` to
...
...
@@ -213,7 +224,7 @@ function create_recordtype(name::AbstractString = "")
record_type
=
create_entity
(
name
)
set_role
(
record_type
,
"R
ecordType
"
)
set_role
(
record_type
,
"R
ECORD_TYPE
"
)
return
record_type
...
...
@@ -229,7 +240,7 @@ function create_record(name::AbstractString = "")
record
=
create_entity
(
name
)
set_role
(
record
,
"R
ecord
"
)
set_role
(
record
,
"R
ECORD
"
)
return
record
...
...
@@ -253,7 +264,7 @@ function create_property_entity(;
property
=
create_entity
(
name
)
set_role
(
property
,
"P
roperty
"
)
set_role
(
property
,
"P
ROPERTY
"
)
if
datatype
!=
""
set_datatype
(
property
,
datatype
)
...
...
@@ -592,6 +603,7 @@ function get_description(message::Ref{_Message})
return
unsafe_string
(
out
[])
end
# TODO(henrik, daniel) Include Bools for list and reference here. How should they be returned to the user?
"""
function get_datatype(entity::Ref{_Entity})
...
...
@@ -600,18 +612,22 @@ Return the datatype of the given `entity`
function
get_datatype
(
entity
::
Ref
{
_Entity
})
out
=
Ref
{
Ptr
{
UInt8
}}(
Ptr
{
UInt8
}())
is_ref
=
Ref
{
Bool
}(
false
)
is_list
=
Ref
{
Bool
}(
false
)
err_code
=
ccall
(
(
:
caosdb_entity_entity_get_datatype
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Entity
},
Ref
{
Ptr
{
UInt8
}}),
(
Ref
{
_Entity
},
Ref
{
Ptr
{
UInt8
}}
,
Ref
{
Bool
},
Ref
{
Bool
}
),
entity
,
out
,
is_ref
,
is_list
,
)
CaosDB
.
Exceptions
.
evaluate_return_code
(
err_code
)
return
unsafe_string
(
out
[])
return
unsafe_string
(
out
[])
,
is_ref
[],
is_list
[]
end
"""
...
...
@@ -622,18 +638,22 @@ Return the datatype of the given `property`
function
get_datatype
(
property
::
Ref
{
_Property
})
out
=
Ref
{
Ptr
{
UInt8
}}(
Ptr
{
UInt8
}())
is_ref
=
Ref
{
Bool
}(
false
)
is_list
=
Ref
{
Bool
}(
false
)
err_code
=
ccall
(
(
:
caosdb_entity_property_get_datatype
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Property
},
Ref
{
Ptr
{
UInt8
}}),
(
Ref
{
_Property
},
Ref
{
Ptr
{
UInt8
}}
,
Ref
{
Bool
},
Ref
{
Bool
}
),
property
,
out
,
is_ref
,
is_list
,
)
CaosDB
.
Exceptions
.
evaluate_return_code
(
err_code
)
return
unsafe_string
(
out
[])
return
unsafe_string
(
out
[])
,
is_ref
[],
is_list
[]
end
"""
...
...
@@ -680,6 +700,10 @@ function get_unit(property::Ref{_Property})
return
unsafe_string
(
out
[])
end
# TODO(henrik,daniel) Replace ccall within the `get_value` function by
# a check of the datatype and then call the correct function in case
# of scalar values or construct a vector and fill it with all values
# in case of list values.
"""
function get_value(entity::Ref{_Entity})
...
...
@@ -1365,18 +1389,29 @@ function set_description(entity::Ref{_Entity}, description::AbstractString)
CaosDB
.
Exceptions
.
evaluate_return_code
(
err_code
)
end
# TODO(henrik, daniel) Should throw an error if role != PROPERTY since
# it is silently ignored by C(++) otherwise. Also include bools for
# lists and references. Convenience functions for lists and
# references, too?
"""
function set_datatype(entity::Ref{_Entity}, datatype::AbstractString)
Set the datatype of the given `entity` object.
"""
function
set_datatype
(
entity
::
Ref
{
_Entity
},
datatype
::
AbstractString
)
function
set_datatype
(
entity
::
Ref
{
_Entity
},
datatype
::
AbstractString
;
is_list
::
Bool
=
false
,
is_reference
::
Bool
=
false
,
)
err_code
=
ccall
(
(
:
caosdb_entity_entity_set_datatype
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Entity
},
Cstring
),
(
Ref
{
_Entity
},
Cstring
,
Bool
,
Bool
),
entity
,
datatype
,
is_reference
,
is_list
,
)
CaosDB
.
Exceptions
.
evaluate_return_code
(
err_code
)
...
...
@@ -1388,13 +1423,20 @@ end
Set the datatype of the given `property` object.
"""
function
set_datatype
(
property
::
Ref
{
_Property
},
datatype
::
AbstractString
)
function
set_datatype
(
property
::
Ref
{
_Property
},
datatype
::
AbstractString
;
is_list
::
Bool
=
false
,
is_reference
::
Bool
=
false
,
)
err_code
=
ccall
(
(
:
caosdb_entity_property_set_datatype
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Property
},
Cstring
),
(
Ref
{
_Property
},
Cstring
,
Bool
,
Bool
),
property
,
datatype
,
is_reference
,
is_list
,
)
CaosDB
.
Exceptions
.
evaluate_return_code
(
err_code
)
...
...
@@ -1435,6 +1477,8 @@ function set_unit(property::Ref{_Property}, unit::AbstractString)
CaosDB
.
Exceptions
.
evaluate_return_code
(
err_code
)
end
# TODO(henrik, daniel) overload to choose the correct set
# function. Should throw an error for entities with role != PROPERTY.
"""
function set_value(entity::Ref{_Entity}, value::AbstractString)
...
...
This diff is collapsed.
Click to expand it.
test/runtests.jl
+
12
−
7
View file @
5d70acf8
...
...
@@ -97,12 +97,12 @@ using CaosDB
rt_with_name
=
CaosDB
.
Entity
.
create_recordtype
(
"TestRT"
)
@test
CaosDB
.
Entity
.
get_name
(
rt_with_name
)
==
"TestRT"
@test
CaosDB
.
Entity
.
get_role
(
rt_with_name
)
==
"R
ecordType
"
@test
CaosDB
.
Entity
.
get_role
(
rt_with_name
)
==
"R
ECORD_TYPE
"
prop_with_name_and_unit
=
CaosDB
.
Entity
.
create_property_entity
(
name
=
"TestProp"
,
unit
=
"m"
)
@test
CaosDB
.
Entity
.
get_name
(
prop_with_name_and_unit
)
==
"TestProp"
@test
CaosDB
.
Entity
.
get_role
(
prop_with_name_and_unit
)
==
"P
roperty
"
@test
CaosDB
.
Entity
.
get_role
(
prop_with_name_and_unit
)
==
"P
ROPERTY
"
@test
CaosDB
.
Entity
.
get_unit
(
prop_with_name_and_unit
)
==
"m"
rec_with_parent_and_props
=
CaosDB
.
Entity
.
create_record
(
"TestRec"
)
...
...
@@ -133,19 +133,24 @@ using CaosDB
CaosDB
.
Entity
.
get_parent
(
rec_with_parent_and_props
,
Cint
(
1
)),
)
==
"Parent2"
prop1
=
CaosDB
.
Entity
.
create_property
(
name
=
"Property1"
,
value
=
"2"
)
# TODO(henrik, daniel) re-enable once values can be set again
prop1
=
CaosDB
.
Entity
.
create_property
(
name
=
"Property1"
,
# value = "2"
)
prop2
=
CaosDB
.
Entity
.
create_property
(
id
=
"id_of_property_2"
)
CaosDB
.
Entity
.
set_datatype
(
prop2
,
"TEXT"
)
prop3
=
CaosDB
.
Entity
.
create_property
(
name
=
"Property3"
)
CaosDB
.
Entity
.
append_properties
(
rec_with_parent_and_props
,
[
prop1
,
prop2
,
prop3
])
@test
length
(
CaosDB
.
Entity
.
get_properties
(
rec_with_parent_and_props
))
==
3
# properties can be accessed as a list
@test
CaosDB
.
Entity
.
get_value
(
CaosDB
.
Entity
.
get_properties
(
rec_with_parent_and_props
)[
1
],
)
==
"2"
# TODO(henrik, daniel)
# @test CaosDB.Entity.get_value(
# CaosDB.Entity.get_properties(rec_with_parent_and_props)[1],
# ) == "2"
@test
CaosDB
.
Entity
.
get_datatype
(
CaosDB
.
Entity
.
get_properties
(
rec_with_parent_and_props
)[
2
],
)
==
"TEXT"
)
[
1
]
==
"TEXT"
@test
CaosDB
.
Entity
.
get_id
(
CaosDB
.
Entity
.
get_properties
(
rec_with_parent_and_props
)[
2
],
)
==
"id_of_property_2"
...
...
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