def _copy_file_example_phrases(text_data):

    copy_res = _file_copy(text_data)
    if not copy_res:
        return ErrorResponse(0, 'Save File Error.'), 400

    try:

        with psycopg2.connect(DB_CONNECT) as conn:
            with conn.cursor() as cur:

                # DB Truncate Table
                _truncate_example_phrases(cur)

                # DROP INDEX
                _drop_example_phrases(conn, cur)

                # DB file copy
                _copy_example_phrases(conn, cur, text_data.filename)

                # CREATE INDEX
                _create_index_example_phrases(conn, cur)

    except Exception as e:
        print(datetime.datetime.now(),
              '[_copy_file_example_phrases] Exception:', e, location())
        _file_delete(text_data)
        return ErrorResponse(0, 'Copy File Error.'), 400

    delete_res = _file_delete(text_data)
    if not delete_res:
        return ErrorResponse(0, 'Delete File Error.'), 400

    return SuccessResponse('request is success.'), 200
def _exec_insert_postgrest(payload, url):
    if not payload:
        print('[_exec_insert_postgrest] end(payload error)', location(),
              datetime.datetime.now())
        return ErrorResponse(0, 'Data Format Error.'), 400
    else:
        psg_res = requests.delete(POSTGREST_BASE_URL + url)
        try:
            psg_res.raise_for_status()
        except requests.exceptions.RequestException as e:
            print(e)
            print('[_exec_insert_postgrest] DELETE', url, 'error',
                  psg_res.reason, location(), datetime.datetime.now())
            return ErrorResponse(0, psg_res.reason), psg_res.status_code

        splitPayload = list(split_list(payload, SPLIT_COUNT))
        for i in range(len(splitPayload)):
            split = splitPayload[i]
            psg_res = requests.post(POSTGREST_BASE_URL + url,
                                    headers=HEADER,
                                    data=json.dumps(split))
            try:
                psg_res.raise_for_status()
            except requests.exceptions.RequestException as e:
                print(e)
                print(datetime.datetime.now(), '[_exec_insert_postgrest] POST',
                      url, 'error', i, '.', psg_res.reason, location())
                return ErrorResponse(0, psg_res.reason), psg_res.status_code

        return SuccessResponse('request is success.'), 200
def get_vocabulary_term(file_type, term):  # noqa: E501
    """Get editing vocabulary term

     # noqa: E501

    :param file_type: Specify only editing_vocabulary.   'editing_vocabulary' get editing vocabulary data.
    :type file_type: str
    :param term: Specify the term to request.
    :type term: str

    :rtype: EditingVocabulary
    """
    if not file_type == 'editing_vocabulary':
        print('[get_vocabulary_term] error. invalid param', file_type)
        return ErrorResponse(0, 'Invalid parameter.'), 400

    editing_vocabulary = None

    exec_sql = _create_select_sql(file_type, term)
    exec_res, status_code = _exec_get_postgrest(exec_sql)
    if not status_code == 200:
        return ErrorResponse(0, exec_res['message']), status_code

    if len(exec_res['result']) != 0:
        editing_vocabulary = exec_res['result'][0]

    return EditingVocabulary(editing_vocabulary), 200
def get_vocabulary_data(file_type):  # noqa: E501
    """Get vocabulary data by type

     # noqa: E501

    :param file_type: Specify for editing_vocabulary, reference_vocabulary1, etc.   'editing_vocabulary' get editing vocabulary data.   'reference_vocabulary1' get reference vocabulary1 data.   'reference_vocabulary2' get reference vocabulary2 data.   'reference_vocabulary3' get reference vocabulary3 data.
    :type file_type: str

    :rtype: GetAllSuccessResponse
    """

    reference_vocabulary = []
    editing_vocabulary = []

    if file_type in REFERENCE_VOCABULARY:
        exec_sql = _create_select_sql(file_type)
        exec_res, status_code = _exec_get_postgrest(exec_sql)
        if not status_code == 200:
            return ErrorResponse(0, exec_res['message']), status_code

        reference_vocabulary = exec_res['result']

    elif file_type == 'editing_vocabulary':
        exec_sql = _create_select_sql(file_type)
        exec_res, status_code = _exec_get_postgrest(exec_sql)
        if not status_code == 200:
            return ErrorResponse(0, exec_res['message']), status_code

        editing_vocabulary = exec_res['result']

    else:
        print('[get_vocabulary_data] invalid param ', file_type)
        return ErrorResponse(0, 'Invalid parameter.'), 400

    return GetAllSuccessResponse(editing_vocabulary, reference_vocabulary), 200
