コード例 #1
0
    def build_body(self):
        if self._body_uri is None and self._body_inline is None:
            try:
                assert self._body_content is not None
                assert self._body_mimetype is not None

                self._body_pid = Fedora.get_pid()

                foxml = Foxml(pid=self._body_pid)
                # Object Properties
                foxml.create_object_properties()
                # Dublin Core Datastream
                dublin_core = Foxml.get_dublin_core_element(
                    pid=self._body_pid, title="Open Annotation Collaboration body object (B-1)"
                )
                foxml.create_xml_datastream(
                    element=dublin_core,
                    id="DC",
                    version_id="DC1",
                    mime="text/xml",
                    label="Dublin Core Record for this object",
                )
                # Attach body
                if self._body_mimetype == "text/xml":
                    foxml.create_xml_datastream(
                        element=self._body_content, id="OAC_BODY", label="OAC Body Content", mime=self._body_mimetype
                    )
                else:
                    raise AnnotationError("Only body contents with mimetype 'text/xml' is allowed at this time.")

                # Optional RELS-EXT Datastream for the content model
                if self._body_content_model is not None:
                    body_rels_ext_rdf_element = Foxml.get_rels_ext_model_element(
                        pid=self._body_pid, models=[self._body_content_model]
                    )
                    foxml.create_xml_datastream(
                        element=body_rels_ext_rdf_element,
                        id="RELS-EXT",
                        mime="application/rdf+xml",
                        label="RDF Statements about this object",
                        format_uri="info:fedora/fedora-system:FedoraRELSExt-1.0",
                    )

                self._body_uri = "info:fedora/%s" % self._body_pid
                self._body = foxml.get_foxml()
            except:
                raise  # AnnotationError("Could not create the (B-1) body object from passed parameters")
コード例 #2
0
 def test_pid_creation(self):
     pid1 = int(Fedora.get_pid().split(":")[-1])
     pid2 = int(Fedora.get_pid().split(":")[-1])
     assert pid2 > pid1
コード例 #3
0
    def build_annotation(self):
        self._annotation_pid = Fedora.get_pid()

        foxml = Foxml(pid=self._annotation_pid)
        self._annotation_uri = "info:fedora/%s" % self._annotation_pid

        # Object Properties
        foxml.create_object_properties()
        # Dublin Core Datastream
        dc_uri = "%s/DC" % self._annotation_uri
        dublin_core = Foxml.get_dublin_core_element(pid=self._annotation_pid, title=self._dc_title)
        foxml.create_xml_datastream(
            element=dublin_core,
            id="DC",
            version_id="DC1",
            mime="text/xml",
            label="Dublin Core Record for this object",
            fedora_uri=dc_uri,
            format_uri="http://www.openarchives.org/OAI/2.0/oai_dc/",
        )

        # Inline Body Datastream
        self.body_inline_rdf_element = None
        if self._body_inline is not None:
            self._body_uri = "%s/inlinebody" % self._annotation_uri
            self.body_inline_rdf_element = Foxml.get_body_inline_rdf_element(
                pid=self._annotation_pid, body_uri=self._body_uri, body_inline=self._body_inline
            )
            foxml.create_xml_datastream(
                element=self.body_inline_rdf_element,
                id="inlinebody",
                mime="application/rdf+xml",
                label="Inline Body for OAC annotation",
                fedora_uri=self._body_uri,
            )

        # Annotation Datastream
        anno_uri = "%s/annotation" % self._annotation_uri
        self.annotation_rdf = Foxml.get_annotation_rdf_element(
            pid=self._annotation_pid,
            body_uri=self._body_uri,
            oa_selector=self._oa_selector,
            body_mimetype=self._body_mimetype,
            annotated=self._annotated,
            generator=self._generator,
            annotator=self._annotator,
        )
        foxml.create_xml_datastream(
            element=self.annotation_rdf,
            id="annotation",
            mime="application/rdf+xml",
            label="OAC annotation core",
            fedora_uri=anno_uri,
        )

        # RELS-EXT Datastream
        # This 'get' should never fall back to '' because there is a default annotation content model ('oac:oa-annotation')
        oac_model = app.config.get("DEFUALT_ANNOTATION_CONTENT_MODEL", "")

        # The PID of the SDef object for Annotation Serialization
        # This is not required by Fedora so it was removed.
        # serialization_service = "oac-sdef:serialize"
        # self.rels_ext_rdf_element = Foxml.get_rels_ext_model_element(pid=self._annotation_pid,
        #                                                             models=[oac_model],
        #                                                             services=[serialization_service])
        self.rels_ext_rdf_element = Foxml.get_rels_ext_model_element(pid=self._annotation_pid, models=[oac_model])
        foxml.create_xml_datastream(
            element=self.rels_ext_rdf_element,
            id="RELS-EXT",
            mime="application/rdf+xml",
            label="RDF Statements about this object",
            format_uri="info:fedora/fedora-system:FedoraRELSExt-1.0",
        )

        self.specific_target_rdf_element = None
        self.selector_rdf_element = None
        if self._oa_selector is not None:
            # SpecificTarget Datastream
            sptg_uri = "%s/specifictarget" % self._annotation_uri
            self.specific_target_rdf_element = Foxml.get_specific_target_rdf_element(
                pid=self._annotation_pid, source_uri=self._source_uri, oax_style_uri=self._oax_style_uri
            )
            foxml.create_xml_datastream(
                element=self.specific_target_rdf_element,
                id="specifictarget",
                mime="application/rdf+xml",
                label="SpecificTarget data for OAC annotation",
                fedora_uri=sptg_uri,
            )

            # Selector Datastream
            sele_uri = "%s/selector" % self._annotation_uri
            self.selector_rdf_element = Foxml.get_selector_rdf_element(
                pid=self._annotation_pid,
                oa_selector=self._oa_selector,
                oa_selector_type_uri=self._oa_selector_type_uri,
                fragment_type=self._fragment_type,
            )
            foxml.create_xml_datastream(
                element=self.selector_rdf_element,
                id="selector",
                mime="application/rdf+xml",
                label="Selector data for OAC annotation",
                fedora_uri=sele_uri,
            )

        self._annotation = foxml.get_foxml()