Exemplo n.º 1
0
async def save_user_group(user_group: UserGroup, current_user: User = Depends(deps.get_current_user)):
    if check_fake_id(user_group.userGroupId):
        user_group.userGroupId = None
    if user_group.userGroupId is None or check_fake_id(user_group.userGroupId):
        return create_user_group_storage(user_group)
    else:
        return update_user_group_storage(user_group)
Exemplo n.º 2
0
async def save_user_group(user_group: UserGroup,
                          current_user: User = Depends(deps.get_current_user)):
    if check_fake_id(user_group.userGroupId):
        user_group.userGroupId = None
    if user_group.userGroupId is None or check_fake_id(user_group.userGroupId):
        result = create_user_group_storage(user_group)
        sync_user_group_to_space(result)
        return result
    else:
        sync_user_group_to_space(user_group)
        return update_user_group_storage(user_group)
Exemplo n.º 3
0
def save_console_space(console_space: ConsoleSpace):
    if console_space.connectId is None or check_fake_id(
            console_space.connectId):
        console_space.connectId = get_surrogate_key()
        return create_console_space(console_space)
    else:
        return update_console_space(console_space)
def create_user_group_storage(user_group: UserGroup):
    if user_group.userGroupId is None or check_fake_id(user_group.userGroupId):
        user_group.userGroupId = get_surrogate_key()
    if type(user_group) is not dict:
        user_group = user_group.dict()
    user_groups.insert_one(user_group)
    return user_group
Exemplo n.º 5
0
def create_console_group_to_storage(group: ConsoleSpaceGroup):
    with get_client_db() as client:
        if group.groupId is None or check_fake_id(group.groupId):
            group.groupId = get_surrogate_key()
        client[WATCHMEN].get_collection(GROUP_COLLECTION).insert_one(
            group.dict())
        return ConsoleSpaceGroup.parse_obj(group)
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)
Exemplo n.º 7
0
def create_space(space: Space):
    if space.spaceId is None or check_fake_id(space.spaceId):
        space.spaceId = get_surrogate_key()
    if type(space) is not dict:
        space = space.dict()

    insert_space_to_storage(space)
    return space
Exemplo n.º 8
0
def create_topic_schema(topic: Topic) -> Topic:
    if topic.topicId is None or check_fake_id(topic.topicId):
        topic.topicId = get_surrogate_key()
    save_topic(topic)
    result = Topic.parse_obj(topic)
    if settings.INDEX_ON and topic.type != RAW:
        factor_index_service.create_factor_index_data(result, topic.tenantId)
    return result
Exemplo n.º 9
0
def save_data_source(data_source: DataSource, current_user: User = None):
    if check_fake_id(data_source.dataSourceId):
        data_source.dataSourceId = get_surrogate_key()
        return storage_template.insert_one(data_source, DataSource,
                                           DATA_SOURCES)
    else:
        return storage_template.update_one(data_source, DataSource,
                                           DATA_SOURCES)
async def save_external_writer(external_writer: ExternalWriter,
                               current_user: User = Depends(
                                   deps.get_current_user)):
    if check_fake_id(external_writer.writerId):
        external_writer.writerId = get_surrogate_key()
        return external_storage.create(external_writer)
    else:
        return external_storage.update(external_writer)
async def save_tenant(
    tenant: Tenant,
    current_user: User = Depends(deps.get_current_user)) -> Tenant:
    if check_fake_id(tenant.tenantId):
        tenant.tenantId = get_surrogate_key()
        return tenant_service.create(tenant)
    else:
        return tenant_service.update(tenant)
Exemplo n.º 12
0
async def save_user(user: User) -> User:
    if user.userId is None or check_fake_id(user.userId):
        result = create_user_storage(user)
        sync_user_to_user_groups(result)
        return result
    else:
        sync_user_to_user_groups(user)
        return update_user_storage(user)
Exemplo n.º 13
0
async def save_space(space: Space, current_user: User = Depends(deps.get_current_user)):
    if space.spaceId is None or check_fake_id(space.spaceId):
        # sync space group id
        result = create_space(space)
        sync_space_to_user_group(result)
        return result
    else:
        sync_space_to_user_group(space)
        return update_space_by_id(space.spaceId, space)
