/root> #-------------------------------------------------------------------------------
/root> # ============LICENSE_START=======================================================
/root> #  Copyright (C) 2020 Nordix Foundation.
/root> #  Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
/root> # ================================================================================
/root> # Licensed under the Apache License, Version 2.0 (the "License");
/root> # you may not use this file except in compliance with the License.
/root> # You may obtain a copy of the License at
/root> #
/root> #      http://www.apache.org/licenses/LICENSE-2.0
/root> #
/root> # Unless required by applicable law or agreed to in writing, software
/root> # distributed under the License is distributed on an "AS IS" BASIS,
/root> # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/root> # See the License for the specific language governing permissions and
/root> # limitations under the License.
/root> #
/root> # SPDX-License-Identifier: Apache-2.0
/root> # ============LICENSE_END=========================================================
/root> #-------------------------------------------------------------------------------
/root> 
/root> model create name=APEXgRPCPolicy
result: SUCCESS

/root> 
/root> ##
/root> ## SCHEMAS
/root> ##
/root> 
/root> schema create name=SimpleStringType flavour=Java schema=java.lang.String
result: SUCCESS

/root> schema create name=UUIDType         flavour=Java schema=java.util.UUID
result: SUCCESS

/root> schema create name=SimpleIntType    flavour=Java schema=java.lang.Integer
result: SUCCESS

/root> 
/root> schema create name=CDSRequestCommonHeaderType flavour=Json schema=LS
{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Root",
  "type": "object",
  "required": [
    "requestId",
    "subRequestId",
    "originatorId"
  ],
  "properties": {
    "requestId": {
      "$id": "#root/requestId",
      "title": "Requestid",
      "type": "string",
      "default": "",
      "examples": [
        "123456-1000"
      ],
      "pattern": "^.*$"
    },
    "subRequestId": {
      "$id": "#root/subRequestId",
      "title": "Subrequestid",
      "type": "string",
      "default": "",
      "examples": [
        "sub-123456-1000"
      ],
      "pattern": "^.*$"
    },
    "originatorId": {
      "$id": "#root/originatorId",
      "title": "Originatorid",
      "type": "string",
      "default": "",
      "examples": [
        "sdnc"
      ],
      "pattern": "^.*$"
    }
  }
}

LE
result: SUCCESS

