Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - peigee

Pages: [1] 2 3
1
General Board / Re: creating connector using script
« on: October 07, 2020, 04:37:14 pm »
Thank you Eve. I have also found this by reading Aaron B's earlier post about his sample FK connector code. Now all sorted as per below:

         var Connectors as EA.Collection;
         Connectors = theElement.Connectors;
         var newConnector as EA.Connector;
         newConnector=Connectors.AddNew(c_keycols+"="+c_r_keycols+")","Association");
         newConnector.SupplierID=r_element.ElementID;
         newConnector.StyleEx = "FKINFO=SRC=" + newMethod.Name + ":DST=" + c_r_pkname + ":;";
         newConnector.Direction = "Source -> Destination";
         newConnector.StereotypeEx = "EAUML::FK";
         newConnector.ClientEnd.Role = newMethod.Name;
         newConnector.ClientEnd.Cardinality = "0..*";
         newConnector.SupplierEnd.Role = c_r_pkname;
         newConnector.SupplierEnd.Cardinality = "1";
         newConnector.Update();

2
General Board / Re: creating connector using script
« on: October 07, 2020, 12:25:52 pm »
qwerty, thanks for your question.
I am currently working on an incremental data model 'reverse-engineeror' outside of sparx  that auto-generates a jscript as SPARX 'plug-in' by comparing a target database against the data model in sparx for a specific package. Therefore the newly created connector may be used by other code within the same run session but on a deferent function of the script, depending on the data model difference at the run time.

3
General Board / Re: creating connector using script
« on: October 07, 2020, 11:58:15 am »
Geerty, a good reminder! Just realised while setting StyleEx had created the visual connector in a diagram, it hadn't actually populated values in SourceRole and DestRole of t_connector table, therefore, the FK (Association) connector is still not created correctly.
However your suggested ClientEnd and SuppliedEnd are two readonly properties and wouldn't accept newMethod.MethodID or anything else related to the FK/PK operation records at all.
I am now back to square one!

4
General Board / Re: creating connector using script
« on: October 07, 2020, 10:58:15 am »
The second refresh statement indeed isn't necessary. The first one is for the newly added connector to be navigated to by my subsequent code not listed here.

5
General Board / Re: creating connector using script
« on: October 06, 2020, 06:39:17 pm »
Thank you Geert. I have tried your suggested two properties before by assigning the FK and PK method.name values (perhaps I should have used method.MethodID?). Anyhow after seeing another post suggesting property StyleEx, I got it working, as follows:

--after added a new method for the FK operation record (and its parameters) and located the existing source and target element and the target PK operation name:

         var Connectors as EA.Collection;
         Connectors = theElement.Connectors;
         var newConnector as EA.Connector;
         newConnector=Connectors.AddNew("","Association");
         newConnector.SupplierID=r_element.ElementID;
         newConnector.StyleEx = "FKINFO=SRC=" + newMethod.Name + ":DST=" + c_r_pkname + ":;";
         newConnector.Update();
         Connectors.Refresh();
         r_element.Connectors.Refresh();

6
General Board / Re: creating connector using script
« on: October 06, 2020, 01:19:44 pm »
The replies so far only mentioned the source and target elements (client and supplier id) for the new connector. How to specify the source and target role (attribute sourcerole and destrole in the repository table t_connect) for linking the operation FK and PK, if I want to add a connector for a new FK via java script? I could not find such properties available for the connector object. Here are the sample script I have been experimenting and found out SourceRole and DeskRole are invalid property for the connector:

--after added a new method for the FK operation record (and its parameters) and located the existing source and target element and the target PK operation name:

var Connectors as EA.Collection;
Connectors = theElement.Connectors;
var newConnector as EA.Connector;
newConnector=Connectors.AddNew("","Association");
newConnector.SupplierID=r_element.ElementID;
*newConnector.SourceRole=newMethod.Name;
*newConnector.DeskRole=c_r_pk;
newConnector.Update();
Connectors.Refresh();
target.Connectors.Refresh();

What are the correct properties I shall use to complete an FK constraint addition via Jscript?

7
It has been confirmed to me that Repository.RunModelSearch method does not work with the XML returned from Repository.SqlQuery method. My point is why it doesn't. Certainly an improvement can be easily made here even if it wasn't in the original intention of the RunModelSearch method.

