mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-01 11:52:12 +00:00

* Implement Modern Fluent API Pattern for OpenMetadata Java Client * Add Lineage, Bulk, Search static methods * Add all API support for Java & Python SDKs * Add Python SDKs and mock tests * Add Fluent APIs for sdks * Add Fluent APIs for sdks * Add Fluent APIs for sdks, support async import/export * Remove unnecessary scripts * fix py checkstyle * fix tests with new plural form sdks * Fix tests * remove examples from python sdk * remove examples from python sdk * Fix type check * Fix pyformat check * Fix pyformat check * fix python integration tests * fix pycheck and pytests * fix search api pycheck * fix pycheck * fix pycheck * fix pycheck * Fix test_sdk_integration * Improvements to SDK * Remove SDK coverage for Python 3.9 * Remove SDK coverage for Python 3.9 * Remove SDK coverage for Python 3.9
104 lines
4.0 KiB
Python
104 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Add create methods to remaining service classes."""
|
|
|
|
import os
|
|
import re
|
|
|
|
def add_create_method(filepath, entity, create_class):
|
|
"""Add a create method to a service class."""
|
|
with open(filepath, 'r') as f:
|
|
content = f.read()
|
|
|
|
# Check if method already exists
|
|
if f"public {entity} create({create_class} request)" in content:
|
|
return False
|
|
|
|
# Find the package for the Create class
|
|
packages = {
|
|
"CreateTag": "org.openmetadata.schema.api.classification",
|
|
"CreateClassification": "org.openmetadata.schema.api.classification",
|
|
"CreateStoredProcedure": "org.openmetadata.schema.api.data",
|
|
"CreateContainer": "org.openmetadata.schema.api.data",
|
|
"CreateGlossary": "org.openmetadata.schema.api.data",
|
|
"CreateGlossaryTerm": "org.openmetadata.schema.api.data"
|
|
}
|
|
|
|
package = packages.get(create_class, "org.openmetadata.schema.api.data")
|
|
|
|
# Add import if not present
|
|
import_line = f"import {package}.{create_class};"
|
|
if import_line not in content:
|
|
# Add after the package declaration and existing imports
|
|
lines = content.split('\n')
|
|
import_index = -1
|
|
for i, line in enumerate(lines):
|
|
if line.startswith('import org.openmetadata.'):
|
|
import_index = i
|
|
|
|
if import_index > 0:
|
|
lines.insert(import_index + 1, import_line)
|
|
content = '\n'.join(lines)
|
|
|
|
# Add create method before the closing brace
|
|
create_method = f"""
|
|
// Create {entity.lower()} using {create_class} request
|
|
public {entity} create({create_class} request) throws OpenMetadataException {{
|
|
return httpClient.execute(HttpMethod.POST, basePath, request, {entity}.class);
|
|
}}"""
|
|
|
|
# Find the last closing brace
|
|
last_brace = content.rfind('}')
|
|
if last_brace > 0:
|
|
content = content[:last_brace] + create_method + '\n' + content[last_brace:]
|
|
|
|
# Also add OpenMetadataException import if needed
|
|
if "import org.openmetadata.sdk.exceptions.OpenMetadataException;" not in content:
|
|
lines = content.split('\n')
|
|
for i, line in enumerate(lines):
|
|
if line.startswith('import org.openmetadata.sdk.'):
|
|
lines.insert(i + 1, "import org.openmetadata.sdk.exceptions.OpenMetadataException;")
|
|
content = '\n'.join(lines)
|
|
break
|
|
|
|
# Add HttpMethod import if needed
|
|
if "import org.openmetadata.sdk.network.HttpMethod;" not in content:
|
|
lines = content.split('\n')
|
|
for i, line in enumerate(lines):
|
|
if line.startswith('import org.openmetadata.sdk.network.'):
|
|
lines.insert(i + 1, "import org.openmetadata.sdk.network.HttpMethod;")
|
|
content = '\n'.join(lines)
|
|
break
|
|
|
|
with open(filepath, 'w') as f:
|
|
f.write(content)
|
|
|
|
return True
|
|
|
|
def main():
|
|
services_to_fix = [
|
|
("classification/TagService.java", "Tag", "CreateTag"),
|
|
("classification/ClassificationService.java", "Classification", "CreateClassification"),
|
|
("databases/StoredProcedureService.java", "StoredProcedure", "CreateStoredProcedure"),
|
|
("storages/ContainerService.java", "Container", "CreateContainer"),
|
|
("glossary/GlossaryService.java", "Glossary", "CreateGlossary"),
|
|
("glossary/GlossaryTermService.java", "GlossaryTerm", "CreateGlossaryTerm")
|
|
]
|
|
|
|
services_dir = "openmetadata-sdk/src/main/java/org/openmetadata/sdk/services"
|
|
|
|
fixed_count = 0
|
|
for relative_path, entity, create_class in services_to_fix:
|
|
filepath = os.path.join(services_dir, relative_path)
|
|
if os.path.exists(filepath):
|
|
if add_create_method(filepath, entity, create_class):
|
|
print(f"Added create method to {relative_path}")
|
|
fixed_count += 1
|
|
else:
|
|
print(f"Method already exists in {relative_path}")
|
|
else:
|
|
print(f"File not found: {filepath}")
|
|
|
|
print(f"\nFixed {fixed_count} service files")
|
|
|
|
if __name__ == "__main__":
|
|
main() |