core_algorithm.alc 72 KB

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