<commit_before><!--
 ~ Copyright (c) 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.wso2.carbon.utils.ServerConstants" %>
<%@ page import="org.wso2.carbon.CarbonConstants" %>
<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
<%@ page import="org.wso2.carbon.bpel.ui.clients.InstanceManagementServiceClient" %>
<%@ page import="org.wso2.carbon.bpel.stub.mgt.types.PaginatedInstanceList" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
<%@ page import="org.wso2.carbon.bpel.stub.mgt.types.LimitedInstanceInfoType" %>
<%@ page import="org.wso2.carbon.bpel.ui.BpelUIUtil" %>
<%@ page import="org.wso2.carbon.bpel.ui.clients.ProcessManagementServiceClient" %>
<%@ page import="org.wso2.carbon.bpel.ui.InstanceFilterUtil" %>
<%@ page import="org.apache.commons.httpclient.HttpStatus" %>
<%@ page import="org.wso2.carbon.bpel.ui.InstanceFilter" %>
<%@ page import="org.wso2.carbon.ui.util.CharacterEncoder" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
<%@ page import="javax.xml.namespace.QName" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.TreeMap" %>

<jsp:useBean id="instanceFilter" scope="session" class="org.wso2.carbon.bpel.ui.InstanceFilter"/>
<jsp:setProperty name="instanceFilter" property="*" />

<%
    response.setHeader("Cache-Control",
            "no-store, max-age=0, no-cache, must-revalidate");
    // Set IE extended HTTP/1.1 no-cache headers.
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");
    // Set standard HTTP/1.0 no-cache header.
    response.setHeader("Pragma", "no-cache");

    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String)session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

    InstanceManagementServiceClient client;
    ProcessManagementServiceClient processManagementClient = null;
    PaginatedInstanceList instanceList = null;
    int numberOfPages = 0;
    String processIds[] = null;
    String operation = CharacterEncoder.getSafeText(request.getParameter("operation"));
    String deleteMex = CharacterEncoder.getSafeText(request.getParameter("deleteMex"));
    String pageNumber = CharacterEncoder.getSafeText(request.getParameter("pageNumber"));
    int pageNumberInt = 0;
    String instanceListFilter = CharacterEncoder.getSafeText(request.getParameter("filter"));
