Book a Demo

Author Topic: Mass Update of Components  (Read 15003 times)

stu_cox

  • EA Novice
  • *
  • Posts: 4
  • Karma: +1/-0
    • View Profile
Mass Update of Components
« on: April 20, 2016, 10:50:14 pm »
Good Afternoon,

My company and I are in the process of configuring Sparx for our use, and as a result, decisions we have made in the past now need to be altered. We have many components set to be of type "component" with no stereotype. We would like to align to the TOGAF extension stereotype and mass update the necessary components to be of stereotype "applicationcomponent" together with the additional tag values that this stereotype holds.

Naturally, we can go through each component in turn changing the type but this would not be a constructive use of time. Is there any way to mass do this? i.e. select a group of components (either in browser or on a diagram) and alter all their stereotypes? I can update the component within the database (t_object) but the messy side is the creation of the new tagged values holder in t_objectproperties, as well as the assurance that everything else that is required to be updated has been updated.

I've searched the forums and cannot find an answer to this.

Thanks in anticipation,

Stuart

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Mass Update of Components
« Reply #1 on: April 20, 2016, 10:56:00 pm »
That would be quite easy with a script. Just select all elements in question with a query (finding the stereotyped ones) and then applying the new stereotype to them.

q.

ChB

  • EA User
  • **
  • Posts: 40
  • Karma: +4/-0
    • View Profile
Re: Mass Update of Components
« Reply #2 on: April 20, 2016, 11:09:48 pm »
Have you considered these steps:
  • a CSV export
  • manual edit (search and replace) in the CSV file
  • a CSV import
  • finally right click on the element type in the toolbox and select "Synchronise Stereotype"

Of course make sure you've got a backup first!

I've used the above recipe for a mass update of a different type of element.  Does it work for your components?  I'm not sure if you have a Synchronise Stereotype option for Components.

stu_cox

  • EA Novice
  • *
  • Posts: 4
  • Karma: +1/-0
    • View Profile
Re: Mass Update of Components
« Reply #3 on: April 20, 2016, 11:20:40 pm »
Much appreciated - I'll investigate both these options; are there any pointers on the scripting side?

ChB

  • EA User
  • **
  • Posts: 40
  • Karma: +4/-0
    • View Profile
Re: Mass Update of Components
« Reply #4 on: April 20, 2016, 11:44:19 pm »
See here for my thread on using export/import for a similar bulk change:
http://sparxsystems.com/forums/smf/index.php/topic,30458.0.html

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Mass Update of Components
« Reply #5 on: April 21, 2016, 12:45:25 am »

stu_cox

  • EA Novice
  • *
  • Posts: 4
  • Karma: +1/-0
    • View Profile
Re: Mass Update of Components
« Reply #6 on: April 21, 2016, 12:57:41 am »
Thanks to both of you - I'm sure I can do what I need now with this additional information. Very much appreciated.

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1353
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: Mass Update of Components
« Reply #7 on: April 21, 2016, 08:03:38 pm »
Alternatively here is some JScript Code I've used in the past to convert archimate requirements. Just modify the array at the top to change source object type and stereotype to target object type and stereotype.

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, targetStereotypea
//Add Array of conversions here
Conversions[0] = new TypeConversion("Class", "ArchiMate_Requirement", "Class", "Requirement");

// =================================================================================
// Name: Element Conversion
// Converts elements type and stereotype as defined in the element conversation table.
// The table is included as a file so it may be changed for other mappings
// Navigates from selected package and recursively modifies each element
// 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
// Tagged Value API http://www.sparxsystems.com/enterprise_architect_user_guide/10/automation_and_scripting/taggedvalue.html

function StartWithSelectedPackage()
{
    // Show the script output window
    Repository.EnsureOutputVisible( "Script" );

    Session.Output( "JScript TypeConverstion" );
    Session.Output( "===========================" );

    var thePackage as EA.Package;
    thePackage = Repository.GetTreeSelectedPackage();
   
    if ( thePackage != null && thePackage.ParentID != 0 )
    {
        NavigatePackage( "", thePackage );
    }
    else
    {
        Session.Prompt( "This script requires a package to be selected in the Project Browser.\n" +
            "Please select a package in the Project Browser and try again.", promptOK );
    }
   
    Session.Output( "Done!" );
}

//
// 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();
    }
}

//
// 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;
            theElement.StereotypeEx = Conversions[i].targetStereotype;
            theElement.Update();
            break; // once found cease iterating through for-loop.
        }
    }
}

StartWithSelectedPackage();
« Last Edit: April 27, 2016, 10:40:28 am by Sunshine »
Happy to help
:)