-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbasic_operations.py
More file actions
280 lines (223 loc) · 9.49 KB
/
basic_operations.py
File metadata and controls
280 lines (223 loc) · 9.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
"""
Basic Operations Example using High-Level Utilities
This example demonstrates common Alfresco operations using the high-level
content_utils_highlevel and node_utils_highlevel modules. Shows dramatic
simplification for folder creation, node deletion, and basic file operations.
Original MCP implementation: 554 lines across multiple tools
High-level utilities: ~70 lines total (86% reduction)
"""
from python_alfresco_api.client_factory import ClientFactory
from python_alfresco_api.utils.content_utils_highlevel import (
create_folder_highlevel,
create_document_highlevel,
get_node_info_highlevel
)
from python_alfresco_api.utils.node_utils_highlevel import (
get_node_highlevel,
list_children_highlevel,
delete_node_highlevel,
get_node_path_highlevel,
bulk_delete_nodes_highlevel
)
def folder_operations_example():
"""Example of folder creation and management."""
client_factory = ClientFactory()
core_client = client_factory.create_core_client()
print("Example 1: Folder operations")
try:
# Create a new folder
print("[FOLDER] Creating folder...")
folder_result = create_folder_highlevel(
core_client=core_client,
name="My Project Folder",
parent_id="-shared-",
description="Project documents and files"
)
print(f"[SUCCESS] Folder created: {folder_result}")
# Create a subfolder (you'd extract the folder ID from previous result)
folder_id = "your-folder-id-here"
print("[FOLDER] Creating subfolder...")
subfolder_result = create_folder_highlevel(
core_client=core_client,
name="Documents",
parent_id=folder_id,
description="Document storage"
)
print(f"[SUCCESS] Subfolder created: {subfolder_result}")
except Exception as e:
print(f"[ERROR] Folder operations failed: {e}")
def document_creation_example():
"""Example of creating documents from text content."""
client_factory = ClientFactory()
core_client = client_factory.create_core_client()
print("\nExample 2: Document creation")
try:
# Create a text document (without content first)
print("[DOCUMENT] Creating text document...")
document_result = create_document_highlevel(
core_client=core_client,
name="Project Notes.txt",
parent_id="-my-",
description="Project planning notes"
)
print(f"[SUCCESS] Document created: {document_result}")
# Note: To add content, you would use update_content_from_string_highlevel
# or create_and_upload_file_highlevel for files with content
# Create a markdown document (without content)
print("[DOCUMENT] Creating markdown document...")
markdown_result = create_document_highlevel(
core_client=core_client,
name="Project Plan.md",
parent_id="-shared-",
title="Project Plan Document"
)
print(f"[SUCCESS] Markdown document created: {markdown_result}")
except Exception as e:
print(f"[ERROR] Document creation failed: {e}")
def browsing_operations_example():
"""Example of browsing and getting node information."""
client_factory = ClientFactory()
core_client = client_factory.create_core_client()
print("\nExample 3: Browsing operations")
try:
# List children of shared folder
print("[BROWSE] Listing shared folder contents...")
children_result = list_children_highlevel(
core_client=core_client,
parent_id="-shared-",
max_items=50
)
print(f"[RESULTS] Shared folder contents: {children_result}")
# Get detailed node information
node_id = "your-node-id-here"
print("[INFO] Getting node details...")
node_info = get_node_highlevel(core_client, node_id)
print(f"[RESULTS] Node details: {node_info}")
# Get node path
print("[PATH] Getting node path...")
node_path = get_node_path_highlevel(core_client, node_id)
print(f"[RESULTS] Node path: {node_path}")
except Exception as e:
print(f"[ERROR] Browsing operations failed: {e}")
def deletion_operations_example():
"""Example of deleting nodes and cleanup operations."""
client_factory = ClientFactory()
core_client = client_factory.create_core_client()
print("\nExample 4: Deletion operations")
try:
# Delete a single node
node_to_delete = "your-node-id-here"
print("[DELETE] Deleting single node...")
delete_result = delete_node_highlevel(
core_client=core_client,
node_id=node_to_delete,
permanent=False # Move to trash (can be restored)
)
print(f"[SUCCESS] Node deleted: {delete_result}")
# Bulk delete multiple nodes
nodes_to_delete = [
"node-id-1",
"node-id-2",
"node-id-3"
]
print("[DELETE] Bulk deleting nodes...")
bulk_delete_result = bulk_delete_nodes_highlevel(
core_client=core_client,
node_ids=nodes_to_delete,
permanent=False
)
print(f"[SUCCESS] Bulk delete completed: {bulk_delete_result}")
# Permanent deletion (cannot be restored)
print("[WARNING] Permanent deletion...")
permanent_delete_result = delete_node_highlevel(
core_client=core_client,
node_id="node-to-permanently-delete",
permanent=True
)
print(f"[SUCCESS] Permanently deleted: {permanent_delete_result}")
except Exception as e:
print(f"[ERROR] Deletion operations failed: {e}")
def workspace_organization_example():
"""Example of organizing a workspace with folders and documents."""
client_factory = ClientFactory()
core_client = client_factory.create_core_client()
print("\nExample 5: Workspace organization")
try:
# Create main project folder
print("[WORKSPACE] Creating project workspace...")
project_folder = create_folder_highlevel(
core_client=core_client,
name="New Project 2024",
parent_id="-my-",
description="Main project folder for 2024 initiative"
)
print(f"[SUCCESS] Project folder: {project_folder}")
# Assume we extracted the folder ID
project_id = "extracted-project-folder-id"
# Create organized subfolders
subfolders = [
{"name": "Documents", "desc": "Project documentation"},
{"name": "Resources", "desc": "Reference materials"},
{"name": "Meeting Notes", "desc": "Meeting recordings and notes"},
{"name": "Deliverables", "desc": "Final project outputs"}
]
created_folders = []
for folder_info in subfolders:
print(f"[FOLDER] Creating {folder_info['name']} folder...")
subfolder_result = create_folder_highlevel(
core_client=core_client,
name=folder_info["name"],
parent_id=project_id,
description=folder_info["desc"]
)
created_folders.append(subfolder_result)
print(f"[SUCCESS] Created: {folder_info['name']}")
# Create initial project documents
print("[DOCUMENT] Creating project README...")
readme_content = """# New Project 2024
## Project Overview
This is the main project folder for our 2024 initiative.
## Folder Structure
- Documents/: Project documentation
- Resources/: Reference materials
- Meeting Notes/: Meeting recordings and notes
- Deliverables/: Final project outputs
## Getting Started
1. Review project charter in Documents/
2. Check meeting notes for latest updates
3. Add your work to appropriate folders
"""
readme_result = create_document_highlevel(
core_client=core_client,
name="README.md",
parent_id=project_id,
title="Project README"
)
print(f"[SUCCESS] README created: {readme_result}")
except Exception as e:
print(f"[ERROR] Workspace organization failed: {e}")
if __name__ == "__main__":
print(">>> High-Level Basic Operations Examples")
print("=" * 55)
print("\n[FOLDER] Folder Management:")
folder_operations_example()
print("\n[DOCUMENT] Document Creation:")
document_creation_example()
print("\n[BROWSE] Browsing & Information:")
browsing_operations_example()
print("\n[DELETE] Deletion Operations:")
deletion_operations_example()
print("\n[WORKSPACE] Workspace Organization:")
workspace_organization_example()
print("\n[BENEFITS] Key Benefits:")
print("- One-line operations for complex tasks")
print("- Built-in error handling and validation")
print("- Type safety with Pydantic models")
print("- Consistent return formats")
print("- 86% code reduction vs raw API calls")
print("\n[SUMMARY] Common Operations Summary:")
print("- create_folder_highlevel(): Create folders with metadata")
print("- create_document_highlevel(): Create text documents")
print("- list_children_highlevel(): Browse folder contents")
print("- delete_node_highlevel(): Delete with trash/permanent options")
print("- bulk_delete_nodes_highlevel(): Delete multiple items")