def complete_new_graph(cls, service, uri, parameters, new_graph, resource=None): """I implement :meth:`ILocalCore.complete_new_graph`. I handle the deprecated property ktbs:inherits, replacing it with ktbs:hasParentMethod """ # TODO LATER remove this, as this is a deprecated feature uses_inherits = False if resource is None: for inherited in new_graph.objects(uri, cls._INHERITS): new_graph.add((uri, KTBS.hasParentMethod, inherited)) uses_inherits = True else: added, removed = compute_added_and_removed(new_graph, resource.state, None, None) for added_parent in added.objects(uri, cls._INHERITS): new_graph.add((uri, KTBS.hasParentMethod, added_parent)) uses_inherits = True for rem_parent in removed.objects(uri, cls._INHERITS): new_graph.remove((uri, KTBS.hasParentMethod, rem_parent)) uses_inherits = True if uses_inherits: LOG.warn("Use of deprecated property ktbs:inherits")
def check_new_graph(cls, service, uri, parameters, new_graph, resource=None, added=None, removed=None): """I implement :meth:`~rdfrest.cores.local.ILocalCore.check_new_graph` I check that the sources exist and are in the same base. """ diag = super(AbstractTrace, cls).check_new_graph(service, uri, parameters, new_graph, resource, added, removed) if resource is not None: old_graph = resource.get_state() added, removed = compute_added_and_removed(new_graph, old_graph, added, removed) src_graph = added else: src_graph = new_graph base_uri = new_graph.value(None, KTBS.contains, uri) factory = service.get for src_uri in src_graph.objects(uri, KTBS.hasSource): if not src_uri.startswith(base_uri) \ or not isinstance(factory(src_uri), AbstractTrace): diag.append("Source <%s> is not a trace from the same base" % src_uri) return diag
def check_new_graph(cls, service, uri, parameters, new_graph, resource=None, added=None, removed=None): """I implement :meth:`~rdfrest.cores.local.ILocalCore.check_new_graph` I check that the sources exist and are in the same base. """ diag = super(AbstractTrace, cls).check_new_graph( service, uri, parameters, new_graph, resource, added, removed) if resource is not None: old_graph = resource.get_state() added, removed = compute_added_and_removed(new_graph, old_graph, added, removed) src_graph = added else: src_graph = new_graph base_uri = new_graph.value(None, KTBS.contains, uri) factory = service.get for src_uri in src_graph.objects(uri, KTBS.hasSource): if not src_uri.startswith(base_uri) \ or not isinstance(factory(src_uri), AbstractTrace): diag.append("Source <%s> is not a trace from the same base" % src_uri) return diag
def check_new_graph(cls, service, uri, parameters, new_graph, resource=None, added=None, removed=None): """I overrides :meth:`rdfrest.cores.local.ILocalCore.check_new_graph` I check that parent and parameters are acceptable """ if resource is None: the_graph = new_graph else: old_graph = resource.state added, removed = compute_added_and_removed(new_graph, old_graph, added, removed) the_graph = added # we only check values that were added/changed diag = super(Method, cls).check_new_graph(service, uri, parameters, new_graph, resource, added, removed) # check parent method (if it has been changed) parent_method_uri = the_graph.value(uri, KTBS.hasParentMethod) if parent_method_uri is not None: my_base = parent_uri(uri) parent_base = parent_uri(parent_method_uri) if my_base == parent_base: parent = service.get(URIRef(parent_method_uri)) if parent is None: diag.append("Parent method does not exist <%s>" % parent_method_uri) elif parent.RDF_MAIN_TYPE != KTBS.Method: diag.append("Parent <%s> is not a method" % parent_method_uri) else: if not get_builtin_method_impl(parent_method_uri): diag.append("Parent method is neither in same base nor " "built-in <%s>" % parent_method_uri) # check new parameters new_params = False for param in the_graph.objects(uri, KTBS.hasParameter): new_params = True if not isinstance(param, Literal): diag.append("Parameters should be literals; " "got <%s>" % param) if "=" not in param: diag.append("Parameter is ill-formatted: %r" % str(Literal)) # check global integrity of parameters (including unchanged ones) if new_params: seen = set() for param in new_graph.objects(uri, KTBS.hasParameter): key, _ = param.split("=", 1) if key in seen: diag.append("Parameter %s specified more than once" % key) else: seen.add(key) return diag
def complete_new_graph(cls, service, uri, parameters, new_graph, resource=None): """I implement :meth:`ILocalCore.complete_new_graph`. I handle the deprecated property ktbs:inherits, replacing it with ktbs:hasParentMethod """ # TODO LATER remove this, as this is a deprecated feature uses_inherits = False if resource is None: for inherited in new_graph.objects(uri, cls._INHERITS): new_graph.add((uri, KTBS.hasParentMethod, inherited)) uses_inherits = True else: added, removed = compute_added_and_removed(new_graph, resource.state, None, None) for added_parent in added.objects(uri, cls._INHERITS): new_graph.add((uri, KTBS.hasParentMethod, added_parent)) uses_inherits = True for rem_parent in removed.objects(uri, cls._INHERITS): new_graph.remove((uri, KTBS.hasParentMethod, rem_parent)) uses_inherits = True if uses_inherits: LOG.warn("Use of deprecated property ktbs:inherits")
def check_new_graph(cls, service, uri, parameters, new_graph, resource=None, added=None, removed=None): """I overrides :meth:`rdfrest.cores.local.ILocalCore.check_new_graph` I check that parent and parameters are acceptable """ if resource is None: the_graph = new_graph else: old_graph = resource.state added, removed = compute_added_and_removed(new_graph, old_graph, added, removed) the_graph = added # we only check values that were added/changed diag = super(Method, cls).check_new_graph(service, uri, parameters, new_graph, resource, added, removed) # check parent method (if it has been changed) parent_method_uri = the_graph.value(uri, KTBS.hasParentMethod) if parent_method_uri is not None: my_base = parent_uri(uri) parent_base = parent_uri(parent_method_uri) if my_base == parent_base: parent = service.get(URIRef(parent_method_uri)) if parent is None: diag.append("Parent method does not exist <%s>" % parent_method_uri) elif parent.RDF_MAIN_TYPE != KTBS.Method: diag.append("Parent <%s> is not a method" % parent_method_uri) else: if not get_builtin_method_impl(parent_method_uri): diag.append("Parent method is neither in same base nor " "built-in <%s>" % parent_method_uri) # check new parameters new_params = False for param in the_graph.objects(uri, KTBS.hasParameter): new_params = True if not isinstance(param, Literal): diag.append("Parameters should be literals; " "got <%s>" % param) if "=" not in param: diag.append("Parameter is ill-formatted: %r" % str(Literal)) # check global integrity of parameters (including unchanged ones) if new_params: seen = set() for param in new_graph.objects(uri, KTBS.hasParameter): key, _ = param.split("=", 1) if key in seen: diag.append("Parameter %s specified more than once" % key) else: seen.add(key) return diag