Skip to content

Commit

Permalink
Remove workflow config enabled flag and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Avishka-Shamendra committed Nov 22, 2023
1 parent 447b1ff commit cfecf98
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,12 @@ private WorkflowConfigDTO getWorkFlowConfigDTO(JsonObject workflowConfig) {
for (Map.Entry<String, JsonElement> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -56,27 +55,15 @@ public Map<String, WorkflowConfig> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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<String, List<String>> 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<String, List<String>> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, List<String>> 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<String, List<String>> 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();
}

Expand Down
Loading

0 comments on commit cfecf98

Please sign in to comment.