Ejemplo n.º 1
0
    def _update_graph(self, hashless_iri, graph, allow_new_type, allow_type_removal):
        # Extracts and classifies subjects
        bnode_subjects, other_subjects = extract_subjects(graph)

        #Blank nodes (may obtain a regular IRI)
        resources = create_blank_nodes(self._manager, graph, bnode_subjects, hashless_iri=hashless_iri)

        #Objects with an existing IRI
        reg_resources, resources_to_update = create_regular_resources(self._manager, graph, other_subjects,
                                                                      hashless_iri=hashless_iri)
        resources += reg_resources

        # Subset of regular resources to update
        for resource in resources_to_update:
            resource.update_from_graph(graph, save=False, allow_new_type=allow_new_type,
                                       allow_type_removal=allow_type_removal)

        #Check validity before saving
        for r in resources:
            if not r.is_valid():
                raise OMBadRequestException()

        #TODO: improve it as a transaction (really necessary?)
        for r in resources:
            r.save()

        #Delete omitted resources
        all_resource_iris = {r.id for r in self._manager.filter(hashless_iri=hashless_iri)}
        resource_iris_to_remove = all_resource_iris.difference({r.id for r in resources})
        for iri in resource_iris_to_remove:
            # Cheap because already in the resource cache
            r = self._manager.get(id=iri)
            if r is not None:
                r.delete()
Ejemplo n.º 2
0
def _append_to_hydra_coll_from_graph(collection_resource, graph):
    collection_iri = collection_resource.id
    resource_manager = collection_resource.model_manager.resource_manager

    # Extracts and classifies subjects
    bnode_subjects, other_subjects = extract_subjects(graph)

    # Blank nodes (may obtain a regular IRI)
    new_resources = create_blank_nodes(resource_manager, graph, bnode_subjects, collection_iri=collection_iri)

    # Objects with an existing IRI
    # TODO: ask if it should be accepted
    reg_resources, _ = create_regular_resources(resource_manager, graph, other_subjects, collection_iri=collection_iri)
    new_resources += reg_resources

    return _append_resources_to_hydra_collection(collection_resource, new_resources)
Ejemplo n.º 3
0
    def _update_graph(self, hashless_iri, graph, allow_new_type,
                      allow_type_removal):
        # Extracts and classifies subjects
        bnode_subjects, other_subjects = extract_subjects(graph)

        #Blank nodes (may obtain a regular IRI)
        resources = create_blank_nodes(self._manager,
                                       graph,
                                       bnode_subjects,
                                       hashless_iri=hashless_iri)

        #Objects with an existing IRI
        reg_resources, resources_to_update = create_regular_resources(
            self._manager, graph, other_subjects, hashless_iri=hashless_iri)
        resources += reg_resources

        # Subset of regular resources to update
        for resource in resources_to_update:
            resource.update_from_graph(graph,
                                       save=False,
                                       allow_new_type=allow_new_type,
                                       allow_type_removal=allow_type_removal)

        #Check validity before saving
        for r in resources:
            if not r.is_valid():
                raise OMBadRequestException()

        #TODO: improve it as a transaction (really necessary?)
        for r in resources:
            r.save()

        #Delete omitted resources
        all_resource_iris = {
            r.id
            for r in self._manager.filter(hashless_iri=hashless_iri)
        }
        resource_iris_to_remove = all_resource_iris.difference(
            {r.id
             for r in resources})
        for iri in resource_iris_to_remove:
            # Cheap because already in the resource cache
            r = self._manager.get(id=iri)
            if r is not None:
                r.delete()
Ejemplo n.º 4
0
def _append_to_hydra_coll_from_graph(collection_resource, graph):
    collection_iri = collection_resource.id
    resource_manager = collection_resource.model_manager.resource_manager

    # Extracts and classifies subjects
    bnode_subjects, other_subjects = extract_subjects(graph)

    # Blank nodes (may obtain a regular IRI)
    new_resources = create_blank_nodes(resource_manager,
                                       graph,
                                       bnode_subjects,
                                       collection_iri=collection_iri)

    # Objects with an existing IRI
    # TODO: ask if it should be accepted
    reg_resources, _ = create_regular_resources(resource_manager,
                                                graph,
                                                other_subjects,
                                                collection_iri=collection_iri)
    new_resources += reg_resources

    return _append_resources_to_hydra_collection(collection_resource,
                                                 new_resources)