Enterprise Architect scripting with java - activitydiagram entry point initial - scripting

I want to generate an activity-diagram with my java code.
it work's to create an actionelement:
//Add the actionElement to the package
Element actionElement = elements.AddNew("MyFirstAction", "Action");
elements.Refresh();
//Add the element to the activity diagram
DiagramObject dob = dobs.AddNew("", "");
dobs.Refresh();
//reference the DiagramObject to the before created element
dob.SetElementID(element.GetElementID());
dob.Update();
dobs.Refresh();
So I thought it will work's for the Initial (or EntryPoint) in the same way:
Element initElement = elements.AddNew("Start...","EntryPoint");
But the following Exception appears:
java.lang.Exception: Invalid parent for EntryPoint (Package)
Somebody can help me? My othe question is, if there is any Enumeration for the ElementTypes of the Collection?
Because I only found the following information of the collection class..
AddNew (string Name, string Type)
But the information of the Type tells only "Type: String (up to 30 characters long)".
Here is a link to the Collection Class:
http://www.sparxsystems.com/enterprise_architect_user_guide/9.2/automation/collection.html
Regards
EDIT
With help of Uffe I got the information of subtypes and types of some activity-diagram components. The "orginal name" is that name what you see in the GUI of the Enterprise Architect when you want to add a "New Element or Connector" :
original name: "Action"; type: "Action"; subtype: 0;
original name: "Activity"; type: "Activity"; subtype: 0;
original name: "Structured Activity" (Other->Simple Composite); type: "Activity"; subtype: 8;
original name: "Initial"; type: "StateNode"; subtype: 100;
original name: "Final"; type: "StateNode"; subtype: 101;
original name: "Flow Final"; type: "StateNode"; subtype: 102;
original name: "Decision"; type: "Decision"; subtype: 0;
original name: "Merge"; type: "MergeNode"; subtype: 0;
original name: "Decision"; type: "Decision"; subtype: 0;
original name: "Fork/Join" (horizontal); type: "Synchronization"; subtype: 0;
original name: "Fork/Join" (vertical); type: "Synchronization"; subtype: 1;
original name: "Diagram Legend"; type: "Text"; subtype: 76;
original name: "Synch"; type: "StateNode"; subtype: 6;
Uffe already explained it in his answer. Firstly create the Element with the type parameter and after that set the specific subtype. Don't forget the update() after this.
Element element = elements.AddNew("StartHere", "StateNode");
element.Subtype = 100;
element.Update();
elements.Refresh();
Thanks to Uffe again for this example:)

There is no element type enumeration, the element is simply specified as a string. The valid strings are listed in the help file, specifically in the Type attribute of the Element class (Automation and Scripting -- Enterprise Architect Object Model -- Reference -- Element Package -- Element Class).
There isn't a unique element type string for each type of element EA supports. Instead, many elements have a subtype. This subtype is expressed as an integer (Element.Subtype), and most of them are not documented - but the initial activity of an Activity diagram happens to be one of the few that is.
So in order to create an ActivityInitial element (as it is known in the GUI), you simply create the element specifying the type, and then set its subtype and update it.
Element element = elements.AddNew("StartHere", "StateNode");
element.Subtype = 100;
element.Update();
elements.Refresh();
In order to find out the correct type/subtype combination for other elements, the simplest way is to create an element of the corresponding type in the GUI and then look it up in the database:
select Object_Type, NType from t_object where Name = 'MyTestElement'

Related

"Map iterator is not a function" in OpenFL

I was building my project for Windows and everything was working fine. Now I started building it in HTML5 and I'm getting an error with map iterators:
for (entryMap in mapStruct.map)
{
var array:Array<Dynamic> = entryMap;
var keyObj = getJSONField(array[0], mapStruct.keyType);
var valueObj = getJSONField(array[1], mapStruct.valueType);
map.set(keyObj, valueObj);
}
And I get this error:
Exception name: TypeError: mapStruct.map.iterator is not a function
My project was working fine for Windows, but I don't know what to do, I need to use map like this.
I was trying to guess what is mapStruct without any success.
It looks like your aren't looping on a map in the right way...
Let's see some examples:
var map = ["hello" => 1, "world" => 4];
for (value in map)
{
trace('value: $value');
}
returns:
value: 1
value: 4
Here you have the link to try it online.
On the other hand, if you want to get either key and value, you should iterate it this way:
var map = ["hello" => 1, "world" => 4];
for (key in map.keys())
{
trace('key: $key value: ${map[key]}');
}
* Note the keys method call
And it returns:
key: hello value: 1
key: world value: 4
Here's the 'Try Haxe' link for it
if I knew which type mapStruct is, I'd probably help you more

