/examples/restbuck_server/src/domain/order.e

http://github.com/jocelyn/EiffelWebReloaded · Specman e · 104 lines · 88 code · 13 blank · 3 comment · 2 complexity · e4380cf83624c3f80c4cd4c251ba9f44 MD5 · raw file

  1. note
  2. description: "Summary description for {ORDER}."
  3. author: ""
  4. date: "$Date$"
  5. revision: "$Revision$"
  6. class
  7. ORDER
  8. create
  9. make
  10. feature -- Initialization
  11. make ( an_id : STRING; a_location:STRING)
  12. do
  13. create {ARRAYED_LIST[ITEM]}items.make (10)
  14. set_id(an_id)
  15. set_location(a_location)
  16. status:="submitted"
  17. ensure
  18. order_created: is_valid_status_states (status)
  19. end
  20. feature -- Access
  21. id : STRING
  22. location : STRING
  23. items: LIST[ITEM]
  24. status : STRING
  25. is_valid_status_states (a_status: STRING) : BOOLEAN
  26. --is `a_status' a valid coffee order state
  27. do
  28. a_status.to_lower
  29. Order_states.compare_objects
  30. Result := Order_states.has (a_status)
  31. end
  32. Order_states : ARRAY[STRING]
  33. -- List of valid status states
  34. once
  35. Result := <<"submitted","pay","payed", "cancel","canceled","prepare","prepared","deliver","completed">>
  36. end
  37. is_valid_transition (a_status : STRING) :BOOLEAN
  38. -- Given the correr order state, determine if the transition is valid
  39. do
  40. a_status.to_lower
  41. if status.same_string ("submitted") then
  42. Result := a_status.same_string ("pay") or a_status.same_string ("cancel")
  43. elseif status.same_string ("pay") then
  44. Result := a_status.same_string ("payed")
  45. elseif status.same_string ("cancel") then
  46. Result := a_status.same_string ("canceled")
  47. elseif status.same_string ("payed") then
  48. Result := a_status.same_string ("prepared")
  49. elseif status.same_string ("prepared") then
  50. Result := a_status.same_string ("deliver")
  51. elseif status.same_string ("deliver") then
  52. Result := a_status.same_string ("completed")
  53. end
  54. end
  55. feature -- element change
  56. set_id (an_id : STRING)
  57. require
  58. valid_id :an_id /= Void
  59. do
  60. id := an_id
  61. ensure
  62. id_assigned : id.same_string (an_id)
  63. end
  64. set_location (a_location : STRING)
  65. require
  66. valid_location: a_location /= Void
  67. do
  68. location := a_location
  69. ensure
  70. location_assigned : location.same_string (a_location)
  71. end
  72. set_status (a_status : STRING)
  73. require
  74. valid_status: a_status /= Void and then is_valid_status_states (a_status)
  75. valid_transition : is_valid_transition (a_status)
  76. do
  77. status := a_status
  78. ensure
  79. location_assigned : location.same_string (a_status)
  80. end
  81. add_item (a_item : ITEM)
  82. require
  83. valid_item: a_item /= Void
  84. do
  85. items.force (a_item)
  86. ensure
  87. has_item : items.has (a_item)
  88. end
  89. invariant
  90. order_in_valid_state: is_valid_status_states (status)
  91. end