core_algorithm.alc 70 KB

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