Пример #1
0
 def create(cls, service, uri, new_graph):
     """I implement :meth:`~rdfrest.cores.local.ILocalCore.create`
     """
     super(Method, cls).create(service, uri, new_graph)
     parent_method_uri = new_graph.value(uri, KTBS.hasParentMethod)
     my_base = parent_uri(uri)
     parent_base = parent_uri(parent_method_uri)
     if my_base == parent_base:  # parent is not a built-in method
         parent = service.get(parent_method_uri)
         with parent.edit(_trust=True) as editable:
             editable.add((uri, KTBS.hasParentMethod, parent_method_uri))
Пример #2
0
 def create(cls, service, uri, new_graph):
     """I implement :meth:`~rdfrest.cores.local.ILocalCore.create`
     """
     super(Method, cls).create(service, uri, new_graph)
     parent_method_uri = new_graph.value(uri, KTBS.hasParentMethod)
     my_base = parent_uri(uri)
     parent_base = parent_uri(parent_method_uri)
     if my_base == parent_base:  # parent is not a built-in method
         parent = service.get(parent_method_uri)
         with parent.edit(_trust=True) as editable:
             editable.add((uri, KTBS.hasParentMethod, parent_method_uri))
Пример #3
0
    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
Пример #4
0
 def _get_trace_from_uri(cls, service, obsel_uri):
     """I return the trace owning a given obsel.
     """
     ret = service.get(URIRef(parent_uri(obsel_uri)))
     assert ret.RDF_MAIN_TYPE in (KTBS.StoredTrace, KTBS.ComputedTrace), \
         (ret.RDF_MAIN_TYPE, obsel_uri)
     return ret
Пример #5
0
 def __init__(self, trace, uri):
     # not calling ILocalCore __init__ #pylint: disable=W0231
     assert trace.RDF_MAIN_TYPE in (KTBS.StoredTrace, KTBS.ComputedTrace)
     assert parent_uri(uri) == str(trace.uri)
     self.uri = uri
     self.service = trace.service
     self.home = trace.obsel_collection
     self._state = None
Пример #6
0
    def get_base(self):
        """
        Return the trace base this element belongs to.

        :rtype: `BaseMixin`:class:
        """
        base_uri = parent_uri(self.uri)
        ret = self.factory(base_uri, [KTBS.Base])
        assert isinstance(ret, BaseMixin)
        return ret
Пример #7
0
    def get_base(self):
        """
        Return the trace base this element belongs to.

        :rtype: `BaseMixin`:class:
        """
        base_uri = parent_uri(self.uri)
        ret = self.factory(base_uri, [KTBS.Base])
        assert isinstance(ret, BaseMixin)
        return ret
Пример #8
0
    def get(self, uri, rdf_types=None, _no_spawn=False):
        """I override :meth:`rdfrest.cores.local.Service.get`

        If the original implementation returns None, I try to make an Obsel.
        """
        ret = super(KtbsService, self).get(uri, rdf_types, _no_spawn)
        if ret is None:
            parent = super(KtbsService, self).get(URIRef(parent_uri(uri)),
                                                  None, _no_spawn)
            if parent is not None \
            and parent.RDF_MAIN_TYPE in (KTBS.StoredTrace, KTBS.ComputedTrace):
                assert rdf_types is None or KTBS.Obsel in rdf_types, rdf_types
                ret = Obsel(parent, uri)
        return ret
Пример #9
0
    def get(self, uri, rdf_types=None, _no_spawn=False):
        """I override :meth:`rdfrest.cores.local.Service.get`

        If the original implementation returns None, I try to make an Obsel.
        """
        ret = super(KtbsService, self).get(uri, rdf_types, _no_spawn)
        if ret is None:
            parent = super(KtbsService, self).get(URIRef(parent_uri(uri)), None,
                                                  _no_spawn)
            if parent is not None \
            and parent.RDF_MAIN_TYPE in (KTBS.StoredTrace, KTBS.ComputedTrace):
                assert rdf_types is None or KTBS.Obsel in rdf_types, rdf_types
                ret = Obsel(parent, uri)
        return ret
Пример #10
0
    def get_model(self):
        """
        Return the trace model defining this element.
        
        :rtype: `TraceModelMixin`:class:
        """
        #tmodel_uri = self.state.identifier
        #ret = self.factory(tmodel_uri, KTBS.TraceModel)
        #return ret

        #Waiting above code to be fixed.
        #We can have .../Model#ElementType
        #or          .../Model/ElementType
        defragmented_uri = self.uri.defrag()
        if len(self.uri) != len(defragmented_uri):
            model_uri = defragmented_uri
        else:
            model_uri = parent_uri(self.uri)
        ret = self.factory(model_uri, [KTBS.TraceModel])
        assert isinstance(ret, TraceModelMixin)
        return ret
Пример #11
0
    def get_model(self):
        """
        Return the trace model defining this element.
        
        :rtype: `TraceModelMixin`:class:
        """
        #tmodel_uri = self.state.identifier
        #ret = self.factory(tmodel_uri, KTBS.TraceModel)
        #return ret

        #Waiting above code to be fixed.
        #We can have .../Model#ElementType
        #or          .../Model/ElementType
        defragmented_uri = self.uri.defrag()
        if len(self.uri) != len(defragmented_uri):
            model_uri = defragmented_uri
        else:
            model_uri = parent_uri(self.uri)
        ret = self.factory(model_uri, [KTBS.TraceModel])
        assert isinstance(ret, TraceModelMixin)
        return ret
Пример #12
0
 def parent(self):
     """Return the group containing this item (if any)"""
     ret = self.factory(parent_uri(self.uri), [EXAMPLE.Group])
     assert isinstance(ret, GroupMixin)
     return ret
Пример #13
0
    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
Пример #14
0
 def parent(self):
     """Return the group containing this item (if any)"""
     ret = self.factory(parent_uri(self.uri), [EXAMPLE.Group])
     assert isinstance(ret, GroupMixin)
     return ret