Adding examples module to apex-pdp
[policy/apex-pdp.git] / examples / aadm / src / main / resources / org / onap / policy / apex / examples / aadm / model / mvel / SAPCActTask_TaskLogic.mvel
1 /*
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 import org.onap.policy.apex.examples.aadm.concepts.IMSIStatus;
21
22 logger.debug(subject.id + ":" + subject.taskName + " execution logic");
23 logger.debug(inFields);
24
25 if (inFields["IMSI"] == null) {
26     outFields["IMSI"] = 0;
27 }
28 else {
29     outFields["IMSI"] = inFields["IMSI"];
30 }
31
32 if (outFields["IMSI"] == 0 && inFields["IMSI_IP"] != null && inFields["IMSI_IP"].equals("0")) {
33     // no action arrived
34     outFields["IMSI"] = 0;
35     outFields["PROFILE"] = "none";
36     outFields["BLACKLIST_ON"] = false;
37     outFields["PROBE_ON"]     = false;
38     return true;
39 }
40
41 IMSIStatus imsiStatus = getContextAlbum("IMSIStatusAlbum").get((String)inFields["IMSI"]);
42 logger.debug(imsiStatus);
43
44 if (imsiStatus.getBlockingCount() > 1) {
45     outFields["IMSI"] = 0;
46     outFields["PROFILE"] = "none";
47     outFields["BLACKLIST_ON"] = false;
48     outFields["PROBE_ON"]     = false;
49
50     return true;
51 }
52
53 if (imsiStatus.getBlockingCount() > 0 && imsiStatus.getBlacklistedTime() != 0) {
54     outFields["IMSI"] = 0;
55     outFields["PROFILE"] = "none";
56     outFields["BLACKLIST_ON"] = false;
57     outFields["PROBE_ON"]     = false;
58
59     return true;
60 }
61
62 imsiStatus.incrementBlockingCount();
63 imsiStatus.setBlacklistedTime(System.currentTimeMillis());
64
65 logger.debug("Bocking count for IMSI: " + imsiStatus.getIMSI() + " is: " + imsiStatus.getBlockingCount());
66 getContextAlbum("IMSIStatusAlbum").put(imsiStatus.getIMSI(), imsiStatus);
67
68 outFields["PROFILE"] = "ServiceA";
69 outFields["BLACKLIST_ON"] = true;
70 outFields["PROBE_ON"]     = false;
71
72 if (imsiStatus.getBlockingCount() > 1) {
73     logger.debug("POLICY SAPCPolicy - blacklisting imsi: " + outFields["IMSI"] + " permanently");
74 }
75 else {
76     logger.debug("POLICY SAPCPolicy - blacklisting imsi: " + outFields["IMSI"] + " temporary for 120000 ms");
77 }
78
79 return true;