Reversing source and target in specialization relationships

Started by michel.wicky, February 23, 2025, 15:59:42 PM

Previous topic - Next topic

michel.wicky

I would like to reverse relationship endpoints by updating source and target properties in the relationship object. Is it possible ? Is it some restriction ?
Thank you

Phil Beauvoir

If you value and use Archi, please consider making a donation.
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

michel.wicky

Thank you I found it in the meantime and base my script on it. Thank you.

/*
  Script: Update specialization relationships with reversed endpoints
 
  A jArchi script for use on an Archi repository
 
  Purpose: Reverse all selected specialization relationships
  Useful when you want to swap the source and target of these relationships.
 
  Author: Michel Wicky
  Date: 23-Feb-2025
*/

console.clear();
console.log("Update specialization relationships with reversed endpoints");

// Get only specialization-relationship from selected objects
var revCount = 0;
var objList = $(selection).filter('specialization-relationship');

objList.each(function(rel) {
   
    // Get the concept for the object
    var relConcept = concept(rel);

    // Swap the source and target of the relationship
    var oldSource = relConcept.source;
    var oldTarget = relConcept.target;
   
    relConcept.source = oldTarget;
    relConcept.target = oldSource;
   
    // Increment the counter for each reversed relationship
    revCount++;

});

console.log("Num relationships reversed: ", revCount);

// Fonction utilitaire pour récupérer l'objet concept
function concept(o) {
    if(o.concept)
        return o.concept;
    else
        return o;
}