diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..6b881b98fc2d90ba4bff31e9d896590222164806 --- /dev/null +++ b/Makefile @@ -0,0 +1,40 @@ +# ** header v3.0 +# This file is a part of the CaosDB Project. +# +# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> +# Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# +# ** end header + +# This Makefile is a wrapper for several other scripts. + + +CLANG-FORMAT = clang-format-11 + +.PHONY: help +help: + @echo "Targets:" + @echo " conan-install - Install locally with Conan." + @echo " style - auto-format the source files." + +style: + $(CLANG-FORMAT) -i --verbose \ + $$(find test/ src/ include/ -type f -iname "*.cpp" -o -iname "*.h" -o -iname "*.h.in") +.PHONY: style + +conan-install: + conan create . -s "compiler.libcxx=libstdc++11" +.PHONY: install diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index d763bfe1683072c2571e7d9b728343d9ab8a913e..63b357bc9116252edb3dbf76b4a4bc97cdf4901c 100644 --- a/include/caosdb/entity.h +++ b/include/caosdb/entity.h @@ -54,6 +54,8 @@ public: } friend class Entity; + friend class Parent; + friend class Property; friend class Messages; private: @@ -74,6 +76,8 @@ public: } friend class Entity; + friend class Parent; + friend class Property; private: inline Messages() : wrapped(nullptr){}; @@ -135,15 +139,27 @@ public: /** * Return the error messages of this parent. */ - [[nodiscard]] inline auto GetErrors() const -> const Messages &; + [[nodiscard]] inline auto GetErrors() const -> const Messages & { + return errors; + } + [[nodiscard]] inline auto HasErrors() const -> bool { + return this->errors.wrapped->size() > 0; + } /** * Return the warning messages of this parent. */ - [[nodiscard]] inline auto GetWarnings() const -> const Messages &; + [[nodiscard]] inline auto GetWarnings() const -> const Messages & { + return warnings; + } + [[nodiscard]] inline auto HasWarnings() const -> bool { + return this->warnings.wrapped->size() > 0; + } /** * Return the info messages of this parent. */ - [[nodiscard]] inline auto GetInfos() const -> const Messages &; + [[nodiscard]] inline auto GetInfos() const -> const Messages & { + return infos; + } friend class Entity; friend class Parents; @@ -165,6 +181,9 @@ private: * Message which serves as storage backend. */ mutable caosdb::entity::v1alpha1::Parent *wrapped; + Messages errors; + Messages warnings; + Messages infos; }; /** @@ -316,6 +335,9 @@ public: [[nodiscard]] inline auto GetUnit() const -> const std::string & { return wrapped->unit(); }; + [[nodiscard]] inline auto GetValue() const -> const std::string & { + return wrapped->value(); + }; [[nodiscard]] auto GetParents() const -> const Parents &; [[nodiscard]] auto GetProperties() const -> const Properties &; @@ -328,6 +350,9 @@ public: [[nodiscard]] auto GetWarnings() const -> const Messages & { return warnings; } + [[nodiscard]] inline auto HasWarnings() const -> bool { + return this->warnings.wrapped->size() > 0; + } [[nodiscard]] auto GetInfos() const -> const Messages & { return infos; } inline auto ToString() const -> const std::string { @@ -341,7 +366,6 @@ public: auto SetRole(const std::string &role) -> void; auto SetName(const std::string &name) -> void; - // TODO(fspreck) ... and also these auto SetValue(const std::string &value) -> void; auto SetUnit(const std::string &unit) -> void; // Currently no references or lists. diff --git a/include/caosdb/status_code.h b/include/caosdb/status_code.h index 7a4cd4185d45b5a1f93f271973018ff2c2c42126..6e5f7587ea0e114e4eab61c4bd3960f80cdb514d 100644 --- a/include/caosdb/status_code.h +++ b/include/caosdb/status_code.h @@ -22,6 +22,8 @@ #ifndef CAOSDB_STATUS_CODE_H #define CAOSDB_STATUS_CODE_H +#include <string> + /** * StatusCodes represent the status of this client, it's connections, * configuration and so on. diff --git a/src/caosdb/entity.cpp b/src/caosdb/entity.cpp index 57935d1cb7bd7565a2d64d8b22b2f761246f600a..84105eda6bebbead819d66ae92f5b693fc293481 100644 --- a/src/caosdb/entity.cpp +++ b/src/caosdb/entity.cpp @@ -28,7 +28,11 @@ using ProtoParent = caosdb::entity::v1alpha1::Parent; using ProtoEntity = caosdb::entity::v1alpha1::Entity; using caosdb::utility::get_arena; -Parent::Parent() : wrapped(Parent::CreateProtoParent()) {} +Parent::Parent() : wrapped(Parent::CreateProtoParent()) { + errors.wrapped = this->wrapped->mutable_errors(); + warnings.wrapped = this->wrapped->mutable_warnings(); + infos.wrapped = this->wrapped->mutable_infos(); +} auto Parent::CreateProtoParent() -> ProtoParent * { return google::protobuf::Arena::CreateMessage<ProtoParent>(get_arena()); @@ -107,4 +111,16 @@ auto Entity::SetName(const std::string &name) -> void { this->wrapped->set_name(name); } +auto Entity::SetValue(const std::string &value) -> void { + this->wrapped->set_value(value); +} + +auto Entity::SetUnit(const std::string &unit) -> void { + this->wrapped->set_unit(unit); +} + +auto Entity::SetDatatype(const std::string &datatype) -> void { + this->wrapped->set_datatype(datatype); +} + } // namespace caosdb::entity diff --git a/test/test_entity.cpp b/test/test_entity.cpp index 62e52abf3cccfedae4c9d581f2952fc5f5b9123f..4c0820d84dfe9fac7231c0db32151aac40c8b495 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -73,6 +73,31 @@ TEST(test_entity, test_insert_entity) { EXPECT_EQ(entity.GetName(), "entity_name"); } +// TODO(fspreck) cognitive complexity > 25 (threshold) +TEST(test_entity, test_insert_with_role) { // NOLINT + auto transaction = caosdb::transaction::Transaction( + std::shared_ptr<transaction::EntityTransactionService::Stub>(nullptr)); + + auto entity = Entity(); + entity.SetId("entity_id"); + entity.SetVersionId("version_id"); + entity.SetRole("Property"); + entity.SetDatatype("DOUBLE"); + entity.SetName("Length"); + entity.SetUnit("m"); + entity.SetValue("5.5"); + + transaction.InsertEntity(&entity); + + EXPECT_EQ(entity.GetId(), "entity_id"); + EXPECT_EQ(entity.GetVersionId(), "version_id"); + EXPECT_EQ(entity.GetRole(), "Property"); + EXPECT_EQ(entity.GetDatatype(), "DOUBLE"); + EXPECT_EQ(entity.GetName(), "Length"); + EXPECT_EQ(entity.GetUnit(), "m"); + EXPECT_EQ(entity.GetValue(), "5.5"); +} + // TODO(tf) cognitive complexity > 25 (threshold) TEST(test_entity, test_from_id_response) { // NOLINT IdResponse idResponse; @@ -84,6 +109,7 @@ TEST(test_entity, test_from_id_response) { // NOLINT Entity entity(&idResponse); EXPECT_EQ(entity.GetId(), "entity_id"); + EXPECT_TRUE(entity.HasErrors()); EXPECT_EQ(entity.GetErrors().Size(), 1); EXPECT_EQ(entity.GetErrors().At(0).GetDescription(), "error_desc"); EXPECT_EQ(entity.GetErrors().At(0).GetCode(), @@ -105,6 +131,7 @@ TEST(test_entity, test_from_id_response) { // NOLINT EXPECT_EQ(other_ent.GetId(), "other_entity_id"); std::cout << entity.ToString() << std::endl; EXPECT_EQ(other_ent.GetWarnings().Size(), 1); + EXPECT_TRUE(other_ent.HasWarnings()); EXPECT_EQ(other_ent.GetWarnings().At(0).GetDescription(), "warning_desc"); EXPECT_EQ(other_ent.GetWarnings().At(0).GetCode(), MessageCode::ENTITY_HAS_NO_PROPERTIES);