Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - GeordieKiwi

Pages: [1]
1
General Board / Re: Benefits Maps and EA reporting capabilities
« on: July 09, 2016, 10:12:47 am »
Wow thats really cool. I like the wizard for creating the Investment logic diagram and docs

2
Here is some jscript that could be used.

Code: [Select]
!INC Local Scripts.EAConstants-JScript

function TypeConversion(sourceObject,sourceStereotype,targetObject, targetStereotype)
{
    this.sourceObject = sourceObject;
    this.sourceStereotype = sourceStereotype;
    this.targetObject = targetObject;
    this.targetStereotype = targetStereotype;
}

var Conversions = new Array();
// sourceObject,sourceStereotype,targetObject, targetStereotype

//Add one or more Conversion mappings here
Conversions[0] = new TypeConversion("Requirement", "", "Requirement", "extendedRequirement");


// =================================================================================
// Converts elements type and stereotype as defined in the element conversation table.
// Navigates from selected package or element and recursively modifies each element from source to target
// NOTE: Requires a package to be selected in the Project Browser
//
// Related APIs
// =================================================================================
// Element API - http://www.sparxsystems.com/enterprise_architect_user_guide/10/automation_and_scripting/element2.html
// Repository API http://www.sparxsystems.com/enterprise_architect_user_guide/10/automation_and_scripting/repository3.html

/*
 * Project Browser Script main function
 */
function OnProjectBrowserScript()
{
// Get the type of element selected in the Project Browser
var treeSelectedType = Repository.GetTreeSelectedItemType();

// Handling Code: Uncomment any types you wish this script to support
// NOTE: You can toggle comments on multiple lines that are currently
// selected with [CTRL]+[SHIFT]+[C].
switch ( treeSelectedType )
{
case otElement :
{
// Code for when an element is selected
var theElement as EA.Element;
theElement = Repository.GetTreeSelectedObject();
ConvertElements( "", theElement );
break;
}
case otPackage :
{
// Code for when a package is selected
var thePackage as EA.Package;
thePackage = Repository.GetTreeSelectedObject();
NavigatePackage( "", thePackage );

break;
}
// case otDiagram :
// {
// // Code for when a diagram is selected
// var theDiagram as EA.Diagram;
// theDiagram = Repository.GetTreeSelectedObject();
//
// break;
// }
// case otAttribute :
// {
// // Code for when an attribute is selected
// var theAttribute as EA.Attribute;
// theAttribute = Repository.GetTreeSelectedObject();
//
// break;
// }
// case otMethod :
// {
// // Code for when a method is selected
// var theMethod as EA.Method;
// theMethod = Repository.GetTreeSelectedObject();
//
// break;
// }
default:
{
// Error message
        Session.Prompt( "This script requires a package to be selected in the Project Browser.\n" +
            "Please select a package or element in the Project Browser and try again.", promptOK );
}
}
}

//
// Outputs the packages name and elements, and then recursively processes any child
// packages
//
// Parameters:
// - indent A string representing the current level of indentation
// - thePackage The package object to be processed
//
function NavigatePackage( indent, thePackage )
{
    // Cast thePackage to EA.Package so we get intellisense
    var currentPackage as EA.Package;
    currentPackage = thePackage;
   
    // Add the current package's name to the list
    Session.Output( indent + currentPackage.Name + " (PackageID=" +
        currentPackage.PackageID + ")" );
   
    // Convert the elements this package contains
    ConvertElementsInPackage( indent + "    ", currentPackage );
   
    // Recursively process any child packages
    var childPackageEnumerator = new Enumerator( currentPackage.Packages );
    while ( !childPackageEnumerator.atEnd() )
    {
        var childPackage as EA.Package;
        childPackage = childPackageEnumerator.item();
        NavigatePackage( indent + "    ", childPackage );
       
        childPackageEnumerator.moveNext();
    }
}

//
// Converts the elements of the provided package to the Script output window
//
// Parameters:
// - indent A string representing the current level of indentation
// - thePackage The package object to be processed
//
function ConvertElementsInPackage( indent, thePackage )
{
    // Cast thePackage to EA.Package so we get intellisense
    var currentPackage as EA.Package;
    currentPackage = thePackage;
   
    // Iterate through all elements and add them to the list
    var elementEnumerator = new Enumerator( currentPackage.Elements );
    while ( !elementEnumerator.atEnd() )
    {
        var currentElement as EA.Element;
        currentElement = elementEnumerator.item();
        ConvertElements(indent+"    ",currentElement );

        elementEnumerator.moveNext();
    }
}

function ConvertElements( indent, theElement )
{
    // Cast theElement to EA.Element so we get intellisense
    var currentElement as EA.Element;
    currentElement = theElement;
    currentElement.ObjectType
    ConvertElement(indent+"    ",currentElement );
    // Iterate through all embedded elements and add them to the list
    var elementEnumerator = new Enumerator( currentElement.Elements );
    while ( !elementEnumerator.atEnd() )
    {
        var currentElement as EA.Element;
        currentElement = elementEnumerator.item();
        ConvertElements(indent+"    ",currentElement );
        elementEnumerator.moveNext();
    }
}

// Converts the element from source to target mappings from conversions array
//
// Parameters:
// - indent A string representing the current level of indentation
// - theElement The element object to be processed
function ConvertElement( indent, theElement )
{
// Debug Comment out when run for real
    //Session.Output( indent + "CALLED: ConvertElement with " + theElement.Name + " [" + theElement.Type + ", " + theElement.Stereotype + " )" );

    for ( var i = 0 ; i < Conversions.length ; i++ )
    {
        // If stereotype matches source list then convert
        if ( (theElement.Stereotype == Conversions[i].sourceStereotype) && (theElement.Type == Conversions[i].sourceObject ))
        {
            Session.Output( indent + "CONVERTED: " + theElement.Name + " (" + theElement.Type + ", " + theElement.Stereotype + ")" + "=>" +"("+Conversions[i].targetObject+","+Conversions[i].targetStereotype+")" );
            theElement.Type = Conversions[i].targetObject;
            //Over write the stereotype list to have only one stereotype
            theElement.StereotypeEx = Conversions[i].targetStereotype;
            theElement.Update();
            break; // once found cease iterating through for-loop.
        }
    }
}

OnProjectBrowserScript();

Good timing Sunshine, was just about to do a similar exercise of changing stereotypes.

3
Thanks Sunshine. That code worked  a treat.

4
General Board / Re: Enterprise Integration Patterns
« on: May 18, 2016, 08:22:31 pm »
Thanks Sunshine, really useful mdg for integration pattern

Pages: [1]