core_algorithm.alc 69 KB

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