Example #1
0
def document_package_download(document_package_id):

    document_package_found = DocumentPackageService.get_document_package(
        document_package_id)

    if not document_package_found:
        return 'NOT FOUND', 404

    wanted_status = []

    if RouteUtil.value_to_boolean(request.args.get('includeUnchecked')):
        wanted_status.append('UNCHECKED')
    if RouteUtil.value_to_boolean(request.args.get('includePrechecked')):
        wanted_status.append('PRECHECKED')
    if RouteUtil.value_to_boolean(request.args.get('includeChecked')):
        wanted_status.append('CHECKED')

    documents_zip = DocumentService.get_documents_zip(
        document_package_id,
        RouteUtil.value_to_boolean(request.args.get('includeMetadata')),
        RouteUtil.value_to_boolean(request.args.get('includeText')),
        RouteUtil.value_to_boolean(request.args.get('includeCollaboration')),
        RouteUtil.value_to_boolean(request.args.get('includeStatus')),
        RouteUtil.value_to_boolean(request.args.get('includeDescription')),
        RouteUtil.value_to_boolean(request.args.get('includeLog')),
        RouteUtil.value_to_boolean(request.args.get('includeComments')),
        wanted_status)

    return make_response(
        send_file(documents_zip.filename,
                  as_attachment=True,
                  add_etags=False,
                  attachment_filename=document_package_found['name'] + '.zip',
                  mimetype='application/zip, application/octet-stream'))
Example #2
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'))
Example #3
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
Example #4
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'))
Example #5
0
def document_package_statistics(document_package_id):

    collaborator_email = request.args.get('collaboratorEmail')
    append_agreement = RouteUtil.value_to_boolean(
        request.args.get('appendAgreement'))

    if collaborator_email:
        return RouteUtil.data_to_json_response(
            DocumentPackageService.
            get_document_package_collaborator_statistics(
                document_package_id, collaborator_email, append_agreement))
    else:

        statistics_type = request.args.get('type')
        statistics_filter = request.args.get('filter')
        append_collaborations = request.args.get('appendCollaborations')
        collaborators_to_filter = request.args.get('collaboratorsToFilter')
        if collaborators_to_filter:
            collaborators_to_filter = collaborators_to_filter.split(',')

        if statistics_type == 'token':
            return RouteUtil.data_to_json_response(
                DocumentPackageService.get_document_package_token_statistics(
                    document_package_id=document_package_id,
                    include_collaborations=append_collaborations,
                    collaborators_to_filter=collaborators_to_filter))

        elif statistics_type == 'tag':
            return RouteUtil.data_to_json_response(
                DocumentPackageService.get_document_package_tag_statistics(
                    document_package_id=document_package_id,
                    include_collaborations=append_collaborations,
                    collaborators_to_filter=collaborators_to_filter))
        elif statistics_type == 'relation':
            return RouteUtil.data_to_json_response(
                DocumentPackageService.
                get_document_package_relation_statistics(
                    document_package_id=document_package_id,
                    include_collaborations=append_collaborations,
                    collaborators_to_filter=collaborators_to_filter))
        elif statistics_type == 'connector':
            return RouteUtil.data_to_json_response(
                DocumentPackageService.
                get_document_package_connector_statistics(
                    document_package_id=document_package_id,
                    include_collaborations=append_collaborations,
                    collaborators_to_filter=collaborators_to_filter))
        elif statistics_type == 'summary':
            return RouteUtil.data_to_json_response(
                DocumentPackageService.get_document_package_summary_statistics(
                    document_package_id=document_package_id,
                    include_collaborations=append_collaborations,
                    collaborators_to_filter=collaborators_to_filter))
        elif statistics_type == 'agreement':

            if statistics_filter == 'all':
                agreement_types = ['tag', 'relation', 'connector']
            else:
                agreement_types = [statistics_filter]

            return RouteUtil.data_to_json_response(
                DocumentPackageService.
                get_document_package_agreement_statistics(
                    document_package_id=document_package_id,
                    collaborators_to_filter=collaborators_to_filter,
                    agreement_types=agreement_types))
        elif statistics_type == 'words':

            return RouteUtil.data_to_json_response(
                DocumentPackageService.get_document_package_words_statistics(
                    document_package_id=document_package_id,
                    include_collaborations=append_collaborations,
                    collaborators_to_filter=collaborators_to_filter))
        else:
            return RouteUtil.data_to_json_response(
                DocumentPackageService.get_document_package_status_statistics(
                    document_package_id=document_package_id,
                    include_collaborations=append_collaborations,
                    collaborators_to_filter=collaborators_to_filter))
Example #6
0
def document(document_id):

    as_file = RouteUtil.value_to_boolean(request.args.get('asFile'))

    if request.method == 'GET':

        if as_file:

            found_document = DocumentService.get_document(
                document_id,
                append_document_package_detail=False,
                append_collaborator_detail=False,
                log_document_open=False)

            if not found_document:
                return 'NOT FOUND', 404
            '''
            document_text = DocumentService.get_document_as_text(found_document)

            temp_file = tempfile.NamedTemporaryFile(delete=False)
            temp_file.write(document_text.encode('utf-8'))
            temp_file.flush()
            temp_file.seek(0)
            '''

            document_file = DocumentService.get_document_as_file(
                found_document, None,
                RouteUtil.value_to_boolean(
                    request.args.get('includeMetadata')),
                RouteUtil.value_to_boolean(request.args.get('includeText')),
                RouteUtil.value_to_boolean(
                    request.args.get('includeCollaboration')),
                RouteUtil.value_to_boolean(request.args.get('includeStatus')),
                RouteUtil.value_to_boolean(
                    request.args.get('includeDescription')),
                RouteUtil.value_to_boolean(request.args.get('includeLog')),
                RouteUtil.value_to_boolean(
                    request.args.get('includeComments')))

            return make_response(
                send_file(document_file.name,
                          as_attachment=True,
                          add_etags=False,
                          attachment_filename=found_document['name'],
                          mimetype='text/plain',
                          cache_timeout=10))
        else:
            return RouteUtil.data_to_json_response(
                DocumentService.get_document(document_id), True)

    elif request.method == 'POST':

        using_change_log = RouteUtil.value_to_boolean(
            request.args.get('usingChangeLog'))
        state_key = request.args.get('stateKey')

        if using_change_log:
            lock_token = DocumentService.get_document_lock(document_id)
            state_key = DocumentService.update_document_by_log(
                document_id, request.json, lock_token, state_key)
            DocumentService.release_document_lock(lock_token, document_id)
            return state_key, 201
        else:
            DocumentService.update_document(document_id, request.json['name'],
                                            request.json['metadata'])
            return 'OK', 201

    elif request.method == 'DELETE':
        DocumentService.remove_document(document_id)
        return 'OK', 201