Пример #1
0
def document_root():

    project_id = request.args.get('projectId')
    document_package_id = request.args.get('documentPackageId')
    status = request.args.get('status')
    skip = request.args.get('skip')
    limit = request.args.get('limit')
    append_document_package_detail = RouteUtil.value_to_boolean(
        request.args.get('appendDocumentPackageDetail'))
    append_collaborator_detail = RouteUtil.value_to_boolean(
        request.args.get('appendCollaboratorDetail'))

    if request.method == 'GET':

        return RouteUtil.data_to_json_response(
            DocumentService.get_documents(project_id, document_package_id,
                                          status, skip, limit,
                                          append_document_package_detail,
                                          append_collaborator_detail))

    elif request.method == 'POST':

        return DocumentService.insert_document(
            document_package_id, RouteUtil.safe_json_get('text'),
            RouteUtil.safe_json_get('name'),
            RouteUtil.safe_json_get('isPlainText'))
Пример #2
0
def document_package_collaborator(document_package_id):

    email = request.args.get('email')

    if request.method == 'GET':

        if email:
            return RouteUtil.data_to_json_response(
                DocumentPackageService.get_document_packages_by_collaborator(
                    document_package_id, email))
        else:
            return RouteUtil.data_to_json_response(
                DocumentPackageService.get_document_package_collaborators(
                    document_package_id))

    elif request.method == 'POST':

        if email:  # update
            DocumentPackageService.update_document_package_collaborator(
                document_package_id, RouteUtil.safe_json_get('groupId'), email)
        else:
            DocumentPackageService.insert_document_package_collaborator(
                document_package_id, RouteUtil.safe_json_get('groupId'),
                RouteUtil.safe_json_get('email'))

        return 'OK', 200

    elif request.method == 'DELETE':
        DocumentPackageService.remove_document_package_collaborator(
            document_package_id, email)
        return 'OK', 200
Пример #3
0
def document_package_change_collaborations_status(document_package_id):

    DocumentPackageService.update_collaborations_status(
        document_package_id, g.user['email'],
        RouteUtil.safe_json_get('collaboratorEmail'),
        RouteUtil.safe_json_get('newStatus'))
    return 'OK', 200
Пример #4
0
def document_collaboration_status(document_id):

    DocumentService.update_collaboration_status(
        document_id, g.user['email'],
        RouteUtil.safe_json_get('collaboratorEmail'),
        RouteUtil.safe_json_get('status'))
    return 'OK', 201
Пример #5
0
def authenticate():
    try:
        return RouteUtil.data_to_json_response(
            AuthenticationService.authenticate(
                RouteUtil.safe_json_get('email'),
                RouteUtil.safe_json_get('password')))
    except ServiceException:
        return 'INVALID USER/PASSWORD', 401
def tokenizer_postagger():

    return RouteUtil.data_to_json_response(
        NlpService.tokenizer_postagger(
            RouteUtil.safe_json_get('text'), RouteUtil.safe_json_get('lang'),
            RouteUtil.safe_json_get('filter'),
            RouteUtil.safe_json_get('smartSentenceSegmentation'),
            RouteUtil.safe_json_get('smartWordSegmentation')))
Пример #7
0
def reset_password():
    try:
        AuthenticationService.update_user_password(
            RouteUtil.safe_json_get('email'), RouteUtil.safe_json_get('token'),
            RouteUtil.safe_json_get('newPassword'), True)
        return 'PASSWORD CHANGED', 200
    except ServiceException:
        return 'INVALID TOKEN', 401
Пример #8
0
def change_password():
    try:
        AuthenticationService.update_user_password(
            g.user['email'], RouteUtil.safe_json_get('currentPassword'),
            RouteUtil.safe_json_get('newPassword'))
        return 'PASSWORD CHANGED', 200
    except ServiceException:
        return 'WRONG PASSWORD', 401
