core_algorithm.alc 70 KB

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