diff --git a/src/Entity.jl b/src/Entity.jl index 54ba7b99a6681eaaa73d9423f05f35c66dfdd8a7..419187468566f37e8403d452dd04425311677b82 100644 --- a/src/Entity.jl +++ b/src/Entity.jl @@ -82,11 +82,6 @@ using CaosDB # 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 @@ -291,7 +286,7 @@ function create_recordtype(name::AbstractString = "") record_type = create_entity(name) - set_role(record_type, "RECORD_TYPE") + set_role(record_type, CaosDB.Constants.ROLE.RECORD_TYPE) return record_type @@ -307,7 +302,7 @@ function create_record(name::AbstractString = "") record = create_entity(name) - set_role(record, "RECORD") + set_role(record, CaosDB.Constants.ROLE.RECORD) return record @@ -336,7 +331,7 @@ function create_property_entity(; property = create_entity(name) - set_role(property, "PROPERTY") + set_role(property, CaosDB.Constants.ROLE.PROPERTY) if datatype != "" set_datatype(property, datatype, is_list = is_list, is_reference = is_reference) @@ -432,7 +427,7 @@ function create_file_entity(; end file_entity = create_entity(name) - set_role(file_entity, "FILE") + set_role(file_entity, CaosDB.Constants.ROLE.FILE) set_local_path(file_entity, local_path) set_remote_path(file_entity, remote_path) @@ -739,7 +734,9 @@ function get_role(entity::Ref{_Entity}) CaosDB.Exceptions.evaluate_return_code(err_code) - return unsafe_string(out[]) + rolename = unsafe_string(out[]) + role = getproperty(CaosDB.Constants.ROLE, Symbol(rolename)) + return role end """ @@ -1279,14 +1276,16 @@ function get_importance(property::Ref{_Property}) err_code = ccall( (:caosdb_entity_property_get_importance, CaosDB.library_name), Cint, - (Ref{_Entity}, Ref{Ptr{UInt8}}), + (Ref{_Property}, Ref{Ptr{UInt8}}), property, out, ) CaosDB.Exceptions.evaluate_return_code(err_code) - return unsafe_string(out[]) + imp_name = unsafe_string(out[]) + imp = getproperty(CaosDB.Constants.IMPORTANCE, Symbol(imp_name)) + return imp end """ @@ -1776,17 +1775,17 @@ function set_id(property::Ref{_Property}, id::AbstractString) end """ - function set_role(entity::Ref{_Entity}, role::AbstractString) + function set_role(entity::Ref{_Entity}, role::CaosDB.Constants.ROLE._ROLE) Set the role of the given `entity` object. """ -function set_role(entity::Ref{_Entity}, role::AbstractString) +function set_role(entity::Ref{_Entity}, role::CaosDB.Constants.ROLE._ROLE) err_code = ccall( (:caosdb_entity_entity_set_role, CaosDB.library_name), Cint, (Ref{_Entity}, Cstring), entity, - role, + string(role), ) CaosDB.Exceptions.evaluate_return_code(err_code) @@ -1887,7 +1886,7 @@ function set_datatype( is_reference::Bool = false, ) - if get_role(entity) != "PROPERTY" + if get_role(entity) != CaosDB.Constants.ROLE.PROPERTY throw( CaosDB.Exceptions.ClientException( "Only entities with role PROPERTY can be assigned a datatype.", @@ -1994,7 +1993,7 @@ function set_value( value::Union{AbstractString,Number,Bool,Vector{T}}, ) where {T<:Union{AbstractString,Number,Bool}} - if get_role(entity) != "PROPERTY" + if get_role(entity) != CaosDB.Constants.ROLE.PROPERTY throw( CaosDB.Exceptions.ClientException( "Only entites with role PROPERTY may be assigned a value.", @@ -2040,17 +2039,23 @@ function set_value( end """ - function set_importance(property::Ref{_Property}, importance::AbstractString) + function set_importance( + property::Ref{_Property}, + importance::CaosDB.Constants.IMPORTANCE._IMPORTANCE + ) Set the importance of the given `property` object. """ -function set_importance(property::Ref{_Property}, importance::AbstractString) +function set_importance( + property::Ref{_Property}, + importance::CaosDB.Constants.IMPORTANCE._IMPORTANCE, +) err_code = ccall( (:caosdb_entity_property_set_importance, CaosDB.library_name), Cint, (Ref{_Property}, Cstring), property, - importance, + string(importance), ) CaosDB.Exceptions.evaluate_return_code(err_code)