2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 import java.util.Date;
21 import java.util.Calendar;
22 import java.util.TimeZone;
23 import java.text.SimpleDateFormat;
25 logger.info("Task Execution: '"+subject.id+"'. Input Event: '"+inFields+"'");
27 outFields.put("amount" , inFields.get("amount"));
28 outFields.put("assistant_ID", inFields.get("assistant_ID"));
29 outFields.put("notes" , inFields.get("notes"));
30 outFields.put("quantity" , inFields.get("quantity"));
31 outFields.put("branch_ID" , inFields.get("branch_ID"));
32 outFields.put("item_ID" , inFields.get("item_ID"));
33 outFields.put("time" , inFields.get("time"));
34 outFields.put("sale_ID" , inFields.get("sale_ID"));
36 item_id = inFields.get("item_ID");
38 //The events used later to test this task use CET timezone!
39 cet = TimeZone.getTimeZone("CET");
40 timenow = Calendar.getInstance(cet);
41 df = new SimpleDateFormat("HH:mm:ss z");
43 timenow.setTimeInMillis(inFields.get("time"));
45 midnight = timenow.clone();
47 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
48 timenow.get(Calendar.DATE),0,0,0);
49 onepm = timenow.clone();
51 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
52 timenow.get(Calendar.DATE),13,0,0);
54 itemisalcohol = false;
55 if(item_id != null && item_id >=1000 && item_id < 2000)
59 ( (timenow.after(midnight) && timenow.before(onepm))
61 (timenow.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
63 outFields.put("authorised", false);
64 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
65 " for time "+df.format(timenow.getTime())+
66 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
67 " and "+df.format(onepm.getTime()) +" or on Sunday");
71 outFields.put("authorised", true);
72 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
73 " for time "+df.format(timenow.getTime()));
78 This task checks if a sale request is for an item that is an alcoholic drink.
79 If the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.
80 Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.
81 In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks :-)