--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * OPENECOMP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.openecomp.mso.bpmn.infrastructure.scripts;\r
+\r
+import static org.apache.commons.lang3.StringUtils.*;\r
+import groovy.xml.XmlUtil\r
+import groovy.json.*\r
+import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor \r
+import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil \r
+import org.openecomp.mso.bpmn.core.WorkflowException \r
+import org.openecomp.mso.bpmn.core.json.JsonUtils \r
+import org.openecomp.mso.rest.APIResponse\r
+\r
+import java.util.UUID;\r
+\r
+import org.camunda.bpm.engine.delegate.BpmnError \r
+import org.camunda.bpm.engine.runtime.Execution\r
+import org.apache.commons.lang3.*\r
+import org.apache.commons.codec.binary.Base64;\r
+import org.springframework.web.util.UriUtils \r
+import org.openecomp.mso.rest.RESTClient \r
+import org.openecomp.mso.rest.RESTConfig\r
+import org.openecomp.mso.rest.APIResponse;\r
+\r
+/**\r
+ * This groovy class supports the <class>CreateSDNCCNetworkResource.bpmn</class> process.\r
+ * flow for SDNC Network Resource Create\r
+ */\r
+public class CreateSDNCCNetworkResource extends AbstractServiceTaskProcessor {\r
+\r
+ String vfcUrl = "/vfc/rest/v1/vfcadapter"\r
+ \r
+ String host = "http://mso.mso.testlab.openecomp.org:8080"\r
+ \r
+ ExceptionUtil exceptionUtil = new ExceptionUtil()\r
+\r
+ JsonUtils jsonUtil = new JsonUtils()\r
+ \r
+ /**\r
+ * Pre Process the BPMN Flow Request\r
+ * Inclouds:\r
+ * generate the nsOperationKey\r
+ * generate the nsParameters\r
+ */\r
+ public void preProcessRequest (Execution execution) {\r
+ def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
+ String msg = ""\r
+ utils.log("INFO", " *** preProcessRequest() *** ", isDebugEnabled)\r
+ try {\r
+ //deal with nsName and Description\r
+ String nsServiceName = execution.getVariable("nsServiceName")\r
+ String nsServiceDescription = execution.getVariable("nsServiceDescription")\r
+ utils.log("INFO", "nsServiceName:" + nsServiceName + " nsServiceDescription:" + nsServiceDescription, isDebugEnabled)\r
+ //deal with operation key\r
+ String globalSubscriberId = execution.getVariable("globalSubscriberId")\r
+ utils.log("INFO", "globalSubscriberId:" + globalSubscriberId, isDebugEnabled)\r
+ String serviceType = execution.getVariable("serviceType")\r
+ utils.log("INFO", "serviceType:" + serviceType, isDebugEnabled)\r
+ String serviceId = execution.getVariable("serviceId")\r
+ utils.log("INFO", "serviceId:" + serviceId, isDebugEnabled)\r
+ String operationId = execution.getVariable("operationId")\r
+ utils.log("INFO", "serviceType:" + serviceType, isDebugEnabled)\r
+ String nodeTemplateUUID = execution.getVariable("resourceUUID")\r
+ utils.log("INFO", "nodeTemplateUUID:" + nodeTemplateUUID, isDebugEnabled)\r
+ /*\r
+ * segmentInformation needed as a object of segment\r
+ * {\r
+ * "domain":"",\r
+ * "nodeTemplateName":"",\r
+ * "nodeType":"",\r
+ * "nsParameters":{\r
+ * //this is the nsParameters sent to VF-C\r
+ * }\r
+ * }\r
+ */\r
+ String nsParameters = execution.getVariable("resourceParameters")\r
+ utils.log("INFO", "nsParameters:" + nsParameters, isDebugEnabled)\r
+ String nsOperationKey = """{\r
+ "globalSubscriberId":"${globalSubscriberId}",\r
+ "serviceType":"${serviceType}",\r
+ "serviceId":"${serviceId}",\r
+ "operationId":"${operationId}",\r
+ "nodeTemplateUUID":"${nodeTemplateUUID}"\r
+ }"""\r
+ execution.setVariable("nsOperationKey", nsOperationKey);\r
+ execution.setVariable("nsParameters", nsParameters)\r
+ \r
+\r
+ } catch (BpmnError e) {\r
+ throw e;\r
+ } catch (Exception ex){\r
+ msg = "Exception in preProcessRequest " + ex.getMessage()\r
+ utils.log("INFO", msg, isDebugEnabled)\r
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)\r
+ }\r
+ utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)\r
+ }\r
+\r
+ \r
+ /**\r
+ * post request\r
+ * url: the url of the request\r
+ * requestBody: the body of the request\r
+ */\r
+ private APIResponse postRequest(Execution execution, String url, String requestBody){\r
+ def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
+ utils.log("INFO"," ***** Started Execute VFC adapter Post Process *****", isDebugEnabled)\r
+ utils.log("INFO","url:"+url +"\nrequestBody:"+ requestBody, isDebugEnabled)\r
+ APIResponse apiResponse = null\r
+ try{\r
+ RESTConfig config = new RESTConfig(url);\r
+ RESTClient client = new RESTClient(config).addHeader("Content-Type", "application/json").addHeader("Accept","application/json").addHeader("Authorization","Basic QlBFTENsaWVudDpwYXNzd29yZDEk");\r
+ apiResponse = client.httpPost(requestBody)\r
+ utils.log("INFO","response code:"+ apiResponse.getStatusCode() +"\nresponse body:"+ apiResponse.getResponseBodyAsString(), isDebugEnabled) \r
+ utils.log("INFO","======== Completed Execute VF-C adapter Post Process ======== ", isDebugEnabled)\r
+ }catch(Exception e){\r
+ utils.log("ERROR","Exception occured while executing AAI Post Call. Exception is: \n" + e, isDebugEnabled)\r
+ throw new BpmnError("MSOWorkflowException")\r
+ } \r
+ return apiResponse\r
+ }\r
+ \r
+ public void postCreateSDNCCall(Execution execution){\r
+ \r
+ }\r
+}\r