Example #1
0
def direct_copy_raw_schema_to_topic(model_schema: ModelSchema, topic: Topic):
    if topic is None:
        topic = Topic()
    topic.topicName = model_schema.name
    topic.factors = convert_business_fields_to_factors(
        model_schema.businessFields)
    return topic
def update_topic_schema(
        topic_id,
        topic: Topic):
    if type(topic) is not dict:
        topic = topic.dict()
    update_topic(topic_id, topic)
    return Topic.parse_obj(topic)
def create_topic_schema(topic):
    if topic.topicId is None or check_fake_id(topic.topicId):
        topic.topicId = get_surrogate_key()
    if type(topic) is not dict:
        topic = topic.dict()
    save_topic(topic)
    return Topic.parse_obj(topic)
async def update_topic(topic_id,
                       topic: Topic = Body(...),
                       current_user: User = Depends(deps.get_current_user)):
    topic = Topic.parse_obj(topic)
    data = update_topic_schema(topic_id, topic)
    # remove_presto_schema_by_name(topic.name)
    create_or_update_presto_schema_fields(data)
    return data
Example #5
0
async def save_topic(topic: Topic, current_user: User = Depends(deps.get_current_user)):
    if check_fake_id(topic.topicId):
        result = create_topic_schema(topic)
        create_or_update_presto_schema_fields(result)
        return result
    else:
        topic = Topic.parse_obj(topic)
        data = update_topic_schema(topic.topicId, topic)
        create_or_update_presto_schema_fields(data)
        return data
def crate_topic_by_raw_data_schema(schema, topic_list, mapping_list):
    factor_list = []
    node: schema
    topic: Topic = Topic(
        **{
            'topic_id': get_surrogate_key(),
            'name': '',
            'topic_type': '',
            'factors': []
        })
    mapping: {}
    # 遍历tree, 创建mapping和topic
    node = schema
    entity = node.data_entity

    # 每个node上的data_entity对应一个topic,data_entity上的一个attr对应一个factor
    topic.name = entity.name
    topic.topic_type = 'test'
    attr_list = entity.attrs
    mapping = Mapping(
        **{
            'mapping_id': get_surrogate_key(),
            'source_entity_id': entity.entity_id,
            'source_entity_name': entity.name,
            'target_topic_id': topic.topicId,
            'target_topic_name': entity.name,
            'mapping_detail_list': []
        })
    mapping_detail_list = []
    for attr in attr_list:
        factor: Factor = Factor(**{
            'id': get_surrogate_key(),
            'name': '',
            'type': ''
        })
        factor.name = attr.name
        factor.type = attr.type
        factor_list.append(factor)
        mapping_detail = MappingDetail(**{
            'source_attr': attr,
            'target_factor': factor
        })
        mapping_detail_list.append(mapping_detail)

    topic.factors = factor_list
    topic_list.append(topic)
    mapping.mapping_detail_list = mapping_detail_list
    mapping_list.append(mapping)
    if len(node.childs) == 0:
        return
    else:
        for node in node.childs:
            crate_topic_by_raw_data_schema(node, topic_list, mapping_list)
    return mapping_list
Example #7
0
def build_topic(model_schema_set: ModelSchemaSet):
    topic = Topic()
    topic.topicId = get_surrogate_key()
    topic.name = model_schema_set.code
    topic.type = "raw"
    topic.factors = []
    parent = ""
    build_factors(topic.factors, parent, model_schema_set.schemas[topic.name],
                  model_schema_set)
    create_topic_schema(topic)
def topic_dict_to_object(topic_schema_dict):
    topic = Topic()
    return topic
def get_topic_by_id(topic_id):
    result = topics.find_one({"topicId": topic_id})
    if result is None:
        return None
    else:
        return Topic.parse_obj(result)
def get_topic(topic_name) -> Topic:
    result = topics.find_one({"name": topic_name})
    if result is None:
        return None
    else:
        return Topic.parse_obj(result)