core_algorithm.alc 69 KB

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