-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtrue_high_level_api_example.py
More file actions
194 lines (172 loc) · 8.69 KB
/
Copy pathtrue_high_level_api_example.py
File metadata and controls
194 lines (172 loc) · 8.69 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
#!/usr/bin/env python3
"""
True High-Level API Design vs Current Thin Wrappers
Shows the difference between current pass-through wrappers and truly
developer-friendly high-level API methods.
"""
from python_alfresco_api import ClientFactory
from python_alfresco_api.auth_util import SimpleAuthUtil
from datetime import datetime
def demonstrate_api_levels():
"""Show the different levels of API abstraction."""
print("🎯 TRUE HIGH-LEVEL API DESIGN vs CURRENT THIN WRAPPERS")
print("=" * 70)
# Setup (same for all approaches)
auth = SimpleAuthUtil('admin', 'admin')
factory = ClientFactory(base_url='http://localhost:8080', auth_util=auth, verify_ssl=False)
core_client = factory.create_core_client()
print("\n📊 COMPARISON OF API ABSTRACTION LEVELS")
print("=" * 50)
# ================================================================
# LEVEL 1: RAW CLIENT (Lowest level)
# ================================================================
print("\n🔴 LEVEL 1: RAW CLIENT (Lowest Level)")
print("-" * 40)
print("from python_alfresco_api.raw_clients.alfresco_core_client.core_client.api.nodes import create_node")
print("from python_alfresco_api.raw_clients.alfresco_core_client.core_client.models.node_body_create import NodeBodyCreate")
print("")
print("folder_body = NodeBodyCreate(")
print(" name='My Folder',")
print(" node_type='cm:folder',")
print(" properties={'cm:title': 'My Title'} if properties else UNSET")
print(")")
print("result = create_node.sync(client=core_client, node_id='-root-', body=folder_body)")
print("")
print("📋 Developer Experience:")
print(" ❌ Need to import raw client functions")
print(" ❌ Need to understand model objects")
print(" ❌ Need to handle UNSET values")
print(" ❌ No error handling or validation")
print(" ❌ No progress tracking")
print(" ❌ Verbose and error-prone")
# ================================================================
# LEVEL 2: CURRENT THIN WRAPPERS (What I implemented)
# ================================================================
print("\n🟡 LEVEL 2: CURRENT THIN WRAPPERS (What I Implemented)")
print("-" * 50)
print("result = core_client.create_folder_sync(")
print(" parent_id='-root-',")
print(" name='My Folder',")
print(" title='My Title'")
print(")")
print("")
print("📋 Developer Experience:")
print(" ✅ Slightly cleaner method call")
print(" ✅ Hides some model complexity")
print(" ❌ Still exposes sync/async modes confusion")
print(" ❌ Still need to understand parent_id patterns")
print(" ❌ No error handling or validation")
print(" ❌ No progress tracking")
print(" ❌ Just a thin pass-through wrapper")
# ================================================================
# LEVEL 3: TRUE HIGH-LEVEL API (What it should be)
# ================================================================
print("\n🟢 LEVEL 3: TRUE HIGH-LEVEL API (What It Should Be)")
print("-" * 50)
print("# Simple, intuitive method calls:")
print("folder = core_client.create_folder('My Documents')")
print("file = folder.upload_file('document.pdf', content=file_data)")
print("file.set_permissions(users=['admin'], access='read')")
print("if file.upload_complete:")
print(" print(f'File uploaded: {file.download_url}')")
print("")
print("# Or fluent/chainable API:")
print("result = (core_client")
print(" .create_folder('Project Files')")
print(" .in_location('-my-')")
print(" .with_title('My Project')")
print(" .with_permissions(users=['team'], access='collaborate')")
print(" .execute())")
print("")
print("📋 Developer Experience:")
print(" ✅ Intuitive, self-documenting method names")
print(" ✅ Sensible defaults (parent location, permissions)")
print(" ✅ Built-in validation and error handling")
print(" ✅ Progress tracking for long operations")
print(" ✅ Chainable operations for workflows")
print(" ✅ Return rich objects with useful methods")
print(" ✅ Hide all internal complexity")
print(" ✅ async/sync handled transparently")
# ================================================================
# WHAT TRUE HIGH-LEVEL METHODS SHOULD PROVIDE
# ================================================================
print("\n🚀 WHAT TRUE HIGH-LEVEL METHODS SHOULD PROVIDE")
print("=" * 50)
features = [
"🎯 Intuitive method names (create_folder, not create_folder_sync)",
"🔧 Sensible defaults (parent='-my-' for user home)",
"✅ Input validation (check names, paths, permissions)",
"🛡️ Error handling with helpful messages",
"📈 Progress tracking for uploads/downloads",
"🔄 Retry logic with exponential backoff",
"🔗 Chainable operations for complex workflows",
"📦 Rich return objects with useful methods",
"🎭 Hide sync/async complexity (auto-detect or configure)",
"🏷️ Smart type hints and IDE auto-completion",
"📋 Built-in logging and debugging support",
"⚡ Performance optimizations (batching, caching)"
]
for feature in features:
print(f" {feature}")
# ================================================================
# PROPOSED IMPLEMENTATION STRATEGY
# ================================================================
print("\n📋 PROPOSED IMPLEMENTATION STRATEGY")
print("=" * 50)
print("🔄 STEP 1: Keep Current Thin Wrappers")
print(" • They provide some value (model object creation)")
print(" • Useful as building blocks for true high-level methods")
print(" • Backward compatibility")
print("\n🚀 STEP 2: Build True High-Level Methods ON TOP")
print(" • Use thin wrappers as building blocks")
print(" • Add validation, defaults, error handling")
print(" • Implement progress tracking and retry logic")
print(" • Create fluent/chainable APIs")
print("\n🎯 STEP 3: Rich Return Objects")
print(" • Return AlfrescoFolder, AlfrescoFile objects")
print(" • With methods like .upload(), .download(), .share()")
print(" • Smart properties like .size, .permissions, .url")
print("\n💡 STEP 4: Developer Experience Features")
print(" • Auto-complete friendly method signatures")
print(" • Built-in help and documentation")
print(" • Smart defaults based on context")
print(" • Helpful error messages with suggestions")
# ================================================================
# EXAMPLE TRUE HIGH-LEVEL IMPLEMENTATION
# ================================================================
print("\n💎 EXAMPLE TRUE HIGH-LEVEL IMPLEMENTATION")
print("=" * 50)
print("class AlfrescoCoreClient:")
print(" def create_folder(self, name: str, parent: str = '-my-',")
print(" title: str = None, description: str = None,")
print(" permissions: dict = None) -> AlfrescoFolder:")
print(" '''Create a folder with sensible defaults and validation.'''")
print(" ")
print(" # Validation")
print(" if not self._is_valid_name(name):")
print(" raise ValueError(f'Invalid folder name: {name}')")
print(" ")
print(" # Sensible defaults")
print(" if title is None:")
print(" title = name")
print(" ")
print(" # Use thin wrapper as building block")
print(" try:")
print(" result = self.create_folder_sync(parent, name, title, description)")
print(" return AlfrescoFolder(result, client=self)")
print(" except Exception as e:")
print(" raise AlfrescoError(f'Failed to create folder {name}: {e}')")
print("")
print("class AlfrescoFolder:")
print(" def upload_file(self, filename: str, content: bytes) -> AlfrescoFile:")
print(" '''Upload a file with progress tracking.'''")
print(" # Implementation with progress bar, retry logic, etc.")
print(" pass")
print("\n🎉 RESULT: Truly developer-friendly, enterprise-grade API!")
print(" • Hide complexity, expose functionality")
print(" • Sensible defaults and smart validation")
print(" • Rich objects with useful methods")
print(" • Progress tracking and error resilience")
print(" • Chainable operations for workflows")
if __name__ == "__main__":
demonstrate_api_levels()