def delete_vocabulary_term(body, file_type):  # noqa: E501
    """Delete editing vocabulary term

     # noqa: E501

    :param body: Specify the term id to request.

    :type body: List[]
    :param file_type: Specify only editing_vocabulary.   'editing_vocabulary' get editing vocabulary data.
    :type file_type: str

    :rtype: List[EditingVocabulary]
    """

    print('[delete_vocabulary_term] file_type :', file_type, ', body :', body)

    if not file_type == 'editing_vocabulary':
        print('[post_vocabulary_term] error. invalid param', file_type)
        return ErrorResponse(0, 'Invalid parameter.'), 400

    for id in body:
        delete_sql = _create_delete_sql(file_type, id)
        print('[delete_vocabulary_term] delete_sql :', delete_sql)
        exec_res, status_code = _exec_delete_postgrest(delete_sql)
        if not status_code == 200:
            return exec_res, status_code

    editing_vocabulary = []
    exec_res, status_code = _exec_get_postgrest('editing_vocabulary')
    if not status_code == 200:
        return ErrorResponse(0, exec_res['message']), status_code

    editing_vocabulary = exec_res['result']

    return editing_vocabulary, 200
def download_file(file_type, out_format):  # noqa: E501
    """Download the file from the server

     # noqa: E501

    :param file_type: Specify for editing_vocabulary or controlled_vocabulary.   'editing_vocabulary' get editing vocabulary file.   'controlled_vocabulary' get controlled vocabulary file.
    :type file_type: str
    :param out_format: Specify the file format.   when editing_vocabulary, format is csv or xlsx.   when controlled_vocabulary, format is n3, nquads, nt, trix, turtle, xml, json-ld.
    :type out_format: str

    :rtype: str
    """
    print('file_type:' + file_type + ' out_format:' + out_format)

    editing_vocabulary = []

    exec_sql = _create_select_sql('editing_vocabulary')
    exec_res, status_code = _exec_get_postgrest(exec_sql)
    if not status_code == 200:
        return ErrorResponse(0, exec_res.message), status_code

    editing_vocabulary = exec_res['result']
    if len(editing_vocabulary) <= 0:
        return ErrorResponse(0, 'Download file not found.'), 404

    if file_type == 'editing_vocabulary':
        # json to csv or xlsx
        ret_serialize =\
            _download_file_ev_serialize(editing_vocabulary, out_format)
    elif file_type == 'controlled_vocabulary':
        # Graph
        ret_graph = _download_file_make(editing_vocabulary)
        ret_serialize = _download_file_serialize(ret_graph, out_format)

    return ret_serialize
def post_vocabulary_term(body, file_type, term):  # noqa: E501
    """Add or Update editing vocabulary terms

     # noqa: E501

    :param body:
    :type body: list | bytes
    :param file_type: Specify only editing_vocabulary.   &#x27;editing_vocabulary&#x27; get editing vocabulary data.
    :type file_type: str
    :param term: Specify the update term
    :type term: str

    :rtype: List[EditingVocabulary]
    """

    # print('[post_vocabulary_term] file_type :', file_type )
    # print('[post_vocabulary_term] term :', term )

    if not file_type == 'editing_vocabulary':
        print('[post_vocabulary_term] error. invalid param', file_type)
        return ErrorResponse(0, 'Invalid parameter.'), 400

    for item in body:
        # print('[post_vocabulary_term] item :', item )
        payload = _create_update_payload(item)
        # print('[post_vocabulary_term] payload :', payload )

        if 'id' in item:
            # update data.
            update_sql = _create_update_sql(file_type, item['id'])
            exec_res, status_code = _exec_update_postgrest(payload, update_sql)
            if not status_code == 200:
                return exec_res, status_code
        else:
            # add data.
            exec_res, status_code = \
                _exec_insert_postgrest(payload, 'editing_vocabulary')
            if not status_code == 200:
                return exec_res, status_code

    editing_vocabulary = []
    exec_res, status_code = _exec_get_postgrest('editing_vocabulary')
    if not status_code == 200:
        return ErrorResponse(0, exec_res['message']), status_code

    editing_vocabulary = exec_res['result']

    return editing_vocabulary, 200
