Advertisement
munnie91

disco

Dec 17th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. layer exercise is
  2. class user is
  3. role: (unregistered, registered, bookshop_owner, admin);
  4. extend bookshop_owner by
  5. own_store: reference bookstore;
  6. end;
  7. is_super_admin:(no, yes);
  8. end;
  9.  
  10. class bookstore is
  11. added: (no, yes);
  12. end;
  13.  
  14. class book is
  15. state: (free, added, is_in_cart, sold);
  16.  
  17. extend is_in_cart by
  18. in_cart: reference cart;
  19. end;
  20. extend sold by
  21. sold_user: reference user;
  22. end;
  23.  
  24. in_store: reference bookstore;
  25. end;
  26.  
  27. class cart is
  28. assigned: (no, yes);
  29. extend yes by
  30. owner: reference user;
  31. end;
  32. end;
  33.  
  34. relation user_own_cart (user, cart) is 0..1: 0..1;
  35.  
  36. --action for all user
  37. action user_browse(u: user) is
  38. when true do
  39. end;
  40.  
  41. action user_seacrh(u: user) is
  42. when true do
  43. end;
  44.  
  45. --user register / unregister from system
  46.  
  47. action user_register(u: user; c: cart) is
  48. when u.role'unregistered and c.assigned'no do
  49. u.role -> registered()||
  50. c.assigned -> yes(owner := u)||
  51. user_own_cart(u,c)
  52. ;
  53. end;
  54.  
  55. action registered_user_unregister(u: user; c: cart) is
  56. when u.role'registered and user_own_cart(u,c) do
  57. u.role -> unregistered()||
  58. c.assigned -> no()||
  59. not user_own_cart(u,c)
  60. ;
  61. end;
  62.  
  63. action unregisterd_owner(u: user) is
  64. when (u.role'bookshop_owner) do
  65. u.role -> unregistered();
  66. end;
  67.  
  68. action unregisterd_admin(u: user) is
  69. when (u.role'admin and not u.is_super_admin'yes) do
  70. u.role -> unregistered();
  71. end;
  72.  
  73. --admin change role
  74. --change to unregistered
  75. action admin_unregisterd_registered_user(a: user; u: user; c: cart) is
  76. when (a.role'admin and u.role'registered and user_own_cart(u,c)) do
  77. u.role -> unregistered()||
  78. c.assigned -> no()||
  79. not user_own_cart(u,c)
  80. ;
  81. end;
  82.  
  83. action admin_unregisterd_owner(a: user; u: user) is
  84. when (a.role'admin and u.role'bookshop_owner ) do
  85. u.role -> unregistered();
  86. end;
  87.  
  88. action admin_unregisterd_admin(a: user; u: user) is
  89. when (a.role'admin and u.role'admin and not u.is_super_admin'yes) do
  90. u.role -> unregistered();
  91. end;
  92.  
  93. --change to registered
  94. action admin_change_admin_to_registered(a: user; u:user; c:cart) is
  95. when (a.role'admin and u.role'admin and c.assigned'no and not u.is_super_admin'yes) do
  96. u.role -> registered()||
  97. c.assigned -> yes(owner := u)||
  98. user_own_cart(u,c)
  99. ;
  100. end;
  101.  
  102. action admin_change_owner_to_registered(a: user; u: user; c:cart) is
  103. when (a.role'admin and u.role'bookshop_owner and c.assigned'no) do
  104. u.role -> registered()||
  105. c.assigned -> yes(owner := u)||
  106. user_own_cart(u,c)
  107. ;
  108. end;
  109.  
  110. --change to owner
  111. action admin_change_registered_to_owner(a: user; u: user; s: bookstore; c:cart) is
  112. when (a.role'admin and u.role'registered and user_own_cart(u,c) and s.added'yes) do
  113. u.role -> bookshop_owner(own_store := s)||
  114. c.assigned -> no()||
  115. not user_own_cart(u,c)
  116. ;
  117. end;
  118.  
  119. action admin_change_admin_to_owner(a: user; u:user; s: bookstore) is
  120. when (a.role'admin and u.role'admin and s.added'yes and not u.is_super_admin'yes) do
  121. u.role -> bookshop_owner(own_store := s);
  122. end;
  123.  
  124. --change to admin
  125. action admin_change_registered_to_admin(a: user; u: user; c:cart) is
  126. when (a.role'admin and u.role'registered and user_own_cart(u,c)) do
  127. u.role -> admin()||
  128. c.assigned -> no()||
  129. not user_own_cart(u,c)
  130. ;
  131. end;
  132.  
  133. action admin_change_owner_to_admin(a: user; u: user) is
  134. when (a.role'admin and u.role'bookshop_owner) do
  135. u.role -> admin();
  136. end;
  137.  
  138. --admin add store
  139. action admin_add_store(a: user; s: bookstore) is
  140. when (a.role'admin and s.added'no) do
  141. s.added -> yes();
  142. end;
  143.  
  144. -- owner add/remove books
  145. action owner_add_book(o: user; s: bookstore; b: book) is
  146. when (o.role'bookshop_owner.own_store = s and b.state'free) do
  147. b.state -> added() ||
  148. b.in_store := s;
  149. end;
  150.  
  151. action owner_remove_book(o: user; s: bookstore; b: book) is
  152. when (o.role'bookshop_owner.own_store = s and b.state'added and b.in_store = s) do
  153. b.state -> free() ||
  154. b.in_store := null;
  155. end;
  156.  
  157. -- add/remove book from cart
  158. action user_add_book_to_cart(u: user; c: cart; b: book) is
  159. when u.role'registered and user_own_cart(u,c) and b.state'added do
  160. b.state -> is_in_cart(in_cart := c);
  161. end;
  162.  
  163. action user_remove_book_from_cart(u: user; c: cart; b: book) is
  164. when u.role'registered and user_own_cart(u,c) and b.state'is_in_cart.in_cart = c do
  165. b.state -> added();
  166. end;
  167.  
  168. action admin_remove_book_from_cart(u: user; c: cart; b: book) is
  169. when u.role'admin and b.state'is_in_cart.in_cart = c do
  170. b.state -> added();
  171. end;
  172.  
  173. action user_pay_for_book_in_cart(u: user; c: cart; b: book) is
  174. when u.role'registered and user_own_cart(u,c) and b.state'is_in_cart.in_cart = c do
  175. b.state -> sold(sold_user := u);
  176. end;
  177. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement