Exemple #1
0
def _get_record(recid, uid, result, fresh_record=False):
    """Retrieve record structure.
    """
    record = None
    mtime = None
    cache_dirty = None
    record_status = record_exists(recid)
    existing_cache = cache_exists(recid, uid)
    if record_status == 0:
        result['resultCode'], result[
            'resultText'] = 1, 'Non-existent record: %s' % recid
    elif record_status == -1:
        result['resultCode'], result[
            'resultText'] = 1, 'Deleted record: %s' % recid
    elif not existing_cache and record_locked_by_other_user(recid, uid):
        result['resultCode'], result[
            'resultText'] = 1, 'Record %s locked by user' % recid
    elif existing_cache and cache_expired(recid, uid) and \
        record_locked_by_other_user(recid, uid):
        result['resultCode'], result[
            'resultText'] = 1, 'Record %s locked by user' % recid
    elif record_locked_by_queue(recid):
        result['resultCode'], result[
            'resultText'] = 1, 'Record %s locked by queue' % recid
    else:
        if fresh_record:
            delete_cache(recid, uid)
            existing_cache = False
        if not existing_cache:
            record_revision, record = create_cache(recid, uid)
            mtime = get_cache_mtime(recid, uid)
            cache_dirty = False
        else:
            tmpRes = get_cache_contents(recid, uid)
            cache_dirty, record_revision, record = tmpRes[0], tmpRes[
                1], tmpRes[2]
            touch_cache(recid, uid)
            mtime = get_cache_mtime(recid, uid)
            if not latest_record_revision(recid, record_revision):
                result['cacheOutdated'] = True
        result['resultCode'], result['resultText'], result[
            'cacheDirty'], result[
                'cacheMTime'] = 0, 'Record OK', cache_dirty, mtime
    record_order_subfields(record)
    return record
Exemple #2
0
def _get_record(recid, uid, result, fresh_record=False):
    """Retrieve record structure.
    """
    record = None
    mtime = None
    cache_dirty = None
    record_status = record_exists(recid)
    existing_cache = cache_exists(recid, uid)
    if record_status == 0:
        result['resultCode'], result['resultText'] = 1, 'Non-existent record: %s' % recid
    elif record_status == -1:
        result['resultCode'], result['resultText'] = 1, 'Deleted record: %s' % recid
    elif not existing_cache and record_locked_by_other_user(recid, uid):
        result['resultCode'], result['resultText'] = 1, 'Record %s locked by user' % recid
    elif existing_cache and cache_expired(recid, uid) and \
        record_locked_by_other_user(recid, uid):
        result['resultCode'], result['resultText'] = 1, 'Record %s locked by user' % recid
    elif record_locked_by_queue(recid):
        result['resultCode'], result['resultText'] = 1, 'Record %s locked by queue' % recid
    else:
        if fresh_record:
            delete_cache(recid, uid)
            existing_cache = False
        if not existing_cache:
            record_revision, record = create_cache(recid, uid)
            mtime = get_cache_mtime(recid, uid)
            cache_dirty = False
        else:
            tmpRes = get_cache_contents(recid, uid)
            cache_dirty, record_revision, record = tmpRes[0], tmpRes[1], tmpRes[2]
            touch_cache(recid, uid)
            mtime = get_cache_mtime(recid, uid)
            if not latest_record_revision(recid, record_revision):
                result['cacheOutdated'] = True
        result['resultCode'], result['resultText'], result['cacheDirty'], result['cacheMTime'] = 0, 'Record OK', cache_dirty, mtime
    record_order_subfields(record)
    return record
