You answered the question in your post. If you want to query for documents in a specific folder you can use the in folder clause and that requires the ID of the folder you want to search.
How to use CMIS repo.query in a temp folder
Question
As part of an integration test, I create documents in a subfolder:
class CmisTestBase(unittest.TestCase):
def setUp(self):
""" Create a root test folder for the test. """
logger.debug("Creating client")
self.cmis_client = CmisClient(REPOSITORY_URL, USERNAME, PASSWORD)
logger.debug("Getting default repo")
self.repo = self.cmis_client.getDefaultRepository()
logger.debug("Getting root folder")
self.root_folder = self.repo.getObjectByPath(TEST_ROOT_PATH)
logger.debug("Creating test folder")
self.folder_name = ".".join(['cmislib', self.__class__.__name__, str(time.time())])
self.test_folder = self.root_folder.createFolder(self.folder_name)
def tearDown(self):
""" Clean up after the test. """
logger.debug("Deleting test folder")
self.test_folder.deleteTree()
And in my tests I create documents and then test that I can query them using repo.query
:
class SearchNoauth(SearchTest):
def setUp(self):
super(SearchNoauth, self).setUp()
def tearDown(self):
super(SearchNoauth, self).tearDown()
def test_noauth_empty(self):
logger.debug("Calling test_noauth_empty")
# Create a single document
self.create_document_simple()
# Retrieve all documents (No argument passed)
response = self.client.profile_noauth()
self.assertEqual(response.status_code, 200)
result_data = response.json()
logger.debug("results: {0}".format(pformat(result_data, indent=4)))
self.assertEqual(len(result_data), 1)
But as near as I can tell, my custom content created in the scope of the test is not found because the default repo does not search the test folder.
I'd expect an API:
to allow searches against a folder (not just a repo) or
to support a syntax for looking for objects in a specific folder
How do I construct a CMIS query that finds matching custom documents in a folder?
A bit more:
self.client.profile_noauth
is a call toprofile_noauth
method in a python client library- that hits a Pyramid server
- that aggregates a number of services, including Alfresco,
- and eventually calls
repo.query
against an Alfresco default repository.
Much of this question is how to modify the facade service's CMIS query to look in a folder.
Later: I think I may have an answer. The basic idea is to get the ID of the folder and use in_folder()
:
>>> folder = repo.getObjectByPath('/Sites/test-site-1/documentLibrary')
>>> query = """
select cmis:objectId, cmis:name
from cmis:document
where in_folder('%s')
order by cmis:lastModificationDate desc
""" % folder.id
Solution