Example #1
0
def update_collection_in_solr(version_id, references):
    cv = CollectionVersion.objects.get(id=version_id)
    cv._ocl_processing = True
    cv.save()
    concepts, mappings = [], [],

    for ref in references:
        if len(ref.concepts) > 0:
            concepts += ref.concepts
        if ref.mappings and len(ref.mappings) > 0:
            mappings += ref.mappings

    concept_versions = ConceptVersion.objects.filter(
        mnemonic__in=_get_version_ids(concepts, 'Concept'))
    mapping_versions = MappingVersion.objects.filter(
        id__in=_get_version_ids(mappings, 'Mapping'))

    if len(concept_versions) > 0:
        update_all_in_index(ConceptVersion, concept_versions)

    if len(mapping_versions) > 0:
        update_all_in_index(MappingVersion, mapping_versions)

    cv._ocl_processing = False
    cv.save()
Example #2
0
def update_collection_in_solr(self, version_id, references):
    from concepts.models import ConceptVersion
    from mappings.models import MappingVersion
    from collection.models import CollectionVersion

    version = CollectionVersion.objects.get(id=version_id)
    version.add_processing(self.request.id)
    try:
        concepts, mappings = [], [],

        for ref in references:
            if len(ref.concepts) > 0:
                concepts += ref.concepts
            if ref.mappings and len(ref.mappings) > 0:
                mappings += ref.mappings

        concept_versions = ConceptVersion.objects.filter(
            mnemonic__in=_get_version_ids(concepts, 'Concept'))
        mapping_versions = MappingVersion.objects.filter(
            id__in=_get_version_ids(mappings, 'Mapping'))

        if len(concept_versions) > 0:
            update_all_in_index(ConceptVersion, concept_versions)

        if len(mapping_versions) > 0:
            update_all_in_index(MappingVersion, mapping_versions)
    finally:
        version.remove_processing(self.request.id)
Example #3
0
def update_collection_in_solr(self, version_id, references):
    from concepts.models import ConceptVersion
    from mappings.models import MappingVersion
    from collection.models import CollectionVersion

    version = CollectionVersion.objects.get(id=version_id)
    version.add_processing(self.request.id)
    try:
        concepts, mappings = [], [],

        for ref in references:
            if len(ref.concepts) > 0:
                concepts += ref.concepts
            if ref.mappings and len(ref.mappings) > 0:
                mappings += ref.mappings

        concept_versions = ConceptVersion.objects.filter(mnemonic__in=_get_version_ids(concepts, 'Concept'))
        mapping_versions = MappingVersion.objects.filter(id__in=_get_version_ids(mappings, 'Mapping'))

        if len(concept_versions) > 0:
            update_all_in_index(ConceptVersion, concept_versions)

        if len(mapping_versions) > 0:
            update_all_in_index(MappingVersion, mapping_versions)
    finally:
        version.remove_processing(self.request.id)
Example #4
0
def index_resource(resource_ids, resource_klass, resource_version_klass, identifier):
    _resource_ids = resource_klass.objects.filter(id__in=resource_ids)
    resource_version_ids = list(set(resource_ids) - set(map(lambda m: m.id, _resource_ids)))
    version_ids = map(lambda r: r.get_latest_version.id, _resource_ids) + resource_version_ids
    kwargs = {}
    kwargs[identifier] = version_ids
    versions = resource_version_klass.objects.filter(**kwargs)
    update_all_in_index(resource_version_klass, versions)
Example #5
0
def index_resource(resource_ids, resource_klass, resource_version_klass, identifier):
    _resource_ids = resource_klass.objects.filter(id__in=resource_ids)
    resource_version_ids = list(set(resource_ids) - set(map(lambda m: m.id, _resource_ids)))
    version_ids = map(lambda r: r.get_latest_version.id, _resource_ids) + resource_version_ids
    kwargs = {}
    kwargs[identifier] = version_ids
    versions = resource_version_klass.objects.filter(**kwargs)
    update_all_in_index(resource_version_klass, versions)
Example #6
0
def update_children_for_resource_version(version_id, _type):
    _resource = resource(version_id, _type)
    _resource._ocl_processing = True
    _resource.save()
    versions = ConceptVersion.objects.filter(id__in=_resource.concepts)
    update_all_in_index(ConceptVersion, versions)
    mappingVersions = MappingVersion.objects.filter(id__in=_resource.mappings)
    update_all_in_index(MappingVersion, mappingVersions)
    _resource._ocl_processing = False
    _resource.save()
Example #7
0
def update_children_for_resource_version(version_id, _type):
    _resource = resource(version_id, _type)
    _resource._ocl_processing = True
    _resource.save()
    versions = ConceptVersion.objects.filter(id__in=_resource.concepts)
    update_all_in_index(ConceptVersion, versions)
    mappingVersions = MappingVersion.objects.filter(id__in=_resource.mappings)
    update_all_in_index(MappingVersion, mappingVersions)
    _resource._ocl_processing = False
    _resource.save()
