Metachain Navigation Filters Duplicates Values

Diagramming issues

Moderator: Moderators

Metachain Navigation Filters Duplicates Values

Postby austin.gage@gmail.com » Wed Jul 18, 2018 5:46 pm

I have a generic table with a derived property using a metachain navigation. The navigation gets multiple objects and then a value of a property as shown below:
metachain.png


The only issue is that is any of the values are the same, it only returns the unique values.
missing value.PNG


Is there any way to keep all the values? Is there a better way to accomplish this?

I am trying to work around the fact that the FMEA plugin allows multiple causes and an occurrence per cause but then only displays a single occurrence value in the OCC column!
You do not have the required permissions to view the files attached to this post.
austin.gage@gmail.com
Forum Newbie
Forum Newbie
 
Posts: 18
Posts Rating:0
Joined: Thu Oct 05, 2017 6:03 pm

Re: Metachain Navigation Filters Duplicates Values

Postby osvaldas.jankauskas@nomagic.com » Wed Jul 25, 2018 8:03 am

Hello,

Thank you for your question.

After creating the expression, a set of elements are returned by default. A set cannot contain the unique values. As a result of this, only the non-unique values are shown.

To achieve your need, you have to create ArrayList. This requires to script.

I've attached the example project how this can be achieved by using JavaScript:

1. Define ArrayList variable "var X = new java.util.ArrayList();"
2. Add all tag values to it "X.addAll(assetValue);
3. Return variable "X".

To return array list instead of set, you need to declare that derivedProperty is non-unique. To do this, set "Is Unique" property of derivedProperty to false.

Look at the attached project for more details.

Array List example.mdzip


If you have any other questions or concerns - feel free to contact us.

Best regards,
No Magic, Inc. Customer Support
You do not have the required permissions to view the files attached to this post.
osvaldas.jankauskas@nomagic.com
Customer Support
Customer Support
 
Posts: 127
Posts Rating:16
Joined: Mon Apr 20, 2015 10:01 am

Re: Metachain Navigation Filters Duplicates Values

Postby kevin.debruin@aero.org » Mon Feb 11, 2019 5:14 pm

Hi,

I am attempting to achieve this result (or something like this) in my generic table. Where do I put this script? In the attached file "Array List example" I do not see a custom column to which a script was placed inside.

For my specific project I have attached a picture. It shows part of my generic table. I have a Requirement that is Verified By different activities. Each of those activities has a Method, but the table will only show what Methods are used, but not which Method is used for which activity. Is is possible to have the method aligned with the appropriate activity? To have the Method column have 4 entries like: Test Inspection Test Test

Best,
-Kevin
You do not have the required permissions to view the files attached to this post.
kevin.debruin@aero.org
Forum Newbie
Forum Newbie
 
Posts: 2
Posts Rating:0
Joined: Fri Oct 26, 2018 3:12 pm

Re: Metachain Navigation Filters Duplicates Values

Postby armando.hysko@ngc.com » Thu Feb 21, 2019 9:31 am

kevin.debruin@aero.org wrote:Hi,

I am attempting to achieve this result (or something like this) in my generic table. Where do I put this script? In the attached file "Array List example" I do not see a custom column to which a script was placed inside.

For my specific project I have attached a picture. It shows part of my generic table. I have a Requirement that is Verified By different activities. Each of those activities has a Method, but the table will only show what Methods are used, but not which Method is used for which activity. Is is possible to have the method aligned with the appropriate activity? To have the Method column have 4 entries like: Test Inspection Test Test

Best,
-Kevin


Hi Kevin
Any luck on figuring this out? I have been having the same problem and for the life of me I can't figure it out.
Thanks Armando
armando.hysko@ngc.com
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:0
Joined: Tue Feb 19, 2019 7:59 pm

Re: Metachain Navigation Filters Duplicates Values

Postby kevin.debruin@aero.org » Thu Feb 21, 2019 12:12 pm

No sorry, still hoping to figure it out.
-Kevin
kevin.debruin@aero.org
Forum Newbie
Forum Newbie
 
