From cfecf98cb6900c766fdd41b924cda0f419594216 Mon Sep 17 00:00:00 2001 From: Avishka-Shamendra Date: Mon, 20 Nov 2023 15:58:52 +0530 Subject: [PATCH] Remove workflow config enabled flag and refactor --- .../impl/config/APIMConfigServiceImpl.java | 5 +- .../apimgt/impl/dto/WorkflowConfigDTO.java | 19 +---- ...ctStateChangeApprovalWorkflowExecutor.java | 36 ++++---- ...PIStateChangeApprovalWorkflowExecutor.java | 35 ++++---- .../workflow/TenantWorkflowConfigHolder.java | 83 +++++++++---------- .../tenant/tenant-config-schema.json | 13 +-- .../config/APIMConfigServiceImplTestCase.java | 6 +- .../TenantWorkflowConfigHolderTest.java | 62 ++++---------- .../impl/workflow/WorkflowTestUtils.java | 4 +- .../src/test/resources/tenant-conf.json | 10 +-- 10 files changed, 105 insertions(+), 168 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/config/APIMConfigServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/config/APIMConfigServiceImpl.java index 0d0412548f1d..a8e408335325 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/config/APIMConfigServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/config/APIMConfigServiceImpl.java @@ -292,15 +292,12 @@ private WorkflowConfigDTO getWorkFlowConfigDTO(JsonObject workflowConfig) { for (Map.Entry entry : configEntries) { String workflowName = entry.getKey(); JsonObject workflowConfigEntry = (JsonObject) entry.getValue(); - - boolean isEnabled = workflowConfigEntry.get(WorkflowConstants.WF_TENANT_CONF_ENABLED) != null - && workflowConfigEntry.get(WorkflowConstants.WF_TENANT_CONF_ENABLED).getAsBoolean(); String className = workflowConfigEntry.get(WorkflowConstants.WF_TENANT_CONF_CLASS) != null ? workflowConfigEntry.get(WorkflowConstants.WF_TENANT_CONF_CLASS).getAsString() : ""; JsonObject properties = workflowConfigEntry.get(WorkflowConstants.WF_TENANT_CONF_PROPERTIES) != null ? workflowConfigEntry.get(WorkflowConstants.WF_TENANT_CONF_PROPERTIES).getAsJsonObject() : null; - config.addWorkflowConfig(workflowName, isEnabled, className, properties); + config.addWorkflowConfig(workflowName, className, properties); } } return config; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/WorkflowConfigDTO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/WorkflowConfigDTO.java index f22bbd6937e2..4a02d878a966 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/WorkflowConfigDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dto/WorkflowConfigDTO.java @@ -38,12 +38,11 @@ public WorkflowConfigDTO() { * Method adds each WorkflowConfig to the workflowConfigMap * * @param workflowName type of workflow - * @param enabled whether the approval/custom workflow is enabled * @param className executor class name (org.wso2.......ExampleWorkflowExecutor) * @param properties the class specific properties */ - public void addWorkflowConfig(String workflowName, boolean enabled, String className, JsonObject properties) { - WorkflowConfig workflowConfig = new WorkflowConfig(enabled, className, properties); + public void addWorkflowConfig(String workflowName, String className, JsonObject properties) { + WorkflowConfig workflowConfig = new WorkflowConfig(className, properties); workflowConfigMap.put(workflowName, workflowConfig); } @@ -56,27 +55,15 @@ public Map getWorkflowConfigMap() { * Represents configuration of each workflow type */ public static class WorkflowConfig { - private boolean enabled; private String className; private JsonObject properties; - private WorkflowConfig(boolean enabled, String className, JsonObject properties) { + private WorkflowConfig(String className, JsonObject properties) { - this.enabled = enabled; this.className = className; this.properties = properties; } - public boolean isEnabled() { - - return enabled; - } - - public void setEnabled(boolean enabled) { - - this.enabled = enabled; - } - public String getClassName() { return className; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/workflow/APIProductStateChangeApprovalWorkflowExecutor.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/workflow/APIProductStateChangeApprovalWorkflowExecutor.java index ace99eec256d..d68e0afd25fa 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/workflow/APIProductStateChangeApprovalWorkflowExecutor.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/workflow/APIProductStateChangeApprovalWorkflowExecutor.java @@ -36,6 +36,7 @@ public class APIProductStateChangeApprovalWorkflowExecutor extends WorkflowExecu private static final Log log = LogFactory.getLog(APIProductStateChangeApprovalWorkflowExecutor.class); private String stateList; + private static String DEFAULT_STATE_LIST = "Created:Publish,Published:Block"; //default value public String getStateList() { @@ -70,27 +71,24 @@ public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowExceptio if (log.isDebugEnabled()) { log.debug("Executing API Product State change Workflow."); } - if (stateList != null) { - Map> stateActionMap = getSelectedStatesToApprove(stateList); - APIStateWorkflowDTO apiStateWorkFlowDTO = (APIStateWorkflowDTO) workflowDTO; - - if (stateActionMap.containsKey(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()) && - stateActionMap.get(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()) - .contains(apiStateWorkFlowDTO.getApiLCAction())) { - setWorkflowParameters(apiStateWorkFlowDTO); - super.execute(workflowDTO); - } else { - // For any other states, act as simple workflow executor. - workflowDTO.setStatus(WorkflowStatus.APPROVED); - // calling super.complete() instead of complete() to act as the simple workflow executor - super.complete(workflowDTO); - } + if (stateList == null) { + stateList = DEFAULT_STATE_LIST; + } + Map> stateActionMap = getSelectedStatesToApprove(stateList); + APIStateWorkflowDTO apiStateWorkFlowDTO = (APIStateWorkflowDTO) workflowDTO; + + if (stateActionMap.containsKey(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()) && + stateActionMap.get(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()) + .contains(apiStateWorkFlowDTO.getApiLCAction())) { + setWorkflowParameters(apiStateWorkFlowDTO); + super.execute(workflowDTO); } else { - String msg = - "State change list is not provided. Please check \"StateList\" property in the workflow configuration."; - log.error(msg); - throw new WorkflowException(msg); + // For any other states, act as simple workflow executor. + workflowDTO.setStatus(WorkflowStatus.APPROVED); + // calling super.complete() instead of complete() to act as the simple workflow executor + super.complete(workflowDTO); } + return new GeneralWorkflowResponse(); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/workflow/APIStateChangeApprovalWorkflowExecutor.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/workflow/APIStateChangeApprovalWorkflowExecutor.java index 43c00c73db63..066efb5b47ea 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/workflow/APIStateChangeApprovalWorkflowExecutor.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/workflow/APIStateChangeApprovalWorkflowExecutor.java @@ -38,6 +38,7 @@ public class APIStateChangeApprovalWorkflowExecutor extends WorkflowExecutor { private static final Log log = LogFactory.getLog(APIStateChangeWSWorkflowExecutor.class); private String stateList; + private static String DEFAULT_STATE_LIST = "Created:Publish,Published:Block"; //default value public String getStateList() { return stateList; @@ -68,26 +69,24 @@ public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowExceptio if (log.isDebugEnabled()) { log.debug("Executing API State change Workflow."); } - if (stateList != null) { - Map> stateActionMap = getSelectedStatesToApprove(stateList); - APIStateWorkflowDTO apiStateWorkFlowDTO = (APIStateWorkflowDTO) workflowDTO; - - if (stateActionMap.containsKey(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()) - && stateActionMap.get(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()) - .contains(apiStateWorkFlowDTO.getApiLCAction())) { - setWorkflowParameters(apiStateWorkFlowDTO); - super.execute(workflowDTO); - } else { - // For any other states, act as simple workflow executor. - workflowDTO.setStatus(WorkflowStatus.APPROVED); - // calling super.complete() instead of complete() to act as the simpleworkflow executor - super.complete(workflowDTO); - } + if (stateList == null) { + stateList = DEFAULT_STATE_LIST; + } + Map> stateActionMap = getSelectedStatesToApprove(stateList); + APIStateWorkflowDTO apiStateWorkFlowDTO = (APIStateWorkflowDTO) workflowDTO; + + if (stateActionMap.containsKey(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()) + && stateActionMap.get(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()) + .contains(apiStateWorkFlowDTO.getApiLCAction())) { + setWorkflowParameters(apiStateWorkFlowDTO); + super.execute(workflowDTO); } else { - String msg = "State change list is not provided. Please check \"StateList\" property in the workflow configuration."; - log.error(msg); - throw new WorkflowException(msg); + // For any other states, act as simple workflow executor. + workflowDTO.setStatus(WorkflowStatus.APPROVED); + // calling super.complete() instead of complete() to act as the simpleworkflow executor + super.complete(workflowDTO); } + return new GeneralWorkflowResponse(); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/workflow/TenantWorkflowConfigHolder.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/workflow/TenantWorkflowConfigHolder.java index d409a34d978e..136deb17d920 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/workflow/TenantWorkflowConfigHolder.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/workflow/TenantWorkflowConfigHolder.java @@ -74,38 +74,38 @@ public void load() throws WorkflowException { if (configObject instanceof WorkflowConfigDTO) { WorkflowConfigDTO workflowConfigDTO = (WorkflowConfigDTO) configObject; - WorkflowConfigDTO.WorkflowConfig workflowElem; + WorkflowConfigDTO.WorkflowConfig workflowConfig; String executorClassName; Class clazz; WorkflowExecutor workFlowExecutor; // Application Creation - workflowElem = workflowConfigDTO. + workflowConfig = workflowConfigDTO. getWorkflowConfigMap().get(WorkflowConstants.APPLICATION_CREATION); - executorClassName = getWorkflowExecutorClassName(workflowElem, + executorClassName = getWorkflowExecutorClassName(workflowConfig, WorkflowConstants.WorkflowClasses.APPLICATION_CREATION_SIMPLE_FLOW_CLASS, WorkflowConstants.WorkflowClasses.APPLICATION_CREATION_APPROVAL_FLOW_CLASS); try { clazz = TenantWorkflowConfigHolder.class.getClassLoader().loadClass(executorClassName); workFlowExecutor = (WorkflowExecutor) clazz.newInstance(); - loadProperties(workflowElem, workFlowExecutor); + loadProperties(workflowConfig, workFlowExecutor); } catch (ClassNotFoundException e1) { workFlowExecutor = new ApplicationCreationSimpleWorkflowExecutor(); } workflowExecutorMap.put(WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION, workFlowExecutor); // Production Application Registration - workflowElem = workflowConfigDTO. + workflowConfig = workflowConfigDTO. getWorkflowConfigMap().get(WorkflowConstants.PRODUCTION_APPLICATION_REGISTRATION); - executorClassName = getWorkflowExecutorClassName(workflowElem, + executorClassName = getWorkflowExecutorClassName(workflowConfig, WorkflowConstants.WorkflowClasses.APPLICATION_REGISTRATION_SIMPLE_FLOW_CLASS, WorkflowConstants.WorkflowClasses.APPLICATION_REGISTRATION_APPROVAL_FLOW_CLASS); try { clazz = TenantWorkflowConfigHolder.class.getClassLoader().loadClass(executorClassName); workFlowExecutor = (WorkflowExecutor) clazz.newInstance(); - loadProperties(workflowElem, workFlowExecutor); + loadProperties(workflowConfig, workFlowExecutor); } catch (ClassNotFoundException e1) { workFlowExecutor = new ApplicationRegistrationSimpleWorkflowExecutor(); } @@ -113,16 +113,16 @@ public void load() throws WorkflowException { WorkflowConstants.WF_TYPE_AM_APPLICATION_REGISTRATION_PRODUCTION, workFlowExecutor); // Sandbox Application Registration - workflowElem = workflowConfigDTO. + workflowConfig = workflowConfigDTO. getWorkflowConfigMap().get(WorkflowConstants.SANDBOX_APPLICATION_REGISTRATION); - executorClassName = getWorkflowExecutorClassName(workflowElem, + executorClassName = getWorkflowExecutorClassName(workflowConfig, WorkflowConstants.WorkflowClasses.APPLICATION_REGISTRATION_SIMPLE_FLOW_CLASS, WorkflowConstants.WorkflowClasses.APPLICATION_REGISTRATION_APPROVAL_FLOW_CLASS); try { clazz = TenantWorkflowConfigHolder.class.getClassLoader().loadClass(executorClassName); workFlowExecutor = (WorkflowExecutor) clazz.newInstance(); - loadProperties(workflowElem, workFlowExecutor); + loadProperties(workflowConfig, workFlowExecutor); } catch (ClassNotFoundException e1) { workFlowExecutor = new ApplicationRegistrationSimpleWorkflowExecutor(); } @@ -130,112 +130,112 @@ public void load() throws WorkflowException { WorkflowConstants.WF_TYPE_AM_APPLICATION_REGISTRATION_SANDBOX, workFlowExecutor); // User Signup - workflowElem = workflowConfigDTO. + workflowConfig = workflowConfigDTO. getWorkflowConfigMap().get(WorkflowConstants.USER_SIGN_UP); - executorClassName = getWorkflowExecutorClassName(workflowElem, + executorClassName = getWorkflowExecutorClassName(workflowConfig, WorkflowConstants.WorkflowClasses.USER_SIGNUP_SIMPLE_FLOW_CLASS, WorkflowConstants.WorkflowClasses.USER_SIGNUP_APPROVAL_FLOW_CLASS); try { clazz = TenantWorkflowConfigHolder.class.getClassLoader().loadClass(executorClassName); workFlowExecutor = (WorkflowExecutor) clazz.newInstance(); - loadProperties(workflowElem, workFlowExecutor); + loadProperties(workflowConfig, workFlowExecutor); } catch (ClassNotFoundException e1) { workFlowExecutor = new UserSignUpSimpleWorkflowExecutor(); } workflowExecutorMap.put(WorkflowConstants.WF_TYPE_AM_USER_SIGNUP, workFlowExecutor); // Subscription Creation - workflowElem = workflowConfigDTO. + workflowConfig = workflowConfigDTO. getWorkflowConfigMap().get(WorkflowConstants.SUBSCRIPTION_CREATION); - executorClassName = getWorkflowExecutorClassName(workflowElem, + executorClassName = getWorkflowExecutorClassName(workflowConfig, WorkflowConstants.WorkflowClasses.SUBSCRIPTION_CREATION_SIMPLE_FLOW_CLASS, WorkflowConstants.WorkflowClasses.SUBSCRIPTION_CREATION_APPROVAL_FLOW_CLASS); try { clazz = TenantWorkflowConfigHolder.class.getClassLoader().loadClass(executorClassName); workFlowExecutor = (WorkflowExecutor) clazz.newInstance(); - loadProperties(workflowElem, workFlowExecutor); + loadProperties(workflowConfig, workFlowExecutor); } catch (ClassNotFoundException e1) { workFlowExecutor = new SubscriptionCreationSimpleWorkflowExecutor(); } workflowExecutorMap.put(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION, workFlowExecutor); // Subscription Update - workflowElem = workflowConfigDTO. + workflowConfig = workflowConfigDTO. getWorkflowConfigMap().get(WorkflowConstants.SUBSCRIPTION_UPDATE); - executorClassName = getWorkflowExecutorClassName(workflowElem, + executorClassName = getWorkflowExecutorClassName(workflowConfig, WorkflowConstants.WorkflowClasses.SUBSCRIPTION_UPDATE_SIMPLE_FLOW_CLASS, WorkflowConstants.WorkflowClasses.SUBSCRIPTION_UPDATE_APPROVAL_FLOW_CLASS); try { clazz = TenantWorkflowConfigHolder.class.getClassLoader().loadClass(executorClassName); workFlowExecutor = (WorkflowExecutor) clazz.newInstance(); - loadProperties(workflowElem, workFlowExecutor); + loadProperties(workflowConfig, workFlowExecutor); } catch (ClassNotFoundException e1) { workFlowExecutor = new SubscriptionUpdateSimpleWorkflowExecutor(); } workflowExecutorMap.put(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_UPDATE, workFlowExecutor); // Subscription Deletion - workflowElem = workflowConfigDTO. + workflowConfig = workflowConfigDTO. getWorkflowConfigMap().get(WorkflowConstants.SUBSCRIPTION_DELETION); - executorClassName = getWorkflowExecutorClassName(workflowElem, + executorClassName = getWorkflowExecutorClassName(workflowConfig, WorkflowConstants.WorkflowClasses.SUBSCRIPTION_DELETION_SIMPLE_FLOW_CLASS, WorkflowConstants.WorkflowClasses.SUBSCRIPTION_DELETION_APPROVAL_FLOW_CLASS); try { clazz = TenantWorkflowConfigHolder.class.getClassLoader().loadClass(executorClassName); workFlowExecutor = (WorkflowExecutor) clazz.newInstance(); - loadProperties(workflowElem, workFlowExecutor); + loadProperties(workflowConfig, workFlowExecutor); } catch (ClassNotFoundException e1) { workFlowExecutor = new SubscriptionDeletionSimpleWorkflowExecutor(); } workflowExecutorMap.put(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION, workFlowExecutor); // Application Deletion - workflowElem = workflowConfigDTO. + workflowConfig = workflowConfigDTO. getWorkflowConfigMap().get(WorkflowConstants.APPLICATION_DELETION); - executorClassName = getWorkflowExecutorClassName(workflowElem, + executorClassName = getWorkflowExecutorClassName(workflowConfig, WorkflowConstants.WorkflowClasses.APPLICATION_DELETION_SIMPLE_FLOW_CLASS, WorkflowConstants.WorkflowClasses.APPLICATION_DELETION_APPROVAL_FLOW_CLASS); try { clazz = TenantWorkflowConfigHolder.class.getClassLoader().loadClass(executorClassName); workFlowExecutor = (WorkflowExecutor) clazz.newInstance(); - loadProperties(workflowElem, workFlowExecutor); + loadProperties(workflowConfig, workFlowExecutor); } catch (ClassNotFoundException e1) { workFlowExecutor = new ApplicationDeletionSimpleWorkflowExecutor(); } workflowExecutorMap.put(WorkflowConstants.WF_TYPE_AM_APPLICATION_DELETION, workFlowExecutor); // API State Change - workflowElem = workflowConfigDTO. + workflowConfig = workflowConfigDTO. getWorkflowConfigMap().get(WorkflowConstants.API_STATE_CHANGE); - executorClassName = getWorkflowExecutorClassName(workflowElem, + executorClassName = getWorkflowExecutorClassName(workflowConfig, WorkflowConstants.WorkflowClasses.API_STATE_CHANGE_SIMPLE_FLOW_CLASS, WorkflowConstants.WorkflowClasses.API_STATE_CHANGE_APPROVAL_FLOW_CLASS); try { clazz = TenantWorkflowConfigHolder.class.getClassLoader().loadClass(executorClassName); workFlowExecutor = (WorkflowExecutor) clazz.newInstance(); - loadProperties(workflowElem, workFlowExecutor); + loadProperties(workflowConfig, workFlowExecutor); } catch (ClassNotFoundException e1) { workFlowExecutor = new APIStateChangeSimpleWorkflowExecutor(); } workflowExecutorMap.put(WorkflowConstants.WF_TYPE_AM_API_STATE, workFlowExecutor); // API Product State Change - workflowElem = workflowConfigDTO. + workflowConfig = workflowConfigDTO. getWorkflowConfigMap().get(WorkflowConstants.API_PRODUCT_STATE_CHANGE); - executorClassName = getWorkflowExecutorClassName(workflowElem, + executorClassName = getWorkflowExecutorClassName(workflowConfig, WorkflowConstants.WorkflowClasses.API_PRODUCT_STATE_CHANGE_SIMPLE_FLOW_CLASS, WorkflowConstants.WorkflowClasses.API_PRODUCT_STATE_CHANGE_APPROVAL_FLOW_CLASS); try { clazz = TenantWorkflowConfigHolder.class.getClassLoader().loadClass(executorClassName); workFlowExecutor = (WorkflowExecutor) clazz.newInstance(); - loadProperties(workflowElem, workFlowExecutor); + loadProperties(workflowConfig, workFlowExecutor); } catch (ClassNotFoundException e1) { workFlowExecutor = new APIProductStateChangeSimpleWorkflowExecutor(); } @@ -318,16 +318,9 @@ public void setInstanceProperty(String name, JsonElement valElem, Object obj) th } else if (Class.forName("[C").equals(params[0])) { method = obj.getClass().getMethod(mName, Class.forName("[C")); method.invoke(obj, primitive.getAsString().toCharArray()); - } else if (OMElement.class.equals(params[0])) { - method = obj.getClass().getMethod(mName, OMElement.class); - OMElement el = AXIOMUtil.stringToOM(primitive.getAsString()); - method.invoke(obj, new OMElement[]{el}); } else { continue; } - } else if (!valElem.isJsonPrimitive() && JsonElement.class.equals(params[0])) { - method = obj.getClass().getMethod(mName, JsonElement.class); - method.invoke(obj, new JsonElement[]{valElem}); } else { continue; } @@ -362,19 +355,23 @@ private static void handleException(String msg, Exception e) throws WorkflowExce /** * Return either the simple workflow, approval flow or custom flow class name based on the config. * - * @param workflowElem the workflow config element + * @param workflowConfig the workflow config element * @param simpleFlowClassName simple flow class name * @param approvalFlowClassName approval flow class name * @return class name */ - private String getWorkflowExecutorClassName(WorkflowConfigDTO.WorkflowConfig workflowElem, + private String getWorkflowExecutorClassName(WorkflowConfigDTO.WorkflowConfig workflowConfig, String simpleFlowClassName, String approvalFlowClassName) { - if (workflowElem != null && workflowElem.isEnabled() && !workflowElem.getClassName().isEmpty()) { - return workflowElem.getClassName(); - } else if (workflowElem != null && workflowElem.isEnabled() && workflowElem.getClassName().isEmpty()) { + + if (workflowConfig != null && !workflowConfig.getClassName().isEmpty()) { + // If a config element is present and a class is specified + return workflowConfig.getClassName(); + } else if (workflowConfig != null && workflowConfig.getClassName().isEmpty()) { + // If a config element is present and a class is not specified its approval flow return approvalFlowClassName; } else { + // else its simple flow return simpleFlowClassName; } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/resources/tenant/tenant-config-schema.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/resources/tenant/tenant-config-schema.json index be6747d99d7d..fe2b6e97f0e5 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/resources/tenant/tenant-config-schema.json +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/resources/tenant/tenant-config-schema.json @@ -1350,17 +1350,20 @@ "type": "object", "title": "Define the corresponding workflow configuration", "properties": { - "Enabled": { - "type": "boolean", - "title": "Set this as true to enable the approval/custom workflow" - }, "Class": { "type": "string", "title": "For a custom flow, define the full class path here" }, "Properties": { "type": "object", - "title": "Define any class-specific properties here" + "title": "Define any class-specific properties here", + "additionalProperties": { + "type": [ + "string", + "number", + "boolean" + ] + } } }, "additionalProperties": false diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/config/APIMConfigServiceImplTestCase.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/config/APIMConfigServiceImplTestCase.java index 740e15a9999a..cb9bf7000198 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/config/APIMConfigServiceImplTestCase.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/config/APIMConfigServiceImplTestCase.java @@ -110,12 +110,10 @@ public void testGetWorkflowConfigWhenConfigured() throws IOException, APIManagem APIMConfigServiceImpl configServiceImpl = new APIMConfigServiceImpl(); WorkflowConfigDTO workflowConfigDTO = configServiceImpl.getWorkFlowConfig("carbon.super"); Assert.assertEquals(4, workflowConfigDTO.getWorkflowConfigMap().size()); - Assert.assertFalse(workflowConfigDTO.getWorkflowConfigMap().get("ApplicationCreation").isEnabled()); - Assert.assertTrue(workflowConfigDTO.getWorkflowConfigMap().get("ApplicationDeletion").isEnabled()); - Assert.assertTrue(workflowConfigDTO.getWorkflowConfigMap().get("UserSignUp").isEnabled()); + Assert.assertNotNull(workflowConfigDTO.getWorkflowConfigMap().get("ApplicationCreation")); + Assert.assertNotNull(workflowConfigDTO.getWorkflowConfigMap().get("ApplicationDeletion").getClassName()); Assert.assertEquals("org.wso2.example.UserSignUpCustomFlowExecutor", workflowConfigDTO.getWorkflowConfigMap().get("UserSignUp").getClassName()); - Assert.assertTrue(workflowConfigDTO.getWorkflowConfigMap().get("UserSignUp").isEnabled()); JsonObject properties = workflowConfigDTO.getWorkflowConfigMap().get("APIStateChange").getProperties(); Assert.assertEquals("Created:Publish,Published:Block", properties.get("StateList").getAsString()); diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/workflow/TenantWorkflowConfigHolderTest.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/workflow/TenantWorkflowConfigHolderTest.java index 98d0d30a90a8..b5f5a1c9672e 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/workflow/TenantWorkflowConfigHolderTest.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/workflow/TenantWorkflowConfigHolderTest.java @@ -89,38 +89,18 @@ public void testLoadingDefaultTenantWorkflowConfig() throws APIManagementExcepti @Test public void testLoadingApprovalTenantWorkflowConfig() throws IOException, APIManagementException { JsonObject WFConfig = JsonParser.parseString("{\n" + - " \"Workflows\": {\n" + - " \"ApplicationCreation\": {\n" + - " \"Enabled\": true\n" + - " },\n" + - " \"ProductionApplicationRegistration\": {\n" + - " \"Enabled\": true\n" + - " },\n" + - " \"SandboxApplicationRegistration\": {\n" + - " \"Enabled\": true\n" + - " },\n" + - " \"SubscriptionCreation\": {\n" + - " \"Enabled\": true\n" + - " },\n" + - " \"SubscriptionUpdate\": {\n" + - " \"Enabled\": true\n" + - " },\n" + - " \"UserSignUp\": {\n" + - " \"Enabled\": true\n" + - " },\n" + - " \"SubscriptionDeletion\": {\n" + - " \"Enabled\": true\n" + - " },\n" + - " \"ApplicationDeletion\": {\n" + - " \"Enabled\": true\n" + - " },\n" + - " \"APIStateChange\": {\n" + - " \"Enabled\": true\n" + - " },\n" + - " \"APIProductStateChange\": {\n" + - " \"Enabled\": true\n" + - " }\n" + - " }\n" + + " \"Workflows\": {\n" + + " \"ApplicationCreation\": {},\n" + + " \"ProductionApplicationRegistration\": {},\n" + + " \"SandboxApplicationRegistration\": {},\n" + + " \"SubscriptionCreation\": {},\n" + + " \"SubscriptionUpdate\": {},\n" + + " \"UserSignUp\": {},\n" + + " \"SubscriptionDeletion\": {},\n" + + " \"ApplicationDeletion\": {},\n" + + " \"APIStateChange\": {},\n" + + " \"APIProductStateChange\": {}\n" + + " }\n" + "}").getAsJsonObject(); TenantWorkflowConfigHolder tenantWorkflowConfigHolder = new TenantWorkflowConfigHolder(tenantDomain, tenantID); @@ -159,7 +139,6 @@ public void testFailureToLoadTenantWFConfigWhenWFExecutorClassNotFound() throws JsonObject invalidWFExecutor = JsonParser.parseString("{\n" + " \"Workflows\": {\n" + " \"UserSignUp\": {\n" + - " \"Enabled\": true,\n" + " \"Class\": \"TestUserSignUpSimpleWorkflowExecutor\"\n" + " }\n" + " }\n" + @@ -180,7 +159,6 @@ public void testFailureToLoadTenantWFConfigWhenWFExecutorClassCannotBeInstantiat JsonObject invalidWFExecutor = JsonParser.parseString("{\n" + " \"Workflows\": {\n" + " \"ApplicationCreation\": {\n" + - " \"Enabled\": true,\n" + " \"Class\": \"org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor\"\n" + " }\n" + " }\n" + @@ -204,7 +182,6 @@ public void testFailureToLoadTenantWFConfigWhenWFExecutorClassCannotAccessible() JsonObject invalidWFExecutor = JsonParser.parseString("{\n" + " \"Workflows\": {\n" + " \"ApplicationCreation\": {\n" + - " \"Enabled\": true,\n" + " \"Class\": \"org.wso2.carbon.apimgt.impl.workflow.InvalidWorkFlowExecutor1\"\n" + " }\n" + " }\n" + @@ -227,7 +204,6 @@ public void testFailureToLoadTenantWFConfigWhenWFExecutorPropertyNameEmpty() thr JsonObject invalidWFExecutor = JsonParser.parseString("{\n" + " \"Workflows\": {\n" + " \"UserSignUp\": {\n" + - " \"Enabled\": true,\n" + " \"Class\": \"org.wso2.carbon.apimgt.impl.workflow.ApplicationCreationApprovalWorkflowExecutor\",\n" + " \"Properties\": {\n" + " \"\": \"xxx\"\n" + @@ -253,7 +229,6 @@ public void testFailureToLoadTenantWFConfigWhenWFExecutorPropertySetterNotDefine JsonObject invalidWFExecutor = JsonParser.parseString("{\n" + " \"Workflows\": {\n" + " \"UserSignUp\": {\n" + - " \"Enabled\": true,\n" + " \"Class\": \"org.wso2.carbon.apimgt.impl.workflow.ApplicationCreationApprovalWorkflowExecutor\",\n" + " \"Properties\": {\n" + " \"TestParam\": \"xxx\"\n" + @@ -282,7 +257,6 @@ public void testFailureToLoadTenantWFConfigWhenWFExecutorPropertySetterInInvalid JsonObject invalidWFExecutor = JsonParser.parseString("{\n" + " \"Workflows\": {\n" + " \"UserSignUp\": {\n" + - " \"Enabled\": true,\n" + " \"Class\": \"org.wso2.carbon.apimgt.impl.workflow.InvalidWorkFlowExecutor2\",\n" + " \"Properties\": {\n" + " \"Username\": \"admin\"\n" + @@ -313,7 +287,6 @@ public void testLoadingTenantWFConfigWhenWFExecutorHasMultipleParamTypes() throw JsonObject WFExecutor = JsonParser.parseString("{\n" + " \"Workflows\": {\n" + " \"UserSignUp\": {\n" + - " \"Enabled\": true,\n" + " \"Class\": \"org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorWithMultipleParamTypes\",\n" + " \"Properties\": {\n" + " \"StringParam\": \"admin\",\n" + @@ -321,9 +294,7 @@ public void testLoadingTenantWFConfigWhenWFExecutorHasMultipleParamTypes() throw " \"BooleanParam\": true,\n" + " \"LongParam\": 10000000,\n" + " \"DoubleParam\": 10.1000000000,\n" + - " \"FloatParam\": 10.1,\n" + - " \"JsonElement\": {\"key\":\"value\"},\n" + - " \"OMElementParam\": \"test\"\n" + + " \"FloatParam\": 10.1\n" + " }\n" + " }\n" + " }\n" + @@ -341,8 +312,6 @@ public void testLoadingTenantWFConfigWhenWFExecutorHasMultipleParamTypes() throw Assert.assertEquals(10000000, executor.longParam); Assert.assertEquals((Double) 10.1000000000, executor.doubleParam); Assert.assertEquals((Float) 10.1f, executor.floatParam); - Assert.assertEquals("{\"key\":\"value\"}", executor.jsonElement.toString()); - Assert.assertEquals("test", executor.omElement.toString()); } catch (WorkflowException e) { @@ -361,7 +330,6 @@ public void testLoadingTenantWFExecutorWithMultipleParamTypesWhenAllPropValuesAr JsonObject WFExecutor = JsonParser.parseString("{\n" + " \"Workflows\": {\n" + " \"UserSignUp\": {\n" + - " \"Enabled\": true,\n" + " \"Class\": \"org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorWithMultipleParamTypes\",\n" + " \"Properties\": {\n" + " \"StringParam\": \"admin\",\n" + @@ -369,8 +337,7 @@ public void testLoadingTenantWFExecutorWithMultipleParamTypesWhenAllPropValuesAr " \"BooleanParam\": \"true\",\n" + " \"LongParam\": \"10000000\",\n" + " \"DoubleParam\": \"10.1000000000\",\n" + - " \"FloatParam\": \"10.1\",\n" + - " \"OMElementParam\": \"test\"\n" + + " \"FloatParam\": \"10.1\"\n" + " }\n" + " }\n" + " }\n" + @@ -388,7 +355,6 @@ public void testLoadingTenantWFExecutorWithMultipleParamTypesWhenAllPropValuesAr Assert.assertEquals(10000000, executor.longParam); Assert.assertEquals((Double) 10.1000000000, executor.doubleParam); Assert.assertEquals((Float) 10.1f, executor.floatParam); - Assert.assertEquals("test", executor.omElement.toString()); } catch (WorkflowException e) { Assert.fail("Unexpected WorkflowException has been thrown while loading workflow executor for different " + "param types"); diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/workflow/WorkflowTestUtils.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/workflow/WorkflowTestUtils.java index 3b7314b63f02..9517ab18c194 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/workflow/WorkflowTestUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/java/org/wso2/carbon/apimgt/impl/workflow/WorkflowTestUtils.java @@ -45,14 +45,12 @@ public static WorkflowConfigDTO getWorkFlowConfigDTOFromJsonConfig(JsonObject te String workflowName = entry.getKey(); JsonObject workflowConfigEntry = (JsonObject) entry.getValue(); - boolean isEnabled = workflowConfigEntry.get("Enabled") != null - && workflowConfigEntry.get("Enabled").getAsBoolean(); String className = workflowConfigEntry.get("Class") != null ? workflowConfigEntry.get("Class").getAsString() : ""; JsonObject properties = workflowConfigEntry.get("Properties") != null ? workflowConfigEntry.get("Properties").getAsJsonObject() : null; - config.addWorkflowConfig(workflowName, isEnabled, className, properties); + config.addWorkflowConfig(workflowName, className, properties); } } return config; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/tenant-conf.json b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/tenant-conf.json index 220ea89a490e..c1a24e140d6e 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/tenant-conf.json +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/test/resources/tenant-conf.json @@ -310,18 +310,12 @@ ] }, "Workflows": { - "ApplicationCreation": { - "Enabled": false - }, - "ApplicationDeletion": { - "Enabled": true - }, + "ApplicationCreation": {}, + "ApplicationDeletion": {}, "UserSignUp": { - "Enabled": true, "Class": "org.wso2.example.UserSignUpCustomFlowExecutor" }, "APIStateChange": { - "Enabled": true, "Properties": { "StateList": "Created:Publish,Published:Block" }