aboutsummaryrefslogtreecommitdiffstats
path: root/Tests/MODELS2020-CaseStudies/case.study.pledge.run/bin/queries/case_study_A.vql
blob: 01cdf372412ba0b98ce31854c7d53e2396dfdd3c (plain) (blame)
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
package queries
 
import "http:///TaxCard.ecore" 

//AttributeRemoved -> DF

//inv1-External_Allowance.amount is a derived feature (TODOcheck)
//inv2-Tax_Card.income.taxPayer.taxesDue is a derived feature (TODOcheck)

//inv3-multiplicity adjusted
@Constraint(message = "inv03", severity = "error", key = {dep})
pattern inv03(dep : Dependent) {
    find x_inv03_eligAll(dep);
    neg find x_inv03_hasAll(dep);
} or {
	Dependent.birth_year(dep, by);
    check(2018-by > 21);
	Dependent.continued_studies(dep, false);
    Dependent.allowances(dep, _);
}
pattern x_inv03_eligAll(dep : Dependent) {
    Dependent.birth_year(dep, by);
    check(2018-by <= 21);
} or {
	Dependent.continued_studies(dep, true);
}
pattern x_inv03_hasAll(dep : Dependent) {
    Dependent.allowances(dep, _);
}

//inv5 - oclIsTypeOf - handled here
@Constraint(message = "inv05", severity = "error", key = {inc})
pattern inv05(inc : Income) {
	//income_type: None
    neg find x_inv08_noType(inc);
    Income.details.worked_days(inc, wd);
    check(wd != 0);
} or {
	//income_type: Not Employment_Income
    Income.income_type(inc, type);
    neg find x_inv08_notEI(type);
    Income.details.worked_days(inc, wd);
    check(wd != 0);
} or {
	//income_type: Employment Income
	Income.income_type(inc, type);
    Employment_Income(type);
    find x_inv05_inRange(inc);
}
pattern x_inv05_inRange(inc : Income) {
    Income.details.worked_days(inc, wd);
    check(wd < 1);
} or {
    Income.details.worked_days(inc, wd);
    check(wd > 25);
}

//inv6-Does not make sens, but directly from OCL
//first part of or from definition of getAge()
@Constraint(message = "inv06", severity = "error", key = {tp})
pattern inv06(tp : Tax_Payer) {
    Tax_Payer.dependents(tp, _);
	Tax_Payer.birth_year(tp, TPBy);
	check(2018 - TPBy > 2018-16);
} or {
	Tax_Payer.birth_year(tp, TPBy);
    Tax_Payer.dependents(tp, dep);
    Dependent.birth_year(dep, DepBy);
    check(2018-DepBy <= 2018-TPBy-16);
}

//inv7-OrderedSet
@Constraint(message = "inv07", severity = "error", key = {inc})
pattern inv07(inc : Income) {
	Income.details.distance(inc, d1);
	Income.details.distance(inc, d2);
	check(d1 != d2);//compare values
}

//user_complete_details-AttributeRemoved

//inv8 - oclIsTypeOf - handled here
@Constraint(message = "inv08", severity = "error", key = {inc})
pattern inv08(inc : Income) {
	//income_type: None
    neg find x_inv08_noType(inc);
    Income.details.distance(inc, dist);
    check(dist != 0);
} or {
	//income_type: Not Employment_Income
    Income.income_type(inc, type);
    neg find x_inv08_notEI(type);
    Income.details.distance(inc, dist);
    check(dist != 0);
} or {
	//income_type: Employment Income
	Income.income_type(inc, type);
    Employment_Income(type);
    find x_inv08_inRange(inc);
}
pattern x_inv08_notEI(type : Employment_Income) {
    Employment_Income(type);
}
pattern x_inv08_noType(inc : Income) {
    Income.income_type(inc, _);
}
pattern x_inv08_inRange(inc : Income) {
    Income.details.distance(inc, dist);
    check(dist < 0);
} or {
    Income.details.distance(inc, dist);
    check(dist > 100);
}
//inv9-DerivedFeature