Posts: 2
Posts Rating:0
Joined: Fri Oct 26, 2018 3:12 pm

Re: Metachain Navigation Filters Duplicates Values

Postby marcus.schwenk@philips.com » Thu Apr 16, 2020 7:49 am

Hello,

this seems to be a common question - i am also struggling with this for a while now.
Update welcom!
Marcus
marcus.schwenk@philips.com
Forum Newbie
Forum Newbie
 
Posts: 2
Posts Rating:0
Joined: Tue Oct 09, 2018 1:27 am

Re: Metachain Navigation Filters Duplicates Values

Postby tiffany.hayes@avionsolutions.com » Thu Oct 08, 2020 2:16 pm

This is a SUPER old conversation, but since there have been a couple people who have posted on this thread over the last couple years wanting an answer I figured I would give my solution. (I have attached a .mdzip file for your perusal)

The short answer is that, as far as I'm aware currently, MagicDraw can't do this on its own. Fields in the specification like "Is Unique" or "Is Ordered" don't seem to actually do anything in this context.

Instead, we have to do a bit of programming in order for this to work the way we want. I used JavaScript personally, but I'm sure you could use any other programming language. Just going to say right now, you will need to be in "Expert Mode" in order to do the things I'll be talking about.

First things first, the normal "Generic Table" will not be enough for what we need to do. Generic tables have no means of removing themselves from MagicDraw's internal XML and therefore will always have this problem. Instead, we have to use "Metric Tables" and to be able to use those, we have to create a new Metric. Rather than go through those steps here, No Magic has a step by step guide for that process in their documentation. Here is the link:
https://docs.nomagic.com/display/MD184/Creating+Metric+Suites
Make sure to go through the "Related Pages" as well to actually follow the process of setting it up.

Once you get to "Building Metric Definitions", stop at Step 10.

tutorialStop.jpg

Okay, with your metric set up here is the important thing. DON'T USE A STRUCTURED EXPRESSION!

No_Structured_Expression.jpg

For whatever reason, by using a structured expression, the resultant output will ALWAYS be an unordered set rather than an ordered list. So instead, we need to do everything manually. I have a couple code blocks that can be very helpful for you to use though!

Selecting "JavaScript" as the language, our first task is to access an element of the model - any element. Luckily, the variable "THIS" is already defined at the metric definition we're working with.

THIS.jpg

So with this element in hand we're diving into our first bit of code. Since that element is named "THIS" we can construct a recursive function that will take us all the way up to the top level package.
Code: Select all
function getTopOwner(element) {
  if (element.getOwner() == null) {
    return(element);
  } else {
    return(getTopOwner(element.getOwner()));
  };
};

And thus, to get the top level package, we can declare a new variable as the output of this function.
Code: Select all
model = getTopOwner(THIS);    // This will give us the top level package element


Basically, the function has a central conditional. If the owner of a given element exists, then it can't be the top level. So we recursively call that owner and try again. And once we find it, that is what gets returned. (More info on JavaScript recursion here: https://javascript.info/recursion).

With this, we now have our scope (which we got manually in JavaScript). What can we do with it? Well at this point I can really only give an example since there are a lot of things one could do. Since I do not know what stereotypes Austin Gage may have been using, I'll use Kevin Debruin's example (or at least something close to it). So we want to collect all of the extended requirements and then place each verification method next to its respective requirement.

At this point, I will need to confess that I'm not actually a programmer - I just play one on television. So my code for grabbing all of the requirements is a bit spaghetti. Regardless, it works and does what I want it to. This is another recursive function that will scour through EVERY package and element to find each requirement.

Code: Select all
// We will need to use the No Magic Stereotype Helper for this function. Documentation at:
// https://docs.nomagic.com/display/MD190/Using+StereotypesHelper
var help = com.nomagic.uml2.ext.jmi.helpers.StereotypesHelper;

