From 62cb1e3f3e41bdca2f9e2e3cf4e8890da34c7e76 Mon Sep 17 00:00:00 2001 From: chenchuanyu Date: Mon, 30 Mar 2020 17:00:28 +0800 Subject: Move the groovy script to the right folder Move the groovy script to the right folder Issue-ID: SO-2368 Change-Id: I9bf70d038c2893115e9cfd728e6d1ceafb94e2c1 Signed-off-by: chenchuanyu Change-Id: I01f4a31808626ecb91cf1b2b25131e5edee308ad (cherry picked from commit 7afcb6b9c3be874059580ef75158ebecedfb6bc9) --- .../infrastructure/HandleOrchestrationTask.groovy | 127 --------------------- .../scripts/HandleOrchestrationTask.groovy | 127 +++++++++++++++++++++ 2 files changed, 127 insertions(+), 127 deletions(-) delete mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/HandleOrchestrationTask.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/HandleOrchestrationTask.groovy (limited to 'bpmn/so-bpmn-infrastructure-common/src/main') diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/HandleOrchestrationTask.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/HandleOrchestrationTask.groovy deleted file mode 100644 index 89490ff620..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/HandleOrchestrationTask.groovy +++ /dev/null @@ -1,127 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.infrastructure.scripts - -import com.fasterxml.jackson.databind.ObjectMapper -import org.onap.so.db.request.beans.OrchestrationTask - -import static org.apache.commons.lang3.StringUtils.* -import org.camunda.bpm.engine.delegate.DelegateExecution -import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor -import org.onap.so.bpmn.common.scripts.ExceptionUtil -import org.onap.so.bpmn.core.UrnPropertiesReader -import org.slf4j.Logger -import org.slf4j.LoggerFactory - -class HandleOrchestrationTask extends AbstractServiceTaskProcessor { - private static final Logger logger = LoggerFactory.getLogger(HandleOrchestrationTask.class) - - ExceptionUtil exceptionUtil = new ExceptionUtil() - def supportedMethod = ["GET", "POST", "PUT"] - def validStatus = [200, 201] - - @Override - public void preProcessRequest(DelegateExecution execution) { - logger.debug("Start preProcessRequest") - String method = execution.getVariable("method") - if (!supportedMethod.contains(method)) { - String msg = "Method: " + method + " is not supported" - logger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - - String taskId = execution.getVariable("taskId") - if (isBlank(taskId)) { - String msg = "taskId is empty" - logger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - - def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.requestDb.endpoint",execution) - def orchestrationTaskEndpoint = dbAdapterEndpoint + "/orchestrationTask/" - if (!"POST".equals(method)) { - orchestrationTaskEndpoint = orchestrationTaskEndpoint + taskId - } - execution.setVariable("url", orchestrationTaskEndpoint) - logger.debug("DB Adapter Endpoint is: " + orchestrationTaskEndpoint) - def dbAdapterAuth = UrnPropertiesReader.getVariable("mso.adapters.requestDb.auth") - Map headerMap = [:] - headerMap.put("content-type", "application/json") - headerMap.put("Authorization", dbAdapterAuth) - execution.setVariable("headerMap", headerMap) - logger.debug("DB Adapter Header is: " + headerMap) - - String requestId = execution.getVariable("requestId") - if (("POST".equals(method) || "PUT".equals(method)) && isBlank(requestId)) { - String msg = "requestId is empty" - logger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - String taskName = execution.getVariable("taskName") - if (("POST".equals(method) || "PUT".equals(method)) && isBlank(taskName)) { - String msg = "task name is empty" - logger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - String taskStatus = execution.getVariable("taskStatus") - if (("POST".equals(method) || "PUT".equals(method)) && isBlank(taskStatus)) { - String msg = "task status is empty" - logger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - String isManual = execution.getVariable("isManual") - if (("POST".equals(method) || "PUT".equals(method)) && isBlank(isManual)) { - String msg = "isManual is empty" - logger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - String paramJson = execution.getVariable("paramJson") - - String payload = "" - if ("POST".equals(method) || "PUT".equals(method)) { - OrchestrationTask task = new OrchestrationTask() - task.setTaskId(taskId) - task.setRequestId(requestId) - task.setName(taskName) - task.setStatus(taskStatus) - task.setIsManual(isManual) - task.setParams(paramJson) - ObjectMapper objectMapper = new ObjectMapper() - payload = objectMapper.writeValueAsString(task) - logger.debug("Outgoing payload is \n" + payload) - } - execution.setVariable("payload", payload) - logger.debug("End preProcessRequest") - } - - public void postProcess(DelegateExecution execution) { - Integer statusCode = execution.getVariable("statusCode") - logger.debug("statusCode: " + statusCode) - String response = execution.getVariable("response") - logger.debug("response: " + response) - if (!validStatus.contains(statusCode)) { - String msg = "Error in sending orchestrationTask request. \nstatusCode: " + statusCode + "\nresponse: " + response - logger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - } -} - diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/HandleOrchestrationTask.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/HandleOrchestrationTask.groovy new file mode 100644 index 0000000000..89490ff620 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/HandleOrchestrationTask.groovy @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.scripts + +import com.fasterxml.jackson.databind.ObjectMapper +import org.onap.so.db.request.beans.OrchestrationTask + +import static org.apache.commons.lang3.StringUtils.* +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.core.UrnPropertiesReader +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +class HandleOrchestrationTask extends AbstractServiceTaskProcessor { + private static final Logger logger = LoggerFactory.getLogger(HandleOrchestrationTask.class) + + ExceptionUtil exceptionUtil = new ExceptionUtil() + def supportedMethod = ["GET", "POST", "PUT"] + def validStatus = [200, 201] + + @Override + public void preProcessRequest(DelegateExecution execution) { + logger.debug("Start preProcessRequest") + String method = execution.getVariable("method") + if (!supportedMethod.contains(method)) { + String msg = "Method: " + method + " is not supported" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + String taskId = execution.getVariable("taskId") + if (isBlank(taskId)) { + String msg = "taskId is empty" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.requestDb.endpoint",execution) + def orchestrationTaskEndpoint = dbAdapterEndpoint + "/orchestrationTask/" + if (!"POST".equals(method)) { + orchestrationTaskEndpoint = orchestrationTaskEndpoint + taskId + } + execution.setVariable("url", orchestrationTaskEndpoint) + logger.debug("DB Adapter Endpoint is: " + orchestrationTaskEndpoint) + def dbAdapterAuth = UrnPropertiesReader.getVariable("mso.adapters.requestDb.auth") + Map headerMap = [:] + headerMap.put("content-type", "application/json") + headerMap.put("Authorization", dbAdapterAuth) + execution.setVariable("headerMap", headerMap) + logger.debug("DB Adapter Header is: " + headerMap) + + String requestId = execution.getVariable("requestId") + if (("POST".equals(method) || "PUT".equals(method)) && isBlank(requestId)) { + String msg = "requestId is empty" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + String taskName = execution.getVariable("taskName") + if (("POST".equals(method) || "PUT".equals(method)) && isBlank(taskName)) { + String msg = "task name is empty" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + String taskStatus = execution.getVariable("taskStatus") + if (("POST".equals(method) || "PUT".equals(method)) && isBlank(taskStatus)) { + String msg = "task status is empty" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + String isManual = execution.getVariable("isManual") + if (("POST".equals(method) || "PUT".equals(method)) && isBlank(isManual)) { + String msg = "isManual is empty" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + String paramJson = execution.getVariable("paramJson") + + String payload = "" + if ("POST".equals(method) || "PUT".equals(method)) { + OrchestrationTask task = new OrchestrationTask() + task.setTaskId(taskId) + task.setRequestId(requestId) + task.setName(taskName) + task.setStatus(taskStatus) + task.setIsManual(isManual) + task.setParams(paramJson) + ObjectMapper objectMapper = new ObjectMapper() + payload = objectMapper.writeValueAsString(task) + logger.debug("Outgoing payload is \n" + payload) + } + execution.setVariable("payload", payload) + logger.debug("End preProcessRequest") + } + + public void postProcess(DelegateExecution execution) { + Integer statusCode = execution.getVariable("statusCode") + logger.debug("statusCode: " + statusCode) + String response = execution.getVariable("response") + logger.debug("response: " + response) + if (!validStatus.contains(statusCode)) { + String msg = "Error in sending orchestrationTask request. \nstatusCode: " + statusCode + "\nresponse: " + response + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } +} + -- cgit 1.2.3-korg