//inv10-Ordered Sets
@Constraint(message = "inv10", severity = "error", key = {inc})
pattern inv10(inc : Income) {
	Income.details.amount(inc, a1);
	Income.details.amount(inc, a2);
	check(a1 != a2);//compare values
}

//inv11-attributes-handled by multiplicity
@Constraint(message = "inv11", severity = "error", key = {exp})
pattern inv11(exp : Expense) {
    find x_inv11_incOver100(exp);
    find x_inv11_incNotOver100(exp);
}
pattern x_inv11_incOver100(exp : Expense) {
    Expense.income.income_amount(exp, incVal);
    check(incVal / 2 > 50);

} or {
	Expense.declared_amount(exp, decl);
    check(decl != 50);
}
pattern x_inv11_incNotOver100(exp : Expense) {
    Expense.income.income_amount(exp, incVal);
    check(incVal / 2 <= 50);
} or {
	Expense.declared_amount(exp, decl);
    check(decl < 50);
} or {
	Expense.income.income_amount(exp, incVal);
	Expense.declared_amount(exp, decl);
	check(decl > incVal/2);
}

//inv12
//exists - handled logically
@Constraint(message = "inv12", severity = "error", key = {tp})
pattern inv12(tp : Tax_Payer) {
    Tax_Payer.addresses(tp, hab_add);
    Habitual_Address(hab_add);
    neg find x_inv12_notZZ(hab_add);
    Tax_Payer.incomes(tp, inc);
    Local_Income(inc);
    neg find x_inv12_notNonRes(tp);
}
pattern x_inv12_notNonRes(tp : Non_Resident_Tax_Payer) {
    Non_Resident_Tax_Payer(tp);
}
pattern x_inv12_notZZ(hab_add : Habitual_Address) {
    Address.country(hab_add, ::ZZ);
}

//inv13 - Added new containment rel Phys_Pers->Address
//exists - handled logically
@Constraint(message = "inv13", severity = "error", key = {tp})
pattern inv13(tp : Tax_Payer) {
    Tax_Payer.addresses(tp, hab_add);
    Habitual_Address(hab_add);
    Address.country(hab_add, ::ZZ);
    neg find x_inv13(tp);
}
pattern x_inv13(tp : Resident_Tax_Payer) {
    Resident_Tax_Payer(tp);
}

//inv14-MultiplicityChanged

//inv15-Ordered Sets in assignment if block
//ERROR if no household object
@Constraint(message = "inv15", severity = "error", key = {ea})
pattern inv15(ea : External_Allowance) {
	neg find x_inv15(ea);
}
pattern x_inv15(ea : External_Allowance) {
    External_Allowance.person(ea, child);
    Household.children(h, child);//only one due to multiplicity
    Household.parents.individual_A(h, iA);
    Tax_Payer(iA);
    External_Allowance.reciver(ea, iA);
} or {
    External_Allowance.person(ea, child);
    Household.children(h, child);//only one due to multiplicity
    Household.parents.individual_B(h, iB);
    Tax_Payer(iB);
    External_Allowance.reciver(ea, iB);
}

//inv16-Tax_Card.tax_card_type is a derived feature

//inv17-attribute-handled by multiplicity
@Constraint(message = "inv17", severity = "error", key = {lur})
pattern inv17(lur : Legal_Union_Record) {
    Legal_Union_Record.start_year(lur, sy);
    check(sy < 1950);
} or {
	Legal_Union_Record.start_year(lur, sy);
	check(sy > 2018);
}

//inv18-MultiplicityChecked
//inv19-MultiplicityChecked