/* The second recursive function takes in a model element and looks through all
of the packages to find every requirement within. This can take a fair bit of time
so feel free to optimize this solution.     

One other thing to note, is that I was unable to determine a method of recursion
for this function using only local variables. Thus I have declared a global variable
reqResult that will store the requirements as they are found. The function itself
returns a null value - the array "reqResult" will be the variable you need to call
in order to use the results of the function. */

var reqResult = new java.util.ArrayList();
function findRequirements(element){
  var nestedArray = new java.util.ArrayList();
  nest = element.getOwnedElement();
  // I need the elements in an array to work with.  This will allow the structure
  // to remain ordered and non-unique. Iterate through them to do this.
  iter = nest.iterator();
  while (iter.hasNext()) {
    nestedArray.add(iter.next());
  };
  // With this new array list, we loop through the items and perform our recursion
  for (e in nestedArray) {
    // declare a variable here just for ease of use
    term = nestedArray[e];
    ////////////////////////////////////////////////////////
    // This is the conditional statement that dictates what the
    // search function is looking for
    if (help.hasStereotypeOrDerived(term, "extendedRequirement")) {
      reqResult.add(term);
    };
    ////////////////////////////////////////////////////////
    // Perform recursion if the element has owned elements
    if (term.hasOwnedElement()){
      findRequirements(term);
    };
  };

  /* Once ALL model elements have been searched, the function ends. Recall that
  the function returns "null" and you need to call "reqResult" to actually
  use the information pulled from this function. */

  return(null);
};


This code is a bit more complicated, but basically it takes a top level package (the one we just got from the previous recursive function) and recursively checks every element for the particular type of element we want (in this case, an extendedRequirement).

With these requirements now gotten, we can do one final bit of scripting to pull out the verification method. Keep in mind that the StereotypesHelper returns sets and not individual elements.

Code: Select all
/* we will declare a reflexive array that will store
element information (i.e. the Id number) while I'm working on it. */ 
// 0 -> Requirement itself; 1 -> Requirement ID Number
var ReqArg = java.lang.reflect.Array.newInstance(java.lang.Object.class, 2);

/* we will also declare a new variable that will store the results of
our search in an ordered and non-unique form */
var result = new java.util.ArrayList();

// Running the two functions from above
model = getTopOwner(THIS);
findRequirements(model);
 
  /* And now we can iterate through the requirements and pull the information */
  for (i in reqResult) {
    // Store current requirement in local memory
    ReqArg[0] = reqResult[i];
    // Store requirement ID in local memory
    ReqArg[1] = help.getStereotypePropertyValue(ReqArg[0], "extendedRequirement", "verifyMethod");
    // Ensure the method actually has a value
    if (ReqArg[1].isEmpty()){
      // if there was no method, just set the value to be null rather than a null set
      ReqArg[1] = "";
    } else {
      // if there WAS a method, set the argument to the method and not a set containing the method
      ReqArg[1] = ReqArg[1][0];
    };
  // And now we add these to our resultant array of values (THIS ONE TAKES THE ENUMERATION LITERALS)
  result.add(ReqArg[1]);
  };
result;


The index in the third to last line lets you choose between selecting the Verification Method or the Requirement itself. There is a bit of copy and paste that needs to happen between your metrics, but by just swapping out that one term you can get the rows of your table to line up. And thus you would get something like this:

tableExample.jpg


Please feel free to ask any questions about this. I know that this is basically creating your own plugin from scratch. However, it has been the only solution I've found so far that works.
You do not have the required permissions to view the files attached to this post.
tiffany.hayes@avionsolutions.com
Forum Newbie
Forum Newbie
 
Posts: 15
Posts Rating:4
Joined: Fri Oct 02, 2020 1:11 pm

Re: Metachain Navigation Filters Duplicates Values

Postby si.laskailey721@gmail.com » Fri May 07, 2021 10:33 pm

I am very impressed with your post. I hope to receive more great posts.





ToysRUs Credit Card
si.laskailey721@gmail.com
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:0
Joined: Fri May 07, 2021 10:32 pm


Return to Diagramming

Who is online

Users browsing this forum: No registered users and 0 guests