-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoicingOrders.ocl
165 lines (132 loc) · 5.69 KB
/
InvoicingOrders.ocl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
-- Copyright (c) 2003-2007 ETH Zurich, Switzerland
-- 2016 The University of Sheffield, UK
--
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- * Redistributions of source code must retain the above copyright notice, this
-- list of conditions and the following disclaimer.
--
-- * Redistributions in binary form must reproduce the above copyright notice,
-- this list of conditions and the following disclaimer in the documentation
-- and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--
-- SPDX-License-Identifier: BSD-2-Clause
--
------------------------------------------
-- Case 1
------------------------------------------
package InvoicingOrders
--
-- 1) Constraining the Data Model
-- ==============================
-- The stock of a Product is always a natural number, i.e., it is a
-- positive Integer. This also ensures the definedness of the stock.
context Product
inv isNat: self.stock >= 0
-- The Product id is unique.
context Product
inv idUnique: Product::allInstances()
->forAll(p1:Product, p2:Product | p1.id <> p2.id)
-- The quantity of an Order is always a natural number, i.e., it is
-- a positive Integer. This also ensures the definedness of the
-- quantity.
context Order
inv isNat: self.quantity >= 0
-- The state of an Order should either be `pending' or `invoiced'.
-- As a direct support for enumeration is not well developed in most
-- CASE tools, we use a String and constrain it to the two
-- alternatives using an invariant.
context Order
inv stateRange: (self.state = 'pending')
or (self.state = 'invoiced')
-- The Order id is unique.
context Order
inv idUnique: Order::allInstances()
->forAll(o1:Order, o2:Order | o1.id <> o2.id)
--
-- 2) Constraining the Dynamic Part
-- ================================
-- Initialize the state of an Order
context Order::state : String
init: 'pending'
-- Create a new Order
context Order::Order(prd:Product, qty:Integer):OclVoid
pre: qty > 0
pre: self.warehouse.products->exists(x:Product | x = prd)
pre: not prd.oclIsUndefined()
post: self.oclIsNew() and self.quantity = qty
-- and self.orderedProduct = prd
-- The state of the order will be changed into "invoiced" if the ordered quantity
-- is either less or equal to the quantity which is in stock according to the
-- reference of the ordered product.
context Order::invoice() : Boolean
pre: self.state = 'pending'
-- and self.quantity <= self.orderedProduct.stock
post: self.state = 'invoiced' and self.quantity = self.quantity@pre
-- and self.orderedProduct = self.orderedProduct@pre
-- and self.orderedProduct.stock = [email protected] - self.quantity
-- Cancel order as an opposite operation to invoice order
context Order::cancel() : Boolean
pre: self.state = 'invoiced'
post: self.state = 'pending'
and self.quantity = self.quantity@pre and self.product = self.product@pre
and self.product.stock = [email protected] + [email protected]
-- Create a new Order
context Product::Product():Boolean
pre : true
post: self.stock = 0 and self.oclIsNew()
-- Add quantity of the product to the stock
context Product::supply(qty:Integer):Boolean
pre: qty > 0
post: self.stock = self.stock@pre + qty
-- Remove quantity of the product from the stock
context Product::release(qty:Integer):Boolean
pre: self.stock >= qty
post: self.stock = self.stock@pre - qty
endpackage
-- ------------------------------------------
-- -- Case 2
-- ------------------------------------------
package InvoicingOrders
--
-- 1) Constraining the Data Model
-- ==============================
-- First, we present several invariants on the static data model. These
-- type constraints
-- There is one and only one Warehouse.
context Warehouse
inv isStatic: self.allInstances()->size() = 1
-- All products are in the Warehouse.
context Product
inv isInWarehouse :
not self.warehouse.oclIsUndefined()
-- -- All orders are in the Warehouse.
context Order
inv isInWarehouse: not self.warehouse.oclIsUndefined()
--
-- 2) Constraining the Dynamic Part
-- ================================
-- Create a new Order
context Order::Order(prd:Product,qty:Integer):OclVoid
pre: self.warehouse.products->exists(x:Product | x = prd)
-- Warehouse management
-- context Warehouse::getFirstInvoicable():Order
-- pre: self.orders->exists(x:Order |
-- x.state = 'pending' and x.quantity <= x.product.stock)
-- body: self.orders->any(x:Order |
-- x.state = 'pending' and x.quantity <= x.product.stock)
endpackage