-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdiscovery_examples.py
More file actions
151 lines (124 loc) · 6.27 KB
/
Copy pathdiscovery_examples.py
File metadata and controls
151 lines (124 loc) · 6.27 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
#!/usr/bin/env python3
"""
Alfresco Discovery API Examples
This file demonstrates how to use the Discovery API with the master client.
The Discovery API provides repository information and system capabilities.
"""
import sys
import os
import json
from python_alfresco_api import ClientFactory
def main():
"""Discovery API examples."""
print("🔍 Discovery API Examples")
# Initialize client factory and create master client
factory = ClientFactory(
base_url="http://localhost:8080",
username="admin",
password="admin"
)
client = factory.create_master_client()
if not client.discovery:
print("❌ Discovery API not available")
return
# Example 1: Get repository information
print("\n1. Getting repository information...")
try:
repo_info = client.discovery.get_repository_information()
if repo_info and hasattr(repo_info, 'entry') and hasattr(repo_info.entry, 'repository'):
repo = repo_info.entry.repository
print("✅ Repository Information Retrieved:")
print(f" Name: {getattr(repo, 'name', 'Unknown')}")
print(f" Version: {getattr(repo.version, 'display', 'Unknown') if hasattr(repo, 'version') else 'Unknown'}")
print(f" Edition: {getattr(repo, 'edition', 'Unknown')}")
status = 'Read-only' if (hasattr(repo, 'status') and getattr(repo.status, 'isReadOnly', False)) else 'Read-write'
print(f" Status: {status}")
# Show license info if available
if hasattr(repo_info.entry, 'license'):
license_info = repo_info.entry.license
print(f" License: {getattr(license_info, 'issued_at', 'Unknown')}")
# Show version details if available
if hasattr(repo, 'version'):
version = repo.version
print(f" Major Version: {getattr(version, 'major', 'Unknown')}")
print(f" Minor Version: {getattr(version, 'minor', 'Unknown')}")
print(f" Patch Version: {getattr(version, 'patch', 'Unknown')}")
else:
print("⚠️ Repository info received but in unexpected format")
except Exception as e:
print(f"⚠️ Standard API call failed: {e}")
# Example 2: Fallback to raw response
print("\n2. Trying raw response fallback...")
try:
raw_response = client.discovery.get_repository_information_without_preload_content()
if raw_response.status == 200:
data = json.loads(raw_response.data.decode('utf-8'))
repo = data['entry']['repository']
print("✅ Repository Information (Raw Response):")
print(f" Name: {repo.get('name', 'Unknown')}")
print(f" Version: {repo.get('version', {}).get('display', 'Unknown')}")
print(f" Edition: {repo.get('edition', 'Unknown')}")
# Show capabilities if available
if 'modules' in data['entry']:
modules = data['entry']['modules']
print(f" Modules: {len(modules)} available")
for module in modules[:3]: # Show first 3 modules
print(f" - {module.get('id', 'Unknown')}: {module.get('version', 'Unknown')}")
else:
print(f"❌ Raw response failed with status: {raw_response.status}")
except Exception as raw_error:
print(f"❌ Raw response also failed: {raw_error}")
# Example 3: Repository capabilities exploration
print("\n3. Exploring repository capabilities...")
try:
# Try to get capabilities through different approaches
repo_info = client.discovery.get_repository_information()
if repo_info:
print("Repository capabilities exploration:")
# Check for specific features (if available in response)
capabilities = []
# Try to determine available features
try:
if hasattr(repo_info, 'entry'):
entry = repo_info.entry
if hasattr(entry, 'repository'):
print(" ✅ Core repository features available")
capabilities.append("Core Repository")
if hasattr(entry, 'license'):
print(" ✅ License information available")
capabilities.append("License Info")
if hasattr(entry, 'modules'):
print(" ✅ Module information available")
capabilities.append("Module Info")
if hasattr(entry, 'status'):
print(" ✅ Status information available")
capabilities.append("Status Info")
except Exception as cap_error:
print(f" ⚠️ Capability detection failed: {cap_error}")
if capabilities:
print(f" Available capabilities: {', '.join(capabilities)}")
else:
print(" Basic repository information only")
except Exception as e:
print(f"❌ Capabilities exploration failed: {e}")
# Example 4: Connection testing
print("\n4. Testing Discovery API connectivity...")
try:
# Multiple attempts to test the API
attempts = [
("Standard call", lambda: client.discovery.get_repository_information()),
("Raw response", lambda: client.discovery.get_repository_information_without_preload_content())
]
for attempt_name, attempt_func in attempts:
try:
result = attempt_func()
if result:
print(f" ✅ {attempt_name}: Success")
else:
print(f" ⚠️ {attempt_name}: Returned None")
except Exception as attempt_error:
print(f" ❌ {attempt_name}: {attempt_error}")
except Exception as e:
print(f"❌ Connectivity testing failed: {e}")
if __name__ == "__main__":
main()