I understand now that converting the SqlQuery returned XML to the format acceptable to RunModelSearch is the only way. There is an sample script (model search operations) describing the expected XML format. I was also provided sample conversioin code (from SQLQuery output) as follows:

Code: [Select]
!INC Local Scripts.EAConstants-JScript
!INC EAScriptLib.JScript-XML

// The columns that will apear in the Model Search window
var SEARCH_SPECIFICATION = "<ReportViewData>" +
                                          "<Fields>" +
                                          "<Field name=\"CLASSGUID\" />" +
                                          "<Field name=\"CLASSTYPE\" />" +
                                          "<Field name=\"Name\" />" +
                                          "</Fields>" +
                                          "<Rows/>" +
                                          "</ReportViewData>";
                                          
function main()
{
      
      var theElement as EA.Element;
      theElement = Repository.GetContextObject();
      
      var objID = theElement.ElementID;
      var sql = " select ea_guid as CLASSGUID,'Attribute' as CLASSTYPE, Name from t_attribute where Object_ID="+objID;
      Session.Output( sql );
      var queryResult = Repository.SQLQuery( sql );
      Session.Output( "queryResult.length=" + queryResult.length );
      if ( queryResult.length > 0 )
      {
            Session.Output( queryResult );
            var resultDOM = XMLParseXML( queryResult );
            
            // Create a DOM object to represent the search tree
            var xmlDOM = CreateXMLObject();

            // Load the search template
            if( xmlDOM.loadXML(SEARCH_SPECIFICATION) )
            {
                  var node = xmlDOM.selectSingleNode( "//ReportViewData//Rows" );
                  
                  //loop over xml rows returned from sql query
                  var rows = resultDOM.selectNodes("//EADATA//Dataset_0//Data//Row");
                  for (var i=0; i < rows.length; i++)
                  {
                        var row = rows.item(i);

                        //available data from the sql statement:
                        var CLASSGUID = row.selectSingleNode("CLASSGUID").text;
                        var CLASSTYPE = row.selectSingleNode("CLASSTYPE").text;
                        var attName = row.selectSingleNode("Name").text;
                        
                        // Add this element to the XML tree
                        AddRow( xmlDOM, node, CLASSGUID, CLASSTYPE, attName );

                  }
                        
            }

            if ( xmlDOM )
                  Repository.RunModelSearch( "", "", "", xmlDOM.xml );
      }
      
}

function CreateXMLObject()
{
      var xmlDOM;
      try
      {
             xmlDOM = new ActiveXObject( "MSXML2.DOMDocument.4.0" );
      }
      catch(e)
      {
             xmlDOM = new ActiveXObject( "MSXML2.DOMDocument.6.0" );
      }
      
      xmlDOM.validateOnParse = false;
      xmlDOM.async = false;
      
      return xmlDOM;
}

function AddRow( xmlDOM, rowsNode, CLASSGUID, CLASSTYPE, attName )
{
      // Create a Row node
      var row = xmlDOM.createElement( "Row" );
      
      // Add the Model Search row data to our DOM
      AddField( xmlDOM, row, "CLASSGUID", CLASSGUID );
      AddField( xmlDOM, row, "CLASSTYPE", CLASSTYPE );
      AddField( xmlDOM, row, "Name", attName );
      
      // Append the newly created row node to the rows node
      rowsNode.appendChild( row );
}

function AddField( xmlDOM, row, name, value )
{
      var fieldNode = xmlDOM.createElement( "Field" );
      
      // Create first attribute for the name
      var nameAttribute = xmlDOM.createAttribute( "name" );
      nameAttribute.value = name;
      fieldNode.attributes.setNamedItem( nameAttribute );
      
      // Create second attribute for the value
      var valueAttribute = xmlDOM.createAttribute( "value" );
      valueAttribute.value = value;
      fieldNode.attributes.setNamedItem( valueAttribute );
      
      // Append the fieldNode
      row.appendChild( fieldNode );
}

main();

8
BTW, I am running EA 12.0.1210 version, Windows 7 Enterprise, Microsoft.NET Framework 4.5.1

9
Therefore, this shall be considered a bug!?

