53 lines
2.3 KiB
C++
53 lines
2.3 KiB
C++
#ifndef SOURCE_FEED_RELATION_H
|
|
#define SOURCE_FEED_RELATION_H
|
|
#include <stdexcept>
|
|
#include <string_view>
|
|
#include "../global_include.h"
|
|
#include "adminive/managed.hpp"
|
|
struct Source_Feed_Relation_Data {
|
|
bool enable{};
|
|
std::string source_key;
|
|
std::string feed_key;
|
|
std::string feed_name;
|
|
PSC_USE_JSON
|
|
};
|
|
namespace adminive {
|
|
template <>
|
|
struct Type_Descriptor<Source_Feed_Relation_Data> {
|
|
static auto get() {
|
|
using T = Source_Feed_Relation_Data;
|
|
return object<T>("source_feed_relation_data", "数据源-数据馈送关系",
|
|
ADMINIVE_FIELD_LABEL(T, enable, "启用").editable().boolean_input(),
|
|
ADMINIVE_FIELD_LABEL(T, source_key, "数据源名称").editable().text_input(),
|
|
ADMINIVE_FIELD_LABEL(T, feed_key, "数据馈送名称").editable().text_input(),
|
|
ADMINIVE_FIELD_LABEL(T, feed_name, "数据馈送名称前缀").editable().text_input());
|
|
}
|
|
};
|
|
}
|
|
struct Source_Feed_Relation {
|
|
std::string key;
|
|
std::string type;
|
|
adminive::Managed_Value<Source_Feed_Relation_Data> settings;
|
|
void from_json(const Psc::JSON* that_json);
|
|
[[nodiscard]] Psc::JSON to_json() const;
|
|
};
|
|
inline std::shared_ptr<Source_Feed_Relation> create_source_feed_relation_from_type(std::string_view type) {
|
|
if (type != "One_to_One_Relation" && type != "Name_One_To_Many_Relation" && type != "First_Source_To_All_Feed_Relation")
|
|
throw std::invalid_argument("unknown Source_Feed_Relation type: " + std::string(type));
|
|
auto result = std::make_shared<Source_Feed_Relation>();
|
|
result->type = type;
|
|
return result;
|
|
}
|
|
struct Source_Feed_Relation_Config {
|
|
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value);
|
|
[[nodiscard]] Psc::JSON to_json() const;
|
|
Ordered_Map<std::string, std::shared_ptr<Source_Feed_Relation>> map;
|
|
static void set_need_refresh();
|
|
[[nodiscard]] bool source_exists(std::string_view key) const;
|
|
[[nodiscard]] bool feed_exists(std::string_view key) const;
|
|
[[nodiscard]] bool source_has_dependency(std::string_view key) const;
|
|
[[nodiscard]] bool feed_has_dependency(std::string_view key) const;
|
|
void validate(const Source_Feed_Relation& relation, std::string_view current_key = {}) const;
|
|
};
|
|
#endif
|