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 Fields: '"+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 GMT timezone!
39 gmt = TimeZone.getTimeZone("GMT");
40 timenow = Calendar.getInstance(gmt);
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 eleven30 = timenow.clone();
51 timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
52 timenow.get(Calendar.DATE),11,30,0);
54 itemisalcohol = false;
55 if(item_id != null && item_id >=1000 && item_id < 2000)
59 && timenow.after(midnight) && timenow.before(eleven30)){
60 outFields.put("authorised", false);
61 outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
62 " for time "+df.format(timenow.getTime())+
63 ". Alcohol can not be sold between "+df.format(midnight.getTime())+
64 " and "+df.format(eleven30.getTime()));
68 outFields.put("authorised", true);
69 outFields.put("message", "Sale authorised by policy task "+subject.taskName+
70 " for time "+df.format(timenow.getTime()));
75 This task checks if a sale request is for an item that is an alcoholic drink. If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not authorised. Otherwise the sale is authorised. In this implementation we assume that items with item_ID value between 1000 and 2000 are all alcoholic drinks :-)