class WorkflowAction {

    protected List<ExecuteBuildingBlock> sortExecutionPathByObjectForVlanTagging(List<ExecuteBuildingBlock> orchFlows,
            String requestAction) {
        List<ExecuteBuildingBlock> sortedOrchFlows = new ArrayList<>();
        if (requestAction.equals(CREATEINSTANCE)) {
            for (ExecuteBuildingBlock ebb : orchFlows) {
                if (ebb.getBuildingBlock().getBpmnFlowName().equals("AssignNetworkBB")) {
                    String key = ebb.getBuildingBlock().getKey();
                    boolean isVirtualLink = Boolean.TRUE.equals(ebb.getBuildingBlock().isVirtualLink());
                    String virtualLinkKey = ebb.getBuildingBlock().getVirtualLinkKey();
                    sortedOrchFlows.add(ebb);
                    for (ExecuteBuildingBlock ebb2 : orchFlows) {
                        if (!isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals(CREATENETWORKBB)
                                && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
                            sortedOrchFlows.add(ebb2);
                            break;
                        }
                        if (isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals(CREATENETWORKBB)
                                && ebb2.getBuildingBlock().getVirtualLinkKey().equalsIgnoreCase(virtualLinkKey)) {
                            sortedOrchFlows.add(ebb2);
                            break;
                        }
                    }
                    for (ExecuteBuildingBlock ebb2 : orchFlows) {
                        if (!isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals(ACTIVATENETWORKBB)
                                && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
                            sortedOrchFlows.add(ebb2);
                            break;
                        }
                        if (isVirtualLink && ebb2.getBuildingBlock().getBpmnFlowName().equals(ACTIVATENETWORKBB)
                                && ebb2.getBuildingBlock().getVirtualLinkKey().equalsIgnoreCase(virtualLinkKey)) {
                            sortedOrchFlows.add(ebb2);
                            break;
                        }
                    }
                } else if (ebb.getBuildingBlock().getBpmnFlowName().equals(CREATENETWORKBB)
                        || ebb.getBuildingBlock().getBpmnFlowName().equals(ACTIVATENETWORKBB)) {
                    continue;
                } else if (!"".equals(ebb.getBuildingBlock().getBpmnFlowName())) {
                    sortedOrchFlows.add(ebb);
                }
            }
        } else if (requestAction.equals("deleteInstance")) {
            for (ExecuteBuildingBlock ebb : orchFlows) {
                if (ebb.getBuildingBlock().getBpmnFlowName().equals("DeactivateNetworkBB")) {
                    sortedOrchFlows.add(ebb);
                    String key = ebb.getBuildingBlock().getKey();
                    for (ExecuteBuildingBlock ebb2 : orchFlows) {
                        if (ebb2.getBuildingBlock().getBpmnFlowName().equals("DeleteNetworkBB")
                                && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
                            sortedOrchFlows.add(ebb2);
                            break;
                        }
                    }
                    for (ExecuteBuildingBlock ebb2 : orchFlows) {
                        if (ebb2.getBuildingBlock().getBpmnFlowName().equals("UnassignNetworkBB")
                                && ebb2.getBuildingBlock().getKey().equalsIgnoreCase(key)) {
                            sortedOrchFlows.add(ebb2);
                            break;
                        }
                    }
                } else if (ebb.getBuildingBlock().getBpmnFlowName().equals("DeleteNetworkBB")
                        || ebb.getBuildingBlock().getBpmnFlowName().equals("UnassignNetworkBB")) {
                    continue;
                } else if (!ebb.getBuildingBlock().getBpmnFlowName().equals("")) {
                    sortedOrchFlows.add(ebb);
                }
            }
        }
        return sortedOrchFlows;
    }

}