10
Looks like Repository.RunModelSearch() does not understand the XML formatted SQL result returned from Repository.SQLQuery() (per posted), because if I supply the following string, Repository.RunModelSearch() does show the content:

Code: [Select]
Repository.RunModelSearch("","","","<ReportViewData><Fields><Field name=\"CLASSGUID\" /><Field name=\"CLASSTYPE\" /><Field name=\"Name\" /></Fields></ReportViewData>") ;

11
Thank KP for your reply.

The leading space in the sql string is not actually a problem as the queryResult did capture the rows and I have also tried in removing the leading space in the sql string.

12
Adding the truncated remaining part due to size limitation from the last post:
Code: [Select]
Attribute</CLASSTYPE><Name>UPDATED_BY_USER_ID</Name></Row>
            <Row><CLASSGUID>{9A05F85C-9F08-47d5-84FB-F40AFD458830}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>ETL_NAME</Name></Row>
            <Row><CLASSGUID>{9C3BC4B3-A84A-4353-9F65-CA05C2F96F50}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>ETL_RUN_ID</Name></Row>
      </Data></Dataset_0>
</EADATA>

13
The queryResult is captured as bellow:
[code]
<?xml version="1.0"?>
      
<EADATA version="1.0" exporter="Enterprise Architect">
      
      <Dataset_0><Data>
            <Row><CLASSGUID>{4A1AB6BB-56EA-480d-B698-BA132EF824CD}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DISPUTE_OUTCOME_TYPE_CODE</Name</Row>
            <Row><CLASSGUID>{139F77F1-32BF-436f-B790-3D8EBEB50FE1}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>IP_SVC_DTL_ID</Name></Row>
            <Row><CLASSGUID>{705B0B34-247A-4ff7-B87F-522B71940CFB}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DISPUTE_TYPE_CODE</Name></Row>
            <Row><CLASSGUID>{E24F1889-4FDC-476c-8906-2EBB31719723}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_ACTIONED</Name></Row>
            <Row><CLASSGUID>{ABB15E1E-9E02-45eb-989E-EBCAF651FF9B}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_HEARING_OFFICER_ASSIGNED</Name></Row>
            <Row><CLASSGUID>{CA3A0157-2EF7-47bc-B098-4F32B36D903C}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>HEARING_OFFICER_FULL_NAME</Name></Row>
            <Row><CLASSGUID>{A3D7014E-A80D-49e9-820A-515AEA7914B2}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>HEARING_OFFICER_ID</Name></Row>
            <Row><CLASSGUID>{7335F82C-3C83-4fff-A7C7-7A15BC7D1D07}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_COOLING_OFF_PERIOD_FROM</Name></Row>
            <Row><CLASSGUID>{080B1667-B09E-4e1b-BF87-83B9C968AD3E}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_COOLING_OFF_PERIOD_TO</Name></Row>
            <Row><CLASSGUID>{5CB1DAF7-ED19-4a6e-9852-8122805E063A}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_GROUNDS_DUE</Name></Row>
            <Row><CLASSGUID>{3CF59272-FD93-4070-960B-6072BFFE4FEF}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_GROUNDS_EXTSN_END</Name></Row>
            <Row><CLASSGUID>{8D1DCC89-E1E5-496b-A36A-E2F8D94EC0F0}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_GROUNDS_FILED</Name></Row>
            <Row><CLASSGUID>{DA096288-B31D-4e8a-9983-A5450FA815F0}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_GROUNDS_SERVED</Name></Row>
            <Row><CLASSGUID>{3FB038AD-9067-43ba-A096-317901C756BC}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_INTNT_TO_DEFEND_DUE</Name></Row>
            <Row><CLASSGUID>{109EFA8E-F535-40ca-8D72-BFF1083D1B92}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_INTNT_TO_DEFEND_EXTSN_END</Name></Row>
            <Row><CLASSGUID>{F87646E4-D779-4bb4-AF24-7271798C1E9A}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_INTNT_TO_DEFEND_FILED</Name></Row>
            <Row><CLASSGUID>{B60ADDF2-588C-450a-8830-95339FCF11DD}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_INTNT_TO_DEFEND_SERVED</Name></Row>
            <Row><CLASSGUID>{B400D06A-5728-4ff6-B64D-0645F3020128}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_NOTICE_OF_INTENT_LODGED</Name></Row>
            <Row><CLASSGUID>{B17171EE-0494-4288-8435-E2853C16201C}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_OPP_WITHDRAWN</Name></Row>
            <Row><CLASSGUID>{43FC30CE-49AF-47e8-A35B-3C71AE33E872}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_REPLY_DUE</Name></Row>
            <Row><CLASSGUID>{A01A8848-6847-4781-9A0C-28B0483EF6A8}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_SUSPENSION_REQ</Name></Row>
            <Row><CLASSGUID>{F3BA2F58-5889-4c0e-9768-28044D6C287D}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_SUSPENSION_START</Name></Row>
            <Row><CLASSGUID>{025F979B-289C-4da4-A0BB-D7CDBE93E41E}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_SUSPENSION_END</Name></Row>
            <Row><CLASSGUID>{FBB17B1E-CF5D-4c0b-8D94-24C542E5ED90}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>GROUNDS_COMMENTS</Name></Row>
            <Row><CLASSGUID>{2CD56093-D8E6-4f34-94B1-1C4E6EB168BA}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>GROUNDS_COMPLETE_IND</Name></Row>
            <Row><CLASSGUID>{74447838-42E9-44ed-96B3-BD698DA3F3C3}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DISPUTE_APPEARANCE_TYPE_CODE</Name></Row>
            <Row><CLASSGUID>{8AFD502A-2288-4a19-8342-78A05E6703F1}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>INTNT_TO_DEFEND_COMMENTS</Name></Row>
            <Row><CLASSGUID>{D7051E64-51F7-4e76-AB95-83CCFA7ACF66}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>INTNT_TO_DEFEND_COMPLETE_IND</Name></Row>
            <Row><CLASSGUID>{0951D204-8A6A-49f0-8FEB-54FA2BDA1852}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>INTNT_TO_DEFEND_IND</Name></Row>
            <Row><CLASSGUID>{030CF203-A24D-495f-A782-BABA0A687F9E}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>PRECEDENT_IND</Name></Row>
            <Row><CLASSGUID>{3FC64E36-18EE-4c9a-8464-8BDEAD90FA9E}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>YEAR_OF_ACT</Name></Row>
            <Row><CLASSGUID>{4333A0E0-2352-430c-806B-A163215C662A}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_CREATED</Name></Row>
            <Row><CLASSGUID>{464946C6-0A30-49d6-89C8-031856FF8ADC}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>CREATED_BY_USER_ID</Name></Row>
            <Row><CLASSGUID>{FAB86AEC-08AB-40f3-907F-DC179D7307F7}</CLASSGUID><CLASSTYPE>Attribute</CLASSTYPE><Name>DATE_UPDATED</Name></Row>
            <Row><CLASSGUID>{6E078F26-61B5-422b-B913-EB1C5A14328C}</CLASSGUID><CLASSTYPE>

