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

Merge branch 'f-insert' into f-multi-retrieve

parents 8f115afb 3f9227e3
Branches
Tags
Loading
Pipeline #11117 failed
Makefile 0 → 100644
# ** 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
......@@ -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.
......
......@@ -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.
......
......@@ -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
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment