core_algorithm.alc 69 KB

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