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