Skip to content
Snippets Groups Projects
Commit 5d70acf8 authored by florian's avatar florian
Browse files

DRAFT: Fix roles and datatypes, add TODOS

parent fff83ed9
No related branches found
No related tags found
1 merge request!7ENH: Implement queries and entity retrieval
Pipeline #12342 passed
Pipeline: CaosDB Julia Integration Tests

#12343

    ......@@ -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, "RecordType")
    set_role(record_type, "RECORD_TYPE")
    return record_type
    ......@@ -229,7 +240,7 @@ function create_record(name::AbstractString = "")
    record = create_entity(name)
    set_role(record, "Record")
    set_role(record, "RECORD")
    return record
    ......@@ -253,7 +264,7 @@ function create_property_entity(;
    property = create_entity(name)
    set_role(property, "Property")
    set_role(property, "PROPERTY")
    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)
    ......
    ......@@ -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) == "RecordType"
    @test CaosDB.Entity.get_role(rt_with_name) == "RECORD_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) == "Property"
    @test CaosDB.Entity.get_role(prop_with_name_and_unit) == "PROPERTY"
    @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"
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment