Source code for aac.plugins.exclusive_fields.exclusive_fields_impl
"""The AaC Exclusive fields 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="Exclusive Fields"
[docs]defmutually_exclusive_fields(instance:Any,definition:Definition,defining_schema,fields:list[str])->ExecutionResult:"""Business logic for the Mutually exclusive fields constraint."""num_present=0forfieldinfields:instance_fields=vars(instance)iffieldininstance_fields:field_value=getattr(instance,field)iffield_valueisNone:# handle primitives and schema defined typescontinueelif(isinstance(field_value,list)andlen(field_value)==0):# handle listscontinueelif(isinstance(field_value,dict)andlen(field_value)==0):# this is for the any typecontinueelse:num_present+=1# we found a real instance, so count itifnum_present==0:error_msg=ExecutionMessage(f"None of the following fields were present: {fields}",MessageLevel.ERROR,"No file to reference"ifnotdefinition.sourceordefinition.source.uri=="<string>"elsedefinition.source.uri,None,)returnExecutionResult(plugin_name,"Mutually exclusive fields",ExecutionStatus.GENERAL_FAILURE,[error_msg],)ifnum_present>1:error_msg=ExecutionMessage(f"More than one of the following fields were present: {fields}",MessageLevel.ERROR,"No file to reference"ifnotdefinition.sourceordefinition.source.uri=="<string>"elsedefinition.source.uri,None,)returnExecutionResult(plugin_name,"Mutually exclusive fields",ExecutionStatus.GENERAL_FAILURE,[error_msg],)returnExecutionResult(plugin_name,"Mutually exclusive fields",ExecutionStatus.SUCCESS,[])