jarchi: how to select object at the far end of a relationship?

Started by TimHale, May 09, 2019, 22:26:32 PM

Previous topic - Next topic

TimHale

I'm having difficulty selecting the object at the far end of a relationship.

I have one or more objects from $(selection).
I'm iterating through the selection objects with a for loop, setting var thisObject = $(selection).get(i);
then I'm iterating through each object's connections with a for loop, setting var thisConnection = $(thisObject).rels().get(j);

Once I have a connection instance, how can I select thisConnection.sourceEnds() or thisConnection.targetEnds(), so that I can retrieve some attributes found there?

If I'm understanding the Archi metamodel correctly, sourceEnds/targetEnds work with the base relationship concepts, not with the connection instance on the view.

Thanks
Tim

Phil Beauvoir

Depends on the selection.

If the selection is from the Model Tree then rels() will return Relationship concepts. And with a Relationship you can get the single source and target at the end of the relationship:

var relationship = $(thisObject).rels().get(j);
var source = relationship.source;
var target= relationship.target;

And all other methods on a concept.

But if the selection is on a View you will get visual connections and objects. You can use the same .source and .target methods but you'll need to get the underlying concept with .concept.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

TimHale

this is how I solved it.  Is this what you were describing?

function findConnectionEndObject(thisConnection, position) { // connection is a connection object; position is one of "source" or "target"
   var returnVal = {
      success: false,
      object:     ""
   }
   
   // select the desired connection end in the model tree
   if (position == "source") {
      var testObjectConns = $(thisConnection.concept.source);
   }
   else {
      var testObjectConns = $(thisConnection.concept.target);
   }
   
   // get the count of visual instances the target object has in the entire model
   var countTestObjects = testObjectConns.objectRefs().size();

   for (m = 0; m < countTestObjects; m++) {
   
      var testObject = testObjectConns.objectRefs().get(m);
      
      // get count of visual connections this visual object has in the entire model
      var countConnections = $(testObject).rels().size();
      
      for (n = 0; n < countConnections; n ++) {

         var testConnection = $(testObject).rels().get(n);
         
         // when we match connection id's, we've found the right visual instance on the right view
         if (testConnection.id == thisConnection.id) {
            returnVal.result = true;
            returnVal.object = testObject;
            m = n = Number.MAX_VALUE; // blast the loop variables
         }
      }
   }
   return returnVal;
}

Phil Beauvoir

If your aim is to just find the source or target model concept at the end of a connection on a view you can get these easily with:

sourceConcept = thisConnection.concept.source;

and

targetConcept = thisConnection.concept.target;

Don't understand what the rest of the function is doing?
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

TimHale

Sigh.
I missed the obvious answer.  I am doing some exploration in terms of moving objects and manipulating bendpoints.   
Based on earlier issues trying to select connections by id, I made an erroneous assumption that I couldn't select the connection target by id either.

Oh well,  I guess I just took the scenic route this weekend.  I learned some other aspects of working with jArchi along the way.

Thanks!