/root> 
/root> schema create name=CDSResponseCommonHeaderType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "timestamp": {
      "type": "string"
    },
    "requestId": {
      "type": "string"
    },
    "subRequestId": {
      "type": "string"
    },
    "flag": {
      "type": "object"
    },
    "originatorId": {
      "type": "string"
    }
  },
  "required": [
    "timestamp",
    "requestId",
    "subRequestId",
    "flag",
    "originatorId"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=CDSActionIdentifiersType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "actionName": {
      "type": "string"
    },
    "blueprintName": {
      "type": "string"
    },
    "blueprintVersion": {
      "type": "string"
    },
    "mode": {
      "type": "string"
    }
  },
  "required": [
    "actionName",
    "blueprintName",
    "blueprintVersion",
    "mode"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=CDSResponseStatusType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "code": {
      "type": "integer"
    },
    "message": {
      "type": "string"
    },
    "eventType": {
      "type": "string"
    },
    "timestamp": {
      "type": "string"
    }
  },
  "required": [
    "code",
    "message",
    "eventType",
    "timestamp"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=CDSCreateSubscriptionPayloadType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": [
    "create-subscription-request"
  ],
  "properties": {
    "create-subscription-request": {
      "type": "object",
      "required": [
        "create-subscription-properties"
      ],
      "properties": {
        "create-subscription-properties": {
          "type": "object",
          "required": [
            "nfName",
            "administrativeState",
            "subscriptionName",
            "measurementGroups",
            "fileBasedGP",
            "fileLocation"
          ],
          "properties": {
            "nfName": {
              "type": "string",
              "default": "",
              "examples": [
                "pnf300"
              ],
              "pattern": "^.*$"
            },
            "administrativeState": {
              "type": "string",
              "default": "",
              "examples": [
                "UNLOCKED"
              ],
              "pattern": "^.*$"
            },
            "subscriptionName": {
              "type": "string",
              "default": "",
              "examples": [
                "testPolicyB"
              ],
              "pattern": "^.*$"
            },
            "measurementGroups": {
              "type": "array",
              "default": [],
              "items": {
                "type": "object",
                "required": [
                  "measurementGroup"
                ],
                "properties": {
                  "measurementGroup": {
                    "type": "object",
                    "required": [
                      "measurementTypes",
                      "managedObjectDNsBasic"
                    ],
                    "properties": {
                      "measurementTypes": {
                        "type": "array",
                        "default": [],
                        "items": {
                          "type": "object",
                          "required": [
                            "measurementType"
                          ],
                          "properties": {
                            "measurementType": {
                              "type": "string",
                              "default": "",
                              "examples": [
                                "countera"
                              ],
                              "pattern": "^.*$"
                            }
                          }
                        }
                      },
                      "managedObjectDNsBasic": {
                        "type": "array",
                        "default": [],
                        "items": {
                          "$id": "#root/create-subscription-request/create-subscription-properties/measurementGroups/items/measurementGroup/managedObjectDNsBasic/items",
                          "title": "Items",
                          "type": "object",
                          "required": [
                            "DN"
                          ],
                          "properties": {
                            "DN": {
                              "type": "string",
                              "default": "",
                              "examples": [
                                "dna"
                              ],
                              "pattern": "^.*$"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            },
            "fileBasedGP": {
              "type": "string",
              "default": "",
              "examples": [
                "15.0"
              ],
              "pattern": "^.*$"
            },
            "fileLocation": {
              "type": "string",
              "default": "",
              "examples": [
                "/pm/pm.xml"
              ],
              "pattern": "^.*$"
            }
          }
        }
      }
    }
  }
}
LE
result: SUCCESS

/root> 
/root> schema create name=CDSDeleteSubscriptionPayloadType flavour=Avro schema=LS
{
  "type": "map",
  "values": {
    "type": "record",
    "name": "CDSRequestPayloadEntry",
    "fields": [
      {
        "name": "delete_DasH_subscription_DasH_properties",
        "type": {
          "name": "delete_DasH_subscription_DasH_properties_record",
          "type": "record",
          "fields": [
            {
              "name": "nfName",
              "type": "string"
            },
            {
              "name": "subscriptionName",
              "type": "string"
            },
            {
              "name": "administrativeState",
              "type": "string"
            },
            {
              "name": "fileBasedGP",
              "type": "string"
            },
            {
              "name": "fileLocation",
              "type": "string"
            },
            {
              "name": "measurementGroups",
              "type": {
                "type": "array",
                "items": {
                  "name": "measurementGroups_record",
                  "type": "record",
                  "fields": [
                    {
                      "name": "measurementGroup",
                      "type": {
                        "name": "measurementGroup",
                        "type": "record",
                        "fields": [
                          {
                            "name": "measurementTypes",
                            "type": {
                              "type": "array",
                              "items": {
                                "name": "measurementTypes_record",
                                "type": "record",
                                "fields": [
                                  {
                                    "name": "measurementType",
                                    "type": "string"
                                  }
                                ]
                              }
                            }
                          },
                          {
                            "name": "managedObjectDNsBasic",
                            "type": {
                              "type": "array",
                              "items": {
                                "name": "managedObjectDNsBasic_record",
                                "type": "record",
                                "fields": [
                                  {
                                    "name": "DN",
                                    "type": "string"
                                  }
                                ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            }
          ]
        }
      }
    ]
  }
}
LE
result: SUCCESS

/root> 
/root> schema create name=CDSResponsePayloadType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "create-subscription-response": {
      "type": "object",
      "properties": {
        "odl-response": {
          "type": "object",
          "properties": {
            "status": {
              "type": "string"
            }
          },
          "required": [
            "status"
          ]
        }
      },
      "required": [
        "odl-response"
      ]
    }
  },
  "required": [
    "create-subscription-response"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=SubscriptionStatusType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "subscriptionName": {
      "type": "string"
    },
    "nfName": {
      "type": "string"
    },
    "changeType": {
      "type": "string"
    },
    "message": {
      "type": "string"
    }
  },
  "required": [
    "subscriptionName",
    "nfName",
    "changeType",
    "message"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=PMSubscriptionType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "changeType": {
      "type": "string"
    },
    "closedLoopControlName": {
      "type": "string"
    },
    "policyName": {
      "type": "string"
    },
    "nfName": {
      "type": "string"
    },
    "subscription": {
      "type": "array",
      "items": [
        {
          "type": "object",
          "properties": {
            "measurementGroup": {
              "type": "object",
              "properties": {
                "measurementTypes": {
                  "type": "array",
                  "items": [
                    {
                      "type": "object",
                      "properties": {
                        "measurementType": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "measurementType"
                      ]
                    },
                    {
                      "type": "object",
                      "properties": {
                        "measurementType": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "measurementType"
                      ]
                    }
                  ]
                },
                "managedObjectDNsBasic": {
                  "type": "array",
                  "items": [
                    {
                      "type": "object",
                      "properties": {
                        "DN": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "DN"
                      ]
                    },
                    {
                      "type": "object",
                      "properties": {
                        "DN": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "DN"
                      ]
                    }
                  ]
                }
              },
              "required": [
                "measurementTypes",
                "managedObjectDNsBasic"
              ]
            }
          },
          "required": [
            "measurementGroup"
          ]
        }
      ]
    }
  },
  "required": [
    "changeType",
    "closedLoopControlName",
    "policyName",
    "nfName",
    "subscription"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=SubscriptionType flavour=Json schema=LS
{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Root",
  "type": "object",
  "required": [
    "subscriptionName",
    "administrativeState",
    "fileBasedGP",
    "fileLocation",
    "measurementGroups"
  ],
  "properties": {
    "subscriptionName": {
      "$id": "#root/subscriptionName",
      "title": "Subscriptionname",
      "type": "string",
      "default": "",
      "examples": [
        "testPolicyB"
      ],
      "pattern": "^.*$"
    },
    "administrativeState": {
      "$id": "#root/administrativeState",
      "title": "Administrativestate",
      "type": "string",
      "default": "",
      "examples": [
        "UNLOCKED"
      ],
      "pattern": "^.*$"
    },
    "fileBasedGP": {
      "$id": "#root/fileBasedGP",
      "title": "Filebasedgp",
      "type": "integer",
      "examples": [
        15
      ],
      "default": 0
    },
    "fileLocation": {
      "$id": "#root/fileLocation",
      "title": "Filelocation",
      "type": "string",
      "default": "",
      "examples": [
        "/pm/pm.xml"
      ],
      "pattern": "^.*$"
    },
    "measurementGroups": {
      "$id": "#root/measurementGroups",
      "title": "Measurementgroups",
      "type": "array",
      "default": [],
      "items": {
        "$id": "#root/measurementGroups/items",
        "title": "Items",
        "type": "object",
        "required": [
          "measurementGroup"
        ],
        "properties": {
          "measurementGroup": {
            "$id": "#root/measurementGroups/items/measurementGroup",
            "title": "Measurementgroup",
            "type": "object",
            "required": [
              "measurementTypes",
              "managedObjectDNsBasic"
            ],
            "properties": {
              "measurementTypes": {
                "$id": "#root/measurementGroups/items/measurementGroup/measurementTypes",
                "title": "Measurementtypes",
                "type": "array",
                "default": [],
                "items": {
                  "$id": "#root/measurementGroups/items/measurementGroup/measurementTypes/items",
                  "title": "Items",
                  "type": "object",
                  "required": [
                    "measurementType"
                  ],
                  "properties": {
                    "measurementType": {
                      "$id": "#root/measurementGroups/items/measurementGroup/measurementTypes/items/measurementType",
                      "title": "Measurementtype",
                      "type": "string",
                      "default": "",
                      "examples": [
                        "countera"
                      ],
                      "pattern": "^.*$"
                    }
                  }
                }
              },
              "managedObjectDNsBasic": {
                "$id": "#root/measurementGroups/items/measurementGroup/managedObjectDNsBasic",
                "title": "Managedobjectdnsbasic",
                "type": "array",
                "default": [],
                "items": {
                  "$id": "#root/measurementGroups/items/measurementGroup/managedObjectDNsBasic/items",
                  "title": "Items",
                  "type": "object",
                  "required": [
                    "DN"
                  ],
                  "properties": {
                    "DN": {
                      "$id": "#root/measurementGroups/items/measurementGroup/managedObjectDNsBasic/items/DN",
                      "title": "Dn",
                      "type": "string",
                      "default": "",
                      "examples": [
                        "dna"
                      ],
                      "pattern": "^.*$"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

LE
result: SUCCESS

/root> 
/root> ##
/root> ## EVENTS
/root> ##
/root> 
/root> album create name=PMSubscriptionAlbum scope=policy writable=true schemaName=PMSubscriptionType
result: SUCCESS

/root> 
/root> # Incoming event
/root> event create name=testPolicyB version=0.0.1 nameSpace=org.onap.policy.apex.onap.pmcontrol source=DCAE target=APEX toscaPolicyState=ENTRY
result: SUCCESS

/root> event parameter create name=testPolicyB parName=nfName schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=testPolicyB parName=policyName schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=testPolicyB parName=changeType schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=testPolicyB parName=closedLoopControlName schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=testPolicyB parName=subscription schemaName=SubscriptionType
result: SUCCESS

/root> 
/root> event create name=PMSubscriptionOutputEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=PMSubscriptionOutputEvent parName=albumID     schemaName=UUIDType
result: SUCCESS

/root> 
/root> event create name=CreateSubscriptionPayloadEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=CreateSubscriptionPayloadEvent parName=payload schemaName=CDSCreateSubscriptionPayloadType
result: SUCCESS

/root> event parameter create name=CreateSubscriptionPayloadEvent parName=albumID     schemaName=UUIDType
result: SUCCESS

/root> 
/root> event create name=DeleteSubscriptionPayloadEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionPayloadEvent parName=payload schemaName=CDSDeleteSubscriptionPayloadType
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionPayloadEvent parName=albumID     schemaName=UUIDType
result: SUCCESS

/root> 
/root> event create name=CreateSubscriptionRequestEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=CreateSubscriptionRequestEvent parName=commonHeader schemaName=CDSRequestCommonHeaderType
result: SUCCESS

/root> event parameter create name=CreateSubscriptionRequestEvent parName=actionIdentifiers schemaName=CDSActionIdentifiersType
result: SUCCESS

/root> event parameter create name=CreateSubscriptionRequestEvent parName=payload schemaName=CDSCreateSubscriptionPayloadType
result: SUCCESS

/root> 
/root> event create name=DeleteSubscriptionRequestEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionRequestEvent parName=commonHeader schemaName=CDSRequestCommonHeaderType
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionRequestEvent parName=actionIdentifiers schemaName=CDSActionIdentifiersType
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionRequestEvent parName=payload schemaName=CDSDeleteSubscriptionPayloadType
result: SUCCESS

/root> 
/root> event create name=CDSResponseEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=CDS target=APEX
result: SUCCESS

/root> event parameter create name=CDSResponseEvent parName=commonHeader schemaName=CDSResponseCommonHeaderType
result: SUCCESS

/root> event parameter create name=CDSResponseEvent parName=actionIdentifiers schemaName=CDSActionIdentifiersType
result: SUCCESS

/root> event parameter create name=CDSResponseEvent parName=status schemaName=CDSResponseStatusType
result: SUCCESS

/root> event parameter create name=CDSResponseEvent parName=payload schemaName=CDSResponsePayloadType
result: SUCCESS

/root> 
/root> event create name=CDSResponseStatusEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=DCAE toscaPolicyState=EXIT_SUCCESS
result: SUCCESS

/root> event parameter create name=CDSResponseStatusEvent parName=status schemaName=SubscriptionStatusType
result: SUCCESS

/root> 
/root> event create name=LogEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=DCAE
result: SUCCESS

/root> event parameter create name=LogEvent parName=final_status schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=LogEvent parName=message schemaName=SimpleStringType
result: SUCCESS

/root> 
/root> ##
/root> ## TASKS
/root> ##
/root> 
/root> 
/root> task create name=ReceivePMSubscriptionTask
result: SUCCESS

/root> task contextref create name=ReceivePMSubscriptionTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=ReceivePMSubscriptionTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */
var uuidType = java.util.UUID;
var HashMapType = java.util.HashMap;


//albumID will be used to fetch info from our album later
var albumID = uuidType.fromString("d0050623-18e5-46c9-9298-9a567990cd7c");
var pmSubscriptionInfo = new java.util.HashMap();
var returnValue = true;;

if (executor.inFields.get("policyName") != null) {
    var changeType = executor.inFields.get("changeType")
    var nfName = executor.inFields.get("nfName")
    var policyName = executor.inFields.get("policyName")
    var closedLoopControlName = executor.inFields.get("closedLoopControlName")
    var subscription = executor.inFields.get("subscription")

    var obj = {};
    obj["nfName"] = executor.inFields.get("nfName")
    executor.logger.info("nfName" + executor.stringify2Json(obj))

    var ticketInfo = new HashMapType();
    populate_creator_info(ticketInfo);
    executor.logger.info("ticketInfo" + executor.stringify2Json(ticketInfo))

    pmSubscriptionInfo.put("nfName", executor.inFields.get("nfName"));
    pmSubscriptionInfo.put("changeType", executor.inFields.get("changeType"))
    pmSubscriptionInfo.put("policyName", executor.inFields.get("policyName"))
    pmSubscriptionInfo.put("closedLoopControlName", executor.inFields.get("closedLoopControlName"))
    pmSubscriptionInfo.put("subscription", subscription)

    executor.getContextAlbum("PMSubscriptionAlbum").put(albumID.toString(), pmSubscriptionInfo);

    executor.outFields.put("albumID", albumID)
} else {
    executor.message = "Received invalid event"
    returnValue = false;
}

function populate_creator_info(ticketInfo){
    populate_field(ticketInfo, "appId", "NSO");
    populate_field(ticketInfo, "creatorId", "fidLab");
    populate_field(ticketInfo, "creatorFirstName", "PSO");
    populate_field(ticketInfo, "creatorLastName", "team7");
    populate_field(ticketInfo, "creatorGroup", "PSO-team7");
    populate_field(ticketInfo, "creatorPEIN", "0000000");
    populate_field(ticketInfo, "creatorPhoneNumber", "800-450-7771");
    populate_field(ticketInfo, "fid", "fidLab");
    populate_field(ticketInfo, "organizationCode", "PSO");
    populate_field(ticketInfo, "source", create_caEn_value("SURV/ALARM FROM/PSO"));
    populate_field(ticketInfo, "customerName", "XYZ");
    populate_field(ticketInfo, "authorization", "Basic dGVzdHVzZXI=");
}

function populate_field(mapname, name, value){
    if (value == null){
        mapname.put(name, "none");
    } else{
        mapname.put(name, value);
    }

}

function create_caEn_value(value){
    var attr = {};
    attr["caEn"] = String(value);
    return attr;
}

returnValue;

LE
result: SUCCESS

/root> 
/root> task create name=CreateSubscriptionPayloadTask
result: SUCCESS

/root> task contextref create name=CreateSubscriptionPayloadTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=CreateSubscriptionPayloadTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())

var payloadProperties = new java.util.HashMap();

payloadProperties.put("nfName",  pmSubscriptionInfo.get("nfName"))
payloadProperties.put("subscriptionName",  pmSubscriptionInfo.get("subscription").get("subscriptionName"))
payloadProperties.put("administrativeState", pmSubscriptionInfo.get("subscription").get("administrativeState"))
payloadProperties.put("fileBasedGP",  pmSubscriptionInfo.get("subscription").get("fileBasedGP").toString())
payloadProperties.put("fileLocation", pmSubscriptionInfo.get("subscription").get("fileLocation"))
payloadProperties.put("measurementGroups", pmSubscriptionInfo.get("subscription").get("measurementGroups"))

var payloadEntry = new java.util.HashMap();
payloadEntry.put("create-subscription-properties", payloadProperties)

var payload = new java.util.HashMap();
var payloadSchemaHelper = executor.subject.getOutFieldSchemaHelper("payload");
payload.put("create-subscription-request", payloadEntry);

executor.logger.info("CDS payload - " + executor.stringify2Json( payload, payloadSchemaHelper));

executor.outFields.put("albumID", executor.inFields.get("albumID"));
executor.outFields.put("payload", payload);

executor.logger.info("Sending Create Subscription Event to CDS");

true;
LE
result: SUCCESS

/root> 
/root> task create name=DeleteSubscriptionPayloadTask
result: SUCCESS

/root> task contextref create name=DeleteSubscriptionPayloadTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=DeleteSubscriptionPayloadTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())

var payloadProperties = new java.util.HashMap();

payloadProperties.put("nfName",  pmSubscriptionInfo.get("nfName"))
payloadProperties.put("subscriptionName",  pmSubscriptionInfo.get("subscription").get("subscriptionName"))
payloadProperties.put("administrativeState", pmSubscriptionInfo.get("subscription").get("administrativeState"))
payloadProperties.put("fileBasedGP",  pmSubscriptionInfo.get("subscription").get("fileBasedGP").toString())
payloadProperties.put("fileLocation", pmSubscriptionInfo.get("subscription").get("fileLocation"))
payloadProperties.put("measurementGroups", pmSubscriptionInfo.get("subscription").get("measurementGroups"))

var payloadEntry = new java.util.HashMap();
payloadEntry.put("delete-subscription-properties", payloadProperties)

var payload = new java.util.HashMap();
payload.put("delete-subscription-request", payloadEntry);

executor.outFields.put("albumID", executor.inFields.get("albumID"))
executor.outFields.put("payload", payload);

executor.logger.info("Sending delete Subscription Event to CDS")

true;

LE
result: SUCCESS

/root> 
/root> task create name=CreateSubscriptionRequestTask
result: SUCCESS

/root> task contextref create name=CreateSubscriptionRequestTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=CreateSubscriptionRequestTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())
var payload = executor.inFields.get("payload")
var actionName = "create-subscription"

var commonHeader = new java.util.HashMap();
commonHeader.put("originatorId", "sdnc");
commonHeader.put("requestId", "123456-1000");
commonHeader.put("subRequestId", "sub-123456-1000");

var actionIdentifiers = new java.util.HashMap();
actionIdentifiers.put("actionName", actionName);
actionIdentifiers.put("blueprintName", "pm_control");
actionIdentifiers.put("blueprintVersion", "1.0.0");
actionIdentifiers.put("mode", "sync");

executor.outFields.put("commonHeader", commonHeader);
executor.outFields.put("actionIdentifiers", actionIdentifiers);
executor.outFields.put("payload", payload);

executor.logger.info("Sending Activate Subscription Event to CDS")

true;
LE
result: SUCCESS

/root> 
/root> task create name=DeleteSubscriptionRequestTask
result: SUCCESS

/root> task contextref create name=DeleteSubscriptionRequestTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=DeleteSubscriptionRequestTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())
var payload = executor.inFields.get("payload")
var actionName = "delete-subscription"

var commonHeader = new java.util.HashMap();
commonHeader.put("originatorId", "sdnc");
commonHeader.put("requestId", "123456-1000");
commonHeader.put("subRequestId", "sub-123456-1000");

var actionIdentifiers = new java.util.HashMap();
actionIdentifiers.put("actionName", actionName);
actionIdentifiers.put("blueprintName", "pm_control");
actionIdentifiers.put("blueprintVersion", "1.0.0");
actionIdentifiers.put("mode", "sync");

executor.outFields.put("commonHeader", commonHeader);
executor.outFields.put("actionIdentifiers", actionIdentifiers);
executor.outFields.put("payload", payload);

executor.logger.info("Sending Deactivate Subscription Event to CDS")

true;
LE
result: SUCCESS

/root> 
/root> task create name=CDSResponseTask
result: SUCCESS

/root> task contextref create name=CDSResponseTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=CDSResponseTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */


var uuidType = java.util.UUID;

var albumID = uuidType.fromString("d0050623-18e5-46c9-9298-9a567990cd7c");

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(albumID.toString());

var responseStatus = new java.util.HashMap();

responseStatus.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName"))
responseStatus.put("nfName", pmSubscriptionInfo.get("nfName"))
responseStatus.put("changeType", pmSubscriptionInfo.get("changeType"))

var response = executor.inFields.get("payload")

if ("failure".equals(response.get("create-subscription-response").get("odl-response").get("status"))) {
    responseStatus.put("message", "failed")
} else {
    responseStatus.put("message", "success")
}

var cdsResponseEventFields = java.util.HashMap();
cdsResponseEventFields.put("status", responseStatus);
executor.addFieldsToOutput(cdsResponseEventFields);

var logEventFields = java.util.HashMap();
logEventFields.put("final_status", "FINAL_SUCCESS");
logEventFields.put("message", "Operation successfully completed.");
executor.addFieldsToOutput(logEventFields);
true;

LE
result: SUCCESS

/root> 
/root> 
/root> ##
/root> ## POLICIES
/root> ##
/root> 
/root> 
/root> # Policy ReceiveEventPolicy
/root> policy create name=ReceiveEventPolicy template=Freestyle firstState=ReceiveSubscriptionState
result: SUCCESS

/root> 
/root> # State CreateSubscription
/root> policy state create name=ReceiveEventPolicy stateName=CreateSubscription triggerName=CreateSubscriptionPayloadEvent defaultTaskName=CreateSubscriptionRequestTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=CreateSubscription outputName=IssueCreateSubscriptionRequestOutput eventName=CreateSubscriptionRequestEvent nextState=NULL
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CreateSubscription taskName=CreateSubscriptionRequestTask outputType=DIRECT outputName=IssueCreateSubscriptionRequestOutput
result: SUCCESS

/root> policy state contextref create name=ReceiveEventPolicy stateName=CreateSubscription albumName=PMSubscriptionAlbum
result: SUCCESS

/root> 
/root> # State DeleteSubscription
/root> policy state create name=ReceiveEventPolicy stateName=DeleteSubscription triggerName=DeleteSubscriptionPayloadEvent defaultTaskName=DeleteSubscriptionRequestTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=DeleteSubscription outputName=IssueDeleteSubscriptionRequestOutput eventName=DeleteSubscriptionRequestEvent nextState=NULL
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=DeleteSubscription taskName=DeleteSubscriptionRequestTask outputType=DIRECT outputName=IssueDeleteSubscriptionRequestOutput
result: SUCCESS

/root> policy state contextref create name=ReceiveEventPolicy stateName=DeleteSubscription albumName=PMSubscriptionAlbum
result: SUCCESS

/root> 
/root> # State CreateOrDeleteState
/root> policy state create name=ReceiveEventPolicy stateName=CreateOrDeleteState triggerName=PMSubscriptionOutputEvent defaultTaskName=CreateSubscriptionPayloadTask
result: SUCCESS

/root> 
/root> policy state output create name=ReceiveEventPolicy stateName=CreateOrDeleteState outputName=CreateSubscriptionPayload eventName=CreateSubscriptionPayloadEvent nextState=CreateSubscription
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CreateOrDeleteState taskName=CreateSubscriptionPayloadTask outputType=DIRECT outputName=CreateSubscriptionPayload
result: SUCCESS

/root> 
/root> policy state output create name=ReceiveEventPolicy stateName=CreateOrDeleteState outputName=DeleteSubscriptionPayload eventName=DeleteSubscriptionPayloadEvent nextState=DeleteSubscription
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CreateOrDeleteState taskName=DeleteSubscriptionPayloadTask outputType=DIRECT outputName=DeleteSubscriptionPayload
result: SUCCESS

/root> 
/root> policy state contextref create name=ReceiveEventPolicy stateName=CreateOrDeleteState albumName=PMSubscriptionAlbum
result: SUCCESS

/root> policy state selecttasklogic create name=ReceiveEventPolicy stateName=CreateOrDeleteState logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())
var changeType = pmSubscriptionInfo.get("changeType").toString()

if ("CREATE".equals(changeType)) {
    executor.subject.getTaskKey("CreateSubscriptionPayloadTask").copyTo(executor.selectedTask);
}
else if ("DELETE".equals(changeType)) {
    executor.subject.getTaskKey("DeleteSubscriptionPayloadTask").copyTo(executor.selectedTask);
}

true;
LE
result: SUCCESS

/root> 
/root> # State ReceiveSubscriptionState
/root> policy state create name=ReceiveEventPolicy stateName=ReceiveSubscriptionState triggerName=testPolicyB defaultTaskName=ReceivePMSubscriptionTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=ReceiveSubscriptionState outputName=ReceivePMSubscriptionOutput eventName=PMSubscriptionOutputEvent nextState=CreateOrDeleteState
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=ReceiveSubscriptionState taskName=ReceivePMSubscriptionTask outputType=DIRECT outputName=ReceivePMSubscriptionOutput
result: SUCCESS

/root> policy state contextref create name=ReceiveEventPolicy stateName=ReceiveSubscriptionState albumName=PMSubscriptionAlbum
result: SUCCESS

/root> 
/root> 
/root> # Policy CDSResponsePolicy
/root> policy create name=CDSResponsePolicy template=Freestyle firstState=CDSResponseState
result: SUCCESS

/root> 
/root> # State CDSResponseState
/root> policy state create name=CDSResponsePolicy stateName=CDSResponseState triggerName=CDSResponseEvent defaultTaskName=CDSResponseTask
result: SUCCESS

/root> policy state output create name=CDSResponsePolicy stateName=CDSResponseState outputName=ResponseOutput eventName=CDSResponseStatusEvent
result: SUCCESS

/root> policy state output create name=CDSResponsePolicy stateName=CDSResponseState outputName=ResponseOutput eventName=LogEvent
result: SUCCESS

/root> policy state taskref create name=CDSResponsePolicy stateName=CDSResponseState taskName=CDSResponseTask outputType=DIRECT outputName=ResponseOutput
result: SUCCESS

/root> 
/root> validate
result: SUCCESS
{
  "name": "APEXgRPCPolicy",
  "version": "0.0.1"
}
***validation of model successful***

/root> /root> #-------------------------------------------------------------------------------
/root> # ============LICENSE_START=======================================================
/root> #  Copyright (C) 2020 Nordix Foundation.
/root> #  Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
/root> # ================================================================================
/root> # Licensed under the Apache License, Version 2.0 (the "License");
/root> # you may not use this file except in compliance with the License.
/root> # You may obtain a copy of the License at
/root> #
/root> #      http://www.apache.org/licenses/LICENSE-2.0
/root> #
/root> # Unless required by applicable law or agreed to in writing, software
/root> # distributed under the License is distributed on an "AS IS" BASIS,
/root> # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/root> # See the License for the specific language governing permissions and
/root> # limitations under the License.
/root> #
/root> # SPDX-License-Identifier: Apache-2.0
/root> # ============LICENSE_END=========================================================
/root> #-------------------------------------------------------------------------------
/root> 
/root> model create name=APEXgRPCPolicy
result: SUCCESS

/root> 
/root> ##
/root> ## SCHEMAS
/root> ##
/root> 
/root> schema create name=SimpleStringType flavour=Java schema=java.lang.String
result: SUCCESS

/root> schema create name=UUIDType         flavour=Java schema=java.util.UUID
result: SUCCESS

/root> schema create name=SimpleIntType    flavour=Java schema=java.lang.Integer
result: SUCCESS

/root> 
/root> schema create name=CDSRequestCommonHeaderType flavour=Json schema=LS
{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Root",
  "type": "object",
  "required": [
    "requestId",
    "subRequestId",
    "originatorId"
  ],
  "properties": {
    "requestId": {
      "$id": "#root/requestId",
      "title": "Requestid",
      "type": "string",
      "default": "",
      "examples": [
        "123456-1000"
      ],
      "pattern": "^.*$"
    },
    "subRequestId": {
      "$id": "#root/subRequestId",
      "title": "Subrequestid",
      "type": "string",
      "default": "",
      "examples": [
        "sub-123456-1000"
      ],
      "pattern": "^.*$"
    },
    "originatorId": {
      "$id": "#root/originatorId",
      "title": "Originatorid",
      "type": "string",
      "default": "",
      "examples": [
        "sdnc"
      ],
      "pattern": "^.*$"
    }
  }
}

LE
result: SUCCESS

/root> 
/root> schema create name=CDSResponseCommonHeaderType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "timestamp": {
      "type": "string"
    },
    "requestId": {
      "type": "string"
    },
    "subRequestId": {
      "type": "string"
    },
    "flag": {
      "type": "object"
    },
    "originatorId": {
      "type": "string"
    }
  },
  "required": [
    "timestamp",
    "requestId",
    "subRequestId",
    "flag",
    "originatorId"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=CDSActionIdentifiersType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "actionName": {
      "type": "string"
    },
    "blueprintName": {
      "type": "string"
    },
    "blueprintVersion": {
      "type": "string"
    },
    "mode": {
      "type": "string"
    }
  },
  "required": [
    "actionName",
    "blueprintName",
    "blueprintVersion",
    "mode"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=CDSResponseStatusType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "code": {
      "type": "integer"
    },
    "message": {
      "type": "string"
    },
    "eventType": {
      "type": "string"
    },
    "timestamp": {
      "type": "string"
    }
  },
  "required": [
    "code",
    "message",
    "eventType",
    "timestamp"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=CDSCreateSubscriptionPayloadType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": [
    "create-subscription-request"
  ],
  "properties": {
    "create-subscription-request": {
      "type": "object",
      "required": [
        "create-subscription-properties"
      ],
      "properties": {
        "create-subscription-properties": {
          "type": "object",
          "required": [
            "nfName",
            "administrativeState",
            "subscriptionName",
            "measurementGroups",
            "fileBasedGP",
            "fileLocation"
          ],
          "properties": {
            "nfName": {
              "type": "string",
              "default": "",
              "examples": [
                "pnf300"
              ],
              "pattern": "^.*$"
            },
            "administrativeState": {
              "type": "string",
              "default": "",
              "examples": [
                "UNLOCKED"
              ],
              "pattern": "^.*$"
            },
            "subscriptionName": {
              "type": "string",
              "default": "",
              "examples": [
                "testPolicyB"
              ],
              "pattern": "^.*$"
            },
            "measurementGroups": {
              "type": "array",
              "default": [],
              "items": {
                "type": "object",
                "required": [
                  "measurementGroup"
                ],
                "properties": {
                  "measurementGroup": {
                    "type": "object",
                    "required": [
                      "measurementTypes",
                      "managedObjectDNsBasic"
                    ],
                    "properties": {
                      "measurementTypes": {
                        "type": "array",
                        "default": [],
                        "items": {
                          "type": "object",
                          "required": [
                            "measurementType"
                          ],
                          "properties": {
                            "measurementType": {
                              "type": "string",
                              "default": "",
                              "examples": [
                                "countera"
                              ],
                              "pattern": "^.*$"
                            }
                          }
                        }
                      },
                      "managedObjectDNsBasic": {
                        "type": "array",
                        "default": [],
                        "items": {
                          "$id": "#root/create-subscription-request/create-subscription-properties/measurementGroups/items/measurementGroup/managedObjectDNsBasic/items",
                          "title": "Items",
                          "type": "object",
                          "required": [
                            "DN"
                          ],
                          "properties": {
                            "DN": {
                              "type": "string",
                              "default": "",
                              "examples": [
                                "dna"
                              ],
                              "pattern": "^.*$"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            },
            "fileBasedGP": {
              "type": "string",
              "default": "",
              "examples": [
                "15.0"
              ],
              "pattern": "^.*$"
            },
            "fileLocation": {
              "type": "string",
              "default": "",
              "examples": [
                "/pm/pm.xml"
              ],
              "pattern": "^.*$"
            }
          }
        }
      }
    }
  }
}
LE
result: SUCCESS

/root> 
/root> schema create name=CDSDeleteSubscriptionPayloadType flavour=Avro schema=LS
{
  "type": "map",
  "values": {
    "type": "record",
    "name": "CDSRequestPayloadEntry",
    "fields": [
      {
        "name": "delete_DasH_subscription_DasH_properties",
        "type": {
          "name": "delete_DasH_subscription_DasH_properties_record",
          "type": "record",
          "fields": [
            {
              "name": "nfName",
              "type": "string"
            },
            {
              "name": "subscriptionName",
              "type": "string"
            },
            {
              "name": "administrativeState",
              "type": "string"
            },
            {
              "name": "fileBasedGP",
              "type": "string"
            },
            {
              "name": "fileLocation",
              "type": "string"
            },
            {
              "name": "measurementGroups",
              "type": {
                "type": "array",
                "items": {
                  "name": "measurementGroups_record",
                  "type": "record",
                  "fields": [
                    {
                      "name": "measurementGroup",
                      "type": {
                        "name": "measurementGroup",
                        "type": "record",
                        "fields": [
                          {
                            "name": "measurementTypes",
                            "type": {
                              "type": "array",
                              "items": {
                                "name": "measurementTypes_record",
                                "type": "record",
                                "fields": [
                                  {
                                    "name": "measurementType",
                                    "type": "string"
                                  }
                                ]
                              }
                            }
                          },
                          {
                            "name": "managedObjectDNsBasic",
                            "type": {
                              "type": "array",
                              "items": {
                                "name": "managedObjectDNsBasic_record",
                                "type": "record",
                                "fields": [
                                  {
                                    "name": "DN",
                                    "type": "string"
                                  }
                                ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            }
          ]
        }
      }
    ]
  }
}
LE
result: SUCCESS

/root> 
/root> schema create name=CDSResponsePayloadType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "create-subscription-response": {
      "type": "object",
      "properties": {
        "odl-response": {
          "type": "object",
          "properties": {
            "status": {
              "type": "string"
            }
          },
          "required": [
            "status"
          ]
        }
      },
      "required": [
        "odl-response"
      ]
    }
  },
  "required": [
    "create-subscription-response"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=SubscriptionStatusType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "subscriptionName": {
      "type": "string"
    },
    "nfName": {
      "type": "string"
    },
    "changeType": {
      "type": "string"
    },
    "message": {
      "type": "string"
    }
  },
  "required": [
    "subscriptionName",
    "nfName",
    "changeType",
    "message"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=PMSubscriptionType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "changeType": {
      "type": "string"
    },
    "closedLoopControlName": {
      "type": "string"
    },
    "policyName": {
      "type": "string"
    },
    "nfName": {
      "type": "string"
    },
    "subscription": {
      "type": "array",
      "items": [
        {
          "type": "object",
          "properties": {
            "measurementGroup": {
              "type": "object",
              "properties": {
                "measurementTypes": {
                  "type": "array",
                  "items": [
                    {
                      "type": "object",
                      "properties": {
                        "measurementType": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "measurementType"
                      ]
                    },
                    {
                      "type": "object",
                      "properties": {
                        "measurementType": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "measurementType"
                      ]
                    }
                  ]
                },
                "managedObjectDNsBasic": {
                  "type": "array",
                  "items": [
                    {
                      "type": "object",
                      "properties": {
                        "DN": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "DN"
                      ]
                    },
                    {
                      "type": "object",
                      "properties": {
                        "DN": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "DN"
                      ]
                    }
                  ]
                }
              },
              "required": [
                "measurementTypes",
                "managedObjectDNsBasic"
              ]
            }
          },
          "required": [
            "measurementGroup"
          ]
        }
      ]
    }
  },
  "required": [
    "changeType",
    "closedLoopControlName",
    "policyName",
    "nfName",
    "subscription"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=SubscriptionType flavour=Json schema=LS
{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Root",
  "type": "object",
  "required": [
    "subscriptionName",
    "administrativeState",
    "fileBasedGP",
    "fileLocation",
    "measurementGroups"
  ],
  "properties": {
    "subscriptionName": {
      "$id": "#root/subscriptionName",
      "title": "Subscriptionname",
      "type": "string",
      "default": "",
      "examples": [
        "testPolicyB"
      ],
      "pattern": "^.*$"
    },
    "administrativeState": {
      "$id": "#root/administrativeState",
      "title": "Administrativestate",
      "type": "string",
      "default": "",
      "examples": [
        "UNLOCKED"
      ],
      "pattern": "^.*$"
    },
    "fileBasedGP": {
      "$id": "#root/fileBasedGP",
      "title": "Filebasedgp",
      "type": "integer",
      "examples": [
        15
      ],
      "default": 0
    },
    "fileLocation": {
      "$id": "#root/fileLocation",
      "title": "Filelocation",
      "type": "string",
      "default": "",
      "examples": [
        "/pm/pm.xml"
      ],
      "pattern": "^.*$"
    },
    "measurementGroups": {
      "$id": "#root/measurementGroups",
      "title": "Measurementgroups",
      "type": "array",
      "default": [],
      "items": {
        "$id": "#root/measurementGroups/items",
        "title": "Items",
        "type": "object",
        "required": [
          "measurementGroup"
        ],
        "properties": {
          "measurementGroup": {
            "$id": "#root/measurementGroups/items/measurementGroup",
            "title": "Measurementgroup",
            "type": "object",
            "required": [
              "measurementTypes",
              "managedObjectDNsBasic"
            ],
            "properties": {
              "measurementTypes": {
                "$id": "#root/measurementGroups/items/measurementGroup/measurementTypes",
                "title": "Measurementtypes",
                "type": "array",
                "default": [],
                "items": {
                  "$id": "#root/measurementGroups/items/measurementGroup/measurementTypes/items",
                  "title": "Items",
                  "type": "object",
                  "required": [
                    "measurementType"
                  ],
                  "properties": {
                    "measurementType": {
                      "$id": "#root/measurementGroups/items/measurementGroup/measurementTypes/items/measurementType",
                      "title": "Measurementtype",
                      "type": "string",
                      "default": "",
                      "examples": [
                        "countera"
                      ],
                      "pattern": "^.*$"
                    }
                  }
                }
              },
              "managedObjectDNsBasic": {
                "$id": "#root/measurementGroups/items/measurementGroup/managedObjectDNsBasic",
                "title": "Managedobjectdnsbasic",
                "type": "array",
                "default": [],
                "items": {
                  "$id": "#root/measurementGroups/items/measurementGroup/managedObjectDNsBasic/items",
                  "title": "Items",
                  "type": "object",
                  "required": [
                    "DN"
                  ],
                  "properties": {
                    "DN": {
                      "$id": "#root/measurementGroups/items/measurementGroup/managedObjectDNsBasic/items/DN",
                      "title": "Dn",
                      "type": "string",
                      "default": "",
                      "examples": [
                        "dna"
                      ],
                      "pattern": "^.*$"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

LE
result: SUCCESS

/root> 
/root> ##
/root> ## EVENTS
/root> ##
/root> 
/root> album create name=PMSubscriptionAlbum scope=policy writable=true schemaName=PMSubscriptionType
result: SUCCESS

/root> 
/root> # Incoming event
/root> event create name=testPolicyB version=0.0.1 nameSpace=org.onap.policy.apex.onap.pmcontrol source=DCAE target=APEX toscaPolicyState=ENTRY
result: SUCCESS

/root> event parameter create name=testPolicyB parName=nfName schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=testPolicyB parName=policyName schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=testPolicyB parName=changeType schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=testPolicyB parName=closedLoopControlName schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=testPolicyB parName=subscription schemaName=SubscriptionType
result: SUCCESS

/root> 
/root> event create name=PMSubscriptionOutputEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=PMSubscriptionOutputEvent parName=albumID     schemaName=UUIDType
result: SUCCESS

/root> 
/root> event create name=CreateSubscriptionPayloadEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=CreateSubscriptionPayloadEvent parName=payload schemaName=CDSCreateSubscriptionPayloadType
result: SUCCESS

/root> event parameter create name=CreateSubscriptionPayloadEvent parName=albumID     schemaName=UUIDType
result: SUCCESS

/root> 
/root> event create name=DeleteSubscriptionPayloadEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionPayloadEvent parName=payload schemaName=CDSDeleteSubscriptionPayloadType
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionPayloadEvent parName=albumID     schemaName=UUIDType
result: SUCCESS

/root> 
/root> event create name=CreateSubscriptionRequestEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=CreateSubscriptionRequestEvent parName=commonHeader schemaName=CDSRequestCommonHeaderType
result: SUCCESS

/root> event parameter create name=CreateSubscriptionRequestEvent parName=actionIdentifiers schemaName=CDSActionIdentifiersType
result: SUCCESS

/root> event parameter create name=CreateSubscriptionRequestEvent parName=payload schemaName=CDSCreateSubscriptionPayloadType
result: SUCCESS

/root> 
/root> event create name=DeleteSubscriptionRequestEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionRequestEvent parName=commonHeader schemaName=CDSRequestCommonHeaderType
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionRequestEvent parName=actionIdentifiers schemaName=CDSActionIdentifiersType
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionRequestEvent parName=payload schemaName=CDSDeleteSubscriptionPayloadType
result: SUCCESS

/root> 
/root> event create name=CDSResponseEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=CDS target=APEX
result: SUCCESS

/root> event parameter create name=CDSResponseEvent parName=commonHeader schemaName=CDSResponseCommonHeaderType
result: SUCCESS

/root> event parameter create name=CDSResponseEvent parName=actionIdentifiers schemaName=CDSActionIdentifiersType
result: SUCCESS

/root> event parameter create name=CDSResponseEvent parName=status schemaName=CDSResponseStatusType
result: SUCCESS

/root> event parameter create name=CDSResponseEvent parName=payload schemaName=CDSResponsePayloadType
result: SUCCESS

/root> 
/root> event create name=CDSResponseStatusEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=DCAE toscaPolicyState=EXIT_SUCCESS
result: SUCCESS

/root> event parameter create name=CDSResponseStatusEvent parName=status schemaName=SubscriptionStatusType
result: SUCCESS

/root> 
/root> event create name=LogEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=DCAE
result: SUCCESS

/root> event parameter create name=LogEvent parName=final_status schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=LogEvent parName=message schemaName=SimpleStringType
result: SUCCESS

/root> 
/root> ##
/root> ## TASKS
/root> ##
/root> 
/root> 
/root> task create name=ReceivePMSubscriptionTask
result: SUCCESS

/root> task contextref create name=ReceivePMSubscriptionTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=ReceivePMSubscriptionTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */
var uuidType = java.util.UUID;
var HashMapType = java.util.HashMap;


//albumID will be used to fetch info from our album later
var albumID = uuidType.fromString("d0050623-18e5-46c9-9298-9a567990cd7c");
var pmSubscriptionInfo = new java.util.HashMap();
var returnValue = true;;

if (executor.inFields.get("policyName") != null) {
    var changeType = executor.inFields.get("changeType")
    var nfName = executor.inFields.get("nfName")
    var policyName = executor.inFields.get("policyName")
    var closedLoopControlName = executor.inFields.get("closedLoopControlName")
    var subscription = executor.inFields.get("subscription")

    var obj = {};
    obj["nfName"] = executor.inFields.get("nfName")
    executor.logger.info("nfName" + executor.stringify2Json(obj))

    var ticketInfo = new HashMapType();
    populate_creator_info(ticketInfo);
    executor.logger.info("ticketInfo" + executor.stringify2Json(ticketInfo))

    pmSubscriptionInfo.put("nfName", executor.inFields.get("nfName"));
    pmSubscriptionInfo.put("changeType", executor.inFields.get("changeType"))
    pmSubscriptionInfo.put("policyName", executor.inFields.get("policyName"))
    pmSubscriptionInfo.put("closedLoopControlName", executor.inFields.get("closedLoopControlName"))
    pmSubscriptionInfo.put("subscription", subscription)

    executor.getContextAlbum("PMSubscriptionAlbum").put(albumID.toString(), pmSubscriptionInfo);

    executor.outFields.put("albumID", albumID)
} else {
    executor.message = "Received invalid event"
    returnValue = false;
}

function populate_creator_info(ticketInfo){
    populate_field(ticketInfo, "appId", "NSO");
    populate_field(ticketInfo, "creatorId", "fidLab");
    populate_field(ticketInfo, "creatorFirstName", "PSO");
    populate_field(ticketInfo, "creatorLastName", "team7");
    populate_field(ticketInfo, "creatorGroup", "PSO-team7");
    populate_field(ticketInfo, "creatorPEIN", "0000000");
    populate_field(ticketInfo, "creatorPhoneNumber", "800-450-7771");
    populate_field(ticketInfo, "fid", "fidLab");
    populate_field(ticketInfo, "organizationCode", "PSO");
    populate_field(ticketInfo, "source", create_caEn_value("SURV/ALARM FROM/PSO"));
    populate_field(ticketInfo, "customerName", "XYZ");
    populate_field(ticketInfo, "authorization", "Basic dGVzdHVzZXI=");
}

function populate_field(mapname, name, value){
    if (value == null){
        mapname.put(name, "none");
    } else{
        mapname.put(name, value);
    }

}

function create_caEn_value(value){
    var attr = {};
    attr["caEn"] = String(value);
    return attr;
}

returnValue;

LE
result: SUCCESS

/root> 
/root> task create name=CreateSubscriptionPayloadTask
result: SUCCESS

/root> task contextref create name=CreateSubscriptionPayloadTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=CreateSubscriptionPayloadTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())

var payloadProperties = new java.util.HashMap();

payloadProperties.put("nfName",  pmSubscriptionInfo.get("nfName"))
payloadProperties.put("subscriptionName",  pmSubscriptionInfo.get("subscription").get("subscriptionName"))
payloadProperties.put("administrativeState", pmSubscriptionInfo.get("subscription").get("administrativeState"))
payloadProperties.put("fileBasedGP",  pmSubscriptionInfo.get("subscription").get("fileBasedGP").toString())
payloadProperties.put("fileLocation", pmSubscriptionInfo.get("subscription").get("fileLocation"))
payloadProperties.put("measurementGroups", pmSubscriptionInfo.get("subscription").get("measurementGroups"))

var payloadEntry = new java.util.HashMap();
payloadEntry.put("create-subscription-properties", payloadProperties)

var payload = new java.util.HashMap();
var payloadSchemaHelper = executor.subject.getOutFieldSchemaHelper("payload");
payload.put("create-subscription-request", payloadEntry);

executor.logger.info("CDS payload - " + executor.stringify2Json( payload, payloadSchemaHelper));

executor.outFields.put("albumID", executor.inFields.get("albumID"));
executor.outFields.put("payload", payload);

executor.logger.info("Sending Create Subscription Event to CDS");

true;
LE
result: SUCCESS

/root> 
/root> task create name=DeleteSubscriptionPayloadTask
result: SUCCESS

/root> task contextref create name=DeleteSubscriptionPayloadTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=DeleteSubscriptionPayloadTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())

var payloadProperties = new java.util.HashMap();

payloadProperties.put("nfName",  pmSubscriptionInfo.get("nfName"))
payloadProperties.put("subscriptionName",  pmSubscriptionInfo.get("subscription").get("subscriptionName"))
payloadProperties.put("administrativeState", pmSubscriptionInfo.get("subscription").get("administrativeState"))
payloadProperties.put("fileBasedGP",  pmSubscriptionInfo.get("subscription").get("fileBasedGP").toString())
payloadProperties.put("fileLocation", pmSubscriptionInfo.get("subscription").get("fileLocation"))
payloadProperties.put("measurementGroups", pmSubscriptionInfo.get("subscription").get("measurementGroups"))

var payloadEntry = new java.util.HashMap();
payloadEntry.put("delete-subscription-properties", payloadProperties)

var payload = new java.util.HashMap();
payload.put("delete-subscription-request", payloadEntry);

executor.outFields.put("albumID", executor.inFields.get("albumID"))
executor.outFields.put("payload", payload);

executor.logger.info("Sending delete Subscription Event to CDS")

true;

LE
result: SUCCESS

/root> 
/root> task create name=CreateSubscriptionRequestTask
result: SUCCESS

/root> task contextref create name=CreateSubscriptionRequestTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=CreateSubscriptionRequestTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())
var payload = executor.inFields.get("payload")
var actionName = "create-subscription"

var commonHeader = new java.util.HashMap();
commonHeader.put("originatorId", "sdnc");
commonHeader.put("requestId", "123456-1000");
commonHeader.put("subRequestId", "sub-123456-1000");

var actionIdentifiers = new java.util.HashMap();
actionIdentifiers.put("actionName", actionName);
actionIdentifiers.put("blueprintName", "pm_control");
actionIdentifiers.put("blueprintVersion", "1.0.0");
actionIdentifiers.put("mode", "sync");

executor.outFields.put("commonHeader", commonHeader);
executor.outFields.put("actionIdentifiers", actionIdentifiers);
executor.outFields.put("payload", payload);

executor.logger.info("Sending Activate Subscription Event to CDS")

true;
LE
result: SUCCESS

/root> 
/root> task create name=DeleteSubscriptionRequestTask
result: SUCCESS

/root> task contextref create name=DeleteSubscriptionRequestTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=DeleteSubscriptionRequestTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())
var payload = executor.inFields.get("payload")
var actionName = "delete-subscription"

var commonHeader = new java.util.HashMap();
commonHeader.put("originatorId", "sdnc");
commonHeader.put("requestId", "123456-1000");
commonHeader.put("subRequestId", "sub-123456-1000");

var actionIdentifiers = new java.util.HashMap();
actionIdentifiers.put("actionName", actionName);
actionIdentifiers.put("blueprintName", "pm_control");
actionIdentifiers.put("blueprintVersion", "1.0.0");
actionIdentifiers.put("mode", "sync");

executor.outFields.put("commonHeader", commonHeader);
executor.outFields.put("actionIdentifiers", actionIdentifiers);
executor.outFields.put("payload", payload);

executor.logger.info("Sending Deactivate Subscription Event to CDS")

true;
LE
result: SUCCESS

/root> 
/root> task create name=CDSResponseTask
result: SUCCESS

/root> task contextref create name=CDSResponseTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=CDSResponseTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */


var uuidType = java.util.UUID;

var albumID = uuidType.fromString("d0050623-18e5-46c9-9298-9a567990cd7c");

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(albumID.toString());

var responseStatus = new java.util.HashMap();

responseStatus.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName"))
responseStatus.put("nfName", pmSubscriptionInfo.get("nfName"))
responseStatus.put("changeType", pmSubscriptionInfo.get("changeType"))

var response = executor.inFields.get("payload")

if ("failure".equals(response.get("create-subscription-response").get("odl-response").get("status"))) {
    responseStatus.put("message", "failed")
} else {
    responseStatus.put("message", "success")
}

var cdsResponseEventFields = java.util.HashMap();
cdsResponseEventFields.put("status", responseStatus);
executor.addFieldsToOutput(cdsResponseEventFields);

var logEventFields = java.util.HashMap();
logEventFields.put("final_status", "FINAL_SUCCESS");
logEventFields.put("message", "Operation successfully completed.");
executor.addFieldsToOutput(logEventFields);
true;

LE
result: SUCCESS

/root> 
/root> 
/root> ##
/root> ## POLICIES
/root> ##
/root> 
/root> 
/root> # Policy ReceiveEventPolicy
/root> policy create name=ReceiveEventPolicy template=Freestyle firstState=ReceiveSubscriptionState
result: SUCCESS

/root> 
/root> # State CreateSubscription
/root> policy state create name=ReceiveEventPolicy stateName=CreateSubscription triggerName=CreateSubscriptionPayloadEvent defaultTaskName=CreateSubscriptionRequestTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=CreateSubscription outputName=IssueCreateSubscriptionRequestOutput eventName=CreateSubscriptionRequestEvent nextState=NULL
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CreateSubscription taskName=CreateSubscriptionRequestTask outputType=DIRECT outputName=IssueCreateSubscriptionRequestOutput
result: SUCCESS

/root> policy state contextref create name=ReceiveEventPolicy stateName=CreateSubscription albumName=PMSubscriptionAlbum
result: SUCCESS

/root> 
/root> # State DeleteSubscription
/root> policy state create name=ReceiveEventPolicy stateName=DeleteSubscription triggerName=DeleteSubscriptionPayloadEvent defaultTaskName=DeleteSubscriptionRequestTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=DeleteSubscription outputName=IssueDeleteSubscriptionRequestOutput eventName=DeleteSubscriptionRequestEvent nextState=NULL
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=DeleteSubscription taskName=DeleteSubscriptionRequestTask outputType=DIRECT outputName=IssueDeleteSubscriptionRequestOutput
result: SUCCESS

/root> policy state contextref create name=ReceiveEventPolicy stateName=DeleteSubscription albumName=PMSubscriptionAlbum
result: SUCCESS

/root> 
/root> # State CreateOrDeleteState
/root> policy state create name=ReceiveEventPolicy stateName=CreateOrDeleteState triggerName=PMSubscriptionOutputEvent defaultTaskName=CreateSubscriptionPayloadTask
result: SUCCESS

/root> 
/root> policy state output create name=ReceiveEventPolicy stateName=CreateOrDeleteState outputName=CreateSubscriptionPayload eventName=CreateSubscriptionPayloadEvent nextState=CreateSubscription
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CreateOrDeleteState taskName=CreateSubscriptionPayloadTask outputType=DIRECT outputName=CreateSubscriptionPayload
result: SUCCESS

/root> 
/root> policy state output create name=ReceiveEventPolicy stateName=CreateOrDeleteState outputName=DeleteSubscriptionPayload eventName=DeleteSubscriptionPayloadEvent nextState=DeleteSubscription
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CreateOrDeleteState taskName=DeleteSubscriptionPayloadTask outputType=DIRECT outputName=DeleteSubscriptionPayload
result: SUCCESS

/root> 
/root> policy state contextref create name=ReceiveEventPolicy stateName=CreateOrDeleteState albumName=PMSubscriptionAlbum
result: SUCCESS

/root> policy state selecttasklogic create name=ReceiveEventPolicy stateName=CreateOrDeleteState logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())
var changeType = pmSubscriptionInfo.get("changeType").toString()

if ("CREATE".equals(changeType)) {
    executor.subject.getTaskKey("CreateSubscriptionPayloadTask").copyTo(executor.selectedTask);
}
else if ("DELETE".equals(changeType)) {
    executor.subject.getTaskKey("DeleteSubscriptionPayloadTask").copyTo(executor.selectedTask);
}

true;
LE
result: SUCCESS

/root> 
/root> # State ReceiveSubscriptionState
/root> policy state create name=ReceiveEventPolicy stateName=ReceiveSubscriptionState triggerName=testPolicyB defaultTaskName=ReceivePMSubscriptionTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=ReceiveSubscriptionState outputName=ReceivePMSubscriptionOutput eventName=PMSubscriptionOutputEvent nextState=CreateOrDeleteState
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=ReceiveSubscriptionState taskName=ReceivePMSubscriptionTask outputType=DIRECT outputName=ReceivePMSubscriptionOutput
result: SUCCESS

/root> policy state contextref create name=ReceiveEventPolicy stateName=ReceiveSubscriptionState albumName=PMSubscriptionAlbum
result: SUCCESS

/root> 
/root> 
/root> # Policy CDSResponsePolicy
/root> policy create name=CDSResponsePolicy template=Freestyle firstState=CDSResponseState
result: SUCCESS

/root> 
/root> # State CDSResponseState
/root> policy state create name=CDSResponsePolicy stateName=CDSResponseState triggerName=CDSResponseEvent defaultTaskName=CDSResponseTask
result: SUCCESS

/root> policy state output create name=CDSResponsePolicy stateName=CDSResponseState outputName=ResponseOutput eventName=CDSResponseStatusEvent
result: SUCCESS

/root> policy state output create name=CDSResponsePolicy stateName=CDSResponseState outputName=ResponseOutput eventName=LogEvent
result: SUCCESS

/root> policy state taskref create name=CDSResponsePolicy stateName=CDSResponseState taskName=CDSResponseTask outputType=DIRECT outputName=ResponseOutput
result: SUCCESS

/root> 
/root> validate
result: SUCCESS
{
  "name": "APEXgRPCPolicy",
  "version": "0.0.1"
}
***validation of model successful***

/root> /root> #-------------------------------------------------------------------------------
/root> # ============LICENSE_START=======================================================
/root> #  Copyright (C) 2020 Nordix Foundation.
/root> #  Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
/root> # ================================================================================
/root> # Licensed under the Apache License, Version 2.0 (the "License");
/root> # you may not use this file except in compliance with the License.
/root> # You may obtain a copy of the License at
/root> #
/root> #      http://www.apache.org/licenses/LICENSE-2.0
/root> #
/root> # Unless required by applicable law or agreed to in writing, software
/root> # distributed under the License is distributed on an "AS IS" BASIS,
/root> # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/root> # See the License for the specific language governing permissions and
/root> # limitations under the License.
/root> #
/root> # SPDX-License-Identifier: Apache-2.0
/root> # ============LICENSE_END=========================================================
/root> #-------------------------------------------------------------------------------
/root> 
/root> model create name=APEXgRPCPolicy
result: SUCCESS

/root> 
/root> ##
/root> ## SCHEMAS
/root> ##
/root> 
/root> schema create name=SimpleStringType flavour=Java schema=java.lang.String
result: SUCCESS

/root> schema create name=UUIDType         flavour=Java schema=java.util.UUID
result: SUCCESS

/root> schema create name=SimpleIntType    flavour=Java schema=java.lang.Integer
result: SUCCESS

/root> 
/root> schema create name=CDSRequestCommonHeaderType flavour=Json schema=LS
{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Root",
  "type": "object",
  "required": [
    "requestId",
    "subRequestId",
    "originatorId"
  ],
  "properties": {
    "requestId": {
      "$id": "#root/requestId",
      "title": "Requestid",
      "type": "string",
      "default": "",
      "examples": [
        "123456-1000"
      ],
      "pattern": "^.*$"
    },
    "subRequestId": {
      "$id": "#root/subRequestId",
      "title": "Subrequestid",
      "type": "string",
      "default": "",
      "examples": [
        "sub-123456-1000"
      ],
      "pattern": "^.*$"
    },
    "originatorId": {
      "$id": "#root/originatorId",
      "title": "Originatorid",
      "type": "string",
      "default": "",
      "examples": [
        "sdnc"
      ],
      "pattern": "^.*$"
    }
  }
}

LE
result: SUCCESS

/root> 
/root> schema create name=CDSResponseCommonHeaderType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "timestamp": {
      "type": "string"
    },
    "requestId": {
      "type": "string"
    },
    "subRequestId": {
      "type": "string"
    },
    "flag": {
      "type": "object"
    },
    "originatorId": {
      "type": "string"
    }
  },
  "required": [
    "timestamp",
    "requestId",
    "subRequestId",
    "flag",
    "originatorId"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=CDSActionIdentifiersType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "actionName": {
      "type": "string"
    },
    "blueprintName": {
      "type": "string"
    },
    "blueprintVersion": {
      "type": "string"
    },
    "mode": {
      "type": "string"
    }
  },
  "required": [
    "actionName",
    "blueprintName",
    "blueprintVersion",
    "mode"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=CDSResponseStatusType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "code": {
      "type": "integer"
    },
    "message": {
      "type": "string"
    },
    "eventType": {
      "type": "string"
    },
    "timestamp": {
      "type": "string"
    }
  },
  "required": [
    "code",
    "message",
    "eventType",
    "timestamp"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=CDSCreateSubscriptionPayloadType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": [
    "create-subscription-request"
  ],
  "properties": {
    "create-subscription-request": {
      "type": "object",
      "required": [
        "create-subscription-properties"
      ],
      "properties": {
        "create-subscription-properties": {
          "type": "object",
          "required": [
            "nfName",
            "administrativeState",
            "subscriptionName",
            "measurementGroups",
            "fileBasedGP",
            "fileLocation"
          ],
          "properties": {
            "nfName": {
              "type": "string",
              "default": "",
              "examples": [
                "pnf300"
              ],
              "pattern": "^.*$"
            },
            "administrativeState": {
              "type": "string",
              "default": "",
              "examples": [
                "UNLOCKED"
              ],
              "pattern": "^.*$"
            },
            "subscriptionName": {
              "type": "string",
              "default": "",
              "examples": [
                "testPolicyB"
              ],
              "pattern": "^.*$"
            },
            "measurementGroups": {
              "type": "array",
              "default": [],
              "items": {
                "type": "object",
                "required": [
                  "measurementGroup"
                ],
                "properties": {
                  "measurementGroup": {
                    "type": "object",
                    "required": [
                      "measurementTypes",
                      "managedObjectDNsBasic"
                    ],
                    "properties": {
                      "measurementTypes": {
                        "type": "array",
                        "default": [],
                        "items": {
                          "type": "object",
                          "required": [
                            "measurementType"
                          ],
                          "properties": {
                            "measurementType": {
                              "type": "string",
                              "default": "",
                              "examples": [
                                "countera"
                              ],
                              "pattern": "^.*$"
                            }
                          }
                        }
                      },
                      "managedObjectDNsBasic": {
                        "type": "array",
                        "default": [],
                        "items": {
                          "$id": "#root/create-subscription-request/create-subscription-properties/measurementGroups/items/measurementGroup/managedObjectDNsBasic/items",
                          "title": "Items",
                          "type": "object",
                          "required": [
                            "DN"
                          ],
                          "properties": {
                            "DN": {
                              "type": "string",
                              "default": "",
                              "examples": [
                                "dna"
                              ],
                              "pattern": "^.*$"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            },
            "fileBasedGP": {
              "type": "string",
              "default": "",
              "examples": [
                "15.0"
              ],
              "pattern": "^.*$"
            },
            "fileLocation": {
              "type": "string",
              "default": "",
              "examples": [
                "/pm/pm.xml"
              ],
              "pattern": "^.*$"
            }
          }
        }
      }
    }
  }
}
LE
result: SUCCESS

/root> 
/root> schema create name=CDSDeleteSubscriptionPayloadType flavour=Avro schema=LS
{
  "type": "map",
  "values": {
    "type": "record",
    "name": "CDSRequestPayloadEntry",
    "fields": [
      {
        "name": "delete_DasH_subscription_DasH_properties",
        "type": {
          "name": "delete_DasH_subscription_DasH_properties_record",
          "type": "record",
          "fields": [
            {
              "name": "nfName",
              "type": "string"
            },
            {
              "name": "subscriptionName",
              "type": "string"
            },
            {
              "name": "administrativeState",
              "type": "string"
            },
            {
              "name": "fileBasedGP",
              "type": "string"
            },
            {
              "name": "fileLocation",
              "type": "string"
            },
            {
              "name": "measurementGroups",
              "type": {
                "type": "array",
                "items": {
                  "name": "measurementGroups_record",
                  "type": "record",
                  "fields": [
                    {
                      "name": "measurementGroup",
                      "type": {
                        "name": "measurementGroup",
                        "type": "record",
                        "fields": [
                          {
                            "name": "measurementTypes",
                            "type": {
                              "type": "array",
                              "items": {
                                "name": "measurementTypes_record",
                                "type": "record",
                                "fields": [
                                  {
                                    "name": "measurementType",
                                    "type": "string"
                                  }
                                ]
                              }
                            }
                          },
                          {
                            "name": "managedObjectDNsBasic",
                            "type": {
                              "type": "array",
                              "items": {
                                "name": "managedObjectDNsBasic_record",
                                "type": "record",
                                "fields": [
                                  {
                                    "name": "DN",
                                    "type": "string"
                                  }
                                ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            }
          ]
        }
      }
    ]
  }
}
LE
result: SUCCESS

/root> 
/root> schema create name=CDSResponsePayloadType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "create-subscription-response": {
      "type": "object",
      "properties": {
        "odl-response": {
          "type": "object",
          "properties": {
            "status": {
              "type": "string"
            }
          },
          "required": [
            "status"
          ]
        }
      },
      "required": [
        "odl-response"
      ]
    }
  },
  "required": [
    "create-subscription-response"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=SubscriptionStatusType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "subscriptionName": {
      "type": "string"
    },
    "nfName": {
      "type": "string"
    },
    "changeType": {
      "type": "string"
    },
    "message": {
      "type": "string"
    }
  },
  "required": [
    "subscriptionName",
    "nfName",
    "changeType",
    "message"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=PMSubscriptionType flavour=Json schema=LS
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "changeType": {
      "type": "string"
    },
    "closedLoopControlName": {
      "type": "string"
    },
    "policyName": {
      "type": "string"
    },
    "nfName": {
      "type": "string"
    },
    "subscription": {
      "type": "array",
      "items": [
        {
          "type": "object",
          "properties": {
            "measurementGroup": {
              "type": "object",
              "properties": {
                "measurementTypes": {
                  "type": "array",
                  "items": [
                    {
                      "type": "object",
                      "properties": {
                        "measurementType": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "measurementType"
                      ]
                    },
                    {
                      "type": "object",
                      "properties": {
                        "measurementType": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "measurementType"
                      ]
                    }
                  ]
                },
                "managedObjectDNsBasic": {
                  "type": "array",
                  "items": [
                    {
                      "type": "object",
                      "properties": {
                        "DN": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "DN"
                      ]
                    },
                    {
                      "type": "object",
                      "properties": {
                        "DN": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "DN"
                      ]
                    }
                  ]
                }
              },
              "required": [
                "measurementTypes",
                "managedObjectDNsBasic"
              ]
            }
          },
          "required": [
            "measurementGroup"
          ]
        }
      ]
    }
  },
  "required": [
    "changeType",
    "closedLoopControlName",
    "policyName",
    "nfName",
    "subscription"
  ]
}

LE
result: SUCCESS

/root> 
/root> schema create name=SubscriptionType flavour=Json schema=LS
{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Root",
  "type": "object",
  "required": [
    "subscriptionName",
    "administrativeState",
    "fileBasedGP",
    "fileLocation",
    "measurementGroups"
  ],
  "properties": {
    "subscriptionName": {
      "$id": "#root/subscriptionName",
      "title": "Subscriptionname",
      "type": "string",
      "default": "",
      "examples": [
        "testPolicyB"
      ],
      "pattern": "^.*$"
    },
    "administrativeState": {
      "$id": "#root/administrativeState",
      "title": "Administrativestate",
      "type": "string",
      "default": "",
      "examples": [
        "UNLOCKED"
      ],
      "pattern": "^.*$"
    },
    "fileBasedGP": {
      "$id": "#root/fileBasedGP",
      "title": "Filebasedgp",
      "type": "integer",
      "examples": [
        15
      ],
      "default": 0
    },
    "fileLocation": {
      "$id": "#root/fileLocation",
      "title": "Filelocation",
      "type": "string",
      "default": "",
      "examples": [
        "/pm/pm.xml"
      ],
      "pattern": "^.*$"
    },
    "measurementGroups": {
      "$id": "#root/measurementGroups",
      "title": "Measurementgroups",
      "type": "array",
      "default": [],
      "items": {
        "$id": "#root/measurementGroups/items",
        "title": "Items",
        "type": "object",
        "required": [
          "measurementGroup"
        ],
        "properties": {
          "measurementGroup": {
            "$id": "#root/measurementGroups/items/measurementGroup",
            "title": "Measurementgroup",
            "type": "object",
            "required": [
              "measurementTypes",
              "managedObjectDNsBasic"
            ],
            "properties": {
              "measurementTypes": {
                "$id": "#root/measurementGroups/items/measurementGroup/measurementTypes",
                "title": "Measurementtypes",
                "type": "array",
                "default": [],
                "items": {
                  "$id": "#root/measurementGroups/items/measurementGroup/measurementTypes/items",
                  "title": "Items",
                  "type": "object",
                  "required": [
                    "measurementType"
                  ],
                  "properties": {
                    "measurementType": {
                      "$id": "#root/measurementGroups/items/measurementGroup/measurementTypes/items/measurementType",
                      "title": "Measurementtype",
                      "type": "string",
                      "default": "",
                      "examples": [
                        "countera"
                      ],
                      "pattern": "^.*$"
                    }
                  }
                }
              },
              "managedObjectDNsBasic": {
                "$id": "#root/measurementGroups/items/measurementGroup/managedObjectDNsBasic",
                "title": "Managedobjectdnsbasic",
                "type": "array",
                "default": [],
                "items": {
                  "$id": "#root/measurementGroups/items/measurementGroup/managedObjectDNsBasic/items",
                  "title": "Items",
                  "type": "object",
                  "required": [
                    "DN"
                  ],
                  "properties": {
                    "DN": {
                      "$id": "#root/measurementGroups/items/measurementGroup/managedObjectDNsBasic/items/DN",
                      "title": "Dn",
                      "type": "string",
                      "default": "",
                      "examples": [
                        "dna"
                      ],
                      "pattern": "^.*$"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

LE
result: SUCCESS

/root> 
/root> ##
/root> ## EVENTS
/root> ##
/root> 
/root> album create name=PMSubscriptionAlbum scope=policy writable=true schemaName=PMSubscriptionType
result: SUCCESS

/root> 
/root> # Incoming event
/root> event create name=testPolicyB version=0.0.1 nameSpace=org.onap.policy.apex.onap.pmcontrol source=DCAE target=APEX toscaPolicyState=ENTRY
result: SUCCESS

/root> event parameter create name=testPolicyB parName=nfName schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=testPolicyB parName=policyName schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=testPolicyB parName=changeType schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=testPolicyB parName=closedLoopControlName schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=testPolicyB parName=subscription schemaName=SubscriptionType
result: SUCCESS

/root> 
/root> event create name=PMSubscriptionOutputEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=PMSubscriptionOutputEvent parName=albumID     schemaName=UUIDType
result: SUCCESS

/root> 
/root> event create name=CreateSubscriptionPayloadEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=CreateSubscriptionPayloadEvent parName=payload schemaName=CDSCreateSubscriptionPayloadType
result: SUCCESS

/root> event parameter create name=CreateSubscriptionPayloadEvent parName=albumID     schemaName=UUIDType
result: SUCCESS

/root> 
/root> event create name=DeleteSubscriptionPayloadEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionPayloadEvent parName=payload schemaName=CDSDeleteSubscriptionPayloadType
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionPayloadEvent parName=albumID     schemaName=UUIDType
result: SUCCESS

/root> 
/root> event create name=CreateSubscriptionRequestEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=CreateSubscriptionRequestEvent parName=commonHeader schemaName=CDSRequestCommonHeaderType
result: SUCCESS

/root> event parameter create name=CreateSubscriptionRequestEvent parName=actionIdentifiers schemaName=CDSActionIdentifiersType
result: SUCCESS

/root> event parameter create name=CreateSubscriptionRequestEvent parName=payload schemaName=CDSCreateSubscriptionPayloadType
result: SUCCESS

/root> 
/root> event create name=DeleteSubscriptionRequestEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=APEX
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionRequestEvent parName=commonHeader schemaName=CDSRequestCommonHeaderType
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionRequestEvent parName=actionIdentifiers schemaName=CDSActionIdentifiersType
result: SUCCESS

/root> event parameter create name=DeleteSubscriptionRequestEvent parName=payload schemaName=CDSDeleteSubscriptionPayloadType
result: SUCCESS

/root> 
/root> event create name=CDSResponseEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=CDS target=APEX
result: SUCCESS

/root> event parameter create name=CDSResponseEvent parName=commonHeader schemaName=CDSResponseCommonHeaderType
result: SUCCESS

/root> event parameter create name=CDSResponseEvent parName=actionIdentifiers schemaName=CDSActionIdentifiersType
result: SUCCESS

/root> event parameter create name=CDSResponseEvent parName=status schemaName=CDSResponseStatusType
result: SUCCESS

/root> event parameter create name=CDSResponseEvent parName=payload schemaName=CDSResponsePayloadType
result: SUCCESS

/root> 
/root> event create name=CDSResponseStatusEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=DCAE toscaPolicyState=EXIT_SUCCESS
result: SUCCESS

/root> event parameter create name=CDSResponseStatusEvent parName=status schemaName=SubscriptionStatusType
result: SUCCESS

/root> 
/root> event create name=LogEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=DCAE
result: SUCCESS

/root> event parameter create name=LogEvent parName=final_status schemaName=SimpleStringType
result: SUCCESS

/root> event parameter create name=LogEvent parName=message schemaName=SimpleStringType
result: SUCCESS

/root> 
/root> ##
/root> ## TASKS
/root> ##
/root> 
/root> 
/root> task create name=ReceivePMSubscriptionTask
result: SUCCESS

/root> task contextref create name=ReceivePMSubscriptionTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=ReceivePMSubscriptionTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */
var uuidType = java.util.UUID;
var HashMapType = java.util.HashMap;


//albumID will be used to fetch info from our album later
var albumID = uuidType.fromString("d0050623-18e5-46c9-9298-9a567990cd7c");
var pmSubscriptionInfo = new java.util.HashMap();
var returnValue = true;;

if (executor.inFields.get("policyName") != null) {
    var changeType = executor.inFields.get("changeType")
    var nfName = executor.inFields.get("nfName")
    var policyName = executor.inFields.get("policyName")
    var closedLoopControlName = executor.inFields.get("closedLoopControlName")
    var subscription = executor.inFields.get("subscription")

    var obj = {};
    obj["nfName"] = executor.inFields.get("nfName")
    executor.logger.info("nfName" + executor.stringify2Json(obj))

    var ticketInfo = new HashMapType();
    populate_creator_info(ticketInfo);
    executor.logger.info("ticketInfo" + executor.stringify2Json(ticketInfo))

    pmSubscriptionInfo.put("nfName", executor.inFields.get("nfName"));
    pmSubscriptionInfo.put("changeType", executor.inFields.get("changeType"))
    pmSubscriptionInfo.put("policyName", executor.inFields.get("policyName"))
    pmSubscriptionInfo.put("closedLoopControlName", executor.inFields.get("closedLoopControlName"))
    pmSubscriptionInfo.put("subscription", subscription)

    executor.getContextAlbum("PMSubscriptionAlbum").put(albumID.toString(), pmSubscriptionInfo);

    executor.outFields.put("albumID", albumID)
} else {
    executor.message = "Received invalid event"
    returnValue = false;
}

function populate_creator_info(ticketInfo){
    populate_field(ticketInfo, "appId", "NSO");
    populate_field(ticketInfo, "creatorId", "fidLab");
    populate_field(ticketInfo, "creatorFirstName", "PSO");
    populate_field(ticketInfo, "creatorLastName", "team7");
    populate_field(ticketInfo, "creatorGroup", "PSO-team7");
    populate_field(ticketInfo, "creatorPEIN", "0000000");
    populate_field(ticketInfo, "creatorPhoneNumber", "800-450-7771");
    populate_field(ticketInfo, "fid", "fidLab");
    populate_field(ticketInfo, "organizationCode", "PSO");
    populate_field(ticketInfo, "source", create_caEn_value("SURV/ALARM FROM/PSO"));
    populate_field(ticketInfo, "customerName", "XYZ");
    populate_field(ticketInfo, "authorization", "Basic dGVzdHVzZXI=");
}

function populate_field(mapname, name, value){
    if (value == null){
        mapname.put(name, "none");
    } else{
        mapname.put(name, value);
    }

}

function create_caEn_value(value){
    var attr = {};
    attr["caEn"] = String(value);
    return attr;
}

returnValue;

LE
result: SUCCESS

/root> 
/root> task create name=CreateSubscriptionPayloadTask
result: SUCCESS

/root> task contextref create name=CreateSubscriptionPayloadTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=CreateSubscriptionPayloadTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())

var payloadProperties = new java.util.HashMap();

payloadProperties.put("nfName",  pmSubscriptionInfo.get("nfName"))
payloadProperties.put("subscriptionName",  pmSubscriptionInfo.get("subscription").get("subscriptionName"))
payloadProperties.put("administrativeState", pmSubscriptionInfo.get("subscription").get("administrativeState"))
payloadProperties.put("fileBasedGP",  pmSubscriptionInfo.get("subscription").get("fileBasedGP").toString())
payloadProperties.put("fileLocation", pmSubscriptionInfo.get("subscription").get("fileLocation"))
payloadProperties.put("measurementGroups", pmSubscriptionInfo.get("subscription").get("measurementGroups"))

var payloadEntry = new java.util.HashMap();
payloadEntry.put("create-subscription-properties", payloadProperties)

var payload = new java.util.HashMap();
var payloadSchemaHelper = executor.subject.getOutFieldSchemaHelper("payload");
payload.put("create-subscription-request", payloadEntry);

executor.logger.info("CDS payload - " + executor.stringify2Json( payload, payloadSchemaHelper));

executor.outFields.put("albumID", executor.inFields.get("albumID"));
executor.outFields.put("payload", payload);

executor.logger.info("Sending Create Subscription Event to CDS");

true;
LE
result: SUCCESS

/root> 
/root> task create name=DeleteSubscriptionPayloadTask
result: SUCCESS

/root> task contextref create name=DeleteSubscriptionPayloadTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=DeleteSubscriptionPayloadTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())

var payloadProperties = new java.util.HashMap();

payloadProperties.put("nfName",  pmSubscriptionInfo.get("nfName"))
payloadProperties.put("subscriptionName",  pmSubscriptionInfo.get("subscription").get("subscriptionName"))
payloadProperties.put("administrativeState", pmSubscriptionInfo.get("subscription").get("administrativeState"))
payloadProperties.put("fileBasedGP",  pmSubscriptionInfo.get("subscription").get("fileBasedGP").toString())
payloadProperties.put("fileLocation", pmSubscriptionInfo.get("subscription").get("fileLocation"))
payloadProperties.put("measurementGroups", pmSubscriptionInfo.get("subscription").get("measurementGroups"))

var payloadEntry = new java.util.HashMap();
payloadEntry.put("delete-subscription-properties", payloadProperties)

var payload = new java.util.HashMap();
payload.put("delete-subscription-request", payloadEntry);

executor.outFields.put("albumID", executor.inFields.get("albumID"))
executor.outFields.put("payload", payload);

executor.logger.info("Sending delete Subscription Event to CDS")

true;

LE
result: SUCCESS

/root> 
/root> task create name=CreateSubscriptionRequestTask
result: SUCCESS

/root> task contextref create name=CreateSubscriptionRequestTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=CreateSubscriptionRequestTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())
var payload = executor.inFields.get("payload")
var actionName = "create-subscription"

var commonHeader = new java.util.HashMap();
commonHeader.put("originatorId", "sdnc");
commonHeader.put("requestId", "123456-1000");
commonHeader.put("subRequestId", "sub-123456-1000");

var actionIdentifiers = new java.util.HashMap();
actionIdentifiers.put("actionName", actionName);
actionIdentifiers.put("blueprintName", "pm_control");
actionIdentifiers.put("blueprintVersion", "1.0.0");
actionIdentifiers.put("mode", "sync");

executor.outFields.put("commonHeader", commonHeader);
executor.outFields.put("actionIdentifiers", actionIdentifiers);
executor.outFields.put("payload", payload);

executor.logger.info("Sending Activate Subscription Event to CDS")

true;
LE
result: SUCCESS

/root> 
/root> task create name=DeleteSubscriptionRequestTask
result: SUCCESS

/root> task contextref create name=DeleteSubscriptionRequestTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=DeleteSubscriptionRequestTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())
var payload = executor.inFields.get("payload")
var actionName = "delete-subscription"

var commonHeader = new java.util.HashMap();
commonHeader.put("originatorId", "sdnc");
commonHeader.put("requestId", "123456-1000");
commonHeader.put("subRequestId", "sub-123456-1000");

var actionIdentifiers = new java.util.HashMap();
actionIdentifiers.put("actionName", actionName);
actionIdentifiers.put("blueprintName", "pm_control");
actionIdentifiers.put("blueprintVersion", "1.0.0");
actionIdentifiers.put("mode", "sync");

executor.outFields.put("commonHeader", commonHeader);
executor.outFields.put("actionIdentifiers", actionIdentifiers);
executor.outFields.put("payload", payload);

executor.logger.info("Sending Deactivate Subscription Event to CDS")

true;
LE
result: SUCCESS

/root> 
/root> task create name=CDSResponseTask
result: SUCCESS

/root> task contextref create name=CDSResponseTask albumName=PMSubscriptionAlbum
result: SUCCESS

/root> task logic create name=CDSResponseTask logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix. All rights reserved.
 *  Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */


var uuidType = java.util.UUID;

var albumID = uuidType.fromString("d0050623-18e5-46c9-9298-9a567990cd7c");

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(albumID.toString());

var responseStatus = new java.util.HashMap();

responseStatus.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName"))
responseStatus.put("nfName", pmSubscriptionInfo.get("nfName"))
responseStatus.put("changeType", pmSubscriptionInfo.get("changeType"))

var response = executor.inFields.get("payload")

if ("failure".equals(response.get("create-subscription-response").get("odl-response").get("status"))) {
    responseStatus.put("message", "failed")
} else {
    responseStatus.put("message", "success")
}

var cdsResponseEventFields = java.util.HashMap();
cdsResponseEventFields.put("status", responseStatus);
executor.addFieldsToOutput(cdsResponseEventFields);

var logEventFields = java.util.HashMap();
logEventFields.put("final_status", "FINAL_SUCCESS");
logEventFields.put("message", "Operation successfully completed.");
executor.addFieldsToOutput(logEventFields);
true;

LE
result: SUCCESS

/root> 
/root> 
/root> ##
/root> ## POLICIES
/root> ##
/root> 
/root> 
/root> # Policy ReceiveEventPolicy
/root> policy create name=ReceiveEventPolicy template=Freestyle firstState=ReceiveSubscriptionState
result: SUCCESS

/root> 
/root> # State CreateSubscription
/root> policy state create name=ReceiveEventPolicy stateName=CreateSubscription triggerName=CreateSubscriptionPayloadEvent defaultTaskName=CreateSubscriptionRequestTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=CreateSubscription outputName=IssueCreateSubscriptionRequestOutput eventName=CreateSubscriptionRequestEvent nextState=NULL
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CreateSubscription taskName=CreateSubscriptionRequestTask outputType=DIRECT outputName=IssueCreateSubscriptionRequestOutput
result: SUCCESS

/root> policy state contextref create name=ReceiveEventPolicy stateName=CreateSubscription albumName=PMSubscriptionAlbum
result: SUCCESS

/root> 
/root> # State DeleteSubscription
/root> policy state create name=ReceiveEventPolicy stateName=DeleteSubscription triggerName=DeleteSubscriptionPayloadEvent defaultTaskName=DeleteSubscriptionRequestTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=DeleteSubscription outputName=IssueDeleteSubscriptionRequestOutput eventName=DeleteSubscriptionRequestEvent nextState=NULL
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=DeleteSubscription taskName=DeleteSubscriptionRequestTask outputType=DIRECT outputName=IssueDeleteSubscriptionRequestOutput
result: SUCCESS

/root> policy state contextref create name=ReceiveEventPolicy stateName=DeleteSubscription albumName=PMSubscriptionAlbum
result: SUCCESS

/root> 
/root> # State CreateOrDeleteState
/root> policy state create name=ReceiveEventPolicy stateName=CreateOrDeleteState triggerName=PMSubscriptionOutputEvent defaultTaskName=CreateSubscriptionPayloadTask
result: SUCCESS

/root> 
/root> policy state output create name=ReceiveEventPolicy stateName=CreateOrDeleteState outputName=CreateSubscriptionPayload eventName=CreateSubscriptionPayloadEvent nextState=CreateSubscription
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CreateOrDeleteState taskName=CreateSubscriptionPayloadTask outputType=DIRECT outputName=CreateSubscriptionPayload
result: SUCCESS

/root> 
/root> policy state output create name=ReceiveEventPolicy stateName=CreateOrDeleteState outputName=DeleteSubscriptionPayload eventName=DeleteSubscriptionPayloadEvent nextState=DeleteSubscription
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=CreateOrDeleteState taskName=DeleteSubscriptionPayloadTask outputType=DIRECT outputName=DeleteSubscriptionPayload
result: SUCCESS

/root> 
/root> policy state contextref create name=ReceiveEventPolicy stateName=CreateOrDeleteState albumName=PMSubscriptionAlbum
result: SUCCESS

/root> policy state selecttasklogic create name=ReceiveEventPolicy stateName=CreateOrDeleteState logicFlavour=JAVASCRIPT logic=LS
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2020 Nordix Foundation.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

executor.logger.info(executor.subject.id);

var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString())
var changeType = pmSubscriptionInfo.get("changeType").toString()

if ("CREATE".equals(changeType)) {
    executor.subject.getTaskKey("CreateSubscriptionPayloadTask").copyTo(executor.selectedTask);
}
else if ("DELETE".equals(changeType)) {
    executor.subject.getTaskKey("DeleteSubscriptionPayloadTask").copyTo(executor.selectedTask);
}

true;
LE
result: SUCCESS

/root> 
/root> # State ReceiveSubscriptionState
/root> policy state create name=ReceiveEventPolicy stateName=ReceiveSubscriptionState triggerName=testPolicyB defaultTaskName=ReceivePMSubscriptionTask
result: SUCCESS

/root> policy state output create name=ReceiveEventPolicy stateName=ReceiveSubscriptionState outputName=ReceivePMSubscriptionOutput eventName=PMSubscriptionOutputEvent nextState=CreateOrDeleteState
result: SUCCESS

/root> policy state taskref create name=ReceiveEventPolicy stateName=ReceiveSubscriptionState taskName=ReceivePMSubscriptionTask outputType=DIRECT outputName=ReceivePMSubscriptionOutput
result: SUCCESS

/root> policy state contextref create name=ReceiveEventPolicy stateName=ReceiveSubscriptionState albumName=PMSubscriptionAlbum
result: SUCCESS

/root> 
/root> 
/root> # Policy CDSResponsePolicy
/root> policy create name=CDSResponsePolicy template=Freestyle firstState=CDSResponseState
result: SUCCESS

/root> 
/root> # State CDSResponseState
/root> policy state create name=CDSResponsePolicy stateName=CDSResponseState triggerName=CDSResponseEvent defaultTaskName=CDSResponseTask
result: SUCCESS

/root> policy state output create name=CDSResponsePolicy stateName=CDSResponseState outputName=ResponseOutput eventName=CDSResponseStatusEvent
result: SUCCESS

/root> policy state output create name=CDSResponsePolicy stateName=CDSResponseState outputName=ResponseOutput eventName=LogEvent
result: SUCCESS

/root> policy state taskref create name=CDSResponsePolicy stateName=CDSResponseState taskName=CDSResponseTask outputType=DIRECT outputName=ResponseOutput
result: SUCCESS

/root> 
/root> validate
result: SUCCESS
{
  "name": "APEXgRPCPolicy",
  "version": "0.0.1"
}
***validation of model successful***

/root> 