Exemple #3
0
def perform_request_record(requestType, uid, data):
    """Handle 'major' record related requests.
    Handle retrieving, submitting or cancelling the merging session.
    """
    #TODO add checks before submission and cancel, replace get_bibrecord call
    result = {'resultCode': 0, 'resultText': ''}
    recid1 = data["recID1"]
    record1 = _get_record(recid1, uid, result)
    if result[
            'resultCode'] != 0:  #if record not accessible return error information
        return result

    if requestType == 'submit':
        if 'duplicate' in data:
            recid2 = data['duplicate']
            record2 = _get_record_slave(recid2, result, 'recid', uid)
            if result['resultCode'] != 0:  #return in case of error
                return result
            (errcode, message) = check_doi_status_after_merge(
                data["recID1"],
                data['duplicate'],
                record1,
                record2,
                record2_marked_as_duplicate_p=data.has_key('duplicate'),
                submit_confirmed_p=data.get('additional_data', {
                    'confirmed_submit': False
                }).get('confirmed_submit', False))
            if errcode:
                result['resultCode'] = errcode
                result['resultText'] = message
                return result

            # mark record2 as deleted
            record_add_field(record2, '980', ' ', ' ', '', [('c', 'DELETED')])
            # mark record2 as duplicate of record1
            record_add_field(record2, '970', ' ', ' ', '',
                             [('d', str(recid1))])
            # add recid of deleted record to master record
            record_add_field(record1, '981', ' ', ' ', '',
                             [('a', str(recid2))])

            # To ensure updates happen in order, use a seq id
            sequence_id = str(random.randrange(1, 4294967296))

            # submit record2 to be deleted
            xml_record2 = record_xml_output(record2)
            save_xml_record(recid2,
                            uid,
                            xml_record2,
                            task_name="bibmerge",
                            sequence_id=sequence_id)

            # submit record1
            xml_record1 = record_xml_output(record1)
            save_xml_record(recid1,
                            uid,
                            xml_record1,
                            task_name="bibmerge",
                            sequence_id=sequence_id)

            # Delete cache file if it exists
            if cache_exists(recid1, uid):
                delete_cache(recid1, uid)

            result['resultText'] = 'Records submitted'
            return result

        (errcode, message) = check_doi_status_after_merge(
            data["recID1"],
            data["recID2"],
            record1,
            None,
            submit_confirmed_p=data.get('additional_data', {
                'confirmed_submit': False
            }).get('confirmed_submit', False))
        if errcode:
            result['resultCode'] = errcode
            result['resultText'] = message
            return result

        #submit record1 from cache
        save_xml_record(recid1, uid, task_name="bibmerge")

        # Delete cache file if it exists
        if cache_exists(recid1, uid):
            delete_cache(recid1, uid)

        result['resultText'] = 'Record submitted'
        return result

    elif requestType == 'cancel':
        delete_cache(recid1, uid)
        result['resultText'] = 'Cancelled'
        return result

    recid2 = data["recID2"]
    mode = data['record2Mode']
    record2 = _get_record_slave(recid2, result, mode, uid)
    if result[
            'resultCode'] != 0:  #if record not accessible return error information
        return result

    if requestType == 'getRecordCompare':
        result['resultHtml'] = bibmerge_templates.BM_html_all_diff(
            record1, record2)
        result['resultText'] = 'Records compared'

    elif requestType == 'recCopy':
        copy_R2_to_R1(record1, record2)
        result['resultHtml'] = bibmerge_templates.BM_html_all_diff(
            record1, record2)
        result['resultText'] = 'Record copied'

    elif requestType == 'recMerge':
        merge_record(record1, record2, merge_conflicting_fields=True)
        result['resultHtml'] = bibmerge_templates.BM_html_all_diff(
            record1, record2)
        result['resultText'] = 'Records merged'

    elif requestType == 'recMergeNC':
        merge_record(record1, record2, merge_conflicting_fields=False)
        result['resultHtml'] = bibmerge_templates.BM_html_all_diff(
            record1, record2)
        result['resultText'] = 'Records merged'

    else:
        result['resultCode'], result['resultText'] = 1, 'Wrong request type'

    return result
Exemple #4
0
def perform_request_record(requestType, uid, data):
    """Handle 'major' record related requests.
    Handle retrieving, submitting or cancelling the merging session.
    """
    #TODO add checks before submission and cancel, replace get_bibrecord call
    result = {
        'resultCode': 0,
        'resultText': ''
        }
    recid1 = data["recID1"]
    record1 = _get_record(recid1, uid, result)
    if result['resultCode'] != 0: #if record not accessible return error information
        return result

    if requestType == 'submit':
        if 'duplicate' in data:
            recid2 = data['duplicate']
            record2 = _get_record_slave(recid2, result, 'recid', uid)
            if result['resultCode'] != 0: #return in case of error
                return result
            # mark record2 as deleted
            record_add_field(record2, '980', ' ', ' ', '', [('c', 'DELETED')])
            # mark record2 as duplicate of record1
            record_add_field(record2, '970', ' ', ' ', '', [('d', str(recid1))])

            # submit record2 to be deleted
            xml_record2 = record_xml_output(record2)
            save_xml_record(recid2, uid, xml_record2)

            #submit record1
            xml_record1 = record_xml_output(record1)
            save_xml_record(recid1, uid, xml_record1)

            result['resultText'] = 'Records submitted'
            return result

        #submit record1 from cache
        save_xml_record(recid1, uid)

        # Delete cache file if it exists
        if cache_exists(recid1, uid):
            delete_cache_file(recid1, uid)

        result['resultText'] = 'Record submitted'
        return result

    elif requestType == 'cancel':
        delete_cache_file(recid1, uid)
        result['resultText'] = 'Cancelled'
        return result

    recid2 = data["recID2"]
    mode = data['record2Mode']
    record2 = _get_record_slave(recid2, result, mode, uid)
    if result['resultCode'] != 0: #if record not accessible return error information
        return result

    if requestType == 'getRecordCompare':
        result['resultHtml'] = bibmerge_templates.BM_html_all_diff(record1, record2)
        result['resultText'] = 'Records compared'

    elif requestType == 'recCopy':
        copy_R2_to_R1(record1, record2)
        result['resultHtml'] = bibmerge_templates.BM_html_all_diff(record1, record2)
        result['resultText'] = 'Record copied'

    elif requestType == 'recMerge':
        merge_record(record1, record2, merge_conflicting_fields=True)
        result['resultHtml'] = bibmerge_templates.BM_html_all_diff(record1, record2)
        result['resultText'] = 'Records merged'

    elif requestType == 'recMergeNC':
        merge_record(record1, record2, merge_conflicting_fields=False)
        result['resultHtml'] = bibmerge_templates.BM_html_all_diff(record1, record2)
        result['resultText'] = 'Records merged'

    else:
        result['resultCode'], result['resultText'] = 1, 'Wrong request type'

    return result