Пример #9
0
def document_package(document_package_id):

    append_statistics = request.args.get('appendStatistics')

    if request.method == 'GET':
        return RouteUtil.data_to_json_response(
            DocumentPackageService.get_document_package(
                document_package_id, append_statistics=append_statistics),
            True)

    elif request.method == 'POST':
        DocumentPackageService.update_document_package(
            document_package_id, RouteUtil.safe_json_get('name'),
            RouteUtil.safe_json_get('randomAnnotation'),
            RouteUtil.safe_json_get('showSelfAgreementFeedback'),
            RouteUtil.safe_json_get('selfAgreementFeedbackGoal'),
            RouteUtil.safe_json_get('usePrecheckAgreementThreshold'),
            RouteUtil.safe_json_get('precheckAgreementThreshold'),
            RouteUtil.safe_json_get('useTagAgreement'),
            RouteUtil.safe_json_get('useRelationAgreement'),
            RouteUtil.safe_json_get('useConnectorAgreement'))
        return 'OK', 200

    elif request.method == 'DELETE':
        DocumentPackageService.remove_document_package(document_package_id)
        return 'OK', 200
Пример #10
0
def document_package_root():

    ids = request.args.get('ids')
    project_id = request.args.get('projectId')
    collaborator_email = request.args.get('collaboratorEmail')
    append_statistics = request.args.get('appendStatistics')
    skip = request.args.get('skip')
    limit = request.args.get('limit')

    if request.method == 'GET':

        if ids:
            return RouteUtil.data_to_json_response(
                DocumentPackageService.get_document_packages(
                    ids.split(","), append_statistics=append_statistics))

        elif project_id:
            return RouteUtil.data_to_json_response(
                DocumentPackageService.get_document_packages_by_project(
                    project_id, append_statistics=append_statistics))

        elif collaborator_email:
            return RouteUtil.data_to_json_response(
                DocumentPackageService.get_document_packages_by_collaborator(
                    collaborator_email, append_statistics=append_statistics))

        else:
            return RouteUtil.data_to_json_response(
                DocumentPackageService.get_document_packages(
                    skip=skip,
                    limit=limit,
                    append_statistics=append_statistics))

    elif request.method == 'POST':

        return DocumentPackageService.create_document_package(
            RouteUtil.safe_json_get('projectId'),
            RouteUtil.safe_json_get('name'),
            RouteUtil.safe_json_get('randomAnnotation'),
            RouteUtil.safe_json_get('showSelfAgreementFeedback'),
            RouteUtil.safe_json_get('selfAgreementFeedbackGoal'),
            RouteUtil.safe_json_get('usePrecheckAgreementThreshold'),
            RouteUtil.safe_json_get('precheckAgreementThreshold'),
            RouteUtil.safe_json_get('useTagAgreement'),
            RouteUtil.safe_json_get('useRelationAgreement'),
            RouteUtil.safe_json_get('useConnectorAgreement'))
Пример #11
0
def project(project_id):

    append_statistics = RouteUtil.value_to_boolean(
        request.args.get('appendStatistics'))

    if request.method == 'GET':
        return RouteUtil.data_to_json_response(
            ProjectService.get_project(project_id, True, append_statistics),
            True)

    elif request.method == 'POST':
        ProjectService.update_project(
            project_id, RouteUtil.safe_json_get('name'),
            RouteUtil.safe_json_get('smartSentenceSegmentation'),
            RouteUtil.safe_json_get('smartWordSegmentation'),
            RouteUtil.safe_json_get('textReplacements'))
        return 'OK', 200

    elif request.method == 'DELETE':
        ProjectService.remove_project(project_id)
        return 'OK', 200
Пример #12
0
def document_package_group(document_package_id):

    group_id = request.args.get('groupId')
    collaborator_email = request.args.get('collaboratorEmail')

    if request.method == 'GET':

        if group_id or collaborator_email:
            if group_id:
                return RouteUtil.data_to_json_response(
                    DocumentPackageService.get_document_package_group(
                        document_package_id, int(group_id)))
            else:
                return RouteUtil.data_to_json_response(
                    DocumentPackageService.
                    get_document_package_group_by_collaborator_email(
                        document_package_id, collaborator_email))
        else:
            return RouteUtil.data_to_json_response(
                DocumentPackageService.get_document_package_groups(
                    document_package_id))

    elif request.method == 'POST':

        if group_id:  # update
            DocumentPackageService.update_document_package_group(
                document_package_id, int(group_id),
                RouteUtil.safe_json_get('name'),
                RouteUtil.safe_json_get('warmUpSize'),
                RouteUtil.safe_json_get('reannotationStep'))
        else:
            return str(
                DocumentPackageService.insert_document_package_group(
                    document_package_id, RouteUtil.safe_json_get('name'),
                    RouteUtil.safe_json_get('warmUpSize'),
                    RouteUtil.safe_json_get('reannotationStep')))

        return 'OK', 200

    elif request.method == 'DELETE':
        DocumentPackageService.remove_document_package_group(
            document_package_id, int(group_id))
        return 'OK', 200
