Merge pull request #4 from bjoernsteinhagen/bjorn/proper-next-gen-validation
style: checking for next-gen more stable
This commit is contained in:
@@ -39,12 +39,23 @@ def automate_function(
|
||||
commit_root = automate_context.speckle_client.commit.get(
|
||||
automate_context.automation_run_data.project_id, version_id
|
||||
)
|
||||
model_root = automate_context.receive_version()
|
||||
|
||||
# Validate source application
|
||||
source_validator = RevitSourceValidator() # Built for revit, therefore check
|
||||
if not source_validator.validate(commit_root.sourceApplication):
|
||||
if not source_validator.validate_source_application(
|
||||
commit_root.sourceApplication
|
||||
):
|
||||
automate_context.mark_run_failed(
|
||||
f"Automation requires Revit v3 commits. Received: {commit_root.sourceApplication}"
|
||||
f"Automation requires models from Revit. Received: {commit_root.sourceApplication}"
|
||||
)
|
||||
return
|
||||
if not source_validator.validate_connector_version(
|
||||
int(getattr(model_root, "version", 2))
|
||||
):
|
||||
automate_context.mark_run_failed(
|
||||
"Automation required Revit models using the v3 "
|
||||
"connector. Received: v2."
|
||||
)
|
||||
return
|
||||
|
||||
@@ -52,7 +63,6 @@ def automate_function(
|
||||
processor = configure_components()
|
||||
|
||||
# Process model
|
||||
model_root = automate_context.receive_version() # TODO: Line 35 and 36!?
|
||||
processor.process_elements(model_root)
|
||||
|
||||
# Logger information - successes
|
||||
|
||||
@@ -8,5 +8,11 @@ class RevitSourceValidator(SourceApplicationValidator):
|
||||
# ℹ️ sourceApplication value for v3: slug => revit
|
||||
# ⚠️ We're just working with v3 data - adapt commit_processor for v2 data structure if you want
|
||||
# ⚠️ Alternatively, write a model factory that injects the correct CommitProcessor()
|
||||
def validate(self, source_app: str) -> bool:
|
||||
return source_app == "revit"
|
||||
def validate_source_application(self, source_app: str) -> bool:
|
||||
return source_app.lower().startswith("revit")
|
||||
|
||||
def validate_connector_version(self, connector_version: int) -> bool:
|
||||
if connector_version == 2:
|
||||
return False # TODO: If you want to support v2, implement a factory method
|
||||
elif connector_version == 3:
|
||||
return True
|
||||
|
||||
@@ -5,14 +5,13 @@ class SourceApplicationValidator(ABC):
|
||||
"""Interface for source application validator.
|
||||
Host app should be supported by the automation.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def validate(self, source_app: str) -> bool:
|
||||
"""Assert that the source application is supported.
|
||||
|
||||
Args:
|
||||
source_app (str): sourceApplication from the commit root
|
||||
|
||||
Returns:
|
||||
bool: True if supported, False if not
|
||||
"""
|
||||
def validate_source_application(self, source_app: str) -> bool:
|
||||
"""Assert that the source application is supported."""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def validate_connector_version(self, connector_version: str) -> bool:
|
||||
"""Assert that the connector version is supported."""
|
||||
pass
|
||||
|
||||
@@ -59,19 +59,25 @@ def create_processor_chain() -> tuple[RevitModel, RevitLogger]:
|
||||
try:
|
||||
# Get version data
|
||||
commit_root = branch.commits.items[0]
|
||||
model_root = model_data
|
||||
|
||||
# Validate source application
|
||||
source_validator = RevitSourceValidator()
|
||||
if not source_validator.validate(commit_root.sourceApplication):
|
||||
if not source_validator.validate_source_application(commit_root.sourceApplication):
|
||||
print(
|
||||
f"Automation requires Revit v3 commits. Received: {commit_root.sourceApplication}"
|
||||
)
|
||||
if not source_validator.validate_connector_version(
|
||||
int(getattr(model_root, "version", 2))
|
||||
):
|
||||
print(
|
||||
"Automation required Revit models using the v3 " "connector. Received: v2."
|
||||
)
|
||||
|
||||
# Create processor chain and get logger for results
|
||||
processor, logger = create_processor_chain()
|
||||
|
||||
# Process model
|
||||
model_root = model_data
|
||||
processor.process_elements(model_root)
|
||||
|
||||
# Report compliance issues
|
||||
|
||||
Reference in New Issue
Block a user