From b618f7dda0ab8e105483301d274baa06be5de564 Mon Sep 17 00:00:00 2001 From: Donald Oakes Date: Thu, 4 Jun 2020 17:18:44 -0600 Subject: [PATCH] #842 doctypes --- docs/_docs/code/knowledge-transfer.md | 3 +- .../mdw/activity/types/TaskActivity.java | 59 ++------ .../impl/DomDocumentTranslator.java | 6 +- .../translator/impl/GroovyNodeTranslator.java | 8 +- .../impl/IntegerListTranslator.java | 8 +- .../translator/impl/JavaObjectTranslator.java | 7 +- .../translator/impl/JsonObjectTranslator.java | 6 +- .../translator/impl/JsonableTranslator.java | 12 +- .../translator/impl/LongListTranslator.java | 17 ++- .../impl/StringDocumentTranslator.java | 10 +- .../translator/impl/StringListTranslator.java | 6 +- .../impl/StringStringMapTranslator.java | 6 +- .../translator/impl/XmlBeanTranslator.java | 68 +++++----- .../impl/XmlBeanWrapperTranslator.java | 11 +- .../translator/impl/YamlTranslator.java | 12 +- .../mdw/dataaccess/db/CommonDataAccess.java | 11 +- .../mdw/jaxb/JaxbElementTranslator.java | 56 ++++---- .../mdw/model/request/Response.java | 3 - .../mdw/model/variable/Document.java | 30 ++--- .../mdw/model/workflow/Package.java | 31 +++-- .../model/workflow/ProcessRuntimeContext.java | 4 +- .../DocumentReferenceTranslator.java | 18 ++- .../mdw/translator/DynamicJavaTranslator.java | 66 --------- .../listener/ExternalEventHandlerBase.java | 21 ++- .../mdw/listener/ListenerHelper.java | 45 +++---- .../listener/ProcessStartEventHandler.java | 4 +- .../data/process/EngineDataAccess.java | 9 +- .../data/process/EngineDataAccessCache.java | 55 ++++---- .../data/process/EngineDataAccessDB.java | 4 - .../mdw/service/rest/DocumentValues.java | 63 --------- .../mdw/services/EventServices.java | 16 +-- .../mdw/services/WorkflowServices.java | 17 ++- .../mdw/services/event/EventServicesImpl.java | 57 ++++---- .../mdw/services/process/BaseActivity.java | 114 ++++++++-------- .../services/process/ProcessEngineDriver.java | 54 ++++---- .../mdw/services/process/ProcessExecutor.java | 27 ++-- .../services/process/ProcessExecutorImpl.java | 126 +++++++++--------- .../mdw/services/request/BaseHandler.java | 6 +- .../request/FallbackRequestHandler.java | 13 -- .../services/request/ProcessRunHandler.java | 5 +- .../mdw/services/rest/JsonRestService.java | 2 +- .../mdw/services/rest/JsonXmlRestService.java | 2 +- .../task/AutoFormTaskValuesProvider.java | 4 +- .../mdw/services/task/TaskWorkflowHelper.java | 8 +- .../mdw/services/test/TestCaseRun.java | 17 +-- .../workflow/WorkflowServicesImpl.java | 118 ++++++---------- .../mdw/camel/CxfPayloadTranslator.java | 42 +++--- .../centurylink/mdw/camel/MdwProducer.java | 2 +- .../com/centurylink/mdw/gson/.mdw/versions | 2 +- .../centurylink/mdw/gson/GsonTranslator.java | 6 +- .../mdw/microservice/.mdw/versions | 2 +- .../MicroserviceStatusProcessMonitor.java | 11 +- .../com/centurylink/mdw/testing/.mdw/versions | 2 +- .../mdw/testing/TestCaseActivityMonitor.java | 2 +- .../centurylink/mdw/tests/code/.mdw/versions | 4 +- .../mdw/tests/code/RequestHandlers.proc | 6 +- .../mdw/tests/code/SimpleDynamicJava.test | 2 +- .../mdw/tests/microservice/.mdw/versions | 2 +- .../MicroserviceOrchestration.proc | 1 - .../mdw/tests/services/.mdw/versions | 4 +- .../mdw/tests/services/HybridService.java | 2 +- .../mdw/tests/services/TestHandler.java | 42 +----- .../mdw/tests/variables/.mdw/versions | 19 ++- .../mdw/tests/variables/JavaObject.proc | 24 +--- .../mdw/tests/variables/JavaObject.test | 3 + .../mdw/tests/variables/JavaObject.yaml | 24 ++++ .../tests/variables/JavaObjectHandler.test | 5 +- .../tests/variables/JavaObjectHandler.yaml | 27 ++++ .../mdw/tests/variables/Jsonable.proc | 31 ++--- .../mdw/tests/variables/JsonableHandler.test | 3 + .../mdw/tests/variables/JsonableHandler.yaml | 57 ++++++++ .../mdw/tests/variables/JsonableInput.test | 3 + .../mdw/tests/variables/JsonableInput.yaml | 34 +++++ .../mdw/tests/variables/JsonableRequest.test | 7 + .../mdw/tests/variables/JsonableRequest.yaml | 57 ++++++++ .../activity/event/EventWaitActivity.java | 10 +- .../InvokeHeterogeneousProcessActivity.java | 13 +- .../process/InvokeProcessActivityBase.java | 7 +- .../process/InvokeSubProcessActivity.java | 2 +- .../task/AutoFormManualTaskActivity.java | 28 ++-- .../activity/transform/TransformActivity.java | 10 +- .../adapter/ObjectAdapterActivity.java | 4 +- .../workflow/adapter/TextAdapterActivity.java | 2 +- 83 files changed, 861 insertions(+), 886 deletions(-) delete mode 100644 mdw-common/src/com/centurylink/mdw/translator/DynamicJavaTranslator.java delete mode 100644 mdw-services/src/com/centurylink/mdw/service/rest/DocumentValues.java create mode 100644 mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObject.yaml create mode 100644 mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObjectHandler.yaml create mode 100644 mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableHandler.yaml create mode 100644 mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableInput.yaml create mode 100644 mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableRequest.yaml diff --git a/docs/_docs/code/knowledge-transfer.md b/docs/_docs/code/knowledge-transfer.md index dd30036f77..83e2fefeaa 100644 --- a/docs/_docs/code/knowledge-transfer.md +++ b/docs/_docs/code/knowledge-transfer.md @@ -9,10 +9,11 @@ title: MDW Knowledge Transfer Sessions - [Listeners/Handlers](#listeners-handlers) - [Adapters](#adapters) - [Manual Tasks](#manual-tasks) + - [Build and Environments](#build-and-env) + - [Fallout/Exception Handling](#fallout-exception-handling) - [MDWHub/JSX Assets](#mdwhub-jsx-assets) - [Dashboard](#dashboard) - [Autotests](#autotests) - [Milestones](#milestones) - [CLI](#cli) - [MDW Studio](#mdw-studio) - - [Build and Environments](#build-and-env) diff --git a/mdw-common/src/com/centurylink/mdw/activity/types/TaskActivity.java b/mdw-common/src/com/centurylink/mdw/activity/types/TaskActivity.java index 80b0169991..245103f805 100644 --- a/mdw-common/src/com/centurylink/mdw/activity/types/TaskActivity.java +++ b/mdw-common/src/com/centurylink/mdw/activity/types/TaskActivity.java @@ -15,61 +15,22 @@ */ package com.centurylink.mdw.activity.types; -import com.centurylink.mdw.constant.TaskAttributeConstant; - - /** - * Interface for all Manual Task activities. + * Manual Task activities. */ public interface TaskActivity extends GeneralActivity { - static final String ATTRIBUTE_TASK_LOGICAL_ID = "TaskLogicalId"; - static final String ATTRIBUTE_TASK_NAME = "TaskName"; - static final String ATTRIBUTE_TASK_DESC = "Task Description"; - static final String ATTRIBUTE_TASK_CATEGORY = "Category"; - static final String ATTRIBUTE_TASK_OBSERVER = "Observer"; - static final String ATTRIBUTE_TASK_SLA = TaskAttributeConstant.TASK_SLA; - static final String ATTRIBUTE_TASK_SLA_UNITS = "SLAUnits"; - static final String ATTRIBUTE_TASK_ALERT_INTERVAL = "AlertInterval"; - static final String ATTRIBUTE_TASK_ALERT_INTERVAL_UNITS = "AlertIntervalUnits"; - static final String ATTRIBUTE_TASK_GROUPS = TaskAttributeConstant.GROUPS; - static final String ATTRIBUTE_TASK_VARIABLES = "Variables"; - static final String ATTRIBUTE_TASK_NOTICES = TaskAttributeConstant.NOTICES; - static final String ATTRIBUTE_NOTICE_GROUPS = TaskAttributeConstant.NOTICE_GROUPS; - static final String ATTRIBUTE_RECIPIENT_EMAILS = TaskAttributeConstant.RECIPIENT_EMAILS; - static final String ATTRIBUTE_CC_GROUPS = TaskAttributeConstant.CC_GROUPS; - static final String ATTRIBUTE_TASK_AUTOASSIGN = TaskAttributeConstant.AUTO_ASSIGN; - static final String ATTRIBUTE_AUTO_ASSIGN_RULES = TaskAttributeConstant.AUTO_ASSIGN_RULES; - static final String ATTRIBUTE_TASK_ROUTING = TaskAttributeConstant.ROUTING_STRATEGY; - static final String ATTRIBUTE_ROUTING_RULES = TaskAttributeConstant.ROUTING_RULES; - static final String ATTRIBUTE_SUBTASK_STRATEGY = TaskAttributeConstant.SUBTASK_STRATEGY; - static final String ATTRIBUTE_SUBTASK_RULES = TaskAttributeConstant.SUBTASK_RULES; - static final String ATTRIBUTE_INDEX_PROVIDER = TaskAttributeConstant.INDEX_PROVIDER; - static final String ATTRIBUTE_ASSIGNEE_VAR = TaskAttributeConstant.ASSIGNEE_VAR; - static final String ATTRIBUTE_TASK_ID = "TaskId"; // set by loader - not persisted - static final String ATTRIBUTE_FORM_NAME = "FormName"; - static final String ATTRIBUTE_FORM_VERSION = "FormVersion"; - static final String ATTRIBUTE_FORM_DATA_VAR = "FormDataVar"; - static final String ATTRIBUTE_CUSTOM_PAGE = TaskAttributeConstant.CUSTOM_PAGE; - static final String ATTRIBUTE_CUSTOM_PAGE_ASSET_VERSION = TaskAttributeConstant.CUSTOM_PAGE_ASSET_VERSION; - static final String ATTRIBUTE_RENDERING = TaskAttributeConstant.RENDERING_ENGINE; - static final String ATTRIBUTE_TASK_INDICES = TaskAttributeConstant.INDICES; - static final String ATTRIBUTE_TASK_PRIORITIZATION = TaskAttributeConstant.PRIORITY_STRATEGY; - static final String ATTRIBUTE_TASK_PRIORITY = TaskAttributeConstant.PRIORITY; - static final String ATTRIBUTE_PRIORITIZATION_RULES = TaskAttributeConstant.PRIORITIZATION_RULES; - static final String ATTRIBUTE_SERVICE_PROCESSES = TaskAttributeConstant.SERVICE_PROCESSES; - - static final String ATTRVALUE_CREATE_NEW_FORM = "(new form - click View Form to create)"; + String ATTRIBUTE_TASK_VARIABLES = "Variables"; - static final String VARIABLE_DISPLAY_NOTDISPLAYED = "Not Displayed"; - static final String VARIABLE_DISPLAY_OPTIONAL = "Optional"; - static final String VARIABLE_DISPLAY_REQUIRED = "Required"; - static final String VARIABLE_DISPLAY_READONLY = "Read Only"; - static final String VARIABLE_DISPLAY_HIDDEN = "Hidden"; + String VARIABLE_DISPLAY_NOTDISPLAYED = "Not Displayed"; + String VARIABLE_DISPLAY_OPTIONAL = "Optional"; + String VARIABLE_DISPLAY_REQUIRED = "Required"; + String VARIABLE_DISPLAY_READONLY = "Read Only"; + String VARIABLE_DISPLAY_HIDDEN = "Hidden"; - static final String TASK_CREATE_RESPONSE_ID_PREFIX = "Task instance created - ID="; + String TASK_CREATE_RESPONSE_ID_PREFIX = "Task instance created - ID="; // these attributes indicate new-style task template - static final String ATTRIBUTE_TASK_TEMPLATE = "TASK_TEMPLATE"; - static final String ATTRIBUTE_TASK_TEMPLATE_VERSION = "TASK_TEMPLATE_assetVersion"; + String ATTRIBUTE_TASK_TEMPLATE = "TASK_TEMPLATE"; + String ATTRIBUTE_TASK_TEMPLATE_VERSION = "TASK_TEMPLATE_assetVersion"; } diff --git a/mdw-common/src/com/centurylink/mdw/common/translator/impl/DomDocumentTranslator.java b/mdw-common/src/com/centurylink/mdw/common/translator/impl/DomDocumentTranslator.java index 9039a2a21e..af08f791ca 100644 --- a/mdw-common/src/com/centurylink/mdw/common/translator/impl/DomDocumentTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/common/translator/impl/DomDocumentTranslator.java @@ -25,7 +25,8 @@ public class DomDocumentTranslator extends DocumentReferenceTranslator implements XmlDocumentTranslator { - public Object realToObject(String str) throws TranslationException { + @Override + public Object toObject(String str, String type) throws TranslationException { try { return DomHelper.toDomDocument(str); } catch (Exception e) { @@ -33,7 +34,8 @@ public Object realToObject(String str) throws TranslationException { } } - public String realToString(Object obj) throws TranslationException { + @Override + public String toString(Object obj, String variableType) throws TranslationException { try { Document document = (Document) obj; diff --git a/mdw-common/src/com/centurylink/mdw/common/translator/impl/GroovyNodeTranslator.java b/mdw-common/src/com/centurylink/mdw/common/translator/impl/GroovyNodeTranslator.java index b69bf1566c..20577f9d3a 100644 --- a/mdw-common/src/com/centurylink/mdw/common/translator/impl/GroovyNodeTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/common/translator/impl/GroovyNodeTranslator.java @@ -33,7 +33,7 @@ @Deprecated public class GroovyNodeTranslator extends DocumentReferenceTranslator implements XmlDocumentTranslator { - public Object realToObject(String str) throws TranslationException { + public Object toObject(String str, String type) throws TranslationException { try { return new XmlParser().parseText(str); } catch (Exception e) { @@ -41,7 +41,7 @@ public Object realToObject(String str) throws TranslationException { } } - public String realToString(Object obj) throws TranslationException { + public String toString(Object obj, String variableType) throws TranslationException { StringWriter writer = null; try { Node node = (Node) obj; @@ -63,7 +63,7 @@ public String realToString(Object obj) throws TranslationException { public Document toDomDocument(Object obj) throws TranslationException { // TODO: avoid reparsing try { - return DomHelper.toDomDocument(realToString(obj)); + return DomHelper.toDomDocument(toString(obj, null)); } catch (Exception ex) { throw new TranslationException(ex.getMessage(), ex); @@ -72,7 +72,7 @@ public Document toDomDocument(Object obj) throws TranslationException { public Object fromDomNode(org.w3c.dom.Node domNode) throws TranslationException { try { - return realToObject(DomHelper.toXml(domNode)); + return toObject(DomHelper.toXml(domNode), null); } catch (Exception ex) { throw new TranslationException(ex.getMessage(), ex); diff --git a/mdw-common/src/com/centurylink/mdw/common/translator/impl/IntegerListTranslator.java b/mdw-common/src/com/centurylink/mdw/common/translator/impl/IntegerListTranslator.java index a52358b913..89e762e7d2 100644 --- a/mdw-common/src/com/centurylink/mdw/common/translator/impl/IntegerListTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/common/translator/impl/IntegerListTranslator.java @@ -24,12 +24,13 @@ import com.centurylink.mdw.translator.DocumentReferenceTranslator; import com.centurylink.mdw.translator.TranslationException; +@SuppressWarnings("unused") public class IntegerListTranslator extends DocumentReferenceTranslator { @Override - public Object realToObject(String str) throws TranslationException { + public Object toObject(String str, String type) throws TranslationException { try { - List intList = new ArrayList(); + List intList = new ArrayList<>(); JSONArray jsonArray = new JSONArray(str); for (int i = 0; i < jsonArray.length(); i++) intList.add((Integer)jsonArray.opt(i)); @@ -41,7 +42,8 @@ public Object realToObject(String str) throws TranslationException { } @SuppressWarnings("unchecked") - public String realToString(Object obj) throws TranslationException { + @Override + public String toString(Object obj, String variableType) throws TranslationException { List intList = (List) obj; JSONArray jsonArray = new JSONArray(); for (Integer integer : intList) diff --git a/mdw-common/src/com/centurylink/mdw/common/translator/impl/JavaObjectTranslator.java b/mdw-common/src/com/centurylink/mdw/common/translator/impl/JavaObjectTranslator.java index 88d403f0d8..977ce0d459 100644 --- a/mdw-common/src/com/centurylink/mdw/common/translator/impl/JavaObjectTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/common/translator/impl/JavaObjectTranslator.java @@ -32,7 +32,8 @@ public class JavaObjectTranslator extends DocumentReferenceTranslator { - public Object realToObject(String str) throws TranslationException { + @Override + public Object toObject(String str, String type) throws TranslationException { ObjectInputStream ois = null; try { byte[] decoded = decodeBase64(str); @@ -76,7 +77,8 @@ protected Class resolveClass(ObjectStreamClass desc) throws IOException, Clas } } - public String realToString(Object obj) throws TranslationException { + @Override + public String toString(Object obj, String variableType) throws TranslationException { if (!(obj instanceof Serializable)) throw new TranslationException("Object must implement java.io.Serializable: " + obj.getClass()); @@ -106,5 +108,4 @@ protected byte[] decodeBase64(String inputString) { protected String encodeBase64(byte[] inputBytes) { return new String(Base64.encodeBase64(inputBytes)); } - } \ No newline at end of file diff --git a/mdw-common/src/com/centurylink/mdw/common/translator/impl/JsonObjectTranslator.java b/mdw-common/src/com/centurylink/mdw/common/translator/impl/JsonObjectTranslator.java index 0949263a22..b0e95448f4 100644 --- a/mdw-common/src/com/centurylink/mdw/common/translator/impl/JsonObjectTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/common/translator/impl/JsonObjectTranslator.java @@ -23,9 +23,11 @@ import com.centurylink.mdw.translator.JsonTranslator; import com.centurylink.mdw.translator.TranslationException; +@SuppressWarnings("unused") public class JsonObjectTranslator extends DocumentReferenceTranslator implements JsonTranslator { - public Object realToObject(String str) throws TranslationException { + @Override + public Object toObject(String str, String type) throws TranslationException { try { return new JsonObject(str); } catch (JSONException e) { @@ -33,7 +35,7 @@ public Object realToObject(String str) throws TranslationException { } } - public String realToString(Object obj) throws TranslationException { + public String toString(Object obj, String variableType) throws TranslationException { try { JSONObject jsonObject = (JSONObject) obj; return jsonObject.toString(2); diff --git a/mdw-common/src/com/centurylink/mdw/common/translator/impl/JsonableTranslator.java b/mdw-common/src/com/centurylink/mdw/common/translator/impl/JsonableTranslator.java index 2b52d6ae4e..22c3ebbb30 100644 --- a/mdw-common/src/com/centurylink/mdw/common/translator/impl/JsonableTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/common/translator/impl/JsonableTranslator.java @@ -25,7 +25,11 @@ public class JsonableTranslator extends DocumentReferenceTranslator implements JsonTranslator { - public Object realToObject(String str) throws TranslationException { + /** + * TODO honor runtime type + */ + @Override + public Object toObject(String str, String type) throws TranslationException { try { JSONObject json = new JsonObject(str); return createJsonable(json); @@ -35,7 +39,11 @@ public Object realToObject(String str) throws TranslationException { } } - public String realToString(Object obj) throws TranslationException { + /** + * TODO prop-driven JSONABLE_TYPE population + */ + @Override + public String toString(Object obj, String variableType) throws TranslationException { Jsonable jsonable = (Jsonable) obj; JSONObject json = new JsonObject(); try { diff --git a/mdw-common/src/com/centurylink/mdw/common/translator/impl/LongListTranslator.java b/mdw-common/src/com/centurylink/mdw/common/translator/impl/LongListTranslator.java index 88b8f0dbdc..91df1cebf0 100644 --- a/mdw-common/src/com/centurylink/mdw/common/translator/impl/LongListTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/common/translator/impl/LongListTranslator.java @@ -15,21 +15,21 @@ */ package com.centurylink.mdw.common.translator.impl; -import java.util.ArrayList; -import java.util.List; - +import com.centurylink.mdw.translator.DocumentReferenceTranslator; +import com.centurylink.mdw.translator.TranslationException; import org.json.JSONArray; import org.json.JSONException; -import com.centurylink.mdw.translator.DocumentReferenceTranslator; -import com.centurylink.mdw.translator.TranslationException; +import java.util.ArrayList; +import java.util.List; +@SuppressWarnings("unused") public class LongListTranslator extends DocumentReferenceTranslator { @Override - public Object realToObject(String str) throws TranslationException { + public Object toObject(String str, String type) throws TranslationException { try { - List longList = new ArrayList(); + List longList = new ArrayList<>(); JSONArray jsonArray = new JSONArray(str); for (int i = 0; i < jsonArray.length(); i++) longList.add(jsonArray.opt(i) == null ? null : jsonArray.getLong(i)); @@ -41,12 +41,11 @@ public Object realToObject(String str) throws TranslationException { } @SuppressWarnings("unchecked") - public String realToString(Object obj) throws TranslationException { + public String toString(Object obj, String variableType) throws TranslationException { List longList = (List) obj; JSONArray jsonArray = new JSONArray(); for (Long longElement : longList) jsonArray.put(longElement); return jsonArray.toString(); } - } \ No newline at end of file diff --git a/mdw-common/src/com/centurylink/mdw/common/translator/impl/StringDocumentTranslator.java b/mdw-common/src/com/centurylink/mdw/common/translator/impl/StringDocumentTranslator.java index cd8631c30d..6ab80fddc1 100644 --- a/mdw-common/src/com/centurylink/mdw/common/translator/impl/StringDocumentTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/common/translator/impl/StringDocumentTranslator.java @@ -21,13 +21,15 @@ import com.centurylink.mdw.translator.JsonTranslator; import com.centurylink.mdw.translator.TranslationException; -public class StringDocumentTranslator extends DocumentReferenceTranslator implements JsonTranslator -{ - public Object realToObject(String str) throws TranslationException { +public class StringDocumentTranslator extends DocumentReferenceTranslator implements JsonTranslator { + + @Override + public Object toObject(String str, String type) throws TranslationException { return str; } - public String realToString(Object obj) throws TranslationException { + @Override + public String toString(Object obj, String variableType) throws TranslationException { return obj.toString(); } diff --git a/mdw-common/src/com/centurylink/mdw/common/translator/impl/StringListTranslator.java b/mdw-common/src/com/centurylink/mdw/common/translator/impl/StringListTranslator.java index 0fbe104dfa..634f174181 100644 --- a/mdw-common/src/com/centurylink/mdw/common/translator/impl/StringListTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/common/translator/impl/StringListTranslator.java @@ -24,10 +24,11 @@ import com.centurylink.mdw.translator.DocumentReferenceTranslator; import com.centurylink.mdw.translator.TranslationException; +@SuppressWarnings("unused") public class StringListTranslator extends DocumentReferenceTranslator { @Override - public Object realToObject(String str) throws TranslationException { + public Object toObject(String str, String type) throws TranslationException { try { List stringList = new ArrayList<>(); JSONArray jsonArray = new JSONArray(str); @@ -41,7 +42,8 @@ public Object realToObject(String str) throws TranslationException { } @SuppressWarnings("unchecked") - public String realToString(Object obj) throws TranslationException { + @Override + public String toString(Object obj, String variableType) throws TranslationException { List stringList = (List) obj; JSONArray jsonArray = new JSONArray(); for (String string : stringList) diff --git a/mdw-common/src/com/centurylink/mdw/common/translator/impl/StringStringMapTranslator.java b/mdw-common/src/com/centurylink/mdw/common/translator/impl/StringStringMapTranslator.java index 92fae6b4be..0cc73db757 100644 --- a/mdw-common/src/com/centurylink/mdw/common/translator/impl/StringStringMapTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/common/translator/impl/StringStringMapTranslator.java @@ -26,10 +26,11 @@ import com.centurylink.mdw.translator.DocumentReferenceTranslator; import com.centurylink.mdw.translator.TranslationException; +@SuppressWarnings("unused") public class StringStringMapTranslator extends DocumentReferenceTranslator { @Override - public Object realToObject(String str) throws TranslationException { + public Object toObject(String str, String type) throws TranslationException { try { Map stringMap = new HashMap<>(); JSONObject jsonObject = new JsonObject(str); @@ -47,7 +48,8 @@ public Object realToObject(String str) throws TranslationException { } @SuppressWarnings("unchecked") - public String realToString(Object obj) throws TranslationException { + @Override + public String toString(Object obj, String variableType) throws TranslationException { Map stringMap = (Map) obj; JSONObject jsonObject = new JsonObject(); Iterator it = stringMap.keySet().iterator(); diff --git a/mdw-common/src/com/centurylink/mdw/common/translator/impl/XmlBeanTranslator.java b/mdw-common/src/com/centurylink/mdw/common/translator/impl/XmlBeanTranslator.java index 66f85b6e2e..34de839a66 100644 --- a/mdw-common/src/com/centurylink/mdw/common/translator/impl/XmlBeanTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/common/translator/impl/XmlBeanTranslator.java @@ -33,10 +33,43 @@ public class XmlBeanTranslator extends DocumentReferenceTranslator implements XmlDocumentTranslator { private static StandardLogger logger = LoggerUtil.getStandardLogger(); - // Note that, due to static loading, the logger should be defined before xmlOptions - // Note also using a static method instead of static block just for code niceness private static XmlOptions xmlOptions = getXmlOptions(); + /** + * TODO honor passed type to create appropriate instance + */ + @Override + public Object toObject(String str, String type) throws TranslationException { + try { + XmlObject xmlBean = XmlObject.Factory.parse(str, xmlOptions); + return xmlBean; + } + catch (XmlException e) { + throw new TranslationException(e.getMessage(), e); + } + } + + @Override + public String toString(Object obj, String variableType) throws TranslationException { + XmlObject xmlBean = (XmlObject) obj; + XmlOptions tempOptions = new XmlOptions(xmlOptions); + tempOptions.setSavePrettyPrint(); + return xmlBean.xmlText(tempOptions); + } + + public Document toDomDocument(Object obj) throws TranslationException { + return (Document) ((XmlObject) obj).getDomNode(); + } + + public Object fromDomNode(Node domNode) throws TranslationException { + try { + return XmlObject.Factory.parse(domNode); + } + catch (XmlException ex) { + throw new TranslationException(ex.getMessage(), ex); + } + } + /** * Moved this to a static block/method so it's done only once * @return XmlOptions @@ -105,35 +138,4 @@ private static XmlOptions getXmlOptions() { return xmlOptions; } - - public Object realToObject(String str) throws TranslationException { - try { - XmlObject xmlBean = XmlObject.Factory.parse(str, xmlOptions); - return xmlBean; - } - catch (XmlException e) { - throw new TranslationException(e.getMessage(), e); - } - } - - public String realToString(Object obj) throws TranslationException { - XmlObject xmlBean = (XmlObject) obj; - XmlOptions tempOptions = new XmlOptions(xmlOptions); - tempOptions.setSavePrettyPrint(); - return xmlBean.xmlText(tempOptions); - } - - public Document toDomDocument(Object obj) throws TranslationException { - return (Document) ((XmlObject) obj).getDomNode(); - } - - public Object fromDomNode(Node domNode) throws TranslationException { - try { - return XmlObject.Factory.parse(domNode); - } - catch (XmlException ex) { - throw new TranslationException(ex.getMessage(), ex); - } - } - } diff --git a/mdw-common/src/com/centurylink/mdw/common/translator/impl/XmlBeanWrapperTranslator.java b/mdw-common/src/com/centurylink/mdw/common/translator/impl/XmlBeanWrapperTranslator.java index 5cf3901cac..e01f6c94a3 100644 --- a/mdw-common/src/com/centurylink/mdw/common/translator/impl/XmlBeanWrapperTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/common/translator/impl/XmlBeanWrapperTranslator.java @@ -27,12 +27,13 @@ @Deprecated public class XmlBeanWrapperTranslator extends DocumentReferenceTranslator implements XmlDocumentTranslator { - public Object realToObject(String str) throws TranslationException { + @Override + public Object toObject(String str, String type) throws TranslationException { try { int xmlIdx = str.indexOf('<'); - String type = str.substring(0, xmlIdx).trim(); + String declaredType = str.substring(0, xmlIdx).trim(); String xml = str.substring(xmlIdx); - Class wrapperClass = Class.forName(type); + Class wrapperClass = Class.forName(declaredType); Constructor constructor = wrapperClass.getConstructor(new Class[]{String.class}); return constructor.newInstance(xml); } catch (Exception e) { @@ -40,7 +41,8 @@ public Object realToObject(String str) throws TranslationException { } } - public String realToString(Object obj) throws TranslationException { + @Override + public String toString(Object obj, String variableType) throws TranslationException { XmlBeanWrapper xmlBeanWrapper = (XmlBeanWrapper) obj; return xmlBeanWrapper.getClass().getName() + "\n" + xmlBeanWrapper.getXml(); } @@ -52,5 +54,4 @@ public Document toDomDocument(Object obj) throws TranslationException { public Object fromDomNode(Node domNode) throws TranslationException { throw new UnsupportedOperationException("Cannot create XmlBeanWrapper from DOM Node"); } - } diff --git a/mdw-common/src/com/centurylink/mdw/common/translator/impl/YamlTranslator.java b/mdw-common/src/com/centurylink/mdw/common/translator/impl/YamlTranslator.java index 14267861a6..f13342b114 100644 --- a/mdw-common/src/com/centurylink/mdw/common/translator/impl/YamlTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/common/translator/impl/YamlTranslator.java @@ -41,9 +41,14 @@ * declares the type (class name) of the JavaBean object. * Implements XmlDocumentTranslator only for serializing as ExecutionPlan (TODO fix that). */ -public class YamlTranslator extends DocumentReferenceTranslator implements XmlDocumentTranslator, JsonTranslator { +public class YamlTranslator extends DocumentReferenceTranslator + implements XmlDocumentTranslator, JsonTranslator { - public Object realToObject(String str) throws TranslationException { + /** + * TODO honor passed type + */ + @Override + public Object toObject(String str, String type) throws TranslationException { try { Representer representer = new Representer(); representer.getPropertyUtils().setSkipMissingProperties(true); @@ -69,7 +74,8 @@ protected Class getClassForName(String name) throws ClassNotFoundException { } } - public String realToString(Object obj) throws TranslationException { + @Override + public String toString(Object obj, String variableType) throws TranslationException { try { return new Yaml(getRepresenter(), getDumperOptions()).dump(obj); } diff --git a/mdw-common/src/com/centurylink/mdw/dataaccess/db/CommonDataAccess.java b/mdw-common/src/com/centurylink/mdw/dataaccess/db/CommonDataAccess.java index 110a124f06..09df471075 100644 --- a/mdw-common/src/com/centurylink/mdw/dataaccess/db/CommonDataAccess.java +++ b/mdw-common/src/com/centurylink/mdw/dataaccess/db/CommonDataAccess.java @@ -15,6 +15,7 @@ */ package com.centurylink.mdw.dataaccess.db; +import com.centurylink.mdw.cache.VariableTypeCache; import com.centurylink.mdw.constant.OwnerType; import com.centurylink.mdw.dataaccess.DataAccessException; import com.centurylink.mdw.dataaccess.DatabaseAccess; @@ -372,7 +373,7 @@ protected void updateMembersById(Long id, Long[] members, public Document getDocument(Long documentId) throws DataAccessException { try { db.openConnection(); - return this.getDocument(documentId, false); + return getDocument(documentId, false); } catch (SQLException ex) { throw new DataAccessException("Failed to load document: " + documentId, ex); } finally { @@ -425,12 +426,14 @@ public Document loadDocument(Long documentId, boolean forUpdate) doc.setOwnerId(rs.getLong("OWNER_ID")); doc.setType(rs.getString("DOCUMENT_TYPE")); if (OwnerType.VARIABLE_INSTANCE.equals(doc.getOwnerType())) { - query = "select VARIABLE_TYPE from VARIABLE_INSTANCE where VARIABLE_INST_ID = ?"; + query = "select VARIABLE_TYPE, VARIABLE_TYPE_ID from VARIABLE_INSTANCE where VARIABLE_INST_ID = ?"; rs = db.runSelect(query, doc.getOwnerId()); if (rs.next()) { String variableType = rs.getString(1); - if (variableType != null && !variableType.isEmpty()) - doc.setVariableType(variableType); + if (variableType == null || variableType.isEmpty()) { + variableType = VariableTypeCache.getVariableType(rs.getInt(2)).getName(); + } + doc.setVariableType(variableType); } } boolean foundInDocDb = false; diff --git a/mdw-common/src/com/centurylink/mdw/jaxb/JaxbElementTranslator.java b/mdw-common/src/com/centurylink/mdw/jaxb/JaxbElementTranslator.java index 290b776d56..aa2dd12da7 100644 --- a/mdw-common/src/com/centurylink/mdw/jaxb/JaxbElementTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/jaxb/JaxbElementTranslator.java @@ -15,40 +15,23 @@ */ package com.centurylink.mdw.jaxb; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; - -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; - import com.centurylink.mdw.translator.DocumentReferenceTranslator; import com.centurylink.mdw.translator.TranslationException; import com.centurylink.mdw.translator.XmlDocumentTranslator; import com.centurylink.mdw.xml.DomHelper; +import org.w3c.dom.Document; +import org.w3c.dom.Node; -public class JaxbElementTranslator extends DocumentReferenceTranslator implements XmlDocumentTranslator { - - private Marshaller marshaller; - public Marshaller getMarshaller() { return marshaller; } - public void setMarshaller(Marshaller marshaller) { this.marshaller = marshaller; } - - private Unmarshaller unmarshaller; - public Unmarshaller getUnmarshaller() { return unmarshaller; } - public void setUnmarshaller(Unmarshaller unmarshaller) { this.unmarshaller = unmarshaller; } - - public Object getJaxbObject(String xml) throws TranslationException { - return realToObject(xml); - } +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; - public String getXml(Object jaxbObject) throws TranslationException { - return realToString(jaxbObject); - } +public class JaxbElementTranslator extends DocumentReferenceTranslator implements XmlDocumentTranslator { - public Object realToObject(String str) throws TranslationException { + @Override + public Object toObject(String str, String type) throws TranslationException { try { ByteArrayInputStream in = new ByteArrayInputStream(str.getBytes()); return unmarshaller.unmarshal(in); @@ -57,7 +40,8 @@ public Object realToObject(String str) throws TranslationException { } } - public String realToString(Object obj) throws TranslationException { + @Override + public String toString(Object obj, String variableType) throws TranslationException { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); @@ -69,6 +53,22 @@ public String realToString(Object obj) throws TranslationException { } } + private Marshaller marshaller; + public Marshaller getMarshaller() { return marshaller; } + public void setMarshaller(Marshaller marshaller) { this.marshaller = marshaller; } + + private Unmarshaller unmarshaller; + public Unmarshaller getUnmarshaller() { return unmarshaller; } + public void setUnmarshaller(Unmarshaller unmarshaller) { this.unmarshaller = unmarshaller; } + + public Object getJaxbObject(String xml) throws TranslationException { + return toObject(xml, null); + } + + public String getXml(Object jaxbObject) throws TranslationException { + return toString(jaxbObject, null); + } + public Document toDomDocument(Object obj) throws TranslationException { try { // TODO: use JAXB Binder to avoid reparse diff --git a/mdw-common/src/com/centurylink/mdw/model/request/Response.java b/mdw-common/src/com/centurylink/mdw/model/request/Response.java index 30daffb912..c9cc9049d9 100644 --- a/mdw-common/src/com/centurylink/mdw/model/request/Response.java +++ b/mdw-common/src/com/centurylink/mdw/model/request/Response.java @@ -25,9 +25,6 @@ public class Response implements Jsonable { public String getContent() { return content; } public void setContent(String content) { this.content = content; } - /** - * Response content as object (for non-Text Adapter). - */ private Object object; public Object getObject() { return object; } public void setObject(Object object) { this.object = object; } diff --git a/mdw-common/src/com/centurylink/mdw/model/variable/Document.java b/mdw-common/src/com/centurylink/mdw/model/variable/Document.java index 60a9023e03..2cdab606f7 100644 --- a/mdw-common/src/com/centurylink/mdw/model/variable/Document.java +++ b/mdw-common/src/com/centurylink/mdw/model/variable/Document.java @@ -18,10 +18,9 @@ import com.centurylink.mdw.cache.asset.PackageCache; import com.centurylink.mdw.model.workflow.Package; -import java.io.Serializable; import java.util.Date; -public class Document implements Serializable { +public class Document { /** * Actual runtime type @@ -38,12 +37,10 @@ public void setType(String type) { /** * Declared variable type for translating - * (falls back to document type) + * (falls back to document type for compatibility) */ private String variableType; - public String getVariableType() { - return variableType == null ? type : variableType; - } + public String getVariableType() { return variableType; } public void setVariableType(String variableType) { this.variableType = variableType; } @@ -113,7 +110,7 @@ public String getContent(Package pkg) { if (content == null && object != null) { if (pkg == null) pkg = PackageCache.getMdwBasePackage(); - content = pkg.getStringValue(type, object, true); + content = pkg.getStringValue(getVariableType(), object, true); } return content; } @@ -127,29 +124,26 @@ public void setContent(String content) { } private Object object; // object content - public Object getObject(String type, Package pkg) { + public Object getObject(String variableType, Package pkg) { if (pkg == null) pkg = PackageCache.getMdwBasePackage(); - if (type == null || type.equals(this.type)) { + if (variableType == null || variableType.equals(this.variableType)) { if (object == null && content != null) { - object = pkg.getObjectValue(this.type, content, true); + object = pkg.getObjectValue(variableType, content, true, type); } } else { + this.variableType = variableType; if (content != null) { - this.type = type; - object = pkg.getObjectValue(this.type, content, true); + object = pkg.getObjectValue(variableType, content, true, type); } else if (object != null) { - content = pkg.getStringValue(this.type, object, true); - this.type = type; - object = pkg.getStringValue(this.type, content, true); + content = pkg.getStringValue(variableType, object, true); + object = pkg.getStringValue(variableType, content, true); } } return object; } - public void setObject(Object object, String type) { + public void setObject(Object object) { this.object = object; - if (type != null) - this.type = type; content = null; } } diff --git a/mdw-common/src/com/centurylink/mdw/model/workflow/Package.java b/mdw-common/src/com/centurylink/mdw/model/workflow/Package.java index ead64d1b08..7ee29f18e8 100644 --- a/mdw-common/src/com/centurylink/mdw/model/workflow/Package.java +++ b/mdw-common/src/com/centurylink/mdw/model/workflow/Package.java @@ -158,41 +158,48 @@ public VariableTranslator getTranslator(String variableType) throws TranslationE } } - public Object getObjectValue(String type, String strValue) throws TranslationException { - return getObjectValue(type, strValue, false); + public Object getObjectValue(String variableType, String strValue) throws TranslationException { + return getObjectValue(variableType, strValue, false, null); + } + + @Deprecated + public Object getObjectValue(String variableType, String strValue, boolean deep) + throws TranslationException { + return getObjectValue(variableType, strValue, deep, null); } /** * Translates a string to a deserialized object using this package's ClassLoader. */ - public Object getObjectValue(String type, String strValue, boolean deep) throws TranslationException { + public Object getObjectValue(String variableType, String strValue, boolean deep, String documentType) + throws TranslationException { if (strValue == null || strValue.trim().isEmpty() || strValue.equals(VariableTranslator.EMPTY_STRING)) return null; - VariableTranslator translator = getTranslator(type); + VariableTranslator translator = getTranslator(variableType); if (translator == null) - throw new TranslationException("Translator not found: " + type); + throw new TranslationException("Translator not found: " + variableType); if (deep && translator instanceof DocumentReferenceTranslator) - return ((DocumentReferenceTranslator)translator).realToObject(strValue); + return ((DocumentReferenceTranslator)translator).toObject(strValue, documentType); else return translator.toObject(strValue); } - public String getStringValue(String type, Object objValue) throws TranslationException { - return getStringValue(type, objValue, false); + public String getStringValue(String variableType, Object objValue) throws TranslationException { + return getStringValue(variableType, objValue, false); } /** * Translates an object to its serialized string representation using this package's ClassLoader. */ - public String getStringValue(String type, Object objValue, boolean deep) throws TranslationException { + public String getStringValue(String variableType, Object objValue, boolean deep) throws TranslationException { if (objValue == null) return deep ? "" : VariableTranslator.EMPTY_STRING; // TODO: why - VariableTranslator translator = getTranslator(type); + VariableTranslator translator = getTranslator(variableType); if (translator == null) - throw new TranslationException("Translator not found: " + type); + throw new TranslationException("Translator not found: " + variableType); if (deep && translator instanceof DocumentReferenceTranslator) - return ((DocumentReferenceTranslator)translator).realToString(objValue); + return ((DocumentReferenceTranslator)translator).toString(objValue, variableType); else return translator.toString(objValue); } diff --git a/mdw-common/src/com/centurylink/mdw/model/workflow/ProcessRuntimeContext.java b/mdw-common/src/com/centurylink/mdw/model/workflow/ProcessRuntimeContext.java index 533cd1a79e..8ad944d5cc 100644 --- a/mdw-common/src/com/centurylink/mdw/model/workflow/ProcessRuntimeContext.java +++ b/mdw-common/src/com/centurylink/mdw/model/workflow/ProcessRuntimeContext.java @@ -409,7 +409,7 @@ public String getValueAsString(String key) throws ServiceException { if (translator instanceof JavaObjectTranslator) return obj.toString(); else if (translator instanceof DocumentReferenceTranslator) - return ((DocumentReferenceTranslator) translator).realToString(obj); + return ((DocumentReferenceTranslator)translator).toString(obj, var.getType()); else return translator.toString(obj); } catch (Exception ex) { @@ -425,7 +425,7 @@ public Object getValueForString(String varName, String strVal) throws ServiceExc try { VariableTranslator translator = getPackage().getTranslator(var.getType()); if (translator instanceof DocumentReferenceTranslator) - return ((DocumentReferenceTranslator)translator).realToObject(strVal); + return ((DocumentReferenceTranslator)translator).toObject(strVal, null); else return translator.toObject(strVal); } catch (Exception ex) { diff --git a/mdw-common/src/com/centurylink/mdw/translator/DocumentReferenceTranslator.java b/mdw-common/src/com/centurylink/mdw/translator/DocumentReferenceTranslator.java index 5c98b1ef35..f37d5d7dd0 100644 --- a/mdw-common/src/com/centurylink/mdw/translator/DocumentReferenceTranslator.java +++ b/mdw-common/src/com/centurylink/mdw/translator/DocumentReferenceTranslator.java @@ -30,15 +30,19 @@ public final String toString(Object obj) throws TranslationException { /** * toString converts DocumentReference to string, - * whereas this method converts the real object to string + * whereas this method serializes the actual object to string + * @param obj document object + * @param variableType declared variable type */ - public abstract String realToString(Object obj) - throws TranslationException; + public abstract String toString(Object obj, String variableType) + throws TranslationException; /** - * toObject converts String to DocumentReference - * whereas this methods converts the string to real object + * toObject converts String to DocumentReference, + * whereas this methods deserializes to actual object + * @param str string representation + * @param type document runtime type */ - public abstract Object realToObject(String str) - throws TranslationException; + public abstract Object toObject(String str, String type) + throws TranslationException; } diff --git a/mdw-common/src/com/centurylink/mdw/translator/DynamicJavaTranslator.java b/mdw-common/src/com/centurylink/mdw/translator/DynamicJavaTranslator.java deleted file mode 100644 index 079e3590f1..0000000000 --- a/mdw-common/src/com/centurylink/mdw/translator/DynamicJavaTranslator.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2017 CenturyLink, Inc. - * - * 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. - */ -package com.centurylink.mdw.translator; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; - -import com.centurylink.mdw.common.translator.impl.JavaObjectTranslator; - -public class DynamicJavaTranslator extends JavaObjectTranslator { - - @Override - public Object realToObject(String str) throws TranslationException { - - ObjectInputStream ois = null; - try { - byte[] decoded = decodeBase64(str); - ByteArrayInputStream bais = new ByteArrayInputStream(decoded); - ois = new ObjectInputStream(bais); - try { - return ois.readObject(); - } - catch (Exception cnfex) { - if (!(cnfex instanceof ClassNotFoundException)) - cnfex.printStackTrace(); // shouldn't happen - // try dynamic java classloader - bais.reset(); - ois.close(); - ois = new DynamicJavaInputStream(bais, getPackage()); - try { - return ois.readObject(); - } - catch (ClassNotFoundException ex2) { - // throw the original exception -- more likely to be the root cause - String msg = "Can't find: " + cnfex.getMessage() + " AND unable to locate class in Dynamic Java"; - throw new ClassNotFoundException(msg, cnfex); - } - } - } - catch (Throwable t) { // including NoClassDefFoundError - throw new TranslationException(t.getMessage(), t); - } - finally { - if (ois != null) { - try { - ois.close(); - } catch (IOException ex) {} - } - } - } - -} diff --git a/mdw-services/src/com/centurylink/mdw/listener/ExternalEventHandlerBase.java b/mdw-services/src/com/centurylink/mdw/listener/ExternalEventHandlerBase.java index 632abeeb26..ceb9446c8e 100644 --- a/mdw-services/src/com/centurylink/mdw/listener/ExternalEventHandlerBase.java +++ b/mdw-services/src/com/centurylink/mdw/listener/ExternalEventHandlerBase.java @@ -27,6 +27,8 @@ import com.centurylink.mdw.model.workflow.Process; import com.centurylink.mdw.request.RequestHandlerException; import com.centurylink.mdw.service.data.process.ProcessCache; +import com.centurylink.mdw.services.EventServices; +import com.centurylink.mdw.services.ServiceLocator; import com.centurylink.mdw.services.process.ProcessEngineDriver; import com.centurylink.mdw.services.request.Acknowledgement; import com.centurylink.mdw.services.request.BaseHandler; @@ -38,6 +40,7 @@ import com.centurylink.mdw.xml.XmlPath; import org.apache.xmlbeans.XmlObject; +import javax.xml.bind.JAXBElement; import java.io.IOException; import java.util.Map; @@ -124,8 +127,9 @@ protected String invokeServiceProcess(Long processId, Long requestId, String mas int performanceLevel, Map headers) throws Exception { Map stringParams = translateInputValues(processId, parameters); ProcessEngineDriver engineDriver = new ProcessEngineDriver(); - return engineDriver.invokeService(processId, OwnerType.DOCUMENT, requestId, masterRequestId, + Response response = engineDriver.invokeService(processId, OwnerType.DOCUMENT, requestId, masterRequestId, masterRequest, stringParams, responseVarName, performanceLevel, null, null, headers); + return response == null ? null : response.getContent(); } protected String invokeServiceProcess(Long processId, Long eventInstId, String masterRequestId, @@ -240,18 +244,25 @@ protected DocumentReference createDocument(String docType, Object document, } } - protected void updateDocumentContent(DocumentReference docref, Object doc, String type) + protected void updateDocumentContent(DocumentReference docref, Object doc, String variableType) throws ActivityException { ListenerHelper helper = new ListenerHelper(); - helper.updateDocumentContent(docref, doc, type, getPackage()); + try { + EventServices eventMgr = ServiceLocator.getEventServices(); + eventMgr.updateDocumentContent(docref.getDocumentId(), doc, pkg); + } + catch (Exception ex) { + logger.error(ex.getMessage(), ex); + throw new ActivityException(ex.getMessage(), ex); + } } public String marshalJaxb(Object jaxbObject, Package pkg) throws Exception { - return getJaxbTranslator(pkg).realToString(jaxbObject); + return getJaxbTranslator(pkg).toString(jaxbObject, JAXBElement.class.getName()); } public Object unmarshalJaxb(String xml, Package pkg) throws Exception { - return getJaxbTranslator(pkg).realToObject(xml); + return getJaxbTranslator(pkg).toObject(xml, JAXBElement.class.getName()); } static String JAXB_TRANSLATOR_CLASS = "com.centurylink.mdw.jaxb.JaxbElementTranslator"; diff --git a/mdw-services/src/com/centurylink/mdw/listener/ListenerHelper.java b/mdw-services/src/com/centurylink/mdw/listener/ListenerHelper.java index 01365b17b7..72dc6b90b3 100644 --- a/mdw-services/src/com/centurylink/mdw/listener/ListenerHelper.java +++ b/mdw-services/src/com/centurylink/mdw/listener/ListenerHelper.java @@ -15,7 +15,6 @@ */ package com.centurylink.mdw.listener; -import com.centurylink.mdw.activity.ActivityException; import com.centurylink.mdw.activity.types.StartActivity; import com.centurylink.mdw.app.ApplicationContext; import com.centurylink.mdw.cache.asset.PackageCache; @@ -26,6 +25,7 @@ import com.centurylink.mdw.dataaccess.DataAccessException; import com.centurylink.mdw.file.Packages; import com.centurylink.mdw.model.JsonObject; +import com.centurylink.mdw.model.StringDocument; import com.centurylink.mdw.model.asset.AssetPath; import com.centurylink.mdw.model.event.InternalEvent; import com.centurylink.mdw.model.listener.Listener; @@ -560,17 +560,17 @@ private boolean persistMeta(Map metaInfo) { } private Long createRequestDocument(String request, Long handlerId, String path) throws RequestHandlerException { - String docType = request == null || request.isEmpty() || isJson(request) ? JSONObject.class.getName() : XmlObject.class.getName(); - return createDocument(docType, request, null, OwnerType.LISTENER_REQUEST, handlerId, path).getDocumentId(); + String varType = request == null || request.isEmpty() || isJson(request) ? JSONObject.class.getName() : XmlObject.class.getName(); + return createDocument(varType, request, null, OwnerType.LISTENER_REQUEST, handlerId, path).getDocumentId(); } private Long createResponseDocument(Response response, Long ownerId) throws RequestHandlerException { - String docType = String.class.getName(); - return createDocument(docType, response, OwnerType.LISTENER_RESPONSE, ownerId).getDocumentId(); + String variableType = StringDocument.class.getName(); + return createDocument(variableType, response, OwnerType.LISTENER_RESPONSE, ownerId).getDocumentId(); } private JSONObject createRequestMetaDocument(Map metaInfo, Set reqMetaInfo, Long ownerId) - throws RequestHandlerException, JSONException{ + throws RequestHandlerException { JSONObject meta = new JsonObject(); JSONObject headers = new JsonObject(); @@ -685,9 +685,9 @@ private XmlObject parseXmlBean(String request) { } } - public DocumentReference createDocument(String docType, Object document, String ownerType, Long ownerId) + public DocumentReference createDocument(String variableType, Object document, String ownerType, Long ownerId) throws RequestHandlerException { - return createDocument(docType, document, null, ownerType, ownerId); + return createDocument(variableType, document, null, ownerType, ownerId); } /** @@ -695,10 +695,9 @@ public DocumentReference createDocument(String docType, Object document, String * document reference returned can be sent as parameters to start or inform * processes. * - * @param docType - * this should be variable type if the document reference is to - * be bound to variables. - * @param document + * @param variableType + * Variable type for serializing + * @param docObj * The document object itself, such as an XML bean document * (subclass of XmlObject) * @param pkg @@ -713,16 +712,16 @@ public DocumentReference createDocument(String docType, Object document, String * This should be the external event handler ID for * LISTENER_REQUEST and request document ID for LISTENER_RESPONSE */ - public DocumentReference createDocument(String docType, Object document, Package pkg, String ownerType, Long ownerId) + public DocumentReference createDocument(String variableType, Object docObj, Package pkg, String ownerType, Long ownerId) throws RequestHandlerException { - return createDocument(docType, document, pkg, ownerType, ownerId, null); + return createDocument(variableType, docObj, pkg, ownerType, ownerId, null); } - public DocumentReference createDocument(String docType, Object document, Package pkg, + public DocumentReference createDocument(String variableType, Object docObj, Package pkg, String ownerType, Long ownerId, String path) throws RequestHandlerException { // TODO: proper package association (usually pkg is null) try { - Long docId = ServiceLocator.getEventServices().createDocument(docType, ownerType, ownerId, document, pkg, path); + Long docId = ServiceLocator.getEventServices().createDocument(variableType, ownerType, ownerId, docObj, pkg, path); return new DocumentReference(docId); } catch (Exception ex) { @@ -731,19 +730,7 @@ public DocumentReference createDocument(String docType, Object document, Package } } - public void updateDocumentContent(DocumentReference docref, Object doc, String type, Package pkg) - throws ActivityException { - try { - EventServices eventMgr = ServiceLocator.getEventServices(); - eventMgr.updateDocumentContent(docref.getDocumentId(), doc, type, pkg); - } - catch (Exception ex) { - logger.error(ex.getMessage(), ex); - throw new ActivityException(ex.getMessage(), ex); - } - } - - public ServiceHandler getServiceHandler(String request, Map metaInfo) + public ServiceHandler getServiceHandler(String request, Map metaInfo) throws EventException { EventServices eventMgr = ServiceLocator.getEventServices(); String protocol = metaInfo.get(Listener.METAINFO_PROTOCOL); diff --git a/mdw-services/src/com/centurylink/mdw/listener/ProcessStartEventHandler.java b/mdw-services/src/com/centurylink/mdw/listener/ProcessStartEventHandler.java index cb01b08a49..d3d4cfec46 100644 --- a/mdw-services/src/com/centurylink/mdw/listener/ProcessStartEventHandler.java +++ b/mdw-services/src/com/centurylink/mdw/listener/ProcessStartEventHandler.java @@ -91,8 +91,8 @@ protected Map buildParameters(XmlObject msgdoc, Map getRoles(String path) { - List roles = super.getRoles(path); - roles.add(Role.PROCESS_EXECUTION); - return roles; - } - - /** - * Retrieve a document string value - */ - @Override - @Path("/{documentId}") - public JSONObject get(String path, Map headers) - throws ServiceException, JSONException { - WorkflowServices workflowServices = ServiceLocator.getWorkflowServices(); - String docId = getSegment(path, 1); - if (docId == null) { - throw new ServiceException(ServiceException.BAD_REQUEST, "Invalid path: " + path); - } - try { - JSONObject json = new JSONObject(); - json.put("value", workflowServices.getDocumentStringValue(Long.valueOf(docId))); - return json; - } - catch (NumberFormatException e) { - throw new ServiceException(ServiceException.BAD_REQUEST, "Invalid path: " + path, e); - } - } -} diff --git a/mdw-services/src/com/centurylink/mdw/services/EventServices.java b/mdw-services/src/com/centurylink/mdw/services/EventServices.java index 6a3d6074db..7fa0922cc6 100644 --- a/mdw-services/src/com/centurylink/mdw/services/EventServices.java +++ b/mdw-services/src/com/centurylink/mdw/services/EventServices.java @@ -37,14 +37,14 @@ public interface EventServices { void createAuditLog(UserAction userAction) throws DataAccessException, EventException; - Long createEventLog(String pEventName, String pEventCategory, String pEventSubCat, String pEventSource, - String pEventOwner, Long pEventOwnerId, String user, String modUser, String comments) + Long createEventLog(String eventName, String category, String subcategory, String source, + String ownerType, Long ownerId, String user, String modUser, String comments) throws DataAccessException, EventException; - List getEventLogs(String pEventName, String pEventSource, - String pEventOwner, Long pEventOwnerId) throws ServiceException; + List getEventLogs(String eventName, String source, + String ownerType, Long ownerId) throws ServiceException; - Integer notifyProcess(String pEventName, Long pEventInstId, String message, int delay) + Integer notifyProcess(String eventName, Long eventInstanceId, String message, int delay) throws DataAccessException, EventException; /** @@ -72,16 +72,16 @@ VariableInstance getVariableInstance(Long procInstId, String name) VariableInstance setVariableInstance(Long procInstId, String name, Object value, Package pkg) throws DataAccessException; - void updateDocumentContent(Long docid, Object doc, String type, Package pkg) + void updateDocumentContent(Long docid, Object docObj, Package pkg) throws DataAccessException; void updateDocumentInfo(Long docid, String documentType, String ownerType, Long ownerId) throws DataAccessException; - Long createDocument(String type, String ownerType, Long ownerId, Object doc, Package pkg) + Long createDocument(String variableType, String ownerType, Long ownerId, Object docObj, Package pkg) throws DataAccessException; - Long createDocument(String type, String ownerType, Long ownerId, Object doc, Package pkg, String path) + Long createDocument(String variableType, String ownerType, Long ownerId, Object docObj, Package pkg, String path) throws DataAccessException; void sendDelayEventsToWaitActivities(String masterRequestId) diff --git a/mdw-services/src/com/centurylink/mdw/services/WorkflowServices.java b/mdw-services/src/com/centurylink/mdw/services/WorkflowServices.java index d5b6255913..800b709dfe 100644 --- a/mdw-services/src/com/centurylink/mdw/services/WorkflowServices.java +++ b/mdw-services/src/com/centurylink/mdw/services/WorkflowServices.java @@ -22,6 +22,7 @@ import com.centurylink.mdw.model.report.Hotspot; import com.centurylink.mdw.model.report.Insight; import com.centurylink.mdw.model.report.Timepoint; +import com.centurylink.mdw.model.request.Response; import com.centurylink.mdw.model.variable.Document; import com.centurylink.mdw.model.variable.VariableInstance; import com.centurylink.mdw.model.workflow.Package; @@ -181,20 +182,20 @@ Long launchProcess(String name, String masterRequestId, String ownerType, Long launchProcess(Process process, String masterRequestId, String ownerType, Long ownerId, Map params) throws ServiceException; - Object invokeServiceProcess(String processName, Object masterRequest, String masterRequestId, + Response invokeServiceProcess(String processName, Object masterRequest, String masterRequestId, Map parameters, Map headers) throws ServiceException; - String invokeServiceProcess(Process process, String masterRequestId, String ownerType, + Response invokeServiceProcess(Process process, String masterRequestId, String ownerType, Long ownerId, Map params, Map headers) throws ServiceException; /** * responseHeaders will be populated from process variable, if any */ - Object invokeServiceProcess(String processName, Object masterRequest, String masterRequestId, - Map parameters, Map headers, Map responseHeaders) throws ServiceException; + Response invokeServiceProcess(String processName, Object masterRequest, String masterRequestId, + Map parameters, Map headers, Map responseHeaders) throws ServiceException; - String invokeServiceProcess(Process process, String masterRequestId, String ownerType, - Long ownerId, Map params) throws ServiceException; + Response invokeServiceProcess(Process process, String masterRequestId, String ownerType, + Long ownerId, Map params) throws ServiceException; Integer notify(String event, String message, int delay) throws ServiceException; @@ -220,9 +221,7 @@ String invokeServiceProcess(Process process, String masterRequestId, String owne * Converts a document to a string, applying a consistent format for XML and JSON. * Use when comparing document values (such as in Automated Tests). */ - String getDocumentStringValue(Long id) throws ServiceException; - - String getDocType(Object docObj); + String getDocumentStringValue(Long id, String variableType, Package pkg) throws ServiceException; ProcessRun runProcess(ProcessRun runRequest) throws ServiceException; diff --git a/mdw-services/src/com/centurylink/mdw/services/event/EventServicesImpl.java b/mdw-services/src/com/centurylink/mdw/services/event/EventServicesImpl.java index 4334b7e37a..06feb7f2c3 100644 --- a/mdw-services/src/com/centurylink/mdw/services/event/EventServicesImpl.java +++ b/mdw-services/src/com/centurylink/mdw/services/event/EventServicesImpl.java @@ -73,22 +73,22 @@ public void createAuditLog(UserAction userAction) throws DataAccessException, Ev /** * Method that creates the event log based on the passed in params * - * @param pEventName event name - * @param pEventCategory event category - * @param pEventSource event source - * @param pEventOwner event owner - * @param pEventOwnerId event owner id + * @param eventName event name + * @param category event category + * @param source event source + * @param ownerType event owner + * @param ownerId event owner id * @return EventLog */ - public Long createEventLog(String pEventName, String pEventCategory, String pEventSubCat, String pEventSource, - String pEventOwner, Long pEventOwnerId, String user, String modUser, String comments) + public Long createEventLog(String eventName, String category, String subcategory, String source, + String ownerType, Long ownerId, String user, String modUser, String comments) throws DataAccessException, EventException { TransactionWrapper transaction = null; EngineDataAccessDB edao = new EngineDataAccessDB(); try { transaction = edao.startTransaction(); - return edao.recordEventLog(pEventName, pEventCategory, pEventSubCat, - pEventSource, pEventOwner, pEventOwnerId, user, modUser, comments); + return edao.recordEventLog(eventName, category, subcategory, + source, ownerType, ownerId, user, modUser, comments); } catch (SQLException e) { edao.rollbackTransaction(transaction); throw new EventException("Failed to create event log", e); @@ -97,12 +97,12 @@ public Long createEventLog(String pEventName, String pEventCategory, String pEve } } - public Integer notifyProcess(String eventName, Long docId, String message, int delay) + public Integer notifyProcess(String eventName, Long eventInstanceId, String message, int delay) throws DataAccessException, EventException { EngineDataAccess edao = new EngineDataAccessDB(); InternalMessenger msgBroker = MessengerFactory.newInternalMessenger(); ProcessExecutor engine = new ProcessExecutor(edao, msgBroker, false); - return engine.notifyProcess(eventName, docId, message, delay); + return engine.notifyProcess(eventName, eventInstanceId, message, delay); } /** @@ -463,7 +463,7 @@ public TransitionInstance getWorkTransitionInstance(Long pId) return wti; } - public void updateDocumentContent(Long docId, Object docObj, String type, Package pkg) + public void updateDocumentContent(Long docId, Object docObj, Package pkg) throws DataAccessException { TransactionWrapper transaction = null; EngineDataAccessDB edao = new EngineDataAccessDB(); @@ -473,7 +473,7 @@ public void updateDocumentContent(Long docId, Object docObj, String type, Packag if (docObj instanceof String) doc.setContent((String)docObj); else - doc.setObject(docObj, type); + doc.setObject(docObj); edao.updateDocumentContent(doc.getId(), doc.getContent(pkg)); } catch (SQLException e) { throw new DataAccessException(-1, "Failed to update document content", e); @@ -488,17 +488,17 @@ public void updateDocumentInfo(Long docid, String documentType, EngineDataAccessDB edao = new EngineDataAccessDB(); try { transaction = edao.startTransaction(); - Document docvo = edao.getDocument(docid, false); + Document doc = edao.getDocument(docid, false); if (documentType != null) - docvo.setType(documentType); + doc.setType(documentType); if (ownerType != null) { - if (!ownerType.equalsIgnoreCase(docvo.getOwnerType())) - edao.getDocumentDbAccess().updateDocumentDbOwnerType(docvo, ownerType); - docvo.setOwnerType(ownerType); + if (!ownerType.equalsIgnoreCase(doc.getOwnerType())) + edao.getDocumentDbAccess().updateDocumentDbOwnerType(doc, ownerType); + doc.setOwnerType(ownerType); } if (ownerId != null) - docvo.setOwnerId(ownerId); - edao.updateDocumentInfo(docvo); + doc.setOwnerId(ownerId); + edao.updateDocumentInfo(doc); } catch (SQLException e) { throw new DataAccessException(-1, "Failed to update document content", e); @@ -508,12 +508,12 @@ public void updateDocumentInfo(Long docid, String documentType, } } - public Long createDocument(String type, String ownerType, Long ownerId, Object doc, Package pkg) + public Long createDocument(String variableType, String ownerType, Long ownerId, Object docObj, Package pkg) throws DataAccessException { - return createDocument(type, ownerType, ownerId, doc, pkg, null); + return createDocument(variableType, ownerType, ownerId, docObj, pkg,null); } - public Long createDocument(String type, String ownerType, Long ownerId, Object docObj, Package pkg, String path) + public Long createDocument(String variableType, String ownerType, Long ownerId, Object docObj, Package pkg, String path) throws DataAccessException { TransactionWrapper transaction = null; EngineDataAccessDB edao = new EngineDataAccessDB(); @@ -532,8 +532,9 @@ public Long createDocument(String type, String ownerType, Long ownerId, Object d else if (docObj instanceof String) doc.setContent((String)docObj); else - doc.setObject(docObj, type); - doc.setType(type); + doc.setObject(docObj); + doc.setVariableType(variableType); + doc.setType(docObj == null || docObj instanceof String ? variableType : docObj.getClass().getName()); doc.setOwnerType(ownerType); doc.setOwnerId(ownerId); doc.setPath(path); @@ -545,11 +546,11 @@ else if (docObj instanceof String) } } - public List getEventLogs(String eventName, String eventSource, - String eventOwner, Long ownerId) throws ServiceException { + public List getEventLogs(String eventName, String source, + String ownerType, Long ownerId) throws ServiceException { EventDataAccess dataAccess = new EventDataAccess(); try { - return dataAccess.getEventLogs(eventName, eventSource, eventOwner, ownerId); + return dataAccess.getEventLogs(eventName, source, ownerType, ownerId); } catch (DataAccessException ex) { throw new ServiceException(ServiceException.INTERNAL_ERROR, ex.getMessage(), ex); } diff --git a/mdw-services/src/com/centurylink/mdw/services/process/BaseActivity.java b/mdw-services/src/com/centurylink/mdw/services/process/BaseActivity.java index 02dae0c8c6..d7526aff9c 100644 --- a/mdw-services/src/com/centurylink/mdw/services/process/BaseActivity.java +++ b/mdw-services/src/com/centurylink/mdw/services/process/BaseActivity.java @@ -97,7 +97,7 @@ public abstract class BaseActivity implements GeneralActivity { /** * Repopulates variable values in case they've changed during execution. */ - public ActivityRuntimeContext getRuntimeContext() throws ActivityException { + public ActivityRuntimeContext getRuntimeContext() { for (VariableInstance var : getParameters()) { try { _runtimeContext.getValues().put(var.getName(), getVariableValue(var.getName())); @@ -562,18 +562,18 @@ protected Long setParameterValue(Long processInstId, String name, Object value) * The method will throw an exception if the document reference points to * a remote document. * @param name name - * @param varType variable type + * @param variableType variable type * @param value this is the document */ - protected DocumentReference setParameterValueAsDocument(String name, String varType, Object value) + protected DocumentReference setParameterValueAsDocument(String name, String variableType, Object value) throws ActivityException { DocumentReference docref = (DocumentReference)this.getParameterValue(name); if (docref == null) { - docref = createDocument(varType, value, OwnerType.VARIABLE_INSTANCE, 0L); + docref = createDocument(variableType, value, OwnerType.VARIABLE_INSTANCE, 0L); Long varInstId = setParameterValue(name, docref); updateDocumentInfo(docref, null, OwnerType.VARIABLE_INSTANCE, varInstId); } else { - updateDocumentContent(docref, value, varType); + updateDocumentContent(docref, value, variableType); } return docref; } @@ -846,54 +846,54 @@ protected String translatePlaceHolder(String eventName) { * Given a document reference object (typically bound to a * document variable), returns the actual document object. */ - protected Object getDocument(DocumentReference docref, String type) throws ActivityException { - Document docvo; + protected Object getDocument(DocumentReference docRef, String variableType) throws ActivityException { + Document doc; try { - docvo = engine.getDocument(docref, false); + doc = engine.getDocument(docRef, false); // deserialize if needed - docvo.getObject(type, getPackage()); + return doc.getObject(variableType, getPackage()); } catch (Exception ex) { - logexception("Error retrieving " + docref, ex); - throw new ActivityException("Error retrieving " + docref, ex); + logexception("Error retrieving " + docRef, ex); + throw new ActivityException("Error retrieving " + docRef, ex); } - return docvo.getObject(type, getPackage()); } - protected String getDocumentContent(DocumentReference docref) throws ActivityException { - Document docvo; + protected String getDocumentContent(DocumentReference docRef) + throws ActivityException { + Document doc; try { - docvo = engine.getDocument(docref, false); + doc = engine.getDocument(docRef, false); + return doc == null ? null : doc.getContent(getPackage()); } catch (Exception ex) { - logexception("Error retrieving " + docref, ex); - throw new ActivityException("Error retrieving " + docref, ex); + logexception("Error retrieving " + docRef, ex); + throw new ActivityException("Error retrieving " + docRef, ex); } - return docvo==null?null:docvo.getContent(getPackage()); } /** * Same as getDocument() but also puts a write lock on it. * The lock will be released at the end of the transaction. * - * @param docref document reference + * @param docRef document reference */ - protected Object getDocumentForUpdate(DocumentReference docref, String type) - throws ActivityException { - Document docvo; + protected Object getDocumentForUpdate(DocumentReference docRef, String variableType) throws ActivityException { + Document doc; try { - docvo = engine.getDocument(docref, true); + doc = engine.getDocument(docRef, true); // deserialize here (TODO why?) - Object obj = getPackage().getObjectValue(type, docvo.getContent(getPackage()), true); - docvo.setObject(obj, type); + Object obj = getPackage().getObjectValue(variableType, doc.getContent(getPackage()), true, doc.getType()); + doc.setObject(obj); + doc.setVariableType(variableType); } catch (Exception ex) { - logexception("Error retrieving " + docref, ex); - throw new ActivityException("Error retrieving " + docref, ex); + logexception("Error retrieving " + docRef, ex); + throw new ActivityException("Error retrieving " + docRef, ex); } - return docvo.getObject(type, getPackage()); + return doc.getObject(variableType, getPackage()); } - protected DocumentReference createDocument(String docType, Object document, String ownerType, + protected DocumentReference createDocument(String variableType, Object document, String ownerType, Long ownerId) throws ActivityException { - return createDocument(docType, document, ownerType, ownerId, null, null, null); + return createDocument(variableType, document, ownerType, ownerId, null, null, null); } protected DocumentReference createDocument(String docType, Object document, String ownerType, @@ -901,12 +901,17 @@ protected DocumentReference createDocument(String docType, Object document, Stri return createDocument(docType, document, ownerType, ownerId, null, null, path); } + protected DocumentReference createDocument(String variableType, Object document, String ownerType, + Long ownerId, Integer statusCode, String statusMessage) throws ActivityException { + return createDocument(variableType, document, ownerType, ownerId, statusCode, statusMessage, null); + } + /** * Create a new document, persisted in database, and return a document * reference object, to be bound to a variable. * - * @param docType type of the document (i.e. variable type) - * @param document document object itself + * @param variableType type of the document (i.e. variable type) + * @param docObj document object itself * @param ownerType owner type. More than likely this will be OwnerType.VARIABLE_INSTANCE * other possible types are LISTENER_REQUEST, LISTENER_RESPONSE, * ADAPTOR_REQUEST, ADAPTOR_RESPONSE @@ -915,19 +920,14 @@ protected DocumentReference createDocument(String docType, Object document, Stri * @param statusMessage message * @return document reference */ - protected DocumentReference createDocument(String docType, Object document, String ownerType, - Long ownerId, Integer statusCode, String statusMessage) throws ActivityException { - return createDocument(docType, document, ownerType, ownerId, statusCode, statusMessage, null); - } - - protected DocumentReference createDocument(String docType, Object document, String ownerType, + protected DocumentReference createDocument(String variableType, Object docObj, String ownerType, Long ownerId, Integer statusCode, String statusMessage, String path) throws ActivityException { try { - if (!(document instanceof String)) { - // do serialization here TODO: left over from package-aware translator providers - document = getPackage().getStringValue(docType, document, true); + if (!(docObj instanceof String)) { + // do serialization here TODO: left over from package-aware translator providers? + docObj = getPackage().getStringValue(variableType, docObj, true); } - return engine.createDocument(docType, ownerType, ownerId, statusCode, statusMessage, path, document); + return engine.createDocument(variableType, ownerType, ownerId, statusCode, statusMessage, path, docObj, getPackage()); } catch (Exception ex) { logger.error(ex.getMessage(), ex); throw new ActivityException(ex.getMessage(), ex); @@ -937,17 +937,17 @@ protected DocumentReference createDocument(String docType, Object document, Stri /** * Update the content (actual document object) bound to the given * document reference object. - * @param docref document reference - * @param document document + * @param docRef document reference + * @param docObj document */ - protected void updateDocumentContent(DocumentReference docref, Object document, String type) + protected void updateDocumentContent(DocumentReference docRef, Object docObj, String variableType) throws ActivityException { try { - if (!(document instanceof String)) { + if (!(docObj instanceof String)) { // serialize here TODO: leftover support for package aware translator providers - document = getPackage().getStringValue(type, document, true); + docObj = getPackage().getStringValue(variableType, docObj, true); } - engine.updateDocumentContent(docref, document, type, getPackage()); + engine.updateDocumentContent(docRef, docObj, getPackage()); } catch (Exception ex) { logger.error(ex.getMessage(), ex); throw new ActivityException(ex.getMessage(), ex); @@ -1273,7 +1273,7 @@ protected void setVariableValue(String varName, String varType, Object value) th // don't check in production (or for cache-only perf level since old values are not retained) if (!ApplicationContext.isProduction() && (getPerformanceLevel() < 5)) { - boolean changed = hasDocumentValueChanged(varName, value); + boolean changed = hasDocumentValueChanged(varName, varType, value); if (changed){ if (!isOutputDoc) { @@ -1318,7 +1318,7 @@ protected boolean isOutputDocument(String variableName) { return false; } - private boolean hasDocumentValueChanged(String varName, Object newValue) throws DataAccessException { + private boolean hasDocumentValueChanged(String varName, String varType, Object newValue) throws DataAccessException { DocumentReference docRef = (DocumentReference) getParameterValue(varName); if (docRef == null) @@ -1332,20 +1332,21 @@ private boolean hasDocumentValueChanged(String varName, Object newValue) throws if (newValue == null) return true; // we already know old value is not null + + String docType = newValue.getClass().getName(); String oldString = doc.getContent(getPackage()); - Object oldObject = getPackage().getObjectValue(doc.getType(), oldString, true); + Object oldObject = getPackage().getObjectValue(varType, oldString, true, docType); if (doc.getType().equals(Object.class.getName())) return !newValue.equals(oldObject); // general comparison involves reserializing since round-trip results are not guaranteed - oldString = getPackage().getStringValue(doc.getType(), oldObject, true); - String newString = getPackage().getStringValue(doc.getType(), newValue, true); + oldString = getPackage().getStringValue(varType, oldObject, true); + String newString = getPackage().getStringValue(varType, newValue, true); return !newString.equals(oldString); } - public TransactionWrapper startTransaction() - throws ActivityException { + public TransactionWrapper startTransaction() throws ActivityException { try { return engine.startTransaction(); } catch (DataAccessException e) { @@ -1353,8 +1354,7 @@ public TransactionWrapper startTransaction() } } - public void stopTransaction(TransactionWrapper transaction) - throws ActivityException { + public void stopTransaction(TransactionWrapper transaction) throws ActivityException { try { engine.stopTransaction(transaction); } catch (DataAccessException e) { diff --git a/mdw-services/src/com/centurylink/mdw/services/process/ProcessEngineDriver.java b/mdw-services/src/com/centurylink/mdw/services/process/ProcessEngineDriver.java index 62eb351e40..22a502e3d6 100644 --- a/mdw-services/src/com/centurylink/mdw/services/process/ProcessEngineDriver.java +++ b/mdw-services/src/com/centurylink/mdw/services/process/ProcessEngineDriver.java @@ -32,6 +32,7 @@ import com.centurylink.mdw.model.event.InternalEvent; import com.centurylink.mdw.model.listener.Listener; import com.centurylink.mdw.model.monitor.ScheduledEvent; +import com.centurylink.mdw.model.request.Response; import com.centurylink.mdw.model.variable.Document; import com.centurylink.mdw.model.variable.DocumentReference; import com.centurylink.mdw.model.variable.Variable; @@ -682,19 +683,20 @@ private void processEvent(ProcessExecutor engine, InternalEvent event, ProcessIn } } - private void addDocumentToCache(ProcessExecutor engine, Long docid, String type, String content) { + private void addDocumentToCache(ProcessExecutor engine, Long docId, String variableType, String docType, String content, Package pkg) { if (content != null) { - if (docid == 0L) { + if (docId == 0L) { try { - engine.createDocument(type, OwnerType.LISTENER_REQUEST, 0L, content); + engine.createDocument(variableType, OwnerType.LISTENER_REQUEST, 0L, content, pkg); } catch (DataAccessException e) { // should never happen, as this is cache only } } else { Document doc = new Document(); doc.setContent(content); - doc.setId(docid); - doc.setType(type); + doc.setId(docId); + doc.setType(docType); + doc.setVariableType(variableType); engine.addDocumentToCache(doc); } } @@ -704,7 +706,7 @@ private void addDocumentToCache(ProcessExecutor engine, Long docid, String type, * Invoke a real-time service process. * @return the service response */ - public String invokeService(Long processId, String ownerType, + public Response invokeService(Long processId, String ownerType, Long ownerId, String masterRequestId, String masterRequest, Map parameters, String responseVarName, Map headers) throws Exception { return invokeService(processId, ownerType, ownerId, masterRequestId, masterRequest, parameters, responseVarName, 0, null, null, headers); @@ -735,7 +737,7 @@ public String invokeService(Long processId, String ownerType, * @return response message, which is obtained from the variable named ie responseVarName * of the process. */ - public String invokeService(Long processId, String ownerType, + public Response invokeService(Long processId, String ownerType, Long ownerId, String masterRequestId, String masterRequest, Map parameters, String responseVarName, int performanceLevel, String secondaryOwnerType, Long secondaryOwnerId, Map headers) @@ -753,8 +755,9 @@ public String invokeService(Long processId, String ownerType, ProcessExecutor engine = new ProcessExecutor(edao, msgBroker, true); engineLogger.setPerformanceLevel(performanceLevel); if (performanceLevel >= 5) { - if (OwnerType.DOCUMENT.equals(ownerType)) - addDocumentToCache(engine, ownerId, XmlObject.class.getName(), masterRequest); + if (OwnerType.DOCUMENT.equals(ownerType)) { + addDocumentToCache(engine, ownerId, XmlObject.class.getName(), XmlObject.class.getName(), masterRequest, pkg); + } if (parameters != null) { for (String key : parameters.keySet()) { String value = parameters.get(key); @@ -764,8 +767,9 @@ public String invokeService(Long processId, String ownerType, Document doc = engine.loadDocument(docRef, false); if (doc != null) { String docContent = doc.getContent(pkg); - if (docContent != null) - addDocumentToCache(engine, docRef.getDocumentId(), doc.getType(), docContent); + if (docContent != null) { + addDocumentToCache(engine, docRef.getDocumentId(), process.getVariable(key).getType(), doc.getType(), docContent, pkg); + } } } } @@ -777,12 +781,15 @@ public String invokeService(Long processId, String ownerType, boolean completed = mainProcessInst.getStatusCode().equals(WorkStatus.STATUS_COMPLETED); if (headers != null) headers.put(Listener.METAINFO_MDW_PROCESS_INSTANCE_ID, mainProcessInst.getId().toString()); - String resp = completed ? engine.getSynchronousProcessResponse(mainProcessInst.getId(), responseVarName, pkg) : null; + Response response = null; + if (completed) { + response = engine.getSynchronousProcessResponse(mainProcessInst.getId(), responseVarName, pkg); + } long stopMilli = System.currentTimeMillis(); logger.info("Synchronous process executed in " + ((stopMilli - startMilli) / 1000.0) + " seconds at performance level " + performanceLevel); if (completed) - return resp; + return response; if (lastException == null) throw new ProcessException("Process instance not completed"); throw new ProcessException(lastException.getMessage(), lastException); @@ -901,13 +908,13 @@ private void bindRequestVariable(Process procdef, engine.createVariableInstance(pi, VariableConstants.REQUEST, docref); } - private void bindRequestHeadersVariable(Process procdef, Map headers, + private void bindRequestHeadersVariable(Process process, Map headers, ProcessExecutor engine, ProcessInstance pi) throws DataAccessException { - Variable headersVO = procdef.getVariable(VariableConstants.REQUEST_HEADERS); - if (headersVO == null) + Variable headersVar = process.getVariable(VariableConstants.REQUEST_HEADERS); + if (headersVar == null) return; - int cat = headersVO.getVariableCategory(); - String vartype = headersVO.getType(); + int cat = headersVar.getVariableCategory(); + String varType = headersVar.getType(); if (cat != Variable.CAT_INPUT && cat != Variable.CAT_INOUT) return; List viList = pi.getVariables(); @@ -918,16 +925,13 @@ private void bindRequestHeadersVariable(Process procdef, Map head } } - if (vartype.equals(Map.class.getName())) { - engine.createVariableInstance(pi, VariableConstants.REQUEST_HEADERS, headers); - } - else if (vartype.equals("java.util.Map") || vartype.equals(Object.class.getName())) { - DocumentReference docRef = engine.createDocument(vartype, OwnerType.VARIABLE_INSTANCE, 0L, headers); + if (varType.equals("java.util.Map") || varType.equals(Object.class.getName())) { + DocumentReference docRef = engine.createDocument(varType, OwnerType.VARIABLE_INSTANCE, 0L, headers, getPackage(process)); VariableInstance varInst = engine.createVariableInstance(pi, VariableConstants.REQUEST_HEADERS, docRef); - engine.updateDocumentInfo(docRef, null, null, varInst.getInstanceId(), null, null); + engine.updateDocumentInfo(docRef, null, null, varInst.getId(), null, null); } else { - logger.info("Implicit requestHeaders supports variable types " + Map.class.getName() + " or " + Object.class.getName()); + logger.info("Implicit requestHeaders supports variable type java.util.Map"); } } diff --git a/mdw-services/src/com/centurylink/mdw/services/process/ProcessExecutor.java b/mdw-services/src/com/centurylink/mdw/services/process/ProcessExecutor.java index cc2faeeff8..772a7721d7 100644 --- a/mdw-services/src/com/centurylink/mdw/services/process/ProcessExecutor.java +++ b/mdw-services/src/com/centurylink/mdw/services/process/ProcessExecutor.java @@ -25,6 +25,7 @@ import com.centurylink.mdw.dataaccess.RetryableTransaction; import com.centurylink.mdw.model.event.EventWaitInstance; import com.centurylink.mdw.model.event.InternalEvent; +import com.centurylink.mdw.model.request.Response; import com.centurylink.mdw.model.variable.Document; import com.centurylink.mdw.model.variable.DocumentReference; import com.centurylink.mdw.model.variable.VariableInstance; @@ -825,26 +826,26 @@ public Document loadDocument(DocumentReference docRef, boolean forUpdate) throws } } - public DocumentReference createDocument(String type, String ownerType, Long ownerId, Object doc) + public DocumentReference createDocument(String variableType, String ownerType, Long ownerId, Object docObj, Package pkg) throws DataAccessException { - return createDocument(type, ownerType, ownerId, null, null, doc); + return createDocument(variableType, ownerType, ownerId, null, null, docObj, pkg); } - public DocumentReference createDocument(String type, String ownerType, Long ownerId, Integer statusCode, - String statusMessage, Object doc) throws DataAccessException { - return createDocument(type, ownerType, ownerId, statusCode, statusMessage, null, doc); + public DocumentReference createDocument(String variableType, String ownerType, Long ownerId, Integer statusCode, + String statusMessage, Object docObj, Package pkg) throws DataAccessException { + return createDocument(variableType, ownerType, ownerId, statusCode, statusMessage, null, docObj, pkg); } - public DocumentReference createDocument(String type, String ownerType, Long ownerId, Integer statusCode, - String statusMessage, String path, Object doc) throws DataAccessException { + public DocumentReference createDocument(String variableType, String ownerType, Long ownerId, Integer statusCode, + String statusMessage, String path, Object docObj, Package pkg) throws DataAccessException { TransactionWrapper transaction = null; try { transaction = startTransaction(); - return engineImpl.createDocument(type, ownerType, ownerId, statusCode, statusMessage, path, doc); + return engineImpl.createDocument(variableType, ownerType, ownerId, statusCode, statusMessage, path, docObj, pkg); } catch (DataAccessException ex) { if (canRetryTransaction(ex)) { transaction = (TransactionWrapper)initTransactionRetry(transaction); - return ((ProcessExecutor)getTransactionRetrier()).createDocument(type, ownerType, ownerId, statusCode, statusMessage, path, doc); + return ((ProcessExecutor)getTransactionRetrier()).createDocument(variableType, ownerType, ownerId, statusCode, statusMessage, path, docObj, pkg); } else { throw ex; @@ -854,16 +855,16 @@ public DocumentReference createDocument(String type, String ownerType, Long owne } } - public void updateDocumentContent(DocumentReference docRef, Object doc, String type, Package pkg) + public void updateDocumentContent(DocumentReference docRef, Object doc, Package pkg) throws DataAccessException { TransactionWrapper transaction = null; try { transaction = startTransaction(); - engineImpl.updateDocumentContent(docRef, doc, type, pkg); + engineImpl.updateDocumentContent(docRef, doc, pkg); } catch (DataAccessException ex) { if (canRetryTransaction(ex)) { transaction = (TransactionWrapper)initTransactionRetry(transaction); - ((ProcessExecutor)getTransactionRetrier()).updateDocumentContent(docRef, doc, type, pkg); + ((ProcessExecutor)getTransactionRetrier()).updateDocumentContent(docRef, doc, pkg); } else { throw ex; @@ -1046,7 +1047,7 @@ public void sendDelayedInternalEvent(InternalEvent event, int delaySeconds, Stri } } - public String getSynchronousProcessResponse(Long procInstId, String varName, Package pkg) + public Response getSynchronousProcessResponse(Long procInstId, String varName, Package pkg) throws DataAccessException { TransactionWrapper transaction = null; try { diff --git a/mdw-services/src/com/centurylink/mdw/services/process/ProcessExecutorImpl.java b/mdw-services/src/com/centurylink/mdw/services/process/ProcessExecutorImpl.java index b4d9da7f59..5d14ef8542 100644 --- a/mdw-services/src/com/centurylink/mdw/services/process/ProcessExecutorImpl.java +++ b/mdw-services/src/com/centurylink/mdw/services/process/ProcessExecutorImpl.java @@ -30,6 +30,7 @@ import com.centurylink.mdw.model.event.EventWaitInstance; import com.centurylink.mdw.model.event.InternalEvent; import com.centurylink.mdw.model.monitor.ScheduledEvent; +import com.centurylink.mdw.model.request.Response; import com.centurylink.mdw.model.variable.Document; import com.centurylink.mdw.model.variable.DocumentReference; import com.centurylink.mdw.model.variable.Variable; @@ -137,33 +138,34 @@ VariableInstance createVariableInstance(ProcessInstance processInstance, String return variableInstance; } - DocumentReference createDocument(String type, String ownerType, Long ownerId, Object document) + DocumentReference createDocument(String variableType, String ownerType, Long ownerId, Object docObj, Package pkg) throws DataAccessException { - return createDocument(type, ownerType, ownerId, null, null, document); + return createDocument(variableType, ownerType, ownerId, null, null, docObj, pkg); } - DocumentReference createDocument(String type, String ownerType, Long ownerId, - Integer statusCode, String statusMessage, Object document) throws DataAccessException { - return createDocument(type, ownerType, ownerId, statusCode, statusMessage, null, document); + DocumentReference createDocument(String variableType, String ownerType, Long ownerId, + Integer statusCode, String statusMessage, Object docObj, Package pkg) throws DataAccessException { + return createDocument(variableType, ownerType, ownerId, statusCode, statusMessage, null, docObj, pkg); } - DocumentReference createDocument(String type, String ownerType, Long ownerId, - Integer statusCode, String statusMessage, String path, Object document) + DocumentReference createDocument(String variableType, String ownerType, Long ownerId, + Integer statusCode, String statusMessage, String path, Object docObj, Package pkg) throws DataAccessException { DocumentReference docRef; try { Document doc = new Document(); - if (document instanceof String) - doc.setContent((String)document); + if (docObj instanceof String) + doc.setContent((String)docObj); else - doc.setObject(document, type); - doc.setType(type); + doc.setObject(docObj); + doc.setType(docObj == null || docObj instanceof String ? variableType : docObj.getClass().getName()); + doc.setVariableType(variableType); doc.setOwnerType(ownerType); doc.setOwnerId(ownerId); doc.setStatusCode(statusCode); doc.setStatusMessage(statusMessage); doc.setPath(path); - edao.createDocument(doc); + edao.createDocument(doc, pkg); docRef = new DocumentReference(doc.getId()); } catch (Exception ex) { throw new DataAccessException(ex.getMessage(), ex); @@ -187,14 +189,14 @@ Document loadDocument(DocumentReference documentReference, boolean forUpdate) th } } - void updateDocumentContent(DocumentReference docRef, Object doc, String type, Package pkg) + void updateDocumentContent(DocumentReference docRef, Object doc, Package pkg) throws DataAccessException { try { Document docvo = edao.getDocument(docRef.getDocumentId(), false); if (doc instanceof String) docvo.setContent((String)doc); else - docvo.setObject(doc, type); + docvo.setObject(doc); edao.updateDocumentContent(docvo.getId(), docvo.getContent(pkg)); } catch (SQLException ex) { throw new DataAccessException(ex.getMessage(), ex); @@ -226,7 +228,7 @@ private List convertParameters(Map eventParams, var.setStringValue(value); } else { - var.setData(createDocument(var.getType(), OwnerType.PROCESS_INSTANCE, procInstId, value)); + var.setData(createDocument(variable.getType(), OwnerType.PROCESS_INSTANCE, procInstId, value, getPackage(process))); } } else { @@ -246,8 +248,7 @@ private List convertParameters(Map eventParams, ProcessInstance createProcessInstance(Long processId, String ownerType, Long ownerId, String secondaryOwnerType, Long secondaryOwnerId, String masterRequestId, Map parameters, String label, String template) - throws ProcessException, DataAccessException - { + throws ProcessException, DataAccessException { ProcessInstance pi = null; try { Process process; @@ -358,7 +359,7 @@ void cancelEventWaitInstances(Long activityInstanceId) throws DataAccessExceptio } } - String getServiceProcessResponse(Long procInstId, String varName, Package pkg) throws DataAccessException { + Response getServiceProcessResponse(Long procInstId, String varName, Package pkg) throws DataAccessException { try { VariableInstance varInst; if (varName == null) { @@ -372,12 +373,16 @@ String getServiceProcessResponse(Long procInstId, String varName, Package pkg) t } if (varInst == null) return null; + Response response = new Response(); if (varInst.isDocument(pkg)) { - Document docvo = getDocument((DocumentReference)varInst.getData(pkg), false); - return docvo.getContent(pkg); + Document doc = getDocument((DocumentReference)varInst.getData(pkg), false); + response.setContent(doc.getContent(pkg)); + response.setObject(doc.getObject(varInst.getType(), pkg)); } else { - return varInst.getStringValue(pkg); + response.setContent(varInst.getStringValue(pkg)); + response.setObject(varInst.getData(pkg)); } + return response; } catch (SQLException ex) { throw new DataAccessException("Failed to get value for variable " + varName, ex); } @@ -1841,8 +1846,8 @@ public void notifyMonitors(ProcessInstance processInstance, InternalLogMessage l Object value = var.getData(pkg); if (value instanceof DocumentReference) { try { - Document docVO = getDocument((DocumentReference) value, false); - value = docVO == null ? null : docVO.getObject(var.getType(), pkg); + Document doc = getDocument((DocumentReference) value, false); + value = doc == null ? null : doc.getObject(var.getType(), pkg); } catch (DataAccessException ex) { logger.error(ex.getMessage(), ex); @@ -1868,13 +1873,13 @@ public void notifyMonitors(ProcessInstance processInstance, InternalLogMessage l for (String varName : updated.keySet()) { if (processInstance.getVariables() == null) processInstance.setVariables(new ArrayList<>()); - Variable varVO = process.getVariable(varName); - if (varVO == null || !varVO.isInput()) + Variable variable = process.getVariable(varName); + if (variable == null || !variable.isInput()) throw new ProcessException("Process '" + process.getQualifiedLabel() + "' has no such input variable defined: " + varName); if (processInstance.getVariable(varName) != null) throw new ProcessException("Process '" + process.getQualifiedLabel() + "' input variable already populated: " + varName); - if (runtimeContext.getPackage().getTranslator(varVO.getType()).isDocumentReferenceVariable()) { - DocumentReference docRef = createDocument(varVO.getType(), OwnerType.VARIABLE_INSTANCE, 0L, updated.get(varName)); + if (runtimeContext.getPackage().getTranslator(variable.getType()).isDocumentReferenceVariable()) { + DocumentReference docRef = createDocument(variable.getType(), OwnerType.VARIABLE_INSTANCE, 0L, updated.get(varName), getPackage(process)); VariableInstance varInst = createVariableInstance(processInstance, varName, docRef); updateDocumentInfo(docRef, process.getVariable(varInst.getName()).getType(), OwnerType.VARIABLE_INSTANCE, varInst.getId(), null, null); processInstance.getVariables().add(varInst); @@ -1902,7 +1907,7 @@ else if (logMessage == InternalLogMessage.PROCESS_COMPLETE) { } public DocumentReference createActivityExceptionDocument(ProcessInstance processInst, - ActivityInstance actInstVO, BaseActivity activityImpl, Throwable th) throws DataAccessException { + ActivityInstance activityInst, BaseActivity activityImpl, Throwable th) throws DataAccessException { ActivityException actEx; if (th instanceof ActivityException) { actEx = (ActivityException) th; @@ -1915,18 +1920,18 @@ public DocumentReference createActivityExceptionDocument(ProcessInstance process actEx.setStackTrace(th.getStackTrace()); } + Package pkg = getPackage(getMainProcessDefinition(processInst)); // populate activity context - if (actInstVO != null) { + if (activityInst != null) { Process process = getProcessDefinition(processInst); - Package pkg = getPackage(getMainProcessDefinition(processInst)); if (pkg != null) processInst.setPackageName(pkg.getName()); - Activity activity = process.getActivity(actInstVO.getActivityId()); + Activity activity = process.getActivity(activityInst.getActivityId()); ActivityImplementor activityImplementor = ImplementorCache.get(activity.getImplementor()); String category = activityImplementor == null ? GeneralActivity.class.getName() : activityImplementor.getCategory(); ActivityRuntimeContext runtimeContext = new ActivityRuntimeContext(null, pkg, process, processInst, - getDataAccess().getPerformanceLevel(), isInService(), activity, category, actInstVO, + getDataAccess().getPerformanceLevel(), isInService(), activity, category, activityInst, activityImpl instanceof SuspendableActivity); // TODO option to suppress variables if (activityImpl == null) { @@ -1944,18 +1949,18 @@ else if (processInst.getVariable(var.getName()) != null) { Document doc = getDocument((DocumentReference)value, false); value = doc == null ? null : doc.getObject(var.getType(), pkg); } - runtimeContext.getVariables().put(var.getName(), processInst.getVariable(var.getName()).getData(pkg)); + runtimeContext.getValues().put(var.getName(), processInst.getVariable(var.getName()).getData(pkg)); } } catch (ActivityException | DataAccessException ex) { - engineLogger.error(processInst.getProcessId(), processInst.getId(), actInstVO.getActivityId(), actInstVO.getId(), ex.getMessage(), ex); + engineLogger.error(processInst.getProcessId(), processInst.getId(), activityInst.getActivityId(), activityInst.getId(), ex.getMessage(), ex); } } actEx.setRuntimeContext(runtimeContext); } - return createDocument(Exception.class.getName(), OwnerType.ACTIVITY_INSTANCE, actInstVO.getId(), actEx); + return createDocument(Exception.class.getName(), OwnerType.ACTIVITY_INSTANCE, activityInst.getId(), actEx, pkg); } public DocumentReference createProcessExceptionDocument(ProcessInstance processInst, Throwable th) @@ -1971,39 +1976,36 @@ public DocumentReference createProcessExceptionDocument(ProcessInstance processI procEx = new ProcessException(th.toString(), th.getCause()); procEx.setStackTrace(th.getStackTrace()); } - Long procId = 0L; - if (processInst != null) { - procId = processInst.getId(); - Process process = getProcessDefinition(processInst); - Package pkg = getPackage(getMainProcessDefinition(processInst)); - if (pkg != null) - processInst.setPackageName(pkg.getName()); + Package pkg = getPackage(getMainProcessDefinition(processInst)); + Long procId = processInst.getId(); + Process process = getProcessDefinition(processInst); + if (pkg != null) + processInst.setPackageName(pkg.getName()); - ProcessRuntimeContext runtimeContext = new ProcessRuntimeContext(null, pkg, process, processInst, - getDataAccess().getPerformanceLevel(), isInService()); + ProcessRuntimeContext runtimeContext = new ProcessRuntimeContext(null, pkg, process, processInst, + getDataAccess().getPerformanceLevel(), isInService()); - try { - processInst.setVariables(getDataAccess().getProcessInstanceVariables(processInst.getId())); - } catch (SQLException ignored) {} - - for (VariableInstance var : processInst.getVariables()) { - Object value = var.getData(pkg); - if (value instanceof DocumentReference) { - try { - Document docVO = getDocument((DocumentReference) value, false); - value = docVO == null ? null : docVO.getObject(var.getType(), pkg); - } - catch (DataAccessException ex) { - engineLogger.error(processInst.getProcessId(), processInst.getId(), processInst.getMasterRequestId(), ex.getMessage(), ex); - } + try { + processInst.setVariables(getDataAccess().getProcessInstanceVariables(processInst.getId())); + } catch (SQLException ignored) {} + + for (VariableInstance var : processInst.getVariables()) { + Object value = var.getData(pkg); + if (value instanceof DocumentReference) { + try { + Document doc = getDocument((DocumentReference) value, false); + value = doc == null ? null : doc.getObject(var.getType(), pkg); + } + catch (DataAccessException ex) { + engineLogger.error(processInst.getProcessId(), processInst.getId(), processInst.getMasterRequestId(), ex.getMessage(), ex); } - runtimeContext.getVariables().put(var.getName(), value); } - - procEx.setRuntimeContext(runtimeContext); + runtimeContext.getValues().put(var.getName(), value); } - return createDocument(Exception.class.getName(), OwnerType.PROCESS_INSTANCE, procId, procEx); + procEx.setRuntimeContext(runtimeContext); + + return createDocument(Exception.class.getName(), OwnerType.PROCESS_INSTANCE, procId, procEx, pkg); } private Package getPackage(Process process) { diff --git a/mdw-services/src/com/centurylink/mdw/services/request/BaseHandler.java b/mdw-services/src/com/centurylink/mdw/services/request/BaseHandler.java index d1df40117a..d8acb29632 100644 --- a/mdw-services/src/com/centurylink/mdw/services/request/BaseHandler.java +++ b/mdw-services/src/com/centurylink/mdw/services/request/BaseHandler.java @@ -58,9 +58,9 @@ protected Long launchProcess(Long processId, Long requestId, String masterReques * @param masterRequestId Master request ID to be assigned to the process instance * @param inputValues input value bindings for the process instance to be created * @param headers request headers - * @return response message, which is obtained from the response variable + * @return response message, populated with content from the response variable */ - protected String invokeServiceProcess(Long processId, Long requestId, String masterRequestId, + protected Response invokeServiceProcess(Long processId, Long requestId, String masterRequestId, String masterRequest, Map inputValues, Map headers) throws ProcessException, DataAccessException { Map stringParams = translateInputValues(processId, inputValues); @@ -121,7 +121,7 @@ protected Map translateInputValues(Long processId, Map inputValues = getInputValues(request, message, headers); if (processType.equals(ProcessVisibilityConstant.SERVICE)) { - String responseContent = invokeServiceProcess(process.getId(), requestId, masterRequestId, + return invokeServiceProcess(process.getId(), requestId, masterRequestId, request.getContent(), inputValues, headers); - return new Response(responseContent); } else { launchProcess(process.getId(), requestId, masterRequestId, inputValues, headers); @@ -88,7 +87,7 @@ protected Map getInputValues(Request request, Object message, Map values = new HashMap<>(); String varType = requestVar.getType(); if (pkg.getTranslator(varType).isDocumentReferenceVariable()) { - Object document = pkg.getObjectValue(varType, request.getContent(), true); + Object document = pkg.getObjectValue(varType, request.getContent(), true, message.getClass().getName()); String path = headers.get(Listener.METAINFO_REQUEST_PATH); Long requestId = new Long(headers.get(Listener.METAINFO_DOCUMENT_ID)); Long docId = ServiceLocator.getEventServices().createDocument(varType, OwnerType.DOCUMENT, requestId, document, pkg, path); diff --git a/mdw-services/src/com/centurylink/mdw/services/rest/JsonRestService.java b/mdw-services/src/com/centurylink/mdw/services/rest/JsonRestService.java index c8121cca35..d2b136fc65 100644 --- a/mdw-services/src/com/centurylink/mdw/services/rest/JsonRestService.java +++ b/mdw-services/src/com/centurylink/mdw/services/rest/JsonRestService.java @@ -220,7 +220,7 @@ protected JSONObject invokeServiceProcess(String name, Object request, String re JSONObject responseJson; Map responseHeaders = new HashMap<>(); Object responseObject = ServiceLocator.getWorkflowServices().invokeServiceProcess(name, - request, requestId, parameters, headers, responseHeaders); + request, requestId, parameters, headers, responseHeaders).getObject(); if (responseObject instanceof JSONObject) responseJson = (JSONObject) responseObject; else if (responseObject instanceof Jsonable) diff --git a/mdw-services/src/com/centurylink/mdw/services/rest/JsonXmlRestService.java b/mdw-services/src/com/centurylink/mdw/services/rest/JsonXmlRestService.java index ed09eec04c..b5c3fc463b 100644 --- a/mdw-services/src/com/centurylink/mdw/services/rest/JsonXmlRestService.java +++ b/mdw-services/src/com/centurylink/mdw/services/rest/JsonXmlRestService.java @@ -58,7 +58,7 @@ public String getXml(XmlObject xml, Map metaInfo) throws Service Package pkg = getPkg(metaInfo); JSONObject jsonObj = null; if (xml != null) - jsonObj = ((Jsonable)getJaxbTranslator(pkg).realToObject(xml.xmlText())).getJson(); + jsonObj = ((Jsonable)getJaxbTranslator(pkg).toObject(xml.xmlText(), XmlObject.class.getName())).getJson(); return getJson(jsonObj, metaInfo); } diff --git a/mdw-services/src/com/centurylink/mdw/services/task/AutoFormTaskValuesProvider.java b/mdw-services/src/com/centurylink/mdw/services/task/AutoFormTaskValuesProvider.java index 68d6c7d726..71eca57e71 100644 --- a/mdw-services/src/com/centurylink/mdw/services/task/AutoFormTaskValuesProvider.java +++ b/mdw-services/src/com/centurylink/mdw/services/task/AutoFormTaskValuesProvider.java @@ -80,8 +80,8 @@ public void apply(TaskRuntimeContext runtimeContext, Map values) throw new ServiceException(400, "Variable not found: " + name); } else { - String type = var.getType(); - runtimeContext.getValues().put(name, runtimeContext.getPackage().getObjectValue(type, values.get(name), true)); + runtimeContext.getValues().put(name, + runtimeContext.getPackage().getObjectValue(var.getType(), values.get(name), true)); } } } diff --git a/mdw-services/src/com/centurylink/mdw/services/task/TaskWorkflowHelper.java b/mdw-services/src/com/centurylink/mdw/services/task/TaskWorkflowHelper.java index d9f7a74621..0cc8094683 100644 --- a/mdw-services/src/com/centurylink/mdw/services/task/TaskWorkflowHelper.java +++ b/mdw-services/src/com/centurylink/mdw/services/task/TaskWorkflowHelper.java @@ -570,7 +570,7 @@ else if (taskAction.equals(TaskAction.COMPLETE)) } jsonMsg.put(TaskAttributeConstant.TASK_ACTION, formAction); JSONObject jsonMeta = new JsonObject().put("META", jsonMsg); - Long docId = createDocument(JSONObject.class.getName(), jsonMeta); + Long docId = createDocument(jsonMeta, JSONObject.class.getName()); String av = PropertyManager.getProperty(PropertyNames.ACTIVITY_RESUME_DELAY); int delay = 2; if (av!=null) { @@ -605,7 +605,7 @@ private void resumeCustom(String action) throws ServiceException { param.setName("Action"); param.setStringValue(action); - Long docId = createDocument(XmlObject.class.getName(), actionRequestDoc); + Long docId = createDocument(actionRequestDoc, XmlObject.class.getName()); int delay = 2; String av = PropertyManager.getProperty(PropertyNames.ACTIVITY_RESUME_DELAY); if (av!=null) { @@ -631,7 +631,7 @@ private void notifyProcess(String eventName, Long eventInstId, eventManager.notifyProcess(eventName, eventInstId, message, delay); } - private Long createDocument(String type, Object value) throws DataAccessException, ServiceException { + private Long createDocument(Object value, String variableType) throws DataAccessException, ServiceException { if (!OwnerType.PROCESS_INSTANCE.equals(taskInstance.getOwnerType())) throw new DataAccessException("Invalid owner for creating task doc: " + taskInstance.getOwnerType() + " (" + taskInstance.getId() + ")"); @@ -640,7 +640,7 @@ private Long createDocument(String type, Object value) throws DataAccessExceptio ProcessInstance proc = workflowServices.getProcess(taskInstance.getOwnerId()); Package pkg = PackageCache.getPackage(proc.getPackageName()); EventServices eventMgr = ServiceLocator.getEventServices(); - return eventMgr.createDocument(type, OwnerType.TASK_INSTANCE, taskInstance.getTaskInstanceId(), value, pkg); + return eventMgr.createDocument(variableType, OwnerType.TASK_INSTANCE, taskInstance.getTaskInstanceId(), value, pkg); } public Long getActivityInstanceId(boolean sourceActInst) diff --git a/mdw-services/src/com/centurylink/mdw/services/test/TestCaseRun.java b/mdw-services/src/com/centurylink/mdw/services/test/TestCaseRun.java index 6429679f70..c954aed538 100644 --- a/mdw-services/src/com/centurylink/mdw/services/test/TestCaseRun.java +++ b/mdw-services/src/com/centurylink/mdw/services/test/TestCaseRun.java @@ -20,7 +20,6 @@ import com.centurylink.mdw.adapter.AdapterStubResponse; import com.centurylink.mdw.app.ApplicationContext; import com.centurylink.mdw.bpm.MDWStatusMessageDocument; -import com.centurylink.mdw.cache.asset.AssetCache; import com.centurylink.mdw.cache.asset.PackageCache; import com.centurylink.mdw.common.service.Query; import com.centurylink.mdw.common.service.ServiceException; @@ -29,6 +28,7 @@ import com.centurylink.mdw.constant.OwnerType; import com.centurylink.mdw.java.CompiledJavaCache; import com.centurylink.mdw.model.asset.Asset; +import com.centurylink.mdw.model.asset.AssetVersion; import com.centurylink.mdw.model.asset.AssetVersionSpec; import com.centurylink.mdw.model.listener.Listener; import com.centurylink.mdw.model.task.TaskInstance; @@ -421,7 +421,7 @@ protected String getStringValue(VariableInstance var, Package pkg) throws TestEx String val = var.getStringValue(pkg); if (var.isDocument(pkg)) { try { - val = workflowServices.getDocumentStringValue(new DocumentReference(val).getDocumentId()); + val = workflowServices.getDocumentStringValue(new DocumentReference(val).getDocumentId(), var.getType(), pkg); } catch (ServiceException ex) { throw new TestException(ex.getMessage(), ex); @@ -439,15 +439,15 @@ boolean verifyProcess(TestCaseProcess[] processes, Asset expectedResults) throws return false; try { - List processVos = new ArrayList<>(); + List processDefs = new ArrayList<>(); if (isVerbose()) log.println("loading runtime data for processes:"); for (TestCaseProcess process : processes) { if (isVerbose()) log.println(" - " + process.getLabel()); - processVos.add(process.getProcess()); + processDefs.add(process.getProcess()); } - processInstances = loadResults(processVos, expectedResults, processes[0]); + processInstances = loadResults(processDefs, expectedResults, processes[0]); if (processInstances.isEmpty()) throw new IllegalStateException("No process instances found for masterRequestId: " + masterRequestId); return verifyProcesses(expectedResults); @@ -532,11 +532,8 @@ Asset getAsset(String path) throws TestException { return getProcess(path); try { String assetPath = path.indexOf('/') > 0 ? path : getTestCase().getPackage() + '/' + path; - Asset asset = AssetCache.getAsset(assetPath); - if (asset != null) { - // don't require cache refresh to make changes - asset.load(); - } + Asset asset = new Asset(ApplicationContext.getAssetRoot(), new AssetVersion(assetPath, 0)); + asset.load(); return asset; } catch (IOException ex) { diff --git a/mdw-services/src/com/centurylink/mdw/services/workflow/WorkflowServicesImpl.java b/mdw-services/src/com/centurylink/mdw/services/workflow/WorkflowServicesImpl.java index e66e2e3234..3f2284539b 100644 --- a/mdw-services/src/com/centurylink/mdw/services/workflow/WorkflowServicesImpl.java +++ b/mdw-services/src/com/centurylink/mdw/services/workflow/WorkflowServicesImpl.java @@ -38,6 +38,7 @@ import com.centurylink.mdw.model.report.Hotspot; import com.centurylink.mdw.model.report.Insight; import com.centurylink.mdw.model.report.Timepoint; +import com.centurylink.mdw.model.request.Response; import com.centurylink.mdw.model.system.SysInfo; import com.centurylink.mdw.model.system.SysInfoCategory; import com.centurylink.mdw.model.task.TaskInstance; @@ -73,14 +74,12 @@ import com.centurylink.mdw.util.log.StandardLogger; import com.centurylink.mdw.util.timer.CodeTimer; import com.centurylink.mdw.variable.VariableTranslator; -import com.centurylink.mdw.xml.XmlBeanWrapper; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; import org.json.JSONException; import org.json.JSONObject; import org.yaml.snakeyaml.Yaml; -import javax.xml.bind.JAXBElement; import java.io.IOException; import java.sql.SQLException; import java.text.ParseException; @@ -437,7 +436,8 @@ public Value getProcessValue(Long instanceId, String name) throws ServiceExcepti // ensure consistent formatting for doc values String str = varInst.getStringValue(runtimeContext.getPackage()); if (varInst != null && str != null && str.startsWith("DOCUMENT:")) - stringVal = getDocumentStringValue(new DocumentReference(varInst.getStringValue(runtimeContext.getPackage())).getDocumentId()); + stringVal = getDocumentStringValue(new DocumentReference(varInst.getStringValue(runtimeContext.getPackage())).getDocumentId(), + var.getType(), runtimeContext.getPackage()); } else { stringVal = runtimeContext.getValueAsString(name); @@ -487,8 +487,8 @@ public ProcessRuntimeContext getContext(Long instanceId, Boolean embeddedVars) t Object value = var.getData(pkg); if (value instanceof DocumentReference) { try { - Document docVO = getWorkflowDataAccess().getDocument(((DocumentReference)value).getDocumentId()); - value = docVO == null ? null : docVO.getObject(var.getType(), pkg); + Document doc = getWorkflowDataAccess().getDocument(((DocumentReference)value).getDocumentId()); + value = doc == null ? null : doc.getObject(var.getType(), pkg); vars.put(var.getName(), value); } catch (TranslationException ex) { @@ -545,7 +545,8 @@ public ProcessList getProcesses(Query query) throws ServiceException { } public ProcessInstance getProcessForTrigger(Long triggerId) throws ServiceException { - String ownerContent = getDocumentStringValue(triggerId); + Document doc = getDocument(triggerId); + String ownerContent = getDocumentStringValue(triggerId, doc.getVariableType(), getPackage(doc)); try { JSONObject json = new JsonObject(ownerContent); if (!json.has("runtimeContext")) { @@ -849,12 +850,12 @@ public Long launchProcess(Process process, String masterRequestId, String ownerT } } - public Object invokeServiceProcess(String name, Object masterRequest, String masterRequestId, + public Response invokeServiceProcess(String name, Object masterRequest, String masterRequestId, Map parameters, Map headers) throws ServiceException { return invokeServiceProcess(name, masterRequest, masterRequestId, parameters, headers, null); } - public Object invokeServiceProcess(String processName, Object masterRequest, String masterRequestId, + public Response invokeServiceProcess(String processName, Object masterRequest, String masterRequestId, Map parameters, Map headers, Map responseHeaders) throws ServiceException { try { @@ -863,10 +864,14 @@ public Object invokeServiceProcess(String processName, Object masterRequest, Str Process process = ProcessCache.getProcess(processName); Package pkg = PackageCache.getPackage(process.getPackageName()); if (masterRequest != null) { - String docType = getDocType(masterRequest); + String varType = StringDocument.class.getName(); + if (masterRequest instanceof JSONObject) + varType = JSONObject.class.getName(); + else if (masterRequest instanceof Jsonable) + varType = Jsonable.class.getName(); EventServices eventMgr = ServiceLocator.getEventServices(); - docId = eventMgr.createDocument(docType, OwnerType.LISTENER_REQUEST, 0L, masterRequest, pkg); - request = pkg.getStringValue(docType, masterRequest, true); + docId = eventMgr.createDocument(varType, OwnerType.LISTENER_REQUEST, 0L, masterRequest, pkg); + request = pkg.getStringValue(varType, masterRequest, true); if (headers == null) headers = new HashMap<>(); headers.put(Listener.METAINFO_DOCUMENT_ID, docId.toString()); @@ -877,15 +882,8 @@ public Object invokeServiceProcess(String processName, Object masterRequest, Str String responseVarName = "response"; // currently not configurable ProcessEngineDriver engineDriver = new ProcessEngineDriver(); - String resp = engineDriver.invokeService(process.getId(), OwnerType.DOCUMENT, docId, masterRequestId, + Response response = engineDriver.invokeService(process.getId(), OwnerType.DOCUMENT, docId, masterRequestId, request, stringParams, responseVarName, headers); - Object response = resp; - if (resp != null) { - Variable var = process.getVariable(responseVarName); - if (var != null && var.isOutput() && !var.isString()) { - response = pkg.getObjectValue(var.getType(), resp, true); - } - } Variable responseHeadersVar = process.getVariable("responseHeaders"); if (responseHeaders != null && responseHeadersVar != null && responseHeadersVar.getType().equals( "java.util.Map")) { @@ -911,12 +909,12 @@ public Object invokeServiceProcess(String processName, Object masterRequest, Str } } - public String invokeServiceProcess(Process process, String masterRequestId, String ownerType, + public Response invokeServiceProcess(Process process, String masterRequestId, String ownerType, Long ownerId, Map params) throws ServiceException { return invokeServiceProcess(process, masterRequestId, ownerType, ownerId, params, null); } - public String invokeServiceProcess(Process process, String masterRequestId, String ownerType, + public Response invokeServiceProcess(Process process, String masterRequestId, String ownerType, Long ownerId, Map params, Map headers) throws ServiceException { try { ProcessEngineDriver driver = new ProcessEngineDriver(); @@ -935,8 +933,7 @@ public String invokeServiceProcess(Process process, String masterRequestId, Stri public Integer notify(String event, String message, int delay) throws ServiceException { try { EventServices eventManager = ServiceLocator.getEventServices(); - Long docId = eventManager.createDocument(StringDocument.class.getName(), OwnerType.INTERNAL_EVENT, 0L, - message, null); + Long docId = eventManager.createDocument(StringDocument.class.getName(), OwnerType.INTERNAL_EVENT, 0L, message, null); return eventManager.notifyProcess(event, docId, message, delay); } catch (Exception ex) { @@ -955,10 +952,15 @@ public Integer notify(Package runtimePackage, String eventName, Object eventMess Long docId = 0L; String message = null; if (eventMessage != null) { - String docType = getDocType(eventMessage); + String varType = StringDocument.class.getName(); + if (eventMessage instanceof JSONObject) + varType = JSONObject.class.getName(); + else if (eventMessage instanceof Jsonable) + varType = Jsonable.class.getName(); + EventServices eventMgr = ServiceLocator.getEventServices(); - docId = eventMgr.createDocument(docType, OwnerType.LISTENER_REQUEST, 0L, eventMessage, runtimePackage); - message = runtimePackage.getStringValue(docType, eventMessage, true); + docId = eventMgr.createDocument(varType, OwnerType.LISTENER_REQUEST, 0L, eventMessage, runtimePackage); + message = runtimePackage.getStringValue(StringDocument.class.getName(), eventMessage, true); } EventServices eventManager = ServiceLocator.getEventServices(); return eventManager.notifyProcess(eventName, docId, message, delay); @@ -1072,13 +1074,13 @@ public void setDocumentValue(ProcessRuntimeContext context, String varName, Obje * and these need to be updated to use this method. */ public void createDocument(ProcessRuntimeContext context, String varName, Object value) throws ServiceException { - String type = context.getProcess().getVariable(varName).getType(); + String varType = context.getProcess().getVariable(varName).getType(); EventServices eventMgr = ServiceLocator.getEventServices(); Long procInstId = context.getProcessInstance().isEmbedded() ? context.getProcessInstance().getOwnerId() : context.getProcessInstanceId(); try { - Long docId = eventMgr.createDocument(type, OwnerType.PROCESS_INSTANCE, procInstId, value, context.getPackage()); + Long docId = eventMgr.createDocument(varType, OwnerType.PROCESS_INSTANCE, procInstId, value, context.getPackage()); VariableInstance varInst = eventMgr.setVariableInstance(procInstId, varName, new DocumentReference(docId), context.getPackage()); - eventMgr.updateDocumentInfo(docId, type, OwnerType.VARIABLE_INSTANCE, varInst.getId()); + eventMgr.updateDocumentInfo(docId, varType, OwnerType.VARIABLE_INSTANCE, varInst.getId()); } catch (DataAccessException ex) { throw new ServiceException(ServiceException.INTERNAL_ERROR, "Error creating document for process: " + procInstId, ex); @@ -1160,7 +1162,7 @@ public void updateDocument(ProcessRuntimeContext context, String varName, Object throw new ServiceException(ServiceException.NOT_FOUND, varName + " not found for process: " + context.getProcessInstanceId()); try { - eventMgr.updateDocumentContent(varInst.getDocumentId(), value, varInst.getType(), context.getPackage()); + eventMgr.updateDocumentContent(varInst.getDocumentId(), value, context.getPackage()); } catch (DataAccessException ex) { throw new ServiceException(ServiceException.INTERNAL_ERROR, "Error updating document: " + @@ -1174,8 +1176,8 @@ private Map translateParameters(Process process, Map translateParameters(Process process, Map translateParameters(Process process, Map body = new ArrayList(); @@ -58,4 +47,15 @@ public Object realToObject(String str) throws TranslationException { } } + @SuppressWarnings("rawtypes") + public Document toDomDocument(Object obj) throws TranslationException { + return (Document)((CxfPayload)obj).getBody().get(0); + } + + @SuppressWarnings({"rawtypes","unchecked"}) + public Object fromDomNode(Node domNode) throws TranslationException { + List nodeList = new ArrayList(); + nodeList.add(domNode); + return new CxfPayload(null, nodeList); + } } diff --git a/mdw-workflow/assets/com/centurylink/mdw/camel/MdwProducer.java b/mdw-workflow/assets/com/centurylink/mdw/camel/MdwProducer.java index 3e715c84cd..0ac838c8ad 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/camel/MdwProducer.java +++ b/mdw-workflow/assets/com/centurylink/mdw/camel/MdwProducer.java @@ -215,7 +215,7 @@ protected DocumentReference storeDocument(String docType, Object document, Packa } protected Map getMetaInfo(Message request) { - Map metaInfo = new HashMap(); + Map metaInfo = new HashMap<>(); for (String key : request.getHeaders().keySet()) { metaInfo.put(key, request.getHeader(key, String.class)); } diff --git a/mdw-workflow/assets/com/centurylink/mdw/gson/.mdw/versions b/mdw-workflow/assets/com/centurylink/mdw/gson/.mdw/versions index c98078d339..e4a1d55821 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/gson/.mdw/versions +++ b/mdw-workflow/assets/com/centurylink/mdw/gson/.mdw/versions @@ -1,3 +1,3 @@ -GsonTranslator.java=1 +GsonTranslator.java=2 gson-2.8.6.jar=1 readme.md=1 diff --git a/mdw-workflow/assets/com/centurylink/mdw/gson/GsonTranslator.java b/mdw-workflow/assets/com/centurylink/mdw/gson/GsonTranslator.java index 445f48a486..ebea79fc22 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/gson/GsonTranslator.java +++ b/mdw-workflow/assets/com/centurylink/mdw/gson/GsonTranslator.java @@ -12,7 +12,8 @@ @Variable(type="com.google.gson.JsonElement") public class GsonTranslator extends DocumentReferenceTranslator implements JsonTranslator { - public Object realToObject(String str) throws TranslationException { + @Override + public Object toObject(String str, String type) throws TranslationException { try { JSONObject json = new JsonObject(str); return createJsonable(json); @@ -22,7 +23,8 @@ public Object realToObject(String str) throws TranslationException { } } - public String realToString(Object obj) throws TranslationException { + @Override + public String toString(Object obj, String variableType) throws TranslationException { Jsonable jsonable = (Jsonable) obj; JSONObject json = new JsonObject(); try { diff --git a/mdw-workflow/assets/com/centurylink/mdw/microservice/.mdw/versions b/mdw-workflow/assets/com/centurylink/mdw/microservice/.mdw/versions index b55e103a4b..75c1b3c901 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/microservice/.mdw/versions +++ b/mdw-workflow/assets/com/centurylink/mdw/microservice/.mdw/versions @@ -13,7 +13,7 @@ MicroserviceDsl.kt=2 MicroserviceInstance.java=3 MicroserviceList.java=2 MicroserviceRestAdapter.java=24 -MicroserviceStatusProcessMonitor.java=4 +MicroserviceStatusProcessMonitor.java=5 OrchestratorActivity.java=19 ResponseCollector.java=4 ServicePlanModel.kt=6 diff --git a/mdw-workflow/assets/com/centurylink/mdw/microservice/MicroserviceStatusProcessMonitor.java b/mdw-workflow/assets/com/centurylink/mdw/microservice/MicroserviceStatusProcessMonitor.java index ee963d91a7..e82d192c80 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/microservice/MicroserviceStatusProcessMonitor.java +++ b/mdw-workflow/assets/com/centurylink/mdw/microservice/MicroserviceStatusProcessMonitor.java @@ -56,12 +56,13 @@ public Map onFinish(ProcessRuntimeContext context) { tw = db.startTransaction(); VariableInstance varInst = context.getProcessInstance().getVariable(serviceSummaryVarName); if (varInst.getDocumentId() != null) { - Document docVo = db.getDocument(varInst.getDocumentId(), true); - if (docVo != null && docVo.getContent(null) != null) { - summary = (ServiceSummary)docVo.getObject(varInst.getType(), context.getPackage()); + Document doc = db.getDocument(varInst.getDocumentId(), true); + if (doc != null && doc.getContent(null) != null) { + summary = (ServiceSummary)doc.getObject(varInst.getType(), context.getPackage()); summary.getMicroservice(microserviceName, context.getProcessInstanceId()).setStatus(WorkStatus.STATUSNAME_COMPLETED); - docVo.setObject(summary, varInst.getType()); - db.updateDocumentContent(docVo.getId(), docVo.getContent(context.getPackage())); + doc.setObject(summary); + doc.setVariableType(varInst.getType()); + db.updateDocumentContent(doc.getId(), doc.getContent(context.getPackage())); context.logInfo("Updated status for microservice " + microserviceName); WorkflowServices wfs = ServiceLocator.getWorkflowServices(); wfs.notify("service-summary-update-" + context.getMasterRequestId(), null, 2); diff --git a/mdw-workflow/assets/com/centurylink/mdw/testing/.mdw/versions b/mdw-workflow/assets/com/centurylink/mdw/testing/.mdw/versions index 7aba67db73..f4ba9e3af8 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/testing/.mdw/versions +++ b/mdw-workflow/assets/com/centurylink/mdw/testing/.mdw/versions @@ -2,7 +2,7 @@ AdapterStubbingMonitor.java=2 AutomatedTests.java=24 RandomTests.java=7 StartupCleaner.java=1 -TestCaseActivityMonitor.java=12 +TestCaseActivityMonitor.java=13 function-test-results.xsl=2 load-test-results.xsl=1 readme.md=5 diff --git a/mdw-workflow/assets/com/centurylink/mdw/testing/TestCaseActivityMonitor.java b/mdw-workflow/assets/com/centurylink/mdw/testing/TestCaseActivityMonitor.java index 4a388765c7..6bf369261b 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/testing/TestCaseActivityMonitor.java +++ b/mdw-workflow/assets/com/centurylink/mdw/testing/TestCaseActivityMonitor.java @@ -75,7 +75,7 @@ public Map onFinish(ActivityRuntimeContext runtimeContext) { Map updates = null; Map variables = stubResponse.getVariables(); if (variables != null) { - updates = new HashMap(); + updates = new HashMap<>(); for (String name : variables.keySet()) { String strValue = variables.get(name); Process process = runtimeContext.getProcess(); diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/code/.mdw/versions b/mdw-workflow/assets/com/centurylink/mdw/tests/code/.mdw/versions index 73aa9129ec..1bf0cfde40 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/code/.mdw/versions +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/code/.mdw/versions @@ -34,13 +34,13 @@ KtProcessHandler.kt=1 MyTaskRefData.java=1 PauseActivity.proc=5 ReflectChildDocUpdate.proc=6 -RequestHandlers.proc=1 +RequestHandlers.proc=2 RequestHandlersJava.test=1 RequestHandlersJava.yaml=1 RequestHandlersKt.test=1 RequestHandlersKt.yaml=1 SimpleDynamicJava.proc=8 -SimpleDynamicJava.test=2 +SimpleDynamicJava.test=3 SimpleDynamicJava.yaml=2 WhichActivity.kt=1 acknowledge.xml=2 diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/code/RequestHandlers.proc b/mdw-workflow/assets/com/centurylink/mdw/tests/code/RequestHandlers.proc index 3de2184b57..ae7ce7c3d9 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/code/RequestHandlers.proc +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/code/RequestHandlers.proc @@ -20,10 +20,10 @@ activities: implementor: com.centurylink.mdw.workflow.activity.event.EventWaitActivity attributes: SLA_DISPLAY_UNITS: Hours - WAIT_EVENT_NAMES: '[["RequestHandlers-${masterRequestId}",""]]' - rcvdMsgDocVar: notifyMessage STATUS_AFTER_TIMEOUT: Cancelled + WAIT_EVENT_NAMES: '[["RequestHandlers-${masterRequestId}",""]]' WORK_DISPLAY_INFO: x=280,y=100,w=100,h=60 + rcvdMsgDocVar: notifyMessage transitions: - id: T2 to: A2 @@ -40,5 +40,5 @@ variables: attributes: ArrowStyle: ArrowEnd NodeStyle: BoxIcon - WORK_DISPLAY_INFO: x=38,y=35,w=162,h=26 PROCESS_VISIBILITY: PUBLIC + WORK_DISPLAY_INFO: x=38,y=35,w=162,h=26 diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/code/SimpleDynamicJava.test b/mdw-workflow/assets/com/centurylink/mdw/tests/code/SimpleDynamicJava.test index da2e1fae7a..6b34ea926e 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/code/SimpleDynamicJava.test +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/code/SimpleDynamicJava.test @@ -10,5 +10,5 @@ start process("SimpleDynamicJava") { variables = [ responsibleParty: "dxoakes", instructions: asset("escalate.xml").text ] } -sleep 60 +sleep 30 verify process("SimpleDynamicJava") diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/microservice/.mdw/versions b/mdw-workflow/assets/com/centurylink/mdw/tests/microservice/.mdw/versions index 752340e55f..9d54eaaec9 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/microservice/.mdw/versions +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/microservice/.mdw/versions @@ -4,7 +4,7 @@ GET_ServiceSummary.yaml=1 GroupRequestMapper.groovy=3 MicroserviceApi.test=2 MicroserviceApi.yaml=1 -MicroserviceOrchestration.proc=7 +MicroserviceOrchestration.proc=8 MicroserviceOrchestrator.test=3 MicroserviceOrchestrator.yaml=4 POST_User.yaml=2 diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/microservice/MicroserviceOrchestration.proc b/mdw-workflow/assets/com/centurylink/mdw/tests/microservice/MicroserviceOrchestration.proc index 153c6f82ce..f995a662ca 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/microservice/MicroserviceOrchestration.proc +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/microservice/MicroserviceOrchestration.proc @@ -174,7 +174,6 @@ attributes: ArrowStyle: ArrowEnd NodeStyle: BoxIcon PROCESS_VISIBILITY: SERVICE - PerformanceLevel: '0' WORK_DISPLAY_INFO: x=379,y=59,w=250,h=26 requestMethod: POST requestParameters: '[["User","Body","true","User with optional groups","com.centurylink.mdw.tests.microservice/User.java","[0.2,1)"]]' diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/services/.mdw/versions b/mdw-workflow/assets/com/centurylink/mdw/tests/services/.mdw/versions index 8b279b52e5..5ceda0d1fb 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/services/.mdw/versions +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/services/.mdw/versions @@ -27,7 +27,7 @@ GetEmployeeRequest.xml=1 GetEmployeeResponse.xml=2 GetEmployeeResponseSoap.xml=2 GetEmployeeSoap.xml=3 -HybridService.java=4 +HybridService.java=5 HybridServices.test=5 LdapAdapter.proc=1 LdapAdapter.test=1 @@ -90,7 +90,7 @@ SolutionService.test=4 SolutionValues.test=5 SwaggerValidator.proc=3 SwaggerValidator.test=2 -TestHandler.java=3 +TestHandler.java=5 UnparseableResponse.proc=1 UnparseableResponse.test=1 UnparseableResponse.yaml=1 diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/services/HybridService.java b/mdw-workflow/assets/com/centurylink/mdw/tests/services/HybridService.java index 3d4f250c58..4b5b1dcce3 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/services/HybridService.java +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/services/HybridService.java @@ -58,7 +58,7 @@ public String getXml(XmlObject xml, Map metaInfo) throws Service String response = super.getXml(xml, metaInfo); if (response != null) { try { - response = getJaxbTranslator(getPkg(metaInfo)).realToString(new Employee(new JSONObject(response))); + response = getJaxbTranslator(getPkg(metaInfo)).toString(new Employee(new JSONObject(response)), Employee.class.getName()); } catch (Exception e) { throw new ServiceException(e.getMessage()); diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/services/TestHandler.java b/mdw-workflow/assets/com/centurylink/mdw/tests/services/TestHandler.java index d9264f04a6..71601a3ca2 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/services/TestHandler.java +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/services/TestHandler.java @@ -16,11 +16,9 @@ import com.centurylink.mdw.model.request.Response; import com.centurylink.mdw.model.task.TaskInstance; import com.centurylink.mdw.model.task.UserTaskAction; -import com.centurylink.mdw.model.variable.DocumentReference; import com.centurylink.mdw.model.variable.Variable; import com.centurylink.mdw.model.variable.VariableInstance; import com.centurylink.mdw.model.workflow.ActivityInstance; -import com.centurylink.mdw.model.workflow.Package; import com.centurylink.mdw.model.workflow.Process; import com.centurylink.mdw.model.workflow.ProcessInstance; import com.centurylink.mdw.request.RequestHandler; @@ -137,17 +135,16 @@ private String handleProcessLaunch(ActionRequestDocument xmlbean, String message params.put(param.getName(), param.getStringValue()); } String processType = proc.getProcessType(); - String resp; if (processType.equals(ProcessVisibilityConstant.SERVICE)) { Map stringParams = translateInputValues(proc.getId(), params); ProcessEngineDriver engineDriver = new ProcessEngineDriver(); - resp = engineDriver.invokeService(proc.getId(), OwnerType.DOCUMENT, requestId, masterRequestId, + Response resp = engineDriver.invokeService(proc.getId(), OwnerType.DOCUMENT, requestId, masterRequestId, message, stringParams, null, performanceLevel, null, null, metaInfo); + return resp == null ? null : resp.getContent(); } else { launchProcess(proc.getId(), requestId, masterRequestId, params, null); - resp = createSuccessResponse(null); + return createSuccessResponse(null); } - return resp; } /** @@ -173,7 +170,7 @@ private String handleNotifyProcess(ActionRequestDocument xmlbean, String message EventServices eventMgr = ServiceLocator.getEventServices(); eventName = translatePlaceHolder(eventName, xmlbean, eventMgr); Long docid = eventMgr.createDocument(StringDocument.class.getName(), OwnerType.DOCUMENT, - new Long(metaInfo.get(Listener.METAINFO_DOCUMENT_ID)), msgContent, null); + new Long(metaInfo.get(Listener.METAINFO_DOCUMENT_ID)), msgContent, null, StringDocument.class.getName()); logger.debug("Regression tester notify process with event '" + eventName + "'"); super.notifyProcesses(eventName, docid, msgContent, 0); return createSuccessResponse(null); @@ -321,37 +318,6 @@ private String handleTaskAction(ActionRequestDocument xmlbean, String message, M EventServices eventManager = ServiceLocator.getEventServices(); Long procInstId = taskInst.getOwnerId(); ProcessInstance procInst = eventManager.getProcessInstance(procInstId); - Process procdef = ProcessCache.getProcess(procInst.getProcessId()); - if (procInst.isEmbedded()) { - procInstId = procInst.getOwnerId(); - } - for (Parameter param : params) { - String pname = param.getName(); - if (pname.startsWith("formdata.")) { - String varname = pname.substring(9); - VariableInstance var = eventManager.getVariableInstance(procInstId, varname); - Package pkg = PackageCache.getPackage(procdef.getPackageName()); - if (var == null) { - Variable vardef = procdef.getVariable(varname); - if (vardef == null) - throw new RequestHandlerException("The variable is not defined: " + varname); - if (pkg.getTranslator(vardef.getType()).isDocumentReferenceVariable()) { - Long docid = eventManager.createDocument(vardef.getType(), - OwnerType.PROCESS_INSTANCE, procInstId, param.getStringValue(), pkg); - eventManager.setVariableInstance(procInstId, varname, new DocumentReference(docid), pkg); - } else { - eventManager.setVariableInstance(procInstId, varname, param.getStringValue(), pkg); - } - } else { - if (var.isDocument(pkg)) { - DocumentReference docref = (DocumentReference)var.getData(pkg); - eventManager.updateDocumentContent(docref.getDocumentId(), param.getStringValue(), var.getType(), null); - } else { - eventManager.setVariableInstance(procInstId, varname, param.getStringValue(), pkg); - } - } - } - } } } ServiceLocator.getTaskServices().performAction(taskInstId, directAction, cuid, cuid, null, null, true); diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/.mdw/versions b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/.mdw/versions index de4718b4d5..2da195b302 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/.mdw/versions +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/.mdw/versions @@ -1,11 +1,16 @@ Gson.proc=1 -JavaObject.proc=1 -JavaObject.test=1 -JavaObjectHandler.test=1 +JavaObject.proc=2 +JavaObject.test=2 +JavaObject.yaml=1 +JavaObjectHandler.test=2 +JavaObjectHandler.yaml=1 JavaRequestHandler.java=1 -Jsonable.proc=3 -JsonableHandler.test=1 -JsonableInput.test=1 -JsonableRequest.test=1 +Jsonable.proc=4 +JsonableHandler.test=2 +JsonableHandler.yaml=1 +JsonableInput.test=2 +JsonableInput.yaml=1 +JsonableRequest.test=2 +JsonableRequest.yaml=1 JsonableRequestHandler.java=1 Mountain.java=3 diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObject.proc b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObject.proc index 4ed4def275..2ae647c1a7 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObject.proc +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObject.proc @@ -14,7 +14,7 @@ activities: name: Stop implementor: com.centurylink.mdw.workflow.activity.process.ProcessFinishActivity attributes: - WORK_DISPLAY_INFO: x=700,y=110,w=60,h=40 + WORK_DISPLAY_INFO: x=570,y=110,w=60,h=40 - id: A3 name: Populate implementor: com.centurylink.mdw.workflow.activity.java.DynamicJavaActivity @@ -47,25 +47,11 @@ activities: Output Documents: '["mountain","mountains"]' WORK_DISPLAY_INFO: x=190,y=100,w=100,h=60 transitions: - - id: T2 - to: A4 - event: FINISH - attributes: - TRANSITION_DISPLAY_INFO: type=Elbow,lx=320,ly=130,xs=294&346,ys=130&130 -- id: A4 - name: Wait - implementor: com.centurylink.mdw.workflow.activity.event.EventWaitActivity - attributes: - SLA_DISPLAY_UNITS: Hours - STATUS_AFTER_TIMEOUT: Cancelled - WAIT_EVENT_NAMES: '[["Wait-${masterRequestId}",""]]' - WORK_DISPLAY_INFO: x=350,y=100,w=100,h=60 - transitions: - - id: T3 + - id: T5 to: A5 event: FINISH attributes: - TRANSITION_DISPLAY_INFO: type=Elbow,lx=485,ly=130,xs=454&516,ys=130&130 + TRANSITION_DISPLAY_INFO: type=Elbow,lx=335,ly=130,xs=294&376,ys=130&130 - id: A5 name: Update implementor: com.centurylink.mdw.workflow.activity.script.ScriptExecutorActivity @@ -80,13 +66,13 @@ activities: input.elevation = input.elevation - 1 } SCRIPT: Groovy - WORK_DISPLAY_INFO: x=520,y=100,w=100,h=60 + WORK_DISPLAY_INFO: x=380,y=100,w=100,h=60 transitions: - id: T4 to: A2 event: FINISH attributes: - TRANSITION_DISPLAY_INFO: type=Elbow,lx=660,ly=130,xs=624&696,ys=130&130 + TRANSITION_DISPLAY_INFO: type=Elbow,lx=525,ly=130,xs=484&566,ys=130&130 variables: input: type: java.lang.Object diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObject.test b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObject.test index 739486c8a5..1d6bf3ccb2 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObject.test +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObject.test @@ -3,3 +3,6 @@ package com.centurylink.mdw.tests.variables start process("JavaObject.proc") { variables = [testCase: "Input Variable"] } + +wait process +verify process diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObject.yaml b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObject.yaml new file mode 100644 index 0000000000..a8915a96c0 --- /dev/null +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObject.yaml @@ -0,0 +1,24 @@ +process: # 10609 + name: JavaObject + instance: 1 + activity: # 1 "2020-06-04 17:03:35.013" + name: Start + status: Completed + activity: # 3 "2020-06-04 17:03:35.034" + name: Populate + status: Completed + activity: # 5 "2020-06-04 17:03:35.064" + name: Update + status: Completed + activity: # 2 "2020-06-04 17:03:35.096" + name: Stop + status: Completed + variable: # 12369 + name: mountain + value: Fuji, 12388 ft, Japan + variable: # 12370 + name: mountains + value: [Denali, 20310 ft, United States, K2, 28251 ft, Pakistan, Evans, 14271 ft, United States] + variable: # 12368 + name: testCase + value: Input Variable \ No newline at end of file diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObjectHandler.test b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObjectHandler.test index 2eef7fb7d6..d8105a568a 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObjectHandler.test +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObjectHandler.test @@ -15,4 +15,7 @@ def response = post http("api/REST/variablesTest/JavaObject") { } }""" } -assert response.code == 200 \ No newline at end of file +assert response.code == 200 + +wait process("JavaObject.proc") +verify process \ No newline at end of file diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObjectHandler.yaml b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObjectHandler.yaml new file mode 100644 index 0000000000..625e282dab --- /dev/null +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JavaObjectHandler.yaml @@ -0,0 +1,27 @@ +process: # 10611 + name: JavaObject + instance: 1 + activity: # 1 "2020-06-04 17:04:57.011" + name: Start + status: Completed + activity: # 3 "2020-06-04 17:04:57.023" + name: Populate + status: Completed + activity: # 5 "2020-06-04 17:04:57.043" + name: Update + status: Completed + activity: # 2 "2020-06-04 17:04:57.066" + name: Stop + status: Completed + variable: # 12374 + name: input + value: Everest, 29028 ft, Nepal + variable: # 12379 + name: mountain + value: Fuji, 12388 ft, Japan + variable: # 12380 + name: mountains + value: [Denali, 20310 ft, United States, K2, 28251 ft, Pakistan, Evans, 14271 ft, United States] + variable: # 12375 + name: testCase + value: Request Handler \ No newline at end of file diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/Jsonable.proc b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/Jsonable.proc index 3296d13080..7809a70a8f 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/Jsonable.proc +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/Jsonable.proc @@ -9,12 +9,12 @@ activities: to: A4 event: FINISH attributes: - TRANSITION_DISPLAY_INFO: type=Elbow,lx=160,ly=150,xs=134&186,ys=150&150 + TRANSITION_DISPLAY_INFO: type=Elbow,lx=175,ly=150,xs=134&216,ys=150&150 - id: A2 name: Stop implementor: com.centurylink.mdw.workflow.activity.process.ProcessFinishActivity attributes: - WORK_DISPLAY_INFO: x=790,y=130,w=60,h=40 + WORK_DISPLAY_INFO: x=670,y=130,w=60,h=40 - id: A4 name: Create/Update implementor: com.centurylink.mdw.workflow.activity.script.ScriptExecutorActivity @@ -35,27 +35,13 @@ activities: SCRIPT: Groovy - WORK_DISPLAY_INFO: x=190,y=110,w=120,h=80 + WORK_DISPLAY_INFO: x=220,y=110,w=120,h=80 transitions: - - id: T2 - to: A5 - event: FINISH - attributes: - TRANSITION_DISPLAY_INFO: type=Elbow,lx=350,ly=150,xs=314&386,ys=150&150 -- id: A5 - name: Wait Here - implementor: com.centurylink.mdw.workflow.activity.event.EventWaitActivity - attributes: - SLA_DISPLAY_UNITS: Hours - STATUS_AFTER_TIMEOUT: Cancelled - WAIT_EVENT_NAMES: '[["Wait-${masterRequestId}",""]]' - WORK_DISPLAY_INFO: x=390,y=110,w=120,h=80 - transitions: - - id: T3 + - id: T5 to: A6 event: FINISH attributes: - TRANSITION_DISPLAY_INFO: type=Elbow,lx=550,ly=150,xs=514&586,ys=150&150 + TRANSITION_DISPLAY_INFO: type=Elbow,lx=385,ly=150,xs=344&426,ys=150&150 - id: A6 name: Further Updates implementor: com.centurylink.mdw.workflow.activity.java.DynamicJavaActivity @@ -63,13 +49,13 @@ activities: ClassName: Jsonable_A6 Java: "package com.centurylink.mdw.tests.variables;\n\nimport com.centurylink.mdw.java.JavaExecutionException;\nimport com.centurylink.mdw.java.JavaExecutor;\n\nimport java.util.Map;\n\npublic class Jsonable_A6 implements JavaExecutor {\n\n public Object execute(Map variables) throws JavaExecutionException {\n Mountain request = (Mountain)variables.get(\"request\");\n if (request != null) {\n request.setElevation(request.getElevation() - 1);\n }\n Mountain input = (Mountain)variables.get(\"input\");\n if (input != null) {\n input.setElevation(input.getElevation() - 1);\n }\n Mountain local = (Mountain)variables.get(\"local\");\n if (local != null) {\n local.setElevation(local.getElevation() - 1);\n }\n \n return null;\n }\n}\n" Output Documents: '["input","local","request"]' - WORK_DISPLAY_INFO: x=590,y=110,w=120,h=80 + WORK_DISPLAY_INFO: x=430,y=110,w=120,h=80 transitions: - id: T4 to: A2 event: FINISH attributes: - TRANSITION_DISPLAY_INFO: type=Elbow,lx=750,ly=150,xs=714&786,ys=150&150 + TRANSITION_DISPLAY_INFO: type=Elbow,lx=610,ly=150,xs=554&666,ys=150&150 variables: input: type: com.centurylink.mdw.model.Jsonable @@ -80,6 +66,9 @@ variables: request: type: com.centurylink.mdw.model.Jsonable category: INPUT + requestHeaders: + type: java.util.Map + category: INPUT testCase: type: java.lang.String category: INPUT diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableHandler.test b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableHandler.test index e22115fe14..0a64d977c2 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableHandler.test +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableHandler.test @@ -15,3 +15,6 @@ def response = post http("api/REST/variablesTest/Jsonable") { }""" } assert response.code == 200 + +wait process("Jsonable.proc") +verify process diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableHandler.yaml b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableHandler.yaml new file mode 100644 index 0000000000..b3a6eefd6f --- /dev/null +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableHandler.yaml @@ -0,0 +1,57 @@ +process: # 10612 + name: Jsonable + instance: 1 + activity: # 1 "2020-06-04 17:04:59.009" + name: Start + status: Completed + activity: # 4 "2020-06-04 17:04:59.023" + name: Create/Update + status: Completed + activity: # 6 "2020-06-04 17:04:59.273" + name: Further Updates + status: Completed + activity: # 2 "2020-06-04 17:04:59.474" + name: Stop + status: Completed + variable: # 12383 + name: local + value: | + { + "country": "Japan", + "elevation": 12388, + "name": "Fuji" + } + variable: # 12376 + name: request + value: | + { + "country": "Tanzania", + "elevation": 19339, + "name": "Kilimanjaro" + } + variable: # 12378 + name: requestHeaders + value: | + { + "AuthenticatedUser": "mdwapp", + "Content-Type": "application/json", + "HttpMethod": "POST", + "Protocol": "REST", + "RemoteAddr": "${~.*}", + "RemoteHost": "${~.*}", + "RemotePort": "${~\\d*}", + "RequestPath": "variablesTest/Jsonable", + "RequestURL": "http://${~.*}/mdw/api/REST/variablesTest/Jsonable", + "ServiceClass": "com.centurylink.mdw.hub.servlet.RestServlet", + "accept": "${~.*}", + "connection": "keep-alive", + "content-length": "${~\\d*}", + "content-type": "application/json", + "document-id": "${~\\d*}", + "host": "${~.*}", + "mdw-request-id": "${masterRequestId}", + "user-agent": "${~.*}" + } + variable: # 12377 + name: testCase + value: Request Handler \ No newline at end of file diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableInput.test b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableInput.test index a65945bfa8..26f32acdce 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableInput.test +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableInput.test @@ -12,3 +12,6 @@ start process("Jsonable.proc") { testCase: 'Input Variable' ] } + +wait process +verify process diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableInput.yaml b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableInput.yaml new file mode 100644 index 0000000000..a6a7e1403c --- /dev/null +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableInput.yaml @@ -0,0 +1,34 @@ +process: # 10613 + name: Jsonable + instance: 1 + activity: # 1 "2020-06-04 17:05:00.507" + name: Start + status: Completed + activity: # 4 "2020-06-04 17:05:00.522" + name: Create/Update + status: Completed + activity: # 6 "2020-06-04 17:05:00.539" + name: Further Updates + status: Completed + activity: # 2 "2020-06-04 17:05:00.556" + name: Stop + status: Completed + variable: # 12381 + name: input + value: | + { + "country": "United States", + "elevation": 20308, + "name": "Denali" + } + variable: # 12386 + name: local + value: | + { + "country": "Japan", + "elevation": 12388, + "name": "Fuji" + } + variable: # 12382 + name: testCase + value: Input Variable \ No newline at end of file diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableRequest.test b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableRequest.test index 82b03a2e4e..6f4b8bb1a5 100644 --- a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableRequest.test +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableRequest.test @@ -1,9 +1,16 @@ package com.centurylink.mdw.tests.variables def response = post http("api/com/centurylink/mdw/tests/variables/Jsonable") { + headers = [ + "Content-Type": "application/json", + "mdw-request-id": masterRequestId + ] payload = '''{ "name": "Everest", "elevation": 29029, "country": "Nepal" }''' } + +wait process("Jsonable.proc") +verify process diff --git a/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableRequest.yaml b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableRequest.yaml new file mode 100644 index 0000000000..cc172cb58a --- /dev/null +++ b/mdw-workflow/assets/com/centurylink/mdw/tests/variables/JsonableRequest.yaml @@ -0,0 +1,57 @@ +process: # 10614 + name: Jsonable + instance: 1 + activity: # 1 "2020-06-04 17:05:03.010" + name: Start + status: Completed + activity: # 4 "2020-06-04 17:05:03.026" + name: Create/Update + status: Completed + activity: # 6 "2020-06-04 17:05:03.042" + name: Further Updates + status: Completed + activity: # 2 "2020-06-04 17:05:03.059" + name: Stop + status: Completed + variable: # 12387 + name: local + value: | + { + "country": "Japan", + "elevation": 12388, + "name": "Fuji" + } + variable: # 12384 + name: request + value: | + { + "country": "Nepal", + "elevation": 29027, + "name": "Everest" + } + variable: # 12385 + name: requestHeaders + value: | + { + "AuthenticatedUser": "mdwapp", + "Content-Type": "application/json", + "HttpMethod": "POST", + "Protocol": "REST", + "RemoteAddr": "${~.*}", + "RemoteHost": "${~.*}", + "RemotePort": "${~\\d*}", + "RequestPath": "com/centurylink/mdw/tests/variables/Jsonable", + "RequestURL": "http://${~.*}/mdw/api/com/centurylink/mdw/tests/variables/Jsonable", + "ServiceClass": "com.centurylink.mdw.hub.servlet.RestServlet", + "accept": "${~.*}", + "connection": "keep-alive", + "content-length": "${~\\d*}", + "content-type": "application/json", + "document-id": "${~\\d*}", + "host": "${~.*}", + "mdw-request-id": "${masterRequestId}", + "user-agent": "${~.*}" + } + variable: # 12388 + name: testCase + value: Process Request \ No newline at end of file diff --git a/mdw-workflow/src/com/centurylink/mdw/workflow/activity/event/EventWaitActivity.java b/mdw-workflow/src/com/centurylink/mdw/workflow/activity/event/EventWaitActivity.java index 0133fa3043..58a60ad2f3 100644 --- a/mdw-workflow/src/com/centurylink/mdw/workflow/activity/event/EventWaitActivity.java +++ b/mdw-workflow/src/com/centurylink/mdw/workflow/activity/event/EventWaitActivity.java @@ -176,12 +176,12 @@ protected void processMessage(String message) { try { String rcvdMsgDocVar = getAttributeValueSmart(RECEIVED_MESSAGE_DOC_VAR); if (rcvdMsgDocVar != null && !rcvdMsgDocVar.isEmpty()) { - Process processVO = getProcessDefinition(); - Variable variableVO = processVO.getVariable(rcvdMsgDocVar); - if (variableVO == null) - throw new ActivityException("Received Message Variable '" + rcvdMsgDocVar + "' is not defined or is not Document Type for process " + processVO.getQualifiedLabel()); + Process process = getProcessDefinition(); + Variable variable = process.getVariable(rcvdMsgDocVar); + if (variable == null) + throw new ActivityException("Received Message Variable '" + rcvdMsgDocVar + "' is not defined or is not Document Type for process " + process.getQualifiedLabel()); if (message != null) { - this.setParameterValueAsDocument(rcvdMsgDocVar, variableVO.getType(), message); + setParameterValueAsDocument(rcvdMsgDocVar, variable.getType(), message); } } } diff --git a/mdw-workflow/src/com/centurylink/mdw/workflow/activity/process/InvokeHeterogeneousProcessActivity.java b/mdw-workflow/src/com/centurylink/mdw/workflow/activity/process/InvokeHeterogeneousProcessActivity.java index 6cb073608e..a6d973c063 100644 --- a/mdw-workflow/src/com/centurylink/mdw/workflow/activity/process/InvokeHeterogeneousProcessActivity.java +++ b/mdw-workflow/src/com/centurylink/mdw/workflow/activity/process/InvokeHeterogeneousProcessActivity.java @@ -113,7 +113,7 @@ protected ProcessExecutionPlanDocument getProcessExecutionPlan() } } - private void updateExecutionPlan(ProcessExecutionPlanDocument process_plan) + private void updateExecutionPlan(ProcessExecutionPlanDocument exePlan) throws ActivityException { String plan_varname = getAttributeValue(EXECUTION_PLAN_VARIABLE); DocumentReference docref = (DocumentReference)getParameterValue(plan_varname); @@ -121,11 +121,11 @@ private void updateExecutionPlan(ProcessExecutionPlanDocument process_plan) String str; if (Yaml.class.getName().equals(varType)) { // TODO better way that supports other types like JSONObject and Jsonable DocumentReferenceTranslator translator = (DocumentReferenceTranslator)getPackage().getTranslator(varType); - Object obj = ((XmlDocumentTranslator)translator).fromDomNode(process_plan.getDomNode()); - str = translator.realToString(obj); + Object obj = ((XmlDocumentTranslator)translator).fromDomNode(exePlan.getDomNode()); + str = translator.toString(obj, varType); } else { - str = process_plan.xmlText(); + str = exePlan.xmlText(); } super.updateDocumentContent(docref, str, getParameterType(plan_varname)); } @@ -436,10 +436,9 @@ else if (value.startsWith("DOCUMENT:")) { if (outputVariableUpdated.get(varname)) throw new ActivityException("Output Document variable value already returned by another sub process"); else - outputVariableUpdated.put(varname, Boolean.valueOf(true)); + outputVariableUpdated.put(varname, Boolean.TRUE); } - DocumentReference docref = super.createDocument(var.getType(), - value, OwnerType.PROCESS_INSTANCE, this.getProcessInstanceId()); + DocumentReference docref = createDocument(var.getType(), value, OwnerType.PROCESS_INSTANCE, this.getProcessInstanceId()); value0 = new DocumentReference(docref.getDocumentId()); // check map for variable, not allowed multiple children to update same docs diff --git a/mdw-workflow/src/com/centurylink/mdw/workflow/activity/process/InvokeProcessActivityBase.java b/mdw-workflow/src/com/centurylink/mdw/workflow/activity/process/InvokeProcessActivityBase.java index 3ec6f71e67..b2d8083e6d 100644 --- a/mdw-workflow/src/com/centurylink/mdw/workflow/activity/process/InvokeProcessActivityBase.java +++ b/mdw-workflow/src/com/centurylink/mdw/workflow/activity/process/InvokeProcessActivityBase.java @@ -128,11 +128,12 @@ public final boolean resume(InternalEvent msg) Integer status = lockActivityInstance(); if (msg.isProcess()) { boolean done = resumeOnProcessFinish(msg, status); - if (done) onFinish(); + if (done) + onFinish(); return done; } else { - String messageString = this.getMessageFromEventMessage(msg); - this.setReturnCode(msg.getCompletionCode()); + String messageString = this.getMessageFromEventMessage(msg); + setReturnCode(msg.getCompletionCode()); processOtherMessage(messageString); handleEventCompletionCode(); return true; diff --git a/mdw-workflow/src/com/centurylink/mdw/workflow/activity/process/InvokeSubProcessActivity.java b/mdw-workflow/src/com/centurylink/mdw/workflow/activity/process/InvokeSubProcessActivity.java index ad6e3d36f4..44e603f49a 100644 --- a/mdw-workflow/src/com/centurylink/mdw/workflow/activity/process/InvokeSubProcessActivity.java +++ b/mdw-workflow/src/com/centurylink/mdw/workflow/activity/process/InvokeSubProcessActivity.java @@ -256,7 +256,7 @@ else if (varvalue.startsWith("DOCUMENT:")) { value = getPackage().getObjectValue(var.getType(), varvalue); } else { - DocumentReference docref = super.createDocument(var.getType(), + DocumentReference docref = createDocument(var.getType(), varvalue, OwnerType.PROCESS_INSTANCE, this.getProcessInstanceId()); value = new DocumentReference(docref.getDocumentId()); } diff --git a/mdw-workflow/src/com/centurylink/mdw/workflow/activity/task/AutoFormManualTaskActivity.java b/mdw-workflow/src/com/centurylink/mdw/workflow/activity/task/AutoFormManualTaskActivity.java index 0585d56fb6..244d1c872e 100644 --- a/mdw-workflow/src/com/centurylink/mdw/workflow/activity/task/AutoFormManualTaskActivity.java +++ b/mdw-workflow/src/com/centurylink/mdw/workflow/activity/task/AutoFormManualTaskActivity.java @@ -95,20 +95,14 @@ protected String getWaitEvent() throws ActivityException { } protected boolean messageIsTaskAction(String messageString) throws ActivityException { - if (messageString.startsWith("{")) { - JSONObject jsonobj; - try { - jsonobj = new JsonObject(messageString); - JSONObject meta = jsonobj.has("META")?jsonobj.getJSONObject("META"):null; - if (meta==null || !meta.has(TaskAttributeConstant.TASK_ACTION)) return false; - String action = meta.getString(TaskAttributeConstant.TASK_ACTION); - return action!=null && action.startsWith("@"); - } catch (JSONException e) { - throw new ActivityException(0, "Failed to parse JSON message", e); - } - } else { - int k = messageString.indexOf("FORMDATA"); - return k>0 && k<8; + try { + JSONObject jsonobj = new JsonObject(messageString); + JSONObject meta = jsonobj.has("META")?jsonobj.getJSONObject("META"):null; + if (meta==null || !meta.has(TaskAttributeConstant.TASK_ACTION)) return false; + String action = meta.getString(TaskAttributeConstant.TASK_ACTION); + return action!=null && action.startsWith("@"); + } catch (JSONException e) { + throw new ActivityException("Failed to parse JSON message", e); } } @@ -161,11 +155,7 @@ protected void processTaskAction(String messageString) throws ActivityException * The method updates all variables specified as non-readonly * * @param datadoc - * @return completion code; when it returns null, the completion - * code is taken from the completionCode parameter of - * the message with key FormDataDocument.ATTR_ACTION - * @throws ActivityException - * @throws JSONException + * @return completion code */ protected String extractFormData(JSONObject datadoc) throws ActivityException, JSONException { diff --git a/mdw-workflow/src/com/centurylink/mdw/workflow/activity/transform/TransformActivity.java b/mdw-workflow/src/com/centurylink/mdw/workflow/activity/transform/TransformActivity.java index f3c461ee64..4d152bbcc6 100644 --- a/mdw-workflow/src/com/centurylink/mdw/workflow/activity/transform/TransformActivity.java +++ b/mdw-workflow/src/com/centurylink/mdw/workflow/activity/transform/TransformActivity.java @@ -149,7 +149,7 @@ private void executeXSLT() throws ActivityException { VariableTranslator inTranslator = getPackage().getTranslator(inputVarType); if (inTranslator instanceof DocumentReferenceTranslator) { DocumentReferenceTranslator docRefTranslator = (DocumentReferenceTranslator) inTranslator; - String input = docRefTranslator.realToString(getVariableValue(inputVarName)); + String input = docRefTranslator.toString(getValue(inputVarName), inputVarType); output = transform(input, transform); } else { @@ -164,7 +164,7 @@ private void executeXSLT() throws ActivityException { throw new ActivityException("Output document is not writable: " + outputVarName); if (outTranslator instanceof DocumentReferenceTranslator) { DocumentReferenceTranslator docRefTranslator = (DocumentReferenceTranslator) outTranslator; - Object doc = docRefTranslator.realToObject(output); + Object doc = docRefTranslator.toObject(output, outputVarType); setVariableValue(outputVarName, outputVarType, doc); } else { @@ -186,11 +186,11 @@ private Object getGPathParamValue(String varName, String varType) throws Activit value = builder; } else { - value = new XmlParser().parseText(docRefTranslator.realToString(value)); + value = new XmlParser().parseText(docRefTranslator.toString(value, varType)); } } else { - value = new XmlSlurper().parseText(docRefTranslator.realToString(value)); + value = new XmlSlurper().parseText(docRefTranslator.toString(value, varType)); } } catch (Exception ex) { @@ -209,7 +209,7 @@ private void setGPathParamValue(String varName, String varType, Object value) th try { if (value instanceof Node) new XmlNodePrinter(new PrintWriter(outputDocumentWriter)).print((Node)value); - Object doc = docRefTranslator.realToObject(outputDocumentWriter.toString()); + Object doc = docRefTranslator.toObject(outputDocumentWriter.toString(), varType); super.setVariableValue(varName, varType, doc); } catch (Exception ex) { diff --git a/mdw-workflow/src/com/centurylink/mdw/workflow/adapter/ObjectAdapterActivity.java b/mdw-workflow/src/com/centurylink/mdw/workflow/adapter/ObjectAdapterActivity.java index cab39c0e89..46ed91c140 100644 --- a/mdw-workflow/src/com/centurylink/mdw/workflow/adapter/ObjectAdapterActivity.java +++ b/mdw-workflow/src/com/centurylink/mdw/workflow/adapter/ObjectAdapterActivity.java @@ -309,14 +309,14 @@ protected Long logRequest(String message) { protected Long logResponse(Response response) { try { - DocumentReference docref = createDocument(String.class.getName(), response.getContent(), + DocumentReference docRef = createDocument(String.class.getName(), response.getContent(), OwnerType.ADAPTER_RESPONSE, getActivityInstanceId(), response.getStatusCode(), response.getStatusMessage(), response.getPath()); Long elapsedTime = getEngine().getRequestCompletionTime(OwnerType.ADAPTER, getActivityInstanceId()); if (elapsedTime != null) getEngine().setElapsedTime(OwnerType.ADAPTER, getActivityInstanceId(), elapsedTime); - return docref.getDocumentId(); + return docRef.getDocumentId(); } catch (Exception ex) { logger.error(ex.getMessage(), ex); return null; diff --git a/mdw-workflow/src/com/centurylink/mdw/workflow/adapter/TextAdapterActivity.java b/mdw-workflow/src/com/centurylink/mdw/workflow/adapter/TextAdapterActivity.java index a0d486f072..ce0047c97c 100644 --- a/mdw-workflow/src/com/centurylink/mdw/workflow/adapter/TextAdapterActivity.java +++ b/mdw-workflow/src/com/centurylink/mdw/workflow/adapter/TextAdapterActivity.java @@ -135,7 +135,7 @@ protected String getRequestData() throws ActivityException { else if (translator instanceof JsonableTranslator) return ((JsonableTranslator)translator).toJson(request).toString(2); else if (translator instanceof DocumentReferenceTranslator) - return ((DocumentReferenceTranslator)translator).realToString(request); + return ((DocumentReferenceTranslator)translator).toString(request, varInst.getType()); else return translator.toString(request); }