core_algorithm.alc 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902
  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. String core_model_location = "models/core"
  16. Element core = ?
  17. String current_user_id
  18. Element caches
  19. Void function initialize_core():
  20. // TODO make this more flexible by putting it in the bootstrap in a similar way as other models
  21. add_code_model(import_node("models/ActionLanguage"), "models/Conformance_MV", wrap_conformance)
  22. return !
  23. Boolean function is_typed_by(model_id : String, metamodel_id : String):
  24. return (set_len(get_instanceOf_links(model_id, metamodel_id)) > 0)!
  25. Element function get_instanceOf_links(model_id : String, metamodel_id : String):
  26. Element result
  27. Element options
  28. String elem
  29. result = set_create()
  30. options = allOutgoingAssociationInstances(core, model_id, "instanceOf")
  31. while (set_len(options) > 0):
  32. elem = set_pop(options)
  33. if (value_eq(readAssociationDestination(core, elem), metamodel_id)):
  34. set_add(result, elem)
  35. return result!
  36. String function get_instanceOf_link(model_id : String, metamodel_id : String):
  37. Element all_links
  38. String choice
  39. all_links = get_instanceOf_links(model_id, metamodel_id)
  40. if (set_len(all_links) > 1):
  41. log("WARNING: multiple instanceOf relations were detected for this model; picking one at random!")
  42. elif (set_len(all_links) == 0):
  43. log("No types found!")
  44. return read_root()!
  45. choice = set_pop(all_links)
  46. return choice!
  47. Element function get_full_model(model_id : String, metamodel_id : String):
  48. // TODO we are restricted to using SimpleClassDiagrams as M3 level, through this code!
  49. Element m
  50. Element all_links
  51. String choice
  52. choice = get_instanceOf_link(model_id, metamodel_id)
  53. m = dict_create()
  54. dict_add(m, "model", import_node(read_attribute(core, model_id, "location")))
  55. // TODO for now this is restricted to the fixed semantics
  56. // dict_add(m, "semantics", set_pop(allAssociationDestinations(core, choice, "semantics")))
  57. dict_add(m, "semantics", get_model_id("conformance_mv"))
  58. if (metamodel_id == model_id):
  59. // Found the meta-circular level, so we can stop!
  60. dict_add(m, "metamodel", m)
  61. else:
  62. Element mm
  63. mm = get_full_model(metamodel_id, get_model_id("SimpleClassDiagrams"))
  64. if (element_eq(mm, read_root())):
  65. return read_root()!
  66. else:
  67. dict_add(m, "metamodel", mm)
  68. if (element_neq(choice, read_root())):
  69. if (set_len(allAssociationDestinations(core, choice, "typing")) == 1):
  70. // Add the preferred original type mapping
  71. dict_add(m, "type_mapping", import_node(read_attribute(core, set_pop(allAssociationDestinations(core, choice, "typing")), "location")))
  72. else:
  73. // Start from scratch
  74. dict_add(m, "type_mapping", new_type_mapping())
  75. else:
  76. // Start from scratch
  77. dict_add(m, "type_mapping", new_type_mapping())
  78. if (find_type_mapping(m)):
  79. // TODO store the found type model somewhere
  80. return m!
  81. else:
  82. log("No type mapping could be deduced!")
  83. log("Error for " + cast_v2s(read_attribute(core, model_id, "name")))
  84. log(" and type " + cast_v2s(read_attribute(core, metamodel_id, "name")))
  85. return read_root()!
  86. Integer function get_relation_to_model(user_id : String, model_id : String):
  87. if (set_in(allAssociationDestinations(core, model_id, "owner"), user_id)):
  88. // We are the owner
  89. return 0!
  90. else:
  91. String group_id
  92. group_id = set_pop(allAssociationDestinations(core, model_id, "group"))
  93. if (set_in(allAssociationDestinations(core, user_id, "belongsTo"), group_id)):
  94. // We are in the owning group
  95. return 1!
  96. else:
  97. // We are not related whatsoever
  98. return 2!
  99. Boolean function is_admin(user_id : String):
  100. if (read_attribute(core, user_id, "admin")):
  101. return True!
  102. else:
  103. return False!
  104. Boolean function allow_read(user_id : String, model_id : String):
  105. if (is_admin(user_id)):
  106. // Is admin, so always allow
  107. return True!
  108. else:
  109. // Check permissions
  110. String permission
  111. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  112. if (bool_or(permission == "1", permission == "2")):
  113. return True!
  114. else:
  115. return False!
  116. Boolean function allow_write(user_id : String, model_id : String):
  117. if (is_admin(user_id)):
  118. // Is admin, so always allow
  119. return True!
  120. else:
  121. // Check permissions
  122. String permission
  123. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  124. if (permission == "2"):
  125. return True!
  126. else:
  127. return False!
  128. Boolean function allow_change_metadata(user_id : String, model_id : String):
  129. if (is_admin(user_id)):
  130. // Is admin, so always allow
  131. return True!
  132. else:
  133. if (get_relation_to_model(user_id, model_id) == 0):
  134. // Only owner can chmod
  135. return True!
  136. else:
  137. return False!
  138. Boolean function allow_group_modify(user_id : String, group_id : String):
  139. if (is_admin(user_id)):
  140. // Is admin, so always allow
  141. return True!
  142. else:
  143. if (set_in(allAssociationDestinations(core, group_id, "owner"), user_id)):
  144. // We are an owner
  145. return True!
  146. else:
  147. return False!
  148. Boolean function check_login(user_id : String):
  149. String password
  150. String stored_password
  151. stored_password = read_attribute(core, user_id, "password")
  152. output("Password for existing user?")
  153. password = hash(input())
  154. return password == stored_password!
  155. Void function new_task():
  156. String username
  157. String user_id
  158. String password
  159. // Load in a hard-reference to the previously created model
  160. core = import_node(core_model_location)
  161. while (True):
  162. output("Log on as which user?")
  163. username = input()
  164. user_id = get_user_id(username)
  165. if (user_id == ""):
  166. // New user
  167. // Add user to Core Formalism
  168. user_id = instantiate_node(core, "User", "")
  169. instantiate_attribute(core, user_id, "name", username)
  170. instantiate_attribute(core, user_id, "admin", False)
  171. output("This is a new user: please give password!")
  172. password = hash(input())
  173. output("Please repeat the password")
  174. if (password == hash(input())):
  175. output("Passwords match!")
  176. instantiate_attribute(core, user_id, "password", password)
  177. break!
  178. else:
  179. output("Not the same password!")
  180. else:
  181. if (check_login(user_id)):
  182. break!
  183. else:
  184. output("Wrong password!")
  185. user_function_skip_init(user_id)
  186. // User destroyed already, so just stop execution
  187. return!
  188. String function get_model_id(name : String):
  189. Element models
  190. String model
  191. if (dict_in(caches["models"], name)):
  192. if (value_eq(read_attribute(core, caches["models"][name], "name"), name)):
  193. return caches["models"][name]!
  194. models = allInstances(core, "Model")
  195. while (set_len(models) > 0):
  196. model = set_pop(models)
  197. if (value_eq(name, read_attribute(core, model, "name"))):
  198. dict_overwrite(caches["models"], name, model)
  199. return model!
  200. return ""!
  201. String function get_service_id(name : String):
  202. Element services
  203. String service
  204. services = allInstances(core, "Service")
  205. while (set_len(services) > 0):
  206. service = set_pop(services)
  207. if (value_eq(read_attribute(core, service, "name"), name)):
  208. return service!
  209. return ""!
  210. String function get_user_id(name : String):
  211. Element users
  212. String user
  213. users = allInstances(core, "User")
  214. while (set_len(users) > 0):
  215. user = set_pop(users)
  216. if (value_eq(read_attribute(core, user, "name"), name)):
  217. return user!
  218. return ""!
  219. String function get_group_id(name : String):
  220. Element groups
  221. String group
  222. groups = allInstances(core, "Group")
  223. while (set_len(groups) > 0):
  224. group = set_pop(groups)
  225. if (value_eq(read_attribute(core, group, "name"), name)):
  226. return group!
  227. return ""!
  228. String function export_typing(model : Element, name : String):
  229. String result
  230. result = instantiate_node(core, "TypeMapping", "")
  231. // Create type mapping model
  232. String location
  233. location = "type_mappings/" + cast_id2s(model["type_mapping"])
  234. export_node(location, model["type_mapping"])
  235. String instance_of
  236. instantiate_attribute(core, result, "name", "TM_" + name)
  237. instantiate_attribute(core, result, "location", location)
  238. instantiate_attribute(core, result, "permissions", "200")
  239. instantiate_link(core, "owner", "", result, current_user_id)
  240. instantiate_link(core, "group", "", result, get_group_id("nobody"))
  241. instance_of = instantiate_link(core, "instanceOf", "", result, get_model_id("TypeMapping"))
  242. instantiate_link(core, "semantics", "", instance_of, get_model_id("conformance_mv"))
  243. return result!
  244. Void function model_create(model : Element, name : String, type_id : String, kind : String):
  245. String location
  246. String model_id
  247. String instance_of
  248. // Create model itself
  249. location = "models/" + cast_id2s(model)
  250. export_node(location, model["model"])
  251. model_id = instantiate_node(core, kind, "")
  252. instantiate_attribute(core, model_id, "name", name)
  253. instantiate_attribute(core, model_id, "location", location)
  254. instantiate_attribute(core, model_id, "permissions", "200")
  255. instantiate_link(core, "owner", "", model_id, current_user_id)
  256. instantiate_link(core, "group", "", model_id, get_group_id("nobody"))
  257. instance_of = instantiate_link(core, "instanceOf", "", model_id, type_id)
  258. instantiate_link(core, "semantics", "", instance_of, get_model_id("conformance_mv"))
  259. // Create type mapping model
  260. instantiate_link(core, "typing", "", instance_of, export_typing(model, name))
  261. return!
  262. Void function model_overwrite(model : Element, model_id : String, metamodel_id : String):
  263. // TODO this should be more elegant than just hiding the old elements
  264. String location
  265. String instanceOf_link
  266. location = "models/" + cast_id2s(model)
  267. export_node(location, model["model"])
  268. // Change location in meta-data
  269. unset_attribute(core, model_id, "location")
  270. instantiate_attribute(core, model_id, "location", location)
  271. // Update the instanceOf relation of the context in which we are working
  272. String choice
  273. choice = get_instanceOf_link(model_id, metamodel_id)
  274. if (element_neq(choice, read_root())):
  275. // There was a link, so we remove it
  276. model_delete_element(core, choice)
  277. // Create a new instanceOf relation now
  278. String instance_of
  279. instance_of = instantiate_link(core, "instanceOf", "", model_id, metamodel_id)
  280. instantiate_link(core, "semantics", "", instance_of, get_model_id("conformance_mv"))
  281. instantiate_link(core, "typing", "", instance_of, export_typing(model, read_attribute(core, model_id, "name")))
  282. return!
  283. Boolean function check_conformance(model_id : String):
  284. // TODO check if it actually conforms, considering that instanceOf link
  285. // --> in-depth check
  286. return True!
  287. Boolean function pm_finished(worklist : Element, pm : String):
  288. Element finished
  289. Integer cnt
  290. Integer i
  291. // Check if any of the "finish" elements are in the worklist
  292. // If so, we can already finish, and therefore will stop immediately
  293. finished = allInstances(pm, "Finish")
  294. worklist = set_copy(worklist)
  295. while (set_len(worklist) > 0):
  296. // Check each finished element individually
  297. if (set_in(finished, list_read(set_pop(worklist), 0))):
  298. return True!
  299. return False!
  300. Element function execute_operation(operation_id : String, input_models : Element, tracability_model : Element):
  301. // Operations are always in-place and uses only a single metamodel
  302. // Therefore, we must:
  303. // 1) Find merged metamodel
  304. // 2) Merge the different source models and retype
  305. // 3) Perform the operation on the merged model
  306. // 4) Split the resulting model based on the target formalisms; if operation successful
  307. Element input_model
  308. String trace_link_id
  309. Element merged_model
  310. String merged_metamodel_id
  311. String ramified_metamodel_id
  312. Boolean result
  313. String exact_type
  314. Element trace_links
  315. String model_ID
  316. String key
  317. Element keys
  318. Element input_keys
  319. Element output_keys
  320. Element model_tuples
  321. String metamodel_name
  322. Element metamodel
  323. String metamodel_ID
  324. Boolean tracability
  325. // 0) Find the signature of the operation
  326. Element input_metamodels
  327. Element output_metamodels
  328. Element iter
  329. String edge
  330. input_metamodels = dict_create()
  331. iter = allOutgoingAssociationInstances(core, operation_id, "transformInput")
  332. while (set_len(iter) > 0):
  333. edge = set_pop(iter)
  334. dict_add(input_metamodels, read_attribute(core, edge, "name"), read_attribute(core, readAssociationDestination(core, edge), "name"))
  335. output_metamodels = dict_create()
  336. iter = allOutgoingAssociationInstances(core, operation_id, "transformOutput")
  337. while (set_len(iter) > 0):
  338. edge = set_pop(iter)
  339. dict_add(output_metamodels, read_attribute(core, edge, "name"), read_attribute(core, readAssociationDestination(core, edge), "name"))
  340. // 1) Find merged metamodel
  341. exact_type = read_type(core, operation_id)
  342. trace_links = allOutgoingAssociationInstances(core, operation_id, "tracability")
  343. merged_metamodel_id = ""
  344. while (set_len(trace_links) > 0):
  345. trace_link_id = set_pop(trace_links)
  346. if (value_eq(read_attribute(core, trace_link_id, "type"), "operatesOn")):
  347. merged_metamodel_id = readAssociationDestination(core, trace_link_id)
  348. // 2) Merge source models
  349. if (merged_metamodel_id != ""):
  350. model_tuples = set_create()
  351. keys = dict_keys(input_models)
  352. while (set_len(keys) > 0):
  353. key = set_pop(keys)
  354. Element mm
  355. mm = get_full_model(get_model_id(input_models[key]), get_model_id(input_metamodels[key]))
  356. if (element_eq(mm, read_root())):
  357. log("Signature mismatch in operation for tag " + key)
  358. output("Signature mismatch in operation for tag " + key)
  359. return read_root()!
  360. set_add_node(model_tuples, create_tuple(key, mm))
  361. Element merged_metamodel
  362. merged_metamodel = get_full_model(merged_metamodel_id, get_model_id("SimpleClassDiagrams"))
  363. if (element_eq(merged_metamodel, read_root())):
  364. log("Merged metamodel in operation is not of type SimpleClassDiagrams")
  365. output("Merged metamodel in operation is not of type SimpleClassDiagrams")
  366. return read_root()!
  367. merged_model = model_join(model_tuples, merged_metamodel, tracability_model)
  368. else:
  369. if (bool_and(dict_len(input_models) == 1, dict_len(output_metamodels) == 0)):
  370. // Just skip the merge...
  371. Element m
  372. m = get_full_model(get_model_id(input_models[set_pop(dict_keys(input_models))]), get_model_id(input_metamodels[set_pop(dict_keys(input_metamodels))]))
  373. if (element_eq(m, read_root())):
  374. log("Signature mismatch in operation for tag " + cast_v2s(set_pop(dict_keys(input_models))))
  375. output("Signature mismatch in operation for tag " + cast_v2s(set_pop(dict_keys(input_models))))
  376. return read_root()!
  377. merged_model = model_copy(m)
  378. elif (bool_and(dict_len(input_models) == 0, dict_len(output_metamodels) == 0)):
  379. merged_model = read_root()
  380. else:
  381. log("Could not resolve intermediate merged metamodel")
  382. output("Could not resolve intermediate merged metamodel")
  383. return read_root()!
  384. // 3) Transform
  385. if (exact_type == "ModelTransformation"):
  386. trace_links = allOutgoingAssociationInstances(core, merged_metamodel_id, "tracability")
  387. ramified_metamodel_id = ""
  388. while (set_len(trace_links) > 0):
  389. trace_link_id = set_pop(trace_links)
  390. if (value_eq(read_attribute(core, trace_link_id, "type"), "RAMified")):
  391. ramified_metamodel_id = readAssociationDestination(core, trace_link_id)
  392. Element operation
  393. operation = get_full_model(operation_id, ramified_metamodel_id)
  394. if (element_eq(operation, read_root())):
  395. log("Operation could not be typed by specified RAMified metamodel!")
  396. output("Operation could not be typed by specified RAMified metamodel!")
  397. return read_root()!
  398. result = transform(merged_model, operation)
  399. elif (exact_type == "ManualOperation"):
  400. output("Please perform manual operation " + cast_v2s(read_attribute(core, operation_id, "name")))
  401. modify(merged_model, True)
  402. result = True
  403. elif (exact_type == "ActionLanguage"):
  404. Element func
  405. Element al
  406. al = get_full_model(operation_id, get_model_id("ActionLanguage"))
  407. if (element_eq(al, read_root())):
  408. log("Action Language operation not typed by ActionLanguage metamodel!")
  409. output("Action Language operation not typed by ActionLanguage metamodel!")
  410. return read_root()!
  411. func = get_func_AL_model(al)
  412. result = func(merged_model)
  413. else:
  414. log("Unknown type of operation: " + exact_type)
  415. output("Unknown type of operation: " + exact_type)
  416. return read_root()!
  417. // 4) Split in different models depending on type
  418. if (element_neq(tracability_model, read_root())):
  419. tracability = True
  420. else:
  421. tracability = False
  422. if (result):
  423. model_tuples = set_create()
  424. keys = dict_keys(output_metamodels)
  425. while (set_len(keys) > 0):
  426. key = set_pop(keys)
  427. Element mm
  428. mm = get_full_model(get_model_id(output_metamodels[key]), get_model_id("SimpleClassDiagrams"))
  429. if (element_eq(mm, read_root())):
  430. log("Output metamodel cannot be interpreted using SimpleClassDiagrams: " + key)
  431. output("Output metamodel cannot be interpreted using SimpleClassDiagrams: " + key)
  432. return read_root()!
  433. set_add_node(model_tuples, create_tuple(key, mm))
  434. result = model_split(merged_model, model_tuples, tracability)
  435. if (tracability):
  436. Element new_tracability_model
  437. new_tracability_model = result["__tracability"]
  438. dict_overwrite(tracability_model, "model", new_tracability_model["model"])
  439. dict_overwrite(tracability_model, "type_mapping", new_tracability_model["type_mapping"])
  440. dict_overwrite(tracability_model, "metamodel", new_tracability_model["metamodel"])
  441. dict_delete(result, "__tracability")
  442. return result!
  443. else:
  444. log("Negative result of execution")
  445. return read_root()!
  446. Boolean function enact_action(pm : Element, element : String, prefix : String):
  447. Boolean result
  448. String transformation_id
  449. Element lst
  450. String elem
  451. Element inputs
  452. Element outputs
  453. String type_name
  454. String exact_type
  455. Element trace_links
  456. Element output_mms
  457. Element consumes_link
  458. String name
  459. String value
  460. String elem_name
  461. Element keys
  462. String key
  463. String consume
  464. String produce
  465. Element output_map
  466. inputs = dict_create()
  467. outputs = dict_create()
  468. output_map = dict_create()
  469. // Read out the referenced element from the MvC
  470. transformation_id = get_model_id(read_attribute(pm, element, "name"))
  471. // Find all input model names
  472. lst = allOutgoingAssociationInstances(pm, element, "Consumes")
  473. while (set_len(lst) > 0):
  474. consume = set_pop(lst)
  475. value = read_attribute(pm, readAssociationDestination(pm, consume), "name")
  476. dict_add(inputs, read_attribute(pm, consume, "name"), prefix + value)
  477. // Find all output model names and their metamodel
  478. lst = allOutgoingAssociationInstances(pm, element, "Produces")
  479. while (set_len(lst) > 0):
  480. produce = set_pop(lst)
  481. elem = readAssociationDestination(pm, produce)
  482. type_name = read_attribute(pm, elem, "type")
  483. elem_name = read_attribute(pm, elem, "name")
  484. dict_add(outputs, read_attribute(pm, produce, "name"), type_name)
  485. dict_add(output_map, read_attribute(pm, produce, "name"), prefix + elem_name)
  486. if read_type(core, transformation_id) == "ActionLanguage":
  487. log(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  488. output(string_join("Enacting ActionLanguage: ", read_attribute(pm, element, "name")))
  489. elif read_type(core, transformation_id) == "ManualOperation":
  490. log(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  491. output(string_join("Enacting ManualOperation: ", read_attribute(pm, element, "name")))
  492. else:
  493. log(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  494. output(string_join("Enacting ModelTransformation: ", read_attribute(pm, element, "name")))
  495. result = execute_operation(transformation_id, inputs, read_root())
  496. if (element_eq(result, read_root())):
  497. // Something went wrong!
  498. return False!
  499. else:
  500. keys = dict_keys(result)
  501. while (set_len(keys) > 0):
  502. key = set_pop(keys)
  503. if (get_model_id(output_map[key]) == ""):
  504. // New model
  505. model_create(result[key], output_map[key], get_model_id(key), "Model")
  506. else:
  507. model_overwrite(result[key], get_model_id(output_map[key]), get_model_id(outputs[key]))
  508. return True!
  509. Void function enact_PM(pm : Element, prefix : String):
  510. Element worklist
  511. String element
  512. String start
  513. String type
  514. Boolean result
  515. Element tuple
  516. Element counters
  517. Element join_nodes
  518. output("Success")
  519. // Initialize Join counters
  520. counters = dict_create()
  521. join_nodes = allInstances(pm, "Join")
  522. while (set_len(join_nodes) > 0):
  523. dict_add(counters, set_pop(join_nodes), 0)
  524. // Create the worklist with the Start instance as first element
  525. worklist = set_create()
  526. set_add_node(worklist, create_tuple(set_pop(allInstances(pm, "Start")), True))
  527. while (bool_not(pm_finished(worklist, pm))):
  528. // Pop a random element from the list and execute it
  529. tuple = set_pop(worklist)
  530. element = tuple[0]
  531. result = tuple[1]
  532. // Find the type (to see what to do with it)
  533. // this does not yet yield the type of transformation, if it is an Execution
  534. type = read_type(pm, element)
  535. if (type == "Start"):
  536. // Initial node, just progress to the next elements
  537. // Nothing to do here though, as we have just started
  538. result = True
  539. elif (type == "Finish"):
  540. // Should be impossible, as we would have ended...
  541. result = result
  542. elif (type == "Fork"):
  543. result = result
  544. elif (type == "Join"):
  545. // Only do this if all dependencies are fullfilled
  546. // So add to the counter of this Join
  547. dict_overwrite(counters, element, integer_addition(counters[element], 1))
  548. // Now check whether we have enough tokens to execute the Join itself
  549. Integer required
  550. Integer got
  551. required = set_len(allIncomingAssociationInstances(pm, element, "Next")) + set_len(allIncomingAssociationInstances(pm, element, "Else"))
  552. got = counters[element]
  553. if (got == required):
  554. // Reset counter to 0
  555. dict_overwrite(counters, element, 0)
  556. // And continue
  557. else:
  558. // We haven't gotten all yet, so we wait (i.e., continue without adding Next link to worklist)
  559. continue!
  560. elif (type == "Exec"):
  561. // Execute a transformation
  562. // This the difficult part!
  563. result = enact_action(pm, element, prefix)
  564. elif (type == "Decision"):
  565. // If the previous result is true, we add the normal one, otherwise the false one
  566. // in this context, that means that if it is false, we should add it manually to the list, and then continue the simulation loop
  567. if (bool_not(result)):
  568. // Apparently it is False, so map this to the "Else" branch
  569. set_add_node(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Else")), True))
  570. continue!
  571. else:
  572. // Apparently it is True, so map this to the "Then" branch
  573. set_add_node(worklist, create_tuple(set_pop(allAssociationDestinations(pm, element, "Then")), True))
  574. continue!
  575. // We have finished the execution, so add all outgoing edges to the worklist
  576. Element all_next
  577. all_next = allAssociationDestinations(pm, element, "Next")
  578. String next
  579. while (set_len(all_next) > 0):
  580. next = set_pop(all_next)
  581. set_add_node(worklist, create_tuple(next, result))
  582. // Reached a finish element, so stop
  583. output("Success")
  584. return !
  585. String function cmd_help():
  586. String result
  587. result = ""
  588. result = result + ("Model operations\n")
  589. result = result + (" model_add -- Add a new model\n")
  590. result = result + (" model_modify -- Modify an existing model\n")
  591. result = result + (" model_list -- List all models\n")
  592. result = result + (" model_list_full -- List all models with full info\n")
  593. result = result + (" model_overwrite -- Overwrites a model with an uploaded model, leaving all metadata\n")
  594. result = result + (" model_render -- Render a given model with a specified mapper\n")
  595. result = result + (" verify -- Check whether a model conforms to its metamodel\n")
  596. result = result + ("\n")
  597. result = result + ("Transformation-specific operations\n")
  598. result = result + (" transformation_add_MT -- Initialize a new model transformation\n")
  599. result = result + (" transformation_add_AL -- Initialize a new action language transformation\n")
  600. result = result + (" transformation_add_MANUAL -- Initialize a new manual transformation\n")
  601. result = result + (" transformation_execute -- Execute a transformation on a set of input models\n")
  602. result = result + (" transformation_list -- List all model transformations\n")
  603. result = result + (" transformation_list_full -- List all model transformations with permissions\n")
  604. result = result + (" transformation_detail -- List transformation details\n")
  605. result = result + (" transformation_between -- List all transformations between two metamodels\n")
  606. result = result + ("\n")
  607. result = result + ("Process operations\n")
  608. result = result + (" process_execute -- Execute a process model\n")
  609. result = result + ("\n")
  610. result = result + ("Model permission operations\n")
  611. result = result + (" permission_modify -- Change model permissions\n")
  612. result = result + (" permission_owner -- Change model owner\n")
  613. result = result + (" permission_group -- Change model group\n")
  614. result = result + ("\n")
  615. result = result + ("Group operations\n")
  616. result = result + (" group_create -- Create a group\n")
  617. result = result + (" group_delete -- Delete a group\n")
  618. result = result + (" group_owner_add -- Add group owner\n")
  619. result = result + (" group_owner_delete -- Remove group owner\n")
  620. result = result + (" group_join -- Add someone to your group\n")
  621. result = result + (" group_kick -- Kick someone from your group\n")
  622. result = result + (" group_list -- List all groups you are a member of\n")
  623. result = result + ("\n")
  624. if (is_admin(current_user_id)):
  625. result = result + ("Admin operations\n")
  626. result = result + (" admin_promote -- Promote a user to admin status\n")
  627. result = result + (" admin_demote -- Demote a user to normal status\n")
  628. result = result + ("\n")
  629. result = result + ("General operations\n")
  630. result = result + (" self-destruct -- Remove current user and revoke all permissions \n")
  631. result = result + (" exit -- Kill the current task, while retaining user\n")
  632. return result!
  633. String function cmd_model_add(type : String, name : String):
  634. // Model addition operation, which uses model upload commands of the compiler
  635. String location
  636. String type_id
  637. Element new_model
  638. String new_model_id
  639. type_id = get_model_id(type)
  640. if (type_id != ""):
  641. // Type exists
  642. if (allow_read(current_user_id, type_id)):
  643. // And is readable
  644. if (get_model_id(name) == ""):
  645. // Model doesn't exist yet
  646. Element mm
  647. mm = get_full_model(type_id, get_model_id("SimpleClassDiagrams"))
  648. if (element_eq(mm, read_root())):
  649. return "Type is not typed by SimpleClassDiagrams: " + type!
  650. output("Waiting for model constructors...")
  651. new_model = construct_model_raw(mm)
  652. model_create(new_model, name, type_id, "Model")
  653. return "Success"!
  654. else:
  655. return "Model exists: " + name!
  656. else:
  657. return "Permission denied to model: " + type!
  658. else:
  659. return "Model not found: " + type!
  660. String function cmd_process_execute(process : String, prefix : String):
  661. // Execute a process model until it reaches termination
  662. String process_id
  663. process_id = get_model_id(process)
  664. if (process_id != ""):
  665. if (allow_read(current_user_id, process_id)):
  666. Element pm
  667. pm = get_full_model(process_id, get_model_id("ProcessModel"))
  668. if (element_eq(pm, read_root())):
  669. return "Specified model cannot be interpreted as a ProcessModel: " + process!
  670. enact_PM(pm, prefix)
  671. return "Success"!
  672. else:
  673. return "Permission denied to model: " + process!
  674. else:
  675. return "Model not found: " + process!
  676. String function cmd_transformation_between(source_name : String, target_name : String):
  677. String source_id
  678. String target_id
  679. Element onSource
  680. Element onTarget
  681. Element result
  682. String transformation
  683. source_id = get_model_id(source_name)
  684. if (source_id != ""):
  685. target_id = get_model_id(target_name)
  686. if (target_id != ""):
  687. onSource = allAssociationOrigins(core, source_id, "transformInput")
  688. onTarget = allAssociationOrigins(core, target_id, "transformOutput")
  689. result = set_overlap(onSource, onTarget)
  690. String r
  691. r = "Success: "
  692. while (set_len(result) > 0):
  693. transformation = set_pop(result)
  694. if (allow_read(current_user_id, transformation)):
  695. r = r + string_join(read_attribute(core, transformation, "name"), "\n")
  696. return r!
  697. else:
  698. return "Model not found: " + target_name!
  699. else:
  700. return "Model not found: " + source_name!
  701. String function cmd_model_render(model_name : String, mapper_name : String):
  702. String model_ID
  703. String mapper_ID
  704. String rendered_name
  705. String tracability_name
  706. Element inputs
  707. Element output_map
  708. Element rendered_model
  709. Element tracability_model
  710. Element result
  711. Element out_links
  712. String link
  713. model_ID = get_model_id(model_name)
  714. if (model_ID != ""):
  715. mapper_ID = get_model_id(mapper_name)
  716. if (allow_read(current_user_id, model_ID)):
  717. if (mapper_ID != ""):
  718. if (allow_read(current_user_id, mapper_ID)):
  719. // Everything is fine; start the actual operation
  720. // Find metamodel to render to
  721. rendered_name = (("__RENDERED_" + model_name) + "__") + mapper_name
  722. tracability_name = (("__TRACABILITY_" + model_name) + "__") + mapper_name
  723. // Take the abstract syntax model and the previously rendered model
  724. inputs = dict_create()
  725. dict_add(inputs, "abstract", model_name)
  726. dict_add(inputs, "rendered", rendered_name)
  727. // Fetch the output types
  728. output_map = dict_create()
  729. out_links = allOutgoingAssociationInstances(core, mapper_ID, "transformOutput")
  730. while(set_len(out_links) > 0):
  731. link = set_pop(out_links)
  732. dict_add(output_map, read_attribute(core, link, "name"), read_attribute(core, readAssociationDestination(core, link), "name"))
  733. if (get_model_id(rendered_name) == ""):
  734. // Instantiate
  735. Element rendered
  736. rendered = get_full_model(get_model_id(output_map["rendered"]), get_model_id("SimpleClassDiagrams"))
  737. if (element_eq(rendered, read_root())):
  738. return "Rendered metamodel cannot conform to SimpleClassDiagrams"!
  739. rendered_model = instantiate_model(rendered)
  740. model_create(rendered_model, rendered_name, get_model_id(output_map["rendered"]), "Model")
  741. // Tracability model won't exist either
  742. tracability_model = instantiate_model(get_full_model(get_model_id("Tracability"), get_model_id("SimpleClassDiagrams")))
  743. model_create(tracability_model, tracability_name, get_model_id("Tracability"), "Model")
  744. else:
  745. // Read out tracability model
  746. tracability_model = get_full_model(get_model_id(tracability_name), get_model_id("Tracability"))
  747. if (element_eq(tracability_model, read_root())):
  748. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  749. // Do the operation itself!
  750. result = execute_operation(mapper_ID, inputs, tracability_model)
  751. // Overwrite the previous rendered model
  752. model_overwrite(result["rendered"], get_model_id(rendered_name), get_model_id(output_map["rendered"]))
  753. model_overwrite(result["abstract"], get_model_id(model_name), get_model_id(output_map["abstract"]))
  754. // Tracability updated in-place
  755. model_overwrite(tracability_model, get_model_id(tracability_name), get_model_id("Tracability"))
  756. tracability_model = get_full_model(get_model_id(tracability_name), get_model_id("Tracability"))
  757. if (element_eq(tracability_model, read_root())):
  758. return "Tracability model not typed by Tracability metamodel: " + tracability_name!
  759. // Also output the resulting model
  760. return "Success: " + JSON_print(get_full_model(get_model_id(rendered_name), get_model_id(output_map["rendered"])))!
  761. else:
  762. return "Permission denied to model: " + mapper_name!
  763. else:
  764. return "Model not found: " + mapper_name!
  765. else:
  766. return "Permission denied to model: " + model_name!
  767. else:
  768. return "Model not found: " + model_name!
  769. String function cmd_transformation_execute(transformation_name : String, source_models : Element, target_models : Element):
  770. // Execute a transformation, whatever type it is
  771. // First we detect the type, so we know how to prepare for invocation
  772. String transformation_id
  773. String exact_type
  774. Element sources
  775. Element targets
  776. String source
  777. String target
  778. Element inputs
  779. Element outputs
  780. Element output_map
  781. Element trace_links
  782. String target_model_name
  783. String source_model_name
  784. String source_model_ID
  785. Element result
  786. Element keys
  787. String key
  788. String assoc_name
  789. transformation_id = get_model_id(transformation_name)
  790. if (transformation_id != ""):
  791. if (allow_read(current_user_id, transformation_id)):
  792. if (is_nominal_instance(core, transformation_id, "Transformation")):
  793. // Read out source and target links
  794. inputs = dict_create()
  795. sources = allOutgoingAssociationInstances(core, transformation_id, "transformInput")
  796. while (set_len(sources) > 0):
  797. source = set_pop(sources)
  798. assoc_name = read_attribute(core, source, "name")
  799. if (dict_in(source_models, assoc_name)):
  800. source_model_name = source_models[assoc_name]
  801. else:
  802. return "Source model not bound: " + assoc_name!
  803. source_model_ID = get_model_id(source_model_name)
  804. if (source_model_ID != ""):
  805. if (allow_read(current_user_id, source_model_ID)):
  806. // Check for conformance to the requested metamodel
  807. dict_add(inputs, assoc_name, source_model_name)
  808. continue!
  809. else:
  810. return "Permission denied to model: " + source_model_name!
  811. else:
  812. return "Model not found: " + source_model_name!
  813. targets = allOutgoingAssociationInstances(core, transformation_id, "transformOutput")
  814. outputs = dict_create()
  815. output_map = dict_create()
  816. while (set_len(targets) > 0):
  817. target = set_pop(targets)
  818. assoc_name = read_attribute(core, target, "name")
  819. if (dict_in(target_models, assoc_name)):
  820. target_model_name = target_models[assoc_name]
  821. else:
  822. return "Target model not bound: " + assoc_name!
  823. if (get_model_id(target_model_name) == ""):
  824. // Doesn't exist yet, so we can easily create
  825. dict_add(output_map, assoc_name, read_attribute(core, readAssociationDestination(core, target), "name"))
  826. dict_add(outputs, assoc_name, target_model_name)
  827. else:
  828. // Already exists, so we need to check for write access
  829. if (allow_write(current_user_id, get_model_id(target_model_name))):
  830. dict_add(output_map, assoc_name, read_attribute(core, readAssociationDestination(core, target), "name"))
  831. dict_add(outputs, assoc_name, target_model_name)
  832. else:
  833. return "Permission denied to model: " + target_model_name!
  834. if (read_type(core, transformation_id) == "ActionLanguage"):
  835. output("Success: ready for AL execution")
  836. elif (read_type(core, transformation_id) == "ManualOperation"):
  837. output("Success: ready for MANUAL execution")
  838. else:
  839. output("Success: ready for MT execution")
  840. result = execute_operation(transformation_id, inputs, read_root())
  841. // Now write out the models again
  842. if (element_eq(result, read_root())):
  843. // Something went wrong!
  844. return "Failure"!
  845. else:
  846. keys = dict_keys(result)
  847. while (set_len(keys) > 0):
  848. key = set_pop(keys)
  849. if (get_model_id(outputs[key]) == ""):
  850. // New model
  851. model_create(result[key], outputs[key], get_model_id(key), "Model")
  852. else:
  853. model_overwrite(result[key], get_model_id(outputs[key]), get_model_id(output_map[key]))
  854. return "Success"!
  855. else:
  856. return "Model is not executable: " + transformation_name!
  857. else:
  858. return "Permission denied to model: " + transformation_name!
  859. else:
  860. return "Model not found: " + transformation_name!
  861. String function cmd_verify(model_name : String, metamodel_name : String):
  862. // Check whether a model conforms to its specification (with the selected type mapping)
  863. String model_id
  864. String result
  865. Element inputs
  866. model_id = get_model_id(model_name)
  867. if (model_id != ""):
  868. if (allow_read(current_user_id, model_id)):
  869. Element m
  870. m = get_full_model(get_model_id(model_name), get_model_id(metamodel_name))
  871. if (element_eq(m, read_root())):
  872. return "No conformance relation can be found between these models"!
  873. return string_join("Success: ", conformance_scd(m))!
  874. else:
  875. return "Permission denied to model: " + model_name!
  876. else:
  877. return "Model not found: " + model_name!
  878. String function cmd_model_overwrite(model_name : String, metamodel_name : String):
  879. // Overwrites an existing model without changing any metadata
  880. String model_id
  881. String type_id
  882. Element new_model
  883. model_id = get_model_id(model_name)
  884. if (model_id != ""):
  885. if (allow_write(current_user_id, model_id)):
  886. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  887. if (allow_read(current_user_id, type_id)):
  888. Element mm
  889. mm = get_full_model(get_model_id(metamodel_name), get_model_id("SimpleClassDiagrams"))
  890. if (element_eq(mm, read_root())):
  891. return "Metamodel does not conform to SimpleClassDiagrams: " + metamodel_name!
  892. output("Waiting for model constructors...")
  893. new_model = construct_model_raw(mm)
  894. model_overwrite(new_model, model_id, metamodel_name)
  895. return "Success"!
  896. else:
  897. return string_join("Permission denied to model: ", read_attribute(core, type_id, "name"))!
  898. else:
  899. return "Permission denied to model: " + model_name!
  900. else:
  901. return "Model not found: " + model_name!
  902. String function cmd_model_modify(model_name : String, metamodel_name : String):
  903. // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
  904. String model_id
  905. String type_id
  906. model_id = get_model_id(model_name)
  907. if (model_id != ""):
  908. if (allow_read(current_user_id, model_id)):
  909. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  910. if (allow_read(current_user_id, type_id)):
  911. Element new_model
  912. new_model = get_full_model(model_id, get_model_id(metamodel_name))
  913. if (element_eq(new_model, read_root())):
  914. return "No conformance relation can be found between these models"!
  915. output("Success")
  916. modify(new_model, allow_write(current_user_id, model_id))
  917. if (allow_write(current_user_id, model_id)):
  918. // Overwrite the modified model
  919. model_overwrite(new_model, model_id, metamodel_name)
  920. return "Success"!
  921. else:
  922. return string_join("Permission denied to model: ", read_attribute(core, type_id, "name"))!
  923. else:
  924. return "Permission denied to model: " + model_name!
  925. else:
  926. return "Model not found: " + model_name!
  927. String function cmd_model_delete(model_name : String):
  928. String model_id
  929. model_id = get_model_id(model_name)
  930. if (model_id != ""):
  931. if (allow_write(current_user_id, model_id)):
  932. model_delete_element(core, model_id)
  933. return "Success"!
  934. else:
  935. return "Permission denied to model: " + model_name!
  936. else:
  937. return "Model not found: " + model_name!
  938. String function cmd_model_list():
  939. // List all models
  940. Element models
  941. String result
  942. String m
  943. result = "Success: "
  944. models = allInstances(core, "Model")
  945. while (set_len(models) > 0):
  946. m = set_pop(models)
  947. if (set_len(allAssociationDestinations(core, m, "instanceOf")) > 0):
  948. result = (result + string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name"))) + "\n"
  949. else:
  950. result = result + string_join(string_join(" ", read_attribute(core, m, "name")), " : None\n")
  951. return result!
  952. String function cmd_model_list_full():
  953. // List all models with full info
  954. Element models
  955. String m
  956. String permissions
  957. String owner
  958. String group
  959. String name
  960. String type
  961. String result
  962. result = "Success: "
  963. models = allInstances(core, "Model")
  964. while (set_len(models) > 0):
  965. m = set_pop(models)
  966. permissions = read_attribute(core, m, "permissions")
  967. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  968. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  969. name = read_attribute(core, m, "name")
  970. if (set_len(allAssociationDestinations(core, m, "instanceOf")) > 0):
  971. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  972. else:
  973. type = "None"
  974. result = (result + (((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + name) + " : ") + type)) + "\n"
  975. return result!
  976. String function cmd_transformation_add_MANUAL(source_models : Element, target_models : Element, operation_name : String):
  977. return transformation_add(source_models, target_models, operation_name, "manual")!
  978. String function cmd_transformation_add_AL(source_models : Element, target_models : Element, operation_name : String):
  979. return transformation_add(source_models, target_models, operation_name, "actionlanguage")!
  980. String function transformation_add(source_models : Element, target_models : Element, operation_name : String, operation_type : String):
  981. // Add a manual transformation model
  982. String model_id
  983. Element models
  984. Element source
  985. Element target
  986. String name
  987. Element all_formalisms
  988. Element formalism_map
  989. Element merged_formalism
  990. String merged_formalism_id
  991. String source_formalism_id
  992. String tracability_link
  993. Element fused
  994. Element keys
  995. String key
  996. Element mm
  997. source = dict_create()
  998. target = dict_create()
  999. all_formalisms = set_create()
  1000. formalism_map = set_create()
  1001. fused = set_create()
  1002. keys = dict_keys(source_models)
  1003. while (set_len(keys) > 0):
  1004. key = set_pop(keys)
  1005. name = source_models[key]
  1006. model_id = get_model_id(name)
  1007. if (model_id != ""):
  1008. if (allow_read(current_user_id, model_id)):
  1009. if (bool_not(dict_in(source, key))):
  1010. dict_add(source, key, model_id)
  1011. mm = get_full_model(model_id, get_model_id("SimpleClassDiagrams"))
  1012. if (element_eq(mm, read_root())):
  1013. return "Transformation source type not in SimpleClassDiagrams hierarchy: " + key!
  1014. if (bool_not(set_in(fused, key))):
  1015. set_add_node(formalism_map, create_tuple(key, mm))
  1016. set_add(fused, key)
  1017. if (bool_not(set_in(all_formalisms, model_id))):
  1018. set_add(all_formalisms, model_id)
  1019. else:
  1020. return "Name already selected for source: " + key!
  1021. else:
  1022. return "Permission denied to model: " + name!
  1023. else:
  1024. return "Model not found: " + name!
  1025. keys = dict_keys(target_models)
  1026. while (set_len(keys) > 0):
  1027. key = set_pop(keys)
  1028. name = target_models[key]
  1029. model_id = get_model_id(name)
  1030. if (model_id != ""):
  1031. if (allow_read(current_user_id, model_id)):
  1032. if (bool_not(dict_in(target, key))):
  1033. dict_add(target, key, model_id)
  1034. mm = get_full_model(model_id, get_model_id("SimpleClassDiagrams"))
  1035. if (element_eq(mm, read_root())):
  1036. return "Transformation target type not in SimpleClassDiagrams hierarchy: " + key!
  1037. if (bool_not(set_in(fused, key))):
  1038. set_add_node(formalism_map, create_tuple(key, mm))
  1039. set_add(fused, key)
  1040. if (bool_not(set_in(all_formalisms, model_id))):
  1041. set_add(all_formalisms, model_id)
  1042. else:
  1043. return "Name already selected for target: " + key!
  1044. else:
  1045. return "Permission denied to model: " + name!
  1046. else:
  1047. return "Model not found: " + name!
  1048. if (get_model_id(operation_name) == ""):
  1049. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1050. // New location is available, so write
  1051. if (bool_not(bool_and(dict_len(source_models) == 0, dict_len(target_models) == 0))):
  1052. merged_formalism = model_fuse(formalism_map)
  1053. modify(merged_formalism, True)
  1054. if (operation_type == "manual"):
  1055. // Finished with all information, now create the model itself!
  1056. Element m
  1057. m = get_full_model(get_model_id("ManualOperation"), get_model_id("SimpleClassDiagrams"))
  1058. if (element_eq(m, read_root())):
  1059. log("Error when opening ManualOperation: no conformance relation found")
  1060. return "Error when opening ManualOperation: no conformance relation found"!
  1061. model_create(instantiate_model(m), operation_name, get_model_id("ManualOperation"), "ManualOperation")
  1062. model_id = get_model_id(operation_name)
  1063. elif (operation_type == "actionlanguage"):
  1064. // Finished with all information, now create the model itself!
  1065. output("Waiting for code constructors...")
  1066. add_code_model(get_full_model(get_model_id("ActionLanguage"), get_model_id("SimpleClassDiagrams")), "AL/" + operation_name, construct_function())
  1067. model_create(import_node("AL/" + operation_name), operation_name, get_model_id("ActionLanguage"), "ActionLanguage")
  1068. model_id = get_model_id(operation_name)
  1069. if (bool_not(bool_and(dict_len(source_models) == 0, dict_len(target_models) == 0))):
  1070. model_create(merged_formalism, "__merged_" + operation_name, get_model_id("SimpleClassDiagrams"), "Model")
  1071. merged_formalism_id = get_model_id("__merged_" + operation_name)
  1072. // Add tracability links at this level
  1073. while (set_len(all_formalisms) > 0):
  1074. source_formalism_id = set_pop(all_formalisms)
  1075. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, source_formalism_id)
  1076. instantiate_attribute(core, tracability_link, "type", "merged")
  1077. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1078. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1079. // Extend metadata with info on source and target
  1080. String link
  1081. String dst
  1082. keys = dict_keys(source)
  1083. while (set_len(keys) > 0):
  1084. key = set_pop(keys)
  1085. link = instantiate_link(core, "transformInput", "", model_id, source[key])
  1086. instantiate_attribute(core, link, "name", key)
  1087. keys = dict_keys(target)
  1088. while (set_len(keys) > 0):
  1089. key = set_pop(keys)
  1090. link = instantiate_link(core, "transformOutput", "", model_id, target[key])
  1091. instantiate_attribute(core, link, "name", key)
  1092. return "Success"!
  1093. else:
  1094. return "Model exists: " + operation_name!
  1095. String function cmd_transformation_add_MT(source_models : Element, target_models : Element, operation_name : String):
  1096. // Add a model transformation model
  1097. // Just a usual model instantiation, but need to add the source and target links based on user info
  1098. String ramified_metamodel_id
  1099. Element ramified_metamodel
  1100. String model_id
  1101. Element models
  1102. Element links
  1103. String link_id
  1104. Element supported
  1105. Element source
  1106. Element target
  1107. String name
  1108. String new_model_id
  1109. String merged_link_id
  1110. Element links_merged
  1111. String merged_formalism
  1112. Element keys
  1113. String key
  1114. Element mm
  1115. Element to_ramify
  1116. String source_formalism_id
  1117. String merged_formalism_id
  1118. String tracability_link
  1119. source = dict_create()
  1120. target = dict_create()
  1121. to_ramify = set_create()
  1122. keys = dict_keys(source_models)
  1123. while (set_len(keys) > 0):
  1124. key = set_pop(keys)
  1125. name = source_models[key]
  1126. model_id = get_model_id(name)
  1127. if (model_id != ""):
  1128. if (allow_read(current_user_id, name)):
  1129. // Check whether or not it is SimpleClassDiagrams
  1130. if (is_typed_by(model_id, get_model_id("SimpleClassDiagrams"))):
  1131. if (bool_not(dict_in(source, key))):
  1132. dict_add(source, key, model_id)
  1133. mm = get_full_model(model_id, get_model_id("SimpleClassDiagrams"))
  1134. if (element_eq(mm, read_root())):
  1135. return "ModelTransformation source type not in SimpleClassDiagrams hierarchy: " + name!
  1136. set_add_node(to_ramify, create_tuple(key, mm))
  1137. else:
  1138. return "Name was already assigned a metamodel: " + key!
  1139. else:
  1140. return "Model not supported for RAMification: " + name!
  1141. else:
  1142. return "Permission denied: " + name!
  1143. else:
  1144. return "Model not found: " + name!
  1145. keys = dict_keys(target_models)
  1146. while (set_len(keys) > 0):
  1147. key = set_pop(keys)
  1148. name = target_models[key]
  1149. model_id = get_model_id(name)
  1150. if (model_id != ""):
  1151. if (allow_read(current_user_id, name)):
  1152. if (is_typed_by(model_id, get_model_id("SimpleClassDiagrams"))):
  1153. if (bool_not(dict_in(target, key))):
  1154. if (dict_in(source, key)):
  1155. if (value_eq(model_id, source[key])):
  1156. dict_add(target, key, model_id)
  1157. // Don't add to to_ramify, as it is already in there!
  1158. else:
  1159. return "Name in output cannot have different type than input: " + key!
  1160. else:
  1161. dict_add(target, key, model_id)
  1162. mm = get_full_model(model_id, get_model_id("SimpleClassDiagrams"))
  1163. if (element_eq(mm, read_root())):
  1164. return "ModelTransformation target type not in SimpleClassDiagrams hierarchy: " + name!
  1165. set_add_node(to_ramify, create_tuple(key, mm))
  1166. else:
  1167. return "Name was already assigned a metamodel: " + key!
  1168. else:
  1169. return "Model not supported for RAMification: " + name!
  1170. else:
  1171. return "Permission denied: " + name!
  1172. else:
  1173. return "Model not found: " + name!
  1174. merged_formalism = model_fuse(to_ramify)
  1175. modify(merged_formalism, True)
  1176. ramified_metamodel = ramify(merged_formalism)
  1177. model_create(ramified_metamodel, "__RAM_" + operation_name, get_model_id("SimpleClassDiagrams"), "Model")
  1178. ramified_metamodel_id = get_model_id("__RAM_" + operation_name)
  1179. // Now use the RAMified model to create the instance
  1180. if (get_model_id(operation_name) == ""):
  1181. String new_model
  1182. // Finished with all information, now create the model itself!
  1183. output("Waiting for model constructors...")
  1184. new_model = construct_model_raw(get_full_model(ramified_metamodel_id, get_model_id("SimpleClassDiagrams")))
  1185. model_create(new_model, operation_name, ramified_metamodel_id, "ModelTransformation")
  1186. model_id = get_model_id(operation_name)
  1187. // Write out a merged metamodel containing all these models: this is the MM for the manual operation
  1188. // New location is available, so write
  1189. model_create(merged_formalism, "__merged_" + operation_name, get_model_id("SimpleClassDiagrams"), "Model")
  1190. merged_formalism_id = get_model_id("__merged_" + operation_name)
  1191. // Add tracability links at this level
  1192. tracability_link = instantiate_link(core, "tracability", "", model_id, merged_formalism_id)
  1193. instantiate_attribute(core, tracability_link, "type", "operatesOn")
  1194. // Add tracability links at this level
  1195. tracability_link = instantiate_link(core, "tracability", "", merged_formalism_id, ramified_metamodel_id)
  1196. instantiate_attribute(core, tracability_link, "type", "RAMified")
  1197. // Extend metadata with info on source and target
  1198. String link
  1199. String dst
  1200. keys = dict_keys(source)
  1201. while (set_len(keys) > 0):
  1202. key = set_pop(keys)
  1203. dst = source[key]
  1204. link = instantiate_link(core, "transformInput", "", model_id, dst)
  1205. instantiate_attribute(core, link, "name", key)
  1206. keys = dict_keys(target)
  1207. while (set_len(keys) > 0):
  1208. key = set_pop(keys)
  1209. dst = target[key]
  1210. link = instantiate_link(core, "transformOutput", "", model_id, dst)
  1211. instantiate_attribute(core, link, "name", key)
  1212. return "Success"!
  1213. else:
  1214. return "Model exists: " + operation_name!
  1215. String function cmd_transformation_list():
  1216. // List all models
  1217. Element models
  1218. String m
  1219. String type
  1220. String result
  1221. result = "Success: "
  1222. models = allInstances(core, "Transformation")
  1223. while (set_len(models) > 0):
  1224. m = set_pop(models)
  1225. result = result + ((string_join(("[" + read_type(core, m)) + "]", string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")))) + "\n")
  1226. return result!
  1227. String function cmd_transformation_list_full():
  1228. // List all models with full info
  1229. Element models
  1230. String m
  1231. String permissions
  1232. String owner
  1233. String group
  1234. String name
  1235. String type
  1236. String result
  1237. result = ""
  1238. models = allInstances(core, "Transformation")
  1239. while (set_len(models) > 0):
  1240. m = set_pop(models)
  1241. permissions = read_attribute(core, m, "permissions")
  1242. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  1243. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  1244. name = read_attribute(core, m, "name")
  1245. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  1246. result = result + ((((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + ((("[" + read_type(core, m)) + "] ") + name)) + " : ") + type) + "\n")
  1247. return result!
  1248. String function cmd_permission_modify(model_name : String, permissions : String):
  1249. Integer permission
  1250. String model_id
  1251. model_id = get_model_id(model_name)
  1252. if (model_id != ""):
  1253. if (get_relation_to_model(current_user_id, model_id) == 0):
  1254. Boolean fail
  1255. Integer i
  1256. i = 0
  1257. if (string_len(permissions) != 3):
  1258. fail = True
  1259. while (i < 3):
  1260. permission = cast_s2i(string_get(permissions, i))
  1261. if (bool_or(permission < 0, permission > 2)):
  1262. fail = True
  1263. break!
  1264. i = i + 1
  1265. if (bool_not(fail)):
  1266. unset_attribute(core, model_id, "permissions")
  1267. instantiate_attribute(core, model_id, "permissions", permissions)
  1268. return "Success"!
  1269. else:
  1270. return "Permission has incorrect format: must be a string of three characters, with each character being a digit between 0 and 2"!
  1271. else:
  1272. return "Permission denied to model: " + model_name!
  1273. else:
  1274. return "Model not found: " + model_name!
  1275. String function cmd_permission_owner(model_name : String, new_user_name : String):
  1276. String model_id
  1277. String new_user_id
  1278. model_id = get_model_id(model_name)
  1279. if (model_id != ""):
  1280. if (bool_or(get_relation_to_model(current_user_id, model_id) == 0, is_admin(current_user_id))):
  1281. new_user_id = get_user_id(new_user_name)
  1282. if (new_user_id != ""):
  1283. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  1284. instantiate_link(core, "owner", "", model_id, new_user_id)
  1285. return "Success"!
  1286. else:
  1287. return "No such user: " + new_user_name!
  1288. else:
  1289. return "Permission denied to model: " + model_name!
  1290. else:
  1291. return "Model not found: " + model_name!
  1292. String function cmd_permission_group(model_name : String, new_group_name : String):
  1293. String model_id
  1294. String group_id
  1295. model_id = get_model_id(model_name)
  1296. if (model_id != ""):
  1297. if (bool_or(get_relation_to_model(current_user_id, model_id) == 0, is_admin(current_user_id))):
  1298. group_id = get_group_id(new_group_name)
  1299. if (group_id != ""):
  1300. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  1301. instantiate_link(core, "group", "", model_id, group_id)
  1302. return "Success"!
  1303. else:
  1304. return "No such group: " + new_group_name!
  1305. else:
  1306. return "Permission denied to model: " + model_name!
  1307. else:
  1308. return "Model not found: " + model_name!
  1309. String function cmd_group_create(group_name : String):
  1310. // Create a new group and become its owner
  1311. String group_id
  1312. String name
  1313. group_id = get_group_id(group_name)
  1314. if (group_id == ""):
  1315. group_id = instantiate_node(core, "Group", "")
  1316. instantiate_attribute(core, group_id, "name", group_name)
  1317. instantiate_link(core, "belongsTo", "", current_user_id, group_id)
  1318. instantiate_link(core, "owner", "", group_id, current_user_id)
  1319. return "Success"!
  1320. else:
  1321. return "Group exists: " + group_name!
  1322. String function cmd_group_delete(group_name : String):
  1323. // Delete an existing group
  1324. String group_id
  1325. group_id = get_group_id(group_name)
  1326. if (group_id != ""):
  1327. if (allow_group_modify(current_user_id, group_id)):
  1328. model_delete_element(core, group_id)
  1329. return "Success"!
  1330. else:
  1331. return "Permission denied to group: " + group_name!
  1332. else:
  1333. return "Group not found: " + group_name!
  1334. String function cmd_group_owner_add(group_name : String, other_user_name : String):
  1335. // Add an owner to your group
  1336. String group_id
  1337. String other_user_id
  1338. group_id = get_group_id(group_name)
  1339. if (group_id != ""):
  1340. if (allow_group_modify(current_user_id, group_id)):
  1341. other_user_id = get_user_id(other_user_name)
  1342. if (other_user_id != ""):
  1343. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1344. instantiate_link(core, "owner", "", group_id, other_user_id)
  1345. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1346. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1347. return "Success"!
  1348. else:
  1349. return "User is already the owner!"!
  1350. else:
  1351. return "User not found: " + other_user_name!
  1352. else:
  1353. return "Permission denied to group: " + group_name!
  1354. else:
  1355. return "Group not found: " + group_name!
  1356. String function cmd_group_owner_delete(group_name : String, other_user_name : String):
  1357. // Remove an owner from your group
  1358. String group_id
  1359. String other_user_id
  1360. group_id = get_group_id(group_name)
  1361. if (group_id != ""):
  1362. if (allow_group_modify(current_user_id, group_id)):
  1363. other_user_id = get_user_id(other_user_name)
  1364. if (other_user_id != ""):
  1365. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1366. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1367. Element overlap
  1368. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "owner"), allOutgoingAssociationInstances(core, other_user_id, "owner"))
  1369. model_delete_element(core, set_pop(overlap))
  1370. return "Success"!
  1371. else:
  1372. return "User is not an owner of the group!"!
  1373. else:
  1374. return "User is not a member of the group!"!
  1375. else:
  1376. return "User not found: " + other_user_name!
  1377. else:
  1378. return "Permission denied to group: " + group_name!
  1379. else:
  1380. return "Group not found: " + group_name!
  1381. String function cmd_group_join(group_name : String, other_user_name : String):
  1382. // Add someone to your group
  1383. String group_id
  1384. String other_user_id
  1385. group_id = get_group_id(group_name)
  1386. if (group_id != ""):
  1387. if (allow_group_modify(current_user_id, group_id)):
  1388. other_user_id = get_user_id(other_user_name)
  1389. if (other_user_id != ""):
  1390. if (set_in(allOutgoingAssociationInstances(core, other_user_id, "belongsTo"), group_id)):
  1391. instantiate_link(core, "belongsTo", "", other_user_id, group_id)
  1392. return "Success"!
  1393. else:
  1394. return "User is already a member of the group!"!
  1395. else:
  1396. return "User not found: " + other_user_name!
  1397. else:
  1398. return "Permission denied to group: " + group_name!
  1399. else:
  1400. return "Group not found: " + group_name!
  1401. String function cmd_group_kick(group_name : String, other_user_name : String):
  1402. // Remove someone from your group
  1403. String group_id
  1404. String other_user_id
  1405. group_id = get_group_id(group_name)
  1406. if (group_id != ""):
  1407. if (allow_group_modify(current_user_id, group_id)):
  1408. other_user_id = get_user_id(other_user_name)
  1409. if (other_user_id != ""):
  1410. Element overlap
  1411. if (set_in(allAssociationDestinations(core, other_user_id, "belongsTo"), group_id)):
  1412. overlap = set_overlap(allIncomingAssociationInstances(core, group_id, "belongsTo"), allOutgoingAssociationInstances(core, other_user_id, "belongsTo"))
  1413. model_delete_element(core,set_pop(overlap))
  1414. // Check if user was an owner as well
  1415. if (set_in(allAssociationDestinations(core, group_id, "owner"), other_user_id)):
  1416. overlap = set_overlap(allIncomingAssociationInstances(core, other_user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  1417. model_delete_element(core, set_pop(overlap))
  1418. return "Success"!
  1419. else:
  1420. return "User is not a member of the group!"!
  1421. else:
  1422. return "User not found: " + other_user_name!
  1423. else:
  1424. return "Permission denied to group: " + group_name!
  1425. else:
  1426. return "Group not found: " + group_name!
  1427. String function cmd_group_list():
  1428. // List all groups you are a member of (and whether you are admin or not!)
  1429. Element groups
  1430. String group_id
  1431. String admin
  1432. String result
  1433. result = ""
  1434. groups = allAssociationDestinations(core, current_user_id, "belongsTo")
  1435. while (set_len(groups) > 0):
  1436. group_id = set_pop(groups)
  1437. if (set_in(allAssociationDestinations(core, group_id, "owner"), current_user_id)):
  1438. admin = " A "
  1439. else:
  1440. admin = " "
  1441. result = result + (string_join(admin, read_attribute(core, group_id, "name")) + "\n")
  1442. return result!
  1443. String function cmd_admin_promote(other_user_name : String):
  1444. // Promote a user to admin status
  1445. if (is_admin(current_user_id)):
  1446. String other_user_id
  1447. other_user_id = get_user_id(other_user_name)
  1448. if (other_user_id != ""):
  1449. unset_attribute(core, other_user_id, "admin")
  1450. instantiate_attribute(core, other_user_id, "admin", True)
  1451. return "Success"!
  1452. else:
  1453. return "User not found: " + other_user_name!
  1454. else:
  1455. return "Permission denied to administrate: " + other_user_name!
  1456. String function cmd_admin_demote(other_user_name : String):
  1457. // Demote a user to normal status
  1458. if (is_admin(current_user_id)):
  1459. String other_user_id
  1460. other_user_id = get_user_id(other_user_name)
  1461. if (other_user_id != ""):
  1462. unset_attribute(core, other_user_id, "admin")
  1463. instantiate_attribute(core, other_user_id, "admin", False)
  1464. return "Success"!
  1465. else:
  1466. return "User not found: " + other_user_name!
  1467. else:
  1468. return "Permission denied to administrate: " + other_user_name!
  1469. String function cmd_service_register(service_name : String):
  1470. // Active a service for this specific user
  1471. if (get_service_id(service_name) == ""):
  1472. String service
  1473. service = instantiate_node(core, "Service", "")
  1474. instantiate_attribute(core, service, "name", service_name)
  1475. instantiate_attribute(core, service, "port", get_taskname())
  1476. output("Success: " + get_taskname())
  1477. // Wait until we can stop the service
  1478. log("Waiting for service_stop")
  1479. while (cast_v2s(input()) != "\"service_stop\""):
  1480. output("Service is running on this task: stop it by sending 'service_stop'")
  1481. log("Finished")
  1482. model_delete_element(core, service)
  1483. // Service terminated
  1484. return "Success"!
  1485. else:
  1486. return "Service already exists: " + service_name!
  1487. String function cmd_user_password(user_name : String, new_password : String):
  1488. if (bool_or(current_user_id == get_user_id(user_name), is_admin(current_user_id))):
  1489. if (get_user_id(user_name) != ""):
  1490. instantiate_attribute(core, get_user_id(user_name), "password", hash(new_password))
  1491. return "Success"!
  1492. else:
  1493. return "No such user: " + user_name!
  1494. else:
  1495. return "Permission denied to user: " + user_name!
  1496. String function cmd_transformation_signature(transformation_name : String):
  1497. String model_id
  1498. model_id = get_model_id(transformation_name)
  1499. if (model_id != ""):
  1500. if (is_nominal_instance(core, model_id, "Transformation")):
  1501. if (allow_read(current_user_id, transformation_name)):
  1502. String result
  1503. String elem
  1504. Element inputs
  1505. Element outputs
  1506. result = "Success: "
  1507. inputs = allOutgoingAssociationInstances(core, model_id, "transformInput")
  1508. while (set_len(inputs) > 0):
  1509. elem = set_pop(inputs)
  1510. result = string_join(string_join(string_join(string_join("I ", read_attribute(core, elem, "name")), " "), read_attribute(core, readAssociationDestination(core, elem), "name")), "\n")
  1511. outputs = allOutgoingAssociationInstances(core, model_id, "transformOutput")
  1512. while (set_len(outputs) > 0):
  1513. elem = set_pop(outputs)
  1514. result = string_join(string_join(string_join(string_join("O ", read_attribute(core, elem, "name")), " "), read_attribute(core, readAssociationDestination(core, elem), "name")), "\n")
  1515. return result!
  1516. else:
  1517. return "Permission denied to transformation: " + transformation_name!
  1518. else:
  1519. return "Model is not a transformation: " + transformation_name!
  1520. else:
  1521. return "No such transformation: " + transformation_name!
  1522. String function cmd_element_list_nice(model_name : String, metamodel_name : String):
  1523. if (get_model_id(model_name) != ""):
  1524. if (allow_read(current_user_id, get_model_id(model_name))):
  1525. Element mm
  1526. mm = get_full_model(get_model_id(model_name), get_model_id(metamodel_name))
  1527. if (element_eq(mm, read_root())):
  1528. return "No conformance relation between these models"!
  1529. return "Success: " + JSON_print(mm)!
  1530. else:
  1531. return "Permission denied to model: " + model_name!
  1532. else:
  1533. return "No such model: " + model_name!
  1534. Void function user_function_skip_init(user_id : String):
  1535. String cmd
  1536. String result
  1537. caches = dict_create()
  1538. dict_add_fast(caches, "models", dict_create())
  1539. dict_add_fast(caches, "users", dict_create())
  1540. current_user_id = user_id
  1541. output("Welcome to the Model Management Interface v2.0!")
  1542. output("Use the 'help' command for a list of possible commands")
  1543. while (True):
  1544. cmd = input()
  1545. if (cmd == "help"):
  1546. output(cmd_help())
  1547. elif (cmd == "model_add"):
  1548. output(cmd_model_add(single_input("Model type?"), single_input("Model name?")))
  1549. elif (cmd == "process_execute"):
  1550. output(cmd_process_execute(single_input("Process to execute?"), single_input("Model prefix to use?")))
  1551. elif (cmd == "transformation_between"):
  1552. output(cmd_transformation_between(single_input("Source type?"), single_input("Target type?")))
  1553. elif (cmd == "model_render"):
  1554. output(cmd_model_render(single_input("Model name?"), single_input("Mapper name?")))
  1555. elif (cmd == "transformation_execute"):
  1556. output(cmd_transformation_execute(single_input("Transformation name?"), dict_input("Source models?"), dict_input("Target models?")))
  1557. elif (cmd == "verify"):
  1558. result = cmd_verify(single_input("Model name?"), single_input("Metamodel name?"))
  1559. if (result != ""):
  1560. output(result)
  1561. elif (cmd == "model_overwrite"):
  1562. output(cmd_model_overwrite(single_input("Model name?"), single_input("Metamodel name?")))
  1563. elif (cmd == "model_modify"):
  1564. output(cmd_model_modify(single_input("Model name?"), single_input("Metamodel name?")))
  1565. elif (cmd == "model_delete"):
  1566. output(cmd_model_delete(single_input("Model name?")))
  1567. elif (cmd == "model_list"):
  1568. output(cmd_model_list())
  1569. elif (cmd == "model_list_full"):
  1570. output(cmd_model_list_full())
  1571. elif (cmd == "transformation_add_MANUAL"):
  1572. output(cmd_transformation_add_MANUAL(dict_input("Source model names?"), dict_input("Target model names?"), single_input("Operation name?")))
  1573. elif (cmd == "transformation_add_AL"):
  1574. output(cmd_transformation_add_AL(dict_input("Source model names?"), dict_input("Target model names?"), single_input("Operation name?")))
  1575. elif (cmd == "transformation_add_MT"):
  1576. output(cmd_transformation_add_MT(dict_input("Source model names?"), dict_input("Target models?"), single_input("Operation name?")))
  1577. elif (cmd == "transformation_list"):
  1578. output(cmd_transformation_list())
  1579. elif (cmd == "transformation_list_full"):
  1580. output(cmd_transformation_list_full())
  1581. elif (cmd == "permission_modify"):
  1582. output(cmd_permission_modify(single_input("Model name?"), single_input("Permissions?")))
  1583. elif (cmd == "permission_owner"):
  1584. output(cmd_permission_owner(single_input("Model name?"), single_input("New owning user?")))
  1585. elif (cmd == "permission_group"):
  1586. output(cmd_permission_group(single_input("Model name?"), single_input("New owning group?")))
  1587. elif (cmd == "group_create"):
  1588. output(cmd_group_create(single_input("New group name?")))
  1589. elif (cmd == "group_delete"):
  1590. output(cmd_group_delete(single_input("Group name?")))
  1591. elif (cmd == "group_owner_add"):
  1592. output(cmd_group_owner_add(single_input("Group name?"), single_input("User name?")))
  1593. elif (cmd == "group_owner_delete"):
  1594. output(cmd_group_owner_delete(single_input("Group name?"), single_input("User name?")))
  1595. elif (cmd == "group_join"):
  1596. output(cmd_group_join(single_input("Group name?"), single_input("User name?")))
  1597. elif (cmd == "group_kick"):
  1598. output(cmd_group_kick(single_input("Group name?"), single_input("User name?")))
  1599. elif (cmd == "group_list"):
  1600. output(cmd_group_list())
  1601. elif (cmd == "admin_promote"):
  1602. output(cmd_admin_promote(single_input("User name?")))
  1603. elif (cmd == "admin_demote"):
  1604. output(cmd_admin_demote(single_input("User name?")))
  1605. elif (cmd == "service_register"):
  1606. output(cmd_service_register(single_input("Service name?")))
  1607. elif (cmd == "user_password"):
  1608. output(cmd_user_password(single_input("User name?"), single_input("New password?")))
  1609. elif (cmd == "transformation_read_signature"):
  1610. output(cmd_transformation_signature(single_input("Transformation name?")))
  1611. elif (cmd == "element_list_nice"):
  1612. output(cmd_element_list_nice(single_input("Model name?"), single_input("Metamodel name?")))
  1613. elif (cmd == "verbose"):
  1614. set_verbose(True)
  1615. elif (cmd == "quiet"):
  1616. set_verbose(False)
  1617. elif (cmd == "self-destruct"):
  1618. // Delete user from Core Formalism
  1619. model_delete_element(core, user_id)
  1620. return !
  1621. elif (cmd == "exit"):
  1622. // Exit by actually removing the user and decoupling it from all of its models
  1623. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  1624. // as the current user will have been deleted
  1625. return !
  1626. elif (cmd == "add_conformance"):
  1627. // TODO
  1628. cmd = "FAIL"
  1629. elif (cmd == "remove_conformance"):
  1630. // TODO
  1631. cmd = "FAIL"
  1632. elif (cmd == "user_name"):
  1633. // TODO
  1634. cmd = "FAIL"
  1635. elif (cmd == "service_poll"):
  1636. // TODO
  1637. cmd = "FAIL"
  1638. else:
  1639. output("Unknown command: " + cmd)
  1640. // We never get here!
  1641. return !