From d5e965de3eb3fec418169855e7aa6a2e675919b0 Mon Sep 17 00:00:00 2001 From: Chuong Ho Date: Tue, 10 Sep 2024 14:12:26 +0800 Subject: [PATCH] add get element group by project --- .../src/aps_toolkit/AECDataModel.py | 59 +++++++++++++++++++ .../src/test/test_aec_data_model.py | 4 ++ 2 files changed, 63 insertions(+) diff --git a/APSToolkitPython/src/aps_toolkit/AECDataModel.py b/APSToolkitPython/src/aps_toolkit/AECDataModel.py index 9b41876..2313e0c 100644 --- a/APSToolkitPython/src/aps_toolkit/AECDataModel.py +++ b/APSToolkitPython/src/aps_toolkit/AECDataModel.py @@ -96,3 +96,62 @@ def get_folders(self, project_id: str) -> pd.DataFrame: result = self.execute_query_variables(data['query'], data['variables']) folders = result['data']['foldersByProject']['results'] return pd.json_normalize(folders) + + def get_element_group_by_project(self, projectId: str) -> pd.DataFrame: + """ + Get element groups by project, return source file urn and version urn in alternativeIdentifiers + :param projectId: + :return: + """ + data = { + "query": """ + query GetElementGroupsByProject($projectId: ID!) { + elementGroupsByProject(projectId: $projectId) { + pagination { + cursor + } + results{ + name + id + version{ + versionNumber + createdOn + createdBy{ + id + userName + firstName + lastName + email + lastModifiedOn + createdOn + } + } + createdOn + lastModifiedBy{ + id + userName + firstName + lastName + email + lastModifiedOn + } + alternativeIdentifiers{ + fileUrn + fileVersionUrn + } + parentFolder{ + id + name + objectCount + } + } + } + } + """, + "variables": { + "projectId": projectId + } + } + result = self.execute_query_variables(data['query'], data['variables']) + item_versions = result['data']['elementGroupsByProject']['results'] + return pd.json_normalize(item_versions) diff --git a/APSToolkitPython/src/test/test_aec_data_model.py b/APSToolkitPython/src/test/test_aec_data_model.py index 95e3e5e..2683ed5 100644 --- a/APSToolkitPython/src/test/test_aec_data_model.py +++ b/APSToolkitPython/src/test/test_aec_data_model.py @@ -34,6 +34,10 @@ def test_get_folders(self): result = self.aec_data_model.get_folders(self.project_id) self.assertIsNotNone(result) + def test_get_element_group_by_project(self): + result = self.aec_data_model.get_element_group_by_project(self.project_id) + self.assertIsNotNone(result) + def test_version_group_by_project(self): query = """ query GetElementGroupsByProject($projectId: ID!) {