Update APEX example to use JSON Schema plugin
[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  *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21 var uuidType = java.util.UUID;
22 var HashMapType = java.util.HashMap;
23
24
25 //albumID will be used to fetch info from our album later
26 var albumID = uuidType.fromString("d0050623-18e5-46c9-9298-9a567990cd7c");
27 var pmSubscriptionInfo = new java.util.HashMap();
28 var returnValue = true;;
29
30 if (executor.inFields.get("policyName") != null) {
31     var changeType = executor.inFields.get("changeType")
32     var nfName = executor.inFields.get("nfName")
33     var policyName = executor.inFields.get("policyName")
34     var closedLoopControlName = executor.inFields.get("closedLoopControlName")
35     var subscription = executor.inFields.get("subscription")
36
37     var obj = {};
38     obj["nfName"] = executor.inFields.get("nfName")
39     executor.logger.info("nfName" + executor.stringify2Json(obj))
40
41     var ticketInfo = new HashMapType();
42     populate_creator_info(ticketInfo);
43     executor.logger.info("ticketInfo" + executor.stringify2Json(ticketInfo))
44
45     pmSubscriptionInfo.put("nfName", executor.inFields.get("nfName"));
46     pmSubscriptionInfo.put("changeType", executor.inFields.get("changeType"))
47     pmSubscriptionInfo.put("policyName", executor.inFields.get("policyName"))
48     pmSubscriptionInfo.put("closedLoopControlName", executor.inFields.get("closedLoopControlName"))
49     pmSubscriptionInfo.put("subscription", subscription)
50
51     executor.getContextAlbum("PMSubscriptionAlbum").put(albumID.toString(), pmSubscriptionInfo);
52
53     executor.outFields.put("albumID", albumID)
54 } else {
55     executor.message = "Received invalid event"
56     returnValue = false;
57 }
58
59 function populate_creator_info(ticketInfo){
60     populate_field(ticketInfo, "appId", "NSO");
61     populate_field(ticketInfo, "creatorId", "fidLab");
62     populate_field(ticketInfo, "creatorFirstName", "PSO");
63     populate_field(ticketInfo, "creatorLastName", "team7");
64     populate_field(ticketInfo, "creatorGroup", "PSO-team7");
65     populate_field(ticketInfo, "creatorPEIN", "0000000");
66     populate_field(ticketInfo, "creatorPhoneNumber", "800-450-7771");
67     populate_field(ticketInfo, "fid", "fidLab");
68     populate_field(ticketInfo, "organizationCode", "PSO");
69     populate_field(ticketInfo, "source", create_caEn_value("SURV/ALARM FROM/PSO"));
70     populate_field(ticketInfo, "customerName", "XYZ");
71     populate_field(ticketInfo, "authorization", "Basic dGVzdHVzZXI=");
72 }
73
74 function populate_field(mapname, name, value){
75     if (value == null){
76         mapname.put(name, "none");
77     } else{
78         mapname.put(name, value);
79     }
80
81 }
82
83 function create_caEn_value(value){
84     var attr = {};
85     attr["caEn"] = String(value);
86     return attr;
87 }
88
89 returnValue;