Example #8
0
def update_children_for_source_version(version_id):
    sv = SourceVersion.objects.get(id=version_id)
    sv._ocl_processing = True
    sv.save()
    versions = ConceptVersion.objects.filter(id__in=sv.concepts)
    update_all_in_index(ConceptVersion, versions)
    mappings = Mapping.objects.filter(id__in=sv.mappings)
    update_all_in_index(Mapping, mappings)
    sv._ocl_processing = False
    sv.save()
Example #9
0
def delete_resources_from_collection_in_solr(version_id, concepts, mappings):
    cv = CollectionVersion.objects.get(id=version_id)
    cv._ocl_processing = True
    cv.save()

    if len(concepts) > 0:
        concepts = Concept.objects.filter(id__in=concepts)
        version_ids = map(lambda c: c.get_latest_version.id, concepts)
        versions = ConceptVersion.objects.filter(mnemonic__in=version_ids)
        update_all_in_index(ConceptVersion, versions)

    if len(mappings) > 0:
        mappings = Mapping.objects.filter(id__in=mappings)
        update_all_in_index(Mapping, mappings)

    cv._ocl_processing = False
    cv.save()
Example #10
0
def update_children_for_resource_version(self, version_id, _type):
    from concepts.models import ConceptVersion
    from mappings.models import MappingVersion

    _resource = resource(version_id, _type)
    _resource.add_processing(self.request.id)
    try:
        concept_versions = _resource.get_concepts()
        mapping_versions = _resource.get_mappings()

        logger.info('Indexing %s concepts...' % concept_versions.count())

        update_all_in_index(ConceptVersion, concept_versions)
        logger.info('Indexing %s mappings...' % mapping_versions.count())

        update_all_in_index(MappingVersion, mapping_versions)

    finally:
        _resource.remove_processing(self.request.id)
Example #11
0
def update_children_for_resource_version(self, version_id, _type):
    from concepts.models import ConceptVersion
    from mappings.models import MappingVersion

    _resource = resource(version_id, _type)
    _resource.add_processing(self.request.id)
    try:
        concept_versions = _resource.get_concepts()
        mapping_versions = _resource.get_mappings()

        logger.info('Indexing %s concepts...' % concept_versions.count())

        update_all_in_index(ConceptVersion, concept_versions)
        logger.info('Indexing %s mappings...' % mapping_versions.count())

        update_all_in_index(MappingVersion, mapping_versions)

    finally:
        _resource.remove_processing(self.request.id)
Example #12
0
def update_children_for_resource_version(self, version_id, _type):
    _resource = resource(version_id, _type)
    _resource.add_processing(self.request.id)
    try:
        if _type == 'source':
            concept_versions = _resource.get_concepts()
            mapping_versions = _resource.get_mappings()
        else:
            concept_versions = ConceptVersion.objects.filter(
                id__in=_resource.concepts)
            mapping_versions = MappingVersion.objects.filter(
                id__in=_resource.mappings)

        logger.info('Indexing %s concepts...' % concept_versions.count())
        update_all_in_index(ConceptVersion, concept_versions)
        logger.info('Indexing %s mappings...' % mapping_versions.count())
        update_all_in_index(MappingVersion, mapping_versions)

    finally:
        _resource.remove_processing(self.request.id)
Example #13
0
def update_collection_in_solr(version_id, references):
    cv = CollectionVersion.objects.get(id=version_id)
    cv._ocl_processing = True
    cv.save()
    concepts, mappings = [], [],

    for ref in references:
        if len(ref.concepts) > 0:
            concepts += ref.concepts
        if ref.mappings and len(ref.mappings) > 0:
            mappings += ref.mappings

    concept_versions = ConceptVersion.objects.filter(mnemonic__in=_get_version_ids(concepts, 'Concept'))
    mapping_versions = MappingVersion.objects.filter(id__in=_get_version_ids(mappings, 'Mapping'))

    if len(concept_versions) > 0:
        update_all_in_index(ConceptVersion, concept_versions)

    if len(mapping_versions) > 0:
        update_all_in_index(MappingVersion, mapping_versions)

    cv._ocl_processing = False
    cv.save()
Example #14
0
def update_collection_in_solr(version_id, references):
    cv = CollectionVersion.objects.get(id=version_id)
    cv._ocl_processing = True
    cv.save()
    concepts, mappings = [], [],

    for ref in references:
        if len(ref.concepts) > 0:
            concepts += ref.concepts
        if hasattr(ref, 'mappings') and ref.mappings is not None:
            mappings += ref.mappings

    version_ids = map(lambda c: c.get_latest_version.id, concepts)
    versions = ConceptVersion.objects.filter(mnemonic__in=version_ids)

    if len(versions) > 0:
        update_all_in_index(ConceptVersion, versions)

    if len(mappings) > 0:
        mappings = Mapping.objects.filter(id__in=map(lambda m: m.id, mappings))
        update_all_in_index(Mapping, mappings)

    cv._ocl_processing = False
    cv.save()
Example #15
0
def update_search_index_task(self, model, query):
    logger.info('Updating search index for %s...' % model.__name__)
    update_all_in_index(model, query)
Example #16
0
def update_search_index_task(self, model, query):
    logger.info('Updating search index for %s...' % model.__name__)
    update_all_in_index(model, query)