def get_record_revision_ids(recid): """Return list of all record revision IDs. Return revision IDs in chronologically decreasing order (latest first). """ res = [] tmp_res = get_record_revisions(recid) for row in tmp_res: res.append('%s.%s' % (row[0], row[1])) return res
def get_record_revision_ids(recid): """Return list of all record revision IDs. Return revision IDs in chronologically decreasing order (latest first). """ res = [] tmp_res = get_record_revisions(recid) for row in tmp_res: res.append("%s.%s" % (row[0], row[1])) return res
def main(): from invenio.legacy.search_engine import get_record from invenio.legacy.bibupload.engine import ( bibupload, ) from invenio.legacy.bibrecord import ( create_record, ) from invenio.legacy.bibedit.db_layer import get_record_revisions from invenio.legacy.bibedit.utils import ( get_record_revision_ids, get_marcxml_of_revision, ) # Loop through list of records for r in RECORDS: rec = get_record(r) if not rec: break print('Processing record: {0}'.format(r)) # pprint(rec) print(get_record_revision_ids(r)) print revs = get_record_revisions(r) print(revs) print for id, rev in revs[0:1]: marcxml = get_marcxml_of_revision(r, rev) # print(marcxml) # print rec = create_record(marcxml)[0] pprint(rec) if raw_input('Bibupload (y/n)? ') == 'y': # bibupload(rec, 'delete') # sleep(5) bibupload(rec, 'replace')
def main(): from invenio.legacy.search_engine import get_record from invenio.legacy.bibupload.engine import ( bibupload, ) from invenio.legacy.bibrecord import ( create_record, ) from invenio.legacy.bibedit.db_layer import get_record_revisions from invenio.legacy.bibedit.utils import ( get_record_revision_ids, get_marcxml_of_revision, ) # Loop through list of records for r in RECORDS: rec = get_record(r) if not rec: break print('Processing record: {0}'.format(r)) # pprint(rec) print(get_record_revision_ids(r)) print revs = get_record_revisions(r) print(revs) print for id, rev in revs[0:1]: marcxml = get_marcxml_of_revision(r, rev) # print(marcxml) # print rec = create_record(marcxml)[0] pprint(rec) if raw_input('Bibupload (y/n)? ') == 'y': # bibupload(rec, 'delete') # sleep(5) bibupload(rec, 'replace')
def record_revision_exists(recid, revid): results = get_record_revisions(recid) for res in results: if res[1] == revid: return True return False
def record_revision_exists(recid, revid): results = get_record_revisions(recid) for res in results: if res[1] == revid: return True return False
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)
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)