Exemple #1
0
def insert_wf_record_source(json, record_uuid, source):
    """Stores a record in the WorkflowRecordSource table in the db.

    Args:
        json(dict): the record's content to store
        record_uuid(uuid): the record's uuid
        source(string): the source of the record
    """
    if not source:
        return

    source = get_source_for_root(source)
    record_source = read_wf_record_source(record_uuid=record_uuid,
                                          source=source)

    if record_source is None:
        record_source = WorkflowsRecordSources(
            source=source.lower(),
            json=json,
            record_uuid=record_uuid,
        )
        db.session.add(record_source)
    else:
        record_source.json = json
    db.session.commit()
Exemple #2
0
def insert_wf_record_source(json, record_uuid, source):
    """Stores a record in the WorkflowRecordSource table in the db.

    Args:
        json(dict): the record's content to store
        record_uuid(uuid): the record's uuid
        source(string): the source of the record
    """
    if not source:
        return

    source = get_source_for_root(source)
    record_source = read_wf_record_source(
        record_uuid=record_uuid, source=source)

    if record_source is None:
        record_source = WorkflowsRecordSources(
            source=source.lower(),
            json=json,
            record_uuid=record_uuid,
        )
        db.session.add(record_source)
    else:
        record_source.json = json
    db.session.commit()
Exemple #3
0
 def _merge_roots(new_uuid, head_roots, update_roots):
     """Return the new roots to link to head."""
     head_sources = {h.source: h for h in head_roots}
     for update_root in update_roots:
         if update_root.source not in head_sources:
             head_roots.append(
                 WorkflowsRecordSources(source=update_root.source,
                                        record_uuid=new_uuid,
                                        json=update_root.json))
         elif head_sources[
                 update_root.source].updated < update_root.updated:
             head_roots.remove(head_sources[update_root.source])
             head_roots.append(
                 WorkflowsRecordSources(source=update_root.source,
                                        record_uuid=new_uuid,
                                        json=update_root.json))
         db.session.delete(update_root)
     return head_roots
Exemple #4
0
 def _merge_roots(new_uuid, head_roots, update_roots):
     """Return the new roots to link to head."""
     head_sources = [h.source for h in head_roots]
     for u in update_roots:
         if u.source not in head_sources:
             head_roots.append(
                 WorkflowsRecordSources(
                     source=u.source,
                     record_id=new_uuid,
                     json=u.json
                 )
             )
     return head_roots
Exemple #5
0
def store_root(obj, eng):
    """Insert or update the current record head's root into the ``WorkflowsRecordSources`` table."""
    if not current_app.config.get('FEATURE_FLAG_ENABLE_MERGER', False):
        obj.log.info(
            'skipping storing source root, feature flag ``FEATURE_FLAG_ENABLE_MERGER`` is disabled.'
        )
        return

    root = obj.extra_data['merger_root']
    head_uuid = obj.extra_data['head_uuid']

    source = LiteratureReader(root).source.lower()

    if not source:
        return

    root_record = WorkflowsRecordSources(
        source=get_source_for_root(source),
        record_uuid=head_uuid,
        json=root,
    )
    db.session.merge(root_record)
    db.session.commit()