document_ai_warehouse/common/src/common/utils/document_warehouse_utils.py [303:361]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        client = self.get_document_service_client()
        parent = client.common_location_path(self.project_number, self.api_location)

        # Initialize request argument(s)
        document = contentwarehouse_v1.Document()
        document.raw_document_path = raw_document_path
        document.display_name = display_name
        document.title = display_name
        document.reference_id = reference_id
        document.inline_raw_document = raw_inline_bytes
        document.text_extraction_disabled = False
        self.set_raw_document_file_type_from_mimetype(
            document=document, mime_type=mime_type
        )

        # Add properties from metadata

        if len(metadata_properties) > 0:
            document.properties.extend(metadata_properties)

        if docai_document:
            document.cloud_ai_document = docai_document._pb
            if append_docai_entities_to_doc_properties:
                self.append_docai_entities_to_doc_properties(
                    docai_document=docai_document,
                    docwarehouse_document=document,
                    docai_property_name=docai_property_name,
                )
        elif document_text:
            document.plain_text = document_text

        document.document_schema_name = f"{parent}/documentSchemas/{document_schema_id}"

        request = contentwarehouse_v1.CreateDocumentRequest(
            parent=parent,
            document=document,
        )

        request.request_metadata = self.create_request_metadata(
            caller_user_id=caller_user_id
        )

        response = client.create_document(request=request)

        return response

    def create_document_schema(self, schema: str) -> contentwarehouse_v1.DocumentSchema:
        # schema_json = json.loads(text_schema)

        client = self.get_document_schema_service_client()
        parent = client.common_location_path(self.project_number, self.api_location)

        # Initialize request argument(s)
        request = contentwarehouse_v1.CreateDocumentSchemaRequest()

        request.parent = parent

        # define schema
        request.document_schema = contentwarehouse_v1.DocumentSchema.from_json(schema)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



document_ai_warehouse/document_ai_warehouse_processing_python/document_warehouse_utils.py [277:337]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        client = self.get_document_service_client()
        parent = client.common_location_path(self.project_number, self.api_location)

        # Initialize request argument(s)
        document = contentwarehouse_v1.Document()
        document.raw_document_path = raw_document_path
        document.display_name = display_name
        document.title = display_name
        document.reference_id = reference_id
        document.inline_raw_document = raw_inline_bytes
        document.text_extraction_disabled = False
        self.set_raw_document_file_type_from_mimetype(
            document=document, mime_type=mime_type
        )

        # Add properties from metadata

        if len(metadata_properties) > 0:
            document.properties.extend(metadata_properties)

        if docai_document:
            document.cloud_ai_document = docai_document._pb
            if append_docai_entities_to_doc_properties:
                self.append_docai_entities_to_doc_properties(
                    docai_document=docai_document,
                    docwarehouse_document=document,
                    docai_property_name=docai_property_name,
                )
        elif document_text:
            document.plain_text = document_text

        document.document_schema_name = f"{parent}/documentSchemas/{document_schema_id}"

        request = contentwarehouse_v1.CreateDocumentRequest(
            parent=parent,
            document=document,
        )

        request.request_metadata = self.create_request_metadata(
            caller_user_id=caller_user_id
        )

        # Make the request
        response = client.create_document(request=request)

        # Handle the response
        return response

    def create_document_schema(self, schema: str) -> contentwarehouse_v1.DocumentSchema:
        # schema_json = json.loads(text_schema)

        client = self.get_document_schema_service_client()
        parent = client.common_location_path(self.project_number, self.api_location)

        # Initialize request argument(s)
        request = contentwarehouse_v1.CreateDocumentSchemaRequest()

        request.parent = parent

        # define schema
        request.document_schema = contentwarehouse_v1.DocumentSchema.from_json(schema)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



