core_algorithm.alc 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475
  1. include "modelling.alh"
  2. include "library.alh"
  3. include "primitives.alh"
  4. include "constructors.alh"
  5. include "object_operations.alh"
  6. include "mini_modify.alh"
  7. include "model_management.alh"
  8. include "ramify.alh"
  9. include "conformance_scd.alh"
  10. include "transform.alh"
  11. include "metamodels.alh"
  12. include "utils.alh"
  13. include "conformance_finding.alh"
  14. include "typing.alh"
  15. include "compiler.alh"
  16. include "random.alh"
  17. include "io.alh"
  18. String core_model_location = "models/core"
  19. Element core = ?
  20. String current_user_id
  21. Element caches
  22. Element pm_tasks = ?
  23. String function get_foldername(name : String):
  24. Element result
  25. result = string_split(name, "/")
  26. list_pop_final(result)
  27. if (list_len(result) == 0):
  28. return ""!
  29. // 'result' now contains a list of entries which we have to join with the seperator
  30. String str
  31. str = list_pop(result, 0)
  32. while (list_len(result) > 0):
  33. str = string_join(str + "/", list_pop(result, 0))
  34. return str!
  35. String function get_filename(name : String):
  36. return list_pop_final(string_split(name, "/"))!
  37. String function full_name(model_id : String):
  38. return read_attribute(core, model_id, "name")!
  39. Void function initialize_core():
  40. // TODO make this more flexible by putting it in the bootstrap in a similar way as other models
  41. add_code_model(import_node("models/ActionLanguage"), "models/Conformance_MV", wrap_conformance)
  42. return !
  43. Boolean function is_typed_by(model_id : String, metamodel_id : String):
  44. return (set_len(get_instanceOf_links(model_id, metamodel_id)) > 0)!
  45. Element function get_instanceOf_links(model_id : String, metamodel_id : String):
  46. Element result
  47. Element options
  48. String elem
  49. result = set_create()
  50. options = allOutgoingAssociationInstances(core, model_id, "instanceOf")
  51. while (set_len(options) > 0):
  52. elem = set_pop(options)
  53. if (value_eq(readAssociationDestination(core, elem), metamodel_id)):
  54. set_add(result, elem)
  55. return result!
  56. String function get_instanceOf_link(model_id : String, metamodel_id : String):
  57. Element all_links
  58. String choice
  59. all_links = get_instanceOf_links(model_id, metamodel_id)
  60. if (set_len(all_links) > 1):
  61. log("WARNING: multiple instanceOf relations were detected for this model; picking one at random!")
  62. elif (set_len(all_links) == 0):
  63. log("No types found!")
  64. log("Source model: " + cast_value(read_attribute(core, model_id, "name")))
  65. log("Target meta-model: " + cast_value(read_attribute(core, metamodel_id, "name")))
  66. return read_root()!
  67. choice = set_pop(all_links)
  68. return choice!
  69. Element function get_full_model(model_id : String, metamodel_id : String):
  70. // TODO we are restricted to using formalisms/SimpleClassDiagrams as M3 level, through this code!
  71. Element m
  72. Element all_links
  73. String choice
  74. choice = get_instanceOf_link(model_id, metamodel_id)
  75. m = dict_create()
  76. dict_add(m, "model", import_node(read_attribute(core, model_id, "location")))
  77. // TODO for now this is restricted to the fixed semantics
  78. // dict_add(m, "semantics", set_pop(allAssociationDestinations(core, choice, "semantics")))
  79. dict_add(m, "semantics", get_entry_id("models/conformance_mv"))
  80. if (metamodel_id == model_id):
  81. // Found the meta-circular level, so we can stop!
  82. dict_add(m, "metamodel", m)
  83. else:
  84. Element mm
  85. mm = get_full_model(metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  86. if (element_eq(mm, read_root())):
  87. return read_root()!
  88. else:
  89. dict_add(m, "metamodel", mm)
  90. if (element_neq(choice, read_root())):
  91. Element types
  92. types = allAssociationDestinations(core, choice, "typing")
  93. if (set_len(types) == 1):
  94. // Add the preferred original type mapping
  95. set_type_mapping(m, import_node(read_attribute(core, set_pop(types), "location")))
  96. else:
  97. // Start from scratch
  98. new_type_mapping(m)
  99. else:
  100. // Start from scratch
  101. new_type_mapping(m)
  102. if (find_type_mapping(m)):
  103. // TODO store the found type model somewhere
  104. return m!
  105. else:
  106. log("No type mapping could be deduced!")
  107. log("Error for " + cast_value(read_attribute(core, model_id, "name")))
  108. log(" and type " + cast_value(read_attribute(core, metamodel_id, "name")))
  109. return read_root()!
  110. Integer function get_relation_to_model(user_id : String, model_id : String):
  111. if (set_in(allAssociationDestinations(core, model_id, "owner"), user_id)):
  112. // We are the owner
  113. return 0!
  114. else:
  115. String group_id
  116. group_id = set_pop(allAssociationDestinations(core, model_id, "group"))
  117. if (set_in(allAssociationDestinations(core, user_id, "belongsTo"), group_id)):
  118. // We are in the owning group
  119. return 1!
  120. else:
  121. // We are not related whatsoever
  122. return 2!
  123. Boolean function is_admin(user_id : String):
  124. if (read_attribute(core, user_id, "admin")):
  125. return True!
  126. else:
  127. return False!
  128. Boolean function allow_read(user_id : String, model_id : String):
  129. if (is_admin(user_id)):
  130. // Is admin, so always allow
  131. return True!
  132. else:
  133. // Check permissions
  134. String permission
  135. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  136. if (bool_or(permission == "1", permission == "2")):
  137. return True!
  138. else:
  139. return False!
  140. Boolean function allow_write(user_id : String, model_id : String):
  141. if (is_admin(user_id)):
  142. // Is admin, so always allow
  143. return True!
  144. else:
  145. // Check permissions
  146. String permission
  147. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  148. if (permission == "2"):
  149. return True!
  150. else:
  151. return False!
  152. Boolean function allow_change_metadata(user_id : String, model_id : String):
  153. if (is_admin(user_id)):
  154. // Is admin, so always allow
  155. return True!
  156. else:
  157. if (get_relation_to_model(user_id, model_id) == 0):
  158. // Only owner can chmod
  159. return True!
  160. else:
  161. return False!
  162. Boolean function allow_group_modify(user_id : String, group_id : String):
  163. if (is_admin(user_id)):
  164. // Is admin, so always allow
  165. return True!
  166. else:
  167. if (set_in(allAssociationDestinations(core, group_id, "owner"), user_id)):
  168. // We are an owner
  169. return True!
  170. else:
  171. return False!
  172. Boolean function check_login(user_id : String):
  173. String password
  174. String stored_password
  175. stored_password = read_attribute(core, user_id, "password")
  176. output("Password for existing user?")
  177. password = hash(input())
  178. return password == stored_password!
  179. Void function new_task():
  180. String username
  181. String user_id
  182. String password
  183. // Load in a hard-reference to the previously created model
  184. core = import_node(core_model_location)
  185. while (True):
  186. output("Log on as which user?")
  187. username = input()
  188. user_id = get_user_id(username)
  189. if (user_id == ""):
  190. // New user
  191. // Add user to Core Formalism
  192. user_id = instantiate_node(core, "User", "")
  193. instantiate_attribute(core, user_id, "name", username)
  194. instantiate_attribute(core, user_id, "admin", False)
  195. output("This is a new user: please give password!")
  196. password = hash(input())
  197. output("Please repeat the password")
  198. if (password == hash(input())):
  199. output("Passwords match!")
  200. instantiate_attribute(core, user_id, "password", password)
  201. break!
  202. else:
  203. output("Not the same password!")
  204. else:
  205. if (check_login(user_id)):
  206. break!
  207. else:
  208. output("Wrong password!")
  209. user_function_skip_init(user_id)
  210. // User destroyed already, so just stop execution
  211. return!
  212. String function get_entry_id(name : String):
  213. Element hierarchy_split
  214. String current
  215. Integer i
  216. Element elems
  217. String current_part
  218. String elem
  219. Boolean found
  220. if (name == ""):
  221. return caches["root"]!
  222. if (dict_in(caches["models"], name)):
  223. if (dict_in(core, caches["models"])):
  224. if (full_name(caches["models"][name]) == name):
  225. return caches["models"][name]!
  226. current = get_entry_id(get_foldername(name))
  227. if (current == ""):
  228. return ""!
  229. if (current_part != ""):
  230. elems = allAssociationDestinations(core, current, "contains")
  231. while (set_len(elems) > 0):
  232. elem = set_pop(elems)
  233. dict_overwrite(caches["models"], read_attribute(core, elem, "name"), elem)
  234. if (value_eq(name, read_attribute(core, elem, "name"))):
  235. return elem!
  236. else:
  237. return current!
  238. return ""!
  239. String function get_service_id(name : String):
  240. core = import_node(core_model_location)
  241. Element services
  242. String service
  243. services = allInstances(core, "Service")
  244. while (set_len(services) > 0):
  245. service = set_pop(services)
  246. if (value_eq(read_attribute(core, service, "name"), name)):
  247. return service!
  248. return ""!
  249. String function get_user_id(name : String):
  250. Element users
  251. String user
  252. users = allInstances(core, "User")
  253. while (set_len(users) > 0):
  254. user = set_pop(users)
  255. if (value_eq(read_attribute(core, user, "name"), name)):
  256. return user!
  257. return ""!
  258. String function get_group_id(name : String):
  259. Element groups
  260. String group
  261. groups = allInstances(core, "Group")
  262. while (set_len(groups) > 0):
  263. group = set_pop(groups)
  264. if (value_eq(read_attribute(core, group, "name"), name)):
  265. return group!
  266. return ""!
  267. String function create_folders(user_id : String, folder_name : String):
  268. Element hierarchy
  269. Integer i
  270. String prev
  271. String elem
  272. String new_entry
  273. String cummul
  274. if (get_entry_id(folder_name) != ""):
  275. // Folders already exist, so don't iterate
  276. return get_entry_id(folder_name)!
  277. i = 0
  278. hierarchy = string_split(folder_name, "/")
  279. prev = get_entry_id("")
  280. cummul = ""
  281. // Go through folders first
  282. while (i < list_len(hierarchy)):
  283. elem = list_read(hierarchy, i)
  284. if (cummul == ""):
  285. cummul = elem
  286. else:
  287. cummul = string_join(cummul + "/", elem)
  288. if (get_entry_id(cummul) == ""):
  289. if (allow_write(user_id, prev)):
  290. // Element does not exist yet!
  291. new_entry = instantiate_node(core, "Folder", "")
  292. instantiate_attribute(core, new_entry, "name", cummul)
  293. instantiate_attribute(core, new_entry, "permissions", "200")
  294. instantiate_link(core, "contains", "", prev, new_entry)
  295. instantiate_link(core, "group", "", new_entry, get_group_id("nobody"))
  296. instantiate_link(core, "owner", "", new_entry, user_id)
  297. else:
  298. return read_root()!
  299. prev = get_entry_id(cummul)
  300. i = i + 1
  301. return prev!
  302. String function store_entry(model_id : String, full_name : String, user_id : String):
  303. String prev
  304. if (get_entry_id(full_name) != ""):
  305. // Delete any old models
  306. model_delete(get_entry_id(full_name))
  307. prev = create_folders(user_id, get_foldername(full_name))
  308. instantiate_link(core, "contains", "", prev, model_id)
  309. return full_name!
  310. String function export_typing(model : Element, name : String):
  311. String result
  312. result = instantiate_node(core, "TypeMapping", "")
  313. name = "type mappings/" + name
  314. // Create type mapping model
  315. String location
  316. location = "type mappings/" + cast_id(get_type_mapping(model))
  317. export_node(location, get_type_mapping(model))
  318. String instance_of
  319. name = store_entry(result, name, get_user_id("admin"))
  320. instantiate_attribute(core, result, "name", name)
  321. instantiate_attribute(core, result, "location", location)
  322. instantiate_attribute(core, result, "permissions", "200")
  323. instantiate_link(core, "owner", "", result, current_user_id)
  324. instantiate_link(core, "group", "", result, get_group_id("nobody"))
  325. instance_of = instantiate_link(core, "instanceOf", "", result, get_entry_id("formalisms/TypeMapping"))
  326. instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
  327. return result!
  328. Void function model_create(model : Element, name : String, type_id : String, kind : String):
  329. String location
  330. String model_id
  331. String instance_of
  332. // Create model itself
  333. location = "models/" + cast_id(model)
  334. export_node(location, model["model"])
  335. model_id = instantiate_node(core, kind, "")
  336. instantiate_attribute(core, model_id, "name", store_entry(model_id, name, current_user_id))
  337. instantiate_attribute(core, model_id, "location", location)
  338. instantiate_attribute(core, model_id, "permissions", "200")
  339. instantiate_link(core, "owner", "", model_id, current_user_id)
  340. instantiate_link(core, "group", "", model_id, get_group_id("nobody"))
  341. instance_of = instantiate_link(core, "instanceOf", "", model_id, type_id)
  342. instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
  343. // Create type mapping model
  344. instantiate_link(core, "typing", "", instance_of, export_typing(model, name))
  345. return!
  346. Void function model_overwrite(model : Element, model_id : String, metamodel_id : String):
  347. // TODO this should be more elegant than just hiding the old elements
  348. String location
  349. String instanceOf_link
  350. location = "models/" + cast_id(model)
  351. export_node(location, model["model"])
  352. // Change location in meta-data
  353. unset_attribute(core, model_id, "location")
  354. instantiate_attribute(core, model_id, "location", location)
  355. // Update the instanceOf relation of the context in which we are working
  356. String choice
  357. choice = get_instanceOf_link(model_id, metamodel_id)
  358. if (element_neq(choice, read_root())):
  359. // There was a link, so we remove it
  360. // First remove the type mapping it referred to
  361. Element tl
  362. tl = allAssociationDestinations(core, choice, "typing")
  363. while (set_len(tl) > 0):
  364. model_delete_element(core, set_pop(tl))
  365. // Now delete the element itself
  366. model_delete_element(core, choice)
  367. // Create a new instanceOf relation now
  368. String instance_of
  369. instance_of = instantiate_link(core, "instanceOf", "", model_id, metamodel_id)
  370. instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
  371. instantiate_link(core, "typing", "", instance_of, export_typing(model, full_name(model_id)))
  372. return!
  373. Boolean function check_conformance(model_id : String):
  374. // TODO check if it actually conforms, considering that instanceOf link
  375. // --> in-depth check
  376. return True!
  377. Element function merge_models(models_dict : Element, operation_name : String):
  378. core = import_node(core_model_location)
  379. // 0) Find operation signature
  380. Element input_metamodels
  381. Element iter
  382. String edge
  383. String operation_id
  384. operation_id = get_entry_id(operation_name)
  385. input_metamodels = dict_create()
  386. iter = allOutgoingAssociationInstances(core, operation_id, "transformInput")
  387. while (set_len(iter) > 0):
  388. edge = set_pop(iter)
  389. dict_add(input_metamodels, read_attribute(core, edge, "name"), read_attribute(core, readAssociationDestination(core, edge), "name"))
  390. String merged_metamodel_id
  391. String trace_link_id
  392. Element trace_links
  393. // 1) Find merged metamodel
  394. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  395. merged_metamodel_id = ""
  396. while (set_len(trace_links) > 0):
  397. trace_link_id = set_pop(trace_links)
  398. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  399. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  400. // 2) Merge source models
  401. if (merged_metamodel_id != ""):
  402. Element model_tuples
  403. Element keys
  404. String key
  405. Element mm
  406. model_tuples = set_create()
  407. keys = dict_keys(models_dict)
  408. while (set_len(keys) > 0):
  409. key = set_pop(keys)
  410. mm = get_full_model(get_entry_id(models_dict[key]), get_entry_id(input_metamodels[key]))
  411. if (element_eq(mm, read_root())):
  412. log("Signature mismatch in operation for tag " + key)
  413. output("Signature mismatch in operation for tag " + key)
  414. return read_root()!
  415. set_add_node(model_tuples, create_tuple(key, mm))
  416. Element merged_metamodel
  417. merged_metamodel = get_full_model(merged_metamodel_id, get_entry_id("SimpleClassDiagrams"))
  418. if (element_eq(merged_metamodel, read_root())):
  419. log("Merged metamodel in operation is not of type SimpleClassDiagrams")
  420. output("Merged metamodel in operation is not of type SimpleClassDiagrams")
  421. return read_root()!
  422. return model_join(model_tuples, merged_metamodel, read_root())!
  423. else:
  424. return read_root()!
  425. Element function split_model(model : Element, metamodels_dict : Element):
  426. core = import_node(core_model_location)
  427. Element model_tuples
  428. Element keys
  429. String key
  430. Element mm
  431. model_tuples = set_create()
  432. keys = dict_keys(metamodels_dict)
  433. while (set_len(keys) > 0):
  434. key = set_pop(keys)
  435. mm = get_full_model(get_entry_id(metamodels_dict[key]), get_entry_id("SimpleClassDiagrams"))
  436. if (element_eq(mm, read_root())):
  437. log("Output metamodel cannot be interpreted using SimpleClassDiagrams: " + key)
  438. output("Output metamodel cannot be interpreted using SimpleClassDiagrams: " + key)
  439. return read_root()!
  440. set_add_node(model_tuples, create_tuple(key, mm))
  441. return model_split(model, model_tuples, read_root())!
  442. Element function get_model(model_name : String, metamodel_name : String):
  443. core = import_node(core_model_location)
  444. return get_full_model(get_entry_id(model_name), get_entry_id(metamodel_name))!
  445. Void function store_model(model_name : String, metamodel_name : String, model : Element):
  446. core = import_node(core_model_location)
  447. if (get_entry_id(model_name) == ""):
  448. // New model
  449. model_create(model, model_name, get_entry_id(metamodel_name), "Model")
  450. else:
  451. model_overwrite(model, get_entry_id(model_name), get_entry_id(metamodel_name))
  452. return!
  453. String function get_ramified_metamodel(model_name : String):
  454. core = import_node(core_model_location)
  455. String operation_id
  456. Element trace_links
  457. String merged_metamodel_id
  458. String trace_link_id
  459. String ramified_metamodel_id
  460. operation_id = get_entry_id(model_name)
  461. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  462. merged_metamodel_id = ""
  463. while (set_len(trace_links) > 0):
  464. trace_link_id = set_pop(trace_links)
  465. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  466. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  467. trace_links = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  468. ramified_metamodel_id = ""
  469. while (set_len(trace_links) > 0):
  470. trace_link_id = set_pop(trace_links)
  471. if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
  472. ramified_metamodel_id = readAssociationDestination(core, trace_link_id)
  473. return read_attribute(core, ramified_metamodel_id, "name")!
  474. return read_root()!
  475. Element function execute_operation(operation_id : String, input_models : Element, tracability_model : Element):
  476. // Operations are always in-place and uses only a single metamodel
  477. // Therefore, we must:
  478. // 1) Find merged metamodel
  479. // 2) Merge the different source models and retype
  480. // 3) Perform the operation on the merged model
  481. // 4) Split the resulting model based on the target formalisms; if operation successful
  482. Element input_model
  483. String trace_link_id
  484. Element merged_model
  485. String merged_metamodel_id
  486. String ramified_metamodel_id
  487. Boolean result
  488. String exact_type
  489. Element trace_links
  490. String model_ID
  491. String key
  492. Element keys
  493. Element input_keys
  494. Element output_keys
  495. Element model_tuples
  496. String metamodel_name
  497. Element metamodel
  498. String metamodel_ID
  499. Boolean tracability
  500. // 0) Find the signature of the operation
  501. Element input_metamodels
  502. Element output_metamodels
  503. Element iter
  504. String edge
  505. input_metamodels = dict_create()
  506. iter = allOutgoingAssociationInstances(core, operation_id, "transformInput")
  507. while (set_len(iter) > 0):
  508. edge = set_pop(iter)
  509. dict_add(input_metamodels, read_attribute(core, edge, "name"), full_name(readAssociationDestination(core, edge)))
  510. output_metamodels = dict_create()
  511. iter = allOutgoingAssociationInstances(core, operation_id, "transformOutput")
  512. while (set_len(iter) > 0):
  513. edge = set_pop(iter)
  514. dict_add(output_metamodels, read_attribute(core, edge, "name"), full_name(readAssociationDestination(core, edge)))
  515. // 1) Find merged metamodel
  516. exact_type = read_type(core, operation_id)
  517. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  518. merged_metamodel_id = ""
  519. while (set_len(trace_links) > 0):
  520. trace_link_id = set_pop(trace_links)
  521. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  522. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  523. // 2) Merge source models
  524. if (merged_metamodel_id != ""):
  525. model_tuples = set_create()
  526. keys = dict_keys(input_models)
  527. while (set_len(keys) > 0):
  528. key = set_pop(keys)
  529. Element mm
  530. if (get_entry_id(input_models[key]) == ""):
  531. // Input model doesn't exist yet, so create
  532. cmd_model_add(input_metamodels[key], input_models[key], "")
  533. log("Creating non-existing input model")
  534. mm = get_full_model(get_entry_id(input_models[key]), get_entry_id(input_metamodels[key]))
  535. if (element_eq(mm, read_root())):
  536. log("Signature mismatch in operation for tag " + key)
  537. output("Signature mismatch in operation for tag " + key)
  538. return read_root()!
  539. set_add_node(model_tuples, create_tuple(key, mm))
  540. Element merged_metamodel
  541. merged_metamodel = get_full_model(merged_metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  542. if (element_eq(merged_metamodel, read_root())):
  543. log("Merged metamodel in operation is not of type formalisms/SimpleClassDiagrams")
  544. output("Merged metamodel in operation is not of type formalisms/SimpleClassDiagrams")
  545. return read_root()!
  546. merged_model = model_join(model_tuples, merged_metamodel, tracability_model)
  547. else:
  548. if (bool_and(dict_len(input_models) == 1, dict_len(output_metamodels) == 0)):
  549. // Just skip the merge...
  550. Element m
  551. m = get_full_model(get_entry_id(input_models[set_pop(dict_keys(input_models))]), get_entry_id(input_metamodels[set_pop(dict_keys(input_metamodels))]))
  552. if (element_eq(m, read_root())):
  553. log("Signature mismatch in operation for tag " + cast_value(set_pop(dict_keys(input_models))))
  554. output("Signature mismatch in operation for tag " + cast_value(set_pop(dict_keys(input_models))))
  555. return read_root()!
  556. merged_model = model_copy(m)
  557. elif (bool_and(dict_len(input_models) == 0, dict_len(output_metamodels) == 0)):
  558. merged_model = read_root()
  559. else:
  560. log("Could not resolve intermediate merged metamodel")
  561. output("Could not resolve intermediate merged metamodel")
  562. return read_root()!
  563. // 3) Transform
  564. if (exact_type == "ModelTransformation"):
  565. trace_links = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  566. ramified_metamodel_id = ""
  567. while (set_len(trace_links) > 0):
  568. trace_link_id = set_pop(trace_links)
  569. if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
  570. ramified_metamodel_id = readAssociationDestination(core, trace_link_id)
  571. Element operation
  572. operation = get_full_model(operation_id, ramified_metamodel_id)
  573. if (element_eq(operation, read_root())):
  574. log("Operation could not be typed by specified RAMified metamodel!")
  575. output("Operation could not be typed by specified RAMified metamodel!")
  576. return read_root()!
  577. result = transform(merged_model, operation)
  578. elif (exact_type == "ManualOperation"):
  579. output("Please perform manual operation " + cast_value(full_name(operation_id)))
  580. String model_name
  581. model_name = ""
  582. while (get_entry_id(model_name) != ""):
  583. model_name = ".tmp/" + random_string(20)
  584. model_create(merged_model, model_name, merged_metamodel_id, "Model")
  585. // We want to modify, so modify
  586. do_spawn_modify(model_name, True)
  587. merged_model = get_full_model(get_entry_id(model_name), merged_metamodel_id)
  588. //model_delete(get_entry_id(model_name))
  589. result = True
  590. elif (exact_type == "ActionLanguage"):
  591. Element func
  592. Element al
  593. al = get_full_model(operation_id, get_entry_id("formalisms/ActionLanguage"))
  594. if (element_eq(al, read_root())):
  595. log("Action Language operation not typed by ActionLanguage metamodel!")
  596. output("Action Language operation not typed by ActionLanguage metamodel!")
  597. return read_root()!
  598. func = get_func_AL_model(al)
  599. result = func(merged_model)
  600. else:
  601. log("Unknown type of operation: " + exact_type)
  602. output("Unknown type of operation: " + exact_type)
  603. return read_root()!
  604. // 4) Split in different models depending on type
  605. if (element_neq(tracability_model, read_root())):
  606. tracability = True
  607. else:
  608. tracability = False
  609. if (result):
  610. model_tuples = set_create()
  611. keys = dict_keys(output_metamodels)
  612. while (set_len(keys) > 0):
  613. key = set_pop(keys)
  614. Element mm
  615. mm = get_full_model(get_entry_id(output_metamodels[key]), get_entry_id("formalisms/SimpleClassDiagrams"))
  616. if (element_eq(mm, read_root())):
  617. log("Output metamodel cannot be interpreted using formalisms/SimpleClassDiagrams: " + key)
  618. output("Output metamodel cannot be interpreted using formalisms/SimpleClassDiagrams: " + key)
  619. return read_root()!
  620. set_add_node(model_tuples, create_tuple(key, mm))
  621. result = model_split(merged_model, model_tuples, tracability)
  622. if (tracability):
  623. Element new_tracability_model
  624. new_tracability_model = result["__tracability"]
  625. dict_overwrite(tracability_model, "model", new_tracability_model["model"])
  626. set_type_mapping(tracability_model, get_type_mapping(new_tracability_model))
  627. dict_overwrite(tracability_model, "metamodel", new_tracability_model["metamodel"])
  628. dict_delete(result, "__tracability")
  629. return result!
  630. else:
  631. log("Negative result of execution")
  632. return read_root()!
  633. Boolean function enact_action(pm : Element, element : String, mapping : Element):
  634. Boolean result
  635. String transformation_id
  636. Element lst
  637. String elem
  638. Element inputs
  639. Element outputs
  640. String type_name
  641. String exact_type
  642. Element trace_links
  643. Element output_mms
  644. Element consumes_link
  645. String name
  646. String elem_name
  647. Element keys
  648. String key
  649. String consume
  650. String produce
  651. Element input_traceability_model
  652. String output_traceability_name
  653. String output_traceability_type
  654. Element output_map
  655. inputs = dict_create()
  656. outputs = dict_create()
  657. output_map = dict_create()
  658. input_traceability_model = read_root()
  659. output_traceability_name = read_root()
  660. output_traceability_type = read_root()
  661. // Read out the referenced element from the MvC
  662. transformation_id = get_entry_id(read_attribute(pm, element, "name"))
  663. // Find all input model names
  664. lst = allOutgoingAssociationInstances(pm, element, "Consumes")
  665. while (set_len(lst) > 0):
  666. consume = set_pop(lst)
  667. elem = readAssociationDestination(pm, consume)
  668. type_name = read_attribute(pm, elem, "type")
  669. elem_name = read_attribute(pm, elem, "name")
  670. if (cast_string(read_attribute(pm, consume, "name")) == "__traceability"):
  671. log("Using input traceability model!")
  672. log("Mapping: " + cast_string(mapping[elem_name]))
  673. log("Type: " + cast_string(type_name))
  674. log("Entry mapping: " + get_entry_id(mapping[elem_name]))
  675. log("Entry type: " + get_entry_id(type_name))
  676. input_traceability_model = model_copy(get_full_model(get_entry_id(mapping[elem_name]), get_entry_id(type_name)))
  677. output_traceability_type = type_name
  678. else:
  679. dict_add(inputs, read_attribute(pm, consume, "name"), mapping[elem_name])
  680. // Find all output model names and their metamodel
  681. lst = allOutgoingAssociationInstances(pm, element, "Produces")
  682. while (set_len(lst) > 0):
  683. produce = set_pop(lst)
  684. elem = readAssociationDestination(pm, produce)
  685. type_name = read_attribute(pm, elem, "type")
  686. elem_name = read_attribute(pm, elem, "name")
  687. if (cast_string(read_attribute(pm, produce, "name")) == "__traceability"):
  688. output_traceability_name = mapping[elem_name]
  689. else:
  690. dict_add(outputs, read_attribute(pm, produce, "name"), type_name)
  691. dict_add(output_map, read_attribute(pm, produce, "name"), mapping[elem_name])
  692. if read_type(core, transformation_id) == "ActionLanguage":
  693. log(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  694. output("Success: ready for AL execution")
  695. elif read_type(core, transformation_id) == "ManualOperation":
  696. log(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  697. output("Success: ready for MANUAL execution")
  698. else:
  699. log(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  700. output("Success: ready for MT execution")
  701. result = execute_operation(transformation_id, inputs, input_traceability_model)
  702. if (element_eq(result, read_root())):
  703. // Something went wrong!
  704. output("Failure")
  705. return False!
  706. else:
  707. // Check if we have to store traceability information
  708. if (element_neq(output_traceability_name, read_root())):
  709. // Yes, so store it
  710. // Note that we have overwritten the previous input traceability model, which is why it was a copy
  711. model_overwrite(input_traceability_model, get_entry_id(output_traceability_name), get_entry_id(output_traceability_type))
  712. log("Writing output traceability model!")
  713. keys = dict_keys(outputs)
  714. while (set_len(keys) > 0):
  715. key = set_pop(keys)
  716. log("Overwriting model at " + key)
  717. log("Read from result: " + cast_id(result[key]))
  718. if (get_entry_id(output_map[key]) == ""):
  719. // New model
  720. model_create(result[key], output_map[key], get_entry_id(outputs[key]), "Model")
  721. else:
  722. model_overwrite(result[key], get_entry_id(output_map[key]), get_entry_id(outputs[key]))
  723. output("Success")
  724. return True!
  725. Element function PM_signature(pm : Element):
  726. Element all_data
  727. Element result
  728. String entry
  729. result = dict_create()
  730. all_data = allInstances(pm, "Data")
  731. while (set_len(all_data) > 0):
  732. entry = set_pop(all_data)
  733. dict_add(result, cast_string(read_attribute(pm, entry, "name")), cast_string(read_attribute(pm, entry, "type")))
  734. return result!
  735. Void function enact_PM_activity(activity_to_task : Element, task_to_result : Element, pm : Element, element : String, mapping : Element):
  736. Boolean result
  737. pm_tasks = activity_to_task
  738. set_add(activity_to_task[element], get_taskname())
  739. result = enact_action(pm, element, mapping)
  740. dict_add_fast(task_to_result, get_taskname(), result)
  741. while (other_has_output(get_taskname())):
  742. sleep(1)
  743. return!
  744. Void function enact_PM(pm : Element, mapping : Element):
  745. Element worklist
  746. String element
  747. String type
  748. Boolean result
  749. Element tuple
  750. Element counters
  751. Element join_nodes
  752. Element exec_nodes
  753. Element keys
  754. String key
  755. output("Success")
  756. // For all entries in the signature, not in the mapping, we add a mock location
  757. Element signature
  758. String mock_location
  759. Element mock_locations
  760. mock_locations = set_create()
  761. signature = PM_signature(pm)
  762. keys = dict_keys(signature)
  763. while (set_len(keys) > 0):
  764. key = set_pop(keys)
  765. if (bool_not(dict_in(mapping, key))):
  766. // Add mock location
  767. mock_location = ""
  768. while (get_entry_id(mock_location) != ""):
  769. mock_location = ".tmp/" + random_string(10)
  770. dict_add(mapping, key, mock_location)
  771. cmd_model_add(signature[key], mapping[key], "")
  772. set_add(mock_locations, mock_location)
  773. // Initialize Join counters
  774. counters = dict_create()
  775. join_nodes = allInstances(pm, "Join")
  776. while (set_len(join_nodes) > 0):
  777. dict_add(counters, set_pop(join_nodes), 0)
  778. // Initialize activity to task dictionary with empty sets
  779. Element activity_to_task
  780. Element task_to_activity
  781. Element task_to_result
  782. activity_to_task = dict_create()
  783. task_to_activity = dict_create()
  784. task_to_result = dict_create()
  785. exec_nodes = allInstances(pm, "Exec")
  786. while (set_len(exec_nodes) > 0):
  787. dict_add(activity_to_task, set_pop(exec_nodes), set_create())
  788. // Create the worklist with the Start instance as first element
  789. worklist = set_create()
  790. set_add(worklist, set_pop(allInstances(pm, "Start")))
  791. // Keep on iterating until we reach finish
  792. while (True):
  793. // Check if there are PM elements to expand
  794. if (set_len(worklist) > 0):
  795. // There is something we can do, so do it!
  796. element = set_pop(worklist)
  797. // Find the type (to see what to do with it)
  798. // this does not yet yield the type of transformation, if it is an Execution
  799. type = read_type(pm, element)
  800. // Some types have nothing to do, such as start and fork
  801. // Therefore, they are not mentioned in the following conditional
  802. if (type == "Finish"):
  803. // We have finished, so terminate
  804. log("Finished node reached!")
  805. break!
  806. elif (type == "Join"):
  807. // Only do this if all dependencies are fullfilled
  808. // So add to the counter of this Join
  809. dict_overwrite(counters, element, integer_addition(counters[element], 1))
  810. // Now check whether we have enough tokens to execute the Join itself
  811. Integer required
  812. Integer got
  813. required = set_len(allIncomingAssociationInstances(pm, element, "Next")) + set_len(allIncomingAssociationInstances(pm, element, "Else"))
  814. got = counters[element]
  815. if (got == required):
  816. // Reset counter to 0
  817. dict_overwrite(counters, element, 0)
  818. // And continue
  819. else:
  820. // We haven't gotten all yet, so we wait (i.e., continue without adding Next link to worklist)
  821. continue!
  822. elif (type == "Exec"):
  823. // Execute a transformation
  824. // This the difficult part!
  825. Element args
  826. String taskname
  827. args = list_create()
  828. list_append(args, activity_to_task)
  829. list_append(args, task_to_result)
  830. list_append(args, pm)
  831. list_append(args, element)
  832. list_append(args, mapping)
  833. taskname = spawn(enact_PM_activity, args)
  834. output(taskname + " : " + cast_string(read_attribute(pm, element, "name")))
  835. dict_add(task_to_activity, taskname, element)
  836. continue!
  837. // We have finished the execution, so add all outgoing edges to the worklist
  838. Element all_next
  839. all_next = allAssociationDestinations(pm, element, "Next")
  840. String next
  841. while (set_len(all_next) > 0):
  842. next = set_pop(all_next)
  843. set_add(worklist, next)
  844. else:
  845. // No new tasks to spawn, so go and check on all running activities
  846. if (dict_len(task_to_result) > 0):
  847. // There are outputs!
  848. Element keys
  849. String task
  850. keys = dict_keys(task_to_result)
  851. while (set_len(keys) > 0):
  852. task = set_pop(keys)
  853. result = task_to_result[task]
  854. Element all_next
  855. all_next = allAssociationDestinations(pm, task_to_activity[task], "Next")
  856. String next
  857. while (set_len(all_next) > 0):
  858. next = set_pop(all_next)
  859. if (read_type(pm, next) == "Decision"):
  860. // Got decision node, so expand immediately
  861. if (result):
  862. set_add(worklist, set_pop(allAssociationDestinations(pm, next, "Then")))
  863. else:
  864. set_add(worklist, set_pop(allAssociationDestinations(pm, next, "Else")))
  865. else:
  866. // Other node, so just append for further processing
  867. set_add(worklist, next)
  868. set_remove(activity_to_task[task_to_activity[task]], task)
  869. dict_delete(task_to_result, task)
  870. dict_delete(task_to_activity, task)
  871. else:
  872. // No finished activities either, so we sleep for some time
  873. sleep(0.1)
  874. // Remove all mock locations again
  875. while (set_len(mock_locations) > 0):
  876. model_delete(get_entry_id(set_pop(mock_locations)))
  877. return !
  878. String function cmd_help():
  879. String result
  880. result = ""
  881. result = result + ("Model operations\n")
  882. result = result + (" model_add -- Add a new model\n")
  883. result = result + (" model_modify -- Modify an existing model\n")
  884. result = result + (" model_list -- List all models\n")
  885. result = result + (" model_list_full -- List all models with full info\n")
  886. result = result + (" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata\n")
  887. result = result + (" model_render -- Render a given model with a specified mapper\n")
  888. result = result + (" verify -- Check whether a model conforms to its metamodel\n")
  889. result = result + ("\n")
  890. result = result + ("Transformation-specific operations\n")
  891. result = result + (" transformation_add_MT -- Initialize a new model transformation\n")
  892. result = result + (" transformation_add_AL -- Initialize a new action language transformation\n")
  893. result = result + (" transformation_add_MANUAL -- Initialize a new manual transformation\n")
  894. result = result + (" transformation_execute -- Execute a transformation on a set of input models\n")
  895. result = result + (" transformation_list -- List all model transformations\n")
  896. result = result + (" transformation_list_full -- List all model transformations with permissions\n")
  897. result = result + (" transformation_detail -- List transformation details\n")
  898. result = result + (" transformation_between -- List all transformations between two metamodels\n")
  899. result = result + ("\n")
  900. result = result + ("Process operations\n")
  901. result = result + (" process_execute -- Execute a process model\n")
  902. result = result + ("\n")
  903. result = result + ("Model permission operations\n")
  904. result = result + (" permission_modify -- Change model permissions\n")
  905. result = result + (" permission_owner -- Change model owner\n")
  906. result = result + (" permission_group -- Change model group\n")
  907. result = result + ("\n")
  908. result = result + ("Group operations\n")
  909. result = result + (" group_create -- Create a group\n")
  910. result = result + (" group_delete -- Delete a group\n")
  911. result = result + (" group_owner_add -- Add group owner\n")
  912. result = result + (" group_owner_delete -- Remove group owner\n")
  913. result = result + (" group_join -- Add someone to your group\n")
  914. result = result + (" group_kick -- Kick someone from your group\n")
  915. result = result + (" group_list -- List all groups you are a member of\n")
  916. result = result + ("\n")
  917. if (is_admin(current_user_id)):
  918. result = result + ("Admin operations\n")
  919. result = result + (" admin_promote -- Promote a user to admin status\n")
  920. result = result + (" admin_demote -- Demote a user to normal status\n")
  921. result = result + ("\n")
  922. result = result + ("General operations\n")
  923. result = result + (" self-destruct -- Remove current user and revoke all permissions \n")
  924. result = result + (" exit -- Kill the current task, while retaining user\n")
  925. return result!
  926. String function cmd_model_add(type : String, name : String, code : String):
  927. // Model addition operation, which uses model upload commands of the compiler
  928. String location
  929. String type_id
  930. Element new_model
  931. String new_model_id
  932. type_id = get_entry_id(type)
  933. if (type_id != ""):
  934. // Type exists
  935. if (allow_read(current_user_id, type_id)):
  936. // And is readable
  937. create_folders(current_user_id, get_foldername(name))
  938. //TODO check if bottommost existing model was writable by us
  939. if (get_entry_id(name) == ""):
  940. // Model doesn't exist yet
  941. Element mm
  942. mm = get_full_model(type_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  943. if (element_eq(mm, read_root())):
  944. return "Type is not typed by formalisms/SimpleClassDiagrams: " + type!
  945. new_model = compile_model(code, mm)
  946. if (element_eq(new_model, read_root())):
  947. return "Compilation error"!
  948. model_create(new_model, name, type_id, "Model")
  949. return "Success"!
  950. else:
  951. return "Model exists: " + name!
  952. else:
  953. return "Permission denied to model: " + type!
  954. else:
  955. return "Model not found: " + type!
  956. String function cmd_process_execute(process : String, mapping : Element):
  957. // Execute a process model until it reaches termination
  958. String process_id
  959. process_id = get_entry_id(process)
  960. if (process_id != ""):
  961. if (allow_read(current_user_id, process_id)):
  962. Element pm
  963. pm = get_full_model(process_id, get_entry_id("formalisms/ProcessModel"))
  964. if (element_eq(pm, read_root())):
  965. return "Specified model cannot be interpreted as a ProcessModel: " + process!
  966. enact_PM(pm, mapping)
  967. return "Success"!
  968. else:
  969. return "Permission denied to model: " + process!
  970. else:
  971. return "Model not found: " + process!
  972. String function cmd_process_signature(process : String):
  973. // Execute a process model until it reaches termination
  974. String process_id
  975. String result
  976. Element signature
  977. Element keys
  978. String key
  979. process_id = get_entry_id(process)
  980. if (process_id != ""):
  981. if (allow_read(current_user_id, process_id)):
  982. Element pm
  983. pm = get_full_model(process_id, get_entry_id("formalisms/ProcessModel"))
  984. if (element_eq(pm, read_root())):
  985. return "Specified model cannot be interpreted as a ProcessModel: " + process!
  986. result = "Success: "
  987. signature = PM_signature(pm)
  988. keys = dict_keys(signature)
  989. while (set_len(keys) > 0):
  990. key = set_pop(keys)
  991. result = result + key + " : " + cast_string(signature[key]) + "\n"
  992. return result!
  993. else:
  994. return "Permission denied to model: " + process!
  995. else:
  996. return "Model not found: " + process!
  997. String function cmd_transformation_between(source_dict : String, target_dict : String):
  998. Element result
  999. Element subresult
  1000. String tag
  1001. String mm
  1002. String mm_id
  1003. Element links
  1004. String link
  1005. Element keys
  1006. result = allInstances(core, "Transformation")
  1007. // Iterate over all inputs
  1008. keys = dict_keys(source_dict)
  1009. while (set_len(keys) > 0):
  1010. subresult = set_create()
  1011. tag = set_pop(keys)
  1012. mm = source_dict[tag]
  1013. mm_id = get_entry_id(mm)
  1014. if (mm_id != ""):
  1015. links = allIncomingAssociationInstances(core, mm_id, "transformInput")
  1016. while (set_len(links) > 0):
  1017. link = set_pop(links)
  1018. if (value_eq(read_attribute(core, link, "name"), tag)):
  1019. // Correct tag, so make transformation a possibility
  1020. set_add(subresult, readAssociationSource(core, link))
  1021. else:
  1022. return "Model not found: " + mm!
  1023. // Got a set of subresults now, which we use to find the overlap
  1024. result = set_overlap(result, subresult)
  1025. keys = dict_keys(target_dict)
  1026. while (set_len(keys) > 0):
  1027. subresult = set_create()
  1028. tag = set_pop(keys)
  1029. mm = target_dict[tag]
  1030. mm_id = get_entry_id(mm)
  1031. if (mm_id != ""):
  1032. links = allIncomingAssociationInstances(core, mm_id, "transformOutput")
  1033. while (set_len(links) > 0):
  1034. link = set_pop(links)
  1035. if (value_eq(read_attribute(core, link, "name"), tag)):
  1036. // Correct tag, so make transformation a possibility
  1037. set_add(subresult, readAssociationSource(core, link))
  1038. else:
  1039. return "Model not found: " + mm!
  1040. // Got a set of subresults now, which we use to find the overlap
  1041. result = set_overlap(result, subresult)
  1042. String r
  1043. String transformation
  1044. r = "Success: "
  1045. while (set_len(result) > 0):
  1046. transformation = set_pop(result)
  1047. if (allow_read(current_user_id, transformation)):
  1048. r = r + string_join(full_name(transformation), "\n")
  1049. return r!
  1050. String function cmd_model_rendered(model_name : String, mapper_name : String):
  1051. Element trace_links
  1052. String rendered
  1053. String trace_link_id
  1054. String allowed_rendered
  1055. Element trace_links_2
  1056. String trace_link_2_id
  1057. allowed_rendered = "Success: "
  1058. trace_links = allOutgoingAssociationInstances(core, get_entry_id(model_name), "tracability")
  1059. while (set_len(trace_links) > 0):
  1060. trace_link_id = set_pop(trace_links)
  1061. if (value_eq(read_attribute(core, trace_link_id, "type"), "CS_perceptualized")):
  1062. rendered = readAssociationDestination(core, trace_link_id)
  1063. trace_links_2 = allOutgoingAssociationInstances(core, rendered, "tracability")
  1064. while (set_len(trace_links_2) > 0):
  1065. trace_link_2_id = set_pop(trace_links_2)
  1066. if (value_eq(read_attribute(core, readAssociationDestination(core, trace_link_2_id), "name"), mapper_name)):
  1067. if (value_eq(read_attribute(core, trace_link_2_id, "type"), "CS_mapper")):
  1068. allowed_rendered = string_join(allowed_rendered, read_attribute(core, rendered, "name")) + "\n"
  1069. return allowed_rendered!
  1070. String function cmd_model_render(model_name : String, mapper_name : String, rendered_name : String):
  1071. String model_ID
  1072. String mapper_ID
  1073. String tracability_name
  1074. Element inputs
  1075. Element output_map
  1076. Element rendered_model
  1077. Element tracability_model
  1078. Element result
  1079. Element out_links
  1080. String link
  1081. String ID_rendered_M
  1082. String ID_rendered_MM
  1083. String ID_SCD
  1084. String ID_tracability_MM
  1085. String ID_tracability_M
  1086. model_ID = get_entry_id(model_name)
  1087. if (model_ID != ""):
  1088. mapper_ID = get_entry_id(mapper_name)
  1089. if (allow_read(current_user_id, model_ID)):
  1090. if (mapper_ID != ""):
  1091. if (allow_read(current_user_id, mapper_ID)):
  1092. // Everything is fine; start the actual operation
  1093. // Find metamodel to render to
  1094. tracability_name = "tracability/" + rendered_name
  1095. // Take the abstract syntax model and the previously rendered model
  1096. inputs = dict_create()
  1097. dict_add(inputs, "abstract", model_name)
  1098. dict_add(inputs, "rendered", rendered_name)
  1099. // Fetch the output types
  1100. output_map = dict_create()
  1101. out_links = allOutgoingAssociationInstances(core, mapper_ID, "transformOutput")
  1102. while(set_len(out_links) > 0):
  1103. link = set_pop(out_links)
  1104. dict_add(output_map, read_attribute(core, link, "name"), full_name(readAssociationDestination(core, link)))
  1105. ID_rendered_MM = get_entry_id(output_map["rendered"])
  1106. ID_SCD = get_entry_id("formalisms/SimpleClassDiagrams")
  1107. ID_tracability_MM = get_entry_id("formalisms/Tracability")
  1108. ID_tracability_M = get_entry_id(tracability_name)
  1109. ID_rendered_M = get_entry_id(rendered_name)
  1110. if (ID_rendered_M == ""):
  1111. // Instantiate
  1112. Element rendered
  1113. rendered = get_full_model(ID_rendered_MM, ID_SCD)
  1114. if (element_eq(rendered, read_root())):
  1115. return "Rendered metamodel doesn't conform to formalisms/SimpleClassDiagrams"!
  1116. rendered_model = instantiate_model(rendered)
  1117. model_create(rendered_model, rendered_name, ID_rendered_MM, "Model")
  1118. // Tracability model won't exist either
  1119. tracability_model = instantiate_model(get_full_model(ID_tracability_MM, ID_SCD))
  1120. model_create(tracability_model, tracability_name, ID_tracability_MM, "Model")
  1121. ID_rendered_M = get_entry_id(rendered_name)
  1122. ID_tracability_M = get_entry_id(tracability_name)
  1123. else:
  1124. // Read out tracability model
  1125. tracability_model = get_full_model(ID_tracability_M, ID_tracability_MM)
  1126. if (element_eq(tracability_model, read_root())):
  1127. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  1128. // Do the operation itself!
  1129. result = execute_operation(mapper_ID, inputs, tracability_model)
  1130. // Overwrite the previous rendered model
  1131. model_overwrite(result["rendered"], ID_rendered_M, ID_rendered_MM)
  1132. // Tracability updated in-place
  1133. model_overwrite(tracability_model, ID_tracability_M, ID_tracability_MM)
  1134. if (element_eq(tracability_model, read_root())):
  1135. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  1136. // Link all information in the megamodel
  1137. String tr_link
  1138. tr_link = instantiate_link(core, "tracability", "", get_entry_id(model_name), ID_rendered_M)
  1139. instantiate_attribute(core, tr_link, "type", "CS_perceptualized")
  1140. tr_link = instantiate_link(core, "tracability", "", ID_rendered_M, get_entry_id(mapper_name))
  1141. instantiate_attribute(core, tr_link, "type", "CS_mapper")
  1142. // Output the resulting model
  1143. String value
  1144. value = JSON_print(result["rendered"])
  1145. return ("Success: " + value) !
  1146. else:
  1147. return "Permission denied to model: " + mapper_name!
  1148. else:
  1149. return "Model not found: " + mapper_name!
  1150. else:
  1151. return "Permission denied to model: " + model_name!
  1152. else:
  1153. return "Model not found: " + model_name!
  1154. Boolean function do_spawn_modify(model_name : String, write : Boolean):
  1155. output("Please edit this model before sending next input: " + model_name)
  1156. input()
  1157. return False!
  1158. Boolean function do_spawn_activity(transformation_id : String, tracability_name : String, inputs : Element, outputs : Element, output_map : Element):
  1159. Element lst
  1160. Element returnvalue
  1161. String taskname
  1162. lst = list_create()
  1163. returnvalue = set_create()
  1164. list_append(lst, returnvalue)
  1165. list_append(lst, transformation_id)
  1166. list_append(lst, tracability_name)
  1167. list_append(lst, inputs)
  1168. list_append(lst, outputs)
  1169. list_append(lst, output_map)
  1170. taskname = spawn(spawn_activity, lst)
  1171. output("Spawned activity on task: " + taskname)
  1172. while (set_len(returnvalue) == 0):
  1173. sleep(0.1)
  1174. output("Finished task: " + taskname)
  1175. return cast_boolean(set_pop(returnvalue))!
  1176. Void function spawn_activity(returnvalue : Element, transformation_id : String, tracability_name : String, inputs : Element, outputs : Element, output_map : Element):
  1177. Element result
  1178. Element keys
  1179. String key
  1180. if (read_type(core, transformation_id) == "ActionLanguage"):
  1181. output("Success: ready for AL execution")
  1182. elif (read_type(core, transformation_id) == "ManualOperation"):
  1183. output("Success: ready for MANUAL execution")
  1184. else:
  1185. output("Success: ready for MT execution")
  1186. // Do tracability
  1187. Element tracability_model
  1188. if (tracability_name != ""):
  1189. // Check if exists
  1190. if (get_entry_id(tracability_name) == ""):
  1191. // No, so create
  1192. tracability_model = instantiate_model(get_full_model(get_entry_id("formalisms/Tracability"), get_entry_id("formalisms/SimpleClassDiagrams")))
  1193. model_create(tracability_model, tracability_name, get_entry_id("formalisms/Tracability"), "Model")
  1194. else:
  1195. // Yes, so read out
  1196. tracability_model = get_full_model(get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
  1197. else:
  1198. tracability_model = read_root()
  1199. result = execute_operation(transformation_id, inputs, tracability_model)
  1200. // Flush tracability again, just to be sure
  1201. if (tracability_name != ""):
  1202. model_overwrite(tracability_model, get_entry_id(tracability_name), get_entry_id("formalisms/Tracability"))
  1203. // Now write out the models again
  1204. if (element_eq(result, read_root())):
  1205. // Something went wrong!
  1206. set_add(returnvalue, False)
  1207. output("Failure")
  1208. else:
  1209. keys = dict_keys(outputs)
  1210. while (set_len(keys) > 0):
  1211. key = set_pop(keys)
  1212. if (get_entry_id(outputs[key]) == ""):
  1213. // New model
  1214. model_create(result[key], outputs[key], get_entry_id(output_map[key]), "Model")
  1215. else:
  1216. model_overwrite(result[key], get_entry_id(outputs[key]), get_entry_id(output_map[key]))
  1217. set_add(returnvalue, True)
  1218. output("Success")
  1219. while (other_has_output(get_taskname())):
  1220. sleep(1)
  1221. return!
  1222. String function cmd_transformation_execute(transformation_name : String, source_models : Element, target_models : Element, tracability_name : String):
  1223. // Execute a transformation, whatever type it is
  1224. // First we detect the type, so we know how to prepare for invocation
  1225. String transformation_id
  1226. String exact_type
  1227. Element sources
  1228. Element targets
  1229. String source
  1230. String target
  1231. Element inputs
  1232. Element outputs
  1233. Element output_map
  1234. Element trace_links
  1235. String target_model_name
  1236. String source_model_name
  1237. String source_model_ID
  1238. String assoc_name
  1239. transformation_id = get_entry_id(transformation_name)
  1240. if (transformation_id != ""):
  1241. if (allow_read(current_user_id, transformation_id)):
  1242. if (is_nominal_instance(core, transformation_id, "Transformation")):
  1243. // Read out source and target links
  1244. inputs = dict_create()
  1245. sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
  1246. while (set_len(sources) > 0):
  1247. source = set_pop(sources)
  1248. assoc_name = read_attribute(core, source, "name")
  1249. if (dict_in(source_models, assoc_name)):
  1250. source_model_name = source_models[assoc_name]
  1251. else:
  1252. return "Source model not bound: " + assoc_name!
  1253. source_model_ID = get_entry_id(source_model_name)
  1254. if (source_model_ID != ""):
  1255. if (allow_read(current_user_id, source_model_ID)):
  1256. // Check for conformance to the requested metamodel
  1257. dict_add(inputs, assoc_name, source_model_name)
  1258. continue!
  1259. else:
  1260. return "Permission denied to model: " + source_model_name!
  1261. else:
  1262. return "Model not found: " + source_model_name!
  1263. targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
  1264. outputs = dict_create()
  1265. output_map = dict_create()
  1266. while (set_len(targets) > 0):
  1267. target = set_pop(targets)
  1268. assoc_name = read_attribute(core, target, "name")
  1269. if (dict_in(target_models, assoc_name)):
  1270. target_model_name = target_models[assoc_name]
  1271. if (get_entry_id(target_model_name) == ""):
  1272. // Doesn't exist yet, so we can easily create
  1273. if (get_entry_id(get_foldername(target_model_name)) == ""):
  1274. return "Folder not found: " + get_foldername(target_model_name)!
  1275. else:
  1276. if (allow_write(current_user_id, get_entry_id(get_foldername(target_model_name)))):
  1277. dict_add(output_map, assoc_name, full_name(readAssociationDestination(core, target)))
  1278. dict_add(outputs, assoc_name, target_model_name)
  1279. else:
  1280. return "Permission denied to folder: " + get_foldername(target_model_name)!
  1281. else:
  1282. // Already exists, so we need to check for write access
  1283. if (allow_write(current_user_id, get_entry_id(target_model_name))):
  1284. dict_add(output_map, assoc_name, read_attribute(core, readAssociationDestination(core, target), "name"))
  1285. dict_add(outputs, assoc_name, target_model_name)
  1286. else:
  1287. return "Permission denied to model: " + target_model_name!
  1288. if (do_spawn_activity(transformation_id, tracability_name, inputs, outputs, output_map)):
  1289. return "Success"!
  1290. else:
  1291. return "Failure"!
  1292. else:
  1293. return "Model is not executable: " + transformation_name!
  1294. else:
  1295. return "Permission denied to model: " + transformation_name!
  1296. else:
  1297. return "Model not found: " + transformation_name!
  1298. String function cmd_verify(model_name : String, metamodel_name : String):
  1299. // Check whether a model conforms to its specification (with the selected type mapping)
  1300. String model_id
  1301. String result
  1302. Element inputs
  1303. model_id = get_entry_id(model_name)
  1304. if (model_id != ""):
  1305. if (allow_read(current_user_id, model_id)):
  1306. if (get_entry_id(metamodel_name) != ""):
  1307. if (allow_read(current_user_id, get_entry_id(metamodel_name))):
  1308. Element m
  1309. m = get_full_model(get_entry_id(model_name), get_entry_id(metamodel_name))
  1310. if (element_eq(m, read_root())):
  1311. return "No conformance relation can be found between these models"!
  1312. return string_join("Success: ", conformance_scd(m))!
  1313. else:
  1314. return "Permission denied to model: " + metamodel_name!
  1315. else:
  1316. return "Model not found: " + metamodel_name!
  1317. else:
  1318. return "Permission denied to model: " + model_name!
  1319. else:
  1320. return "Model not found: " + model_name!
  1321. String function cmd_model_overwrite(model_name : String, metamodel_name : String):
  1322. // Overwrites an existing model without changing any metadata
  1323. String model_id
  1324. String type_id
  1325. Element new_model
  1326. model_id = get_entry_id(model_name)
  1327. if (model_id != ""):
  1328. if (allow_write(current_user_id, model_id)):
  1329. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1330. if (allow_read(current_user_id, type_id)):
  1331. Element mm
  1332. mm = get_full_model(get_entry_id(metamodel_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1333. if (element_eq(mm, read_root())):
  1334. return "Metamodel does not conform to formalisms/SimpleClassDiagrams: " + metamodel_name!
  1335. output("Waiting for model constructors...")
  1336. new_model = compile_model(input(), mm)
  1337. if (element_eq(new_model, read_root())):
  1338. return "Compilation error"!
  1339. model_overwrite(new_model, model_id, get_entry_id(metamodel_name))
  1340. return "Success"!
  1341. else:
  1342. return string_join("Permission denied to model: ", full_name(type_id))!
  1343. else:
  1344. return "Permission denied to model: " + model_name!
  1345. else:
  1346. return "Model not found: " + model_name!
  1347. String function cmd_model_modify(model_name : String, metamodel_name : String):
  1348. // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
  1349. String model_id
  1350. String type_id
  1351. model_id = get_entry_id(model_name)
  1352. if (model_id != ""):
  1353. if (allow_read(current_user_id, model_id)):
  1354. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  1355. if (allow_read(current_user_id, type_id)):
  1356. Element new_model
  1357. new_model = get_full_model(model_id, get_entry_id(metamodel_name))
  1358. if (element_eq(new_model, read_root())):
  1359. return "No conformance relation can be found between these models"!
  1360. modify(new_model, allow_write(current_user_id, model_id))
  1361. if (allow_write(current_user_id, model_id)):
  1362. // Overwrite the modified model
  1363. model_overwrite(new_model, model_id, get_entry_id(metamodel_name))
  1364. return "Success"!
  1365. else:
  1366. return string_join("Permission denied to model: ", full_name(type_id))!
  1367. else:
  1368. return "Permission denied to model: " + model_name!
  1369. else:
  1370. return "Model not found: " + model_name!
  1371. Void function model_delete(model_id : String):
  1372. if (read_type(core, model_id) == "Folder"):
  1373. // Folder, so delete all containing elements as well!
  1374. Element elems
  1375. elems = allAssociationDestinations(core, model_id, "contains")
  1376. while (set_len(elems) > 0):
  1377. model_delete(set_pop(elems))
  1378. // Delete self
  1379. model_delete_element(core, model_id)
  1380. else:
  1381. // Only delete this element
  1382. model_delete_element(core, model_id)
  1383. return!
  1384. String function cmd_model_delete(model_name : String):
  1385. String model_id
  1386. model_id = get_entry_id(model_name)
  1387. if (model_id != ""):
  1388. if (allow_write(current_user_id, model_id)):
  1389. model_delete(model_id)
  1390. return "Success"!
  1391. else:
  1392. return "Permission denied to model: " + model_name!
  1393. else:
  1394. return "Model not found: " + model_name!
  1395. String function cmd_model_list(location : String):
  1396. // List all models
  1397. if (get_entry_id(location) != ""):
  1398. if (allow_read(current_user_id, get_entry_id(location))):
  1399. Element models
  1400. String result
  1401. String m
  1402. result = "Success: "
  1403. models = allAssociationDestinations(core, get_entry_id(location), "contains")
  1404. while (set_len(models) > 0):
  1405. m = set_pop(models)
  1406. if (is_nominal_instance(core, m, "Folder")):
  1407. result = result + (get_filename(read_attribute(core, m, "name")) + "/\n")
  1408. else:
  1409. result = result + (get_filename(read_attribute(core, m, "name")) + "\n")
  1410. return result!
  1411. else:
  1412. return "Permission denied to folder: " + location!
  1413. else:
  1414. return "Location not found: " + location!
  1415. String function cmd_model_list_full(location : String):
  1416. // List all models with full info
  1417. if (get_entry_id(location) != ""):
  1418. if (allow_read(current_user_id, get_entry_id(location))):
  1419. Element models
  1420. String m
  1421. String permissions
  1422. String owner
  1423. String group
  1424. String name
  1425. String type
  1426. String result
  1427. result = "Success: "
  1428. models = allAssociationDestinations(core, get_entry_id(location), "contains")
  1429. while (set_len(models) > 0):
  1430. m = set_pop(models)
  1431. permissions = read_attribute(core, m, "permissions")
  1432. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  1433. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  1434. if (is_nominal_instance(core, m, "Folder")):
  1435. name = get_filename(read_attribute(core, m, "name")) + "/"
  1436. else:
  1437. name = get_filename(read_attribute(core, m, "name"))
  1438. result = result + permissions + " " + owner + " " + group + " " + name + "\n"
  1439. return result!
  1440. else:
  1441. return "Permission denied to folder: " + location!
  1442. else:
  1443. return "Location not found: " + location!
  1444. String function cmd_transformation_add_MANUAL(source_models : Element, target_models : Element, operation_name : String):
  1445. return transformation_add(source_models, target_models, operation_name, "manual")!
  1446. String function cmd_transformation_add_AL(source_models : Element, target_models : Element, operation_name : String):
  1447. return transformation_add(source_models, target_models, operation_name, "actionlanguage")!
  1448. String function transformation_add(source_models : Element, target_models : Element, operation_name : String, operation_type : String):
  1449. // Add a manual transformation model
  1450. String model_id
  1451. Element models
  1452. Element source
  1453. Element target
  1454. String name
  1455. Element all_formalisms
  1456. Element formalism_map
  1457. Element merged_formalism
  1458. String merged_formalism_id
  1459. String source_formalism_id
  1460. String tracability_link
  1461. Element fused
  1462. Element keys
  1463. String key
  1464. Element mm
  1465. source = dict_create()
  1466. target = dict_create()
  1467. all_formalisms = set_create()
  1468. formalism_map = set_create()
  1469. fused = set_create()
  1470. keys = dict_keys(source_models)
  1471. while (set_len(keys) > 0):
  1472. key = set_pop(keys)
  1473. name = source_models[key]
  1474. model_id = get_entry_id(name)
  1475. if (model_id != ""):
  1476. if (allow_read(current_user_id, model_id)):
  1477. if (bool_not(dict_in(source, key))):
  1478. dict_add(source, key, model_id)
  1479. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1480. if (element_eq(mm, read_root())):
  1481. return "Transformation source type not in formalisms/SimpleClassDiagrams hierarchy: " + key!
  1482. if (bool_not(set_in(fused, key))):
  1483. set_add_node(formalism_map, create_tuple(key, mm))
  1484. set_add(fused, key)
  1485. if (bool_not(set_in(all_formalisms, model_id))):
  1486. set_add(all_formalisms, model_id)
  1487. else:
  1488. return "Name already selected for source: " + key!
  1489. else:
  1490. return "Permission denied to model: " + name!
  1491. else:
  1492. return "Model not found: " + name!
  1493. keys = dict_keys(target_models)
  1494. while (set_len(keys) > 0):
  1495. key = set_pop(keys)
  1496. name = target_models[key]
  1497. model_id = get_entry_id(name)
  1498. if (model_id != ""):
  1499. if (allow_read(current_user_id, model_id)):
  1500. if (bool_not(dict_in(target, key))):
  1501. dict_add(target, key, model_id)
  1502. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1503. if (element_eq(mm, read_root())):
  1504. return "Transformation target type not in formalisms/SimpleClassDiagrams hierarchy: " + key!
  1505. if (bool_not(set_in(fused, key))):
  1506. set_add_node(formalism_map, create_tuple(key, mm))
  1507. set_add(fused, key)
  1508. if (bool_not(set_in(all_formalisms, model_id))):
  1509. set_add(all_formalisms, model_id)
  1510. else:
  1511. return "Name already selected for target: " + key!
  1512. else:
  1513. return "Permission denied to model: " + name!
  1514. else:
  1515. return "Model not found: " + name!
  1516. if (get_entry_id(operation_name) == ""):
  1517. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1518. // New location is available, so write
  1519. if (dict_len(source_models) + dict_len(target_models) > 0):
  1520. merged_formalism = model_fuse(formalism_map)
  1521. model_create(merged_formalism, "merged/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1522. do_spawn_modify("merged/" + operation_name, True)
  1523. merged_formalism = get_full_model(get_entry_id("merged/" + operation_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1524. if (operation_type == "manual"):
  1525. if (dict_len(source_models) + dict_len(target_models) == 0):
  1526. return "Manual activity needs at least one formalism in its input or output signature!"!
  1527. // Finished with all information, now create the model itself!
  1528. Element m
  1529. m = get_full_model(get_entry_id("formalisms/ManualOperation"), get_entry_id("formalisms/SimpleClassDiagrams"))
  1530. if (element_eq(m, read_root())):
  1531. log("Error when opening ManualOperation: no conformance relation found")
  1532. return "Error when opening ManualOperation: no conformance relation found"!
  1533. model_create(instantiate_model(m), operation_name, get_entry_id("formalisms/ManualOperation"), "ManualOperation")
  1534. model_id = get_entry_id(operation_name)
  1535. elif (operation_type == "actionlanguage"):
  1536. // Finished with all information, now create the model itself!
  1537. output("Waiting for code constructors...")
  1538. Element compiled
  1539. compiled = compile_code(input())
  1540. if (element_eq(compiled, read_root())):
  1541. return "Compilation error"!
  1542. add_code_model(get_full_model(get_entry_id("formalisms/ActionLanguage"), get_entry_id("formalisms/SimpleClassDiagrams")), "AL/" + operation_name, compiled)
  1543. model_create(import_node("AL/" + operation_name), operation_name, get_entry_id("formalisms/ActionLanguage"), "ActionLanguage")
  1544. model_id = get_entry_id(operation_name)
  1545. if (dict_len(source_models) + dict_len(target_models) > 0):
  1546. merged_formalism_id = get_entry_id("merged/" + operation_name)
  1547. // Add tracability links at this level
  1548. while (set_len(all_formalisms) > 0):
  1549. source_formalism_id = set_pop(all_formalisms)
  1550. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1551. instantiate_attribute(core, tracability_link, "type", "merged")
  1552. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1553. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1554. // Extend metadata with info on source and target
  1555. String link
  1556. String dst
  1557. keys = dict_keys(source)
  1558. while (set_len(keys) > 0):
  1559. key = set_pop(keys)
  1560. link = instantiate_link(core, "transformInput", "", model_id, source[key])
  1561. instantiate_attribute(core, link, "name", key)
  1562. keys = dict_keys(target)
  1563. while (set_len(keys) > 0):
  1564. key = set_pop(keys)
  1565. link = instantiate_link(core, "transformOutput", "", model_id, target[key])
  1566. instantiate_attribute(core, link, "name", key)
  1567. return "Success"!
  1568. else:
  1569. return "Model exists: " + operation_name!
  1570. String function cmd_transformation_add_MT(source_models : Element, target_models : Element, operation_name : String):
  1571. // Add a model transformation model
  1572. // Just a usual model instantiation, but need to add the source and target links based on user info
  1573. String ramified_metamodel_id
  1574. Element ramified_metamodel
  1575. String model_id
  1576. Element models
  1577. Element links
  1578. String link_id
  1579. Element supported
  1580. Element source
  1581. Element target
  1582. String name
  1583. String new_model_id
  1584. String merged_link_id
  1585. Element links_merged
  1586. String merged_formalism
  1587. Element keys
  1588. String key
  1589. Element mm
  1590. Element to_ramify
  1591. String source_formalism_id
  1592. String merged_formalism_id
  1593. String tracability_link
  1594. source = dict_create()
  1595. target = dict_create()
  1596. to_ramify = set_create()
  1597. if (dict_len(source_models) + dict_len(target_models) == 0):
  1598. return "Model transformation needs at least one formalism in its input or output signature!"!
  1599. keys = dict_keys(source_models)
  1600. while (set_len(keys) > 0):
  1601. key = set_pop(keys)
  1602. name = source_models[key]
  1603. model_id = get_entry_id(name)
  1604. if (model_id != ""):
  1605. if (allow_read(current_user_id, name)):
  1606. // Check whether or not it is formalisms/SimpleClassDiagrams
  1607. if (is_typed_by(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))):
  1608. if (bool_not(dict_in(source, key))):
  1609. dict_add(source, key, model_id)
  1610. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1611. if (element_eq(mm, read_root())):
  1612. return "ModelTransformation source type not in formalisms/SimpleClassDiagrams hierarchy: " + name!
  1613. set_add_node(to_ramify, create_tuple(key, mm))
  1614. else:
  1615. return "Name was already assigned a metamodel: " + key!
  1616. else:
  1617. return "Model not supported for RAMification: " + name!
  1618. else:
  1619. return "Permission denied: " + name!
  1620. else:
  1621. return "Model not found: " + name!
  1622. keys = dict_keys(target_models)
  1623. while (set_len(keys) > 0):
  1624. key = set_pop(keys)
  1625. name = target_models[key]
  1626. model_id = get_entry_id(name)
  1627. if (model_id != ""):
  1628. if (allow_read(current_user_id, name)):
  1629. if (is_typed_by(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))):
  1630. if (bool_not(dict_in(target, key))):
  1631. if (dict_in(source, key)):
  1632. if (value_eq(model_id, source[key])):
  1633. dict_add(target, key, model_id)
  1634. // Don't add to to_ramify, as it is already in there!
  1635. else:
  1636. return "Name in output cannot have different type than input: " + key!
  1637. else:
  1638. dict_add(target, key, model_id)
  1639. mm = get_full_model(model_id, get_entry_id("formalisms/SimpleClassDiagrams"))
  1640. if (element_eq(mm, read_root())):
  1641. return "ModelTransformation target type not in formalisms/SimpleClassDiagrams hierarchy: " + name!
  1642. set_add_node(to_ramify, create_tuple(key, mm))
  1643. else:
  1644. return "Name was already assigned a metamodel: " + key!
  1645. else:
  1646. return "Model not supported for RAMification: " + name!
  1647. else:
  1648. return "Permission denied: " + name!
  1649. else:
  1650. return "Model not found: " + name!
  1651. merged_formalism = model_fuse(to_ramify)
  1652. model_create(merged_formalism, "merged/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1653. do_spawn_modify("merged/" + operation_name, True)
  1654. merged_formalism = get_full_model(get_entry_id("merged/" + operation_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1655. model_overwrite(merged_formalism, get_entry_id("merged/" + operation_name), get_entry_id("formalisms/SimpleClassDiagrams"))
  1656. ramified_metamodel = ramify(merged_formalism)
  1657. model_create(ramified_metamodel, "RAMified/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1658. ramified_metamodel_id = get_entry_id("RAMified/" + operation_name)
  1659. // Now use the RAMified model to create the instance
  1660. if (get_entry_id(operation_name) == ""):
  1661. String new_model
  1662. // Finished with all information, now create the model itself!
  1663. output("Waiting for model constructors...")
  1664. new_model = compile_model(input(), get_full_model(ramified_metamodel_id, get_entry_id("formalisms/SimpleClassDiagrams")))
  1665. if (element_eq(new_model, read_root())):
  1666. return "Compilation error"!
  1667. model_create(new_model, operation_name, ramified_metamodel_id, "ModelTransformation")
  1668. model_id = get_entry_id(operation_name)
  1669. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1670. // New location is available, so write
  1671. model_create(merged_formalism, "merged/" + operation_name, get_entry_id("formalisms/SimpleClassDiagrams"), "Model")
  1672. merged_formalism_id = get_entry_id("merged/" + operation_name)
  1673. // Add tracability links at this level
  1674. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1675. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1676. // Add tracability links at this level
  1677. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, ramified_metamodel_id)
  1678. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1679. // Extend metadata with info on source and target
  1680. String link
  1681. String dst
  1682. keys = dict_keys(source)
  1683. while (set_len(keys) > 0):
  1684. key = set_pop(keys)
  1685. dst = source[key]
  1686. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1687. instantiate_attribute(core, link, "name", key)
  1688. keys = dict_keys(target)
  1689. while (set_len(keys) > 0):
  1690. key = set_pop(keys)
  1691. dst = target[key]
  1692. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1693. instantiate_attribute(core, link, "name", key)
  1694. return "Success"!
  1695. else:
  1696. return "Model exists: " + operation_name!
  1697. String function cmd_permission_modify(model_name : String, permissions : String):
  1698. Integer permission
  1699. String model_id
  1700. model_id = get_entry_id(model_name)
  1701. if (model_id != ""):
  1702. if (get_relation_to_model(current_user_id, model_id) == 0):
  1703. Boolean fail
  1704. Integer i
  1705. i = 0
  1706. if (string_len(permissions) != 3):
  1707. fail = True
  1708. while (i < 3):
  1709. permission = cast_integer(string_get(permissions, i))
  1710. if (bool_or(permission < 0, permission > 2)):
  1711. fail = True
  1712. break!
  1713. i = i + 1
  1714. if (bool_not(fail)):
  1715. unset_attribute(core, model_id, "permissions")
  1716. instantiate_attribute(core, model_id, "permissions", permissions)
  1717. return "Success"!
  1718. else:
  1719. return "Permission has incorrect format: must be a string of three characters, with each character being a digit between 0 and 2"!
  1720. else:
  1721. return "Permission denied to model: " + model_name!
  1722. else:
  1723. return "Model not found: " + model_name!
  1724. String function cmd_permission_owner(model_name : String, new_user_name : String):
  1725. String model_id
  1726. String new_user_id
  1727. model_id = get_entry_id(model_name)
  1728. if (model_id != ""):
  1729. if (bool_or(get_relation_to_model(current_user_id, model_id) == 0, is_admin(current_user_id))):
  1730. new_user_id = get_user_id(new_user_name)
  1731. if (new_user_id != ""):
  1732. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  1733. instantiate_link(core, "owner", "", model_id, new_user_id)
  1734. return "Success"!
  1735. else:
  1736. return "No such user: " + new_user_name!
  1737. else:
  1738. return "Permission denied to model: " + model_name!
  1739. else:
  1740. return "Model not found: " + model_name!
  1741. String function cmd_permission_group(model_name : String, new_group_name : String):
  1742. String model_id
  1743. String group_id
  1744. model_id = get_entry_id(model_name)
  1745. if (model_id != ""):
  1746. if (bool_or(get_relation_to_model(current_user_id, model_id) == 0, is_admin(current_user_id))):
  1747. group_id = get_group_id(new_group_name)
  1748. if (group_id != ""):
  1749. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  1750. instantiate_link(core, "group", "", model_id, group_id)
  1751. return "Success"!
  1752. else:
  1753. return "No such group: " + new_group_name!
  1754. else:
  1755. return "Permission denied to model: " + model_name!
  1756. else:
  1757. return "Model not found: " + model_name!
  1758. String function cmd_group_create(group_name : String):
  1759. // Create a new group and become its owner
  1760. String group_id
  1761. String name
  1762. group_id = get_group_id(group_name)
  1763. if (group_id == ""):
  1764. group_id = instantiate_node(core, "Group", "")
  1765. instantiate_attribute(core, group_id, "name", group_name)
  1766. instantiate_link(core, "belongsTo", "", current_user_id, group_id)
  1767. instantiate_link(core, "owner", "", group_id, current_user_id)
  1768. return "Success"!
  1769. else:
  1770. return "Group exists: " + group_name!
  1771. String function cmd_group_delete(group_name : String):
  1772. // Delete an existing group
  1773. String group_id
  1774. group_id = get_group_id(group_name)
  1775. if (group_id != ""):
  1776. if (allow_group_modify(current_user_id, group_id)):
  1777. model_delete_element(core, group_id)
  1778. return "Success"!
  1779. else:
  1780. return "Permission denied to group: " + group_name!
  1781. else:
  1782. return "Group not found: " + group_name!
  1783. String function cmd_group_owner_add(group_name : String, other_user_name : String):
  1784. // Add an owner to your group
  1785. String group_id
  1786. String other_user_id
  1787. group_id = get_group_id(group_name)
  1788. if (group_id != ""):
  1789. if (allow_group_modify(current_user_id, group_id)):
  1790. other_user_id = get_user_id(other_user_name)
  1791. if (other_user_id != ""):
  1792. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1793. instantiate_link(core, "owner", "", group_id, other_user_id)
  1794. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1795. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1796. return "Success"!
  1797. else:
  1798. return "User is already the owner!"!
  1799. else:
  1800. return "User not found: " + other_user_name!
  1801. else:
  1802. return "Permission denied to group: " + group_name!
  1803. else:
  1804. return "Group not found: " + group_name!
  1805. String function cmd_group_owner_delete(group_name : String, other_user_name : String):
  1806. // Remove an owner from your group
  1807. String group_id
  1808. String other_user_id
  1809. group_id = get_group_id(group_name)
  1810. if (group_id != ""):
  1811. if (allow_group_modify(current_user_id, group_id)):
  1812. other_user_id = get_user_id(other_user_name)
  1813. if (other_user_id != ""):
  1814. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1815. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1816. Element overlap
  1817. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "owner"), allOutgoingAssociationInstances(core, other_user_id, "owner"))
  1818. model_delete_element(core, set_pop(overlap))
  1819. return "Success"!
  1820. else:
  1821. return "User is not an owner of the group!"!
  1822. else:
  1823. return "User is not a member of the group!"!
  1824. else:
  1825. return "User not found: " + other_user_name!
  1826. else:
  1827. return "Permission denied to group: " + group_name!
  1828. else:
  1829. return "Group not found: " + group_name!
  1830. String function cmd_group_join(group_name : String, other_user_name : String):
  1831. // Add someone to your group
  1832. String group_id
  1833. String other_user_id
  1834. group_id = get_group_id(group_name)
  1835. if (group_id != ""):
  1836. if (allow_group_modify(current_user_id, group_id)):
  1837. other_user_id = get_user_id(other_user_name)
  1838. if (other_user_id != ""):
  1839. if (set_in(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), group_id)):
  1840. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1841. return "Success"!
  1842. else:
  1843. return "User is already a member of the group!"!
  1844. else:
  1845. return "User not found: " + other_user_name!
  1846. else:
  1847. return "Permission denied to group: " + group_name!
  1848. else:
  1849. return "Group not found: " + group_name!
  1850. String function cmd_group_kick(group_name : String, other_user_name : String):
  1851. // Remove someone from your group
  1852. String group_id
  1853. String other_user_id
  1854. group_id = get_group_id(group_name)
  1855. if (group_id != ""):
  1856. if (allow_group_modify(current_user_id, group_id)):
  1857. other_user_id = get_user_id(other_user_name)
  1858. if (other_user_id != ""):
  1859. Element overlap
  1860. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1861. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "belongsTo"), allOutgoingAssociationInstances(core, other_user_id, "belongsTo"))
  1862. model_delete_element(core,set_pop(overlap))
  1863. // Check if user was an owner as well
  1864. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1865. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1866. model_delete_element(core, set_pop(overlap))
  1867. return "Success"!
  1868. else:
  1869. return "User is not a member of the group!"!
  1870. else:
  1871. return "User not found: " + other_user_name!
  1872. else:
  1873. return "Permission denied to group: " + group_name!
  1874. else:
  1875. return "Group not found: " + group_name!
  1876. String function cmd_group_list():
  1877. // List all groups you are a member of (and whether you are admin or not!)
  1878. Element groups
  1879. String group_id
  1880. String admin
  1881. String result
  1882. result = ""
  1883. groups = allAssociationDestinations(core, current_user_id, "belongsTo")
  1884. while (set_len(groups) > 0):
  1885. group_id = set_pop(groups)
  1886. if (set_in(allAssociationDestinations(core, group_id, "owner"), current_user_id)):
  1887. admin = " A "
  1888. else:
  1889. admin = " "
  1890. result = result + (string_join(admin, read_attribute(core, group_id, "name")) + "\n")
  1891. return result!
  1892. String function cmd_admin_promote(other_user_name : String):
  1893. // Promote a user to admin status
  1894. if (is_admin(current_user_id)):
  1895. String other_user_id
  1896. other_user_id = get_user_id(other_user_name)
  1897. if (other_user_id != ""):
  1898. unset_attribute(core, other_user_id, "admin")
  1899. instantiate_attribute(core, other_user_id, "admin", True)
  1900. return "Success"!
  1901. else:
  1902. return "User not found: " + other_user_name!
  1903. else:
  1904. return "Permission denied to administrate: " + other_user_name!
  1905. String function cmd_admin_demote(other_user_name : String):
  1906. // Demote a user to normal status
  1907. if (is_admin(current_user_id)):
  1908. String other_user_id
  1909. other_user_id = get_user_id(other_user_name)
  1910. if (other_user_id != ""):
  1911. unset_attribute(core, other_user_id, "admin")
  1912. instantiate_attribute(core, other_user_id, "admin", False)
  1913. return "Success"!
  1914. else:
  1915. return "User not found: " + other_user_name!
  1916. else:
  1917. return "Permission denied to administrate: " + other_user_name!
  1918. String function cmd_service_register(service_name : String):
  1919. // Active a service for this specific user
  1920. if (get_service_id(service_name) == ""):
  1921. String service
  1922. service = instantiate_node(core, "Service", "")
  1923. instantiate_attribute(core, service, "name", service_name)
  1924. instantiate_attribute(core, service, "port", get_taskname())
  1925. output("Success: " + get_taskname())
  1926. // Wait until we can stop the service
  1927. while (cast_value(input()) != "\"service_stop\""):
  1928. output("Service is running on this task: stop it by sending 'service_stop'")
  1929. model_delete_element(core, service)
  1930. // Service terminated
  1931. return "Success"!
  1932. else:
  1933. return "Service already exists: " + service_name!
  1934. String function cmd_user_password(user_name : String, new_password : String):
  1935. if (bool_or(current_user_id == get_user_id(user_name), is_admin(current_user_id))):
  1936. if (get_user_id(user_name) != ""):
  1937. instantiate_attribute(core, get_user_id(user_name), "password", hash(new_password))
  1938. return "Success"!
  1939. else:
  1940. return "No such user: " + user_name!
  1941. else:
  1942. return "Permission denied to user: " + user_name!
  1943. String function cmd_transformation_signature(transformation_name : String):
  1944. String model_id
  1945. model_id = get_entry_id(transformation_name)
  1946. if (model_id != ""):
  1947. if (is_nominal_instance(core, model_id, "Transformation")):
  1948. if (allow_read(current_user_id, transformation_name)):
  1949. String result
  1950. String elem
  1951. Element inputs
  1952. Element outputs
  1953. result = "Success: "
  1954. inputs = allOutgoingAssociationInstances(core, model_id, "transformInput")
  1955. while (set_len(inputs) > 0):
  1956. elem = set_pop(inputs)
  1957. result = string_join(string_join(string_join(string_join(result + "I ", read_attribute(core, elem, "name")), " "), full_name(readAssociationDestination(core, elem))), "\n")
  1958. outputs = allOutgoingAssociationInstances(core, model_id, "transformOutput")
  1959. while (set_len(outputs) > 0):
  1960. elem = set_pop(outputs)
  1961. result = string_join(string_join(string_join(string_join(result + "O ", read_attribute(core, elem, "name")), " "), full_name(readAssociationDestination(core, elem))), "\n")
  1962. return result!
  1963. else:
  1964. return "Permission denied to operation: " + transformation_name!
  1965. else:
  1966. return "Model is not an operation: " + transformation_name!
  1967. else:
  1968. return "No such operation: " + transformation_name!
  1969. String function cmd_model_types(model_name : String):
  1970. if (get_entry_id(model_name) != ""):
  1971. String model_id
  1972. model_id = get_entry_id(model_name)
  1973. Element types
  1974. String type
  1975. String result
  1976. result = "Success: "
  1977. types = allAssociationDestinations(core, model_id, "instanceOf")
  1978. while (set_len(types) > 0):
  1979. type = set_pop(types)
  1980. result = string_join(result, full_name(type) + "\n")
  1981. return result!
  1982. else:
  1983. return "No such model: " + model_name!
  1984. String function cmd_folder_create(folder_name : String):
  1985. if (get_entry_id(folder_name) == ""):
  1986. if (element_neq(create_folders(current_user_id, folder_name), read_root())):
  1987. return "Success"!
  1988. else:
  1989. return "Permission denied to folder: " + folder_name!
  1990. else:
  1991. return "Folder alreay exists: " + folder_name!
  1992. String function cmd_conformance_add(model_name : String, metamodel_name : String):
  1993. // Create a new instanceOf relation now
  1994. String instance_of
  1995. instance_of = instantiate_link(core, "instanceOf", "", get_entry_id(model_name), get_entry_id(metamodel_name))
  1996. return "Success"!
  1997. Void function user_function_skip_init(user_id : String):
  1998. String cmd
  1999. String result
  2000. current_user_id = user_id
  2001. caches = dict_create()
  2002. dict_add_fast(caches, "models", dict_create())
  2003. dict_add_fast(caches, "users", dict_create())
  2004. dict_add_fast(caches, "full_name", dict_create())
  2005. // Find root element
  2006. Element elems
  2007. String elem
  2008. elems = allInstances(core, "Folder")
  2009. while (set_len(elems) > 0):
  2010. elem = set_pop(elems)
  2011. if (value_eq(read_attribute(core, elem, "name"), "")):
  2012. if (set_len(allIncomingAssociationInstances(core, elem, "contains")) == 0):
  2013. dict_add_fast(caches, "root", elem)
  2014. break!
  2015. output("Welcome to the Model Management Interface v2.0!")
  2016. output("Use the 'help' command for a list of possible commands")
  2017. while (True):
  2018. cmd = input()
  2019. if (cmd == "help"):
  2020. output(cmd_help())
  2021. elif (cmd == "model_add"):
  2022. output(cmd_model_add(single_input("Model type?"), single_input("Model name?"), single_input("Model textual representation?")))
  2023. elif (cmd == "process_execute"):
  2024. output(cmd_process_execute(single_input("Process to execute?"), dict_input("Model bindings to use?")))
  2025. elif (cmd == "process_signature"):
  2026. output(cmd_process_signature(single_input("Process to execute?")))
  2027. elif (cmd == "transformation_between"):
  2028. output(cmd_transformation_between(dict_input("Source signature?"), dict_input("Target signature?")))
  2029. elif (cmd == "model_render"):
  2030. output(cmd_model_render(single_input("Model name?"), single_input("Mapper name?"), single_input("Rendered name?")))
  2031. elif (cmd == "model_rendered"):
  2032. output(cmd_model_rendered(single_input("Model name?"), single_input("Mapper name?")))
  2033. elif (cmd == "transformation_execute"):
  2034. output(cmd_transformation_execute(single_input("Transformation name?"), dict_input("Source models?"), dict_input("Target models?"), single_input("Tracability model?")))
  2035. elif (cmd == "verify"):
  2036. result = cmd_verify(single_input("Model name?"), single_input("Metamodel name?"))
  2037. if (result != ""):
  2038. output(result)
  2039. elif (cmd == "model_overwrite"):
  2040. output(cmd_model_overwrite(single_input("Model name?"), single_input("Metamodel name?")))
  2041. elif (cmd == "model_modify"):
  2042. output(cmd_model_modify(single_input("Model name?"), single_input("Metamodel name?")))
  2043. elif (cmd == "model_delete"):
  2044. output(cmd_model_delete(single_input("Model name?")))
  2045. elif (cmd == "model_list"):
  2046. output(cmd_model_list(single_input("Location?")))
  2047. elif (cmd == "model_list_full"):
  2048. output(cmd_model_list_full(single_input("Location?")))
  2049. elif (cmd == "transformation_add_MANUAL"):
  2050. output(cmd_transformation_add_MANUAL(dict_input("Source models?"), dict_input("Target models?"), single_input("Operation name?")))
  2051. elif (cmd == "transformation_add_AL"):
  2052. output(cmd_transformation_add_AL(dict_input("Source models?"), dict_input("Target models?"), single_input("Operation name?")))
  2053. elif (cmd == "transformation_add_MT"):
  2054. output(cmd_transformation_add_MT(dict_input("Source models?"), dict_input("Target models?"), single_input("Operation name?")))
  2055. elif (cmd == "permission_modify"):
  2056. output(cmd_permission_modify(single_input("Model name?"), single_input("Permissions?")))
  2057. elif (cmd == "permission_owner"):
  2058. output(cmd_permission_owner(single_input("Model name?"), single_input("New owning user?")))
  2059. elif (cmd == "permission_group"):
  2060. output(cmd_permission_group(single_input("Model name?"), single_input("New owning group?")))
  2061. elif (cmd == "group_create"):
  2062. output(cmd_group_create(single_input("New group name?")))
  2063. elif (cmd == "group_delete"):
  2064. output(cmd_group_delete(single_input("Group name?")))
  2065. elif (cmd == "group_owner_add"):
  2066. output(cmd_group_owner_add(single_input("Group name?"), single_input("User name?")))
  2067. elif (cmd == "group_owner_delete"):
  2068. output(cmd_group_owner_delete(single_input("Group name?"), single_input("User name?")))
  2069. elif (cmd == "group_join"):
  2070. output(cmd_group_join(single_input("Group name?"), single_input("User name?")))
  2071. elif (cmd == "group_kick"):
  2072. output(cmd_group_kick(single_input("Group name?"), single_input("User name?")))
  2073. elif (cmd == "group_list"):
  2074. output(cmd_group_list())
  2075. elif (cmd == "admin_promote"):
  2076. output(cmd_admin_promote(single_input("User name?")))
  2077. elif (cmd == "admin_demote"):
  2078. output(cmd_admin_demote(single_input("User name?")))
  2079. elif (cmd == "service_register"):
  2080. output(cmd_service_register(single_input("Service name?")))
  2081. elif (cmd == "user_password"):
  2082. output(cmd_user_password(single_input("User name?"), single_input("New password?")))
  2083. elif (cmd == "transformation_read_signature"):
  2084. output(cmd_transformation_signature(single_input("Transformation name?")))
  2085. elif (cmd == "verbose"):
  2086. set_verbose(True)
  2087. elif (cmd == "quiet"):
  2088. set_verbose(False)
  2089. elif (cmd == "self-destruct"):
  2090. // Delete user from Core Formalism
  2091. model_delete_element(core, user_id)
  2092. return !
  2093. elif (cmd == "user_logout"):
  2094. // TODO
  2095. cmd = "FAIL"
  2096. elif (cmd == "exit"):
  2097. // Exit by actually removing the user and decoupling it from all of its models
  2098. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  2099. // as the current user will have been deleted
  2100. return !
  2101. elif (cmd == "folder_create"):
  2102. output(cmd_folder_create(single_input("Folder name?")))
  2103. elif (cmd == "add_conformance"):
  2104. output(cmd_conformance_add(single_input("Model name?"), single_input("Metamodel name?")))
  2105. elif (cmd == "remove_conformance"):
  2106. // TODO
  2107. cmd = "FAIL"
  2108. elif (cmd == "user_name"):
  2109. // TODO
  2110. cmd = "FAIL"
  2111. elif (cmd == "service_poll"):
  2112. // TODO
  2113. cmd = "FAIL"
  2114. elif (cmd == "model_types"):
  2115. output(cmd_model_types(single_input("Model name?")))
  2116. else:
  2117. output("Unknown command: " + cmd)
  2118. // We never get here!
  2119. return !