/*-\r
* ============LICENSE_START=======================================================\r
- * OPENECOMP - MSO\r
+ * ONAP - SO\r
* ================================================================================\r
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
* ================================================================================\r
import groovy.json.JsonSlurper\r
\r
import org.camunda.bpm.engine.delegate.BpmnError\r
-import org.camunda.bpm.engine.runtime.Execution\r
+import org.camunda.bpm.engine.delegate.DelegateExecution\r
import org.camunda.bpm.engine.variable.VariableMap\r
import org.camunda.bpm.engine.variable.Variables\r
import org.camunda.bpm.engine.variable.Variables.SerializationDataFormats\r
* Logs a WorkflowException at the ERROR level with the specified message.\r
* @param execution the execution\r
*/\r
- public void logWorkflowException(Execution execution, String message) {\r
+ public void logWorkflowException(DelegateExecution execution, String message) {\r
def workflowException = execution.getVariable("WorkflowException")\r
\r
if (workflowException == null) {\r
* @param execution the execution\r
* @return the name of the destination variable\r
*/\r
- public saveWorkflowException(Execution execution, String variable) {\r
+ public saveWorkflowException(DelegateExecution execution, String variable) {\r
if (variable == null) {\r
throw new NullPointerException();\r
}\r
* @param execution the execution\r
* @return the validated request\r
*/\r
- public String validateRequest(Execution execution, String... requiredVariables) {\r
+ public String validateRequest(DelegateExecution execution, String... requiredVariables) {\r
ExceptionUtil exceptionUtil = new ExceptionUtil()\r
def method = getClass().getSimpleName() + '.validateRequest(' +\r
'execution=' + execution.getId() +\r
* @param execution the execution\r
* @return the inputVars\r
*/\r
- public Map validateJSONReq(Execution execution) {\r
+ public Map validateJSONReq(DelegateExecution execution) {\r
def method = getClass().getSimpleName() + '.validateJSONReq(' +\r
'execution=' + execution.getId() +\r
')'\r
* top-level process\r
* @throws IllegalStateException if a response has already been sent\r
*/\r
- protected void sendWorkflowResponse(Execution execution, Object responseCode, String response) {\r
+ protected void sendWorkflowResponse(DelegateExecution execution, Object responseCode, String response) {\r
def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
try {\r
String processKey = getProcessKey(execution);\r
* Returns true if a workflow response has already been sent.\r
* @param execution the execution\r
*/\r
- protected boolean isWorkflowResponseSent(Execution execution) {\r
+ protected boolean isWorkflowResponseSent(DelegateExecution execution) {\r
def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
String processKey = getProcessKey(execution);\r
return String.valueOf(execution.getVariable(processKey + "WorkflowResponseSent")).equals("true");\r
/**\r
* Returns the process definition key (i.e. the process name) of the\r
* current process.\r
- *\r
+ * \r
* @param execution the execution\r
*/\r
- public String getProcessKey(Execution execution) {\r
+ public String getProcessKey(DelegateExecution execution) {\r
def testKey = execution.getVariable("testProcessKey")\r
if(testKey!=null){\r
return testKey\r
* top-level process.\r
* @param execution the execution\r
*/\r
- public String getMainProcessKey(Execution execution) {\r
- Execution exec = execution\r
+ public String getMainProcessKey(DelegateExecution execution) {\r
+ DelegateExecution exec = execution\r
\r
while (true) {\r
- Execution parent = exec.getSuperExecution()\r
+ DelegateExecution parent = exec.getSuperExecution()\r
\r
if (parent == null) {\r
parent = exec.getParent()\r
* @param elementName Name of element to search for.\r
* @return The element node, if found in the xml.\r
*/\r
- protected String getRequiredNodeXml(Execution execution, String xml, String elementName) {\r
+ protected String getRequiredNodeXml(DelegateExecution execution, String xml, String elementName) {\r
ExceptionUtil exceptionUtil = new ExceptionUtil()\r
def element = utils.getNodeXml(xml, elementName, false)\r
if (element.trim().isEmpty()) {\r
* @param elementName Name of element to whose value to get.\r
* @return The non-empty value of the element, if found in the xml.\r
*/\r
- protected String getRequiredNodeText(Execution execution, String xml, String elementName) {\r
+ protected String getRequiredNodeText(DelegateExecution execution, String xml, String elementName) {\r
ExceptionUtil exceptionUtil = new ExceptionUtil()\r
def elementText = utils.getNodeText1(xml, elementName)\r
if ((elementText == null) || (elementText.isEmpty())) {\r
def nodeText = utils.getNodeText1(xml, elementName)\r
return (nodeText == null) ? defaultValue : nodeText\r
}\r
+\r
/**\r
* Get the text for the specified element from the specified xml. If\r
* the element does not exist, return an empty string.\r
*@param name\r
*@param value\r
*/\r
- public void setVariable(Execution execution, String name, Object value) {\r
+ public void setVariable(DelegateExecution execution, String name, Object value) {\r
VariableMap variables = Variables.createVariables()\r
variables.putValueTyped('payload', Variables.objectValue(value)\r
.serializationDataFormat(SerializationDataFormats.JAVA) // tells the engine to use java serialization for persisting the value\r
*@param name\r
*@return\r
**/\r
- public String getVariable(Execution execution, String name) {\r
+ public String getVariable(DelegateExecution execution, String name) {\r
def myObj = execution.getVariable(name)\r
if(myObj instanceof VariableMap){\r
VariableMap serializedObjectMap = (VariableMap) myObj\r
* Sets flows success indicator variable.\r
*\r
*/\r
- public void setSuccessIndicator(Execution execution, boolean isSuccess) {\r
+ public void setSuccessIndicator(DelegateExecution execution, boolean isSuccess) {\r
String prefix = execution.getVariable('prefix')\r
def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
\r
logDebug('Outgoing SuccessIndicator is: ' + execution.getVariable(prefix+'SuccessIndicator') + '', isDebugLogEnabled)\r
}\r
\r
-\r
/**\r
* Sends a Error Sync Response\r
*\r
*/\r
- public void sendSyncError(Execution execution) {\r
+ public void sendSyncError(DelegateExecution execution) {\r
def isDebugEnabled=execution.getVariable("isDebugLogEnabled")\r
String requestId = execution.getVariable("mso-request-id")\r
logDebug('sendSyncError, requestId: ' + requestId, isDebugEnabled)\r
}\r
}\r
\r
- /**\r
- * Create a WorkflowException - uses ExceptionUtil to build a WorkflowException\r
- * @param execution\r
- * @param errorCode\r
- * @param errorMessage\r
- * @param isDebugEnabled\r
- */\r
- public void buildWorkflowException(Execution execution, int errorCode, String errorMessage, boolean isDebugEnabled) {\r
- (new ExceptionUtil()).buildWorkflowException(execution, errorCode, errorMessage)\r
- }\r
- \r
/**\r
* Executes a named groovy script method in the current object\r
*/\r
if (args != null && args.size() > 0) {\r
\r
// First argument of method to call is always the execution object\r
- Execution execution = (Execution) args[0]\r
+ DelegateExecution execution = (DelegateExecution) args[0]\r
\r
def classAndMethod = getClass().getSimpleName() + '.' + methodName + '(execution=' + execution.getId() + ')'\r
def isDebugEnabled = execution.getVariable('isDebugLogEnabled')\r
* @param messageType the message type (e.g. SDNCAResponse or VNFAResponse)\r
* @param correlator the correlator value (e.g. a request ID)\r
*/\r
- public String createCallbackURL(Execution execution, String messageType, String correlator) {\r
+ public String createCallbackURL(DelegateExecution execution, String messageType, String correlator) {\r
String endpoint = (String) execution.getVariable('URN_mso_workflow_message_endpoint')\r
\r
if (endpoint == null || endpoint.isEmpty()) {\r
'/' + UriUtils.encodePathSegment(messageType, 'UTF-8') +\r
'/' + UriUtils.encodePathSegment(correlator, 'UTF-8')\r
}\r
- \r
+\r
/**\r
*\r
* Constructs a workflow message callback URL for the specified message type and correlator.\r
* @param messageType the message type (e.g. SNIROResponse)\r
* @param correlator the correlator value (e.g. a request ID)\r
*/\r
- public String createWorkflowMessageAdapterCallbackURL(Execution execution, String messageType, String correlator) {\r
+ public String createWorkflowMessageAdapterCallbackURL(DelegateExecution execution, String messageType, String correlator) {\r
String endpoint = (String) execution.getVariable('URN_mso_adapters_workflow_message_endpoint')\r
\r
if (endpoint == null || endpoint.isEmpty()) {\r
'/' + UriUtils.encodePathSegment(messageType, 'UTF-8') +\r
'/' + UriUtils.encodePathSegment(correlator, 'UTF-8')\r
}\r
+ \r
+ public void setRollbackEnabled(DelegateExecution execution, isDebugLogEnabled) {\r
+ \r
+ // Rollback settings\r
+ def prefix = execution.getVariable('prefix')\r
+ def disableRollback = execution.getVariable("disableRollback")\r
+ def defaultRollback = execution.getVariable("URN_mso_rollback").toBoolean()\r
+ \r
+ logDebug('disableRollback: ' + disableRollback, isDebugLogEnabled)\r
+ logDebug('defaultRollback: ' + defaultRollback, isDebugLogEnabled)\r
+ \r
+ def rollbackEnabled\r
+ \r
+ if(disableRollback == null || disableRollback == '' ) {\r
+ // get from default urn settings for mso_rollback\r
+ disableRollback = !defaultRollback\r
+ rollbackEnabled = defaultRollback\r
+ logDebug('disableRollback is null or empty!', isDebugLogEnabled)\r
+ }\r
+ else {\r
+ if(disableRollback == true) {\r
+ rollbackEnabled = false\r
+ }\r
+ else if(disableRollback == false){\r
+ rollbackEnabled = true\r
+ }\r
+ else {\r
+ rollbackEnabled = defaultRollback\r
+ }\r
+ }\r
+ \r
+ execution.setVariable(prefix+"backoutOnFailure", rollbackEnabled)\r
+ logDebug('rollbackEnabled (aka backoutOnFailure): ' + rollbackEnabled, isDebugLogEnabled)\r
+ }\r
+ \r
+ public void setBasicDBAuthHeader(DelegateExecution execution, isDebugLogEnabled) {\r
+ try {\r
+ String basicAuthValueDB = execution.getVariable("URN_mso_adapters_db_auth")\r
+ utils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB, isDebugLogEnabled)\r
+ \r
+ def encodedString = utils.getBasicAuth(basicAuthValueDB, execution.getVariable("URN_mso_msoKey"))\r
+ execution.setVariable("BasicAuthHeaderValueDB",encodedString)\r
+ } catch (IOException ex) {\r
+ String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage()\r
+ utils.log("DEBUG", dataErrorMessage, isDebugLogEnabled)\r
+ (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)\r
+ }\r
+ }\r
}
\ No newline at end of file