core_algorithm.alc 88 KB

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