Beispiel #1
0
    def replace_content_object(self, document_family: DocumentFamily,
                               content_object_id: str,
                               document: Document) -> DocumentFamily:
        from kodexa import KodexaPlatform
        try:
            logger.info(
                f"Replacing document in family {document_family.id} content object {content_object_id}"
            )

            files = {"file": document.to_kddb()}
            content_object_replace = requests.put(
                f"{KodexaPlatform.get_url()}/api/stores/{self.ref.replace(':', '/')}/families/{document_family.id}/objects/{content_object_id}/content",
                headers={"x-access-token": KodexaPlatform.get_access_token()},
                files=files)

            if content_object_replace.status_code == 200:
                return DocumentFamily.parse_obj(content_object_replace.json())

            msg = "Document replace failed [" + content_object_replace.text + "], response " + str(
                content_object_replace.status_code)
            logger.warning(msg)
            raise Exception(msg)
        except JSONDecodeError:
            logger.warning("Unable to decode the JSON response")
            raise
Beispiel #2
0
    def put(self, path: str, document: Document) -> DocumentFamily:
        from kodexa import KodexaPlatform
        try:
            logger.info(f"Putting document to path {path}")

            files = {"file": document.to_kddb()}
            data = {
                "path": path,
                "documentVersion": document.version,
                "document": True
            }
            document_family_response = requests.post(
                f"{KodexaPlatform.get_url()}/api/stores/{self.ref.replace(':', '/')}/fs",
                params={"path": path},
                headers={"x-access-token": KodexaPlatform.get_access_token()},
                files=files,
                data=data)

            if document_family_response.status_code == 200:
                return DocumentFamily.parse_obj(
                    document_family_response.json())

            msg = "Document family create failed [" + document_family_response.text + "], response " + str(
                document_family_response.status_code)
            logger.warning(msg)
            raise Exception(msg)
        except JSONDecodeError:
            logger.warning("Unable to decode the JSON response")
            raise
Beispiel #3
0
    def add_related_document_to_family(self, document_family_id: str,
                                       transition: DocumentTransition,
                                       document: Document) -> ContentObject:
        from kodexa import KodexaPlatform
        try:
            logger.info(f"Putting document to family id {document_family_id}")

            data = {
                'transitionType': transition.transition_type.value,
                'documentVersion': document.version,
                'document': True,
                'sourceContentObjectId': transition.source_content_object_id
            }
            files = {"file": document.to_kddb()}
            document_family_response = requests.post(
                f"{KodexaPlatform.get_url()}/api/stores/{self.ref.replace(':', '/')}/families/{document_family_id}/objects",
                headers={"x-access-token": KodexaPlatform.get_access_token()},
                data=data,
                files=files)

            if document_family_response.status_code == 200:
                return ContentObject.parse_obj(document_family_response.json())

            msg = "Document family create failed [" + document_family_response.text + "], response " + str(
                document_family_response.status_code)
            logger.warning(msg)
            raise Exception(msg)
        except JSONDecodeError:
            logger.warning("Unable to decode the JSON response")
            raise
Beispiel #4
0
def test_virtual_navigation_with_no_0_index():
    document = Document(DocumentMetadata())
    node = document.create_node(node_type='loopy')
    node.content = "banana"
    document.content_node = node

    document.content_node.add_child(document.create_node(node_type='loopy',
                                                         content='banana2'),
                                    index=2)

    assert document.content_node.get_node_at_index(0).content is None
    assert document.content_node.get_node_at_index(
        0).next_node().content is None
    assert document.content_node.get_node_at_index(
        0).next_node().next_node().content == 'banana2'

    test_kddb = document.to_kddb()
    new_kddb = Document.from_kddb(test_kddb)

    assert new_kddb.content_node.get_node_at_index(0).content is None
    assert new_kddb.content_node.get_node_at_index(
        0).next_node().content is None
    assert new_kddb.content_node.get_node_at_index(
        0).next_node().next_node().content == 'banana2'