A variable is assigned with objects, how do I return the number of objects in the variable

I have an object assigned to a variable bio. I just want to return the number of objects assigned to bio (in this case 1).
var bio = {
"name" : "Dave Smith",
"role" : "Web developer",
};
I can find the number of key value pairs but I just want the number of objects.
New at this so not sure if this makes sense.
Is it even possible to have multiple objects in a variable?
any help appreciated.
You have two questions here (I assume you use javascript):
How to know how many objects are assigned to a variable?
You need to do .length on the object. Note that this will work only on something that can be enumerated e.g. array.
var a = {foo: 'bar'};
a.length // undefined
var b = [{foo: 'bar'}];
b.length // 1
How to store multiple objects inside a variable
You need to use arrays like so: var bio = [{name: 'foo'}, {name: 'bar'}];

How can we extract all messages from processing report in json-schema validator

I am using json-schema validator for validating json data. if any error occur it will generate a report. But I want to show the error to the user the report is too big so I want to show only error messages.
This is my report
----------reports-------------
com.github.fge.jsonschema.report.ListProcessingReport: failure
--- BEGIN MESSAGES ---
error: instance failed to match at least one required schema among 4
level: "error"
schema: {"loadingURI":"#","pointer":"/properties/question-groups/items"}
instance: {"pointer":"/question-groups/0"}
domain: "validation"
keyword: "anyOf"
nrSchemas: 4
reports: {"/properties/question-groups/items/anyOf/0":[{"level":"error","schema":{"loadingURI":"#","pointer":"/definitions/multiple-choice/properties/evaluation-key/properties/options/items"},"instance":{"pointer":"/question-groups/0/evaluation-key/options/0"},"domain":"validation","keyword":"allOf","message":"instance failed to match all required schemas (matched only 0 out of 1)","matched":0,"nrSchemas":1,"reports":{"/definitions/multiple-choice/properties/evaluation-key/properties/options/items/allOf/0":[{"level":"error","schema":{"loadingURI":"#","pointer":"/definitions/multiple-choice/properties/evaluation-key/properties/options/items/allOf/0/properties/score"},"instance":{"pointer":"/question-groups/0/evaluation-key/options/0/score"},"domain":"validation","keyword":"type","message":"instance type (string) does not match any allowed primitive type (allowed: [\"integer\"])","found":"string","expected":["integer"]}]}}],"/properties/question-groups/items/anyOf/1":[{"level":"error","schema":{"loadingURI":"#","pointer":"/definitions/text/properties/evaluation-key"},"instance":{"pointer":"/question-groups/0/evaluation-key"},"domain":"validation","keyword":"additionalProperties","message":"object instance has properties which are not allowed by the schema: [\"options\"]","unwanted":["options"]},{"level":"error","schema":{"loadingURI":"#","pointer":"/definitions/text/properties/evaluation-key"},"instance":{"pointer":"/question-groups/0/evaluation-key"},"domain":"validation","keyword":"required","message":"object has missing required properties ([\"scorers\"])","required":["scorers"],"missing":["scorers"]},{"level":"error","schema":{"loadingURI":"#","pointer":"/definitions/text/properties/type"},"instance":{"pointer":"/question-groups/0/type"},"domain":"validation","keyword":"enum","message":"instance value (\"multiple-choice\") not found in enum (possible values: [\"text\"])","value":"multiple-choice","enum":["text"]}],"/properties/question-groups/items/anyOf/2":[{"level":"error","schema":{"loadingURI":"#","pointer":"/definitions/numeric/properties/evaluation-key"},"instance":{"pointer":"/question-groups/0/evaluation-key"},"domain":"validation","keyword":"additionalProperties","message":"object instance has properties which are not allowed by the schema: [\"options\"]","unwanted":["options"]},{"level":"error","schema":{"loadingURI":"#","pointer":"/definitions/numeric/properties/evaluation-key"},"instance":{"pointer":"/question-groups/0/evaluation-key"},"domain":"validation","keyword":"required","message":"object has missing required properties ([\"scorers\"])","required":["scorers"],"missing":["scorers"]},{"level":"error","schema":{"loadingURI":"#","pointer":"/definitions/numeric/properties/type"},"instance":{"pointer":"/question-groups/0/type"},"domain":"validation","keyword":"enum","message":"instance value (\"multiple-choice\") not found in enum (possible values: [\"numeric\"])","value":"multiple-choice","enum":["numeric"]}],"/properties/question-groups/items/anyOf/3":[{"level":"error","schema":{"loadingURI":"#","pointer":"/definitions/table"},"instance":{"pointer":"/question-groups/0"},"domain":"validation","keyword":"anyOf","message":"instance failed to match at least one required schema among 2","nrSchemas":2,"reports":{"/definitions/table/anyOf/0":[{"level":"error","schema":{"loadingURI":"#","pointer":"/definitions/table/anyOf/0"},"instance":{"pointer":"/question-groups/0"},"domain":"validation","keyword":"required","message":"object has missing required properties ([\"cells\"])","required":["cells","evaluation-key","group-id","question-text","type"],"missing":["cells"]}],"/definitions/table/anyOf/1":[{"level":"error","schema":{"loadingURI":"#","pointer":"/definitions/table/anyOf/1"},"instance":{"pointer":"/question-groups/0"},"domain":"validation","keyword":"required","message":"object has missing required properties ([\"cells\",\"matching-unit\"])","required":["cells","evaluation-key","group-id","matching-unit","question-text","type"],"missing":["cells","matching-unit"]}]}}]}
--- END MESSAGES ---
How can I get only error messages, any suggestions will be help full.
Thank you
somu
You can read the report as a JsonNode and get what ever parameter you need from that.
ProcessingReport report;
ProcessingMessage message;
report = schema.validate(jsonData);
Iterator itr = report.iterator();
while(itr.hasNext())
{
message = (ProcessingMessage) itr.next();
System.out.println("Message" + message.asJson().get("message").asText());
System.out.println("Reports" + message.asJson().get("reports").asText());
}
You should iterate over all messages and choose only errors comparing getLogLevel() with LogLevel.ERROR. That works for me
Iterator<ProcessingMessage> itr = report.iterator();
while(itr.hasNext())
{
ProcessingMessage message = (ProcessingMessage) itr.next();
if(message.getLogLevel().equals(LogLevel.ERROR)){
System.out.println(message.toString());
}
}
You can use the following method
String getErrorsList(ProcessingReport report, boolean onlyErrors) {
StringBuilder jsonValidationErrors = new StringBuilder();
for (ProcessingMessage processingMessage : report) {
if(onlyErrors && LogLevel.ERROR.equals(processingMessage.getLogLevel())) {
jsonValidationErrors.append(processingMessage.getMessage()).append("\n\r");
} else if(!onlyErrors) {
jsonValidationErrors.append(processingMessage.getMessage()).append("\n\r");
}
}
return jsonValidationErrors.toString();
}

Conditionally adjust visible columns in Rally Cardboard UI

So I want to allow the user to conditionally turn columns on/off in a Cardboard app I built. I have two problems.
I tried using the 'columns' attribute in the config but I can't seem to find a default value for it that would allow ALL columns to display(All check boxes checked) based on the attribute, ie. the default behavior if I don't include 'columns' in the config object at all (tried null, [] but that displays NO columns).
So that gets to my second problem, if there is no default value is there a simple way to only change that value in the config object or do I have to encapsulate the entire variable in 'if-else' statements?
Finally if I have to manually build the string I need to parse the values of an existing custom attribute (a drop list) we have on the portfolio object. I can't seem to get the rally.forEach loop syntax right. Does someone have a simple example?
Thanks
Dax - Autodesk
I found a example in the online SDK from Rally that I could modify to answer the second part (This assumes a custom attribute on Portfolio item called "ADSK Kanban State" and will output values to console) :
var showAttributeValues = function(results) {
for (var property in results) {
for (var i=0 ; i < results[property].length ; i++) {
console.log("Attribute Value : " + results[property][i]);
}
}
};
var queryConfig = [];
queryConfig[0] = {
type: 'Portfolio Item',
key : 'eKanbanState',
attribute: 'ADSK Kanban State'
};
rallyDataSource.findAll(queryConfig, showAttributeValues);
rally.forEach loops over each key in the first argument and will execute the function passed as the second argument each time.
It will work with either objects or arrays.
For an array:
var array = [1];
rally.forEach(array, function(value, i) {
//value = 1
//i = 0
});
For an object:
var obj = {
foo: 'bar'
};
rally.forEach(obj, function(value, key) {
//value = 'bar'
//key = 'foo'
});
I think that the code to dynamically build a config using the "results" collection created by your query above and passed to your sample showAttributeValues callback, is going to look a lot like the example of dynamically building a set of Table columns as shown in:
Rally App SDK: Is there a way to have variable columns for table?
I'm envisioning something like the following:
// Dynamically build column config array for cardboard config
var columnsArray = new Array();
for (var property in results) {
for (var i=0 ; i < results[property].length ; i++) {
columnsArray.push("'" + results[property][i] + "'");
}
}
var cardboardConfig = {
{
attribute: 'eKanbanState',
columns: columnsArray,
// .. rest of config here
}
// .. (re)-construct cardboard...
Sounds like you're building a neat board. You'll have to provide the board with the list of columns to show each time (destroying the old board and creating a new one).
Example config:
{
attribute: 'ScheduleState'
columns: [
'In-Progress',
'Completed'
]
}

Changing constraints on the fly

I have a dijit.form.NumberTextBox input field that starts out with these parms:
new dijit.form.NumberTextBox({
id: din1,
style: "width:60px",
constraints: {
places: 0,
pattern: '######'
}
},
din1);
Everything works great..My question is I would like to change 'places' and 'pattern' parms on the fly. So I wrote this to change 'places' and 'patterns' parms:
var myFldObj = dijit.byId(din1);
if (myFldObj) {
var myConstObj = myFldObj.attr('constraints');
if (myConstObj) {
myConstObj.places = 2;
myConstObj.pattern = '#####.0';
}
}
So, after I show the form again, I'd expect the entry field to allow 2 decimal places but the form still acts like places=0 and pattern='######'. When I check the values of 'places' and 'pattern' I get what I'd expect (2 and #####.0). My question:
Can you change these values on the fly??
OR
Do you have to destroy the original dijit object and recreate with new parms??
Thx!!
So, here is what worked for me:
First, I think this is a bug because an input field that starts out like
new dijit.form.NumberTextBox({
id: "fieldID",
style: "width:60px",
constraints: {
places: 0
}
},
"fieldID");
that is then changed on the fly with code like:
NOTE: ntbArry - Array of dijit.form.NumberTextBox objs tied to a html
input tag id.
for (var x=0;x < ntbArry.length;x++) {
var handle = ntbArry[x];
if (handle) {
handle.attr('constraints').places = 2;
handle.attr('constraints').pattern = '#####.0#';
}
}
Does not exhibit the same behavior as a field created this way (no constraints mods on the fly):
new dijit.form.NumberTextBox({
id: "fieldID",
style: "width: 60px",
constraints: {
places: 2,
pattern: '#####.0#'
}
},
"fieldID");
It's close in behavior but every time you type a decimal point, the error message pops up stating invalid entry. This message doesn't pop up when typing the decimal point on a field that was originally created with the constraints places=2 and pattern '#####.0#'.
So, to get original behavior I wanted:
fieldIDEvents is an array of dojo events tied to NumberTextBox fields.
Before continuing disconnect dojo events
for (var x=0;x < fieldIDEvents.length;x++) {
var handle = fieldIDEvents[x];
if (handle) {
dojo.disconnect(handle);
}
}
then destroy the NumberTextBox dojo objects
for (var x=0;x < ntbArry.length;x++) {
var handle = ntbArry[x];
if (handle) {
handle.destroy();
ntbArry[x] = null;
}
}
Next, place the input tag back into the html because it gets destroyed:
NOTE: tdtag and an id on a html td tag which should contain the input tag.
var fld1 = this.document.getElementById("tdtag");
if (fld1) {
//alert("\""+fld1.innerHTML+"\"");
fld1.innerHTML = "<input id=\"fieldID\">";
}
Now, create the NumberTextBox object again:
ntbArry[0] = new dijit.form.NumberTextBox({
id: "fieldID",
style: "width: 60px",
constraints: {
places: 2,
pattern: '#####.0#'
}
},
"fieldID");
It's a few extra steps but, at least I know this is what works for me..If I'm missing something basic, let me know, it's easy to miss the small details with this stuff.
I use Dojo 1.3 and I can see that dijit.form.NumberTextBox has no pattern and places properties, but has editOptions property. So I would try to change the constraints like this:
myConstObj.editOption.places = 2;