core_algorithm.alc 69 KB

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