Esempio n. 1
0
    def _merge_record(obj, eng):
        d = Deposition(obj)
        sip = d.get_latest_sip(sealed=False)

        # Get the current record, which contains all fields.
        current_record = get_record(
            sip.metadata.get('recid'), reset_cache=True
        )

        form_class = d.get_draft(draft_id).form_class

        # Create a simplified record from the current record, that only
        # contains fields concerning this deposition.
        current_simple_record = deposition_record(
            current_record,
            [form_class],
            pre_process_load=pre_process_load,
            post_process_load=post_process_load,
            process_export=partial(process_export, d),
        )
        # Create a simplified record from the changes the user have made.
        changed_simple_record = make_record(sip.metadata, is_dump=True)

        # Make an initial patch of current record (e.g. some default values set
        # by the form, might not exists in the current record)
        for k in current_simple_record:
            if k not in current_record:
                current_record[k] = current_simple_record[k]

        # Export clean dumps
        current_simple_json = current_simple_record.dumps(clean=True)
        changed_simple_json = changed_simple_record.dumps(clean=True)
        current_full_json = current_record.dumps(clean=True)

        # Merge changes from changed record into the current record.
        sip.metadata = merge_func(
            d,
            current_full_json,
            current_simple_json,
            changed_simple_json,
        )

        # Ensure we are based on latest version_id to prevent being rejected in
        # the bibupload queue.
        hst_record = HstRECORD.query.filter_by(
            id_bibrec=sip.metadata.get('recid')
        ).order_by(HstRECORD.job_date.desc()).first()

        sip.metadata['modification_date'] = hst_record.job_date.isoformat()

        d.update()
Esempio n. 2
0
    def _merge_record(obj, eng):
        d = Deposition(obj)
        sip = d.get_latest_sip(sealed=False)

        # Get the current record, which contains all fields.
        current_record = get_record(
            sip.metadata.get('recid'), reset_cache=True
        )

        form_class = d.get_draft(draft_id).form_class

        # Create a simplified record from the current record, that only
        # contains fields concerning this deposition.
        current_simple_record = deposition_record(
            current_record,
            [form_class],
            pre_process_load=pre_process_load,
            post_process_load=post_process_load,
            process_export=partial(process_export, d),
        )
        # Create a simplified record from the changes the user have made.
        changed_simple_record = make_record(sip.metadata, is_dump=True)

        # Make an initial patch of current record (e.g. some default values set
        # by the form, might not exists in the current record)
        for k in current_simple_record:
            if k not in current_record:
                current_record[k] = current_simple_record[k]

        # Export clean dumps
        current_simple_json = current_simple_record.dumps(clean=True)
        changed_simple_json = changed_simple_record.dumps(clean=True)
        current_full_json = current_record.dumps(clean=True)

        # Merge changes from changed record into the current record.
        sip.metadata = merge_func(
            d,
            current_full_json,
            current_simple_json,
            changed_simple_json,
        )

        # Ensure we are based on latest version_id to prevent being rejected in
        # the bibupload queue.
        hst_record = HstRECORD.query.filter_by(
            id_bibrec=sip.metadata.get('recid')
        ).order_by(HstRECORD.job_date.desc()).first()

        sip.metadata['modification_date'] = hst_record.job_date.isoformat()

        d.update()