예제 #8
0
def task_user_id_get(userId, type):  # noqa: E501
    """Returns all his own published or accepted tasks in the page.

    Returns the published tasks, the max number is 10. If the page is the last page, the return all left. # noqa: E501

    :param userId: 
    :type userId: str
    :param type: acceptment or publishment
    :type type: str

    :rtype: List[Task]
    """
    tasks = task_manager.get_related_tasks(userId=userId, Type=type)
    if tasks is None:
        return ErrorResponse("error"), 400
    else:
        return [
            Task(id=item['task_id'],
                 money=item['money'],
                 icon=item['photo'],
                 title=item['title'],
                 max_num=item['max_num'],
                 desc=item['task_intro'],
                 part_num=item['participants_num']) for item in tasks
        ]
    return 'do some magic!'
예제 #9
0
def tasks_get(pageId, type=None):  # noqa: E501
    """Returns all related tasks according to the pageId.

    Returns the published tasks, the max number is 10. If the page is the last page, the return all left. # noqa: E501

    :param pageId: Page number
    :type pageId: int
    :param type: default, recommend, easy
    :type type: str

    :rtype: List[Task]
    """
    tasks = task_manager.get_task_list(page_id=pageId)
    if tasks is None:
        return ErrorResponse("error"), 400
    else:
        return [
            Task(id=item['task_id'],
                 money=item['money'],
                 icon=item['icon'],
                 title=item['title'],
                 max_num=item['max_num'],
                 desc=item['task_intro'],
                 part_num=item['participants_num']) for item in tasks
        ]
예제 #10
0
def user_info_put(body):  # noqa: E501
    """User modify his basic info.

     # noqa: E501

    :param body: 
    :type body: dict | bytes

    :rtype: UserInfo
    """
    if connexion.request.is_json:
        body = UserInfoWithoutId.from_dict(connexion.request.get_json())  # noqa: E501
    
    nickName = body.nick_name
    avatarUrl = body.avatar_url

    result = user_manager.modify(nick_name =nickName, avatar_url = avatarUrl)
    if result is not None:
         return UserInfo(
            user_id=result.user_id, 
            nick_name=result.nickname,
            avatar_url=result.photo,
            prove_state=result.isprove)
    else:
        return ErrorResponse(message="error"), 400
예제 #11
0
def user_session_post(body):  # noqa: E501
    """Users login

    Users login # noqa: E501

    :param body: 
    :type body: dict | bytes

    :rtype: UserInfo
    """
    if connexion.request.is_json:
        body = LoginCode.from_dict(connexion.request.get_json())  # noqa: E501
    js_code = body.js_code
    app_id = body.app_id
    app_secret = body.app_secret
    result = user_manager.login(js_code=js_code, app_id=app_id, app_secret=app_secret)
    if result is not None:
        return UserInfo(
            user_id=result.user_id, 
            nick_name=result.nickname,
            avatar_url=result.photo,
            prove_state=result.isprove)
    else:
        return ErrorResponse(message="登录失败"), 400
    return 'do some magic!'
def _check_trem_format_synonymous_relationship(payload_s):
    # An item that does not contain a key term is considered an error.
    for index, item in payload_s.iterrows():
        wk_preferred_label =\
            item['用語名'] if pd.notnull(item['用語名']) else None
        if wk_preferred_label is None:
            return ErrorResponse(0, 'Data Format Error.'), 400
    return SuccessResponse('request is success.'), 200
def _check_trem_format_reference_vocabulary(payload):
    # An item that does not contain a key term is considered an error.
    for item in payload:
        wk_preferred_label =\
            item['term'] if pd.notnull(item['term']) else None
        if wk_preferred_label is None:
            return ErrorResponse(0, 'Data Format Error.'), 400
    return SuccessResponse('request is success.'), 200
