core_algorithm.alc 69 KB

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