示例#1
0
def get_document_by_legacy_recid(legacy_recid):
    """Search documents by its legacy recid."""
    search = DocumentSearch().query('bool',
                                    filter=[
                                        Q('term', legacy_recid=legacy_recid),
                                    ])
    result = search.execute()
    hits_total = result.hits.total if lt_es7 else result.hits.total.value
    if not result.hits or hits_total < 1:
        click.secho(
            'no document found with legacy recid {}'.format(legacy_recid),
            fg='red')
        raise DocumentMigrationError(
            'no document found with legacy recid {}'.format(legacy_recid))
    elif hits_total > 1:
        click.secho(
            'no document found with legacy recid {}'.format(legacy_recid),
            fg='red')
        raise DocumentMigrationError(
            'found more than one document with recid {}'.format(legacy_recid))
    else:
        click.secho(
            '! document found with legacy recid {}'.format(legacy_recid),
            fg='green')
        return Document.get_record_by_pid(result.hits[0].pid)
示例#2
0
文件: api.py 项目: topless/cds-books
def get_document_by_legacy_recid(legacy_recid):
    """Search documents by its legacy recid."""
    search = DocumentSearch().query(
        "bool", filter=[Q("term", legacy_recid=legacy_recid)])
    result = search.execute()
    hits_total = result.hits.total.value
    if hits_total < 1:
        click.secho(
            "no document found with legacy recid {}".format(legacy_recid),
            fg="red",
        )
        raise DocumentMigrationError(
            "no document found with legacy recid {}".format(legacy_recid))
    elif hits_total > 1:
        click.secho(
            "no document found with legacy recid {}".format(legacy_recid),
            fg="red",
        )
        raise DocumentMigrationError(
            "found more than one document with recid {}".format(legacy_recid))
    else:
        click.secho(
            "! document found with legacy recid {}".format(legacy_recid),
            fg="green",
        )
        return Document.get_record_by_pid(result.hits[0].pid)
示例#3
0
def link_documents_and_serials():
    """Link documents/multiparts and serials."""
    def link_records_and_serial(record_cls, search):
        for hit in search.scan():
            # Skip linking if the hit doesn't have a legacy recid since it
            # means it's a volume of a multipart
            if 'legacy_recid' not in hit:
                continue
            record = record_cls.get_record_by_pid(hit.pid)
            for serial in get_serials_by_child_recid(hit.legacy_recid):
                volume = get_migrated_volume_by_serial_title(
                    record, serial['title']['title'])
                create_parent_child_relation(
                    serial, record, current_app.config['SERIAL_RELATION'],
                    volume)

    click.echo('Creating serial relations...')
    link_records_and_serial(
        Document,
        DocumentSearch().filter('term', _migration__has_serial=True))
    link_records_and_serial(
        Series,
        SeriesSearch().filter('bool',
                              filter=[
                                  Q('term',
                                    mode_of_issuance='MULTIPART_MONOGRAPH'),
                                  Q('term', _migration__has_serial=True),
                              ]))
示例#4
0
文件: api.py 项目: topless/cds-books
def link_documents_and_serials():
    """Link documents/multiparts and serials."""

    def link_records_and_serial(record_cls, search):
        for hit in search.scan():
            # Skip linking if the hit doesn't have a legacy recid since it
            # means it's a volume of a multipart
            if "legacy_recid" not in hit:
                continue
            record = record_cls.get_record_by_pid(hit.pid)
            for serial in get_serials_by_child_recid(hit.legacy_recid):
                volume = get_migrated_volume_by_serial_title(
                    record, serial["title"]
                )
                create_parent_child_relation(
                    serial, record, SERIAL_RELATION, volume
                )

    click.echo("Creating serial relations...")
    link_records_and_serial(
        Document, DocumentSearch().filter("term", _migration__has_serial=True)
    )
    link_records_and_serial(
        Series,
        SeriesSearch().filter(
            "bool",
            filter=[
                Q("term", mode_of_issuance="MULTIPART_MONOGRAPH"),
                Q("term", _migration__has_serial=True),
            ],
        ),
    )
示例#5
0
def link_and_create_multipart_volumes():
    """Link and create multipart volume records."""
    click.echo('Creating document volumes and multipart relations...')
    search = DocumentSearch().filter('term', _migration__is_multipart=True)

    for hit in search.scan():
        if 'legacy_recid' not in hit:
            continue
        multipart = get_multipart_by_legacy_recid(hit.legacy_recid)
        documents = create_multipart_volumes(hit.pid, hit.legacy_recid,
                                             hit._migration.volumes)
        for document in documents:
            if document and multipart:
                create_parent_child_relation(
                    multipart, document,
                    current_app.config['MULTIPART_MONOGRAPH_RELATION'],
                    document['volume'])
示例#6
0
文件: api.py 项目: topless/cds-books
def get_documents_with_external_eitems():
    """Return documents with eitems from external providers to be migrated."""
    search = DocumentSearch().filter(
        "bool",
        filter=[
            Q("term", _migration__eitems_has_external=True),
        ],
    )
    return search
示例#7
0
文件: api.py 项目: topless/cds-books
def get_documents_with_proxy_eitems():
    """Return documents with eitems behind proxy to be migrated."""
    search = DocumentSearch().filter(
        "bool",
        filter=[
            Q("term", _migration__eitems_has_proxy=True),
        ],
    )
    return search
示例#8
0
文件: api.py 项目: topless/cds-books
def get_all_documents_with_files():
    """Return all documents with files to be migrated."""
    search = DocumentSearch().filter(
        "bool",
        filter=[
            Q("term", _migration__has_files=True),
        ],
    )
    return search
示例#9
0
def link_and_create_multipart_volumes():
    """Link and create multipart volume records."""
    click.echo('Creating document volumes and multipart relations...')
    search = DocumentSearch().filter('term', _migration__is_multipart=True)
    for hit in search.scan():
        if 'legacy_recid' not in hit:
            continue
        click.secho('Linking multipart {}...'.format(hit.legacy_recid),
                    fg='green')
        multipart = get_multipart_by_legacy_recid(hit.legacy_recid)
        documents = create_multipart_volumes(hit.pid, hit.legacy_recid,
                                             hit._migration.volumes)

        for document in documents:
            if document and multipart:
                click.echo('Creating relations: {0} - {1}'.format(
                    multipart['pid'], document['pid']))
                create_parent_child_relation(multipart, document,
                                             MULTIPART_MONOGRAPH_RELATION,
                                             document['volume'])