Home / Model Expert Help / Validation rules / Validation Scripting Examples
Validation Scripting Examples
Example Scripts
Note: all scripts are examples only, and are supplied on an ‘as-is’ basis. You must check that they meet your requirements, and are functioning correctly.
Internal Use Case checks
This example script checks the details of a single use case.
!INC Local Scripts.EAConstants-VBScript
‘ ‘ Script Name: Use_Case ‘ Author: Ian Mitchell ‘ Purpose: Checks the details of a single Use Case: ‘- are there any scenarios (severity 4) ‘- only a basic path scenario (3) ‘- checks if Internal Requirements are used: if so, severity = 3 ‘ Date: 18/01/2016 ‘ function Use_Case ‘************* Required so that eaDocX knows which element type / stereotype this is used for ‘<Type>UseCase</Type> ‘All stereotypes ‘**************** ‘ Parameters which are passed to the script are: ‘ ElementID ‘find the element dim e as EA.Element set e = Repository.GetElementByID(ElementID.toString) ‘now do the checks dim outputHTML ‘ a string which will contain the results from the script outputHTML = “<results>” ‘look in more detail at the insides of the Use Case if e.Scenarios.count =0 then outputHTML = outputHTML & “<violation note=’Missing scenarios for use case’ severity=’4′ />” end if
if e.Scenarios.count =1 then dim aScenario as EA.Scenario set aScenario = e.Scenarios.GetAt(0) if aScenario.Type = “Basic Path” then outputHTML = outputHTML & “<violation note=’Only basic path scenarios for use case’ severity=’3′ />” end if end if if e.Requirements.count > 0 then outputHTML = outputHTML & “<violation note=’Use Case has Internal Requirements’ severity=’3′ />” end if outputHTML = outputHTML & “</results>” ‘put the HTML string into the return Use_Case = outputHTML end function Use_Case |
Connections of an Element
This example script checks that the right Dependency links exist, with one of 4 stereotypes – Responsible, Accountable, Consulted, Informed – <<High Level>> Requirements and Stakeholders.
!INC Local Scripts.EAConstants–VBScript
‘ ‘ Script Name: APITest ‘ Author: Ian Mitchell ‘ Purpose: Checks connections of a <<High Level>Requirement ‘ Date: 16/12/2013 ‘ function HighLevel_Requirement ‘************* Required so that eaDocX knows which element type / stereotype this is used for ‘<Type>Requirement</Type> ‘<Stereotype>High Level</Stereotype> ‘**************** ‘ Parameters which are passed to the script are: ‘ ElementID ‘find the element dim e as EA.Element set e = Repository.GetElementByID(ElementID.toString) ‘now do the checks dim outputHTML ‘ a string which will contain the results from the script outputHTML = “<results>”
‘check if it has RACI links ‘deliberately no check for ‘Informed’ dim foundAccountable, foundResponsible, foundConsulted foundAccountable = false foundResponsible = false foundConsulted = false
dim c as EA.Connector for each c in e.connectors if c.Type = “Dependency” and c.Stereotype = “Accountable” then foundAccountable = true end if if c.Type = “Dependency” and c.Stereotype = “Responsible” then foundResponsible = true end if if c.Type = “Dependency” and c.Stereotype = “Consulted” then foundConsulted = true end if
next
if not foundAccountable then outputHTML = outputHTML & “<violation note=’No Accountable person’ severity=’5′ />” end if if not foundResponsible then outputHTML = outputHTML & “<violation note=’No Responsible person’ severity=’5′ />” end if ‘if nobody is consulted, this isn’t really an error, just something to think about if not foundConsulted then outputHTML = outputHTML & “<violation note=’No Consulted person’ severity=’1′ />” end if ‘deliberately no check for ‘Informed’
outputHTML = outputHTML & “</results>” ‘put the HTML string into the return HighLevel_Requirement = outputHTML end function HighLevel_Requirement |
Checking <<Functional>> Requirements
This example script checks for two things:
- Do the notes for any <<Functional>>Requirement contains a specific word (“Wibble”)
- Are there any <<Functional>>Requirements which have a status of ‘Approved’, and a phase of ‘2.0’
!INC Local Scripts.EAConstants–VBScript
‘ ‘ Script Name: Functional_Requirement ‘ Author: Ian Mitchell ‘ Purpose: Checks the details of a single functional Requirement ‘ ‘ Date: 22/06/2016 ‘ function Functional_Requirement ‘************* Required so that eaDocX knows which element type / stereotype this is used for ‘<Type>Requirement</Type> ‘<Stereotype>Functional</Stereotype> ‘All stereotypes ‘****************
‘ Parameters which are passed to the script are: ‘ ElementID ‘find the element dim e as EA.Element set e = Repository.GetElementByID(ElementID.toString)
‘now do the checks
dim outputHTML ‘ a string which will contain the results from the script outputHTML = “<results>”
‘1. Does the notes field contain the string ‘Wibble’ ? if instr(e.notes,“Wibble”) <> 0 then outputHTML = outputHTML & “<violation note=’Contains reference to Wibbles’Â severity=’3′ />” end if
‘2. Are there any Phase 2.0 + ‘Approved’ Requirements ? if e.phase = “2.0” then if e.Status = “Approved” then outputHTML = outputHTML & “<violation note=’Approved phase 2.0 requirement in 1.0 package’ severity=’10’ />” end if end if
outputHTML = outputHTML & “</results>”
‘put the HTML string into the return Functional_Requirement = outputHTML end function ‘not sure why this next line is needed, but it won’t work otherwise! Functional_Requirement |
Import / Export of Validation Scripts
Export
To export your Model Expert validation scripts (EA v15):
- EA Ribbon > Configure / Transfer / Export Reference data
- Select ‘Automation Scripts’:
- Choose a file name
Import
To import Model Expert validation scripts:
- EA Ribbon > Configure / Transfer / Import Reference data
- Choose the file saved above
- Choose to import the Automation Scripts:
- Import.