Skip to content
Snippets Groups Projects
Verified Commit 0f96286c authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Add Set/GetDescription

parent 496df10d
Branches
Tags
No related merge requests found
Pipeline #11795 passed
Pipeline: caosdb-cppinttest

#11796

    ...@@ -107,6 +107,7 @@ trigger_inttest: ...@@ -107,6 +107,7 @@ trigger_inttest:
    # ... or use main if possible... # ... or use main if possible...
    - if [[ "$CI_COMMIT_REF_NAME" == "main" ]] ; then - if [[ "$CI_COMMIT_REF_NAME" == "main" ]] ; then
    CPPINT_REF=main ; CPPINT_REF=main ;
    F_BRANCH=main ;
    fi fi
    - if echo "$CI_COMMIT_REF_NAME" | grep -c "^v" ; then - if echo "$CI_COMMIT_REF_NAME" | grep -c "^v" ; then
    CPPINT_REF=main ; CPPINT_REF=main ;
    ......
    ...@@ -113,6 +113,7 @@ public: ...@@ -113,6 +113,7 @@ public:
    friend class ConfigurationManager; friend class ConfigurationManager;
    private: private:
    auto ConvertLogLevel(const std::string &string_level) const -> int;
    auto CreateConsoleSinkConfiguration(const object &from, auto CreateConsoleSinkConfiguration(const object &from,
    const std::string &name, int level) const const std::string &name, int level) const
    -> std::shared_ptr<caosdb::logging::SinkConfiguration>; -> std::shared_ptr<caosdb::logging::SinkConfiguration>;
    ...@@ -236,7 +237,9 @@ private: ...@@ -236,7 +237,9 @@ private:
    ConnectionConfigurationHelper connection_configuration_helper; ConnectionConfigurationHelper connection_configuration_helper;
    LoggingConfigurationHelper logging_configuration_helper; LoggingConfigurationHelper logging_configuration_helper;
    inline ConfigurationManager() { InitializeDefaults(); }; inline ConfigurationManager(){
    // InitializeDefaults();
    };
    /** /**
    * Initialize this ConfigurationManager with the defaults. * Initialize this ConfigurationManager with the defaults.
    ......
    ...@@ -39,6 +39,7 @@ using caosdb::entity::v1alpha1::IdResponse; ...@@ -39,6 +39,7 @@ using caosdb::entity::v1alpha1::IdResponse;
    using ProtoParent = caosdb::entity::v1alpha1::Parent; using ProtoParent = caosdb::entity::v1alpha1::Parent;
    using ProtoProperty = caosdb::entity::v1alpha1::Property; using ProtoProperty = caosdb::entity::v1alpha1::Property;
    using ProtoEntity = caosdb::entity::v1alpha1::Entity; using ProtoEntity = caosdb::entity::v1alpha1::Entity;
    using ProtoMessage = caosdb::entity::v1alpha1::Message;
    /** /**
    * Messages convey information about the state and result of transactions. * Messages convey information about the state and result of transactions.
    ...@@ -63,10 +64,9 @@ public: ...@@ -63,10 +64,9 @@ public:
    friend class Messages; friend class Messages;
    private: private:
    explicit inline Message(caosdb::entity::v1alpha1::Message *wrapped) explicit inline Message(ProtoMessage *wrapped) : wrapped(wrapped){};
    : wrapped(wrapped){};
    caosdb::entity::v1alpha1::Message *wrapped; ProtoMessage *wrapped;
    }; };
    /** /**
    ...@@ -87,8 +87,7 @@ public: ...@@ -87,8 +87,7 @@ public:
    private: private:
    inline Messages() : wrapped(nullptr){}; inline Messages() : wrapped(nullptr){};
    ::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Message> ::google::protobuf::RepeatedPtrField<ProtoMessage> *wrapped;
    *wrapped;
    }; };
    /** /**
    ...@@ -100,8 +99,7 @@ private: ...@@ -100,8 +99,7 @@ private:
    */ */
    class Parent { class Parent {
    public: public:
    explicit inline Parent(caosdb::entity::v1alpha1::Parent *wrapped) explicit inline Parent(ProtoParent *wrapped) : wrapped(wrapped){};
    : wrapped(wrapped){};
    Parent(); Parent();
    /** /**
    ...@@ -185,7 +183,7 @@ private: ...@@ -185,7 +183,7 @@ private:
    /** /**
    * Message which serves as storage backend. * Message which serves as storage backend.
    */ */
    mutable caosdb::entity::v1alpha1::Parent *wrapped; mutable ProtoParent *wrapped;
    // Messages errors; // Messages errors;
    // Messages warnings; // Messages warnings;
    // Messages infos; // Messages infos;
    ...@@ -216,8 +214,7 @@ public: ...@@ -216,8 +214,7 @@ public:
    private: private:
    inline Parents(){}; inline Parents(){};
    explicit inline Parents( explicit inline Parents(
    ::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Parent> ::google::protobuf::RepeatedPtrField<ProtoParent> *wrapped)
    *wrapped)
    : wrapped(wrapped){}; : wrapped(wrapped){};
    /** /**
    ...@@ -230,8 +227,7 @@ private: ...@@ -230,8 +227,7 @@ private:
    * The collection of parent messages which serves as a backend for this * The collection of parent messages which serves as a backend for this
    * class. * class.
    */ */
    ::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Parent> ::google::protobuf::RepeatedPtrField<ProtoParent> *wrapped;
    *wrapped;
    }; };
    /** /**
    ...@@ -242,8 +238,7 @@ private: ...@@ -242,8 +238,7 @@ private:
    */ */
    class Property { class Property {
    public: public:
    explicit inline Property(caosdb::entity::v1alpha1::Property *wrapped) explicit inline Property(ProtoProperty *wrapped) : wrapped(wrapped){};
    : wrapped(wrapped){};
    Property(); Property();
    /** /**
    ...@@ -288,6 +283,10 @@ public: ...@@ -288,6 +283,10 @@ public:
    * Set the name of this property. * Set the name of this property.
    */ */
    auto SetName(const std::string &name) -> void; auto SetName(const std::string &name) -> void;
    /**
    * Set the description of this property.
    */
    auto SetDescription(const std::string &description) -> void;
    /** /**
    * Set the importance of this property. * Set the importance of this property.
    */ */
    ...@@ -325,7 +324,7 @@ public: ...@@ -325,7 +324,7 @@ public:
    private: private:
    static auto CreateProtoProperty() -> ProtoProperty *; static auto CreateProtoProperty() -> ProtoProperty *;
    mutable caosdb::entity::v1alpha1::Property *wrapped; mutable ProtoProperty *wrapped;
    }; };
    /** /**
    ...@@ -353,8 +352,7 @@ public: ...@@ -353,8 +352,7 @@ public:
    private: private:
    inline Properties(){}; inline Properties(){};
    explicit inline Properties( explicit inline Properties(
    ::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Property> ::google::protobuf::RepeatedPtrField<ProtoProperty> *wrapped)
    *wrapped)
    : wrapped(wrapped){}; : wrapped(wrapped){};
    /** /**
    ...@@ -364,8 +362,7 @@ private: ...@@ -364,8 +362,7 @@ private:
    */ */
    auto Append(const Property &property) -> void; auto Append(const Property &property) -> void;
    ::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Property> ::google::protobuf::RepeatedPtrField<ProtoProperty> *wrapped;
    *wrapped;
    }; };
    /** /**
    ...@@ -442,6 +439,10 @@ public: ...@@ -442,6 +439,10 @@ public:
    auto SetRole(const std::string &role) -> void; auto SetRole(const std::string &role) -> void;
    auto SetName(const std::string &name) -> void; auto SetName(const std::string &name) -> void;
    /**
    * Set the description of this entity.
    */
    auto SetDescription(const std::string &description) -> void;
    auto SetValue(const std::string &value) -> void; auto SetValue(const std::string &value) -> void;
    auto SetUnit(const std::string &unit) -> void; auto SetUnit(const std::string &unit) -> void;
    ......
    ...@@ -38,10 +38,10 @@ namespace caosdb::logging { ...@@ -38,10 +38,10 @@ namespace caosdb::logging {
    const std::string logger_name = "caosdb::logging"; const std::string logger_name = "caosdb::logging";
    typedef boost::log::sources::severity_channel_logger<int, std::string> typedef boost::log::sources::severity_channel_logger_mt<int, std::string>
    boost_logger_class; boost_logger_class;
    BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(logger, boost_logger_class) BOOST_LOG_GLOBAL_LOGGER(logger, boost_logger_class)
    /** /**
    * This class stores the integer log level. * This class stores the integer log level.
    ......
    ...@@ -302,8 +302,9 @@ auto LoggingConfigurationHelper::CreateSinkConfiguration( ...@@ -302,8 +302,9 @@ auto LoggingConfigurationHelper::CreateSinkConfiguration(
    assert(from.contains("destination")); assert(from.contains("destination"));
    const auto &destination = const auto &destination =
    std::string(from.at("destination").as_string().c_str()); std::string(from.at("destination").as_string().c_str());
    int level = from.contains("level") int level = from.contains("level")
    ? static_cast<int>(from.at("level").as_int64()) ? ConvertLogLevel(from.at("level").as_string().c_str())
    : default_level; : default_level;
    if (destination == "file") { if (destination == "file") {
    ...@@ -317,38 +318,43 @@ auto LoggingConfigurationHelper::CreateSinkConfiguration( ...@@ -317,38 +318,43 @@ auto LoggingConfigurationHelper::CreateSinkConfiguration(
    } }
    } }
    auto LoggingConfigurationHelper::CreateLoggingConfiguration( auto LoggingConfigurationHelper::ConvertLogLevel(
    const object &from) const -> LoggingConfiguration { const std::string &string_level) const -> int {
    auto default_level_str = from.contains("level")
    ? std::string(from.at("level").as_string().c_str())
    : "";
    int default_level = 0;
    static std::map<std::string, int> log_level_names = { static std::map<std::string, int> log_level_names = {
    {"", CAOSDB_DEFAULT_LOG_LEVEL}, {"off", CAOSDB_LOG_LEVEL_OFF}, {"", CAOSDB_DEFAULT_LOG_LEVEL}, {"off", CAOSDB_LOG_LEVEL_OFF},
    {"fatal", CAOSDB_LOG_LEVEL_FATAL}, {"error", CAOSDB_LOG_LEVEL_ERROR}, {"fatal", CAOSDB_LOG_LEVEL_FATAL}, {"error", CAOSDB_LOG_LEVEL_ERROR},
    {"warn", CAOSDB_LOG_LEVEL_WARN}, {"info", CAOSDB_LOG_LEVEL_INFO}, {"warn", CAOSDB_LOG_LEVEL_WARN}, {"info", CAOSDB_LOG_LEVEL_INFO},
    {"debug", CAOSDB_LOG_LEVEL_DEBUG}, {"trace", CAOSDB_LOG_LEVEL_TRACE}, {"debug", CAOSDB_LOG_LEVEL_DEBUG}, {"trace", CAOSDB_LOG_LEVEL_TRACE},
    {"all", CAOSDB_LOG_LEVEL_ALL}}; {"all", CAOSDB_LOG_LEVEL_ALL}};
    try { try {
    default_level = CAOSDB_DEFAULT_LOG_LEVEL; return log_level_names.at(string_level);
    } catch (const std::out_of_range &exc) { } catch (const std::out_of_range &exc) {
    throw ConfigurationError("Unknown log level: " + default_level_str); throw ConfigurationError("Unknown log level: " + string_level);
    } }
    }
    auto LoggingConfigurationHelper::CreateLoggingConfiguration(
    const object &from) const -> LoggingConfiguration {
    auto default_level_str = from.contains("level")
    ? std::string(from.at("level").as_string().c_str())
    : "";
    int default_level = ConvertLogLevel(default_level_str);
    auto result = LoggingConfiguration(default_level); auto result = LoggingConfiguration(default_level);
    if (default_level == CAOSDB_LOG_LEVEL_OFF) { if (default_level == CAOSDB_LOG_LEVEL_OFF) {
    return result; return result;
    } }
    const auto &sinks = from.at("sinks").as_object(); if (from.contains("sinks")) {
    if (!sinks.empty()) { const auto &sinks = from.at("sinks").as_object();
    const auto *elem = sinks.begin(); if (!sinks.empty()) {
    const auto *elem = sinks.begin();
    while (elem != sinks.end()) { while (elem != sinks.end()) {
    result.AddSink(CreateSinkConfiguration( result.AddSink(CreateSinkConfiguration(
    elem->value().as_object(), elem->key().to_string(), default_level)); elem->value().as_object(), elem->key().to_string(), default_level));
    elem = std::next(elem); elem = std::next(elem);
    }
    } }
    } }
    ......
    ...@@ -114,6 +114,10 @@ auto Property::SetName(const std::string &name) -> void { ...@@ -114,6 +114,10 @@ auto Property::SetName(const std::string &name) -> void {
    this->wrapped->set_name(name); this->wrapped->set_name(name);
    } }
    auto Property::SetDescription(const std::string &description) -> void {
    this->wrapped->set_description(description);
    }
    auto Property::SetImportance(const std::string &importance) -> void { auto Property::SetImportance(const std::string &importance) -> void {
    this->wrapped->set_importance(importance); this->wrapped->set_importance(importance);
    } }
    ...@@ -193,6 +197,10 @@ auto Entity::SetName(const std::string &name) -> void { ...@@ -193,6 +197,10 @@ auto Entity::SetName(const std::string &name) -> void {
    this->wrapped->set_name(name); this->wrapped->set_name(name);
    } }
    auto Entity::SetDescription(const std::string &description) -> void {
    this->wrapped->set_description(description);
    }
    auto Entity::SetValue(const std::string &value) -> void { auto Entity::SetValue(const std::string &value) -> void {
    this->wrapped->set_value(value); this->wrapped->set_value(value);
    } }
    ......
    ...@@ -44,6 +44,10 @@ ...@@ -44,6 +44,10 @@
    namespace caosdb::logging { namespace caosdb::logging {
    BOOST_LOG_GLOBAL_LOGGER_INIT(logger, boost_logger_class) {
    boost_logger_class lg;
    return lg;
    }
    LoggingConfiguration::LoggingConfiguration(int level) LoggingConfiguration::LoggingConfiguration(int level)
    : LevelConfiguration(level) {} : LevelConfiguration(level) {}
    ...@@ -156,6 +160,11 @@ auto initialize_logging_defaults() -> int { ...@@ -156,6 +160,11 @@ auto initialize_logging_defaults() -> int {
    // Called if custom logging settings are specified. // Called if custom logging settings are specified.
    auto initialize_logging(const LoggingConfiguration &configuration) -> void { auto initialize_logging(const LoggingConfiguration &configuration) -> void {
    // first: turn everything off
    boost::log::settings off_settings;
    off_settings["Core.DisableLogging"] = true;
    boost::log::init_from_settings(off_settings);
    boost::log::settings new_settings; boost::log::settings new_settings;
    if (configuration.GetLevel() == CAOSDB_LOG_LEVEL_OFF) { if (configuration.GetLevel() == CAOSDB_LOG_LEVEL_OFF) {
    ......
    ...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
    namespace caosdb::entity { namespace caosdb::entity {
    using caosdb::entity::v1alpha1::IdResponse; using caosdb::entity::v1alpha1::IdResponse;
    using ProtoEntity = caosdb::entity::v1alpha1::Entity; using ProtoEntity = caosdb::entity::v1alpha1::Entity;
    using ProtoParent = caosdb::entity::v1alpha1::Parent;
    using caosdb::utility::get_arena; using caosdb::utility::get_arena;
    TEST(test_entity, test_parent_setters) { TEST(test_entity, test_parent_setters) {
    ...@@ -260,4 +261,25 @@ TEST(test_entity, test_from_id_response) { ...@@ -260,4 +261,25 @@ TEST(test_entity, test_from_id_response) {
    EXPECT_EQ(other_ent.GetInfos().At(0).GetDescription(), "info_desc"); EXPECT_EQ(other_ent.GetInfos().At(0).GetDescription(), "info_desc");
    EXPECT_EQ(other_ent.GetInfos().At(0).GetCode(), MessageCode::UNSPECIFIED); EXPECT_EQ(other_ent.GetInfos().At(0).GetCode(), MessageCode::UNSPECIFIED);
    } }
    TEST(test_entity, test_description) {
    Entity entity;
    Property property;
    Parent parent;
    EXPECT_EQ(entity.GetDescription(), "");
    EXPECT_EQ(property.GetDescription(), "");
    EXPECT_EQ(parent.GetDescription(), "");
    entity.SetDescription("desc entity");
    property.SetDescription("desc property");
    // Parent has not setter
    ProtoParent protoParent;
    protoParent.set_description("desc parent");
    parent = Parent(&protoParent);
    EXPECT_EQ(entity.GetDescription(), "desc entity");
    EXPECT_EQ(property.GetDescription(), "desc property");
    EXPECT_EQ(parent.GetDescription(), "desc parent");
    }
    } // namespace caosdb::entity } // namespace caosdb::entity
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment