ARIS Community - We Love BPM

Import ARIS models from XML

MWZ's picture
by Michael Wieczorek in Reports & Macros posted on 2010-06-28

Now we want to import an xml file into ARIS and generate new models. Therefore we presume the same notation of the xml file as generated above.

First we need a browse dialog so that the user can select the xml file he wants to import:

function getImportFile() {
    var sdefname = "";
    var sdefext = "*.xml!!xml file|*.xml||";
    var sdefdir = "";
    var stitle = "Import xml file";

    var aFiles = Dialogs.getFilePath(sdefname, sdefext, sdefdir, stitle, 0);    // Displays a file selection dialog on the client and makes the content of the selected files available in the report
    if (aFiles != null && aFiles.length > 0) {
        return aFiles[0];
    }
    return null;
}

The return value is an object of type “SelectedFile”. So we use method “getData” to get the content of the file and put it as input for the xml parsing method:

var importFile = getImportFile();
if (importFile != null) {
    var xmlData = importFile.getData();             // Content of the file
    var xmlReader = Context.getXMLParser(xmlData);  // Parses the specified XML file and returns an object that provides access to the XML document.
    if (xmlReader.isValid()) {
        var xmlRoot = xmlReader.getRootElement();   // Root element of the XML document

Next step is to read the model elements from the root object and create models in ARIS:

 var xmlModels = xmlRoot.getChildren("Model");
     var iterModel = xmlModels.iterator()
     while(iterModel.hasNext()) {
        var xmlModel = iterModel.next();
        // Create model
        var oModel = createModel(xmlModel, oGroup);
        if (oModel != null) {

Based on these models we read the objects and the connections and create the corresponding objects/connections in ARIS:

 var xmlObjs = xmlModel.getChildren("ObjDef");
        var iterObj = xmlObjs.iterator()
        while(iterObj.hasNext()) {
            var xmlObj = iterObj.next();
            // Create object definition and occurence
            createObject(xmlObj, oGroup, oModel);
        }

        var xmlCxns = xmlModel.getChildren("CxnDef");
        var iterCxn = xmlCxns.iterator()
        while(iterCxn.hasNext()) {
            var xmlCxn = iterCxn.next();
            // Create cxn definition and occurence
            createCxn(xmlCxn, oModel);
        }

During generation of the model we place all objects an connections with default values in the model so we had to layout the model after generating. We can do this by using the method “doLayout”.

At least, we open the model in the in the modeling window after running the report.

oModel.doLayout();                  // Executes a layout of the model
       oModel.openModel()                  // Opens the model in the modeling window after running the report

Function to create models:

function createModel(xmlModel, oGroup) {
    var sName = xmlModel.getAttribute("Name").getValue();
    var nTypeNum = parseInt(xmlModel.getAttribute("TypeNum").getValue());
    var sID = xmlModel.getAttribute("ID").getValue();

    var oModel = oGroup.CreateModel(nTypeNum, sName, g_nLoc);   // Creates a new model in the current group
    if (oModel.IsValid()) {                                     // Tests the validity of the object
        setAttrID(oModel, sID);                                 // Write attribute 'Identifier'
        return oModel;
    }
    return null;
}

To write the attribute “Identifier” we use this function:

function setAttrID(oItem, sID) {
    return oItem.Attribute(Constants.AT_ID, g_nLoc).setValue(sID);
}

Function to create object definitions and occurrences:

function createObject(xmlObj, oGroup, oModel) {
    var sName = xmlObj.getAttribute("Name").getValue();
    var nTypeNum = parseInt(xmlObj.getAttribute("TypeNum").getValue());
    var sID = xmlObj.getAttribute("ID").getValue();

    var oObjDef = oGroup.CreateObjDef(nTypeNum, sName, g_nLoc); // Creates a new m object definition in the current group
    if (oObjDef.IsValid()) {                                    // Tests the validity of the object
        setAttrID(oObjDef, sID);                                // Write attribute 'Identifier'

        var nSymbol = getSymbol(oModel, oObjDef);
        if (nSymbol > 0) {
            var oObjOcc = oModel.createObjOcc(nSymbol, oObjDef, 0, 0, true);    // Creates a new object occurrence of the specified object definition in the model
            if (oObjOcc.IsValid()) {                            // Tests the validity of the object
                return oObjOcc;
            }
            return null;
        }
    }
    return null;

    
    function getSymbol(oModel, oObjDef) {
        var aSymbols = ArisData.ActiveFilter().Symbols(oModel.TypeNum(), oObjDef.TypeNum());    // Returns a list of permitted symbols of the specified object type in the specified model type
        if (aSymbols.length > 0) {
            return aSymbols[0];
        }
        return 0;
    }
}

Function to create connection definitions and occurrences:

function createCxn(xmlCxn, oModel) {
    var sSourceName = xmlCxn.getAttribute("SourceName").getValue();
    var sTargetName = xmlCxn.getAttribute("TargetName").getValue();    
    var nTypeNum = parseInt(xmlCxn.getAttribute("TypeNum").getValue());
    var sID = xmlCxn.getAttribute("ID").getValue();

    var oSourceObjOcc = getObjectInModel(oModel, sSourceName);
    var oTargetObjOcc = getObjectInModel(oModel, sTargetName);
    
    if (oSourceObjOcc != null && oTargetObjOcc != null) {
        var oCxnOcc = oModel.CreateCxnOcc(oSourceObjOcc, oTargetObjOcc, nTypeNum, getDummyPointList()); // Creates a new relationship (definition and occurrence) between the specified object occurrences in the model
        if (oCxnOcc != null) {
            var oCxnDef = oCxnOcc.Cxn();
            setAttrID(oCxnDef, sID);                                // Write attribute 'Identifier'
        }
        return oCxnOcc;
    }
    return null;

    
    function getObjectInModel(oModel, sName) {
        var oObjOccsInModel = oModel.ObjOccList();                  // Returns all object occurrences in the model
        for (var i = 0; i < oObjOccsInModel.length; i++) {
            var oObjOcc = oObjOccsInModel[i];
            var oObjDef = oObjOcc.ObjDef();
            if (StrComp(oObjDef.Name(g_nLoc), sName) == 0) {        // Compare names
                return oObjOcc;
            }
        }
        return null;
    }    
    
    function getDummyPointList() {
        var pointList = new Array();
        pointList.push(new java.awt.Point(0, 0));
        pointList.push(new java.awt.Point(1, 1));        
        return pointList;
    }    
}

Here you can download the entire source code from the "XML Import" report.

Note: This article describe how to develop a report in ARIS. See this post for links to similar articles.

26747 Views
0 Likes
12 Comments
There are no attachments
abdelghani azri posted on 2010-08-19

Hello all,

I work on importation data from Excel to aris.

I write a script to parse an Excel file, but I have problem to read the sheets.

So can you help me?

Thanks.

Fadi Darani posted on 2010-11-25

Hello Micheal ,

i try it but it did not work .

i can not creatmodel .

Thanks

Linda Thomas posted on 2011-02-02

Hello Michael,
I am very new to ARIS.
As a part of my requirement i need to write a REPORT in ARIS that imports and XML file and stores the node values in a suitable format for creating DATA_TYPE_MODEL in ARIS.

can you please help m in reading this xml and extract the value of xml nodes and store it to some hash maps in ARIS.

Please help me with some inputs as i am totally stuck...
Regards,
Linda

Linda Thomas posted on 2011-02-02

 

Hello Michael,
I am very new to ARIS.
As a part of my requirement i need to write a REPORT in ARIS that imports and XML file and stores the node values in a suitable format  for creating DATA_TYPE_MODEL in ARIS.
 
My XML is like below
  <?xml version="1.0" encoding="utf-16" ?> 
- <GDT>
  <NODE_ID>0050569357F902DD9CE48D5F7D0FDD5F</NODE_ID> 
- <GDT_ATTRIBUTES>
- <UUID_KEY>
  <UUID>00505693-57f9-02dd-9ce4-8d81547adee2</UUID> 
  </UUID_KEY>
- <NAME_KEY>
  <NAME>Amount</NAME> 
  </NAME_KEY>
  <STRUCT_CAT>2</STRUCT_CAT> 
  <USAGE_CAT>2</USAGE_CAT> 
  <RESTRICTED_IND>false</RESTRICTED_IND> 
  </GDT_ATTRIBUTES>
- <ALLOWED_QUALIFIERS>
- <ITEM>
  <NODE_ID>0050569357F902DD9CE48D5F85771D60</NODE_ID> 
  <NAME>Boundary</NAME> 
  <VERSION_ID>0000000000</VERSION_ID> 
  </ITEM>
- <ITEM>
  <NODE_ID>0050569357F902DD9CE48D5F8CA85D62</NODE_ID> 
  <NAME>Principal</NAME> 
  <VERSION_ID>0000000000</VERSION_ID> 
  </ITEM>
- <ITEM>
  <NODE_ID>0050569357F902DD9CE48D5F937F9D64</NODE_ID> 
  <NAME>Order</NAME> 
  <VERSION_ID>0000000000</VERSION_ID> 
  </ITEM>
- <ITEM>
  <NODE_ID>0050569357F902DD9CE48D5F9A5D1D66</NODE_ID> 
  <NAME>Due</NAME> 
  <VERSION_ID>0000000000</VERSION_ID> 
  </ITEM>
 </ALLOWED_QUALIFIERS>
  </GDT>
 
can you please help m in reading this xml and extract the value of xml nodes and store it to some hash maps in ARIS.
 
Please help me with some inputs as i am totally stuck...
Regards,
Linda
 
merrick meredith posted on 2012-02-14

Hello

Do you have the format of the xml file as used in the following script?

 

Thanks

merrick

Romeo Paone posted on 2013-10-24

Dear Michael,

i hope this is the right page where i can post my question regarding the following issue.

I am trying to find the correct format to import the time attributes (static, orientation and processing time) from an excel file into my model in Aris.

The upload of the excel file worked for updating the values of  COST and FREQUENCY attributes.

For example,  a value of the time attirbute has the following format (0000:01:15:00) Constant, but adding the same format with different values on excel, it did not upload the change.

I have tried different format, but nothing seemed to work.

If anyone has a solution on this issue, it would be highly appreciated.

Thank you

Best Regards

Romeo 

Romeo Paone posted on 2013-11-15

Hello again,

maybe i was not that clear.

I am finding problems in importing new values of  the attributes of TIME from an excel file to ARIS.

I cannot find the right format for making changes on the excel file and then importing the new values into ARIS.

 

For example:  format (0000:01:15:00) Constant, if i change this value ( hence same format), it is not imported into ARIS.

This issue is only for the TIME attribute, not for COST and FREQUENCY for example.

Any suggestions?

Thank you very much.

Romeo

Gerard Torres posted on 2015-01-25

Hi,

I don't see oGroup defined anywhere. Would it be something like:

var groups = ArisData.getSelectedGroups();
for(var i = 0; i < groups.length; i++) {
    oGroup = groups[i];
    
    var importFile = getImportFile();
    if(importFile != null) {
        ...
    }
    ...
}

 

If not, where should I get the oGroup value?

Thanks

RAFAEL ASSAYAG posted on 2016-01-15

What a shame!

I tried to read a very very simple XML file:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
  <Model Name="Desdobrar estratégia">
    <ObjDef Name="Planejar força de trabalho" />
    <Model Name="Avaliar estratégia de recursos humanos">
      <ObjDef Name="Monitorar planejamento estratégico de recursos humanos" />
      <ObjDef Name="Gerenciar portfólio" />
    </Model>
    <ObjDef Name="Planejar custo de pessoal" />
    <Model Name="Definir estratégia de recursos humanos">
      <ObjDef Name="Realizar estudos" />
      <ObjDef Name="Estruturar projeto estratégico de recursos humanos" />
    </Model>
  </Model>
</Root>

But it seems not considering the hierarchy. When I apply the sequence

var xmlModels = xmlRoot.getChildren("Model");
    var iterModel = xmlModels.iterator()
    while(iterModel.hasNext())...
 
it considers all "Model" tags under "Root" despising the XML conventions about ends of nodes.
 
  <Model Name="Desdobrar estratégia">
    <Model Name="Avaliar estratégia de recursos humanos">
        .
        .
        ,
    </Model>
  </Model>
 
are treated as
 
  <Model Name="Desdobrar estratégia"/>
  <Model Name="Avaliar estratégia de recursos humanos"/>
 
 
Is there someone who can help me?
 
Thanks in advance.
RAFAEL ASSAYAG posted on 2016-01-18

I suppose I've already "solved" the problem. In reality there's no problem. It was me not working the right way.

After some debugging code trials, I could evaluate clearly the behavior of the methods used.

Sorry!

Thanks to anyone who may be trying to discover what might be "wrong".

Rafael

 

gowtham ramesh posted on 2016-04-12

Hi,

In code, comment says it creates object occurrence that means occurrence of already exiting object or it will be creating it for first time. Please help me understand. and also let me know what exactly object definition and object occurrence means so i can correct myself if I have misunderstood.

Thanks in advance.

Regards,

Gowtham R

Robert Goldenbaum posted on 2016-04-12

You first have to create an object definition and then you can use this when creating an occurrence...

oObjDef = oGroup.createObjDef(...)

if (oObjDef.IsValid()){

    oObjOcc = oModel.createObjOcc(lSymbolNum, oObjDef, ...)

}

You always need an object definition for the occurences. When you put manually in Designer/Architect an object into a model, ARIS creates the needed object definition and places an occ for this def in the model.

Regards,

Robert