SO catalogDB updates
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / onap / so / bpmn / common / scripts / AbstractServiceTaskProcessor.groovy
index 484be19..ec3dac5 100644 (file)
@@ -32,7 +32,8 @@ import org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse
 import org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder
 import org.onap.so.bpmn.core.UrnPropertiesReader
 import org.onap.so.bpmn.core.WorkflowException
-import org.onap.so.client.aai.AAIResourcesClient
+import org.onap.so.client.HttpClientFactory
+import org.onap.aaiclient.client.aai.AAIResourcesClient
 import org.springframework.web.util.UriUtils
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
@@ -44,6 +45,20 @@ public abstract class AbstractServiceTaskProcessor implements ServiceTaskProcess
 
        public MsoUtils utils = new MsoUtils()
 
+       /**
+        * Logs a WorkflowException at the ERROR level with the specified message.
+        * @param execution the execution
+        */
+       public void logWorkflowException(DelegateExecution execution, String message) {
+               def workflowException = execution.getVariable("WorkflowException")
+
+               if (workflowException == null) {
+                       logger.error(message);
+               } else {
+                       logger.error('{}: {}', message, workflowException)
+               }
+       }
+       
        /**
         * Saves the WorkflowException in the execution to the specified variable,
         * clearing the WorkflowException variable so the workflow can continue
@@ -148,7 +163,7 @@ public abstract class AbstractServiceTaskProcessor implements ServiceTaskProcess
                } catch (BpmnError e) {
                        throw e
                } catch (Exception e) {
-                       logger.error('Caught exception in ' + method, e)
+                       logger.error('Caught exception in {}: {}', method, e.getMessage(), e)
                        exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Invalid Message")
                }
        }
@@ -416,7 +431,7 @@ public abstract class AbstractServiceTaskProcessor implements ServiceTaskProcess
        *@param name
        *@return
        **/
-       public String getVariable(DelegateExecution execution, String name) {
+       public static String getVariable(DelegateExecution execution, String name) {
                def myObj = execution.getVariable(name)
                if(myObj instanceof VariableMap){
                        VariableMap serializedObjectMap = (VariableMap) myObj
@@ -522,8 +537,7 @@ public abstract class AbstractServiceTaskProcessor implements ServiceTaskProcess
                                throw bpmnError
                        }
                        catch(Exception e) {
-                               e.printStackTrace()
-                               logger.debug('Unexpected error encountered - ' + e.getMessage())
+                               logger.debug('Unexpected error encountered - {}', e.getMessage(), e)
                                (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 9999, e.getMessage())
                        }
                        finally {
@@ -645,7 +659,7 @@ public abstract class AbstractServiceTaskProcessor implements ServiceTaskProcess
                                rollbackEnabled = defaultRollback
                        }
                }
-               
+
                execution.setVariable(prefix+"backoutOnFailure", rollbackEnabled)
                logger.debug('rollbackEnabled (aka backoutOnFailure): ' + rollbackEnabled)
        }
@@ -664,4 +678,8 @@ public abstract class AbstractServiceTaskProcessor implements ServiceTaskProcess
     public AAIResourcesClient getAAIClient(){
         return  new AAIResourcesClient();
     }
+
+    HttpClientFactory getHttpClientFactory(){
+        return new HttpClientFactory()
+    }
 }