14
My following jscript won't show the Repository.SQLQuery returned results from the subsequent ModelSearch window that it had been opened (no errors reported, the sql does return rows when executed in a SQL client), am I missing anything?

Code: [Select]
......
            var objID = theElement.ElementID;
            sql = " select ea_guid as CLASSGUID,'Attribute' as CLASSTYPE, Name from t_attribute where Object_ID="+objID;
            Session.Output( sql );
            var queryResult = Repository.SQLQuery( sql )
            if ( queryResult.length > 0 )
            {
                  var      resultDOM = XMLParseXML( queryResult )
                  if ( resultDOM )
                  Repository.RunModelSearch( "", "", "", resultDOM.xml );
            }
            ......

15
In scripts, either single or double quotes can be used for a string value, however, in SQL, only single-quotes can be used for string values, while double-quotes are used for database object names (particularly when containing special characters). Therefore, the online document I had mentioned is incorrect in using the double-quotes for the database table name string 't_connector'.

I believe the document description is intended for the navigation to the connector property dialog (technically very easy to implement), in my case, the connector type is 'Association', therefore a FK constraint dialog should have been popped up.

I noticed the online document is meant for 12.1, while my version of EA is 12.0.1210. I gather the feature may not be available for my version. I hope someone can verify this.

Pages: [1] 2 3