dc4948990088a3ab668360b366e5ca39fcb22cb8
[policy/apex-pdp.git] / examples / examples-grpc / src / main / resources / logic / ResponseTask.js
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix. All rights reserved.
4  *  Modifications Copyright (C) 2021 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
22
23 var uuidType = java.util.UUID;
24
25 var albumID = uuidType.fromString("d0050623-18e5-46c9-9298-9a567990cd7c");
26
27 var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(albumID.toString());
28
29 var responseStatus = executor.subject.getOutFieldSchemaHelper("CDSResponseStatusEvent", "status").createNewInstance();
30
31 responseStatus.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName"))
32 responseStatus.put("nfName", pmSubscriptionInfo.get("nfName"))
33 responseStatus.put("changeType", pmSubscriptionInfo.get("changeType"))
34
35 var response = executor.inFields.get("payload")
36
37 if ("failure".equals(response.get("create_DasH_subscription_DasH_response").get("odl_DasH_response").get("status"))) {
38     responseStatus.put("message", "failed")
39 } else {
40     responseStatus.put("message", "success")
41 }
42
43 var cdsResponseEventFields = java.util.HashMap();
44 cdsResponseEventFields.put("status", responseStatus);
45 executor.addFieldsToOutput(cdsResponseEventFields);
46
47 var logEventFields = java.util.HashMap();
48 logEventFields.put("final_status", "FINAL_SUCCESS");
49 logEventFields.put("message", "Operation successfully completed.");
50 executor.addFieldsToOutput(logEventFields);
51 true;