Parent: [346c31] (diff)

Child: [0553f7] (diff)

Download this file

TavernaExtractor.java    2556 lines (1993 with data), 124.8 kB

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
/**
* Copyright (c) 2013/2014 Verein zur Foerderung der IT-Sicherheit in Oesterreich (SBA).
* The work has been developed in the TIMBUS Project and the above-mentioned are Members of the TIMBUS Consortium.
* TIMBUS is supported by the European Union under the 7th Framework Programme for research and technological
* development and demonstration activities (FP7/2007-2013) under grant agreement no. 269940.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including without
* limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTIBITLY, or FITNESS FOR A PARTICULAR
* PURPOSE. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise,
* unless required by applicable law or agreed to in writing, shall any Contributor be liable for damages, including
* any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this
* License or out of the use or inability to use the Work.
* See the License for the specific language governing permissions and limitation under the License.
*/
package net.timbusproject.extractors.modules.tavernaextractor;
import com.jcraft.jsch.Session;
import edu.uci.ics.jung.algorithms.layout.AbstractLayout;
import edu.uci.ics.jung.algorithms.layout.ISOMLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.SparseGraph;
import net.sf.taverna.t2.activities.beanshell.BeanshellActivity;
import net.sf.taverna.t2.activities.beanshell.BeanshellActivityConfigurationBean;
import net.sf.taverna.t2.activities.dataflow.DataflowActivity;
import net.sf.taverna.t2.activities.externaltool.ExternalToolActivity;
import net.sf.taverna.t2.activities.externaltool.ExternalToolActivityConfigurationBean;
import net.sf.taverna.t2.activities.localworker.LocalworkerActivity;
import net.sf.taverna.t2.activities.rest.RESTActivity;
import net.sf.taverna.t2.activities.rshell.RshellActivity;
import net.sf.taverna.t2.activities.rshell.RshellActivityConfigurationBean;
import net.sf.taverna.t2.activities.wsdl.WSDLActivity;
import net.sf.taverna.t2.activities.wsdl.xmlsplitter.XMLInputSplitterActivity;
import net.sf.taverna.t2.activities.wsdl.xmlsplitter.XMLOutputSplitterActivity;
import net.sf.taverna.t2.activities.xpath.XPathActivity;
import net.sf.taverna.t2.activities.xpath.XPathActivityConfigurationBean;
import net.sf.taverna.t2.commandline.CommandLineLauncher;
import net.sf.taverna.t2.commandline.exceptions.DatabaseConfigurationException;
import net.sf.taverna.t2.commandline.exceptions.InvalidOptionException;
import net.sf.taverna.t2.commandline.exceptions.OpenDataflowException;
import net.sf.taverna.t2.commandline.exceptions.ReadInputException;
import net.sf.taverna.t2.invocation.TokenOrderException;
import net.sf.taverna.t2.security.credentialmanager.CMException;
import net.sf.taverna.t2.workbench.models.graph.DotWriter;
import net.sf.taverna.t2.workbench.models.graph.Graph.Alignment;
import net.sf.taverna.t2.workbench.models.graph.GraphController.PortStyle;
import net.sf.taverna.t2.workbench.models.graph.svg.SVGGraphController;
import net.sf.taverna.t2.workflowmodel.*;
import net.sf.taverna.t2.workflowmodel.impl.ProcessorInputPortImpl;
import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
import net.sf.taverna.t2.workflowmodel.processor.activity.DisabledActivity;
import net.sf.taverna.t2.workflowmodel.processor.activity.UnrecognizedActivity;
import net.sf.taverna.t2.workflowmodel.processor.iteration.IterationTypeMismatchException;
import net.sf.taverna.t2.workflowmodel.serialization.DeserializationException;
import net.timbusproject.extractors.helpers.MachineID;
import net.timbusproject.extractors.modules.tavernaextractor.utils.*;
import net.timbusproject.extractors.modules.tavernaextractor.utils.Container;
import net.timbusproject.extractors.modules.tavernaextractor.utils.Container.Orientation;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.sbaresearch.licensecheck.LicenseCheck;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import uk.ac.bolton.archimate.editor.model.viewpoints.IViewpoint;
import uk.ac.bolton.archimate.model.*;
import uk.ac.bolton.archimate.model.impl.BusinessEvent;
import uk.ac.bolton.archimate.model.util.ArchimateResourceFactory;
import static java.nio.file.FileVisitResult.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.*;
import java.awt.*;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
/**
* @author Rudolf Mayer (rmayer@sba-research.org)
* @author Marco Unterberger (munterberger@sba-research.org)
*/
public class TavernaExtractor extends CommandLineLauncher {
private IArchimateFactory factory;
private Map<String, IDiagramModelArchimateObject> elementModelObjectMap;
private List<IRelationship> relations;
private IArchimateDiagramModel layeredView;
private Graph<IArchimateElement, IArchimateElement> graph;
private Layout<IArchimateElement, IArchimateElement> layout;
private int overall_X, overall_Y = 0;
private final int MIN_ELEMENTS_FOR_GROUPING = 3;
private Map<Processor, List<IBusinessObject>> processorObjectMapping = new HashMap<Processor, List<IBusinessObject>>();
private Map<IBusinessObject, IDataObject> business2dataMap = new HashMap<IBusinessObject, IDataObject>();
private Map<Processor, IOrJunction> loopsJunctions = new HashMap<Processor, IOrJunction>();
private HashMap<Processor, IBusinessProcess> processorProcessMap = new HashMap<Processor, IBusinessProcess>();
private List<BeanshellActivity> beanshellScripts = new ArrayList<BeanshellActivity>();
private Map<Processor, IAndJunction> processorInputMap = new HashMap<Processor, IAndJunction>();
private HashMap<Processor, IBusinessObject> processorValueMap = null;
private INode desktop;
private IDiagramModelArchimateObject diagramModelDesktop;
private IBusinessProcess parentProcessWorkflow;
private IBusinessEvent startEvent;
private IAndJunction andJunctionStart;
private IBusinessEvent endEvent;
private IAndJunction andJunctionEnd;
/*
* // Groups //////////////
*/
private IDiagramModelGroup businessProcessModelGroup;
private IDiagramModelGroup externalApplicationModelGroup;
private IDiagramModelGroup applicationComponentModelGroup;
private IDiagramModelGroup externalInfrastructureModelGroup;
private IDiagramModelGroup infrastructureModelGroup;
private IDiagramModelGroup externalProviderModelGroup;
private IDiagramModelGroup processStepsModelGroup;
/*
* // Containers //////////////
*/
private Container inputPorts;
private Container outputPorts;
private Container valueObjects = new Container(Orientation.VERTICAL);
private Container businessObjects;
private Container businessProcesses;
private Container infrastructureServices;
private Container externalApplicationServices;
private Container applicationComponents;
private Container infrastructure;
private Container externalProviders;
private Container dataObjects;
/*
* // Folders //////////////
*/
private IFolder businessFolder;
private IFolder diagramFolder;
private IFolder infrastructureFolder;
private IFolder motivationFolder;
private IFolder applicationFolder;
private IFolder relationsFolder;
/*
* // PROPERTIES & ARGUMENTS //////////////
*/
private static Path archimateOutputPath;
private static Path inputFileName;
private static Path dotLocation;
private static Path tavernaHome;
private static Path tavernaHomeLib;
private static Path tavernaHomeRepo;
private List<IArchimateElement> nodeElements;
//private static Logger LOGGER = LogManager.getLogger("TavernaExtractor");
private LicenseCheck licenseCheck = new LicenseCheck();
private IArtifact workflowFile;
private ISystemSoftware taverna;
private IApplicationComponent workflowApplicationComponent = null;
private IApplicationFunction callScriptApplicationFunction = null;
private IApplicationFunction callXMLSplitterApplicationFunction = null;
private IApplicationFunction callWebServiceApplicationFunction = null;
private IApplicationFunction callToolInvocationFunction = null;
private IApplicationFunction callXPathApplicationFunction = null;
private Dataflow dataflow;
private SSHManager sshManager;
private static Logger LOGGER = LogManager.getLogger("TavernaExtractor");
private String convertedFileAsString = null;
public TavernaExtractor() {
LOGGER.setLevel(Level.INFO);
}
public TavernaExtractor(boolean verbose) {
if (verbose) {
LOGGER.setLevel(Level.DEBUG);
} else {
LOGGER.setLevel(Level.INFO);
}
}
public TavernaExtractor(SSHManager sshManager) {
this.sshManager = sshManager;
}
/*
* // GETTER & SETTER ///////////////
*/
public void setDotLocation(Path dotLocation) {
TavernaExtractor.dotLocation = dotLocation;
}
public Path getDotLocation() {
return dotLocation;
}
public Path getArchimateOutputPath() {
return archimateOutputPath;
}
public void setArchimateOutputPath(Path archimateOutputPath) {
TavernaExtractor.archimateOutputPath = archimateOutputPath;
}
public Path getInputFileName() {
return inputFileName;
}
public void setInputFileName(Path inputFileName) {
TavernaExtractor.inputFileName = inputFileName;
}
public Path getTavernaHome() {
return tavernaHome;
}
public void setTavernaHome(Path tavernaHome) {
TavernaExtractor.tavernaHome = tavernaHome;
}
public Path getTavernaHomeLib() {
return tavernaHomeLib;
}
public void setTavernaHomeLib(Path tavernaHomeLib) {
TavernaExtractor.tavernaHomeLib = tavernaHomeLib;
}
public Path getTavernaHomeRepo() {
return tavernaHomeRepo;
}
public void setTavernaHomeRepo(Path tavernaHomeRepo) {
TavernaExtractor.tavernaHomeRepo = tavernaHomeRepo;
}
public List<IRelationship> getRelations() {
return this.relations;
}
public List<IArchimateElement> getBusinessProcesses() {
return this.businessProcesses.getElements();
}
public List<IArchimateElement> getBusinessObjects() {
return this.businessObjects.getElements();
}
/*
* // Transform a Taverna (t2flow) file to an Archimate file ///////////////
*/
File tavernaFile = null;
public void process(boolean remote) throws EditException, OpenDataflowException, InvalidOptionException,
InvalidDataflowException, TokenOrderException, ReadInputException, DatabaseConfigurationException,
CMException, IOException, DeserializationException, IterationTypeMismatchException, TavernaExtractorException {
LOGGER.info("Start Taverna Extractor ...");
//setup
this.setTavernaHomeLib(this.getTavernaHome().resolve("lib"));
this.setTavernaHomeRepo(this.getTavernaHome().resolve("repository"));
if (remote)
validateRemoteDirectories(this.getTavernaHome(), this.getTavernaHomeLib(), this.getTavernaHomeRepo());
else
validateDirectories(this.getTavernaHome(), this.getTavernaHomeLib(), this.getTavernaHomeRepo());
LOGGER.info("TavernaHome is set to [" + this.getTavernaHome() + "].");
LOGGER.info("TavernaHomeLib is set to [" + this.getTavernaHomeLib() + "].");
LOGGER.info("TavernaHomeRepo is set to [" + this.getTavernaHomeRepo() + "].");
LOGGER.info("Workflow input file is [" + this.getInputFileName() + "].");
LOGGER.info("Archimate output file is [" + this.getArchimateOutputPath() + "].");
inputPorts = new Container(Orientation.VERTICAL);
outputPorts = new Container(Orientation.VERTICAL);
businessObjects = new Container(Orientation.HORIZONTAL);
businessProcesses = new Container(Orientation.HORIZONTAL);
externalApplicationServices = new Container(Orientation.HORIZONTAL);
infrastructure = new Container(Orientation.HORIZONTAL);
infrastructureServices = new Container(Orientation.HORIZONTAL);
applicationComponents = new Container(Orientation.HORIZONTAL);
externalProviders = new Container(Orientation.HORIZONTAL);
dataObjects = new Container(Orientation.HORIZONTAL);
// project configured JRE!
final String JAVA_VERSION = System.getProperty("java.version");
final String JAVA_VENDOR = System.getProperty("java.vendor");
final String OS_SYSTEM_INFO = System.getProperty("os.name") + " [version=" + System.getProperty("os.version")
+ "] [arch=" + System.getProperty("os.arch") + "]";
nodeElements = new ArrayList<IArchimateElement>();
elementModelObjectMap = new HashMap<String, IDiagramModelArchimateObject>();
relations = new ArrayList<IRelationship>();
if (remote)
dataflow = getDataflowRemote();
else
dataflow = getDataflowLocal();
// current classpath
String classpath = System.getProperty("java.class.path");
String[] classpathEntries = classpath.split(File.pathSeparator);
List<String> cleanClasspathEntries = cleanedClasspath(Arrays.asList(classpathEntries));
factory = IArchimateFactory.eINSTANCE;
IArchimateModel model = factory.createArchimateModel();
model.setDefaults();
model.setName("Converted Taverna Workflow " + inputFileName);
// FOLDERS
businessFolder = model.getFolder(FolderType.BUSINESS);
diagramFolder = model.getFolder(FolderType.DIAGRAMS);
infrastructureFolder = model.getFolder(FolderType.TECHNOLOGY);
motivationFolder = model.getFolder(FolderType.MOTIVATION);
applicationFolder = model.getFolder(FolderType.APPLICATION);
relationsFolder = model.getFolder(FolderType.RELATIONS);
// LAYERED VIEWS
layeredView = factory.createArchimateDiagramModel();
layeredView.setName("Layered View");
layeredView.setViewpoint(IViewpoint.LAYERED_VIEWPOINT);
diagramFolder.getElements().add(layeredView);
// GROUPINGS
businessProcessModelGroup = ArchiLayoutUtils.createSubModelGroup(layeredView, "Business process");
externalApplicationModelGroup = ArchiLayoutUtils.createSubModelGroup(layeredView,
"External Application Services");
applicationComponentModelGroup = ArchiLayoutUtils.createSubModelGroup(layeredView,
"Application Component + Services");
externalInfrastructureModelGroup = ArchiLayoutUtils.createSubModelGroup(layeredView,
"External Infrastructure Services");
infrastructureModelGroup = ArchiLayoutUtils.createSubModelGroup(layeredView, "Infrastructure");
// --- CREATING DEFAULT ELEMENTS ---
desktop = factory.createNode();
desktop.setName("Machine");
// adding XRN
MachineID machineID = new MachineID();
IProperty property = factory.createProperty();
property.setKey("XRN");
property.setValue(machineID.getXRN());
desktop.getProperties().add(property);
infrastructureFolder.getElements().add(desktop);
diagramModelDesktop = factory.createDiagramModelArchimateObject();
diagramModelDesktop.setArchimateElement(desktop);
diagramModelDesktop.setBounds(15, 15, 0, 0);
infrastructure.getElements().add(desktop);
// // BEGIN PATTERN v2.0 UPDATE
// --- BEGIN Taverna ---
taverna = (ISystemSoftware) ArchiUtils.initElement(factory.createSystemSoftware(), "Taverna 2.4", infrastructureFolder,
nodeElements);
IConstraint GNULicense = ArchiUtils.initElement(factory.createConstraint(),
"GNU Lesser General Public License (LGPL) 2.1", motivationFolder, infrastructure);
ArchiUtils.initRelation(factory.createRealisationRelationship(), taverna, GNULicense, relationsFolder,
relations);
ArchiUtils.initRelation(factory.createCompositionRelationship(), desktop, taverna, relationsFolder,
relations);
// Workflow file
workflowFile = (IArtifact) ArchiUtils.initElement(factory.createArtifact(), "Worfklow File",
infrastructureFolder, nodeElements);
ArchiUtils.initAccessRelation(factory.createAccessRelationship(), taverna,
workflowFile, applicationFolder, relations, IAccessRelationship.READ_ACCESS);
ArchiUtils.initRelation(factory.createCompositionRelationship(), desktop, workflowFile, relationsFolder,
relations);
workflowFile.getProperties().add(createDepProperties(this.getInputFileName().toString()));
// Orchestration Service
parentProcessWorkflow = ArchiUtils.initElement(factory.createBusinessProcess(), dataflow.getLocalName()
+ " Process", businessFolder, businessProcesses);
workflowApplicationComponent = ArchiUtils.initElement(factory.createApplicationComponent(),
"Workflow Execution Environment", applicationFolder, applicationComponents);
ArchiUtils.initRelation(factory.createRealisationRelationship(), taverna, workflowApplicationComponent,
relationsFolder, relations);
// add dependable Taverna jars from classpath
for (String jar : cleanClasspathEntries) {
taverna.getProperties().add(createDepProperties(jar));
}
// link relevant dependencies from taverna home to context model
IArtifact repoBundle = (IArtifact) ArchiUtils.initElement(factory.createArtifact(), "Repo Bundle", infrastructureFolder, nodeElements);
ArchiUtils.initRelation(factory.createAssociationRelationship(), taverna, repoBundle,
relationsFolder, relations);
ArchiUtils.initRelation(factory.createCompositionRelationship(), desktop, repoBundle,
relationsFolder, relations);
if (this.getTavernaHomeRepo().toFile().isDirectory()) {
final List<File> jarFiles = new ArrayList<>();
final PathMatcher matcher = FileSystems.getDefault()
.getPathMatcher("glob:*.jar");
Files.walkFileTree(this.getTavernaHomeRepo(), new FileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes basicFileAttributes) throws IOException {
return CONTINUE;
}
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException {
if (path != null && matcher.matches(path.getFileName())) {
jarFiles.add(path.toFile());
}
return CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path path, IOException e) throws IOException {
return CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path path, IOException e) throws IOException {
return CONTINUE;
}
});
for (File jarDep : jarFiles) {
String jarLocation = jarDep.getAbsolutePath();
repoBundle.getProperties().add(createDepProperties(jarLocation));
}
} else {
LOGGER.error("ERROR: " + this.getTavernaHomeRepo().toFile() + " is not a directory. No further dependecies processing.");
}
// --- END Taverna ---
// --- BEGIN Events ---
// Start Event
startEvent = ArchiUtils.initElement(factory.createBusinessEvent(), "Start Experiment", businessFolder,
businessProcesses);
// End Event
endEvent = ArchiUtils.initElement(factory.createBusinessEvent(), "Experiment End", businessFolder,
businessProcesses);
// --- END Events ---
// --- BEGIN Java Runtime Environment ---
ISystemSoftware java = (ISystemSoftware) ArchiUtils.initElement(factory.createSystemSoftware(), "JRE "
+ JAVA_VERSION + " (" + JAVA_VENDOR + ")", infrastructureFolder, nodeElements);
// FIXME: this must not always be an ORACLE license
IConstraint oracleLicense = ArchiUtils.initElement(factory.createConstraint(), "Oracle Binary Code License",
motivationFolder, infrastructure);
ArchiUtils.initRelation(factory.createRealisationRelationship(), java, oracleLicense, relationsFolder,
relations);
ArchiUtils.initRelation(factory.createUsedByRelationship(), java, taverna, relationsFolder, relations);
ArchiUtils.initRelation(factory.createCompositionRelationship(), desktop, java, relationsFolder, relations);
// --- BEGIN OS ---
ISystemSoftware operatingSystem = (ISystemSoftware) ArchiUtils.initElement(factory.createSystemSoftware(),
OS_SYSTEM_INFO, infrastructureFolder, nodeElements);
ArchiUtils.initRelationNodeElement(factory.createUsedByRelationship(), operatingSystem, java, relationsFolder,
nodeElements);
ArchiUtils.initRelation(factory.createCompositionRelationship(), desktop, operatingSystem, relationsFolder, relations);
// --- END CREATING DEFAULT ELEMENTS ---
LOGGER.debug("Process Input ports");
for (DataflowInputPort inputPort : dataflow.getInputPorts()) {
IBusinessObject port_business = ArchiUtils.initElement(factory.createBusinessObject(), inputPort.getName(),
businessFolder, inputPorts);
IDataObject port_data = ArchiUtils.initElement(factory.createDataObject(), inputPort.getName(),
applicationFolder, dataObjects);
IArchimateElement port_infrastructure = ArchiUtils.initElement(factory.createArtifact(),
inputPort.getName(), infrastructureFolder, infrastructure);
business2dataMap.put(port_business, port_data);
ArchiUtils.initRelation(factory.createRealisationRelationship(), port_data, port_business, relationsFolder,
relations);
ArchiUtils.initRelation(factory.createRealisationRelationship(), port_infrastructure, port_data,
relationsFolder, relations);
ArchiUtils.initRelation(factory.createCompositionRelationship(), desktop, port_infrastructure,
relationsFolder, relations);
}
LOGGER.debug("Process Output ports");
for (DataflowOutputPort outputPort : dataflow.getOutputPorts()) {
IBusinessObject port_business = ArchiUtils.initElement(factory.createBusinessObject(),
outputPort.getName(), businessFolder, outputPorts);
IDataObject port_data = ArchiUtils.initElement(factory.createDataObject(), outputPort.getName(),
applicationFolder, dataObjects);
IArchimateElement port_infrastructure = ArchiUtils.initElement(factory.createArtifact(),
outputPort.getName(), infrastructureFolder, infrastructure);
business2dataMap.put(port_business, port_data);
ArchiUtils.initRelation(factory.createRealisationRelationship(), port_data, port_business, relationsFolder,
relations);
ArchiUtils.initRelation(factory.createRealisationRelationship(), port_infrastructure, port_data,
relationsFolder, relations);
ArchiUtils.initRelation(factory.createCompositionRelationship(), desktop, port_infrastructure,
relationsFolder, relations);
}
processorProcessMap = new HashMap<Processor, IBusinessProcess>();
processorValueMap = new HashMap<Processor, IBusinessObject>();
//
// first pass - get all Processors, and map them to IBusinessProcess, create business objects
//
treatProcessors(dataflow.getProcessors());
//
// (extend second pass) - redirect relations in case of multiple incoming ports
//
for (Entry<Processor, IAndJunction> entry : processorInputMap.entrySet()) {
Processor targetProcessor = entry.getKey();
IAndJunction andJunction = entry.getValue();
IBusinessProcess targetProcess = processorProcessMap.get(targetProcessor);
// detect incoming triggering relations
List<IRelationship> incomingTriggeringRelations = ArchiUtils.ofClass(relations,
ITriggeringRelationship.class, targetProcess, false);
List<IArchimateElement> sourceElements = ArchiUtils.getSourceElements(incomingTriggeringRelations);
// remove the original incoming relations
ArchiUtils.removeRelation(incomingTriggeringRelations, relations, relationsFolder);
// reconnect relations to AND junction
for (IArchimateElement sourceElement : sourceElements) {
ArchiUtils.initRelation(factory.createTriggeringRelationship(), sourceElement, andJunction,
relationsFolder, relations);
}
// create new relation
ArchiUtils.initRelation(factory.createTriggeringRelationship(), andJunction, targetProcess,
relationsFolder, relations);
}
//
// third pass - detail process steps on other layers
//
detailProcessorsOnLayers(dataflow.getProcessors());
// drawing archimate elements and relations
drawBusinessProcessGroup();
drawExternalApplicationServices();
drawApplicationComponentServices();
drawExternalInfrastructureServices();
drawInfrastructure();
drawExternalProviders();
drawRelations();
// set size of main process diagram element to hold all others
int padding = 5;
IBounds outerBounds = processStepsModelGroup.getBounds();
processStepsModelGroup.setBounds(outerBounds.getX() - padding / 2, outerBounds.getY(), outerBounds.getWidth()
+ padding, outerBounds.getHeight() + 10);
IDiagramModelArchimateObject processDiagramObject = elementModelObjectMap.get(parentProcessWorkflow.getId());
processDiagramObject.setBounds(padding, padding, outerBounds.getWidth() - padding * 2, outerBounds.getHeight()
- padding * 2);
if (remote)
saveRemote(model);
else
saveLocal(model);
}
public void processWebServiceActivity(IFolder businessFolder, IFolder infrastructureFolder,
IFolder applicationFolder, IFolder relationsFolder, IApplicationComponent workflowApplicationComponent,
HashMap<Processor, IBusinessProcess> processorProcessMap,
IApplicationFunction callWebServiceApplicationFunction, Processor processor, String processorName,
Activity<?> a) {
// external service provider
INode externalNode = ArchiUtils.initElement(factory.createNode(), "External Service", infrastructureFolder,
externalProviders);
String type = null;
IProperty prop = factory.createProperty();
IProperty locationProp = factory.createProperty();
if (a instanceof WSDLActivity) {
LOGGER.debug("WSDL Service found = " + processor.getLocalName());
type = "SOAP";
WSDLActivity wsdlActivity = (WSDLActivity) a;
prop.setKey("WSDL_Location");
prop.setValue(wsdlActivity.getConfiguration().getWsdl());
externalNode.getProperties().add(prop);
locationProp = createDepProperties(WSDLActivity.class);
}
if (a instanceof RESTActivity) {
LOGGER.debug("RESTful Service found = " + processor.getLocalName());
type = "HTTP";
RESTActivity restActivity = (RESTActivity) a;
prop.setKey("URL");
prop.setValue(restActivity.getConfiguration().getUrlSignature());
externalNode.getProperties().add(prop);
locationProp = createDepProperties(RESTActivity.class);
}
// create archimate function call only once
if (callWebServiceApplicationFunction == null) {
callWebServiceApplicationFunction = ArchiUtils.initElement(factory.createApplicationFunction(),
"Calling Web Service", applicationFolder, applicationComponents);
ArchiUtils.initRelation(factory.createAssignmentRelationship(), callWebServiceApplicationFunction,
workflowApplicationComponent, relationsFolder, relations);
ArchiUtils.initRelation(factory.createUsedByRelationship(), workflowFile,
callWebServiceApplicationFunction, relationsFolder, relations);
ArchiUtils.initRelation(factory.createRealisationRelationship(), taverna,
callWebServiceApplicationFunction, relationsFolder, relations);
}
IApplicationInterface appIf = ArchiUtils.initElement(factory.createApplicationInterface(), type,
applicationFolder, externalApplicationServices);
IApplicationService appService = ArchiUtils.initElement(factory.createApplicationService(), processorName
+ "Service", applicationFolder, externalApplicationServices);
appService.getProperties().add(locationProp);
ArchiUtils.initRelation(factory.createUsedByRelationship(), appService, processorProcessMap.get(processor),
relationsFolder, relations);
// used-by relation between business processor and application function
ArchiUtils.initRelation(factory.createUsedByRelationship(), callWebServiceApplicationFunction,
processorProcessMap.get(processor), relationsFolder, relations);
ArchiUtils.initRelation(factory.createAssignmentRelationship(), appService, appIf, relationsFolder, relations);
// creating request response data objects
for (IArchimateElement inputElement : ArchiUtils.getInputElementsOfProcess(processorProcessMap.get(processor),
relations)) {
if (!business2dataMap.containsKey(inputElement)) {
IDataObject requestObject = ArchiUtils.initElement(factory.createDataObject(), inputElement.getName()
+ "(Request)", applicationFolder, applicationComponents);
business2dataMap.put((IBusinessObject) inputElement, requestObject);
ArchiUtils.initRelation(factory.createRealisationRelationship(), requestObject, inputElement,
relationsFolder, relations);
}
ArchiUtils.initAccessRelation(factory.createAccessRelationship(), appService,
business2dataMap.get(inputElement), applicationFolder, relations, IAccessRelationship.READ_ACCESS);
}
for (IArchimateElement outputElement : ArchiUtils.getOutputElementsOfProcess(
processorProcessMap.get(processor), relations)) {
if (!business2dataMap.containsKey(outputElement)) {
IDataObject responseObject = ArchiUtils.initElement(factory.createDataObject(), outputElement.getName()
+ "(Response)", applicationFolder, applicationComponents);
business2dataMap.put((IBusinessObject) outputElement, responseObject);
ArchiUtils.initRelation(factory.createRealisationRelationship(), responseObject, outputElement,
relationsFolder, relations);
}
ArchiUtils
.initAccessRelation(factory.createAccessRelationship(), appService,
business2dataMap.get(outputElement), applicationFolder, relations,
IAccessRelationship.WRITE_ACCESS);
}
ArchiUtils.initRelation(factory.createRealisationRelationship(), externalNode, appService, relationsFolder,
relations);
}
public void processRShellActivity(IFolder businessFolder, IFolder infrastructureFolder, IFolder applicationFolder,
IFolder relationsFolder, IApplicationComponent workflowApplicationComponent,
HashMap<Processor, IBusinessProcess> processorProcessMap,
IApplicationFunction callWebServiceApplicationFunction, Processor processor, String processorName,
Activity<?> a) {
if (!(a instanceof RshellActivity)) {
LOGGER.info("Activity [" + a + "] is not an instance of RshellActivity. Stop further processing!");
return;
}
RshellActivity rshellActivity = (RshellActivity) a;
// create archimate function call only once
if (callToolInvocationFunction == null) {
callToolInvocationFunction = ArchiUtils.initElement(factory.createApplicationFunction(),
"Tool Invocation Service", applicationFolder, applicationComponents);
ArchiUtils.initRelation(factory.createAssignmentRelationship(), callToolInvocationFunction,
workflowApplicationComponent, relationsFolder, relations);
ArchiUtils.initRelation(factory.createUsedByRelationship(), workflowFile, callToolInvocationFunction,
relationsFolder, relations);
ArchiUtils.initRelation(factory.createRealisationRelationship(), taverna, callToolInvocationFunction,
relationsFolder, relations);
}
IApplicationService appService = ArchiUtils.initElement(factory.createApplicationService(), processorName
+ "Service", applicationFolder, externalApplicationServices);
appService.getProperties().add(createDepProperties(RshellActivity.class));
ArchiUtils.initRelation(factory.createUsedByRelationship(), appService, processorProcessMap.get(processor),
relationsFolder, relations);
// used-by relation between business processor and application function
ArchiUtils.initRelation(factory.createUsedByRelationship(), callToolInvocationFunction,
processorProcessMap.get(processor), relationsFolder, relations);
// creating input output data objects
for (IArchimateElement inputElement : ArchiUtils.getInputElementsOfProcess(processorProcessMap.get(processor),
relations)) {
if (!business2dataMap.containsKey(inputElement)) {
IDataObject requestObject = ArchiUtils.initElement(factory.createDataObject(), inputElement.getName()
+ "(Input)", applicationFolder, applicationComponents);
business2dataMap.put((IBusinessObject) inputElement, requestObject);
ArchiUtils.initRelation(factory.createRealisationRelationship(), requestObject, inputElement,
relationsFolder, relations);
}
ArchiUtils.initAccessRelation(factory.createAccessRelationship(), appService,
business2dataMap.get(inputElement), applicationFolder, relations, IAccessRelationship.READ_ACCESS);
}
for (IArchimateElement outputElement : ArchiUtils.getOutputElementsOfProcess(
processorProcessMap.get(processor), relations)) {
if (!business2dataMap.containsKey(outputElement)) {
IDataObject responseObject = ArchiUtils.initElement(factory.createDataObject(), outputElement.getName()
+ "(Output)", applicationFolder, applicationComponents);
business2dataMap.put((IBusinessObject) outputElement, responseObject);
ArchiUtils.initRelation(factory.createRealisationRelationship(), responseObject, outputElement,
relationsFolder, relations);
}
ArchiUtils
.initAccessRelation(factory.createAccessRelationship(), appService,
business2dataMap.get(outputElement), applicationFolder, relations,
IAccessRelationship.WRITE_ACCESS);
}
IApplicationInterface appIf = ArchiUtils.initElement(factory.createApplicationInterface(), "SSH",
applicationFolder, externalApplicationServices);
INode externalNode = ArchiUtils.initElement(factory.createNode(), "External Service", infrastructureFolder,
externalProviders);
ArchiUtils.initRelation(factory.createAssignmentRelationship(), appService, appIf, relationsFolder, relations);
ArchiUtils.initRelation(factory.createRealisationRelationship(), externalNode, appService, relationsFolder,
relations);
List<IProperty> props = createPropertiesOutOfRshellConfig(rshellActivity.getConfiguration());
externalNode.getProperties().addAll(props);
}
public void processToolActivity(IFolder businessFolder, IFolder infrastructureFolder, IFolder applicationFolder,
IFolder relationsFolder, IApplicationComponent workflowApplicationComponent,
HashMap<Processor, IBusinessProcess> processorProcessMap,
IApplicationFunction callWebServiceApplicationFunction, Processor processor, String processorName,
Activity<?> a, boolean isExternal) {
if (!(a instanceof ExternalToolActivity)) {
LOGGER.info("Activity [" + a + "] is not an instance of ExternalToolActivity. Stop further processing!");
return;
}
ExternalToolActivity externalInvocation = (ExternalToolActivity) a;
// create archimate function call only once
if (callToolInvocationFunction == null) {
callToolInvocationFunction = ArchiUtils.initElement(factory.createApplicationFunction(),
"Tool Invocation Service", applicationFolder, applicationComponents);
ArchiUtils.initRelation(factory.createAssignmentRelationship(), callToolInvocationFunction,
workflowApplicationComponent, relationsFolder, relations);
ArchiUtils.initRelation(factory.createUsedByRelationship(), workflowFile, callToolInvocationFunction,
relationsFolder, relations);
ArchiUtils.initRelation(factory.createRealisationRelationship(), taverna, callToolInvocationFunction,
relationsFolder, relations);
}
IApplicationService appService = isExternal ? ArchiUtils.initElement(factory.createApplicationService(),
processorName + "Service", applicationFolder, externalApplicationServices) : ArchiUtils
.initElement(factory.createApplicationService(), processorName + "Service", applicationFolder,
applicationComponents);
appService.getProperties().add(createDepProperties(ExternalToolActivity.class));
ArchiUtils.initRelation(factory.createUsedByRelationship(), appService, processorProcessMap.get(processor),
relationsFolder, relations);
// used-by relation between business processor and application function
ArchiUtils.initRelation(factory.createUsedByRelationship(), callToolInvocationFunction,
processorProcessMap.get(processor), relationsFolder, relations);
// creating input output data objects
for (IArchimateElement inputElement : ArchiUtils.getInputElementsOfProcess(processorProcessMap.get(processor),
relations)) {
if (!business2dataMap.containsKey(inputElement)) {
IDataObject requestObject = ArchiUtils.initElement(factory.createDataObject(), inputElement.getName()
+ "(Input)", applicationFolder, applicationComponents);
business2dataMap.put((IBusinessObject) inputElement, requestObject);
ArchiUtils.initRelation(factory.createRealisationRelationship(), requestObject, inputElement,
relationsFolder, relations);
}
ArchiUtils.initAccessRelation(factory.createAccessRelationship(), appService,
business2dataMap.get(inputElement), applicationFolder, relations, IAccessRelationship.READ_ACCESS);
}
for (IArchimateElement outputElement : ArchiUtils.getOutputElementsOfProcess(
processorProcessMap.get(processor), relations)) {
if (!business2dataMap.containsKey(outputElement)) {
IDataObject responseObject = ArchiUtils.initElement(factory.createDataObject(), outputElement.getName()
+ "(Output)", applicationFolder, applicationComponents);
business2dataMap.put((IBusinessObject) outputElement, responseObject);
ArchiUtils.initRelation(factory.createRealisationRelationship(), responseObject, outputElement,
relationsFolder, relations);
}
ArchiUtils
.initAccessRelation(factory.createAccessRelationship(), appService,
business2dataMap.get(outputElement), applicationFolder, relations,
IAccessRelationship.WRITE_ACCESS);
}
if (isExternal) {
IApplicationInterface appIf = ArchiUtils.initElement(factory.createApplicationInterface(), "SSH",
applicationFolder, externalApplicationServices);
INode externalNode = ArchiUtils.initElement(factory.createNode(), "External Service", infrastructureFolder,
externalProviders);
ArchiUtils.initRelation(factory.createAssignmentRelationship(), appService, appIf, relationsFolder,
relations);
ArchiUtils.initRelation(factory.createRealisationRelationship(), externalNode, appService, relationsFolder,
relations);
List<IProperty> props = createPropertiesOutOfXMLMechanism(externalInvocation.getConfiguration());
externalNode.getProperties().addAll(props);
} else {
IArtifact toolAsArtifact = (IArtifact) ArchiUtils.initElement(factory.createArtifact(), "Tool",
infrastructureFolder, nodeElements);
ArchiUtils.initRelation(factory.createRealisationRelationship(), toolAsArtifact, appService,
relationsFolder, relations);
ArchiUtils.initRelation(factory.createCompositionRelationship(), desktop, toolAsArtifact,
relationsFolder, relations);
IProperty commandProperty = factory.createProperty();
commandProperty.setKey("Command");
commandProperty.setValue(externalInvocation.getConfiguration().getUseCaseDescription().getCommand());
toolAsArtifact.getProperties().add(commandProperty);
}
}
public void processXMLSplitterActivity(IFolder infrastructureFolder, IFolder motivationFolder,
IFolder applicationFolder, IFolder relationsFolder, IApplicationComponent workflowApplicationComponent,
HashMap<Processor, IBusinessProcess> processorProcessMap, Processor processor, Activity<?> a)
throws IOException {
LOGGER.debug("XML splitter found = " + processor.getLocalName());
// create external application service for each business process/function
if (callXMLSplitterApplicationFunction == null) {
callXMLSplitterApplicationFunction = ArchiUtils.initElement(factory.createApplicationFunction(),
"XML Splitter Built-In Service", applicationFolder, applicationComponents);
ArchiUtils.initRelation(factory.createAssignmentRelationship(), callXMLSplitterApplicationFunction,
workflowApplicationComponent, relationsFolder, relations);
ArchiUtils.initRelation(factory.createRealisationRelationship(), taverna, callXMLSplitterApplicationFunction,
relationsFolder, relations);
}
IApplicationService appService = ArchiUtils.initElement(factory.createApplicationService(),
processor.getLocalName(), applicationFolder, externalApplicationServices);
appService.getProperties().add(createDepProperties(XMLInputSplitterActivity.class));
ArchiUtils.initRelation(factory.createUsedByRelationship(), appService, processorProcessMap.get(processor),
relationsFolder, relations);
ArchiUtils.initRelation(factory.createUsedByRelationship(), callXMLSplitterApplicationFunction,
processorProcessMap.get(processor), relationsFolder, relations);
LOGGER.debug("Get input elements of process "+ArchiUtils.getInputElementsOfProcess(processorProcessMap.get(processor),
relations).size());
// creating request response data objects
for (IArchimateElement inputElement : ArchiUtils.getInputElementsOfProcess(processorProcessMap.get(processor),
relations)) {
LOGGER.debug("inputElement = "+inputElement.getName());
if (!business2dataMap.containsKey(inputElement)) {
IDataObject requestObject = ArchiUtils.initElement(factory.createDataObject(), inputElement.getName(),
applicationFolder, applicationComponents);
business2dataMap.put((IBusinessObject) inputElement, requestObject);
ArchiUtils.initRelation(factory.createRealisationRelationship(), requestObject, inputElement,
relationsFolder, relations);
}
ArchiUtils.initAccessRelation(factory.createAccessRelationship(), appService,
business2dataMap.get(inputElement), applicationFolder, relations, IAccessRelationship.READ_ACCESS);
}
LOGGER.debug("Get output elements of process "+ArchiUtils.getInputElementsOfProcess(processorProcessMap.get(processor),
relations).size());
for (IArchimateElement outputElement : ArchiUtils.getOutputElementsOfProcess(
processorProcessMap.get(processor), relations)) {
LOGGER.debug("inputElement = "+outputElement.getName());
if (!business2dataMap.containsKey(outputElement)) {
IDataObject responseObject = ArchiUtils.initElement(factory.createDataObject(),
outputElement.getName(), applicationFolder, applicationComponents);
ArchiUtils.initRelation(factory.createRealisationRelationship(), responseObject, outputElement,
relationsFolder, relations);
business2dataMap.put((IBusinessObject) outputElement, responseObject);
}
ArchiUtils
.initAccessRelation(factory.createAccessRelationship(), appService,
business2dataMap.get(outputElement), applicationFolder, relations,
IAccessRelationship.WRITE_ACCESS);
}
}
public void processXPathActivity(IFolder infrastructureFolder, IFolder motivationFolder,
IFolder applicationFolder, IFolder relationsFolder, IApplicationComponent workflowApplicationComponent,
HashMap<Processor, IBusinessProcess> processorProcessMap, Processor processor, Activity<?> a)
throws IOException {
//beanshellScripts.add((BeanshellActivity) a);
LOGGER.debug("XPath script found = " + processor.getLocalName());
//XPathActivity xPathActivity = (XPathActivity) a;
// create external application service for each business process/function
if (callXPathApplicationFunction == null) {
callXPathApplicationFunction = ArchiUtils.initElement(factory.createApplicationFunction(),
"XPath Built-In Service", applicationFolder, applicationComponents);
ArchiUtils.initRelation(factory.createAssignmentRelationship(), callXPathApplicationFunction,
workflowApplicationComponent, relationsFolder, relations);
ArchiUtils.initRelation(factory.createRealisationRelationship(), taverna, callXPathApplicationFunction,
relationsFolder, relations);
}
IApplicationService appService = ArchiUtils.initElement(factory.createApplicationService(),
processor.getLocalName(), applicationFolder, externalApplicationServices);
appService.getProperties().add(createDepProperties(BeanshellActivity.class));
ArchiUtils.initRelation(factory.createUsedByRelationship(), appService, processorProcessMap.get(processor),
relationsFolder, relations);
ArchiUtils.initRelation(factory.createUsedByRelationship(), callXPathApplicationFunction,
processorProcessMap.get(processor), relationsFolder, relations);
IArtifact script = (IArtifact) ArchiUtils.initElement(factory.createArtifact(), processor.getLocalName()
, infrastructureFolder, nodeElements);
XPathActivityConfigurationBean c = (XPathActivityConfigurationBean) a.getConfiguration();
String ex = c.getXpathExpression() != null ? c.getXpathExpression() : "NO_EXPRESSION_AVAILABLE";
String doc = c.getXmlDocument() != null ? c.getXmlDocument() : "NO_XML_DOCUMENT_AVAILABLE";
IProperty property = factory.createProperty();
property.setKey("expression");
property.setValue(ex);
script.getProperties().add(property);
IProperty property_document = factory.createProperty();
property_document.setKey("document");
property_document.setValue(doc);
script.getProperties().add(property_document);
ArchiUtils.initRelation(factory.createCompositionRelationship(), workflowFile, script, relationsFolder,
relations);
ArchiUtils
.initRelation(factory.createRealisationRelationship(), script, appService, relationsFolder, relations);
// creating request response data objects
for (IArchimateElement inputElement : ArchiUtils.getInputElementsOfProcess(processorProcessMap.get(processor),
relations)) {
if (!business2dataMap.containsKey(inputElement)) {
IDataObject requestObject = ArchiUtils.initElement(factory.createDataObject(), inputElement.getName(),
applicationFolder, applicationComponents);
business2dataMap.put((IBusinessObject) inputElement, requestObject);
ArchiUtils.initRelation(factory.createRealisationRelationship(), requestObject, inputElement,
relationsFolder, relations);
}
ArchiUtils.initAccessRelation(factory.createAccessRelationship(), appService,
business2dataMap.get(inputElement), applicationFolder, relations, IAccessRelationship.READ_ACCESS);
}
for (IArchimateElement outputElement : ArchiUtils.getOutputElementsOfProcess(
processorProcessMap.get(processor), relations)) {
if (!business2dataMap.containsKey(outputElement)) {
IDataObject responseObject = ArchiUtils.initElement(factory.createDataObject(),
outputElement.getName(), applicationFolder, applicationComponents);
ArchiUtils.initRelation(factory.createRealisationRelationship(), responseObject, outputElement,
relationsFolder, relations);
business2dataMap.put((IBusinessObject) outputElement, responseObject);
}
ArchiUtils
.initAccessRelation(factory.createAccessRelationship(), appService,
business2dataMap.get(outputElement), applicationFolder, relations,
IAccessRelationship.WRITE_ACCESS);
}
}
public void processBeanshellActivity(IFolder infrastructureFolder, IFolder motivationFolder,
IFolder applicationFolder, IFolder relationsFolder, IApplicationComponent workflowApplicationComponent,
HashMap<Processor, IBusinessProcess> processorProcessMap, Processor processor, Activity<?> a)
throws IOException {
beanshellScripts.add((BeanshellActivity) a);
LOGGER.debug("Beanshell script found = " + processor.getLocalName());
// create external application service for each business process/function
if (callScriptApplicationFunction == null) {
callScriptApplicationFunction = ArchiUtils.initElement(factory.createApplicationFunction(),
"Calling Script", applicationFolder, applicationComponents);
ArchiUtils.initRelation(factory.createAssignmentRelationship(), callScriptApplicationFunction,
workflowApplicationComponent, relationsFolder, relations);
ArchiUtils.initRelation(factory.createRealisationRelationship(), taverna, callScriptApplicationFunction,
relationsFolder, relations);
}
IApplicationService appService = ArchiUtils.initElement(factory.createApplicationService(),
processor.getLocalName(), applicationFolder, externalApplicationServices);
appService.getProperties().add(createDepProperties(BeanshellActivity.class));
ArchiUtils.initRelation(factory.createUsedByRelationship(), appService, processorProcessMap.get(processor),
relationsFolder, relations);
ArchiUtils.initRelation(factory.createUsedByRelationship(), callScriptApplicationFunction,
processorProcessMap.get(processor), relationsFolder, relations);
IArtifact script = (IArtifact) ArchiUtils.initElement(factory.createArtifact(), processor.getLocalName()
+ "Script", infrastructureFolder, nodeElements);
ArchiUtils.initRelation(factory.createCompositionRelationship(), workflowFile, script, relationsFolder,
relations);
ArchiUtils
.initRelation(factory.createRealisationRelationship(), script, appService, relationsFolder, relations);
// creating request response data objects
for (IArchimateElement inputElement : ArchiUtils.getInputElementsOfProcess(processorProcessMap.get(processor),
relations)) {
if (!business2dataMap.containsKey(inputElement)) {
IDataObject requestObject = ArchiUtils.initElement(factory.createDataObject(), inputElement.getName(),
applicationFolder, applicationComponents);
business2dataMap.put((IBusinessObject) inputElement, requestObject);
ArchiUtils.initRelation(factory.createRealisationRelationship(), requestObject, inputElement,
relationsFolder, relations);
}
ArchiUtils.initAccessRelation(factory.createAccessRelationship(), appService,
business2dataMap.get(inputElement), applicationFolder, relations, IAccessRelationship.READ_ACCESS);
}
for (IArchimateElement outputElement : ArchiUtils.getOutputElementsOfProcess(
processorProcessMap.get(processor), relations)) {
if (!business2dataMap.containsKey(outputElement)) {
IDataObject responseObject = ArchiUtils.initElement(factory.createDataObject(),
outputElement.getName(), applicationFolder, applicationComponents);
ArchiUtils.initRelation(factory.createRealisationRelationship(), responseObject, outputElement,
relationsFolder, relations);
business2dataMap.put((IBusinessObject) outputElement, responseObject);
}
ArchiUtils
.initAccessRelation(factory.createAccessRelationship(), appService,
business2dataMap.get(outputElement), applicationFolder, relations,
IAccessRelationship.WRITE_ACCESS);
}
BeanshellActivity bs = (BeanshellActivity) a;
BeanshellActivityConfigurationBean conf = bs.getConfiguration();
// one or more physical dependencies
if (conf.getLocalDependencies().size() > 0) {
Iterator<String> iter = conf.getLocalDependencies().iterator();
while (iter.hasNext()) {
String item = iter.next();
LOGGER.debug("\t Dependency for " + processor.getLocalName() + " [" + item + "]");
IArtifact beanshellScriptDep = (IArtifact) ArchiUtils.initElement(factory.createArtifact(), item,
infrastructureFolder, nodeElements);
ArchiUtils.initRelation(factory.createAssociationRelationship(), script, beanshellScriptDep,
relationsFolder);
ArchiUtils.initRelation(factory.createCompositionRelationship(), beanshellScriptDep, desktop,
relationsFolder);
// Do the license checking
String fileName = this.getTavernaHomeLib() + File.separator + item;
IProperty jarLocation = factory.createProperty();
jarLocation.setKey("hasSourceLocation");
jarLocation.setValue(fileName);
beanshellScriptDep.getProperties().add(jarLocation);
// do proper checking whether the file exists !
Path pathToDep = Paths.get(fileName);
if (Files.exists(pathToDep)) {
String license = licenseCheck.extract(pathToDep.toAbsolutePath().toString());
if (license.equals("Unknown license")) {
LOGGER.debug("\t Unknown license for dependency [" + item + "].");
}
if (license != null && !license.equals("Unknown license")) {
LOGGER.debug("\t Found license [" + license + "] for dependency [" + item + "].");
// create constraint element for dependency
IConstraint licenseConstraint = ArchiUtils.initElement(factory.createConstraint(), license,
motivationFolder, infrastructure);
ArchiUtils.initRelation(factory.createRealisationRelationship(), beanshellScriptDep,
licenseConstraint, relationsFolder, relations);
}
} else {
LOGGER.error("\t ERROR: Jar file [" + fileName + "] not found!");
}
}
}
}
private void drawBusinessProcessGroup() {
int maxX = 15;
int maxY = 15;
int defaultGroupWidth = 130;
int defaultGroupHeight = ArchiLayoutUtils.DEFAULT_ELEMENT_HEIGHT + 10;
businessProcessModelGroup.setBounds(0, 0, 0, 0);
// --- draw input ports ---
IDiagramModelGroup group_inputObjects = factory.createDiagramModelGroup();
group_inputObjects.setName("Input Ports");
businessProcessModelGroup.getChildren().add(group_inputObjects);
group_inputObjects.setBounds(15, 15, defaultGroupWidth, defaultGroupHeight * inputPorts.getElements().size());
Map<String, int[]> boundsMap = ArchiLayoutUtils.getBoundsForElements(inputPorts.getElements(),
inputPorts.getOrientation());
for (IArchimateElement inputPort : inputPorts.getElements()) {
IDiagramModelArchimateObject diagramModelBusinessObject = factory.createDiagramModelArchimateObject();
diagramModelBusinessObject.setArchimateElement(inputPort);
int[] bounds = boundsMap.get(inputPort.getId());
Dimension elementSize = ArchiLayoutUtils.getElementSize(inputPort);
diagramModelBusinessObject.setBounds(bounds[0], bounds[1] + 10, elementSize.width, elementSize.height);
group_inputObjects.getChildren().add(diagramModelBusinessObject);
elementModelObjectMap.put(inputPort.getId(), diagramModelBusinessObject);
}
ArchiLayoutUtils.resize(group_inputObjects);
maxY += ArchiLayoutUtils.getLowerEdgePosition(group_inputObjects);
maxX += ArchiLayoutUtils.getRightEdgePosition(group_inputObjects);
// --- draw value processors ---
if (valueObjects.getElements().size() > 0) { // only draw a group if elements exists
IDiagramModelGroup groupValueProcessors = factory.createDiagramModelGroup();
groupValueProcessors.setName("Constants Input Ports");
businessProcessModelGroup.getChildren().add(groupValueProcessors);
groupValueProcessors.setBounds(15, maxY, defaultGroupWidth, defaultGroupHeight
* valueObjects.getElements().size());
boundsMap = ArchiLayoutUtils
.getBoundsForElements(valueObjects.getElements(), valueObjects.getOrientation());
for (IArchimateElement valueProcessor : valueObjects.getElements()) {
IDiagramModelArchimateObject diagramModelBusinessObject = factory.createDiagramModelArchimateObject();
diagramModelBusinessObject.setArchimateElement(valueProcessor);
int[] bounds = boundsMap.get(valueProcessor.getId());
Dimension elementSize = ArchiLayoutUtils.getElementSize(valueProcessor);
diagramModelBusinessObject.setBounds(bounds[0], bounds[1] + 10, elementSize.width, elementSize.height);
groupValueProcessors.getChildren().add(diagramModelBusinessObject);
elementModelObjectMap.put(valueProcessor.getId(), diagramModelBusinessObject);
}
ArchiLayoutUtils.resize(groupValueProcessors);
maxY += ArchiLayoutUtils.getLowerEdgePosition(groupValueProcessors);
maxX = Math.max(maxX, ArchiLayoutUtils.getRightEdgePosition(groupValueProcessors));
}
// --- draw business objects ---
IDiagramModelGroup group_businessObjects = ArchiLayoutUtils.createSubModelGroup(businessProcessModelGroup,
"Business Objects");
group_businessObjects.setBounds(maxX, 15, 0, 0);
boundsMap = ArchiLayoutUtils.getBoundsForElements(businessObjects.getElements(),
businessObjects.getOrientation());
for (Entry<List<IArchimateElement>, List<IArchimateElement>> group : ArchiUtils.groupElements(
getBusinessProcesses(), relations).entrySet()) {
List<IArchimateElement> elementsInGroup = group.getValue();
IBusinessObject parentBusinessObject = null;
IDiagramModelArchimateObject diagramModelBusinessObjectParent = null;
if (elementsInGroup.size() >= MIN_ELEMENTS_FOR_GROUPING) {
String elementName = group.getKey().get(0).getName() + "=>" + group.getKey().get(1).getName();
parentBusinessObject = ArchiUtils.initElement(factory.createBusinessObject(), elementName,
businessFolder, businessObjects);
parentBusinessObject.setName(elementName);
diagramModelBusinessObjectParent = factory.createDiagramModelArchimateObject();
diagramModelBusinessObjectParent.setArchimateElement(parentBusinessObject);
diagramModelBusinessObjectParent.setBounds(100, 100, 100, 100);
elementModelObjectMap.put(parentBusinessObject.getId(), diagramModelBusinessObjectParent);
group_businessObjects.getChildren().add(diagramModelBusinessObjectParent);
// redirect connections to parent object
ArchiUtils.redirectRelations(parentBusinessObject, group.getKey().get(0), group.getKey().get(1),
elementsInGroup, relations);
ArchiUtils.initAccessRelation(factory.createAccessRelationship(), group.getKey().get(0),
parentBusinessObject, relationsFolder, relations, IAccessRelationship.WRITE_ACCESS);
ArchiUtils.initAccessRelation(factory.createAccessRelationship(), group.getKey().get(1),
parentBusinessObject, relationsFolder, relations, IAccessRelationship.READ_ACCESS);
}
for (IArchimateElement businessObject : elementsInGroup) {
IDiagramModelArchimateObject diagramModelBusinessObject = factory.createDiagramModelArchimateObject();
diagramModelBusinessObject.setArchimateElement(businessObject);
int[] bounds = boundsMap.get(businessObject.getId());
Dimension elementSize = ArchiLayoutUtils.getElementSize(businessObject);
diagramModelBusinessObject.setBounds(bounds[0], bounds[1], elementSize.width, elementSize.height);
group_businessObjects.getChildren().add(diagramModelBusinessObject);
elementModelObjectMap.put(businessObject.getId(), diagramModelBusinessObject);
// if parent exists -> add child & add composition relation & resize
if (diagramModelBusinessObjectParent != null) {
ArchiUtils.initRelation(factory.createCompositionRelationship(), parentBusinessObject,
businessObject, relationsFolder, relations);
diagramModelBusinessObjectParent.getChildren().add(diagramModelBusinessObject);
diagramModelBusinessObjectParent.setBounds(elementModelObjectMap
.get(elementsInGroup.get(0).getId()).getBounds().getX(),
elementModelObjectMap.get(elementsInGroup.get(0).getId()).getBounds().getY(),
diagramModelBusinessObject.getBounds().getX()
+ diagramModelBusinessObject.getBounds().getWidth(), diagramModelBusinessObject
.getBounds().getY() + diagramModelBusinessObject.getBounds().getHeight());
}
}
}
ArchiLayoutUtils.resize(group_businessObjects);
maxX = Math.max(maxX, ArchiLayoutUtils.getRightEdgePosition(group_businessObjects));
// --- draw business process steps ---
processStepsModelGroup = ArchiLayoutUtils.createSubModelGroup(businessProcessModelGroup, "Business Processes");
int starting_y = ArchiLayoutUtils.boundsOf(group_businessObjects)[1]
+ ArchiLayoutUtils.boundsOf(group_businessObjects)[3] + 10;
processStepsModelGroup.setBounds(group_businessObjects.getBounds().getX(), starting_y, 0, 0);
boundsMap = ArchiLayoutUtils.getBoundsForElements(businessProcesses.getElements(),
businessProcesses.getOrientation());
Map<String, Point> graph = null;
if (isDotAvailable()) {
graph = getGraph(dataflow);
}
for (IArchimateElement businessProcess : businessProcesses.getElements()) {
IDiagramModelArchimateObject diagramModelBusinessProcess = factory.createDiagramModelArchimateObject();
diagramModelBusinessProcess.setArchimateElement(businessProcess);
int[] bounds;
if (graph != null) {
bounds = this.getBounds(graph, businessProcess.getName());
} else {
bounds = boundsMap.get(businessProcess.getId());
}
diagramModelBusinessProcess.setBounds(bounds[0], bounds[1] + 15,
ArchiLayoutUtils.CUSTOM_BUSINESS_PROCESS_WIDTH, ArchiLayoutUtils.DEFAULT_ELEMENT_HEIGHT);
if (businessProcess instanceof BusinessEvent) {
businessProcessModelGroup.getChildren().add(diagramModelBusinessProcess);
elementModelObjectMap.put(businessProcess.getId(), diagramModelBusinessProcess);
continue;
}
processStepsModelGroup.getChildren().add(diagramModelBusinessProcess);
elementModelObjectMap.put(businessProcess.getId(), diagramModelBusinessProcess);
ArchiLayoutUtils.resize(processStepsModelGroup);
ArchiLayoutUtils.resize(businessProcessModelGroup);
}
// relocating loop junctions
for (Entry<Processor, IOrJunction> junction : loopsJunctions.entrySet()) {
IBusinessProcess processElement = processorProcessMap.get(junction.getKey());
IBounds bounds = elementModelObjectMap.get(processElement.getId()).getBounds();
int x = bounds.getX() + bounds.getWidth() / 2;
int y = bounds.getY() + bounds.getHeight() + 20;
elementModelObjectMap.get(junction.getValue().getId()).setBounds(x, y, 15, 15);
}
// relocating AND junctions
for (Entry<Processor, IAndJunction> junction : processorInputMap.entrySet()) {
IBusinessProcess processElement = processorProcessMap.get(junction.getKey());
IBounds bounds = elementModelObjectMap.get(processElement.getId()).getBounds();
int x = bounds.getX() + bounds.getWidth() / 2;
int y = bounds.getY() + bounds.getHeight() + 20;
elementModelObjectMap.get(junction.getValue().getId()).setBounds(x, y, 15, 15);
}
// relocate start and end event
elementModelObjectMap.get(startEvent.getId()).setBounds(processStepsModelGroup.getBounds().getX() - 100,
processStepsModelGroup.getBounds().getY() + processStepsModelGroup.getBounds().getHeight() / 2, 100,
ArchiLayoutUtils.DEFAULT_ELEMENT_HEIGHT);
if (andJunctionStart != null) {
elementModelObjectMap.get(andJunctionStart.getId()).setBounds(50,
processStepsModelGroup.getBounds().getHeight() / 2, 15, 15);
}
elementModelObjectMap.get(endEvent.getId()).setBounds(
processStepsModelGroup.getBounds().getX() + processStepsModelGroup.getBounds().getWidth() + 50,
processStepsModelGroup.getBounds().getY() + processStepsModelGroup.getBounds().getHeight() / 2, 100,
ArchiLayoutUtils.DEFAULT_ELEMENT_HEIGHT);
if (andJunctionEnd != null) {
elementModelObjectMap.get(andJunctionEnd.getId()).setBounds(processStepsModelGroup.getBounds().getWidth(),
processStepsModelGroup.getBounds().getHeight() / 2, 15, 15);
}
ArchiLayoutUtils.resize(processStepsModelGroup);
ArchiLayoutUtils.resize(businessProcessModelGroup);
// ArchiLayoutUtils.resize(processStepsModelGroup);
maxX = Math.max(maxX, ArchiLayoutUtils.getRightEdgePosition(processStepsModelGroup));
// all process steps are children of the parent process
for (IArchimateElement element : businessProcesses.getElements()) {
if (element != parentProcessWorkflow && !(element instanceof BusinessEvent)) {
elementModelObjectMap.get(parentProcessWorkflow.getId()).getChildren()
.add(elementModelObjectMap.get(element.getId()));
}
}
// --- draw output ports ---
IDiagramModelGroup groupOutputPorts = ArchiLayoutUtils.createSubModelGroup(businessProcessModelGroup,
"Output Ports");
groupOutputPorts.setBounds(maxX + 35, 15, defaultGroupWidth, defaultGroupHeight
* outputPorts.getElements().size());
boundsMap = ArchiLayoutUtils.getBoundsForElements(outputPorts.getElements(), outputPorts.getOrientation());
for (IArchimateElement outputPort : outputPorts.getElements()) {
IDiagramModelArchimateObject diagramModelBusinessObject = factory.createDiagramModelArchimateObject();
diagramModelBusinessObject.setArchimateElement(outputPort);
int[] bounds = boundsMap.get(outputPort.getId());
final Dimension elementSize = ArchiLayoutUtils.getElementSize(outputPort);
diagramModelBusinessObject.setBounds(bounds[0], bounds[1], elementSize.width, elementSize.height);
groupOutputPorts.getChildren().add(diagramModelBusinessObject);
elementModelObjectMap.put(outputPort.getId(), diagramModelBusinessObject);
ArchiLayoutUtils.resize(groupOutputPorts);
ArchiLayoutUtils.resize(businessProcessModelGroup);
}
maxX = businessProcessModelGroup.getBounds().getWidth() + businessProcessModelGroup.getBounds().getX();
maxY = businessProcessModelGroup.getBounds().getHeight() + businessProcessModelGroup.getBounds().getY();
overall_X = maxX;
overall_Y = maxY;
}
private void drawExternalApplicationServices() {
// hide empty container
if (externalApplicationServices.getElements().isEmpty()) {
externalApplicationModelGroup.setBounds(0, overall_Y + 30, 0, 0);
return;
}
externalApplicationModelGroup.setBounds(0, overall_Y + 30, overall_X, 150);
overall_Y += 150;
Map<String, int[]> boundsMap = ArchiLayoutUtils.getBoundsForElements(externalApplicationServices.getElements(),
externalApplicationServices.orientation);
for (IArchimateElement element : externalApplicationServices.getElements()) {
IDiagramModelArchimateObject diagramModelBusinessObject = factory.createDiagramModelArchimateObject();
diagramModelBusinessObject.setArchimateElement(element);
int[] bounds = boundsMap.get(element.getId());
Dimension elementSize = ArchiLayoutUtils.getElementSize(element);
diagramModelBusinessObject.setBounds(bounds[0], bounds[1], elementSize.width, elementSize.height);
externalApplicationModelGroup.getChildren().add(diagramModelBusinessObject);
elementModelObjectMap.put(element.getId(), diagramModelBusinessObject);
}
ArchiLayoutUtils.resize(externalApplicationModelGroup);
}
private void drawApplicationComponentServices() {
int starting_y = ArchiLayoutUtils.boundsOf(externalApplicationModelGroup)[1]
+ ArchiLayoutUtils.boundsOf(externalApplicationModelGroup)[3] + 20;
applicationComponentModelGroup.setBounds(0, starting_y, overall_X, 150);
overall_Y += 150;
Map<String, int[]> boundsMap = ArchiLayoutUtils.getBoundsForElements(dataObjects.getElements(),
dataObjects.getOrientation());
List<IArchimateElement> alreadyDrawnElements = new ArrayList<IArchimateElement>();
// --- draw data objects ---
for (Entry<List<IArchimateElement>, List<IArchimateElement>> group : ArchiUtils.groupElements(
applicationComponents.getElements(), relations).entrySet()) {
List<IArchimateElement> elementsInGroup = group.getValue();
IDataObject parentDataObject = null;
IDiagramModelArchimateObject diagramModelDataObjectParent = null;
if (elementsInGroup.size() >= MIN_ELEMENTS_FOR_GROUPING) {
String elementName = group.getKey().get(0).getName() + "=>" + group.getKey().get(1).getName();
parentDataObject = ArchiUtils.initElement(factory.createDataObject(), elementName, applicationFolder,
dataObjects);
parentDataObject.setName(elementName);
diagramModelDataObjectParent = factory.createDiagramModelArchimateObject();
diagramModelDataObjectParent.setArchimateElement(parentDataObject);
diagramModelDataObjectParent.setBounds(0, 0, 10, 10);
elementModelObjectMap.put(parentDataObject.getId(), diagramModelDataObjectParent);
applicationComponentModelGroup.getChildren().add(diagramModelDataObjectParent);
// redirect connections to parent object
ArchiUtils.redirectRelations(parentDataObject, group.getKey().get(0), group.getKey().get(1),
elementsInGroup, relations);
ArchiUtils.initAccessRelation(factory.createAccessRelationship(), group.getKey().get(0),
parentDataObject, relationsFolder, relations, IAccessRelationship.WRITE_ACCESS);
ArchiUtils.initAccessRelation(factory.createAccessRelationship(), group.getKey().get(1),
parentDataObject, relationsFolder, relations, IAccessRelationship.READ_ACCESS);
alreadyDrawnElements.add(parentDataObject);
}
for (IArchimateElement dataObject : elementsInGroup) {
IDiagramModelArchimateObject diagramModelBusinessObject = factory.createDiagramModelArchimateObject();
diagramModelBusinessObject.setArchimateElement(dataObject);
int[] bounds = {10, 10};
if (boundsMap.containsKey(dataObject.getId())) {
bounds = boundsMap.get(dataObject.getId());
}
Dimension elementSize = ArchiLayoutUtils.getElementSize(dataObject);
diagramModelBusinessObject.setBounds(bounds[0], bounds[1], elementSize.width, elementSize.height);
applicationComponentModelGroup.getChildren().add(diagramModelBusinessObject);
elementModelObjectMap.put(dataObject.getId(), diagramModelBusinessObject);
alreadyDrawnElements.add(dataObject);
// if parent exists -> add child & add composition relation & resize
if (diagramModelDataObjectParent != null) {
ArchiUtils.initRelation(factory.createCompositionRelationship(), parentDataObject, dataObject,
relationsFolder, relations);
diagramModelDataObjectParent.getChildren().add(diagramModelBusinessObject);
diagramModelDataObjectParent.setBounds(elementModelObjectMap.get(elementsInGroup.get(0).getId())
.getBounds().getX(), elementModelObjectMap.get(elementsInGroup.get(0).getId()).getBounds()
.getY(), diagramModelBusinessObject.getBounds().getX()
+ diagramModelBusinessObject.getBounds().getWidth(), diagramModelBusinessObject.getBounds()
.getY() + diagramModelBusinessObject.getBounds().getHeight());
}
}
}
ArrayList<IArchimateElement> objectsToDraw = (ArrayList<IArchimateElement>) dataObjects.getElements();
objectsToDraw.removeAll(alreadyDrawnElements);
objectsToDraw.addAll(applicationComponents.getElements());
boundsMap = ArchiLayoutUtils.getBoundsForElements(objectsToDraw, applicationComponents.orientation);
for (IArchimateElement element : objectsToDraw) {
IDiagramModelArchimateObject diagramModelBusinessObject = factory.createDiagramModelArchimateObject();
diagramModelBusinessObject.setArchimateElement(element);
int[] bounds = boundsMap.get(element.getId());
final Dimension elementSize = ArchiLayoutUtils.getElementSize(element);
diagramModelBusinessObject.setBounds(bounds[0], bounds[1], elementSize.width, elementSize.height);
applicationComponentModelGroup.getChildren().add(diagramModelBusinessObject);
elementModelObjectMap.put(element.getId(), diagramModelBusinessObject);
}
ArchiLayoutUtils.resize(applicationComponentModelGroup);
}
private void drawExternalInfrastructureServices() {
int starting_y = ArchiLayoutUtils.boundsOf(applicationComponentModelGroup)[1]
+ ArchiLayoutUtils.boundsOf(applicationComponentModelGroup)[3] + 20;
// hide empty container
if (infrastructureServices.getElements().isEmpty()) {
externalInfrastructureModelGroup.setBounds(0, starting_y, 0, 0);
return;
}
externalInfrastructureModelGroup.setBounds(0, starting_y, overall_X, 150);
overall_Y += 150;
LOGGER.debug("drawExternalInfrastructureServices.getElements().size() = "
+ infrastructureServices.getElements().size());
Map<String, int[]> boundsMap = ArchiLayoutUtils.getBoundsForElements(infrastructureServices.getElements(),
infrastructureServices.orientation);
for (IArchimateElement element : infrastructureServices.getElements()) {
IDiagramModelArchimateObject diagramModelBusinessObject = factory.createDiagramModelArchimateObject();
diagramModelBusinessObject.setArchimateElement(element);
int[] bounds = boundsMap.get(element.getId());
diagramModelBusinessObject.setBounds(bounds[0], bounds[1], bounds[2], bounds[3]);
externalInfrastructureModelGroup.getChildren().add(diagramModelBusinessObject);
elementModelObjectMap.put(element.getId(), diagramModelBusinessObject);
}
ArchiLayoutUtils.resize(externalInfrastructureModelGroup);
}
private void drawInfrastructure() {
int starting_y = ArchiLayoutUtils.boundsOf(externalInfrastructureModelGroup)[1]
+ ArchiLayoutUtils.boundsOf(externalInfrastructureModelGroup)[3] + 20;
infrastructureModelGroup.setBounds(0, starting_y, overall_X, 150);
Map<String, int[]> boundsMap = ArchiLayoutUtils.getBoundsForElements(infrastructure.getElements(),
infrastructure.orientation);
for (IArchimateElement element : infrastructure.getElements()) {
IDiagramModelArchimateObject diagramModelBusinessObject = factory.createDiagramModelArchimateObject();
diagramModelBusinessObject.setArchimateElement(element);
int[] bounds = boundsMap.get(element.getId());
diagramModelBusinessObject.setBounds(bounds[0], bounds[1], bounds[2], bounds[3]);
infrastructureModelGroup.getChildren().add(diagramModelBusinessObject);
elementModelObjectMap.put(element.getId(), diagramModelBusinessObject);
if (element.getId().equals(desktop.getId())) {
createDiagramElements(generateLayout(nodeElements), diagramModelBusinessObject);
infrastructureModelGroup.setBounds(0, starting_y, overall_X, diagramModelBusinessObject.getBounds()
.getHeight() + 25);
}
}
ArchiLayoutUtils.resize(infrastructureModelGroup);
}
private void drawExternalProviders() {
if (!externalProviders.getElements().isEmpty()) {
// (*) Group "External Provider"
externalProviderModelGroup = ArchiLayoutUtils.createSubModelGroup(layeredView, "External Service Provider");
int starting_y = ArchiLayoutUtils.boundsOf(externalInfrastructureModelGroup)[1];
int starting_x = ArchiLayoutUtils.boundsOf(externalInfrastructureModelGroup)[0]
+ ArchiLayoutUtils.boundsOf(externalInfrastructureModelGroup)[2] + 20;
externalProviderModelGroup.setBounds(starting_x, starting_y, 150, 150);
Map<String, int[]> boundsMap = ArchiLayoutUtils.getBoundsForElements(externalProviders.getElements(),
externalProviders.orientation);
for (IArchimateElement element : externalProviders.getElements()) {
IDiagramModelArchimateObject diagramModelBusinessObject = factory.createDiagramModelArchimateObject();
diagramModelBusinessObject.setArchimateElement(element);
int[] bounds = boundsMap.get(element.getId());
diagramModelBusinessObject.setBounds(bounds[0], bounds[1], bounds[2], bounds[3]);
externalProviderModelGroup.getChildren().add(diagramModelBusinessObject);
elementModelObjectMap.put(element.getId(), diagramModelBusinessObject);
}
ArchiLayoutUtils.resize(externalProviderModelGroup);
}
}
private void drawRelations() {
for (IRelationship relation : relations) {
if (relation.getSource() == null) {
return;
}
if (relation.getTarget() == null) {
return;
}
LOGGER.debug("drawing relation [" + relation.getSource().getName() + "("
+ relation.getSource().eClass().getName() + ")] --> [" + relation.getTarget().getName() + "("
+ relation.getTarget().eClass().getName() + ")]");
IDiagramModelArchimateObject source = elementModelObjectMap.get(relation.getSource().getId());
IDiagramModelArchimateObject target = elementModelObjectMap.get(relation.getTarget().getId());
ArchiLayoutUtils.createConnection(factory, relation, source, target);
}
}
private Map<IArchimateElement, Point> generateLayout(List<IArchimateElement> elements) {
Map<IArchimateElement, Point> items = new HashMap<IArchimateElement, Point>();
graph = new SparseGraph<IArchimateElement, IArchimateElement>();
for (IArchimateElement element : elements) {
if (element instanceof IRelationship) {
IArchimateElement source = ((IRelationship) element).getSource();
IArchimateElement target = ((IRelationship) element).getTarget();
graph.addEdge(element, source, target);
} else {
graph.addVertex(element);
}
}
layout = new ISOMLayout<IArchimateElement, IArchimateElement>(graph);
layout.setSize(new Dimension(650, 650));
for (IArchimateElement element : layout.getGraph().getVertices()) {
int x = (int) ((AbstractLayout<IArchimateElement, IArchimateElement>) layout).getX(element);
int y = (int) ((AbstractLayout<IArchimateElement, IArchimateElement>) layout).getY(element);
LOGGER.debug(element.getName() + "[" + x + "][" + y + "]");
items.put(element, new Point(x, y));
}
return items;
}
private void createDiagramElements(Map<IArchimateElement, Point> elements, IDiagramModelContainer parent) {
// draw elements
for (Entry<IArchimateElement, Point> entry : elements.entrySet()) {
IDiagramModelArchimateObject diagramModelObject = factory.createDiagramModelArchimateObject();
diagramModelObject.setArchimateElement(entry.getKey());
Dimension size = ArchiLayoutUtils.getElementSize(entry.getKey());
diagramModelObject.setBounds(entry.getValue().x, entry.getValue().y, size.width, size.height);
parent.getChildren().add(diagramModelObject);
// resize parent container
ArchiLayoutUtils.resize(parent);
elementModelObjectMap.put(entry.getKey().getId(), diagramModelObject);
}
// create connections
for (IArchimateElement edge : layout.getGraph().getEdges()) {
IRelationship relationShip = (IRelationship) edge;
String sourceID = relationShip.getSource().getId();
String targetID = relationShip.getTarget().getId();
IDiagramModelArchimateObject source = elementModelObjectMap.get(sourceID);
IDiagramModelArchimateObject target = elementModelObjectMap.get(targetID);
ArchiLayoutUtils.createConnection(factory, relationShip, source, target);
}
}
private boolean sshInvocation(String mechanismAsXMLString) {
return mechanismAsXMLString.contains("<sshInvocation>");
}
private IProperty createDepProperties(Class clazz) {
IProperty property = factory.createProperty();
property.setKey("hasSourceLocation");
property.setValue(getJarLocationOfClass(clazz).getPath().replaceFirst("/", ""));
return property;
}
private IProperty createDepProperties(String pathToJar) {
IProperty property = factory.createProperty();
property.setKey("hasSourceLocation");
property.setValue(pathToJar);
return property;
}
private List<IProperty> createPropertiesOutOfXMLMechanism(ExternalToolActivityConfigurationBean configuration) {
List<IProperty> props = new ArrayList<IProperty>();
try {
Document document = DocumentHelper.parseText(configuration.getMechanismXML());
IProperty hostProperty = factory.createProperty();
hostProperty.setKey("Host");
hostProperty.setValue(document.selectSingleNode("//host").getText());
props.add(hostProperty);
IProperty portProperty = factory.createProperty();
portProperty.setKey("Port");
portProperty.setValue(document.selectSingleNode("//port").getText());
props.add(portProperty);
} catch (DocumentException e) {
LOGGER.error("ERROR parsing external tool invocation mechanism. " + e.getMessage());
}
IProperty commandProperty = factory.createProperty();
commandProperty.setKey("Command");
commandProperty.setValue(configuration.getUseCaseDescription().getCommand());
props.add(commandProperty);
return props;
}
private List<IProperty> createPropertiesOutOfRshellConfig(RshellActivityConfigurationBean configuration) {
List<IProperty> props = new ArrayList<IProperty>();
IProperty hostProperty = factory.createProperty();
hostProperty.setKey("Host");
hostProperty.setValue(configuration.getConnectionSettings().getHost());
props.add(hostProperty);
IProperty portProperty = factory.createProperty();
portProperty.setKey("Port");
portProperty.setValue("" + configuration.getConnectionSettings().getPort());
props.add(portProperty);
IProperty scriptProperty = factory.createProperty();
scriptProperty.setKey("Script");
scriptProperty.setValue(configuration.getScript());
props.add(scriptProperty);
return props;
}
private void printPortInformation(Processor processor) {
if (processor != null) {
for (ProcessorInputPort inputPort : processor.getInputPorts()) {
LOGGER.debug("--> Port = " + inputPort.getName() + "[depth = " + inputPort.getDepth() + "]");
}
for (ProcessorOutputPort outputPort : processor.getOutputPorts()) {
LOGGER.debug("<-- Port = " + outputPort.getName() + "[depth = " + outputPort.getDepth() + "]");
}
}
}
private List<Processor> findStartingProcessors(Dataflow dataflow) {
LOGGER.debug("find starting processors");
List<OutputPort> outputPorts = new ArrayList<OutputPort>();
for (Processor processor : dataflow.getProcessors()) {
for (OutputPort outputPort : processor.getOutputPorts()) {
outputPorts.add(outputPort);
}
}
//TODO: needs improvements -> hasNoPrecedentProcessor not working if only one non-constant value processor exists!!
List<Processor> startingProcessors = new ArrayList<Processor>();
for (Processor processor : dataflow.getProcessors()) {
if (ArchiUtils.isValueProcessor(processor)) {
break;
}
else{
startingProcessors.add(processor);
}
}
if(startingProcessors.size() == 1){
return startingProcessors;
}
startingProcessors = new ArrayList<Processor>();
for (Processor processor : dataflow.getProcessors()) {
if (ArchiUtils.isValueProcessor(processor)) {
break;
}
if (hasNoPrecedentProcessor(processor, outputPorts)) {
LOGGER.debug("Processor '" + processor.getLocalName() + "' has no precendent processors.");
startingProcessors.add(processor);
}
}
LOGGER.debug(startingProcessors.size() + " starting processors found");
return startingProcessors;
}
private List<Processor> findEndProcessors(Dataflow dataflow) {
List<InputPort> inputPorts = new ArrayList<InputPort>();
for (Processor processor : dataflow.getProcessors()) {
for (InputPort inputPort : processor.getInputPorts()) {
inputPorts.add(inputPort);
}
}
List<Processor> endingProcessors = new ArrayList<Processor>();
for (Processor processor : dataflow.getProcessors()) {
// detect if first step processor
if (hasNoSucceedProcessor(processor, inputPorts)) {
LOGGER.debug("Processor '" + processor.getLocalName() + "' has no succeed processors.");
endingProcessors.add(processor);
}
}
return endingProcessors;
}
private boolean hasNoPrecedentProcessor(Processor processor, List<OutputPort> outputPorts) {
for (ProcessorInputPort sink : processor.getInputPorts()) {
if (outputPorts.contains(sink.getIncomingLink().getSource())) {
return false;
}
}
return true;
}
private boolean hasNoSucceedProcessor(Processor processor, List<InputPort> inputPort) {
for (ProcessorOutputPort out : processor.getOutputPorts()) {
for (Datalink links : out.getOutgoingLinks()) {
if (inputPort.contains(links.getSink())) {
return false;
}
}
}
return true;
}
public Map<String, Point> getGraph(Dataflow dataflow) {
SVGGraphController con = new SVGGraphController(dataflow, false, new JSVGCanvas(), Alignment.HORIZONTAL,
PortStyle.NONE);
StringWriter stringWriter = new StringWriter();
DotWriter dotWriter = new DotWriter(stringWriter);
try {
String tmpDirPath = System.getProperty("java.io.tmpdir");
File dotTmp = new File(tmpDirPath + File.separator + "tavernaExtractorToArchimate.dot");
FileWriter fw = new FileWriter(dotTmp);
dotWriter = new DotWriter(fw);
dotWriter.writeGraph(con.getGraph());
fw.close();
// Dot to SVG
File svgTmp = new File(tmpDirPath + File.separator + "tavernaExtractorToArchimate.dot.svg");
String[] COMMAND = {this.getDotLocation().toString(), "-Tsvg", dotTmp.getAbsolutePath(), "-o", svgTmp.getAbsolutePath()};
LOGGER.debug("Running command '" + StringUtils.join(COMMAND, " ") + "'.");
ProcessBuilder proc = new ProcessBuilder(COMMAND);
Process process = proc.start();
InputStream stderr = process.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null) {
}
process.waitFor();
// parse SVG
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
DocumentBuilder builder;
builder = factory.newDocumentBuilder();
org.w3c.dom.Document doc = builder.parse(svgTmp);
XPath xpath = XPathFactory.newInstance().newXPath();
final String XPATH_EXPRESSION = "//g[@class='node']/text/text() | //g[@class='node']/text/@x | //g[@class='node']/text/@y";
XPathExpression expr = xpath.compile(XPATH_EXPRESSION);
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
return transform(nodes);
} catch (IOException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (XPathExpressionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return Collections.emptyMap();
}
private Map<String, Point> transform(NodeList nodeList) {
Map<String, Point> reducedMap = new HashMap<String, Point>();
Map<String, Point> map = new HashMap<String, Point>();
for (int i = 0; i < nodeList.getLength() - 1; i += 3) {
String key = nodeList.item(i + 2).getTextContent();
try {
Integer x = (int) Math.abs(Double.parseDouble(nodeList.item(i).getTextContent()));
Integer y = (int) Math.abs(Double.parseDouble(nodeList.item(i + 1).getTextContent()));
map.put(key, new Point(x, y));
} catch (NumberFormatException nfe) {
LOGGER.error("ERROR: Unable to convert to integer. " + nfe.getMessage());
map.put(key, new Point(1, 1));
}
}
for (Entry<String, Point> entry : map.entrySet()) {
for (IArchimateElement businessProcess : businessProcesses.getElements()) {
if (businessProcess.getName().equals(entry.getKey())) {
reducedMap.put(entry.getKey(), entry.getValue());
}
}
}
return reducedMap;
}
private int[] getBounds(Map<String, Point> map, String name) {
if (map.containsKey(name)) {
return new int[]{map.get(name).x, map.get(name).y};
}
return new int[]{-1, -1};
}
private int numberOfTriggringInputProcessors(Dataflow dataflow, Processor processor) {
@SuppressWarnings("unchecked")
List<ProcessorInputPort> inputs = (List<ProcessorInputPort>) processor.getInputPorts();
int inputsNumber = inputs.size();
for (ProcessorInputPort processorInput : processor.getInputPorts()) {
for (DataflowInputPort dataflowInput : dataflow.getInputPorts()) {
if (processorInput.getIncomingLink().getSource().getName().equals(dataflowInput.getName())) {
inputsNumber--;
}
}
}
return inputsNumber;
}
private boolean isDotAvailable() {
boolean dot = false;
if (dotLocation != null) {
try {
dot = dotLocation.toFile().exists() ? true : false;
} catch (InvalidPathException ipe) {
return false;
}
}
return dot;
}
private void detailProcessorsOnLayers(List<? extends Processor> processors) throws IOException {
for (Processor processor : processors) {
String processorName = processor.getLocalName();
for (Activity<?> a : processor.getActivityList()) {
LOGGER.debug(processorName + " [" + processor.getActivityList().size() + "] -> "
+ a.getClass().getName());
printPortInformation(processor);
// TODO UnrecognizedActivity detected !!
if (a instanceof UnrecognizedActivity) {
LOGGER.error("\tPROBLEM: UnrecognizedActivity detected! ");
}
// TODO DisabledActivity detected !!
// From the javadoc: A disabled activity is a wrapper for an Activity that is offline or similarly
// disabled
else if (a instanceof DisabledActivity) {
LOGGER.error("\tPROBLEM: DisabledActivity detected! ");
// TODO: create a note element with information
}
// nested worklfow
else if (a instanceof DataflowActivity) {
DataflowActivity nestedWF = (DataflowActivity) a;
detailProcessorsOnLayers(nestedWF.getNestedDataflow().getProcessors());
}
// processing RShellActivity
else if (a instanceof RshellActivity) {
processRShellActivity(businessFolder, infrastructureFolder, applicationFolder, relationsFolder,
workflowApplicationComponent, processorProcessMap, callToolInvocationFunction, processor,
processorName, a);
}
// processing ExternalToolActivity
else if (a instanceof ExternalToolActivity) {
ExternalToolActivityConfigurationBean conf = (ExternalToolActivityConfigurationBean) a
.getConfiguration();
if (conf != null && conf.getMechanismXML() != null) {
String mechanismAsXMLString = conf.getMechanismXML();
if (sshInvocation(mechanismAsXMLString)) { // SSH invocation
// treat like as an web service dependency
processToolActivity(businessFolder, infrastructureFolder, applicationFolder,
relationsFolder, workflowApplicationComponent, processorProcessMap,
callToolInvocationFunction, processor, processorName, a, true);
} else { // local tool invocation
processToolActivity(businessFolder, infrastructureFolder, applicationFolder,
relationsFolder, workflowApplicationComponent, processorProcessMap,
callToolInvocationFunction, processor, processorName, a, false);
}
}
}
// processing Beanshell activities
else if (a instanceof BeanshellActivity) {
processBeanshellActivity(infrastructureFolder, motivationFolder, applicationFolder,
relationsFolder, workflowApplicationComponent, processorProcessMap, processor, a);
}
// processing REST activity
else if (a instanceof RESTActivity) {
processWebServiceActivity(businessFolder, infrastructureFolder, applicationFolder, relationsFolder,
workflowApplicationComponent, processorProcessMap, callWebServiceApplicationFunction,
processor, processorName, a);
}
// processing WSDL activity
// IMPORTANT: Service(=Activity) MUST BE ONLINE !! Otherwise it will be of type DisabledActivity
// From the javadoc: A disabled activity is a wrapper for an Activity that is offline or similarly
// disabled
else if (a instanceof WSDLActivity) {
processWebServiceActivity(businessFolder, infrastructureFolder, applicationFolder, relationsFolder,
workflowApplicationComponent, processorProcessMap, callWebServiceApplicationFunction,
processor, processorName, a);
}
else if (a instanceof XMLInputSplitterActivity || a instanceof XMLOutputSplitterActivity) {
processXMLSplitterActivity(infrastructureFolder, motivationFolder, applicationFolder,
relationsFolder, workflowApplicationComponent, processorProcessMap, processor, a);
}
else if (a instanceof XPathActivity){
LOGGER.info("XPathActivity has to be done");
processXPathActivity(infrastructureFolder, motivationFolder, applicationFolder,
relationsFolder, workflowApplicationComponent, processorProcessMap, processor, a);
}
else if (a instanceof LocalworkerActivity){
/*
Localworker Activity equals BeanshellActivity ?!
*/
processBeanshellActivity(infrastructureFolder, motivationFolder, applicationFolder,
relationsFolder, workflowApplicationComponent, processorProcessMap, processor, a);
}
else{
LOGGER.debug("Unfortunately, we do not process that kind of activity.");
}
}
}
}
private void validateDirectories(Path... dirs) throws TavernaExtractorException {
for (Path path : dirs) {
if (path == null || Files.notExists(path) || !Files.isDirectory(path) || !Files.isReadable(path)) {
throw new TavernaExtractorException("Directory '" + path + "' does not exists or is invalid.");
}
}
}
private void validateRemoteDirectories(Path... dirs) throws TavernaExtractorException {
try {
for (Path path : dirs)
sshManager.directoryExists(sshManager.createSession(15000), path);
} catch (SSHManagerException sshME) {
throw new TavernaExtractorException(sshME.getLocalizedMessage());
}
}
private List<String> cleanedClasspath(List<String> classpathEntries) {
List<String> cleanedClasspathEntries = new ArrayList<String>();
for (String entry : classpathEntries)
if (entry.contains("taverna-2."))
cleanedClasspathEntries.add(entry);
return cleanedClasspathEntries;
}
private URL getJarLocationOfClass(Class clazz) {
return clazz.getProtectionDomain().getCodeSource().getLocation();
}
public void treatProcessors(List<? extends Processor> processors) {
for (Processor processor : dataflow.getProcessors()) {
IArchimateElement archimateElement = null;
LOGGER.debug("Treat processor "+processor.getLocalName());
// "value" processors are actually a constant input port, treat them special
if (ArchiUtils.isValueProcessor(processor)) {
IBusinessObject valueBusinessObject = ArchiUtils.initElement(factory.createBusinessObject(),
processor.getLocalName(), businessFolder, valueObjects);
archimateElement = valueBusinessObject;
processorValueMap.put(processor, valueBusinessObject);
} else {
// create the archimate element
IBusinessProcess process = ArchiUtils.initElement(factory.createBusinessProcess(),
processor.getLocalName(), businessFolder, businessProcesses);
archimateElement = process;
// composition relation to parent workflow
ArchiUtils.initRelation(factory.createCompositionRelationship(), parentProcessWorkflow, process,
relationsFolder, relations);
// put created elements to lookup map for later when creating relations
processorProcessMap.put(processor, process);
}
// add additional relationship between processor and workflow input port
for (ProcessorInputPort port : processor.getInputPorts()) {
for (IArchimateElement item : ArchiUtils.getElementsByname(
port.getIncomingLink().getSource().getName(), inputPorts.getElements())) {
IAccessRelationship readAccessRelation = ArchiUtils.initRelation(
factory.createAccessRelationship(), archimateElement, item, relationsFolder, relations);
readAccessRelation.setAccessType(IAccessRelationship.READ_ACCESS);
}
}
// add additional relationship between processor and workflow output port
for (ProcessorOutputPort port : processor.getOutputPorts()) {
for (Datalink datalink : port.getOutgoingLinks()) {
for (IArchimateElement item : ArchiUtils.getElementsByname(datalink.getSink().getName(),
outputPorts.getElements())) {
IAccessRelationship readAccessRelation = ArchiUtils.initRelation(
factory.createAccessRelationship(), archimateElement, item, relationsFolder, relations);
readAccessRelation.setAccessType(IAccessRelationship.WRITE_ACCESS);
}
}
}
}
// connect all starting processors with the start event
List<Processor> startingProcessors = findStartingProcessors(dataflow);
for (Processor processor : startingProcessors) {
if (startingProcessors.size() <= 1) {
ArchiUtils.initRelation(factory.createTriggeringRelationship(), startEvent,
processorProcessMap.get(processor), relationsFolder, relations);
}
// additional AND junction
else {
if (andJunctionStart == null) {
andJunctionStart = ArchiUtils.initElement(factory.createAndJunction(), "AndJunction",
businessFolder, businessProcesses);
ArchiUtils.initRelation(factory.createTriggeringRelationship(), startEvent, andJunctionStart,
relationsFolder, relations);
}
ArchiUtils.initRelation(factory.createTriggeringRelationship(), andJunctionStart,
processorProcessMap.get(processor), relationsFolder, relations);
}
}
// connect all ending processors with the end event
List<Processor> endprocessors = findEndProcessors(dataflow);
for (Processor processor : endprocessors) {
if (endprocessors.size() <= 1) {
ArchiUtils.initRelation(factory.createTriggeringRelationship(), processorProcessMap.get(processor),
endEvent, relationsFolder, relations);
}
// additional AND junction
else {
if (andJunctionEnd == null) {
andJunctionEnd = ArchiUtils.initElement(factory.createAndJunction(), "EndingAndJunction",
businessFolder, businessProcesses);
ArchiUtils.initRelation(factory.createTriggeringRelationship(), andJunctionEnd, endEvent,
relationsFolder, relations);
}
ArchiUtils.initRelation(factory.createTriggeringRelationship(), processorProcessMap.get(processor),
andJunctionEnd, relationsFolder, relations);
}
}
//
// second pass - add relations between processes
//
Stack<Processor> processorStack = new Stack<Processor>();
for (Processor processor : dataflow.getProcessors()) {
boolean isValueProcessor = ArchiUtils.isValueProcessor(processor);
for (ProcessorOutputPort processorOutputPort : processor.getOutputPorts()) {
LOGGER.debug("Process processorOutputPort = '" + processorOutputPort.getName() + "'");
for (Datalink datalink : processorOutputPort.getOutgoingLinks()) {
EventHandlingInputPort sink = datalink.getSink();
if (sink instanceof ProcessorInputPortImpl) {
boolean split = false;
IOrJunction orJunction = null;
// after this processor we need an Or-junction
if (datalink.getSource().getDepth() - datalink.getSink().getDepth() > 0) {
split = true;
orJunction = ArchiUtils.initElement(factory.createOrJunction(), "OrJunctionMerge",
businessFolder, businessProcesses);
// if (!loopsJunctions.containsKey(processor)) {
loopsJunctions.put(processor, orJunction);
// }
processorStack.push(processor);
}
// after this processor we need an Or-junction
if (datalink.getSource().getDepth() - datalink.getSink().getDepth() < 0) {
split = true;
orJunction = ArchiUtils.initElement(factory.createOrJunction(), "OrJunctionSplit",
businessFolder, businessProcesses);
// if (!loopsJunctions.containsKey(processor)) {
loopsJunctions.put(processor, orJunction);
// }
if (!processorStack.isEmpty()) {
Processor startProcessor = processorStack.pop();
// draw loop back relation
IOrJunction splitJunction = loopsJunctions.get(startProcessor);
IOrJunction mergeJunction = loopsJunctions.get(processor);
ArchiUtils.initRelation(factory.createTriggeringRelationship(), mergeJunction,
splitJunction, relationsFolder, relations);
LOGGER.debug("loop detected between [" + startProcessor.getLocalName() + "] --> ["
+ processor.getLocalName() + "]");
}
}
Processor targetProcessor = ((ProcessorInputPortImpl) sink).getProcessor();
IBusinessProcess targetProcess = processorProcessMap.get(targetProcessor);
if (isValueProcessor) {
// value processors are constants, we treat them like process inputs
IBusinessObject sourceBusinessObject = processorValueMap.get(processor);
// make sure we only create one triggering relation combining two elements
if (!ArchiUtils.containsRelation(targetProcess, sourceBusinessObject, relations)) {
ArchiUtils.initRelation(factory.createTriggeringRelationship(), sourceBusinessObject,
targetProcess, relationsFolder, relations);
}
} else {
// 1. create relation
IBusinessProcess sourceProcess = processorProcessMap.get(processor);
// check if source processor has more than one input port. if so, we need a additional AND
// junction
if (numberOfTriggringInputProcessors(dataflow, processor) > 1) {
// have to do that check, otherwise we will initialize (which means create and draw
// ) an Archimate element every time
if (!processorInputMap.containsKey(processor)) {
// create additional AND Junction
processorInputMap.put(processor, ArchiUtils.initElement(
factory.createAndJunction(), processor.getLocalName() + "_AND",
businessFolder, businessProcesses));
}
}
// make sure we only create one triggering relation combining two elements
if (!ArchiUtils.containsRelation(targetProcess, sourceProcess, relations)) {
if (split) {
ArchiUtils.initRelation(factory.createTriggeringRelationship(), sourceProcess,
orJunction, relationsFolder, relations);
ArchiUtils.initRelation(factory.createTriggeringRelationship(), orJunction,
targetProcess, relationsFolder, relations);
} else {
ArchiUtils.initRelation(factory.createTriggeringRelationship(), sourceProcess,
targetProcess, relationsFolder, relations);
}
split = false; // reset flags!
}
// 2. create business object
IBusinessObject businessObject = ArchiUtils.initElement(factory.createBusinessObject(),
sink.getName(), businessFolder, businessObjects);
LOGGER.debug("\t BusinessObject for datalink '" + datalink.getSource().getName() + " -> "
+ sink.getName() + "' created.");
if (processorObjectMapping.get(processor) == null) {
processorObjectMapping.put(processor, new ArrayList<IBusinessObject>());
}
processorObjectMapping.get(processor).add(businessObject);
ArchiUtils.initAccessRelation(factory.createAccessRelationship(), sourceProcess,
businessObject, relationsFolder, relations, IAccessRelationship.WRITE_ACCESS);
// 3. create read access relation from target process to business object
ArchiUtils.initAccessRelation(factory.createAccessRelationship(), targetProcess,
businessObject, relationsFolder, relations, IAccessRelationship.READ_ACCESS);
}
} else { // TODO these are likely workflow output ports, need to be treated special
// System.out.println("Unknown sink type for processor " + processor + ", dataLink " + datalink
// + ": " + sink.getClass());
}
}
}
}
}
private Dataflow getDataflowRemote() throws TavernaExtractorException {
try {
URL workflowURL = null;
try {
Session session = sshManager.createSession(15000);
tavernaFile = sshManager.readFile(session, inputFileName.toString());
} catch (SSHManagerException e) {
e.printStackTrace();
throw new TavernaExtractorException(e.getLocalizedMessage());
}
if (tavernaFile.exists()) {
workflowURL = tavernaFile.toURI().toURL();
}
LOGGER.info("Reading workflow from " + workflowURL);
return openDataflow(workflowURL);
} catch (NullPointerException | EditException | OpenDataflowException | MalformedURLException | DeserializationException e) {
e.printStackTrace();
LOGGER.error("ERROR reading workflow from [" + inputFileName + "]." + e.getMessage());
}
return null;
}
private Dataflow getDataflowLocal() throws EditException, OpenDataflowException, MalformedURLException, DeserializationException {
try {
// try to load from classpath
URL workflowURL = getClass().getResource(inputFileName.toString());
if (workflowURL == null) { // if not successful, try opening file
File f = inputFileName.toFile();
if (f.exists()) {
workflowURL = f.toURI().toURL();
}
}
return openDataflow(workflowURL);
} catch (NullPointerException npe) {
npe.printStackTrace();
LOGGER.error("ERROR reading workflow from [" + inputFileName + "]." + npe.getMessage());
}
return null;
}
private void saveRemote(IArchimateModel model) throws TavernaExtractorException {
// Set new file
File outFile = this.getArchimateOutputPath().toFile();
model.setFile(outFile);
// Set model version
model.setVersion(ModelVersion.VERSION);
//create tmp file
Path outputTmp = null;
try {
outputTmp = Files.createTempFile("tavernaExtractor-", ".output");
// Adapted from {@link ArchiveManager#saveModelToXMLFile}
ResourceSet resourceSet = ArchimateResourceFactory.createResourceSet();
Resource resource = resourceSet.createResource(URI.createFileURI(outputTmp.toAbsolutePath().toString()));
resource.getContents().add(model);
resource.save(null);
} catch (IOException e) {
e.printStackTrace();
throw new TavernaExtractorException(e.getLocalizedMessage());
}
LOGGER.info("Wrote model successfully to " + outFile.getAbsolutePath());
// copy temp file to remote host
try {
Session session = sshManager.createSession(15000);
sshManager.sendFile(session, outputTmp.toString(), archimateOutputPath.toString());
} catch (SSHManagerException e) {
e.printStackTrace();
throw new TavernaExtractorException(e.getLocalizedMessage());
}
try {
//for the testbed, return file content as string representation
convertedFileAsString = new String(Files.readAllBytes(outputTmp), StandardCharsets.UTF_8);
// remove both temp files.
Files.deleteIfExists(outputTmp);
Files.deleteIfExists(tavernaFile.toPath());
} catch (IOException e) {
e.printStackTrace();
throw new TavernaExtractorException(e.getLocalizedMessage());
}
}
private void saveLocal(IArchimateModel model) throws IOException {
// Set new file
File outFile = this.getArchimateOutputPath().toFile();
model.setFile(outFile);
// Set model version
model.setVersion(ModelVersion.VERSION);
// Adapted from {@link ArchiveManager#saveModelToXMLFile}
ResourceSet resourceSet = ArchimateResourceFactory.createResourceSet();
Resource resource = resourceSet.createResource(URI.createFileURI(outFile.getAbsolutePath()));
resource.getContents().add(model);
resource.save(null);
LOGGER.info("Wrote model successfully to " + outFile.getAbsolutePath());
}
public String getConvertedFileAsString() throws TavernaExtractorException {
if (convertedFileAsString != null)
return convertedFileAsString;
throw new TavernaExtractorException("Can not read file content");
}
}