Beispiel #1
0
def get_marcxml_of_revision(recid, revid):
    """Return MARCXML string of revision.
    Return empty string if revision does not exist. REVID should be a string.
    """
    res = ""
    tmp_res = get_marcxml_of_record_revision(recid, revid)
    if tmp_res:
        for row in tmp_res:
            res += zlib.decompress(row[0]) + "\n"
    return res
Beispiel #2
0
def get_marcxml_of_revision(recid, revid):
    """Return MARCXML string of revision.
    Return empty string if revision does not exist. REVID should be a string.
    """
    res = ''
    tmp_res = get_marcxml_of_record_revision(recid, revid)
    if tmp_res:
        for row in tmp_res:
            res += zlib.decompress(row[0]) + '\n'
    return res
def get_marcxml_of_revision_id(recid, revid):
    """
    Return MARCXML string with corresponding to revision REVID
    (=RECID.REVDATE) of a record.  Return empty string if revision
    does not exist.
    """
    res = ""
    job_date = "%s-%s-%s %s:%s:%s" % re_revdate_split.search(revid).groups()
    tmp_res = get_marcxml_of_record_revision(recid, job_date)
    if tmp_res:
        for row in tmp_res:
            res += zlib.decompress(row[0]) + "\n"
    return res
    def verify_revision(self, verify_record, original_record, opt_mode=None):
        """
        Compares the upload record with the same 005 record from archive.

        Once the changes are identified, The latest revision of the record is fetched
        from the system and the identified changes are applied over the latest.

        Returns record patch in case of non-conflicting addition/modification/deletion
        Conflicting records raise Error and stops the bibupload process
        """

        upload_rev = ''
        original_rev = ''
        r_date = ''
        record_patch = {}

        # No need for revision check for other operations
        if opt_mode not in ['replace', 'correct']:
            return

        if '001' in verify_record:
            self.rec_id = record_get_field_value(verify_record, '001')

        # Retrieving Revision tags for comparison
        if '005' in verify_record:
            upload_rev = record_get_field_value(verify_record, '005')
            r_date = upload_rev.split('.')[0]

            if r_date not in [k[1] for k in get_record_revisions(self.rec_id)]:
                raise InvenioBibUploadInvalidRevisionError(self.rec_id, r_date)
        else:
            raise InvenioBibUploadMissing005Error(self.rec_id)

        if '005' in original_record:
            original_rev = record_get_field_value(original_record, '005')
        else:
            raise InvenioBibUploadMissing005Error(self.rec_id)

        # Retrieving the archived version
        marc_xml = get_marcxml_of_record_revision(self.rec_id, r_date)
        res = create_record(zlib.decompress(marc_xml[0][0]))
        archived_record = res[0]

        # Comparing Upload and Archive record
        curr_patch = self.compare_records(verify_record, archived_record, opt_mode)

        # No changes in Upload Record compared to Archived Revision
        # Raising Error to skip the bibupload for the record
        if not curr_patch:
            raise InvenioBibUploadUnchangedRecordError(self.rec_id, upload_rev)

        if original_rev == upload_rev:
            # Upload, Archive and Original Records have same Revisions.
            affected_tags = self.retrieve_affected_tags_with_ind(curr_patch)
            return ('correct', self.generate_final_patch(curr_patch, self.rec_id), affected_tags)

        # Comparing Original and Archive record
        orig_patch = self.compare_records(original_record, archived_record, opt_mode)

        # Checking for conflicts
        # If no original patch - Original Record same as Archived Record
        if orig_patch:
            curr_patch = self.detect_conflict(verify_record, curr_patch, upload_rev, \
                                                original_record, orig_patch, original_rev)

        record_patch = self.generate_final_patch(curr_patch, self.rec_id)
        affected_tags = self.retrieve_affected_tags_with_ind(curr_patch)

        # Returning patch in case of no conflicting fields
        return ('correct', record_patch, affected_tags)
Beispiel #5
0
    def verify_revision(self, verify_record, original_record, opt_mode=None):
        """
        Compares the upload record with the same 005 record from archive.

        Once the changes are identified, The latest revision of the record is fetched
        from the system and the identified changes are applied over the latest.

        Returns record patch in case of non-conflicting addition/modification/deletion
        Conflicting records raise Error and stops the bibupload process
        """

        upload_rev = ''
        original_rev = ''
        r_date = ''
        record_patch = {}

        # No need for revision check for other operations
        if opt_mode not in ['replace', 'correct']:
            return

        if '001' in verify_record:
            self.rec_id = record_get_field_value(verify_record, '001')

        # Retrieving Revision tags for comparison
        if '005' in verify_record:
            upload_rev = record_get_field_value(verify_record, '005')
            r_date = upload_rev.split('.')[0]

            if r_date not in [k[1] for k in get_record_revisions(self.rec_id)]:
                raise InvenioBibUploadInvalidRevisionError(self.rec_id, r_date)
        else:
            raise InvenioBibUploadMissing005Error(self.rec_id)

        if '005' in original_record:
            original_rev = record_get_field_value(original_record, '005')
        else:
            raise InvenioBibUploadMissing005Error(self.rec_id)

        # Retrieving the archived version
        marc_xml = get_marcxml_of_record_revision(self.rec_id, r_date)
        res = create_record(zlib.decompress(marc_xml[0][0]))
        archived_record = res[0]

        # Comparing Upload and Archive record
        curr_patch = self.compare_records(verify_record, archived_record,
                                          opt_mode)

        # No changes in Upload Record compared to Archived Revision
        # Raising Error to skip the bibupload for the record
        if not curr_patch:
            raise InvenioBibUploadUnchangedRecordError(self.rec_id, upload_rev)

        if original_rev == upload_rev:
            # Upload, Archive and Original Records have same Revisions.
            affected_tags = self.retrieve_affected_tags_with_ind(curr_patch)
            return ('correct',
                    self.generate_final_patch(curr_patch,
                                              self.rec_id), affected_tags)

        # Comparing Original and Archive record
        orig_patch = self.compare_records(original_record, archived_record,
                                          opt_mode)

        # Checking for conflicts
        # If no original patch - Original Record same as Archived Record
        if orig_patch:
            curr_patch = self.detect_conflict(curr_patch, upload_rev, \
                                                orig_patch, original_rev)

        record_patch = self.generate_final_patch(curr_patch, self.rec_id)
        affected_tags = self.retrieve_affected_tags_with_ind(curr_patch)

        # Returning patch in case of no conflicting fields
        return ('correct', record_patch, affected_tags)