-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathversioning_workflow.py
More file actions
218 lines (164 loc) · 7.78 KB
/
Copy pathversioning_workflow.py
File metadata and controls
218 lines (164 loc) · 7.78 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
"""
Versioning Workflow Example using High-Level Utilities
This example demonstrates the complete Alfresco document versioning workflow using
the high-level version_utils_highlevel module. Shows the core versioning pattern:
checkout → edit → checkin (or cancel) with dramatic code simplification.
Original MCP implementation: 655 lines across 3 tools
High-level utilities: ~50 lines total (88% reduction)
"""
from python_alfresco_api.client_factory import ClientFactory
from python_alfresco_api.utils.version_utils_highlevel import (
checkout_document_highlevel,
checkin_document_highlevel,
cancel_checkout_highlevel,
check_lock_status_highlevel,
get_version_history_highlevel
)
from python_alfresco_api.utils.content_utils_highlevel import create_and_upload_file_highlevel
def basic_versioning_example():
"""Example of the basic versioning workflow: checkout → checkin."""
client_factory = ClientFactory()
core_client = client_factory.create_core_client()
# Example document ID (you would get this from uploading or searching)
document_id = "your-document-id-here"
print("Example 1: Basic versioning workflow")
try:
# Step 1: Checkout document for editing
print("[LOCK] Checking out document...")
checkout_result = checkout_document_highlevel(core_client, document_id)
print(f"[SUCCESS] Checkout successful: {checkout_result}")
# Step 2: Make your changes (simulated here)
print("[EDIT] Making changes to document...")
# In real usage, you would edit the document file here
# Step 3: Checkin with new version (minor version 1.0 → 1.1)
print("[SAVE] Checking in with minor version...")
checkin_result = checkin_document_highlevel(
core_client,
document_id,
comment="Updated document content",
major_version=False # Creates minor version (1.1)
)
print(f"[SUCCESS] Checkin successful: {checkin_result}")
except Exception as e:
print(f"[ERROR] Versioning workflow failed: {e}")
def major_version_example():
"""Example of creating a major version."""
client_factory = ClientFactory()
core_client = client_factory.create_core_client()
document_id = "your-document-id-here"
print("\nExample 2: Major version workflow")
try:
# Checkout
print("[LOCK] Checking out for major changes...")
checkout_result = checkout_document_highlevel(core_client, document_id)
print(f"[SUCCESS] Checkout: {checkout_result}")
# Checkin with major version (1.1 → 2.0)
print("[SAVE] Checking in with major version...")
checkin_result = checkin_document_highlevel(
core_client,
document_id,
comment="Major revision with significant changes",
major_version=True # Creates major version (2.0)
)
print(f"[SUCCESS] Major version created: {checkin_result}")
except Exception as e:
print(f"[ERROR] Major version workflow failed: {e}")
def cancel_checkout_example():
"""Example of cancelling a checkout (discarding changes)."""
client_factory = ClientFactory()
core_client = client_factory.create_core_client()
document_id = "your-document-id-here"
print("\nExample 3: Cancel checkout workflow")
try:
# Checkout
print("[LOCK] Checking out document...")
checkout_result = checkout_document_highlevel(core_client, document_id)
print(f"[SUCCESS] Checkout: {checkout_result}")
# Simulate deciding not to make changes
print("[DECIDE] Deciding not to make changes...")
# Cancel checkout (discards working copy)
print("[CANCEL] Cancelling checkout...")
cancel_result = cancel_checkout_highlevel(core_client, document_id)
print(f"[SUCCESS] Checkout cancelled: {cancel_result}")
except Exception as e:
print(f"[ERROR] Cancel checkout failed: {e}")
def version_status_example():
"""Example of checking document version status."""
client_factory = ClientFactory()
core_client = client_factory.create_core_client()
document_id = "your-document-id-here"
print("\nExample 4: Version status and history")
try:
# Check lock status
print("[CHECK] Checking lock status...")
lock_status = check_lock_status_highlevel(core_client, document_id)
print(f"[STATUS] Lock status: {lock_status}")
# Get version history
print("[HISTORY] Getting version history...")
version_history = get_version_history_highlevel(core_client, document_id)
print(f"[STATUS] Version history: {version_history}")
except Exception as e:
print(f"[ERROR] Status check failed: {e}")
def complete_workflow_example():
"""Complete example: upload → version → checkout → checkin."""
client_factory = ClientFactory()
core_client = client_factory.create_core_client()
print("\nExample 5: Complete document lifecycle")
try:
# Step 1: Upload a new document
print("[UPLOAD] Uploading new document...")
upload_result = create_and_upload_file_highlevel(
core_client=core_client,
file_path="./sample_document.txt",
filename="Sample Document.txt",
parent_id="-shared-"
)
print(f"[SUCCESS] Document uploaded: {upload_result}")
# Extract document ID from upload result (you'd parse this properly)
# document_id = extract_id_from_result(upload_result)
document_id = "newly-created-document-id"
# Step 2: Checkout for editing
print("[LOCK] Checking out for first edit...")
checkout_result = checkout_document_highlevel(core_client, document_id)
print(f"[SUCCESS] Checkout: {checkout_result}")
# Step 3: Checkin minor version (1.0 → 1.1)
print("[SAVE] Creating version 1.1...")
checkin_result = checkin_document_highlevel(
core_client,
document_id,
comment="First minor revision",
major_version=False
)
print(f"[SUCCESS] Version 1.1 created: {checkin_result}")
# Step 4: Another checkout/checkin cycle for major version
print("[LOCK] Checking out for major changes...")
checkout_result2 = checkout_document_highlevel(core_client, document_id)
print("[SAVE] Creating version 2.0...")
checkin_result2 = checkin_document_highlevel(
core_client,
document_id,
comment="Major revision with breaking changes",
major_version=True
)
print(f"[SUCCESS] Version 2.0 created: {checkin_result2}")
except Exception as e:
print(f"[ERROR] Complete workflow failed: {e}")
if __name__ == "__main__":
print(">>> High-Level Versioning Workflow Examples")
print("=" * 60)
print("\n[WORKFLOW] Core Workflow Pattern: checkout → edit → checkin")
basic_versioning_example()
major_version_example()
cancel_checkout_example()
version_status_example()
complete_workflow_example()
print("\n[BENEFITS] Key Benefits:")
print("- Complete versioning workflow in ~10 lines per operation")
print("- Automatic version number management (1.0 → 1.1 → 2.0)")
print("- Built-in error handling and cleanup")
print("- Type safety with Pydantic models")
print("- 88% code reduction vs raw API calls")
print("\n[PATTERN] Version Number Pattern:")
print("- Upload: Creates version 1.0")
print("- Minor checkin: 1.0 → 1.1 → 1.2 → ...")
print("- Major checkin: 1.x → 2.0 → 3.0 → ...")