Exemple #5
0
def perform_request_record(requestType, uid, data):
    """Handle 'major' record related requests.
    Handle retrieving, submitting or cancelling the merging session.
    """
    #TODO add checks before submission and cancel, replace get_bibrecord call
    result = {
        'resultCode': 0,
        'resultText': ''
        }
    recid1 = data["recID1"]
    record1 = _get_record(recid1, uid, result)
    if result['resultCode'] != 0: #if record not accessible return error information
        return result

    if requestType == 'submit':
        if 'duplicate' in data:
            recid2 = data['duplicate']
            record2 = _get_record_slave(recid2, result, 'recid', uid)
            if result['resultCode'] != 0: #return in case of error
                return result
            (errcode, message) = check_doi_status_after_merge(data["recID1"], data['duplicate'],
                                                              record1, record2,
                                                              record2_marked_as_duplicate_p=data.has_key('duplicate'),
                                                              submit_confirmed_p=data.get('additional_data', {'confirmed_submit': False}).get('confirmed_submit', False))
            if errcode:
                result['resultCode'] = errcode
                result['resultText'] = message
                return result

            # mark record2 as deleted
            record_add_field(record2, '980', ' ', ' ', '', [('c', 'DELETED')])
            # mark record2 as duplicate of record1
            record_add_field(record2, '970', ' ', ' ', '', [('d', str(recid1))])
            # add recid of deleted record to master record
            record_add_field(record1, '981', ' ', ' ', '', [('a', str(recid2))])

            # To ensure updates happen in order, use a seq id
            sequence_id = str(random.randrange(1, 4294967296))

            # submit record2 to be deleted
            xml_record2 = record_xml_output(record2)
            save_xml_record(recid2, uid, xml_record2, task_name="bibmerge",
                            sequence_id=sequence_id)

            # submit record1
            xml_record1 = record_xml_output(record1)
            save_xml_record(recid1, uid, xml_record1, task_name="bibmerge",
                            sequence_id=sequence_id)

            # Delete cache file if it exists
            if cache_exists(recid1, uid):
                delete_cache(recid1, uid)

            result['resultText'] = 'Records submitted'
            return result

        (errcode, message) = check_doi_status_after_merge(data["recID1"], data["recID2"],
                                                          record1, None,
                                                          submit_confirmed_p=data.get('additional_data', {'confirmed_submit': False}).get('confirmed_submit', False))
        if errcode:
            result['resultCode'] = errcode
            result['resultText'] = message
            return result

        #submit record1 from cache
        save_xml_record(recid1, uid, task_name="bibmerge")

        # Delete cache file if it exists
        if cache_exists(recid1, uid):
            delete_cache(recid1, uid)

        result['resultText'] = 'Record submitted'
        return result

    elif requestType == 'cancel':
        delete_cache(recid1, uid)
        result['resultText'] = 'Cancelled'
        return result

    recid2 = data["recID2"]
    mode = data['record2Mode']
    record2 = _get_record_slave(recid2, result, mode, uid)
    if result['resultCode'] != 0: #if record not accessible return error information
        return result

    if requestType == 'getRecordCompare':
        result['resultHtml'] = bibmerge_templates.BM_html_all_diff(record1, record2)
        result['resultText'] = 'Records compared'

    elif requestType == 'recCopy':
        copy_R2_to_R1(record1, record2)
        result['resultHtml'] = bibmerge_templates.BM_html_all_diff(record1, record2)
        result['resultText'] = 'Record copied'

    elif requestType == 'recMerge':
        merge_record(record1, record2, merge_conflicting_fields=True)
        result['resultHtml'] = bibmerge_templates.BM_html_all_diff(record1, record2)
        result['resultText'] = 'Records merged'

    elif requestType == 'recMergeNC':
        merge_record(record1, record2, merge_conflicting_fields=False)
        result['resultHtml'] = bibmerge_templates.BM_html_all_diff(record1, record2)
        result['resultText'] = 'Records merged'

    else:
        result['resultCode'], result['resultText'] = 1, 'Wrong request type'

    return result