コード例 #1
0
def test_status_converter():
    """Test the ``status_converter`` function."""
    assert status_converter('COMPLETE') == ArchiveStatus.REGISTERED
    assert status_converter('PROCESSING') == ArchiveStatus.PROCESSING_TRANSFER
    assert status_converter('PROCESSING', True) == \
        ArchiveStatus.PROCESSING_AIP
    assert status_converter('USER_INPUT') == ArchiveStatus.FAILED
コード例 #2
0
def validate_status(status):
    """Accept only valid status."""
    try:
        status_converter(status)
    except Exception:
        return False
    return True
コード例 #3
0
    def get(self, archive, real_status=False):
        """Returns the status of the Archive object.

        :param bool real_status: If real_status is True, ask Archivematica to
            get the current status, as it may be delayed in Invenio servers.
            As we are requesting the Archivematica server, this adds an
            overload rarely welcomed... Thus, this parameter should be False
            most of the time.
        :return: a JSON object representing the archive.
        :rtype: str
        """
        if not real_status \
                or archive.status == ArchiveStatus.FAILED \
                or archive.status == ArchiveStatus.NEW \
                or not archive.archivematica_id:
            return self._to_json(archive)
        # we ask Archivematica
        # first we look at the status of the transfer
        if archive.status in (ArchiveStatus.WAITING,
                              ArchiveStatus.PROCESSING_TRANSFER):
            url = '{base}/api/transfer/status/{uuid}/'.format(
                base=current_app.config['ARCHIVEMATICA_DASHBOARD_URL'],
                uuid=archive.archivematica_id)
            params = {
                'username': current_app.config['ARCHIVEMATICA_DASHBOARD_USER'],
                'api_key':
                current_app.config['ARCHIVEMATICA_DASHBOARD_API_KEY']
            }
            response = requests.get(url, params=params)
            if not response.ok:  # a problem occured
                return jsonify({}), response.status_code
            status = status_converter(response.json()['status'])
            # if status is not complete, we stop here
            if status != ArchiveStatus.REGISTERED:
                if status != archive.status:
                    change_status_func[status](archive.sip,
                                               archive.accession_id,
                                               archive.archivematica_id)
                return self._to_json(archive)
            # transfer finished, we need to update the archive
            status = ArchiveStatus.PROCESSING_AIP
            archive.archivematica_id = response.json()['sip_uuid']
            change_status_func[status](archive.sip, archive.accession_id,
                                       archive.archivematica_id)
        # we try to get the status of the SIP
        url = '{base}/api/ingest/status/{uuid}/'.format(
            base=current_app.config['ARCHIVEMATICA_DASHBOARD_URL'],
            uuid=archive.archivematica_id)
        response = requests.get(url, params=params)
        if not response.ok:  # a problem occured
            return jsonify({}), response.status_code
        status = status_converter(response.json()['status'],
                                  aip_processing=True)
        if status != archive.status:
            change_status_func[status](archive.sip, archive.accession_id,
                                       archive.archivematica_id)
        return self._to_json(archive)
コード例 #4
0
    def patch(self, archive, status='', archivematica_id=''):
        """Change an Archive object.

        The accesion_id is used to change the object. You can only change
        the status or the archivematica_id.
        """
        if archivematica_id and archivematica_id != archive.archivematica_id:
            archive.archivematica_id = archivematica_id
        db.session.commit()
        ark_status = status_converter(status)
        if ark_status and ark_status != archive.status:
            change_status_func[ark_status](archive.sip, archive.accession_id,
                                           archive.archivematica_id)
        return self._to_json(archive)