Exemple #1
0
 def create_document_from_json(self, content=None):
     """
     creates a new document in the database
     :param content: The content as str or Buffer
     :return: document_id as string
     """
     prov_document = form_string(content=content)
     return self.create_document(content=prov_document)
Exemple #2
0
 def create_document_from_provn(self, content=None):
     """
     Creates a prov document in the database based on the provn string or buffer
     :param content: provn string or buffer
     :return:document_id as string
     """
     prov_document = form_string(content=content)
     return self.create_document(content=prov_document)
Exemple #3
0
    def create_document(self, content=None):
        """
        The main method to create the document in the db
        :param content: The content can be a xml, json or provn string or buffer or a ProvDocument instnace
        :return:Document id as string
        """

        # Try to convert the content into the provDocument, if it is already a ProvDocument instance the function will return this document
        try:
            content = form_string(content=content)
        except ParseException as e:
            raise InvalidArgumentTypeException(e)

        prov_document = content

        doc_id = self._adapter.save_document()

        self._create_bundle(doc_id, prov_document)

        bundle_id_map = dict()
        for bundle in prov_document.bundles:
            custom_bundle_identifier = bundle.valid_qualified_name(
                PROV_API_BUNDLE_IDENTIFIER_PREFIX.format(bundle.identifier))
            bundle_record = ProvBundleRecord(
                bundle,
                identifier=custom_bundle_identifier,
                attributes={"prov:bundle_name": bundle.identifier})
            (metadata, attributes
             ) = self._get_metadata_and_attributes_for_record(bundle_record)
            bundle_id = self._adapter.save_bundle(document_id=doc_id,
                                                  attributes=attributes,
                                                  metadata=metadata)
            bundle_id_map.update({bundle.identifier: bundle_id})

            self._create_bundle(bundle_id, bundle)
            self._create_bundle_association(
                document_id=doc_id,
                bundle_id=bundle_id,
                bundle_identifier=custom_bundle_identifier,
                prov_bundle=bundle)

        for bundle in prov_document.bundles:
            self._create_bundle_links(bundle, bundle_id_map)

        return doc_id
    def test_form_string(self):
        result = form_string(self.test_files["json"])
        self.assertIsNotNone(result)
        self.assertIsInstance(result, ProvDocument)

        result = form_string(self.test_files["xml"])
        self.assertIsNotNone(result)
        self.assertIsInstance(result, ProvDocument)

        with self.assertRaises(NotImplementedError):
            form_string(self.test_files["provn"])

        with self.assertRaises(ParseException):
            form_string("A funny string but no xml, json or prov string")