Exemplo n.º 14
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 save_enum_to_storage(enum: Enum):
    if check_fake_id(enum.enumId):
        enum.enumId = get_surrogate_key()
        items_copy = enum.items.copy()
        enum.items = []
        result = template.create(ENUMS, enum, Enum)
        items = __add_enum_id(items_copy, result.enumId)
        save_enum_items_to_storage(items)
        return result
    else:
        items_copy = enum.items.copy()
        enum.items = []
        items = __add_enum_id(items_copy, enum.enumId)
        save_enum_items_to_storage(items)
        return template.update_one(ENUMS, {"enumId": enum.enumId}, enum, Enum)
Exemplo n.º 16
0
def save_enum_to_storage(enum: Enum):
    if check_fake_id(enum.enumId):
        enum.enumId = get_surrogate_key()
        # enum.items = []
        # result = template.create(ENUMS, enum, Enum)
        result = storage_template.insert_one(enum, Enum, ENUMS)
        # items = __add_enum_id(items_copy, result.enumId)
        # save_enum_items_to_storage(items_copy, enum.name)
        return result
    else:
        # items_copy = enum.items.copy()
        # # enum.items = []
        # # items = __add_enum_id(items_copy, enum.enumId)
        # save_enum_items_to_storage(items_copy, enum.name)
        # # return template.update_one(ENUMS, {"enumId": enum.enumId}, enum, Enum)
        return storage_template.update_one(enum, Enum, ENUMS)
Exemplo n.º 17
0
async def create_console_subject(connect_id, subject: ConsoleSpaceSubject = Body(...),
                                 current_user: User = Depends(deps.get_current_user)):
    if check_fake_id(subject.subjectId):
        subject.subjectId = None
        console_space = load_console_space_by_id(connect_id)

        for report in subject.reports:
            report.reportId = get_surrogate_key()
            subject.reportIds.append(report.reportId)

        subject = create_console_subject_to_storage(subject)
        console_space.subjectIds.append(subject.subjectId)
        save_console_space(console_space)

        return subject
    else:
        raise Exception("id is not fake ID")
def create_dashboard_to_storage(dashboard: ConsoleDashboard):
    if dashboard.dashboardId is None or check_fake_id(dashboard.dashboardId):
        dashboard.dashboardId = get_surrogate_key()

    return template.create(DASHBOARDS, dashboard, ConsoleDashboard)
Exemplo n.º 19
0
def save_enum_to_storage(enum: Enum):
    if check_fake_id(enum.enumId):
        template.create(ENUMS, enum, Enum)
    else:
        template.update_one(ENUMS, {"enumId": enum.enumId}, enum, Enum)
Exemplo n.º 20
0
def create_dashboard_to_storage(dashboard: ConsoleDashboard):
    if dashboard.dashboardId is None or check_fake_id(dashboard.dashboardId):
        dashboard.dashboardId = get_surrogate_key()
    console_dashboards.insert_one(dashboard.dict())
    return ConsoleDashboard.parse_obj(dashboard)
def save_enum_items_to_storage(items: List[EnumItem]):
    for item in items:
        if item.itemId is None or check_fake_id(item.itemId):
            item.itemId = get_surrogate_key()
        # template.create_or_update(ENUM_ITEMS, {"itemId": item.itemId}, item, EnumItem)
        upsert_({"itemId": item.itemId}, item, EnumItem, ENUM_ITEMS)
Exemplo n.º 22
0
async def save_user(user: User):
    if user.userId is None or check_fake_id(user.userId):
        return create_user_storage(user)
    else:
        return update_user_storage(user)
Exemplo n.º 23
0
def create_console_subject_to_storage(subject: ConsoleSpaceSubject):
    if subject.subjectId is None or check_fake_id(subject.subjectId):
        subject.subjectId = get_surrogate_key()
    return template.create(CONSOLE_SPACE_SUBJECTS, subject,
                           ConsoleSpaceSubject)
Exemplo n.º 24
0
def create_user_group_storage(user_group: UserGroup):
    if user_group.userGroupId is None or check_fake_id(user_group.userGroupId):
        user_group.userGroupId = get_surrogate_key()
    return template.create(USER_GROUPS, user_group, UserGroup)
Exemplo n.º 25
0
async def save_space(space: Space, current_user: User = Depends(deps.get_current_user)):
    if space.spaceId is None or check_fake_id(space.spaceId):
        return create_space(space)
    else:
        return update_space_by_id(space.spaceId, space)
Exemplo n.º 26
0
def create_user_group_storage(user_group: UserGroup) -> UserGroup:
    if user_group.userGroupId is None or check_fake_id(user_group.userGroupId):
        user_group.userGroupId = get_surrogate_key()
    return storage_template.insert_one(user_group, UserGroup, USER_GROUPS)