Пример #13
0
def project_root():

    skip = request.args.get('skip')
    limit = request.args.get('limit')
    append_statistics = RouteUtil.value_to_boolean(
        request.args.get('appendStatistics'))

    if request.method == 'GET':
        return RouteUtil.data_to_json_response(
            ProjectService.get_projects(
                g.user['email'],
                skip=skip,
                limit=limit,
                append_documents_package_statistics=append_statistics))

    elif request.method == 'POST':

        if 'ontology' not in request.json:
            return 'ONTOLOGY IS REQUIRED', 400

        _, b64data = request.json['ontology']['data'].split(',')
        request.json['ontology']['bytes'] = base64.b64decode(b64data)

        if 'annotationGuidelines' in request.json:
            _, b64data = request.json['annotationGuidelines']['data'].split(
                ',')
            request.json['annotationGuidelines']['bytes'] = base64.b64decode(
                b64data)

        return ProjectService.create_project(
            g.user['email'], RouteUtil.safe_json_get('name'),
            RouteUtil.safe_json_get('language'),
            RouteUtil.safe_json_get('smartSentenceSegmentation'),
            RouteUtil.safe_json_get('smartWordSegmentation'),
            RouteUtil.safe_json_get('textReplacements'),
            RouteUtil.safe_json_get('ontology'),
            RouteUtil.safe_json_get('annotationGuidelines'))
Пример #14
0
def document_package_change_documents_status(document_package_id):

    DocumentPackageService.change_documents_status(
        document_package_id, RouteUtil.safe_json_get('newStatus'))
    return 'OK', 200
Пример #15
0
def user():
    user_email = request.args.get('email')

    if request.method == 'GET':

        # common user only can see your own details
        if g.user['role'] == 'USER':
            return RouteUtil.data_to_json_response(
                AuthenticationService.get_user(g.user['email']))

        if user_email:
            return RouteUtil.data_to_json_response(
                AuthenticationService.get_user(user_email))
        else:
            return RouteUtil.data_to_json_response(
                AuthenticationService.get_users())

    elif request.method == 'POST':

        if user_email:  # update

            # common user only can update your own details and cannot change your role
            if g.user['role'] == 'USER':
                AuthenticationService.update_user(
                    g.user['email'], RouteUtil.safe_json_get('firstName'),
                    RouteUtil.safe_json_get('lastName'), g.user['role'])
            else:
                AuthenticationService.update_user(
                    RouteUtil.safe_json_get('email'),
                    RouteUtil.safe_json_get('firstName'),
                    RouteUtil.safe_json_get('lastName'),
                    RouteUtil.safe_json_get('role'))

            return 'USER UPDATED', 200

        else:  # insert

            if g.user['role'] == 'USER':
                return 'INVALID ROLE', 403

            temporary_token = AuthenticationService.insert_user(
                RouteUtil.safe_json_get('email'),
                RouteUtil.safe_json_get('firstName'),
                RouteUtil.safe_json_get('lastName'),
                RouteUtil.safe_json_get('role'))

            recovery_url = config['RECOVERY_PASSWORD_PAGE_URL'] + '?token=' + temporary_token + \
                           '&email=' + RouteUtil.safe_json_get('email')

            message = config['EMAIL_HEADER']
            message += '<div style="height:200px; padding:50px;">'
            message += '<p>Hi ' + RouteUtil.safe_json_get(
                'firstName') + ',</p>'
            message += config['WELCOME_EMAIL_MESSAGE']
            message += '<p><a href="' + recovery_url + '">' + recovery_url + '</a></p>'
            message += '</div>'
            message += config['EMAIL_FOOTER']

            EmailService.send(config['WELCOME_EMAIL_SUBJECT'],
                              [RouteUtil.safe_json_get('email')], message)

            return 'USER INSERTED', 200

    elif request.method == 'DELETE':

        if g.user['role'] == 'USER':
            return 'INVALID ROLE', 403

        AuthenticationService.remove_user(user_email)
        return 'USER REMOVED', 200