Exemplo n.º 1
0
    def put(self):
        """Handle callback for merge conflicts."""
        workflow_data = workflow_loader()
        workflow_id = workflow_data['id']

        try:
            workflow = workflow_object_class.get(workflow_id)
        except WorkflowsMissingObject:
            raise CallbackWorkflowNotFoundError(workflow_id)

        if workflow.status != ObjectStatus.HALTED or \
           'callback_url' not in workflow.extra_data:
            raise CallbackWorkflowNotInMergeState(workflow.id)

        conflicts = get_value(workflow_data['_extra_data'],
                              'conflicts',
                              default=[])

        workflow.data = workflow_data['metadata']
        workflow.extra_data['conflicts'] = conflicts

        if not conflicts:
            workflow.status = ObjectStatus.RUNNING

            workflow.extra_data.pop('callback_url', None)
            workflow.extra_data.pop('conflicts', None)

            workflow.save()
            db.session.commit()
            workflow.continue_workflow(delayed=True)

            data = {
                'message': 'Workflow {} is continuing.'.format(workflow.id),
            }
            return jsonify(data), 200

        # just save
        data = {
            'message':
            'Workflow {} has been saved with conflicts.'.format(workflow.id),
        }
        workflow.save()
        db.session.commit()

        return jsonify(data), 200
Exemplo n.º 2
0
    def put(self):
        """Handle callback for merge conflicts."""
        workflow_data = workflow_loader()
        workflow_id = workflow_data['id']

        try:
            workflow = workflow_object_class.get(workflow_id)
        except WorkflowsMissingObject:
            raise CallbackWorkflowNotFoundError(workflow_id)

        if workflow.status != ObjectStatus.WAITING or \
           'callback_url' not in workflow.extra_data:
            raise CallbackWorkflowNotInWaitingEditState(workflow.id)

        recid = workflow_data['metadata'].get('control_number')
        try:
            record = get_db_record('lit', recid)
        except RecordGetterError:
            raise CallbackRecordNotFoundError(recid)

        record_permission = RecordPermission.create(action='update',
                                                    record=record)
        if not record_permission.can():
            abort(403, record_permission)

        workflow_id = workflow.id
        workflow.data = workflow_data['metadata']
        workflow.status = ObjectStatus.RUNNING
        workflow.extra_data.pop('callback_url', None)
        workflow.save()
        db.session.commit()
        workflow.continue_workflow(delayed=True)

        ticket_id = workflow_data['_extra_data'].get('curation_ticket_id')
        if ticket_id:
            redirect_url = get_rt_link_for_ticket(ticket_id)
        else:
            redirect_url = '%s://%s/' % (request.scheme, request.host)

        data = {
            'message': 'Workflow {} is continuing.'.format(workflow_id),
            'redirect_url': redirect_url,
        }
        return jsonify(data), 200
Exemplo n.º 3
0
    def put(self):
        """Handle callback from validation errors.

        When validation errors occur, the workflow stops in ``ERROR`` state, to
        continue this endpoint is called.

        Args:
            workflow_data (dict): the workflow object send in the
                request's payload.

        Examples:
            An example of successful call:

                $ curl \\
                    http://web:5000/callback/workflows/resolve_validation_errors \\
                    -H "Host: localhost:5000" \\
                    -H "Content-Type: application/json" \\
                    -d '{
                        "_extra_data": {
                            ... extra data content
                        },
                        "id": 910648,
                        "metadata": {
                            "$schema": "https://labs.inspirehep.net/schemas/records/hep.json",
                            ... record content
                        }
                    }'

            The response:

                HTTP 200 OK

                {"mesage": "Workflow 910648 validated, continuing it."}


            A failed example:

                $ curl \\
                    http://web:5000/callback/workflows/resolve_validation_errors \\
                    -H "Host: localhost:5000" \\
                    -H "Content-Type: application/json" \\
                    -d '{
                        "_extra_data": {
                            ... extra data content
                        },
                        "id": 910648,
                        "metadata": {
                            "$schema": "https://labs.inspirehep.net/schemas/records/hep.json",
                            ... record content
                        }
                    }'

            The error response will contain the workflow that was passed, with the
            new validation errors:

                HTTP 400 Bad request

                {
                    "_extra_data": {
                        "validatior_errors": [
                            {
                                "path": ["path", "to", "error"],
                                "message": "required: ['missing_key1', 'missing_key2']"
                            }
                        ],
                        ... rest of extra data content
                    },
                    "id": 910648,
                    "metadata": {
                        "$schema": "https://labs.inspirehep.net/schemas/records/hep.json",
                        ... record content
                    }
                }
        """
        workflow_data = workflow_loader()
        _validate_workflow_schema(workflow_data)

        workflow_id = workflow_data['id']
        try:
            workflow = workflow_object_class.get(workflow_id)
        except WorkflowsMissingObject:
            raise CallbackWorkflowNotFoundError(workflow_id)

        if workflow.status != ObjectStatus.ERROR or \
           'callback_url' not in workflow.extra_data:
            raise CallbackWorkflowNotInValidationError(workflow_id)

        workflow.data = workflow_data['metadata']
        workflow.status = ObjectStatus.RUNNING

        workflow.extra_data.pop('callback_url', None)
        workflow.extra_data.pop('validation_errors', None)

        workflow.save()
        db.session.commit()
        workflow.continue_workflow(delayed=True)

        data = {
            'message': 'Workflow {} is continuing.'.format(workflow.id),
        }
        return jsonify(data), 200