def get_example_phrases(term, index):  # noqa: E501
    """Get example phrases

     # noqa: E501

    :param term: Get example phrases
    :type term: str
    :param index: Get example phrases
    :type index: int

    :rtype: SearchSuccessResponse
    """
    print('[get_example_phrases] start term:', term, ', index:', index)

    data = {'PGroonga': term}
    count_r = requests.post(POSTGREST_BASE_URL + SEARCH_COUNT_URL, json=data)
    try:
        count_r.raise_for_status()
    except requests.exceptions.RequestException as e:
        print('[get_example_phrases] error code:', end="")
        print(count_r.status_code, ', reason:', count_r.reason)
        return ErrorResponse(0, count_r.reason), count_r.status_code

    result_count = json.loads(count_r.text)
    print('example_search_count_func : ', result_count)

    data = {'PGroonga': term, 'index': index}
    search_r = requests.post(POSTGREST_BASE_URL + SEARCH_URL, json=data)
    try:
        search_r.raise_for_status()
    except requests.exceptions.RequestException as e:
        print('[get_example_phrases] error code:', end="")
        print(search_r.status_code, ', reason:', search_r.reason)
        return ErrorResponse(0, search_r.reason), search_r.status_code

    print('example_search_func : ', search_r)

    search_result = json.loads(search_r.text)

    print('[get_example_phrases] end')

    return SearchSuccessResponse(result_count, search_result), 200
def _check_columns(data_frame):
    # columns = '用語名 代表語 代表語のURI 上位語 同義語候補 上位語候補 品詞 x座標値 y座標値 色1 色2'
    # ins_f = lambda x:columns not in x
    for index, item in data_frame.iterrows():
        # if any(map(ins_f, item)):
        if ('用語名' not in item or '代表語' not in item or '代表語のURI' not in item
                or '上位語' not in item or '同義語候補' not in item
                or '上位語候補' not in item or '品詞' not in item
                or 'x座標値' not in item or 'y座標値' not in item or '色1' not in item
                or '色2' not in item):
            return ErrorResponse(0, 'Data Format Error.'), 400
    return SuccessResponse('request is success.'), 200
예제 #16
0
def user_user_id_proof_state_get(userId):  # noqa: E501
    """User get his authState.

     # noqa: E501

    :param userId: 
    :type userId: str

    :rtype: ProveState
    """
    info = user_manager.get_user_info(user_id=userId)
    if info is not None:
        return ProveState(prove_state=info.isprove)
    else:
        return ErrorResponse(message="error"), 400
예제 #17
0
def task_task_id_accepter_post(taskId, userId):  # noqa: E501
    """User accept the task.

    This operation shows how to override the global security defined above, as we want to open it up for all users. # noqa: E501

    :param taskId: 
    :type taskId: str
    :param userId: the userId of user ready to accept
    :type userId: str

    :rtype: None
    """
    result = task_manager.accept_task(user_id=userId, task_id=taskId)
    if "error" in result:
        return ErrorResponse(result[1]), 400
    else:
        return "success", 200
예제 #18
0
def user_proof_post(body):  # noqa: E501
    """User provide his prove identity.

     # noqa: E501

    :param body: 
    :type body: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = IdenInfo.from_dict(connexion.request.get_json())  # noqa: E501
    result = user_manager.prove(body)
    if 'error' in result:
        return ErrorResponse(result[1]), 400
    else:
        return "成功", 200
예제 #19
0
def task_task_id_info_delete(taskId, userId):  # noqa: E501
    """Publisher abort the task.

    This operation shows how to override the global security defined above, as we want to open it up for all users. # noqa: E501

    :param taskId: 
    :type taskId: str
    :param userId: 
    :type userId: str

    :rtype: None
    """
    result = task_manager.abort_task(task_id=taskId, user_id=userId)
    if 'error' in result:
        return ErrorResponse(result[1]), 400
    else:
        return 'success', 200
예제 #20
0
def task_user_id_post(body):  # noqa: E501
    """User publish the task.

     # noqa: E501

    :param body:
    :type body: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = TaskDetail.from_dict(connexion.request.get_json())  # noqa: E501
    result = task_manager.commit_task(body)
    if 'error' in result:
        return ErrorResponse(result[1]), 400
    else:
        return "success", 200
예제 #21
0
def task_task_id_accepter_delete(taskId, userId):  # noqa: E501
    """Accepter abandon the task.

    This operation shows how to override the global security defined above, as we want to open it up for all users. # noqa: E501

    :param taskId: 
    :type taskId: str
    :param userId: the userId of accepter
    :type userId: str

    :rtype: None
    """
    result = task_manager.abondon_task(user_id=userId, task_id=taskId)
    if 'error' in result:
        return ErrorResponse(result[1]), 400
    else:
        return result[1], 200
