Source code for aac.plugins.if_true_then_empty.if_true_then_empty_impl
"""The AaC If true then empty plugin implementation module."""# NOTE: It is safe to edit this file.# This file is only initially generated by aac gen-plugin, and it won't be overwritten if the file already exists.# There may be some unused imports depending on the definition of the plugin...but that's okfromaac.execute.aac_execution_resultimport(ExecutionResult,ExecutionStatus,ExecutionMessage,MessageLevel,)fromaac.context.definitionimportDefinitionfromtypingimportAnyplugin_name="If true then empty"
[docs]defif_true_then_empty(instance:Any,definition:Definition,defining_schema,bool_field_name:str,empty_field_name:str,)->ExecutionResult:"""Business logic for the If true then empty constraint."""bool_field_value=getattr(instance,bool_field_name,None)ifnotisinstance(bool_field_value,bool):# the constraint failederror_msg=ExecutionMessage(f"The If true then empty constraint for {instance.name} failed because {bool_field_name} is not a boolean. Received {bool_field_value}.",MessageLevel.ERROR,"No file to reference"ifnotdefinition.sourceordefinition.source.uri=="<string>"elsedefinition.source.uri,None,)returnExecutionResult(plugin_name,"If true then empty",ExecutionStatus.GENERAL_FAILURE,[error_msg],)empty_field_value=getattr(instance,empty_field_name,None)is_empty_field_empty=(empty_field_valueisNoneorempty_field_value==""orempty_field_value==[]orempty_field_value=={})ifbool_field_valueandnotis_empty_field_empty:# the constraint failederror_msg=ExecutionMessage(f"The If true then empty constraint for {instance.name} failed because {bool_field_name} is true and {empty_field_name} is not empty.",MessageLevel.ERROR,"No file to reference"ifnotdefinition.sourceordefinition.source.uri=="<string>"elsedefinition.source.uri,None,)returnExecutionResult(plugin_name,"If true then empty",ExecutionStatus.GENERAL_FAILURE,[error_msg],)# the constraint passedreturnExecutionResult(plugin_name,"If true then empty",ExecutionStatus.SUCCESS,[])