Skip to content

Commit

Permalink
[#18] Functions to get documents in a zaak folder
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Aug 27, 2020
1 parent 4658c50 commit 1d8479b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
13 changes: 13 additions & 0 deletions drc_cmis/browser/drc_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,16 @@ class ZaakFolder(CMISBaseObject):
table = "drc:zaakfolder"
name_map = ZAAK_MAP
type_name = "zaak"

def get_children_documents(self) -> List[Document]:
"""Get all the documents in a zaak folder
:return: list of documents
"""
data = {
"cmisaction": "query",
"statement": f"SELECT * FROM drc:document WHERE IN_FOLDER('{self.objectId}')",
}
json_response = self.post_request(self.base_url, data=data)

return self.get_all_results(json_response, Document)
22 changes: 21 additions & 1 deletion drc_cmis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ def create_oio(self, data: dict) -> ObjectInformatieObject:
rhs=[data.get("informatieobject")],
)

# Get the parent folder to check if the document is in a Zaak folder
parent_folder = document.get_parent_folders()[0]

# Check if there are gebruiksrechten related to the document
related_gebruiksrechten = self.query(
return_type_name="gebruiksrechten",
Expand All @@ -258,7 +261,7 @@ def create_oio(self, data: dict) -> ObjectInformatieObject:
)

# Case 1: Already related to a zaak. Copy the document to the destination folder.
if len(retrieved_oios) > 0:
if len(retrieved_oios) > 0 or "drc:zaakfolder" in parent_folder.objectTypeId:
self.copy_document(document, destination_folder)
if len(related_gebruiksrechten) > 0:
for gebruiksrechten in related_gebruiksrechten:
Expand Down Expand Up @@ -378,3 +381,20 @@ def get_or_create_other_folder(self) -> Folder:
parent_folder = self.get_or_create_folder(folder_name, parent_folder, props)

return parent_folder

def get_documents_related_to_zaak(self, identificatie: str) -> List[Document]:
"""Get all documents in the zaak folder with drc:zaakfolder__identificatie.
:param identificatie: str, identification of the zaak
:return: list of Documents
"""

zaak_folder = self.query(
return_type_name="zaakfolder",
lhs=["drc:zaak__identificatie = '%s'"],
rhs=[str(identificatie)],
)[0]

documents = zaak_folder.get_children_documents()

return documents
27 changes: 27 additions & 0 deletions drc_cmis/webservice/drc_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,3 +497,30 @@ class ZaakFolder(CMISBaseObject):
name_map = ZAAK_MAP
type_name = "zaak"
type_class = ZaakFolderData

def get_children_documents(self) -> List[Document]:
"""Get all the documents in a zaak folder
:return: list of documents
"""
# In Corsa, the query "SELECT * FROM cmis:document WHERE IN_FOLDER('objectId')" doesnt work
# Operation getChildren returns all the children (including folders)
soap_envelope = make_soap_envelope(
auth=(self.user, self.password),
repository_id=self.main_repo_id,
folder_id=self.objectId,
cmis_action="getChildren",
)

soap_response = self.request(
"NavigationService", soap_envelope=soap_envelope.toxml()
)

xml_response = extract_xml_from_soap(soap_response)
extracted_data = extract_object_properties_from_xml(xml_response, "getChildren")

return [
Document(data)
for data in extracted_data
if "drc:document" in data["properties"]["cmis:objectTypeId"]["value"]
]

0 comments on commit 1d8479b

Please sign in to comment.