//    String instanceListOrderBy = CharacterEncoder.getSafeText(request.getParameter("order"));
    String instanceListOrderBy = request.getParameter("order");

    String parameters = null;

    String resetFilterLink = "list_instances.jsp?pageNumber=0&operation=reset";
    String activeInstancesFilterLink = "list_instances.jsp?pageNumber=0&filter=status%3Dactive&order=%2dlast-active";
    String completedInstanceFilterLink = "list_instances.jsp?pageNumber=0&filter=status%3Dcompleted&order=%2dlast-active";
    String suspendedInstanceFilterLink = "list_instances.jsp?pageNumber=0&filter=status%3Dsuspended&order=%2dlast-active";
    String terminatedInstanceFilterLink = "list_instances.jsp?pageNumber=0&filter=status%3Dterminated&order=%2dlast-active";
    String failedInstanceFilterLink = "list_instances.jsp?pageNumber=0&filter=status%3Dfailed&order=%2dlast-active";

    String deleteInstancesInFilterLink = "list_instances.jsp?pageNumber=0&operation=deleteInstances";

    boolean isAuthenticatedForProcessManagement =
            CarbonUIUtil.isUserAuthorized(request, "/permission/admin/manage/bpel/processes");
    boolean isAuthenticatedForInstanceManagement =
            CarbonUIUtil.isUserAuthorized(request, "/permission/admin/manage/bpel/instances");
    boolean isAuthenticatedForInstanceMonitor =
            CarbonUIUtil.isUserAuthorized(request, "/permission/admin/monitor/bpel");

    if (isAuthenticatedForInstanceManagement || isAuthenticatedForInstanceMonitor) {
        if(operation != null && operation.equals("reset")){
            instanceFilter = null;
            session.removeAttribute("instanceFilter");
        }

        if(pageNumber == null){
            pageNumber = "0";
        }
        try{
            pageNumberInt = Integer.parseInt(pageNumber);
        } catch (NumberFormatException ignored){

        }


        if (instanceFilter == null) {
            instanceFilter = new InstanceFilter();
            instanceFilter.setAsdec("Ascending");
            instanceFilter.setOrderby("last-active");
        }
        // When handling instance filter, we give the priority to filter URL parameter. If the filter URL
        // parameter is null we use the advance parameter. Also for the order-by filed we give the priority to
        // URL parameter.
        if (instanceListFilter != null && instanceListFilter.length() > 0 && !(" ").equals(instanceListFilter)) {
            String[] stateArray = new String[1];
//            stateArray[0] = instanceListFilter.substring(instanceListFilter.indexOf('=') + 1);
            String[] filterParams = instanceListFilter.split(" ");
            for (String filterParam : filterParams) {
                String[] param = filterParam.split("=");
                if (param[0].equals("pid")) {
                    instanceFilter.setPid(param[1]);
                } else if (param[0].equals("status")) {
                    stateArray[0] = param[1];
                    instanceFilter.setStatus(stateArray);
                }
            }
//            instanceFilter.setStatus(stateArray);
        } //else use the advanced filter

        // TODO: Add instance filter saving support(only for the session)
        if(instanceListOrderBy != null && instanceListOrderBy.length() > 0) {
            if (instanceListOrderBy.startsWith("-")) {
                instanceFilter.setAsdec("Ascending");
            } else {
                instanceFilter.setAsdec("Descending");
            }

            // assumption instanceListOrderBy starts with either "-" or "+"
            instanceFilter.setOrderby(instanceListOrderBy.substring(1));
        }

        instanceListFilter = InstanceFilterUtil.createInstanceFilterStringFromFormData(instanceFilter);
        instanceListOrderBy = InstanceFilterUtil.getOrderByFromFormData(instanceFilter);

        parameters = "filter=" + instanceListFilter + "&order=" + instanceListOrderBy;

        try {
            client = new InstanceManagementServiceClient(cookie, backendServerURL, configContext);
            processManagementClient = new ProcessManagementServiceClient(cookie, backendServerURL,
                                                                         configContext,
                                                                         request.getLocale());
        } catch (Exception e) {
            response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            CarbonUIMessage uiMsg = new CarbonUIMessage(CarbonUIMessage.ERROR, e.getMessage(), e);
            session.setAttribute(CarbonUIMessage.ID, uiMsg);
%>
<jsp:include page="../admin/error.jsp"/>
<%
            return;
        }

        if(operation != null && isAuthenticatedForInstanceManagement) {
            String iid = CharacterEncoder.getSafeText(request.getParameter("iid"));
            if(iid != null && !operation.equals("reset")) {
                Long instanceId = Long.parseLong(iid.trim());
                if(operation.trim().equals("suspend")) {
                    try {
                        client.suspendInstance(instanceId);
                    } catch(Exception e) {
                        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
                        CarbonUIMessage uiMsg = new CarbonUIMessage(CarbonUIMessage.ERROR, e.getMessage(), e);
                        session.setAttribute(CarbonUIMessage.ID, uiMsg);
%>
<jsp:include page="../admin/error.jsp"/><commit_msg>encoding advance filter parameters before sending for issue - https://wso2.org/jira/browse/BPS-460<commit_after><!--
 ~ Copyright (c) 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.wso2.carbon.utils.ServerConstants" %>
<%@ page import="org.wso2.carbon.CarbonConstants" %>
<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
<%@ page import="org.wso2.carbon.bpel.ui.clients.InstanceManagementServiceClient" %>
<%@ page import="org.wso2.carbon.bpel.stub.mgt.types.PaginatedInstanceList" %>
<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
<%@ page import="org.wso2.carbon.bpel.stub.mgt.types.LimitedInstanceInfoType" %>
<%@ page import="org.wso2.carbon.bpel.ui.BpelUIUtil" %>
<%@ page import="org.wso2.carbon.bpel.ui.clients.ProcessManagementServiceClient" %>
<%@ page import="org.wso2.carbon.bpel.ui.InstanceFilterUtil" %>
<%@ page import="org.apache.commons.httpclient.HttpStatus" %>
<%@ page import="org.wso2.carbon.bpel.ui.InstanceFilter" %>
<%@ page import="org.wso2.carbon.ui.util.CharacterEncoder" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
<%@ page import="javax.xml.namespace.QName" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.TreeMap" %>
<%@ page import="java.net.URLEncoder" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<jsp:useBean id="instanceFilter" scope="session" class="org.wso2.carbon.bpel.ui.InstanceFilter"/>
<jsp:setProperty name="instanceFilter" property="*" />


<%
    response.setHeader("Cache-Control",
            "no-store, max-age=0, no-cache, must-revalidate");
    // Set IE extended HTTP/1.1 no-cache headers.
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");
    // Set standard HTTP/1.0 no-cache header.
    response.setHeader("Pragma", "no-cache");

    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String)session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

    InstanceManagementServiceClient client;
    ProcessManagementServiceClient processManagementClient = null;
    PaginatedInstanceList instanceList = null;
    int numberOfPages = 0;
    String processIds[] = null;
    String operation = CharacterEncoder.getSafeText(request.getParameter("operation"));
    String deleteMex = CharacterEncoder.getSafeText(request.getParameter("deleteMex"));
    String pageNumber = CharacterEncoder.getSafeText(request.getParameter("pageNumber"));
    int pageNumberInt = 0;
    String instanceListFilter = CharacterEncoder.getSafeText(request.getParameter("filter"));
    String instanceListOrderBy = CharacterEncoder.getSafeText(request.getParameter("order"));

    String parameters = null;
    final String ENCODING_SCHEME = "UTF-8";

    String resetFilterLink = "list_instances.jsp?pageNumber=0&operation=reset";
    String activeInstancesFilterLink = "list_instances.jsp?pageNumber=0&filter=status%3Dactive&order=%2dlast-active";
    String completedInstanceFilterLink = "list_instances.jsp?pageNumber=0&filter=status%3Dcompleted&order=%2dlast-active";
    String suspendedInstanceFilterLink = "list_instances.jsp?pageNumber=0&filter=status%3Dsuspended&order=%2dlast-active";
    String terminatedInstanceFilterLink = "list_instances.jsp?pageNumber=0&filter=status%3Dterminated&order=%2dlast-active";
    String failedInstanceFilterLink = "list_instances.jsp?pageNumber=0&filter=status%3Dfailed&order=%2dlast-active";

    String deleteInstancesInFilterLink = "list_instances.jsp?pageNumber=0&operation=deleteInstances";

    boolean isAuthenticatedForProcessManagement =
            CarbonUIUtil.isUserAuthorized(request, "/permission/admin/manage/bpel/processes");
    boolean isAuthenticatedForInstanceManagement =
            CarbonUIUtil.isUserAuthorized(request, "/permission/admin/manage/bpel/instances");
    boolean isAuthenticatedForInstanceMonitor =
            CarbonUIUtil.isUserAuthorized(request, "/permission/admin/monitor/bpel");

    if (isAuthenticatedForInstanceManagement || isAuthenticatedForInstanceMonitor) {
        if(operation != null && operation.equals("reset")){
            instanceFilter = null;
            session.removeAttribute("instanceFilter");
        }

        if(pageNumber == null){
            pageNumber = "0";
        }
        try{
            pageNumberInt = Integer.parseInt(pageNumber);
        } catch (NumberFormatException ignored){

        }


        if (instanceFilter == null) {
            instanceFilter = new InstanceFilter();
            instanceFilter.setAsdec("Ascending");
            instanceFilter.setOrderby("last-active");
        }
        // When handling instance filter, we give the priority to filter URL parameter. If the filter URL
        // parameter is null we use the advance parameter. Also for the order-by filed we give the priority to
        // URL parameter.
        if (instanceListFilter != null && instanceListFilter.length() > 0 && !(" ").equals(instanceListFilter)) {
            String[] stateArray = new String[1];
//            stateArray[0] = instanceListFilter.substring(instanceListFilter.indexOf('=') + 1);
            String[] filterParams = instanceListFilter.split(" ");
            for (String filterParam : filterParams) {
                String[] param = filterParam.split("=");
                if (param[0].equals("pid")) {
                    instanceFilter.setPid(param[1]);
                } else if (param[0].equals("status")) {
                    stateArray[0] = param[1];
                    instanceFilter.setStatus(stateArray);
                }
            }
//            instanceFilter.setStatus(stateArray);
        } //else use the advanced filter

        // TODO: Add instance filter saving support(only for the session)
        if(instanceListOrderBy != null && instanceListOrderBy.length() > 0) {
            if (instanceListOrderBy.startsWith("-")) {
                instanceFilter.setAsdec("Ascending");
            } else {
                instanceFilter.setAsdec("Descending");
            }

            // assumption instanceListOrderBy starts with either "-" or "+"
            instanceFilter.setOrderby(instanceListOrderBy.substring(1));
        }

        instanceListFilter = InstanceFilterUtil.createInstanceFilterStringFromFormData(instanceFilter);
        instanceListOrderBy = InstanceFilterUtil.getOrderByFromFormData(instanceFilter);

        parameters = URLEncoder.encode("filter=" + instanceListFilter + "&order=" + instanceListOrderBy,ENCODING_SCHEME);

        try {
            client = new InstanceManagementServiceClient(cookie, backendServerURL, configContext);
            processManagementClient = new ProcessManagementServiceClient(cookie, backendServerURL,
                                                                         configContext,
                                                                         request.getLocale());
        } catch (Exception e) {
            response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            CarbonUIMessage uiMsg = new CarbonUIMessage(CarbonUIMessage.ERROR, e.getMessage(), e);
            session.setAttribute(CarbonUIMessage.ID, uiMsg);
%>
<jsp:include page="../admin/error.jsp"/>
<%
            return;
        }

        if(operation != null && isAuthenticatedForInstanceManagement) {
            String iid = CharacterEncoder.getSafeText(request.getParameter("iid"));
            if(iid != null && !operation.equals("reset")) {
                Long instanceId = Long.parseLong(iid.trim());
                if(operation.trim().equals("suspend")) {
                    try {
                        client.suspendInstance(instanceId);
                    } catch(Exception e) {
                        response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
                        CarbonUIMessage uiMsg = new CarbonUIMessage(CarbonUIMessage.ERROR, e.getMessage(), e);
                        session.setAttribute(CarbonUIMessage.ID, uiMsg);
%>
<jsp:include page="../admin/error.jsp"/>
{'fraction_non_alphanumeric': 0.12112310038980849, 'fraction_numerical': 0.007513699790972261, 'mean_word_length': 3.2318909873296677, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 61, 'https://': 1, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4336784', 'n_tokens_mistral': 4941, 'n_tokens_neox': 4762, 'n_words': 881}