예제 #22
0
def task_task_id_info_get(taskId):  # noqa: E501
    """Returns one task&#39;s detail

    Returns one task&#39;s detail # noqa: E501

    :param taskId: The task&#39;s id in database.
    :type taskId: str

    :rtype: TaskDetailWithPublisher
    """
    task_with_publisher = task_manager.get_task_detail(task_id=taskId)
    if "error" in task_with_publisher:
        return ErrorResponse(task_with_publisher[1]), 400
    else:
        # ?需要做处理
        if ("publisher" in task_with_publisher
                and task_with_publisher["publisher"] is not None):
            user = UserInfoWithTel(
                user_id=task_with_publisher["publisher"]["user_id"],
                nick_name=task_with_publisher["publisher"]["nickname"],
                avatar_url=task_with_publisher["publisher"]["photo"],
                tel=task_with_publisher["publisher"]["phone_number"],
            )
        else:
            user = None
        if "task" in task_with_publisher and task_with_publisher[
                "task"] is not None:
            content = TaskDetail(
                type=task_with_publisher["task"]["type"],
                wjx_id=task_with_publisher["task"]["wjx_id"],
                title=task_with_publisher["task"]["title"],
                time=task_with_publisher["task"]["sign_end_time"],
                max_num=task_with_publisher["task"]["max_num"],
                money=task_with_publisher["task"]["money"],
                part_num=task_with_publisher["task"]["participants_num"],
                desc=task_with_publisher["task"]["task_intro"],
                condition=None,
            )
        else:
            content = None
        return TaskDetailWithPublisher(
            user=user,
            content=content,
            has_received=task_with_publisher.get("task_job_state"),
        )
예제 #23
0
def task_task_id_job_get(taskId):  # noqa: E501
    """User get all the Job.

     # noqa: E501

    :param taskId: 
    :type taskId: str
    :rtype: List[Cert]
    """
    result = task_manager.get_task_jobs(task_id=taskId)
    if len(result) > 0 and "error" is result[0]:
        return ErrorResponse(result[1]), 400
    else:
        return [
            Cert(user_id=item["user_id"],
                 files=item["files"],
                 remarks=item["remarks"]) for item in result
        ]
예제 #24
0
def task_task_id_info_put(taskId, body):  # noqa: E501
    """Publisher add the task info.

     # noqa: E501

    :param taskId: 
    :type taskId: str
    :param body: 
    :type body: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = ExtraTaskInfo.from_dict(
            connexion.request.get_json())  # noqa: E501
    result = task_manager.add_info(task_id=taskId, content=body.content)
    if result is None or 'error' in result:
        return ErrorResponse('add fail'), 400
    else:
        return 'success', 200
예제 #25
0
def task_task_id_job_put(taskId, userId, state):  # noqa: E501
    """Publisher agree the job of the user.

    This operation shows how to override the global security defined above, as we want to open it up for all users. # noqa: E501

    :param taskId: 
    :type taskId: str
    :param userId: 
    :type userId: str
    :param state: agree, reject
    :type state: str

    :rtype: None
    """
    result = task_manager.agree_job(task_id=taskId,
                                    user_id=userId,
                                    state=state)
    if 'error' in result:
        return ErrorResponse(result[1]), 400
    else:
        return 'success', 200
예제 #26
0
def task_task_id_job_post(taskId, body):  # noqa: E501
    """User commit the job.

     # noqa: E501

    :param taskId: 
    :type taskId: str
    :param body: 
    :type body: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = Cert.from_dict(connexion.request.get_json())  # noqa: E501

    result = task_manager.commit_job(user_id=body.user_id,
                                     task_id=taskId,
                                     job=body)
    if result is None or 'error' in result:
        return ErrorResponse('post fail'), 400
    else:
        return 'success', 200
예제 #27
0
def tasks_get(pageId):  # noqa: E501
    """Returns all related tasks according to the pageId.

    Returns the published tasks, the max number is 10. If the page is the last page, the return all left. # noqa: E501

    :param pageId: Page number
    :type pageId: int
    :rtype: List[Task]
    """
    tasks = task_manager.get_task_list(page_id=pageId)
    if tasks is None:
        return ErrorResponse("error"), 400
    else:
        return [
            Task(
                id=item["task_id"],
                money=item["money"],
                icon=item["icon"],
                title=item["title"],
                max_num=item["max_num"],
                desc=item["task_intro"],
                part_num=item["participants_num"],
            ) for item in tasks
        ]
