2ac91e4e21b1265ad923f59329f25bbc4495f653
[policy/apex-pdp.git] /
1 {
2    "apexPolicyModel" : {
3       "key" : {
4          "name" : "MyFirstPolicyModel",
5          "version" : "0.0.1"
6       },
7       "keyInformation" : {
8          "key" : {
9             "name" : "MyFirstPolicyModel_KeyInfo",
10             "version" : "0.0.1"
11          },
12          "keyInfoMap" : {
13             "entry" : [ {
14                "key" : {
15                   "name" : "MorningBoozeCheck",
16                   "version" : "0.0.1"
17                },
18                "value" : {
19                   "key" : {
20                      "name" : "MorningBoozeCheck",
21                      "version" : "0.0.1"
22                   },
23                   "UUID" : "3351b0f4-cf06-4fa2-8823-edf67bd30223",
24                   "description" : "This task checks if the sales request is for an item that contains alcohol.\nIf the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised.\nIn this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-)"
25                }
26             }, {
27                "key" : {
28                   "name" : "MorningBoozeCheckAlt1",
29                   "version" : "0.0.1"
30                },
31                "value" : {
32                   "key" : {
33                      "name" : "MorningBoozeCheckAlt1",
34                      "version" : "0.0.1"
35                   },
36                   "UUID" : "bc6d90c9-c902-4686-afd3-925b30e39990",
37                   "description" : "This task checks if a sale request is for an item that is an alcoholic drink.\nIf the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.\nAlso alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.\nIn this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks"
38                }
39             }, {
40                "key" : {
41                   "name" : "MyFirstPolicy",
42                   "version" : "0.0.1"
43                },
44                "value" : {
45                   "key" : {
46                      "name" : "MyFirstPolicy",
47                      "version" : "0.0.1"
48                   },
49                   "UUID" : "6c5e410f-489a-46ff-964e-982ce6e8b6d0",
50                   "description" : "This is my first Apex policy. It checks if a sale should be authorised or not."
51                }
52             }, {
53                "key" : {
54                   "name" : "MyFirstPolicyModel",
55                   "version" : "0.0.1"
56                },
57                "value" : {
58                   "key" : {
59                      "name" : "MyFirstPolicyModel",
60                      "version" : "0.0.1"
61                   },
62                   "UUID" : "540226fb-55ee-4f0e-a444-983a0494818e",
63                   "description" : "This is my first Apex Policy Model."
64                }
65             }, {
66                "key" : {
67                   "name" : "MyFirstPolicyModel_Events",
68                   "version" : "0.0.1"
69                },
70                "value" : {
71                   "key" : {
72                      "name" : "MyFirstPolicyModel_Events",
73                      "version" : "0.0.1"
74                   },
75                   "UUID" : "ef281318-5ac9-3ef0-8db3-8f9c4e4a81e2",
76                   "description" : "Generated description for concept referred to by key \"MyFirstPolicyModel_Events:0.0.1\""
77                }
78             }, {
79                "key" : {
80                   "name" : "MyFirstPolicyModel_KeyInfo",
81                   "version" : "0.0.1"
82                },
83                "value" : {
84                   "key" : {
85                      "name" : "MyFirstPolicyModel_KeyInfo",
86                      "version" : "0.0.1"
87                   },
88                   "UUID" : "d9248c6f-7c00-38df-8251-611463ba4065",
89                   "description" : "Generated description for concept referred to by key \"MyFirstPolicyModel_KeyInfo:0.0.1\""
90                }
91             }, {
92                "key" : {
93                   "name" : "MyFirstPolicyModel_Policies",
94                   "version" : "0.0.1"
95                },
96                "value" : {
97                   "key" : {
98                      "name" : "MyFirstPolicyModel_Policies",
99                      "version" : "0.0.1"
100                   },
101                   "UUID" : "77c01a6b-510c-3aa9-b640-b4db356aa03b",
102                   "description" : "Generated description for concept referred to by key \"MyFirstPolicyModel_Policies:0.0.1\""
103                }
104             }, {
105                "key" : {
106                   "name" : "MyFirstPolicyModel_Schemas",
107                   "version" : "0.0.1"
108                },
109                "value" : {
110                   "key" : {
111                      "name" : "MyFirstPolicyModel_Schemas",
112                      "version" : "0.0.1"
113                   },
114                   "UUID" : "d0cc3aa0-ea69-3a43-80ff-a0dbb0ebd885",
115                   "description" : "Generated description for concept referred to by key \"MyFirstPolicyModel_Schemas:0.0.1\""
116                }
117             }, {
118                "key" : {
119                   "name" : "MyFirstPolicyModel_Tasks",
120                   "version" : "0.0.1"
121                },
122                "value" : {
123                   "key" : {
124                      "name" : "MyFirstPolicyModel_Tasks",
125                      "version" : "0.0.1"
126                   },
127                   "UUID" : "b02a7e02-2cd0-39e6-b3cb-946fa83a8f08",
128                   "description" : "Generated description for concept referred to by key \"MyFirstPolicyModel_Tasks:0.0.1\""
129                }
130             }, {
131                "key" : {
132                   "name" : "SALE_AUTH",
133                   "version" : "0.0.1"
134                },
135                "value" : {
136                   "key" : {
137                      "name" : "SALE_AUTH",
138                      "version" : "0.0.1"
139                   },
140                   "UUID" : "c4500941-3f98-4080-a9cc-5b9753ed050b",
141                   "description" : "An event emitted by the Policy to indicate whether the sale of an item has been authorised"
142                }
143             }, {
144                "key" : {
145                   "name" : "SALE_INPUT",
146                   "version" : "0.0.1"
147                },
148                "value" : {
149                   "key" : {
150                      "name" : "SALE_INPUT",
151                      "version" : "0.0.1"
152                   },
153                   "UUID" : "4f04aa98-e917-4f4a-882a-c75ba5a99374",
154                   "description" : "An event raised by the PoS system each time an item is scanned for purchase"
155                }
156             }, {
157                "key" : {
158                   "name" : "assistant_ID_type",
159                   "version" : "0.0.1"
160                },
161                "value" : {
162                   "key" : {
163                      "name" : "assistant_ID_type",
164                      "version" : "0.0.1"
165                   },
166                   "UUID" : "36df4c71-9616-4206-8b53-976a5cd4bd87",
167                   "description" : "A type for 'assistant_ID' values"
168                }
169             }, {
170                "key" : {
171                   "name" : "authorised_type",
172                   "version" : "0.0.1"
173                },
174                "value" : {
175                   "key" : {
176                      "name" : "authorised_type",
177                      "version" : "0.0.1"
178                   },
179                   "UUID" : "d48b619e-d00d-4008-b884-02d76ea4350b",
180                   "description" : "A type for 'authorised' values"
181                }
182             }, {
183                "key" : {
184                   "name" : "branch_ID_type",
185                   "version" : "0.0.1"
186                },
187                "value" : {
188                   "key" : {
189                      "name" : "branch_ID_type",
190                      "version" : "0.0.1"
191                   },
192                   "UUID" : "6468845f-4122-4128-8e49-0f52c26078b5",
193                   "description" : "A type for 'branch_ID' values"
194                }
195             }, {
196                "key" : {
197                   "name" : "item_ID_type",
198                   "version" : "0.0.1"
199                },
200                "value" : {
201                   "key" : {
202                      "name" : "item_ID_type",
203                      "version" : "0.0.1"
204                   },
205                   "UUID" : "4f227ff1-aee0-453a-b6b6-9a4b2e0da932",
206                   "description" : "A type for 'item_ID' values"
207                }
208             }, {
209                "key" : {
210                   "name" : "message_type",
211                   "version" : "0.0.1"
212                },
213                "value" : {
214                   "key" : {
215                      "name" : "message_type",
216                      "version" : "0.0.1"
217                   },
218                   "UUID" : "ad1431bb-3155-4e73-b5a3-b89bee498749",
219                   "description" : "A type for 'message' values"
220                }
221             }, {
222                "key" : {
223                   "name" : "notes_type",
224                   "version" : "0.0.1"
225                },
226                "value" : {
227                   "key" : {
228                      "name" : "notes_type",
229                      "version" : "0.0.1"
230                   },
231                   "UUID" : "eecfde90-896c-4343-8f9c-2603ced94e2d",
232                   "description" : "A type for 'notes' values"
233                }
234             }, {
235                "key" : {
236                   "name" : "price_type",
237                   "version" : "0.0.1"
238                },
239                "value" : {
240                   "key" : {
241                      "name" : "price_type",
242                      "version" : "0.0.1"
243                   },
244                   "UUID" : "52c2fc45-fd8c-463c-bd6f-d91b0554aea7",
245                   "description" : "A type for 'amount'/'price' values"
246                }
247             }, {
248                "key" : {
249                   "name" : "quantity_type",
250                   "version" : "0.0.1"
251                },
252                "value" : {
253                   "key" : {
254                      "name" : "quantity_type",
255                      "version" : "0.0.1"
256                   },
257                   "UUID" : "ac3d9842-80af-4a98-951c-bd79a431c613",
258                   "description" : "A type for 'quantity' values"
259                }
260             }, {
261                "key" : {
262                   "name" : "sale_ID_type",
263                   "version" : "0.0.1"
264                },
265                "value" : {
266                   "key" : {
267                      "name" : "sale_ID_type",
268                      "version" : "0.0.1"
269                   },
270                   "UUID" : "cca47d74-7754-4a61-b163-ca31f66b157b",
271                   "description" : "A type for 'sale_ID' values"
272                }
273             }, {
274                "key" : {
275                   "name" : "timestamp_type",
276                   "version" : "0.0.1"
277                },
278                "value" : {
279                   "key" : {
280                      "name" : "timestamp_type",
281                      "version" : "0.0.1"
282                   },
283                   "UUID" : "fd594e88-411d-4a94-b2be-697b3a0d7adf",
284                   "description" : "A type for 'time' values"
285                }
286             } ]
287          }
288       },
289       "policies" : {
290          "key" : {
291             "name" : "MyFirstPolicyModel_Policies",
292             "version" : "0.0.1"
293          },
294          "policyMap" : {
295             "entry" : [ {
296                "key" : {
297                   "name" : "MyFirstPolicy",
298                   "version" : "0.0.1"
299                },
300                "value" : {
301                   "policyKey" : {
302                      "name" : "MyFirstPolicy",
303                      "version" : "0.0.1"
304                   },
305                   "template" : "FREEFORM",
306                   "state" : {
307                      "entry" : [ {
308                         "key" : "BoozeAuthDecide",
309                         "value" : {
310                            "stateKey" : {
311                               "parentKeyName" : "MyFirstPolicy",
312                               "parentKeyVersion" : "0.0.1",
313                               "parentLocalName" : "NULL",
314                               "localName" : "BoozeAuthDecide"
315                            },
316                            "trigger" : {
317                               "name" : "SALE_INPUT",
318                               "version" : "0.0.1"
319                            },
320                            "stateOutputs" : {
321                               "entry" : [ {
322                                  "key" : "MorningBoozeCheck_Output_Direct",
323                                  "value" : {
324                                     "key" : {
325                                        "parentKeyName" : "MyFirstPolicy",
326                                        "parentKeyVersion" : "0.0.1",
327                                        "parentLocalName" : "BoozeAuthDecide",
328                                        "localName" : "MorningBoozeCheck_Output_Direct"
329                                     },
330                                     "outgoingEvent" : {
331                                        "name" : "SALE_AUTH",
332                                        "version" : "0.0.1"
333                                     },
334                                     "nextState" : {
335                                        "parentKeyName" : "NULL",
336                                        "parentKeyVersion" : "0.0.0",
337                                        "parentLocalName" : "NULL",
338                                        "localName" : "NULL"
339                                     }
340                                  }
341                               } ]
342                            },
343                            "contextAlbumReference" : [ ],
344                            "taskSelectionLogic" : {
345                               "key" : "TaskSelectionLogic",
346                               "logicFlavour" : "JAVASCRIPT",
347                               "logic" : "/*\n * ============LICENSE_START=======================================================\n *  Copyright (C) 2016-2018 Ericsson. All rights reserved.\n *  Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nvar returnValue = true;\n\nexecutor.logger.info(\"Task Selection Execution: '\"+executor.subject.id+\"'. Input Event: '\"+executor.inFields+\"'\");\n\nbranchid = executor.inFields.get(\"branch_ID\");\ntaskorig = executor.subject.getTaskKey(\"MorningBoozeCheck\");\ntaskalt = executor.subject.getTaskKey(\"MorningBoozeCheckAlt1\");\ntaskdef = executor.subject.getDefaultTaskKey();\n\nif(branchid >=0 && branchid <1000){\n  taskorig.copyTo(executor.selectedTask);\n}\nelse if (branchid >=1000 && branchid <2000){\n  taskalt.copyTo(executor.selectedTask);\n}\nelse{\n  taskdef.copyTo(executor.selectedTask);\n}\n\n/*\nThis task selection logic selects task \"MorningBoozeCheck\" for branches with 0<=branch_ID<1000 and selects task \"MorningBoozeCheckAlt1\" for branches with 1000<=branch_ID<2000. Otherwise the default task is selected. In this case the default task is also \"MorningBoozeCheck\"\n*/\n\nreturnValue;"
348                            },
349                            "stateFinalizerLogicMap" : {
350                               "entry" : [ ]
351                            },
352                            "defaultTask" : {
353                               "name" : "MorningBoozeCheck",
354                               "version" : "0.0.1"
355                            },
356                            "taskReferences" : {
357                               "entry" : [ {
358                                  "key" : {
359                                     "name" : "MorningBoozeCheck",
360                                     "version" : "0.0.1"
361                                  },
362                                  "value" : {
363                                     "key" : {
364                                        "parentKeyName" : "MyFirstPolicy",
365                                        "parentKeyVersion" : "0.0.1",
366                                        "parentLocalName" : "BoozeAuthDecide",
367                                        "localName" : "MorningBoozeCheck"
368                                     },
369                                     "outputType" : "DIRECT",
370                                     "output" : {
371                                        "parentKeyName" : "MyFirstPolicy",
372                                        "parentKeyVersion" : "0.0.1",
373                                        "parentLocalName" : "BoozeAuthDecide",
374                                        "localName" : "MorningBoozeCheck_Output_Direct"
375                                     }
376                                  }
377                               }, {
378                                  "key" : {
379                                     "name" : "MorningBoozeCheckAlt1",
380                                     "version" : "0.0.1"
381                                  },
382                                  "value" : {
383                                     "key" : {
384                                        "parentKeyName" : "MyFirstPolicy",
385                                        "parentKeyVersion" : "0.0.1",
386                                        "parentLocalName" : "BoozeAuthDecide",
387                                        "localName" : "MorningBoozeCheckAlt1"
388                                     },
389                                     "outputType" : "DIRECT",
390                                     "output" : {
391                                        "parentKeyName" : "MyFirstPolicy",
392                                        "parentKeyVersion" : "0.0.1",
393                                        "parentLocalName" : "BoozeAuthDecide",
394                                        "localName" : "MorningBoozeCheck_Output_Direct"
395                                     }
396                                  }
397                               } ]
398                            }
399                         }
400                      } ]
401                   },
402                   "firstState" : "BoozeAuthDecide"
403                }
404             } ]
405          }
406       },
407       "tasks" : {
408          "key" : {
409             "name" : "MyFirstPolicyModel_Tasks",
410             "version" : "0.0.1"
411          },
412          "taskMap" : {
413             "entry" : [ {
414                "key" : {
415                   "name" : "MorningBoozeCheck",
416                   "version" : "0.0.1"
417                },
418                "value" : {
419                   "key" : {
420                      "name" : "MorningBoozeCheck",
421                      "version" : "0.0.1"
422                   },
423                   "inputFields" : {
424                      "entry" : [ {
425                         "key" : "amount",
426                         "value" : {
427                            "key" : "amount",
428                            "fieldSchemaKey" : {
429                               "name" : "price_type",
430                               "version" : "0.0.1"
431                            },
432                            "optional" : false
433                         }
434                      }, {
435                         "key" : "assistant_ID",
436                         "value" : {
437                            "key" : "assistant_ID",
438                            "fieldSchemaKey" : {
439                               "name" : "assistant_ID_type",
440                               "version" : "0.0.1"
441                            },
442                            "optional" : false
443                         }
444                      }, {
445                         "key" : "branch_ID",
446                         "value" : {
447                            "key" : "branch_ID",
448                            "fieldSchemaKey" : {
449                               "name" : "branch_ID_type",
450                               "version" : "0.0.1"
451                            },
452                            "optional" : false
453                         }
454                      }, {
455                         "key" : "item_ID",
456                         "value" : {
457                            "key" : "item_ID",
458                            "fieldSchemaKey" : {
459                               "name" : "item_ID_type",
460                               "version" : "0.0.1"
461                            },
462                            "optional" : false
463                         }
464                      }, {
465                         "key" : "notes",
466                         "value" : {
467                            "key" : "notes",
468                            "fieldSchemaKey" : {
469                               "name" : "notes_type",
470                               "version" : "0.0.1"
471                            },
472                            "optional" : true
473                         }
474                      }, {
475                         "key" : "quantity",
476                         "value" : {
477                            "key" : "quantity",
478                            "fieldSchemaKey" : {
479                               "name" : "quantity_type",
480                               "version" : "0.0.1"
481                            },
482                            "optional" : false
483                         }
484                      }, {
485                         "key" : "sale_ID",
486                         "value" : {
487                            "key" : "sale_ID",
488                            "fieldSchemaKey" : {
489                               "name" : "sale_ID_type",
490                               "version" : "0.0.1"
491                            },
492                            "optional" : false
493                         }
494                      }, {
495                         "key" : "time",
496                         "value" : {
497                            "key" : "time",
498                            "fieldSchemaKey" : {
499                               "name" : "timestamp_type",
500                               "version" : "0.0.1"
501                            },
502                            "optional" : false
503                         }
504                      } ]
505                   },
506                   "outputFields" : {
507                      "entry" : [ {
508                         "key" : "amount",
509                         "value" : {
510                            "key" : "amount",
511                            "fieldSchemaKey" : {
512                               "name" : "price_type",
513                               "version" : "0.0.1"
514                            },
515                            "optional" : false
516                         }
517                      }, {
518                         "key" : "assistant_ID",
519                         "value" : {
520                            "key" : "assistant_ID",
521                            "fieldSchemaKey" : {
522                               "name" : "assistant_ID_type",
523                               "version" : "0.0.1"
524                            },
525                            "optional" : false
526                         }
527                      }, {
528                         "key" : "authorised",
529                         "value" : {
530                            "key" : "authorised",
531                            "fieldSchemaKey" : {
532                               "name" : "authorised_type",
533                               "version" : "0.0.1"
534                            },
535                            "optional" : false
536                         }
537                      }, {
538                         "key" : "branch_ID",
539                         "value" : {
540                            "key" : "branch_ID",
541                            "fieldSchemaKey" : {
542                               "name" : "branch_ID_type",
543                               "version" : "0.0.1"
544                            },
545                            "optional" : false
546                         }
547                      }, {
548                         "key" : "item_ID",
549                         "value" : {
550                            "key" : "item_ID",
551                            "fieldSchemaKey" : {
552                               "name" : "item_ID_type",
553                               "version" : "0.0.1"
554                            },
555                            "optional" : false
556                         }
557                      }, {
558                         "key" : "message",
559                         "value" : {
560                            "key" : "message",
561                            "fieldSchemaKey" : {
562                               "name" : "message_type",
563                               "version" : "0.0.1"
564                            },
565                            "optional" : true
566                         }
567                      }, {
568                         "key" : "notes",
569                         "value" : {
570                            "key" : "notes",
571                            "fieldSchemaKey" : {
572                               "name" : "notes_type",
573                               "version" : "0.0.1"
574                            },
575                            "optional" : true
576                         }
577                      }, {
578                         "key" : "quantity",
579                         "value" : {
580                            "key" : "quantity",
581                            "fieldSchemaKey" : {
582                               "name" : "quantity_type",
583                               "version" : "0.0.1"
584                            },
585                            "optional" : false
586                         }
587                      }, {
588                         "key" : "sale_ID",
589                         "value" : {
590                            "key" : "sale_ID",
591                            "fieldSchemaKey" : {
592                               "name" : "sale_ID_type",
593                               "version" : "0.0.1"
594                            },
595                            "optional" : false
596                         }
597                      }, {
598                         "key" : "time",
599                         "value" : {
600                            "key" : "time",
601                            "fieldSchemaKey" : {
602                               "name" : "timestamp_type",
603                               "version" : "0.0.1"
604                            },
605                            "optional" : false
606                         }
607                      } ]
608                   },
609                   "taskParameters" : {
610                      "entry" : [ ]
611                   },
612                   "contextAlbumReference" : [ ],
613                   "taskLogic" : {
614                      "key" : "TaskLogic",
615                      "logicFlavour" : "MVEL",
616                      "logic" : "/*\n * ============LICENSE_START=======================================================\n *  Copyright (C) 2016-2018 Ericsson. All rights reserved.\n *  Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\nimport java.util.Date;\nimport java.util.Calendar;\nimport java.util.TimeZone;\nimport java.text.SimpleDateFormat;\n\nlogger.info(\"Task Execution: '\"+subject.id+\"'. Input Fields: '\"+inFields+\"'\");\n\noutFields.put(\"amount\"      , inFields.get(\"amount\"));\noutFields.put(\"assistant_ID\", inFields.get(\"assistant_ID\"));\noutFields.put(\"notes\"       , inFields.get(\"notes\"));\noutFields.put(\"quantity\"    , inFields.get(\"quantity\"));\noutFields.put(\"branch_ID\"   , inFields.get(\"branch_ID\"));\noutFields.put(\"item_ID\"     , inFields.get(\"item_ID\"));\noutFields.put(\"time\"        , inFields.get(\"time\"));\noutFields.put(\"sale_ID\"     , inFields.get(\"sale_ID\"));\n\nitem_id = inFields.get(\"item_ID\");\n\n//The events used later to test this task use GMT timezone!\ngmt = TimeZone.getTimeZone(\"GMT\");\ntimenow = Calendar.getInstance(gmt);\ndf = new SimpleDateFormat(\"HH:mm:ss z\");\ndf.setTimeZone(gmt);\ntimenow.setTimeInMillis(inFields.get(\"time\"));\n\nmidnight = timenow.clone();\nmidnight.set(\n    timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),\n    timenow.get(Calendar.DATE),0,0,0);\neleven30 = timenow.clone();\neleven30.set(\n    timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),\n    timenow.get(Calendar.DATE),11,30,0);\n\nitemisalcohol = false;\nif(item_id != null && item_id >=1000 && item_id < 2000)\n    itemisalcohol = true;\n\nif( itemisalcohol\n    && timenow.after(midnight) && timenow.before(eleven30)){\n  outFields.put(\"authorised\", false);\n  outFields.put(\"message\", \"Sale not authorised by policy task \"+subject.taskName+\n    \" for time \"+df.format(timenow.getTime())+\n    \". Alcohol can not be sold between \"+df.format(midnight.getTime())+\n    \" and \"+df.format(eleven30.getTime()));\n  return true;\n}\nelse{\n  outFields.put(\"authorised\", true);\n  outFields.put(\"message\", \"Sale authorised by policy task \"+subject.taskName+\n    \" for time \"+df.format(timenow.getTime()));\n  return true;\n}\n\n/*\nThis task checks if a sale request is for an item that is an alcoholic drink.\nIf the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not\nauthorised. Otherwise the sale is authorised.\nIn this implementation we assume that items with item_ID value between 1000 and\n2000 are all alcoholic drinks :-)\n*/"
617                   }
618                }
619             }, {
620                "key" : {
621                   "name" : "MorningBoozeCheckAlt1",
622                   "version" : "0.0.1"
623                },
624                "value" : {
625                   "key" : {
626                      "name" : "MorningBoozeCheckAlt1",
627                      "version" : "0.0.1"
628                   },
629                   "inputFields" : {
630                      "entry" : [ {
631                         "key" : "amount",
632                         "value" : {
633                            "key" : "amount",
634                            "fieldSchemaKey" : {
635                               "name" : "price_type",
636                               "version" : "0.0.1"
637                            },
638                            "optional" : false
639                         }
640                      }, {
641                         "key" : "assistant_ID",
642                         "value" : {
643                            "key" : "assistant_ID",
644                            "fieldSchemaKey" : {
645                               "name" : "assistant_ID_type",
646                               "version" : "0.0.1"
647                            },
648                            "optional" : false
649                         }
650                      }, {
651                         "key" : "branch_ID",
652                         "value" : {
653                            "key" : "branch_ID",
654                            "fieldSchemaKey" : {
655                               "name" : "branch_ID_type",
656                               "version" : "0.0.1"
657                            },
658                            "optional" : false
659                         }
660                      }, {
661                         "key" : "item_ID",
662                         "value" : {
663                            "key" : "item_ID",
664                            "fieldSchemaKey" : {
665                               "name" : "item_ID_type",
666                               "version" : "0.0.1"
667                            },
668                            "optional" : false
669                         }
670                      }, {
671                         "key" : "notes",
672                         "value" : {
673                            "key" : "notes",
674                            "fieldSchemaKey" : {
675                               "name" : "notes_type",
676                               "version" : "0.0.1"
677                            },
678                            "optional" : true
679                         }
680                      }, {
681                         "key" : "quantity",
682                         "value" : {
683                            "key" : "quantity",
684                            "fieldSchemaKey" : {
685                               "name" : "quantity_type",
686                               "version" : "0.0.1"
687                            },
688                            "optional" : false
689                         }
690                      }, {
691                         "key" : "sale_ID",
692                         "value" : {
693                            "key" : "sale_ID",
694                            "fieldSchemaKey" : {
695                               "name" : "sale_ID_type",
696                               "version" : "0.0.1"
697                            },
698                            "optional" : false
699                         }
700                      }, {
701                         "key" : "time",
702                         "value" : {
703                            "key" : "time",
704                            "fieldSchemaKey" : {
705                               "name" : "timestamp_type",
706                               "version" : "0.0.1"
707                            },
708                            "optional" : false
709                         }
710                      } ]
711                   },
712                   "outputFields" : {
713                      "entry" : [ {
714                         "key" : "amount",
715                         "value" : {
716                            "key" : "amount",
717                            "fieldSchemaKey" : {
718                               "name" : "price_type",
719                               "version" : "0.0.1"
720                            },
721                            "optional" : false
722                         }
723                      }, {
724                         "key" : "assistant_ID",
725                         "value" : {
726                            "key" : "assistant_ID",
727                            "fieldSchemaKey" : {
728                               "name" : "assistant_ID_type",
729                               "version" : "0.0.1"
730                            },
731                            "optional" : false
732                         }
733                      }, {
734                         "key" : "authorised",
735                         "value" : {
736                            "key" : "authorised",
737                            "fieldSchemaKey" : {
738                               "name" : "authorised_type",
739                               "version" : "0.0.1"
740                            },
741                            "optional" : false
742                         }
743                      }, {
744                         "key" : "branch_ID",
745                         "value" : {
746                            "key" : "branch_ID",
747                            "fieldSchemaKey" : {
748                               "name" : "branch_ID_type",
749                               "version" : "0.0.1"
750                            },
751                            "optional" : false
752                         }
753                      }, {
754                         "key" : "item_ID",
755                         "value" : {
756                            "key" : "item_ID",
757                            "fieldSchemaKey" : {
758                               "name" : "item_ID_type",
759                               "version" : "0.0.1"
760                            },
761                            "optional" : false
762                         }
763                      }, {
764                         "key" : "message",
765                         "value" : {
766                            "key" : "message",
767                            "fieldSchemaKey" : {
768                               "name" : "message_type",
769                               "version" : "0.0.1"
770                            },
771                            "optional" : true
772                         }
773                      }, {
774                         "key" : "notes",
775                         "value" : {
776                            "key" : "notes",
777                            "fieldSchemaKey" : {
778                               "name" : "notes_type",
779                               "version" : "0.0.1"
780                            },
781                            "optional" : true
782                         }
783                      }, {
784                         "key" : "quantity",
785                         "value" : {
786                            "key" : "quantity",
787                            "fieldSchemaKey" : {
788                               "name" : "quantity_type",
789                               "version" : "0.0.1"
790                            },
791                            "optional" : false
792                         }
793                      }, {
794                         "key" : "sale_ID",
795                         "value" : {
796                            "key" : "sale_ID",
797                            "fieldSchemaKey" : {
798                               "name" : "sale_ID_type",
799                               "version" : "0.0.1"
800                            },
801                            "optional" : false
802                         }
803                      }, {
804                         "key" : "time",
805                         "value" : {
806                            "key" : "time",
807                            "fieldSchemaKey" : {
808                               "name" : "timestamp_type",
809                               "version" : "0.0.1"
810                            },
811                            "optional" : false
812                         }
813                      } ]
814                   },
815                   "taskParameters" : {
816                      "entry" : [ ]
817                   },
818                   "contextAlbumReference" : [ ],
819                   "taskLogic" : {
820                      "key" : "TaskLogic",
821                      "logicFlavour" : "MVEL",
822                      "logic" : "/*\n * ============LICENSE_START=======================================================\n *  Copyright (C) 2016-2018 Ericsson. All rights reserved.\n *  Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\nimport java.util.Date;\nimport java.util.Calendar;\nimport java.util.TimeZone;\nimport java.text.SimpleDateFormat;\n\nlogger.info(\"Task Execution: '\"+subject.id+\"'. Input Event: '\"+inFields+\"'\");\n\noutFields.put(\"amount\"      , inFields.get(\"amount\"));\noutFields.put(\"assistant_ID\", inFields.get(\"assistant_ID\"));\noutFields.put(\"notes\"       , inFields.get(\"notes\"));\noutFields.put(\"quantity\"    , inFields.get(\"quantity\"));\noutFields.put(\"branch_ID\"   , inFields.get(\"branch_ID\"));\noutFields.put(\"item_ID\"     , inFields.get(\"item_ID\"));\noutFields.put(\"time\"        , inFields.get(\"time\"));\noutFields.put(\"sale_ID\"     , inFields.get(\"sale_ID\"));\n\nitem_id = inFields.get(\"item_ID\");\n\n//The events used later to test this task use CET timezone!\ncet = TimeZone.getTimeZone(\"CET\");\ntimenow = Calendar.getInstance(cet);\ndf = new SimpleDateFormat(\"HH:mm:ss z\");\ndf.setTimeZone(cet);\ntimenow.setTimeInMillis(inFields.get(\"time\"));\n\nmidnight = timenow.clone();\nmidnight.set(\n    timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),\n    timenow.get(Calendar.DATE),0,0,0);\nonepm = timenow.clone();\nonepm.set(\n    timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),\n    timenow.get(Calendar.DATE),13,0,0);\n\nitemisalcohol = false;\nif(item_id != null && item_id >=1000 && item_id < 2000)\n    itemisalcohol = true;\n\nif( itemisalcohol &&\n    ( (timenow.after(midnight) && timenow.before(onepm))\n      ||\n      (timenow.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)\n    )){\n  outFields.put(\"authorised\", false);\n  outFields.put(\"message\", \"Sale not authorised by policy task \"+subject.taskName+\n    \" for time \"+df.format(timenow.getTime())+\n    \". Alcohol can not be sold between \"+df.format(midnight.getTime())+\n    \" and \"+df.format(onepm.getTime()) +\" or on Sunday\");\n  return true;\n}\nelse{\n  outFields.put(\"authorised\", true);\n  outFields.put(\"message\", \"Sale authorised by policy task \"+subject.taskName+\n    \" for time \"+df.format(timenow.getTime()));\n  return true;\n}\n\n/*\nThis task checks if a sale request is for an item that is an alcoholic drink.\nIf the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.\nAlso alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.\nIn this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks :-)\n*/"
823                   }
824                }
825             } ]
826          }
827       },
828       "events" : {
829          "key" : {
830             "name" : "MyFirstPolicyModel_Events",
831             "version" : "0.0.1"
832          },
833          "eventMap" : {
834             "entry" : [ {
835                "key" : {
836                   "name" : "SALE_AUTH",
837                   "version" : "0.0.1"
838                },
839                "value" : {
840                   "key" : {
841                      "name" : "SALE_AUTH",
842                      "version" : "0.0.1"
843                   },
844                   "nameSpace" : "com.hyperm",
845                   "source" : "APEX",
846                   "target" : "POS",
847                   "parameter" : {
848                      "entry" : [ {
849                         "key" : "amount",
850                         "value" : {
851                            "key" : "amount",
852                            "fieldSchemaKey" : {
853                               "name" : "price_type",
854                               "version" : "0.0.1"
855                            },
856                            "optional" : false
857                         }
858                      }, {
859                         "key" : "assistant_ID",
860                         "value" : {
861                            "key" : "assistant_ID",
862                            "fieldSchemaKey" : {
863                               "name" : "assistant_ID_type",
864                               "version" : "0.0.1"
865                            },
866                            "optional" : false
867                         }
868                      }, {
869                         "key" : "authorised",
870                         "value" : {
871                            "key" : "authorised",
872                            "fieldSchemaKey" : {
873                               "name" : "authorised_type",
874                               "version" : "0.0.1"
875                            },
876                            "optional" : false
877                         }
878                      }, {
879                         "key" : "branch_ID",
880                         "value" : {
881                            "key" : "branch_ID",
882                            "fieldSchemaKey" : {
883                               "name" : "branch_ID_type",
884                               "version" : "0.0.1"
885                            },
886                            "optional" : false
887                         }
888                      }, {
889                         "key" : "item_ID",
890                         "value" : {
891                            "key" : "item_ID",
892                            "fieldSchemaKey" : {
893                               "name" : "item_ID_type",
894                               "version" : "0.0.1"
895                            },
896                            "optional" : false
897                         }
898                      }, {
899                         "key" : "message",
900                         "value" : {
901                            "key" : "message",
902                            "fieldSchemaKey" : {
903                               "name" : "message_type",
904                               "version" : "0.0.1"
905                            },
906                            "optional" : true
907                         }
908                      }, {
909                         "key" : "notes",
910                         "value" : {
911                            "key" : "notes",
912                            "fieldSchemaKey" : {
913                               "name" : "notes_type",
914                               "version" : "0.0.1"
915                            },
916                            "optional" : true
917                         }
918                      }, {
919                         "key" : "quantity",
920                         "value" : {
921                            "key" : "quantity",
922                            "fieldSchemaKey" : {
923                               "name" : "quantity_type",
924                               "version" : "0.0.1"
925                            },
926                            "optional" : false
927                         }
928                      }, {
929                         "key" : "sale_ID",
930                         "value" : {
931                            "key" : "sale_ID",
932                            "fieldSchemaKey" : {
933                               "name" : "sale_ID_type",
934                               "version" : "0.0.1"
935                            },
936                            "optional" : false
937                         }
938                      }, {
939                         "key" : "time",
940                         "value" : {
941                            "key" : "time",
942                            "fieldSchemaKey" : {
943                               "name" : "timestamp_type",
944                               "version" : "0.0.1"
945                            },
946                            "optional" : false
947                         }
948                      } ]
949                   }
950                }
951             }, {
952                "key" : {
953                   "name" : "SALE_INPUT",
954                   "version" : "0.0.1"
955                },
956                "value" : {
957                   "key" : {
958                      "name" : "SALE_INPUT",
959                      "version" : "0.0.1"
960                   },
961                   "nameSpace" : "com.hyperm",
962                   "source" : "POS",
963                   "target" : "APEX",
964                   "parameter" : {
965                      "entry" : [ {
966                         "key" : "amount",
967                         "value" : {
968                            "key" : "amount",
969                            "fieldSchemaKey" : {
970                               "name" : "price_type",
971                               "version" : "0.0.1"
972                            },
973                            "optional" : false
974                         }
975                      }, {
976                         "key" : "assistant_ID",
977                         "value" : {
978                            "key" : "assistant_ID",
979                            "fieldSchemaKey" : {
980                               "name" : "assistant_ID_type",
981                               "version" : "0.0.1"
982                            },
983                            "optional" : false
984                         }
985                      }, {
986                         "key" : "branch_ID",
987                         "value" : {
988                            "key" : "branch_ID",
989                            "fieldSchemaKey" : {
990                               "name" : "branch_ID_type",
991                               "version" : "0.0.1"
992                            },
993                            "optional" : false
994                         }
995                      }, {
996                         "key" : "item_ID",
997                         "value" : {
998                            "key" : "item_ID",
999                            "fieldSchemaKey" : {
1000                               "name" : "item_ID_type",
1001                               "version" : "0.0.1"
1002                            },
1003                            "optional" : false
1004                         }
1005                      }, {
1006                         "key" : "notes",
1007                         "value" : {
1008                            "key" : "notes",
1009                            "fieldSchemaKey" : {
1010                               "name" : "notes_type",
1011                               "version" : "0.0.1"
1012                            },
1013                            "optional" : true
1014                         }
1015                      }, {
1016                         "key" : "quantity",
1017                         "value" : {
1018                            "key" : "quantity",
1019                            "fieldSchemaKey" : {
1020                               "name" : "quantity_type",
1021                               "version" : "0.0.1"
1022                            },
1023                            "optional" : false
1024                         }
1025                      }, {
1026                         "key" : "sale_ID",
1027                         "value" : {
1028                            "key" : "sale_ID",
1029                            "fieldSchemaKey" : {
1030                               "name" : "sale_ID_type",
1031                               "version" : "0.0.1"
1032                            },
1033                            "optional" : false
1034                         }
1035                      }, {
1036                         "key" : "time",
1037                         "value" : {
1038                            "key" : "time",
1039                            "fieldSchemaKey" : {
1040                               "name" : "timestamp_type",
1041                               "version" : "0.0.1"
1042                            },
1043                            "optional" : false
1044                         }
1045                      } ]
1046                   }
1047                }
1048             } ]
1049          }
1050       },
1051       "schemas" : {
1052          "key" : {
1053             "name" : "MyFirstPolicyModel_Schemas",
1054             "version" : "0.0.1"
1055          },
1056          "schemas" : {
1057             "entry" : [ {
1058                "key" : {
1059                   "name" : "assistant_ID_type",
1060                   "version" : "0.0.1"
1061                },
1062                "value" : {
1063                   "key" : {
1064                      "name" : "assistant_ID_type",
1065                      "version" : "0.0.1"
1066                   },
1067                   "schemaFlavour" : "Java",
1068                   "schemaDefinition" : "java.lang.Long"
1069                }
1070             }, {
1071                "key" : {
1072                   "name" : "authorised_type",
1073                   "version" : "0.0.1"
1074                },
1075                "value" : {
1076                   "key" : {
1077                      "name" : "authorised_type",
1078                      "version" : "0.0.1"
1079                   },
1080                   "schemaFlavour" : "Java",
1081                   "schemaDefinition" : "java.lang.Boolean"
1082                }
1083             }, {
1084                "key" : {
1085                   "name" : "branch_ID_type",
1086                   "version" : "0.0.1"
1087                },
1088                "value" : {
1089                   "key" : {
1090                      "name" : "branch_ID_type",
1091                      "version" : "0.0.1"
1092                   },
1093                   "schemaFlavour" : "Java",
1094                   "schemaDefinition" : "java.lang.Long"
1095                }
1096             }, {
1097                "key" : {
1098                   "name" : "item_ID_type",
1099                   "version" : "0.0.1"
1100                },
1101                "value" : {
1102                   "key" : {
1103                      "name" : "item_ID_type",
1104                      "version" : "0.0.1"
1105                   },
1106                   "schemaFlavour" : "Java",
1107                   "schemaDefinition" : "java.lang.Long"
1108                }
1109             }, {
1110                "key" : {
1111                   "name" : "message_type",
1112                   "version" : "0.0.1"
1113                },
1114                "value" : {
1115                   "key" : {
1116                      "name" : "message_type",
1117                      "version" : "0.0.1"
1118                   },
1119                   "schemaFlavour" : "Java",
1120                   "schemaDefinition" : "java.lang.String"
1121                }
1122             }, {
1123                "key" : {
1124                   "name" : "notes_type",
1125                   "version" : "0.0.1"
1126                },
1127                "value" : {
1128                   "key" : {
1129                      "name" : "notes_type",
1130                      "version" : "0.0.1"
1131                   },
1132                   "schemaFlavour" : "Java",
1133                   "schemaDefinition" : "java.lang.String"
1134                }
1135             }, {
1136                "key" : {
1137                   "name" : "price_type",
1138                   "version" : "0.0.1"
1139                },
1140                "value" : {
1141                   "key" : {
1142                      "name" : "price_type",
1143                      "version" : "0.0.1"
1144                   },
1145                   "schemaFlavour" : "Java",
1146                   "schemaDefinition" : "java.lang.Long"
1147                }
1148             }, {
1149                "key" : {
1150                   "name" : "quantity_type",
1151                   "version" : "0.0.1"
1152                },
1153                "value" : {
1154                   "key" : {
1155                      "name" : "quantity_type",
1156                      "version" : "0.0.1"
1157                   },
1158                   "schemaFlavour" : "Java",
1159                   "schemaDefinition" : "java.lang.Integer"
1160                }
1161             }, {
1162                "key" : {
1163                   "name" : "sale_ID_type",
1164                   "version" : "0.0.1"
1165                },
1166                "value" : {
1167                   "key" : {
1168                      "name" : "sale_ID_type",
1169                      "version" : "0.0.1"
1170                   },
1171                   "schemaFlavour" : "Java",
1172                   "schemaDefinition" : "java.lang.Long"
1173                }
1174             }, {
1175                "key" : {
1176                   "name" : "timestamp_type",
1177                   "version" : "0.0.1"
1178                },
1179                "value" : {
1180                   "key" : {
1181                      "name" : "timestamp_type",
1182                      "version" : "0.0.1"
1183                   },
1184                   "schemaFlavour" : "Java",
1185                   "schemaDefinition" : "java.lang.Long"
1186                }
1187             } ]
1188          }
1189       }
1190    }
1191 }