0134b6bca49d54090ef424f48989aac402d46bcc
[policy/apex-pdp.git] / examples / examples-grpc / src / main / resources / logic / ReceivePMSubscriptionTask.js
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix. 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 var uuidType = java.util.UUID;
21 var HashMapType = java.util.HashMap;
22
23
24 //albumID will be used to fetch info from our album later
25 var albumID = uuidType.fromString("d0050623-18e5-46c9-9298-9a567990cd7c");
26 var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").getSchemaHelper().createNewInstance();
27 var returnValue = true;;
28
29 if (executor.inFields.get("policyName") != null) {
30     var changeType = executor.inFields.get("changeType")
31     var nfName = executor.inFields.get("nfName")
32     var policyName = executor.inFields.get("policyName")
33     var closedLoopControlName = executor.inFields.get("closedLoopControlName")
34     var subscription = executor.inFields.get("subscription")
35
36     var obj = {};
37     obj["nfName"] = executor.inFields.get("nfName")
38     executor.logger.info("nfName" + executor.stringify2Json(obj))
39
40     var ticketInfo = new HashMapType();
41     populate_creator_info(ticketInfo);
42     executor.logger.info("ticketInfo" + executor.stringify2Json(ticketInfo))
43
44     pmSubscriptionInfo.put("nfName", executor.inFields.get("nfName"));
45     pmSubscriptionInfo.put("changeType", executor.inFields.get("changeType"))
46     pmSubscriptionInfo.put("policyName", executor.inFields.get("policyName"))
47     pmSubscriptionInfo.put("closedLoopControlName", executor.inFields.get("closedLoopControlName"))
48     pmSubscriptionInfo.put("subscription", subscription)
49
50     executor.getContextAlbum("PMSubscriptionAlbum").put(albumID.toString(), pmSubscriptionInfo);
51
52     executor.outFields.put("albumID", albumID)
53 } else {
54     executor.message = "Received invalid event"
55     returnValue = false;
56 }
57
58 function populate_creator_info(ticketInfo){
59     populate_field(ticketInfo, "appId", "NSO");
60     populate_field(ticketInfo, "creatorId", "fidLab");
61     populate_field(ticketInfo, "creatorFirstName", "PSO");
62     populate_field(ticketInfo, "creatorLastName", "team7");
63     populate_field(ticketInfo, "creatorGroup", "PSO-team7");
64     populate_field(ticketInfo, "creatorPEIN", "0000000");
65     populate_field(ticketInfo, "creatorPhoneNumber", "800-450-7771");
66     populate_field(ticketInfo, "fid", "fidLab");
67     populate_field(ticketInfo, "organizationCode", "PSO");
68     populate_field(ticketInfo, "source", create_caEn_value("SURV/ALARM FROM/PSO"));
69     populate_field(ticketInfo, "customerName", "XYZ");
70     populate_field(ticketInfo, "authorization", "Basic dGVzdHVzZXI=");
71 }
72
73 function populate_field(mapname, name, value){
74     if (value == null){
75         mapname.put(name, "none");
76     } else{
77         mapname.put(name, value);
78     }
79
80 }
81
82 function create_caEn_value(value){
83     var attr = {};
84     attr["caEn"] = String(value);
85     return attr;
86 }
87
88 returnValue;