예제 #28
0
from swagger_server.models.balance import Balance  # noqa: E501
from swagger_server.models.error_response import ErrorResponse  # noqa: E501
from swagger_server.models.iden_info import IdenInfo  # noqa: E501
from swagger_server.models.iden_info_with_credit import IdenInfoWithCredit  # noqa: E501
from swagger_server.models.login_code import LoginCode  # noqa: E501
from swagger_server.models.prove_state import ProveState  # noqa: E501
from swagger_server.models.user_info import UserInfo  # noqa: E501
from swagger_server.models.user_info_without_id import UserInfoWithoutId  # noqa: E501
from swagger_server import util
from swagger_server.modules.userManagementSystem import ManagementSystem
from swagger_server.modules.accessControlSystem import AccessControlSystem as accessControlSystem

user_manager = ManagementSystem()
access_control = accessControlSystem()

login_response = (ErrorResponse(message="login"), 400)

@access_control.login_required(login_response)
def user_info_put(body):  # noqa: E501
    """User modify his basic info.

     # noqa: E501

    :param body: 
    :type body: dict | bytes

    :rtype: UserInfo
    """
    if connexion.request.is_json:
        body = UserInfoWithoutId.from_dict(connexion.request.get_json())  # noqa: E501
    
def upload_file(editing_vocabulary=None,
                reference_vocabulary1=None,
                reference_vocabulary2=None,
                reference_vocabulary3=None,
                example_phrases=None):  # noqa: E501
    """Upload the file to the server

    Uploads the file selected by the client to the server.     When &#x27;editing_vocabulary&#x27; uploaded, its check integrity.    # noqa: E501

    :param editing_vocabulary:
    :type editing_vocabulary: strstr
    :param reference_vocabulary1:
    :type reference_vocabulary1: strstr
    :param reference_vocabulary2:
    :type reference_vocabulary2: strstr
    :param reference_vocabulary3:
    :type reference_vocabulary3: strstr
    :param example_phrases:
    :type example_phrases: strstr

    :rtype: SuccessResponse
    """

    if editing_vocabulary is not None:
        allow_extension, r_ext =\
            _check_extensions(editing_vocabulary,
                              VOCABULARY_ALLOWED_EXTENSIONS)
        if not allow_extension:
            print(datetime.datetime.now(), '[Error] failed _check_extensions',
                  location())
            return ErrorResponse(0, 'Data Format Error.'), 400

        # Check Synonymous Relationship
        df = _read_file_strage(editing_vocabulary, r_ext)

        # Check columns
        exec_res, status_code = _check_columns(df)
        if not status_code == 200:
            print(datetime.datetime.now(), '[Error] failed _check_columns',
                  location())
            return exec_res, status_code

        _repair_broader_term(df)

        exec_res, status_code = _check_synonymous_relationship(df)
        if not status_code == 200:
            print(datetime.datetime.now(),
                  '[Error] failed _check_synonymous_relationship', location())
            return exec_res, status_code

        payload = _make_bulk_data_editing_vocabulary(df)

        exec_res, status_code =\
            _exec_insert_postgrest(payload, 'editing_vocabulary')
        if not status_code == 200:
            print(datetime.datetime.now(),
                  '[Error] failed _exec_insert_postgrest', location())
            return exec_res, status_code

    if reference_vocabulary1 is not None:
        allow_extension, r_ext =\
            _check_extensions(reference_vocabulary1,
                              VOCABULARY_ALLOWED_EXTENSIONS)
        if not allow_extension:
            print(datetime.datetime.now(), '[Error] failed _check_extensions',
                  location())
            return ErrorResponse(0, 'Data Format Error.'), 400

        payload =\
            _make_bulk_data_reference_vocabulary(reference_vocabulary1, r_ext)
        # format check
        exec_res, status_code =\
            _check_trem_format_reference_vocabulary(payload)
        if not status_code == 200:
            print(datetime.datetime.now(),
                  '[Error] failed _check_trem_format_reference_vocabulary',
                  location())
            return ErrorResponse(0, 'Data Format Error.'), 400
        exec_res, status_code =\
            _exec_insert_postgrest(payload, 'reference_vocabulary_1')
        if not status_code == 200:
            print(datetime.datetime.now(),
                  '[Error] failed _exec_insert_postgrest', location())
            return exec_res, status_code

    if reference_vocabulary2 is not None:
        allow_extension, r_ext =\
            _check_extensions(reference_vocabulary2,
                              VOCABULARY_ALLOWED_EXTENSIONS)
        if not allow_extension:
            print(datetime.datetime.now(), '[Error] failed _check_extensions',
                  location())
            return ErrorResponse(0, 'Data Format Error.'), 400

        payload =\
            _make_bulk_data_reference_vocabulary(reference_vocabulary2, r_ext)
        # format check
        exec_res, status_code =\
            _check_trem_format_reference_vocabulary(payload)
        if not status_code == 200:
            print(datetime.datetime.now(),
                  '[Error] failed _check_trem_format_reference_vocabulary',
                  location())
            return ErrorResponse(0, 'Data Format Error.'), 400
        exec_res, status_code =\
            _exec_insert_postgrest(payload, 'reference_vocabulary_2')
        if not status_code == 200:
            print(datetime.datetime.now(),
                  '[Error] failed _exec_insert_postgrest', location())
            return exec_res, status_code

    if reference_vocabulary3 is not None:
        allow_extension, r_ext =\
            _check_extensions(reference_vocabulary3,
                              VOCABULARY_ALLOWED_EXTENSIONS)
        if not allow_extension:
            print(datetime.datetime.now(), '[Error] failed _check_extensions',
                  location())
            return ErrorResponse(0, 'Data Format Error.'), 400

        payload =\
            _make_bulk_data_reference_vocabulary(reference_vocabulary3, r_ext)
        # format check
        exec_res, status_code =\
            _check_trem_format_reference_vocabulary(payload)
        if not status_code == 200:
            print(datetime.datetime.now(),
                  '[Error] failed _check_trem_format_reference_vocabulary',
                  location())
            return ErrorResponse(0, 'Data Format Error.'), 400
        exec_res, status_code =\
            _exec_insert_postgrest(payload, 'reference_vocabulary_3')
        if not status_code == 200:
            print(datetime.datetime.now(),
                  '[Error] failed _exec_insert_postgrest', location())
            return exec_res, status_code

    if example_phrases is not None:
        allow_extension, r_ext =\
            _check_extensions(example_phrases,
                              PHRASES_ALLOWED_EXTENSIONS)
        if not allow_extension:
            print(datetime.datetime.now(), '[Error] failed _check_extensions',
                  location())
            return ErrorResponse(0, 'Data Format Error.'), 400

        # exec_res, status_code = _copy_file_example_phrases(example_phrases)
        # if not status_code == 200:
        #    _file_delete(example_phrases)
        #    return exec_res, status_code

        exec_res, status_code = _insert_example_phrases(example_phrases)
        if not status_code == 200:
            print(datetime.datetime.now(),
                  '[Error] failed _insert_example_phrases', location())
            _file_delete(example_phrases)
            return exec_res, status_code

    return SuccessResponse('request is success.')
예제 #30
0
from swagger_server.models.cert import Cert  # noqa: E501
from swagger_server.models.error_response import ErrorResponse  # noqa: E501
from swagger_server.models.extra_task_info import ExtraTaskInfo  # noqa: E501
from swagger_server.models.task import Task  # noqa: E501
from swagger_server.models.task_detail import TaskDetail  # noqa: E501
from swagger_server.models.task_detail_with_publisher import TaskDetailWithPublisher  # noqa: E501
from swagger_server.models.user_info_with_tel import UserInfoWithTel  # noqa: E501
from swagger_server import util
from swagger_server.modules.taskManagementSystem import taskManagementSystem
from swagger_server.modules.accessControlSystem import AccessControlSystem as accessControlSystem

task_manager = taskManagementSystem()
access_control = accessControlSystem()

login_response = (ErrorResponse('login'), 400)
error_response = (ErrorResponse('error'), 400)


@access_control.login_required(login_response)
def task_task_id_accepter_delete(taskId, userId):  # noqa: E501
    """Accepter abandon the task.

    This operation shows how to override the global security defined above, as we want to open it up for all users. # noqa: E501

    :param taskId: 
    :type taskId: str
    :param userId: the userId of accepter
    :type userId: str

    :rtype: None