<commit_before><!--
~ Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<%@ page import="org.apache.axis2.context.ConfigurationContext" %>

<%@ page import="org.wso2.carbon.CarbonConstants" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
<%@ page import="org.wso2.carbon.utils.ServerConstants" %>
<%@ page import="org.wso2.carbon.bpmn.ui.WorkflowServiceClient" %>
<%@ page import="org.wso2.carbon.bpmn.core.mgt.model.xsd.BPMNInstance" %>
<%@ page import="org.wso2.carbon.ui.util.CharacterEncoder" %>
<%@ page import="org.wso2.carbon.bpmn.core.mgt.model.xsd.BPMNProcess" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
<fmt:bundle basename="org.wso2.carbon.bpmn.ui.i18n.Resources">
<%
    String serverURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    WorkflowServiceClient client;
    BPMNInstance[] bpmnInstances;
    BPMNProcess[] bpmnProcesses;

    String operation = CharacterEncoder.getSafeText(request.getParameter("operation"));
    String instanceId = CharacterEncoder.getSafeText(request.getParameter("instanceID"));
    String pageNumber = CharacterEncoder.getSafeText(request.getParameter("pageNumber"));
    String state = CharacterEncoder.getSafeText(request.getParameter("state"));
    String iid = CharacterEncoder.getSafeText(request.getParameter("iid"));
    String pid = CharacterEncoder.getSafeText(request.getParameter("pid"));
    String startAfter = CharacterEncoder.getSafeText(request.getParameter("startAfter"));
    String startBefore = CharacterEncoder.getSafeText(request.getParameter("startBefore"));
    String variableName = CharacterEncoder.getSafeText(request.getParameter("variable"));
    String variableValue = CharacterEncoder.getSafeText(request.getParameter("value"));

    String parameters = "region=region1&item=bpmn_menu";
    boolean finished = false;
    if (state != null && state.equals("completed")) {
        parameters += "&state=completed";
        finished = true;
    } else {
        parameters += "&state=active";
    }
    if (iid != null && !iid.equals("")) {
        parameters += ("&iid=" + iid);
    }
    if (pid != null && !pid.equals("")) {
        parameters += ("&pid=" + pid);
    }
    if (startAfter != null && !startAfter.equals("")) {
        parameters += ("&startAfter=" + startAfter);
    }
    if (startBefore != null && !startBefore.equals("")) {
        parameters += ("&startBefore=" + startBefore);
    }
    if (variableName != null && !variableName.equals("")) {
        parameters += ("&variable=" + variableName);
    }
    if (variableValue != null && !variableValue.equals("")) {
        parameters += ("&value=" + variableValue);
    }
    int currentPage = 0;
    if(pageNumber != null && !pageNumber.equals("")){
        currentPage = Integer.parseInt(pageNumber);
    }
    int start = currentPage * 10;
    int numberOfPages;
    try {
        client = new WorkflowServiceClient(cookie, serverURL, configContext);


        if(operation != null && operation.equals("deleteProcessInstance")){
            client.deleteProcessInstance(instanceId);
        }else if(operation != null && operation.equals("suspendProcessInstance")){
            client.suspendProcessInstance(instanceId);
        }else if(operation != null && operation.equals("activateProcessInstance")){
            client.activateProcessInstance(instanceId);
        }else if(operation != null && operation.equals("deleteAllProcessInstances")){
            client.deleteAllProcessInstances();
        }

        bpmnInstances = client.getPaginatedInstanceByFilter(finished, iid, startAfter, startBefore, pid,
                variableName, variableValue, start, 10);
        bpmnProcesses = client.getProcessList();
        numberOfPages = (int) Math.ceil(client.getInstanceCount()/10.0);
    } catch (Exception e) {
        CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request, e);
%>
<script type="text/javascript">
    location.href = "../admin/error.jsp";
</script>
<%
        return;
    }
%>
<%
    if(operation != null && operation.equals("instanceInfo")){
%>
    <jsp:include page="instance_variables.jsp"/>
<%  }else{ %>
<link rel="stylesheet" type="text/css" href="css/bpmn_icon_link.css" />
<script>
    function deleteAllInstance() {
        function deleteYes() {
        $.ajax({
        type: 'POST',
        url: location.protocol + "//" + location.host + "/carbon/bpmn/instance_list_view.jsp?region=region1&item=bpmn_instace_menu&operation=deleteAllProcessInstances",
        success: function(data){
            window.location = location.protocol + "//" + location.host + "/carbon/bpmn/process_list_view.jsp?region=region1&item=bpmn_menu";
           }
        });
        }
        sessionAwareFunction(function() {
        CARBON.showConfirmationDialog('<fmt:message key="do.you.want.to.delete.all.instances"/> ' + "?", deleteYes, null);
        }, "<fmt:message key="session.timed.out"/>");
        return false;
    }
    function deleteInstance(iid) {
        function deleteYes() {
        $.ajax({
        type: 'POST',
        url: location.protocol + "//" + location.host + "/carbon/bpmn/instance_list_view.jsp?region=region1&item=bpmn_instace_menu&operation=deleteProcessInstance&instanceID=" + iid,
        success: function(data){
	        window.location = location.protocol + "//" + location.host + "/carbon/bpmn/instance_list_view.jsp?region=region1&item=bpmn_instace_menu";
           }
        });
        }
        sessionAwareFunction(function() {
        CARBON.showConfirmationDialog('<fmt:message key="do.you.want.to.delete.instance"/> ' + iid + "?", deleteYes, null);
        }, "<fmt:message key="session.timed.out"/>");
        return false;
    }
    function suspendInstance(iid) {
        function suspendYes() {
        $.ajax({
        type: 'POST',
        url: location.protocol + "//" + location.host + "/carbon/bpmn/instance_list_view.jsp?region=region1&item=bpmn_instace_menu&operation=suspendProcessInstance&instanceID=" + iid,
        success: function(data){
	        window.location = location.protocol + "//" + location.host + "/carbon/bpmn/instance_list_view.jsp?region=region1&item=bpmn_instace_menu";
           }
        });
        }
        sessionAwareFunction(function() {
        CARBON.showConfirmationDialog('<fmt:message key="do.you.want.to.suspend.instance"/> ' + iid + "?", suspendYes, null);

        }, "<fmt:message key="session.timed.out"/>");
        return false;
    }
    function activateInstance(iid) {
            function activateYes() {
            $.ajax({<commit_msg>Fixing redirection to process view after clicking delete all in bpmn ui. Issue - https://wso2.org/jira/browse/BPS-795<commit_after><!--
~ Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you 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.
-->
<%@ page import="org.apache.axis2.context.ConfigurationContext" %>

<%@ page import="org.wso2.carbon.CarbonConstants" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
<%@ page import="org.wso2.carbon.utils.ServerConstants" %>
<%@ page import="org.wso2.carbon.bpmn.ui.WorkflowServiceClient" %>
<%@ page import="org.wso2.carbon.bpmn.core.mgt.model.xsd.BPMNInstance" %>
<%@ page import="org.wso2.carbon.ui.util.CharacterEncoder" %>
<%@ page import="org.wso2.carbon.bpmn.core.mgt.model.xsd.BPMNProcess" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
<fmt:bundle basename="org.wso2.carbon.bpmn.ui.i18n.Resources">
<%
    String serverURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    WorkflowServiceClient client;
    BPMNInstance[] bpmnInstances;
    BPMNProcess[] bpmnProcesses;

    String operation = CharacterEncoder.getSafeText(request.getParameter("operation"));
    String instanceId = CharacterEncoder.getSafeText(request.getParameter("instanceID"));
    String pageNumber = CharacterEncoder.getSafeText(request.getParameter("pageNumber"));
    String state = CharacterEncoder.getSafeText(request.getParameter("state"));
    String iid = CharacterEncoder.getSafeText(request.getParameter("iid"));
    String pid = CharacterEncoder.getSafeText(request.getParameter("pid"));
    String startAfter = CharacterEncoder.getSafeText(request.getParameter("startAfter"));
    String startBefore = CharacterEncoder.getSafeText(request.getParameter("startBefore"));
    String variableName = CharacterEncoder.getSafeText(request.getParameter("variable"));
    String variableValue = CharacterEncoder.getSafeText(request.getParameter("value"));

    String parameters = "region=region1&item=bpmn_menu";
    boolean finished = false;
    if (state != null && state.equals("completed")) {
        parameters += "&state=completed";
        finished = true;
    } else {
        parameters += "&state=active";
    }
    if (iid != null && !iid.equals("")) {
        parameters += ("&iid=" + iid);
    }
    if (pid != null && !pid.equals("")) {
        parameters += ("&pid=" + pid);
    }
    if (startAfter != null && !startAfter.equals("")) {
        parameters += ("&startAfter=" + startAfter);
    }
    if (startBefore != null && !startBefore.equals("")) {
        parameters += ("&startBefore=" + startBefore);
    }
    if (variableName != null && !variableName.equals("")) {
        parameters += ("&variable=" + variableName);
    }
    if (variableValue != null && !variableValue.equals("")) {
        parameters += ("&value=" + variableValue);
    }
    int currentPage = 0;
    if(pageNumber != null && !pageNumber.equals("")){
        currentPage = Integer.parseInt(pageNumber);
    }
    int start = currentPage * 10;
    int numberOfPages;
    try {
        client = new WorkflowServiceClient(cookie, serverURL, configContext);


        if(operation != null && operation.equals("deleteProcessInstance")){
            client.deleteProcessInstance(instanceId);
        }else if(operation != null && operation.equals("suspendProcessInstance")){
            client.suspendProcessInstance(instanceId);
        }else if(operation != null && operation.equals("activateProcessInstance")){
            client.activateProcessInstance(instanceId);
        }else if(operation != null && operation.equals("deleteAllProcessInstances")){
            client.deleteAllProcessInstances();
        }

        bpmnInstances = client.getPaginatedInstanceByFilter(finished, iid, startAfter, startBefore, pid,
                variableName, variableValue, start, 10);
        bpmnProcesses = client.getProcessList();
        numberOfPages = (int) Math.ceil(client.getInstanceCount()/10.0);
    } catch (Exception e) {
        CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request, e);
%>
<script type="text/javascript">
    location.href = "../admin/error.jsp";
</script>
<%
        return;
    }
%>
<%
    if(operation != null && operation.equals("instanceInfo")){
%>
    <jsp:include page="instance_variables.jsp"/>
<%  }else{ %>
<link rel="stylesheet" type="text/css" href="css/bpmn_icon_link.css" />
<script>
    function deleteAllInstance() {
        function deleteYes() {
        $.ajax({
        type: 'POST',
        url: location.protocol + "//" + location.host + "/carbon/bpmn/instance_list_view.jsp?region=region1&item=bpmn_instace_menu&operation=deleteAllProcessInstances",
        success: function(data){
            window.location = location.protocol + "//" + location.host + "/carbon/bpmn/instance_list_view.jsp?region=region1&item=bpmn_menu&state=completed";
           }
        });
        }
        sessionAwareFunction(function() {
        CARBON.showConfirmationDialog('<fmt:message key="do.you.want.to.delete.all.instances"/> ' + "?", deleteYes, null);
        }, "<fmt:message key="session.timed.out"/>");
        return false;
    }
    function deleteInstance(iid) {
        function deleteYes() {
        $.ajax({
        type: 'POST',
        url: location.protocol + "//" + location.host + "/carbon/bpmn/instance_list_view.jsp?region=region1&item=bpmn_instace_menu&operation=deleteProcessInstance&instanceID=" + iid,
        success: function(data){
	        window.location = location.protocol + "//" + location.host + "/carbon/bpmn/instance_list_view.jsp?region=region1&item=bpmn_instace_menu&state=completed";
           }
        });
        }
        sessionAwareFunction(function() {
        CARBON.showConfirmationDialog('<fmt:message key="do.you.want.to.delete.instance"/> ' + iid + "?", deleteYes, null);
        }, "<fmt:message key="session.timed.out"/>");
        return false;
    }
    function suspendInstance(iid) {
        function suspendYes() {
        $.ajax({
        type: 'POST',
        url: location.protocol + "//" + location.host + "/carbon/bpmn/instance_list_view.jsp?region=region1&item=bpmn_instace_menu&operation=suspendProcessInstance&instanceID=" + iid,
        success: function(data){
	        window.location = location.protocol + "//" + location.host + "/carbon/bpmn/instance_list_view.jsp?region=region1&item=bpmn_instace_menu";
           }
        });
        }
        sessionAwareFunction(function() {
        CARBON.showConfirmationDialog('<fmt:message key="do.you.want.to.suspend.instance"/> ' + iid + "?", suspendYes, null);

        }, "<fmt:message key="session.timed.out"/>");
        return false;
    }
    function activateInstance(iid) {
            function activateYes() {
            $.ajax({
{'fraction_non_alphanumeric': 0.14827383671604777, 'fraction_numerical': 0.00587352346146316, 'mean_word_length': 3.621230398069964, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, 'https://': 1, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5940543', 'n_tokens_mistral': 4622, 'n_tokens_neox': 4481, 'n_words': 796}