//inv20-Useless constraint since both edges are containment (TODOCheck)
//OclIsUndefined-Handled by multiplicity
@Constraint(message = "inv20", severity = "error", key = {lur})
pattern inv20(lur : Legal_Union_Record) {
    Legal_Union_Record.individual_A(lur, iA);
    Legal_Union_Record.individual_B(lur, iB);
    iA == iB;
}
//inv21-MultiplicityChecked
//inv22-MultiplicityChecked
//inv23-MultiplicityChecked
//inv24-MultiplicityChecked
//inv25-MultiplicityChecked
//inv26-MultiplicityChanged
//inv27-dupOfInv24
//inv28-dubOfInv23
//inv29-MultiplicityChanged
//inv30-AttributeRemoved
//inv31-AttributeRemoved
//inv32-AttributeRemoved

//inv33-attribute-handled by multiplicity
@Constraint(message = "inv33", severity = "error", key = {p})
pattern inv33(p : Physical_Person) {
	Physical_Person.birth_year(p, by); 
	check(2018-by < 0);
} or {
	Physical_Person.birth_year(p, by); 
	check(2018-by > 100);
}

//inv34-attribute-handled by multiplicity
@Constraint(message = "inv34", severity = "error", key = {p})
pattern inv34(p : Physical_Person) {
    Physical_Person.birth_month(p, birthMonth);
    check(birthMonth < 1);    
} or {
	Physical_Person.birth_month(p, birthMonth);
    check(birthMonth > 12);
}

//inv35-attribute-handled by multiplicity
@Constraint(message = "inv35", severity = "error", key = {p})
pattern inv35(p : Physical_Person) {
    Physical_Person.birth_day(p, birthDay);
    check(birthDay < 1);    
} or {
	Physical_Person.birth_day(p, birthDay);
    check(birthDay > 28);
}

//inv36-AttributeRemoved
//inv37-AttributeRemoved
//inv38-AttributeRemoved
//inv39-AttributeRemoved
//inv40-AttributeRemoved
//inv41-AttributeRemoved
//inv42-AttributeRemoved
//inv43-AttributeRemoved
//inv44-AttributeRemoved
//inv45-AttributeRemoved
//inv46-AttributeRemoved

//inv47-attributes-handled by multiplicity
@Constraint(message = "inv47", severity = "error", key = {lur})
pattern inv47(lur : Legal_Union_Record) {
    Legal_Union_Record.end_year(lur, endY);
    Legal_Union_Record.start_year(lur, startY);
    neg find x_inv47(lur);
    check(startY >= endY);
} or {
	Legal_Union_Record.end_year(lur, endY);
    Legal_Union_Record.start_year(lur, startY);
    check(endY!= -1);
    check(startY >= endY);
}
pattern x_inv47(lur : Legal_Union_Record) {
    Legal_Union_Record.separation_cause(lur, ::NONE);
}

//inv48-attributes-handled by multiplicity
@Constraint(message = "inv48", severity = "error", key = {p})
pattern inv48(p : Physical_Person) {
   Physical_Person.disability_percentage(p, disPer);
   check(disPer > 1.0);
} or {
   Physical_Person.disability_percentage(p, disPer);
   check(disPer < 0.0);
} or {
   Physical_Person.disability_type(p, ::NONE);
   Physical_Person.disability_percentage(p, disPer);
   check(disPer != 0.0);
} or {
  neg find x_inv48(p);
  Physical_Person.disability_percentage(p, disPer);
  check(disPer == 0.0);
}
pattern x_inv48(p : Physical_Person) {
    Physical_Person.disability_type(p, ::NONE);
}

//inv49-OclKindOf-handled by multiplicity
@Constraint(message = "inv49", severity = "error", key = {lur})
pattern inv49(lur : Legal_Union_Record) {
    neg find x_inv49_1(lur);
}
pattern x_inv49_1(lur : Legal_Union_Record) {
	Legal_Union_Record.individual_A(lur, iA);
	Legal_Union_Record.individual_B(lur, iB);
    Tax_Payer(iA);
    Physical_Person(iB);
    neg find x_inv49_2(iB);
    iA != iB;
}
pattern x_inv49_2(iB: Dependent) {
    Dependent(iB);
}

//inv50-MultiplicityChecked
//inv51-MultiplicityChecked
//inv52-MultiplicityChecked
//inv53-MultiplicityChecked