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 6d542d4f885f38eea214763754e3bbfebe624286..e731f9a0d31f8a8e792ad614ea86e16d260b1b0d 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; }; /** @@ -310,6 +329,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 &; @@ -322,6 +344,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 { @@ -337,7 +362,6 @@ public: auto SetName(const std::string &name) -> void; auto SetVersionId(const std::string &id) -> 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 7d2f9f9572d4f6f2d44ef7ac167f760d9ce62534..9ca2f34ca1896f81f9611bf489133d5263803d79 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 24fd3824aa20c35a253f4cdd6d2020e180e1a1c7..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()); @@ -75,6 +79,8 @@ Entity::Entity() : wrapped(Entity::CreateProtoEntity()) { properties.wrapped = this->wrapped->mutable_properties(); parents.wrapped = this->wrapped->mutable_parents(); errors.wrapped = this->wrapped->mutable_errors(); + warnings.wrapped = this->wrapped->mutable_warnings(); + infos.wrapped = this->wrapped->mutable_infos(); } Entity::Entity(IdResponse *idResponse) : Entity() { @@ -105,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 1f3adf99b0702f7a369e20b42d2f8a3af3ea94dd..66423eb49300422439a75ec20f35e63d703053c1 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -73,6 +73,31 @@ TEST(test_entity, test_insert_entity) { EXPECT_EQ(entity.GetVersionId(), "version_id"); } +// 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; @@ -85,6 +110,7 @@ TEST(test_entity, test_from_id_response) { // NOLINT std::cout << entity.ToString() << std::endl; 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(), @@ -103,6 +129,7 @@ TEST(test_entity, test_from_id_response) { // NOLINT EXPECT_EQ(other_ent.GetId(), "other_entity_id"); 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);