com.photon.phresco.framework.rest.api.QualityService.java Source code

Java tutorial

Introduction

Here is the source code for com.photon.phresco.framework.rest.api.QualityService.java

Source

/**
 * Framework Web Archive
 *
 * Copyright (C) 1999-2014 Photon Infotech Inc.
 *
 * Licensed 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.
 */
package com.photon.phresco.framework.rest.api;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.tools.ant.types.resources.Files;
import org.json.JSONException;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import com.google.gson.Gson;
import com.photon.phresco.commons.FileListFilter;
import com.photon.phresco.commons.FrameworkConstants;
import com.photon.phresco.commons.ResponseCodes;
import com.photon.phresco.commons.model.ApplicationInfo;
import com.photon.phresco.commons.model.FunctionalFrameworkInfo;
import com.photon.phresco.commons.model.ProjectInfo;
import com.photon.phresco.configuration.ConfigReader;
import com.photon.phresco.configuration.Configuration;
import com.photon.phresco.exception.ConfigurationException;
import com.photon.phresco.exception.PhrescoException;
import com.photon.phresco.framework.commons.FrameworkUtil;
import com.photon.phresco.framework.commons.QualityUtil;
import com.photon.phresco.framework.model.PerformancResultInfo;
import com.photon.phresco.framework.model.PerformanceTestResult;
import com.photon.phresco.framework.model.TestCase;
import com.photon.phresco.framework.model.TestCaseError;
import com.photon.phresco.framework.model.TestCaseFailure;
import com.photon.phresco.framework.model.TestReportResult;
import com.photon.phresco.framework.model.TestResult;
import com.photon.phresco.framework.model.TestStep;
import com.photon.phresco.framework.model.TestStepError;
import com.photon.phresco.framework.model.TestStepFailure;
import com.photon.phresco.framework.model.TestSuite;
import com.photon.phresco.framework.rest.api.util.FrameworkServiceUtil;
import com.photon.phresco.plugins.model.Mojos.Mojo.Configuration.Parameters.Parameter;
import com.photon.phresco.plugins.model.Mojos.Mojo.Configuration.Parameters.Parameter.PossibleValues.Value;
import com.photon.phresco.plugins.util.MojoProcessor;
import com.photon.phresco.plugins.util.MojoUtil;
import com.photon.phresco.util.Constants;
import com.photon.phresco.util.HubConfiguration;
import com.photon.phresco.util.NodeConfiguration;
import com.photon.phresco.util.ServiceConstants;
import com.photon.phresco.util.Utility;
import com.phresco.pom.exception.PhrescoPomException;
import com.phresco.pom.model.Plugin;
import com.phresco.pom.util.PomProcessor;
import com.sun.jersey.api.client.ClientResponse.Status;

/**
 * The Class QualityService.
 */
@Path("/quality")
public class QualityService extends RestBase implements ServiceConstants, FrameworkConstants, ResponseCodes {

    /** The test suite map. */
    private static Map<String, Map<String, List<NodeList>>> testSuiteMap = Collections
            .synchronizedMap(new HashMap<String, Map<String, List<NodeList>>>(8));

    /** The set failure test cases. */
    private int setFailureTestCases;

    /** The error test cases. */
    private int errorTestCases;

    /** The node length. */
    private int nodeLength;

    /** The test suite. */
    private String testSuite = "";

    /**
     * Unit.
     *
     * @param appDirName the app dir name
     * @param userId the user id
     * @return the response
     * @throws Exception 
     */
    @GET
    @Path(REST_API_UNIT)
    @Produces(MediaType.APPLICATION_JSON)
    public Response unit(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_QUERY_USERID) String userId, @QueryParam(REST_QUERY_MODULE_NAME) String module)
            throws Exception {
        List<String> testResultFiles = new ArrayList<String>();
        List<String> testResult = new ArrayList<String>();
        ResponseInfo<Map> responseData = new ResponseInfo<Map>();
        try {
            Map<String, Object> unitMap = new HashMap<String, Object>();
            //Map<String, List<String>> unitTestOptionsMap = new HashMap<String, List<String>>();
            String rootModulePath = "";
            String subModuleName = "";
            if (StringUtils.isNotEmpty(module)) {
                rootModulePath = Utility.getProjectHome() + appDirName;
                subModuleName = module;
            } else {
                rootModulePath = Utility.getProjectHome() + appDirName;
            }
            List<String> unitReportOptions = getUnitReportOptions(rootModulePath, subModuleName);
            if (StringUtils.isEmpty(module)) {
                List<String> projectModules = FrameworkServiceUtil.getProjectModules(rootModulePath, subModuleName);
                unitMap.put(PROJECT_MODULES, projectModules);
                if (CollectionUtils.isNotEmpty(projectModules)) {
                    unitReportOptions = getUnitReportOptions(rootModulePath, projectModules.get(0));
                }
            }

            MojoProcessor mojo = new MojoProcessor(new File(FrameworkServiceUtil.getPhrescoPluginInfoFilePath(
                    Constants.PHASE_UNIT_TEST, Constants.PHASE_UNIT_TEST, rootModulePath, subModuleName)));
            List<String> testAgainsts = new ArrayList<String>();
            Parameter testAgainstParameter = mojo.getParameter(Constants.PHASE_UNIT_TEST, REQ_TEST_AGAINST);
            if (testAgainstParameter != null && TYPE_LIST.equalsIgnoreCase(testAgainstParameter.getType())) {
                List<Value> values = testAgainstParameter.getPossibleValues().getValue();
                for (Value value : values) {
                    testAgainsts.add(value.getKey());
                }
            }
            boolean resutlAvailable = testResultAvailunit(rootModulePath, subModuleName, testAgainsts,
                    Constants.PHASE_UNIT_TEST);

            String showDevice = getUnitTestShowDevice(rootModulePath, subModuleName);
            if (resutlAvailable) {

                testResultFiles = testResultFilesunit(rootModulePath, subModuleName, testAgainsts, showDevice,
                        Constants.PHASE_UNIT_TEST);
            }

            if (StringUtils.isNotEmpty(showDevice)) {
                testResult = testResultfileTrim(testResultFiles);
            }

            unitMap.put(TEST_AGAINSTS, testAgainsts);
            unitMap.put(RESULT_AVAILABLE, resutlAvailable);
            unitMap.put(TEST_RESULT_FILES, testResultFiles);
            unitMap.put(TEST_RESULT, testResult);
            unitMap.put(SHOW_DEVICE, showDevice);
            unitMap.put(REPORT_OPTIONS, unitReportOptions);

            ResponseInfo<Map> finalOutput = responseDataEvaluation(responseData, null, unitMap,
                    RESPONSE_STATUS_SUCCESS, PHRQ100001);

            /*ResponseInfo<List<String>> finalOutputvalue = responseDataEvaluation(responseData, null,
                  unitTestOptionsMap, RESPONSE_STATUS_SUCCESS, PHRQ100001);*/
            return Response.ok(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();

        } catch (PhrescoException e) {
            ResponseInfo<List<String>> finalOutput = responseDataEvaluation(responseData, e, null,
                    RESPONSE_STATUS_ERROR, PHRQ110001);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        }
    }

    private List<String> testResultfileTrim(List<String> testResultFiles) {

        StringBuilder testResult = new StringBuilder();
        testResult.append("[");
        for (String p : testResultFiles) {
            if (p.length() != -2) {
                String test = p.substring(5, p.length() - 4);
                testResult.append(test).append(",");
            }

        }
        testResult.append("]");
        String testResultf = testResult.substring(1, testResult.length() - 2).toString();
        List<String> testResultfile = Arrays.asList(testResultf.split("\\s*,\\s*"));
        return testResultfile;
    }

    /**
     * zap.
     *
     * @param appDirName the app dir name
     * @param userId the user id
     * @return the response
     */

    @SuppressWarnings({ "unchecked" })
    @GET
    @Path(REST_API_ZAP)
    @Produces(MediaType.APPLICATION_JSON)
    public Response zap(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_QUERY_MODULE_NAME) String module) {
        ResponseInfo<List<JSONObject>> finalOutput = null;
        JSONObject jsonObject = null;
        ResponseInfo<List<JSONObject>> responseData = new ResponseInfo<List<JSONObject>>();
        try {
            String rootModulePath = "";
            String subModuleName = "";
            if (StringUtils.isNotEmpty(module)) {
                rootModulePath = Utility.getProjectHome() + appDirName;
                subModuleName = module;
            } else {
                rootModulePath = Utility.getProjectHome() + appDirName;
            }

            File pomFileLocation = Utility.getPomFileLocation(rootModulePath, subModuleName);
            String baseDir = pomFileLocation.getParent();
            File reportPath = new File(baseDir + File.separator + DO_NOT_CHECKIN_DIR + File.separator + TARGET
                    + File.separator + ZAP_REPORT + File.separator + REPORT_FILE);
            if (reportPath.exists()) {
                jsonObject = readReport(reportPath.getPath());
            } else {
                throw new PhrescoException(REPORT_ERROR);
            }
            finalOutput = responseDataEvaluation(responseData, null, jsonObject, RESPONSE_STATUS_SUCCESS,
                    PHRQ100003);
        } catch (PhrescoException e) {
            finalOutput = responseDataEvaluation(responseData, e, null, REPORT_ERROR, PHRQ110004);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        }
        return Response.ok(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
    }

    /**
     * zap- status.
     *
     * @param appDirName the app dir name
     * @param userId the user id
     * @return the response
     */

    @SuppressWarnings("unchecked")
    @GET
    @Path(REST_API_ZAP_STATUS)
    @Produces(MediaType.APPLICATION_JSON)
    public Response zapStatus(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_QUERY_MODULE_NAME) String module) {
        ResponseInfo<Boolean> finalOutput = null;
        ResponseInfo<Boolean> responseData = new ResponseInfo<Boolean>();
        StringBuffer url = new StringBuffer(64);
        String protocol = "";
        String host = "";
        String port = "";
        try {
            String rootModulePath = "";
            String subModuleName = "";
            if (StringUtils.isNotEmpty(module)) {
                rootModulePath = Utility.getProjectHome() + appDirName;
                subModuleName = module;
            } else {
                rootModulePath = Utility.getProjectHome() + appDirName;
            }

            File pomFileLocation = Utility.getPomFileLocation(rootModulePath, subModuleName);
            String baseDir = pomFileLocation.getParent();
            StringBuffer buffer = new StringBuffer();
            buffer.append(baseDir + File.separator);
            buffer.append(Constants.DOT_PHRESCO_FOLDER + File.separator);
            buffer.append(CONFIGURATION_INFO_FILE_NAME);
            ConfigReader reader = new ConfigReader(new File(buffer.toString()));

            File infoFile = new File(pomFileLocation.getParent() + File.separator + Constants.DOT_PHRESCO_FOLDER
                    + File.separator + Constants.ZAP_START_INFO_XML);
            MojoProcessor processor = new MojoProcessor(infoFile);
            com.photon.phresco.plugins.model.Mojos.Mojo.Configuration configuration = processor
                    .getConfiguration(Constants.PHASE_ZAP_START);
            Map<String, String> configs = MojoUtil.getAllValues(configuration);
            String environment = configs.get(ENVIRONMENT_NAME);
            if (StringUtils.isEmpty(environment)) {
                environment = reader.getDefaultEnvName();
            }
            List<com.photon.phresco.configuration.Configuration> configurationList = reader
                    .getConfigurations(environment, FrameworkConstants.SERVER);
            boolean urlExists = false;
            if (CollectionUtils.isNotEmpty(configurationList)) {
                com.photon.phresco.configuration.Configuration config = configurationList.get(0);
                Properties properties = config.getProperties();
                protocol = (String) properties.get(PROTOCOL);
                host = (String) properties.get(HOST);
                port = (String) properties.get(PORT);
                url.append(protocol);
                url.append(COLON_DOUBLE_SLASH);
                url.append(host);
                url.append(FrameworkConstants.COLON);
                url.append(port);
                urlExists = checkIfURLExists(url.toString());
            }
            if (urlExists) {
                finalOutput = responseDataEvaluation(responseData, null, ZAP_START_MSG, RESPONSE_STATUS_SUCCESS,
                        PHRQ110005);
            } else {
                finalOutput = responseDataEvaluation(responseData, null, ZAP_NOT_START_MSG, RESPONSE_STATUS_SUCCESS,
                        PHRQ110006);
            }
            return Response.ok(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        } catch (PhrescoException e) {
            finalOutput = responseDataEvaluation(responseData, e, ZAP_START_FAIL, REPORT_ERROR, PHRQ110006);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        } catch (ConfigurationException e) {
            finalOutput = responseDataEvaluation(responseData, e, ZAP_START_FAIL, REPORT_ERROR, PHRQ110006);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        }
    }

    public static boolean checkIfURLExists(String targetUrl) {
        HttpURLConnection httpUrlConn = null;
        try {
            httpUrlConn = (HttpURLConnection) new java.net.URL(targetUrl).openConnection();
            httpUrlConn.setRequestMethod(HEAD_REVISION);
            httpUrlConn.setConnectTimeout(30000);
            httpUrlConn.setReadTimeout(30000);
            return (httpUrlConn.getResponseCode() == HttpURLConnection.HTTP_OK);
        } catch (Exception e) {
            return false;
        } finally {
            httpUrlConn.disconnect();
        }
    }

    private static JSONObject readReport(String path) throws PhrescoException {
        BufferedReader br = null;
        JSONObject jsonObject = null;
        try {
            int PRETTY_PRINT_INDENT_FACTOR = 4;
            br = new BufferedReader(new FileReader(path));
            String line;
            StringBuilder sb = new StringBuilder();

            while ((line = br.readLine()) != null) {
                sb.append(line.trim());
            }
            org.json.JSONObject xmlJSONObj = org.json.XML.toJSONObject(sb.toString());
            String jsonString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);
            JSONParser parser = new JSONParser();
            jsonObject = (JSONObject) parser.parse(jsonString);
        } catch (JSONException je) {
            throw new PhrescoException(je);
        } catch (FileNotFoundException e) {
            throw new PhrescoException(e);
        } catch (IOException e) {
            throw new PhrescoException(e);
        } catch (ParseException je) {
            throw new PhrescoException(je);
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return jsonObject;
    }

    @GET
    @Path("techOptions")
    @Produces(MediaType.APPLICATION_JSON)
    public Response reportOptions(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_QUERY_MODULE_NAME) String module) {
        ResponseInfo<List<String>> responseData = new ResponseInfo<List<String>>();
        try {
            String rootModulePath = "";
            String subModuleName = "";
            if (StringUtils.isNotEmpty(module)) {
                rootModulePath = Utility.getProjectHome() + appDirName;
                subModuleName = module;
            } else {
                rootModulePath = Utility.getProjectHome() + appDirName;
            }

            List<String> unitReportOptions = getUnitReportOptions(rootModulePath, subModuleName);
            ResponseInfo<List<String>> finalOutput = responseDataEvaluation(responseData, null, unitReportOptions,
                    RESPONSE_STATUS_SUCCESS, PHRQ100001);
            return Response.ok(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        } catch (PhrescoException e) {
            ResponseInfo<List<String>> finalOutput = responseDataEvaluation(responseData, e, null,
                    RESPONSE_STATUS_ERROR, PHRQ110001);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        }
    }

    /**
     * Gets the test suites.
     *
     * @param appDirName the app dir name
     * @param testType the test type
     * @param techReport the tech report
     * @param moduleName the module name
     * @return the test suites
     * @throws PhrescoException the phresco exception
     */
    @GET
    @Path(REST_API_TEST_SUITES)
    @Produces(MediaType.APPLICATION_JSON)
    public Response getTestSuites(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_QUERY_TEST_TYPE) String testType,
            @QueryParam(REST_QUERY_TECH_REPORT) String techReport,
            @QueryParam(REST_QUERY_MODULE_NAME) String moduleName,
            @QueryParam(REST_QUERY_PROJECT_CODE) String projectCode, @QueryParam("deviceid") String deviceid)
            throws PhrescoException {
        ResponseInfo<List<TestSuite>> responseData = new ResponseInfo<List<TestSuite>>();

        try {
            if (StringUtils.isNotEmpty(projectCode)) {
                appDirName = projectCode + INTEGRATION_TEST;
            }
            String rootModulePath = "";
            String subModuleName = "";
            if (StringUtils.isNotEmpty(moduleName) && !testType.equals("integration")) {
                rootModulePath = Utility.getProjectHome() + appDirName;
                subModuleName = moduleName;
            } else {
                rootModulePath = Utility.getProjectHome() + appDirName;
            }
            // TO kill the Process
            //         String rootModule = appDirName;
            //         if (StringUtils.isNotEmpty(moduleName)) {
            //            appDirName = appDirName + File.separator + moduleName;
            //         }

            File pomFileLocation = Utility.getPomFileLocation(rootModulePath, subModuleName);
            if (pomFileLocation != null && pomFileLocation.exists()) {
                Utility.killProcess(pomFileLocation.getParent(), testType);
            }
            if (StringUtils.isNotEmpty(techReport)) {
                techReport = techReport.toLowerCase();
            }
            String testSuitePath = getTestSuitePath(appDirName, rootModulePath, subModuleName, testType,
                    techReport);
            String testCasePath = getTestCasePath(appDirName, rootModulePath, subModuleName, testType, techReport);

            List<TestSuite> testSuites = testSuites(appDirName, moduleName, testType, techReport, testSuitePath,
                    testCasePath, ALL, rootModulePath, subModuleName, deviceid);
            if (CollectionUtils.isEmpty(testSuites)) {
                ResponseInfo<Configuration> finalOuptut = responseDataEvaluation(responseData, null, testSuites,
                        RESPONSE_STATUS_SUCCESS, PHRQ000003);
                return Response.status(Status.OK).entity(finalOuptut).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
                        .build();
            }
            ResponseInfo<List<String>> finalOutput = responseDataEvaluation(responseData, null, testSuites,
                    RESPONSE_STATUS_SUCCESS, PHRQ000001);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        } catch (Exception e) {
            ResponseInfo<List<TestSuite>> finalOutput = responseDataEvaluation(responseData, e, null,
                    RESPONSE_STATUS_ERROR, PHRQ010002);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL_HEADER)
                    .build();
        }
    }

    /**
     * Test suites.
     *
     * @param appDirName the app dir name
     * @param moduleName the module name
     * @param testType the test type
     * @param module the module
     * @param techReport the tech report
     * @param testSuitePath the test suite path
     * @param testCasePath the test case path
     * @param testSuite the test suite
     * @return the list
     * @throws PhrescoException the phresco exception
     */
    private List<TestSuite> testSuites(String appDirName, String moduleName, String testType, String techReport,
            String testSuitePath, String testCasePath, String testSuite, String rootModulePath, String subModule,
            String deviceid) throws PhrescoException {
        setTestSuite(testSuite);
        List<TestSuite> allSuites = new ArrayList<TestSuite>();
        try {
            String mapKey = constructMapKey(appDirName, moduleName);
            String testSuitesMapKey = mapKey + testType + moduleName + techReport;
            String testResultPath = getTestResultPath(appDirName, rootModulePath, subModule, testType, techReport);
            File[] testResultFiles = getTestResultFiles(testResultPath, "");

            if (ArrayUtils.isEmpty(testResultFiles)) {
                return null;
            }
            getTestSuiteNames(appDirName, testType, moduleName, techReport, testResultPath, testSuitePath,
                    rootModulePath, subModule, deviceid);
            Map<String, List<NodeList>> testResultNameMap = testSuiteMap.get(testSuitesMapKey);
            if (MapUtils.isEmpty(testResultNameMap)) {
                return null;
            }

            List<NodeList> allTestNodes = new ArrayList<NodeList>();
            Set<String> keys = testResultNameMap.keySet();
            for (String key : keys) {
                List<NodeList> nodes = testResultNameMap.get(key);
                for (NodeList node : nodes) {
                    allTestNodes.add(node);
                }
            }
            int indexOf = 0;
            for (NodeList allTestResultNodeList : allTestNodes) {
                if (allTestResultNodeList.getLength() > 0) {
                    List<TestSuite> allTestSuites = getTestSuite(allTestResultNodeList);

                    if (CollectionUtils.isNotEmpty(allTestSuites)) {
                        for (TestSuite tstSuite : allTestSuites) {
                            // testsuite values are set before calling
                            // getTestCases value
                            setTestSuite(tstSuite.getName());
                            float tests = 0;
                            float failures = 0;
                            float errors = 0;
                            float success = 0;

                            boolean entryAvailable = false;
                            TestSuite suite = new TestSuite();

                            //To check for previous existance
                            if (CollectionUtils.isNotEmpty(allSuites)) {
                                int i = 0;
                                for (TestSuite allSuite : allSuites) {
                                    if (allSuite.getName().equals(tstSuite.getName())) {
                                        suite = allSuite;
                                        entryAvailable = true;
                                        indexOf = i;
                                        break;
                                    }
                                    i++;
                                }
                            }

                            if (entryAvailable) {
                                tests = Math.round(suite.getTotal()) + Math.round(tstSuite.getTests());
                                failures = Math.round(suite.getFailures()) + Math.round(tstSuite.getFailures());
                                errors = Math.round(suite.getErrors()) + Math.round(tstSuite.getErrors());
                            } else {
                                setNodeLength(Math.round(tstSuite.getTests()));
                                setSetFailureTestCases(Math.round(tstSuite.getFailures()));
                                setErrorTestCases(Math.round(tstSuite.getErrors()));

                                tests = Float.parseFloat(String.valueOf(getNodeLength()));
                                failures = Float.parseFloat(String.valueOf(getSetFailureTestCases()));
                                errors = Float.parseFloat(String.valueOf(getErrorTestCases()));
                            }

                            if (failures != 0 && errors == 0) {
                                if (failures > tests) {
                                    success = failures - tests;
                                } else {
                                    success = tests - failures;
                                }
                            } else if (failures == 0 && errors != 0) {
                                if (errors > tests) {
                                    success = errors - tests;
                                } else {
                                    success = tests - errors;
                                }
                            } else if (failures != 0 && errors != 0) {
                                float failTotal = (failures + errors);
                                if (failTotal > tests) {
                                    success = failTotal - tests;
                                } else {
                                    success = tests - failTotal;
                                }
                            } else {
                                success = tests;
                            }
                            suite.setName(tstSuite.getName());
                            suite.setSuccess(success);
                            suite.setErrors(errors);
                            suite.setFailures(failures);
                            suite.setTime(tstSuite.getTime());
                            suite.setTotal(tests);
                            suite.setTestCases(tstSuite.getTestCases());

                            if (entryAvailable) {
                                allSuites.remove(indexOf);
                                allSuites.add(indexOf, suite);
                            } else {
                                allSuites.add(suite);
                            }
                        }
                    }
                }
            }
        } catch (PhrescoException e) {
            throw new PhrescoException(e);
        }
        return allSuites;
    }

    private String constructMapKey(String appDirName, String moduleName) {
        String key = appDirName;
        if (StringUtils.isNotEmpty(moduleName)) {
            key = appDirName + moduleName;
        }
        return key;
    }

    /**
     * Gets the test reports.
     *
     * @param appDirName the app dir name
     * @param testType the test type
     * @param techReport the tech report
     * @param moduleName the module name
     * @param testSuite the test suite
     * @return the test reports
     * @throws PhrescoException the phresco exception
     */
    @GET
    @Path(REST_API_TEST_REPORTS)
    @Produces(MediaType.APPLICATION_JSON)
    public Response getTestReports(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_QUERY_TEST_TYPE) String testType,
            @QueryParam(REST_QUERY_TECH_REPORT) String techReport,
            @QueryParam(REST_QUERY_MODULE_NAME) String moduleName,
            @QueryParam(REST_QUERY_TEST_SUITE) String testSuite,
            @QueryParam(REST_QUERY_PROJECT_CODE) String projectCode, @QueryParam("deviceid") String deviceid)
            throws PhrescoException {
        String testSuitePath = "";
        String testCasePath = "";
        String testStepPath = "";
        try {
            if (StringUtils.isNotEmpty(projectCode)) {
                appDirName = projectCode + INTEGRATION_TEST;
            }
            String rootModule = appDirName;
            String rootModulePath = "";
            String subModuleName = "";
            if (StringUtils.isNotEmpty(moduleName)) {
                rootModulePath = Utility.getProjectHome() + appDirName;
                subModuleName = moduleName;
            } else {
                rootModulePath = Utility.getProjectHome() + appDirName;
            }
            if (StringUtils.isNotEmpty(techReport)) {
                techReport = techReport.toLowerCase();
            }
            testSuitePath = getTestSuitePath(appDirName, rootModulePath, subModuleName, testType, techReport);
            testCasePath = getTestCasePath(appDirName, rootModulePath, subModuleName, testType, techReport);
            testStepPath = getTestStepNodeName(appDirName, rootModulePath, subModuleName, testType, techReport);

            return testReport(rootModule, moduleName, testType, moduleName, techReport, testSuitePath, testCasePath,
                    testStepPath, testSuite, rootModulePath, subModuleName, deviceid);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PhrescoException(e);

        }
    }

    /**
     * Gets the functional test framework.
     *
     * @param appDirName the app dir name
     * @return the functional test framework
     */
    @GET
    @Path(REST_API_FUNCTIONAL_FRAMEWORK)
    @Produces(MediaType.APPLICATION_JSON)
    public Response getFunctionalTestFramework(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_QUERY_MODULE_NAME) String module) {
        ResponseInfo<Map<String, Object>> responseData = new ResponseInfo<Map<String, Object>>();
        try {
            //         if (StringUtils.isNotEmpty(module)) {
            //            appDirName = appDirName + File.separator + module;
            //         }

            String rootModulePath = "";
            String subModuleName = "";
            List<String> testResultFiles = new ArrayList<String>();
            List<String> testResult = new ArrayList<String>();
            if (StringUtils.isNotEmpty(module)) {
                rootModulePath = Utility.getProjectHome() + appDirName;
                subModuleName = module;
            } else {
                rootModulePath = Utility.getProjectHome() + appDirName;
            }
            Map<String, Object> map = new HashMap<String, Object>();
            String functionalTestFramework = FrameworkServiceUtil.getFunctionalTestFramework(rootModulePath,
                    subModuleName);
            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName);
            FunctionalFrameworkInfo functionalFrameworkInfo = projectInfo.getAppInfos().get(0)
                    .getFunctionalFrameworkInfo();
            if (functionalFrameworkInfo != null && StringUtils.isNotEmpty(functionalFrameworkInfo.getIframeUrl())) {
                int responseCode = 400;
                boolean connected = true;
                try {
                    java.net.URL url = new java.net.URL(functionalFrameworkInfo.getIframeUrl());
                    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                    responseCode = connection.getResponseCode();
                } catch (Exception e) {
                    connected = false;
                }
                if (connected && responseCode == 200) {
                    map.put(FUNCTIONAL_IFRAME_URL_ALIVE, true);
                    map.put(FUNCTIONAL_IFRAME_URL, functionalFrameworkInfo.getIframeUrl());
                } else {
                    map.put(FUNCTIONAL_IFRAME_URL_ALIVE, false);
                }
            }
            map.put(FUNCTIONAL_FRAMEWORK, functionalTestFramework);
            if (SELENIUM_GRID.equalsIgnoreCase(functionalTestFramework)) {
                HubConfiguration hubConfig = getHubConfiguration(rootModulePath, subModuleName);
                InetAddress ip = InetAddress.getLocalHost();
                if (hubConfig != null) {
                    String host = ip.getHostAddress();
                    int port = hubConfig.getPort();
                    boolean isConnectionAlive = Utility.isConnectionAlive(HTTP_PROTOCOL, host, port);
                    map.put(HUB_STATUS, isConnectionAlive);
                }
                NodeConfiguration nodeConfig = getNodeConfiguration(rootModulePath, subModuleName);
                if (nodeConfig != null) {
                    String host = ip.getHostAddress();
                    int port = nodeConfig.getConfiguration().getPort();
                    boolean isConnectionAlive = Utility.isConnectionAlive(HTTP_PROTOCOL, host, port);
                    map.put(NODE_STATUS, isConnectionAlive);
                }
            } else if (SELENIUM_APPIUM.equalsIgnoreCase(functionalTestFramework)) {
                Map<String, String> appiumConfig = getAppiumConfiguration(rootModulePath, subModuleName);
                String appiumHost = appiumConfig.get(HOST);
                int appiumPort = Integer.parseInt(appiumConfig.get(PORT));
                if (appiumHost != null) {
                    boolean isConnectionAlive = Utility.isConnectionAlive(HTTP_PROTOCOL, appiumHost, appiumPort);
                    map.put(APPIUM_STATUS, isConnectionAlive);
                }
            }
            MojoProcessor mojo = new MojoProcessor(
                    new File(FrameworkServiceUtil.getPhrescoPluginInfoFilePath(Constants.PHASE_FUNCTIONAL_TEST,
                            Constants.PHASE_FUNCTIONAL_TEST, rootModulePath, subModuleName)));
            List<String> testAgainsts = new ArrayList<String>();
            Parameter testAgainstParameter = mojo.getParameter(Constants.PHASE_FUNCTIONAL_TEST, REQ_TEST_AGAINST);
            if (testAgainstParameter != null && TYPE_LIST.equalsIgnoreCase(testAgainstParameter.getType())) {
                List<Value> values = testAgainstParameter.getPossibleValues().getValue();
                for (Value value : values) {
                    testAgainsts.add(value.getKey());
                }
            }
            boolean resutlAvailable = testResultAvailfunctional(rootModulePath, subModuleName, testAgainsts,
                    Constants.PHASE_FUNCTIONAL_TEST);
            boolean showDevice = Boolean.parseBoolean(getFunctionalTestShowDevice(rootModulePath, subModuleName));
            if (resutlAvailable) {
                testResultFiles = testResultFilesfunctional(rootModulePath, subModuleName, testAgainsts, showDevice,
                        Constants.PHASE_FUNCTIONAL_TEST);
                testResult = testResultfileTrim(testResultFiles);
            }

            map.put(TEST_AGAINSTS, testAgainsts);
            map.put(RESULT_AVAILABLE, resutlAvailable);
            map.put(TEST_RESULT_FILES, testResultFiles);
            map.put(SHOW_DEVICE, showDevice);
            map.put(TEST_RESULT, testResult);

            ResponseInfo<Map<String, Object>> finalOutput = responseDataEvaluation(responseData, null, map,
                    RESPONSE_STATUS_SUCCESS, PHRQ300001);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        } catch (Exception e) {
            ResponseInfo<Map<String, Object>> finalOutput = responseDataEvaluation(responseData, e, null,
                    PHRQ310001);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        }
    }

    /**
     * Gets the status of the Hub/Node/Appium
     * @param appDirName
     * @param fromPage
     * @return
     */
    @GET
    @Path("/connectionAliveCheck")
    @Produces(MediaType.APPLICATION_JSON)
    public Response connectionAliveCheck(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_QUERY_FROM_PAGE) String fromPage, @QueryParam(REST_QUERY_MODULE_NAME) String module) {
        boolean connection_status = false;
        try {
            //         if (StringUtils.isNotEmpty(module)) {
            //            appDirName = appDirName + File.separator + module;
            //         }
            String rootModulePath = "";
            String subModuleName = "";
            if (StringUtils.isNotEmpty(module)) {
                rootModulePath = Utility.getProjectHome() + appDirName;
                subModuleName = module;
            } else {
                rootModulePath = Utility.getProjectHome() + appDirName;
            }
            InetAddress ip = InetAddress.getLocalHost();
            if (HUB_STATUS.equals(fromPage)) {
                HubConfiguration hubConfig = getHubConfiguration(rootModulePath, subModuleName);
                if (hubConfig != null) {
                    String host = ip.getHostAddress();
                    int port = hubConfig.getPort();
                    connection_status = Utility.isConnectionAlive(HTTP_PROTOCOL, host, port);
                }
            } else if (NODE_STATUS.equals(fromPage)) {
                NodeConfiguration nodeConfig = getNodeConfiguration(rootModulePath, subModuleName);
                if (nodeConfig != null) {
                    String host = ip.getHostAddress();
                    int port = nodeConfig.getConfiguration().getPort();
                    connection_status = Utility.isConnectionAlive(HTTP_PROTOCOL, host, port);
                }
            } else if (APPIUM_STATUS.equals(fromPage)) {
                Map<String, String> appiumConfig = getAppiumConfiguration(rootModulePath, subModuleName);
                String appiumHost = appiumConfig.get(HOST);
                int appiumPort = Integer.parseInt(appiumConfig.get(PORT));
                if (appiumHost != null) {
                    connection_status = Utility.isConnectionAlive(HTTP_PROTOCOL, appiumHost, appiumPort);
                }
            }
        } catch (Exception e) {
            return Response.status(Status.OK).entity(null).header("Access-Control-Allow-Origin", "*").build();
        }

        return Response.status(Status.OK).entity(connection_status).header("Access-Control-Allow-Origin", "*")
                .build();
    }

    /**
     * Gets the hub configuration.
     *
     * @param appDirName the app dir name
     * @return the hub configuration
     * @throws PhrescoException the phresco exception
     */
    private HubConfiguration getHubConfiguration(String rootModulePath, String subModuleName)
            throws PhrescoException {
        BufferedReader reader = null;
        HubConfiguration hubConfig = null;
        try {
            String functionalTestDir = FrameworkServiceUtil.getFunctionalTestDir(rootModulePath, subModuleName);
            ProjectInfo info = Utility.getProjectInfo(rootModulePath, subModuleName);
            File testFolderLocation = Utility.getTestFolderLocation(info, rootModulePath, subModuleName);
            StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
            sb.append(functionalTestDir).append(File.separator).append(Constants.HUB_CONFIG_JSON);
            File hubConfigFile = new File(sb.toString());
            Gson gson = new Gson();
            reader = new BufferedReader(new FileReader(hubConfigFile));
            hubConfig = gson.fromJson(reader, HubConfiguration.class);
        } catch (PhrescoException e) {
            throw new PhrescoException(e);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        } catch (FileNotFoundException e) {
            throw new PhrescoException(e);
        } finally {
            Utility.closeReader(reader);
        }

        return hubConfig;
    }

    /**
     * Gets the node configuration.
     *
     * @param appDirName the app dir name
     * @return the node configuration
     * @throws PhrescoException the phresco exception
     */
    private NodeConfiguration getNodeConfiguration(String rootModulePath, String subModuleName)
            throws PhrescoException {
        BufferedReader reader = null;
        NodeConfiguration nodeConfig = null;
        try {
            String functionalTestDir = FrameworkServiceUtil.getFunctionalTestDir(rootModulePath, subModuleName);
            ProjectInfo info = Utility.getProjectInfo(rootModulePath, subModuleName);
            File testFolderLocation = Utility.getTestFolderLocation(info, rootModulePath, subModuleName);
            StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
            sb.append(functionalTestDir).append(File.separator).append(Constants.NODE_CONFIG_JSON);
            File nodeConfigFile = new File(sb.toString());
            Gson gson = new Gson();
            reader = new BufferedReader(new FileReader(nodeConfigFile));
            nodeConfig = gson.fromJson(reader, NodeConfiguration.class);
        } catch (PhrescoException e) {
            throw new PhrescoException(e);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        } catch (FileNotFoundException e) {
            throw new PhrescoException(e);
        } finally {
            Utility.closeReader(reader);
        }

        return nodeConfig;
    }

    /**
     * Gets the appium configuration.
     *
     * @param rootModulePath the root module path
     * @param subModuleName the sub module name
     * @return the appium configuration map
     * @throws PhrescoException the phresco exception
     */
    private Map<String, String> getAppiumConfiguration(String rootModulePath, String subModuleName)
            throws PhrescoException {
        Map<String, String> appiumConfiguration = new HashMap<String, String>();
        String dotPhrescoParent = rootModulePath;
        if (StringUtils.isNotEmpty(subModuleName)) {
            dotPhrescoParent = dotPhrescoParent + File.separatorChar + subModuleName;
        }
        File phrescoEnvConfig = new File(dotPhrescoParent + File.separatorChar + FOLDER_DOT_PHRESCO
                + File.separatorChar + PHRESCO_ENV_CONFIG_FILE_NAME);
        try {
            ConfigReader configReader = new ConfigReader(phrescoEnvConfig);
            String environment = configReader.getDefaultEnvName();
            Configuration config = configReader.getConfigurations(environment, APPIUM).get(0);
            appiumConfiguration.put(HOST, config.getProperties().getProperty(HOST));
            appiumConfiguration.put(PORT, config.getProperties().getProperty(PORT));
        } catch (ConfigurationException e) {
            throw new PhrescoException(e);
        }
        return appiumConfiguration;
    }

    /**
     * Gets the test case path.
     *
     * @param appDirName the app dir name
     * @param testType the test type
     * @param techReport the tech report
     * @return the test case path
     * @throws PhrescoException the phresco exception
     */
    private String getTestCasePath(String appDirName, String rootModulePath, String subModule, String testType,
            String techReport) throws PhrescoException {
        String testCasePath = "";
        if (testType.equals(UNIT)) {
            if (StringUtils.isNotEmpty(techReport)) {
                testCasePath = getUnitTestCasePath(rootModulePath, subModule, techReport);
            } else {
                testCasePath = getUnitTestCasePath(rootModulePath, subModule);
            }
        } else if (testType.equals(FUNCTIONAL)) {
            testCasePath = getFunctionalTestCasePath(rootModulePath, subModule);
        } else if (testType.equals(COMPONENT)) {
            testCasePath = getComponentTestCasePath(rootModulePath, subModule);
        } else if (testType.equals(INTEGRATION)) {
            testCasePath = getIntegrationTestCasePath(appDirName);
        } else if (testType.equals(SEO_TYPE)) {
            testCasePath = getseoTestCasePath(rootModulePath, subModule);
        }
        return testCasePath;
    }

    /**
     * Gets the test step path.
     *
     * @param appDirName the app dir name
     * @param testType the test type
     * @param techReport the tech report
     * @return the test case path
     * @throws PhrescoException the phresco exception
     */
    private String getTestStepNodeName(String appDirName, String rootModulePath, String subModule, String testType,
            String techReport) throws PhrescoException {
        String testStepNodeName = "";
        if (testType.equals(UNIT)) {
            if (StringUtils.isNotEmpty(techReport)) {
                testStepNodeName = getUnitTestStepNodeName(rootModulePath, subModule, techReport);
            } else {
                testStepNodeName = getUnitTestStepNodeName(rootModulePath, subModule);
            }
        } else if (testType.equals(FUNCTIONAL)) {
            testStepNodeName = getFunctionalTestStepNodeName(rootModulePath, subModule);
        }
        return testStepNodeName;
    }

    /**
     * Test report.
     *
     * @param appDirName the app dir name
     * @param moduleName the module name
     * @param testType the test type
     * @param module the module
     * @param techReport the tech report
     * @param testSuitePath the test suite path
     * @param testCasePath the test case path
     * @param testSuite the test suite
     * @return the response
     * @throws PhrescoException the phresco exception
     */
    private Response testReport(String appDirName, String moduleName, String testType, String module,
            String techReport, String testSuitePath, String testCasePath, String testStepPath, String testSuite,
            String rootModulePath, String subModule, String deviceid) throws PhrescoException {
        setTestSuite(testSuite);
        ResponseInfo<TestReportResult> responseDataAll = new ResponseInfo<TestReportResult>();
        ResponseInfo<List<TestCase>> responseData = new ResponseInfo<List<TestCase>>();
        try {
            String mapKey = constructMapKey(appDirName, moduleName);
            String testSuitesMapKey = mapKey + testType + module + techReport;
            if (MapUtils.isEmpty(testSuiteMap)) {
                String testResultPath = getTestResultPath(appDirName, rootModulePath, subModule, testType,
                        techReport);
                getTestSuiteNames(appDirName, testType, moduleName, techReport, testResultPath, testSuitePath,
                        rootModulePath, subModule, deviceid);
            }
            Map<String, List<NodeList>> testResultNameMap = testSuiteMap.get(testSuitesMapKey);
            List<NodeList> testSuitesList = testResultNameMap.get(testSuite);

            if (CollectionUtils.isNotEmpty(testSuitesList) && testSuitesList.size() > 0) {
                List<TestCase> testCases;
                testCases = getTestCases(rootModulePath, subModule, testSuitesList, testSuitePath, testCasePath,
                        testStepPath, testType);
                if (CollectionUtils.isEmpty(testCases)) {
                    ResponseInfo<List<TestCase>> finalOutput = responseDataEvaluation(responseData, null, testCases,
                            RESPONSE_STATUS_SUCCESS, PHRQ000004);
                    return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
                            .build();
                } else {
                    boolean isClassEmpty = false;
                    // to check whether class attribute is there or not
                    for (TestCase testCase : testCases) {
                        if (testCase.getTestClass() == null) {
                            isClassEmpty = true;
                        }
                    }
                    ResponseInfo<List<TestCase>> finalOutput = responseDataEvaluation(responseData, null, testCases,
                            RESPONSE_STATUS_SUCCESS, PHRQ000002);
                    return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
                            .build();
                }
            }
        } catch (PhrescoException e) {
            ResponseInfo<List<TestCase>> finalOutput = responseDataEvaluation(responseData, e, null,
                    RESPONSE_STATUS_ERROR, PHRQ010004);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL_HEADER)
                    .build();
        }

        ResponseInfo<List<TestCase>> finalOutput = responseDataEvaluation(responseData, null, null,
                RESPONSE_STATUS_SUCCESS, PHRQ000004);
        return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
    }

    /**
     * Creates the test report result.
     *
     * @param testSuitesResultMap the test suites result map
     * @param result the result
     */
    private void createTestReportResult(Map<String, String> testSuitesResultMap, TestReportResult result) {
        Set<String> keySet = testSuitesResultMap.keySet();
        int totalValue = keySet.size();
        // All testSuite total colum value calculation
        int totalTstCases = 0;
        int totalSuccessTstCases = 0;
        int totalFailureTstCases = 0;
        int totalErrorTstCases = 0;

        for (String key : keySet) {
            String csvResults = testSuitesResultMap.get(key);
            String[] results = csvResults.split(Constants.COMMA);
            float total = Float.parseFloat(results[0]);
            float success = Float.parseFloat(results[1]);
            float failure = Float.parseFloat(results[2]);
            float error = Float.parseFloat(results[3]);
            totalTstCases = totalTstCases + (int) total;
            totalSuccessTstCases = totalSuccessTstCases + (int) success;
            totalFailureTstCases = totalFailureTstCases + (int) failure;
            totalErrorTstCases = totalErrorTstCases + (int) error;
        }
        result.setTotalTestError(totalErrorTstCases);
        result.setTotalTestFailure(totalFailureTstCases);
        result.setTotalTestSuccess(totalSuccessTstCases);
        result.setTotalTestResults(totalValue);
    }

    /**
     * Gets the test cases.
     *
     * @param appDirName the app dir name
     * @param testSuites the test suites
     * @param testSuitePath the test suite path
     * @param testCasePath the test case path
     * @return the test cases
     * @throws PhrescoException the phresco exception
     */
    private List<TestCase> getTestCases(String rootModulePath, String subModule, List<NodeList> testSuites,
            String testSuitePath, String testCasePath, String testStepPath, String testType)
            throws PhrescoException {
        InputStream fileInputStream = null;
        StringBuilder screenShotDir = new StringBuilder();
        try {
            List<TestCase> testCases = new ArrayList<TestCase>();
            for (NodeList testSuite : testSuites) {
                StringBuilder testCaseBuilder = new StringBuilder();
                testCaseBuilder.append(testSuitePath);
                testCaseBuilder.append(NAME_FILTER_PREFIX);
                testCaseBuilder.append(getTestSuite());
                testCaseBuilder.append(NAME_FILTER_SUFIX);
                testCaseBuilder.append(testCasePath);
                XPath xpath = XPathFactory.newInstance().newXPath();
                NodeList nodeList = (NodeList) xpath.evaluate(testCaseBuilder.toString(),
                        testSuite.item(0).getParentNode(), XPathConstants.NODESET);
                // For tehnologies like php and drupal duoe to plugin change xml
                // testcase path modified
                if (nodeList.getLength() == 0) {
                    StringBuilder sbMulti = new StringBuilder();
                    sbMulti.append(testSuitePath);
                    sbMulti.append(NAME_FILTER_PREFIX);
                    sbMulti.append(getTestSuite());
                    sbMulti.append(NAME_FILTER_SUFIX);
                    sbMulti.append(XPATH_TESTSUTE_TESTCASE);
                    nodeList = (NodeList) xpath.evaluate(sbMulti.toString(), testSuite.item(0).getParentNode(),
                            XPathConstants.NODESET);
                }

                // For technology sharepoint
                if (nodeList.getLength() == 0) {
                    StringBuilder sbMulti = new StringBuilder();
                    sbMulti.append(XPATH_MULTIPLE_TESTSUITE);
                    sbMulti.append(NAME_FILTER_PREFIX);
                    sbMulti.append(getTestSuite());
                    sbMulti.append(NAME_FILTER_SUFIX);
                    sbMulti.append(testCasePath);
                    nodeList = (NodeList) xpath.evaluate(sbMulti.toString(), testSuite.item(0).getParentNode(),
                            XPathConstants.NODESET);
                }

                if (testType.equals(FUNCTIONAL)) {
                    screenShotDir = screenShotDir(rootModulePath, subModule);
                }
                int failureTestCases = 0;
                int errorTestCases = 0;
                for (int i = 0; i < nodeList.getLength(); i++) {
                    Node node = nodeList.item(i);
                    NodeList childNodes = node.getChildNodes();
                    NamedNodeMap nameNodeMap = node.getAttributes();
                    TestCase testCase = new TestCase();
                    List<TestStep> testSteps = new ArrayList<TestStep>();
                    for (int k = 0; k < nameNodeMap.getLength(); k++) {
                        Node attribute = nameNodeMap.item(k);
                        String attributeName = attribute.getNodeName();
                        String attributeValue = attribute.getNodeValue();
                        if (ATTR_NAME.equals(attributeName)) {
                            testCase.setName(attributeValue);
                        } else if (ATTR_CLASS.equals(attributeName) || ATTR_CLASSNAME.equals(attributeName)) {
                            testCase.setTestClass(attributeValue);
                        } else if (ATTR_FILE.equals(attributeName)) {
                            testCase.setFile(attributeValue);
                        } else if (ATTR_LINE.equals(attributeName)) {
                            testCase.setLine(Float.parseFloat(attributeValue));
                        } else if (ATTR_ASSERTIONS.equals(attributeName)) {
                            testCase.setAssertions(Float.parseFloat(attributeValue));
                        } else if (ATTR_TIME.equals(attributeName)) {
                            testCase.setTime(attributeValue);
                        }
                    }

                    if (childNodes != null && childNodes.getLength() > 0) {
                        for (int j = 0; j < childNodes.getLength(); j++) {
                            Node childNode = childNodes.item(j);
                            if (ELEMENT_FAILURE.equals(childNode.getNodeName())) {
                                failureTestCases++;
                                TestCaseFailure failure = getFailure(childNode);
                                if (failure != null) {
                                    File file = new File(screenShotDir.toString() + testCase.getName()
                                            + FrameworkConstants.DOT + IMG_PNG_TYPE);
                                    if (file.exists()) {
                                        failure.setHasFailureImg(true);
                                        fileInputStream = new FileInputStream(file);
                                        if (fileInputStream != null) {
                                            byte[] imgByte = null;
                                            imgByte = IOUtils.toByteArray(fileInputStream);
                                            byte[] encodedImage = Base64.encodeBase64(imgByte);
                                            failure.setScreenshotPath(new String(encodedImage));
                                        }
                                    }
                                    testCase.setTestCaseFailure(failure);
                                }
                            }

                            if (ELEMENT_ERROR.equals(childNode.getNodeName())) {
                                errorTestCases++;
                                TestCaseError error = getError(childNode);
                                if (error != null) {
                                    File file = new File(screenShotDir.toString() + testCase.getName()
                                            + FrameworkConstants.DOT + IMG_PNG_TYPE);
                                    if (file.exists()) {
                                        error.setHasErrorImg(true);
                                        fileInputStream = new FileInputStream(file);
                                        if (fileInputStream != null) {
                                            byte[] imgByte = null;
                                            imgByte = IOUtils.toByteArray(fileInputStream);
                                            byte[] encodedImage = Base64.encodeBase64(imgByte);
                                            error.setScreenshotPath(new String(encodedImage));
                                        }
                                    }
                                    testCase.setTestCaseError(error);
                                }
                            }

                            //To Calculate teststep if it present
                            if (StringUtils.isNotEmpty(testStepPath)
                                    && testStepPath.equalsIgnoreCase(childNode.getNodeName())) {
                                TestStep testStep = new TestStep();
                                Node testStepNode = childNode;
                                NamedNodeMap testStepAttributes = testStepNode.getAttributes();
                                if (testStepAttributes != null && testStepAttributes.getLength() > 0) {
                                    for (int k = 0; k < testStepAttributes.getLength(); k++) {
                                        Node attribute = testStepAttributes.item(k);
                                        String attributeName = attribute.getNodeName();
                                        String attributeValue = attribute.getNodeValue();
                                        if (ATTR_NAME.equals(attributeName)) {
                                            testStep.setName(attributeValue);
                                        } else if (ATTR_ACTION.equals(attributeName)) {
                                            testStep.setAction(attributeValue);
                                        } else if (ATTR_TIME.equals(attributeName)) {
                                            testStep.setTime(attributeValue);
                                        }
                                    }
                                    NodeList testStepChilds = testStepNode.getChildNodes();
                                    if (testStepChilds != null && testStepChilds.getLength() > 0) {
                                        for (int z = 0; z < testStepChilds.getLength(); z++) {
                                            Node testStepChildNode = testStepChilds.item(z);
                                            constructTestStepFailure(testCase, testStep, testStepChildNode);
                                            constructTestStepError(testCase, testStep, testStepChildNode);
                                        }
                                    }
                                    testSteps.add(testStep);
                                    testCase.setTestSteps(testSteps);
                                }
                            }
                        }
                    }
                    testCases.add(testCase);
                }
                setSetFailureTestCases(failureTestCases);
                setErrorTestCases(errorTestCases);
                setNodeLength(nodeList.getLength());
                //
            }
            return testCases;
        } catch (PhrescoException e) {
            throw e;
        } catch (XPathExpressionException e) {
            throw new PhrescoException(e);
        } catch (IOException e) {
            throw new PhrescoException(e);
        } finally {
            try {
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
            } catch (IOException e) {

            }
        }
    }

    private void constructTestStepError(TestCase testCase, TestStep testStep, Node testStepChildNode)
            throws PhrescoException {
        try {
            if (ELEMENT_ERROR.equals(testStepChildNode.getNodeName())) {
                TestStepError testStepError = getTestStepError(testStepChildNode);
                testStep.setTestStepError(testStepError);
            }
        } catch (Exception e) {
            throw new PhrescoException(e);
        }
    }

    private void constructTestStepFailure(TestCase testCase, TestStep testStep, Node testStepChildNode)
            throws PhrescoException {
        try {
            if (ELEMENT_FAILURE.equals(testStepChildNode.getNodeName())) {
                TestStepFailure testStepFailure = getTestStepFailure(testStepChildNode);
                testStep.setTestStepFailure(testStepFailure);
            }
        } catch (Exception e) {
            throw new PhrescoException(e);
        }
    }

    private StringBuilder screenShotDir(String rootModulePath, String subModule) throws PhrescoException {
        StringBuilder screenShotDir = new StringBuilder();
        ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModule);
        File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModule);
        String sceenShotDir = getSceenShotDir(rootModulePath, subModule);
        if (StringUtils.isEmpty(sceenShotDir)) {
            String functionalTestReportDir = getFunctionalTestReportDir(rootModulePath, subModule);
            if (functionalTestReportDir.contains(PROJECT_BASEDIR)) {
                functionalTestReportDir = functionalTestReportDir.replace(PROJECT_BASEDIR,
                        testFolderLocation.toString());
                screenShotDir.append(functionalTestReportDir);
            } else {
                screenShotDir.append(testFolderLocation.toString());
            }
            screenShotDir.append(File.separator);
            screenShotDir.append(SCREENSHOT_DIR);
        } else {
            screenShotDir.append(testFolderLocation.toString());
            screenShotDir.append(File.separator);
            screenShotDir.append(sceenShotDir);
        }
        screenShotDir.append(File.separator);
        return screenShotDir;
    }

    /**
     * Gets the failure.
     *
     * @param failureNode the failure node
     * @return the failure
     */
    private static TestCaseFailure getFailure(Node failureNode) {
        TestCaseFailure failure = new TestCaseFailure();
        failure.setDescription(failureNode.getTextContent());
        failure.setFailureType(REQ_TITLE_EXCEPTION);
        NamedNodeMap nameNodeMap = failureNode.getAttributes();

        if (nameNodeMap != null && nameNodeMap.getLength() > 0) {
            for (int k = 0; k < nameNodeMap.getLength(); k++) {
                Node attribute = nameNodeMap.item(k);
                String attributeName = attribute.getNodeName();
                String attributeValue = attribute.getNodeValue();

                if (ATTR_TYPE.equals(attributeName)) {
                    failure.setFailureType(attributeValue);
                }
            }
        }
        return failure;
    }

    /**
     * Gets the test step failure.
     *
     * @param failureNode the failure node
     * @return the failure
     */
    private static TestStepFailure getTestStepFailure(Node failureNode) {
        TestStepFailure failure = new TestStepFailure();
        failure.setDescription(failureNode.getTextContent());
        failure.setFailureType(REQ_TITLE_EXCEPTION);
        NamedNodeMap nameNodeMap = failureNode.getAttributes();

        if (nameNodeMap != null && nameNodeMap.getLength() > 0) {
            for (int k = 0; k < nameNodeMap.getLength(); k++) {
                Node attribute = nameNodeMap.item(k);
                String attributeName = attribute.getNodeName();
                String attributeValue = attribute.getNodeValue();

                if (ATTR_TYPE.equals(attributeName)) {
                    failure.setFailureType(attributeValue);
                } else if (ATTR_SCREENSHOT.equals(attributeName) && StringUtils.isNotEmpty(attributeValue)) {
                    failure.setScreenshotUrl(attributeValue);
                    failure.setHasFailureImg(true);
                }
            }
        }
        return failure;
    }

    /**
     * Gets the error.
     *
     * @param errorNode the error node
     * @return the error
     */
    private static TestCaseError getError(Node errorNode) {
        TestCaseError tcError = new TestCaseError();
        tcError.setDescription(errorNode.getTextContent());
        tcError.setErrorType(REQ_TITLE_ERROR);
        NamedNodeMap nameNodeMap = errorNode.getAttributes();
        if (nameNodeMap != null && nameNodeMap.getLength() > 0) {
            for (int k = 0; k < nameNodeMap.getLength(); k++) {
                Node attribute = nameNodeMap.item(k);
                String attributeName = attribute.getNodeName();
                String attributeValue = attribute.getNodeValue();

                if (ATTR_TYPE.equals(attributeName)) {
                    tcError.setErrorType(attributeValue);
                }
            }
        }
        return tcError;
    }

    /**
     * Gets the test step error.
     *
     * @param errorNode the error node
     * @return the error
     */
    private static TestStepError getTestStepError(Node errorNode) {
        TestStepError tsError = new TestStepError();
        tsError.setDescription(errorNode.getTextContent());
        tsError.setErrorType(REQ_TITLE_ERROR);
        NamedNodeMap nameNodeMap = errorNode.getAttributes();
        if (nameNodeMap != null && nameNodeMap.getLength() > 0) {
            for (int k = 0; k < nameNodeMap.getLength(); k++) {
                Node attribute = nameNodeMap.item(k);
                String attributeName = attribute.getNodeName();
                String attributeValue = attribute.getNodeValue();

                if (ATTR_TYPE.equals(attributeName)) {
                    tsError.setErrorType(attributeValue);
                }
            }
        }
        return tsError;
    }

    /**
     * Gets the unit report options.
     *
     * @param appDirName the app dir name
     * @return the unit report options
     * @throws PhrescoException the phresco exception
     */
    private List<String> getUnitReportOptions(String rootModulePath, String subModule) throws PhrescoException {
        try {
            String unitTestReportOptions = getUnitTestReportOptions(rootModulePath, subModule);
            if (StringUtils.isNotEmpty(unitTestReportOptions)) {
                return Arrays.asList(unitTestReportOptions.split(Constants.COMMA));
            }
        } catch (Exception e) {
            throw new PhrescoException(e);
        }
        return null;
    }

    /**
     * Gets the test result path.
     *
     * @param appDirName the app dir name
     * @param moduleName the module name
     * @param testType the test type
     * @param techReport the tech report
     * @return the test result path
     * @throws PhrescoException the phresco exception
     */
    private String getTestResultPath(String appDirName, String rootModulePath, String subModule, String testType,
            String techReport) throws PhrescoException {
        //      if(StringUtils.isNotEmpty(moduleName)) {
        //         appDirName = appDirName + File.separator + moduleName; 
        //      }
        String testResultPath = "";
        if (testType.equals(UNIT)) {
            testResultPath = getUnitTestResultPath(rootModulePath, subModule, techReport);
        } else if (testType.equals(FUNCTIONAL)) {
            testResultPath = getFunctionalTestResultPath(rootModulePath, subModule);
        } else if (testType.equals(COMPONENT)) {
            testResultPath = getComponentTestResultPath(rootModulePath, subModule);
        } else if (testType.equals(INTEGRATION)) {
            testResultPath = getIntegraionTestResultPath(appDirName);
        } else if (testType.equals(SEO_TYPE)) {
            testResultPath = getseoTestResultPath(rootModulePath, subModule);
        }
        return testResultPath;
    }

    /**
     * Gets the test suite path.
     *
     * @param appDirName the app dir name
     * @param testType the test type
     * @param techReport the tech report
     * @return the test suite path
     * @throws PhrescoException the phresco exception
     */
    private String getTestSuitePath(String appDirName, String rootModulePath, String subModule, String testType,
            String techReport) throws PhrescoException {
        String testSuitePath = "";
        if (testType.equals(UNIT)) {
            if (StringUtils.isNotEmpty(techReport)) {
                testSuitePath = getUnitTestSuitePath(rootModulePath, subModule, techReport);
            } else {
                testSuitePath = getUnitTestSuitePath(rootModulePath, subModule);
            }
        } else if (testType.equals(COMPONENT)) {
            testSuitePath = getComponentTestSuitePath(rootModulePath, subModule);
        } else if (testType.equals(FUNCTIONAL)) {
            testSuitePath = getFunctionalTestSuitePath(rootModulePath, subModule);
        } else if (testType.equals(INTEGRATION)) {
            testSuitePath = getIntegrationTestSuitePath(appDirName);
        } else if (testType.equals(SEO_TYPE)) {
            testSuitePath = getseoTestSuitePath(rootModulePath, subModule);
        }
        return testSuitePath;
    }

    /**
     * Gets the unit test result path.
     *
     * @param appDirName the app dir name
     * @param moduleName the module name
     * @param techReport the tech report
     * @return the unit test result path
     * @throws PhrescoException the phresco exception
     */
    private String getUnitTestResultPath(String rootModulePath, String subModule, String techReport)
            throws PhrescoException {
        File pomFile = Utility.getPomFileLocation(rootModulePath, subModule);
        StringBuilder sb = new StringBuilder(pomFile.getParent());
        // TODO Need to change this
        StringBuilder tempsb = new StringBuilder(pomFile.getParent());
        if (FrameworkConstants.JAVASCRIPT.equals(techReport)) {
            tempsb.append(FrameworkConstants.UNIT_TEST_QUNIT_REPORT_DIR);
            File file = new File(tempsb.toString());
            if (file.isDirectory() && file.list().length > 0) {
                sb.append(FrameworkConstants.UNIT_TEST_QUNIT_REPORT_DIR);
            } else {
                sb.append(FrameworkConstants.UNIT_TEST_JASMINE_REPORT_DIR);
            }
        } else {
            if (StringUtils.isNotEmpty(techReport)) {
                sb.append(getUnitTestReportDir(rootModulePath, subModule, techReport));
            } else {
                sb.append(getUnitTestReportDir(rootModulePath, subModule));
            }
        }
        return sb.toString();
    }

    /**
     * Gets the functional test result path.
     *
     * @param appDirName the app dir name
     * @param moduleName the module name
     * @return the functional test result path
     * @throws PhrescoException the phresco exception
     */
    private String getFunctionalTestResultPath(String rootModulePath, String subModule) throws PhrescoException {

        StringBuilder sb = new StringBuilder();
        try {
            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModule);
            File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModule);
            String functionalTestReportDir = getFunctionalTestReportDir(rootModulePath, subModule);
            if (functionalTestReportDir.contains(PROJECT_BASEDIR)) {
                functionalTestReportDir = functionalTestReportDir.replace(PROJECT_BASEDIR,
                        testFolderLocation.getPath());
            }
            sb.append(functionalTestReportDir);
        } catch (PhrescoException e) {
            throw new PhrescoException(e);
        }

        return sb.toString();
    }

    /**
     * Gets the seo test result path.
     *
     * @param appDirName the app dir name
     * @param moduleName the module name
     * @return the functional test result path
     * @throws PhrescoException the phresco exception
     */
    private String getseoTestResultPath(String rootModulePath, String subModule) throws PhrescoException {

        StringBuilder sb = new StringBuilder();
        try {
            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModule);
            File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModule);
            String seoTestReportDir = getseoTestReportDir(rootModulePath, subModule);
            if (seoTestReportDir.contains(PROJECT_BASEDIR)) {
                seoTestReportDir = seoTestReportDir.replace(PROJECT_BASEDIR, testFolderLocation.getPath());
            }
            sb.append(seoTestReportDir);
        } catch (PhrescoException e) {
            throw new PhrescoException(e);
        }

        return sb.toString();
    }

    private String getIntegraionTestResultPath(String appDirName) throws PhrescoException {

        StringBuilder sb = new StringBuilder();
        try {
            sb.append(Utility.getProjectHome() + appDirName);
            sb.append(getIntegrationTestReportDir(appDirName));
        } catch (PhrescoException e) {
            throw new PhrescoException(e);
        }

        return sb.toString();
    }

    /**
     * Gets the component test result path.
     *
     * @param appDirName the app dir name
     * @param moduleName the module name
     * @return the component test result path
     * @throws PhrescoException the phresco exception
     */
    private String getComponentTestResultPath(String rootModulePath, String subModule) throws PhrescoException {

        StringBuilder sb = new StringBuilder();
        try {
            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModule);
            File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModule);
            sb.append(testFolderLocation.toString());
            sb.append(getComponentTestReportDir(rootModulePath, subModule));
        } catch (PhrescoException e) {
            throw new PhrescoException(e);
        }

        return sb.toString();
    }

    /**
     * Gets the test suite names.
     *
     * @param appDirName the app dir name
     * @param testType the test type
     * @param moduleName the module name
     * @param techReport the tech report
     * @param testResultPath the test result path
     * @param testSuitePath the test suite path
     * @return the test suite names
     * @throws PhrescoException the phresco exception
     * @throws PhrescoPomException 
     *  
     */
    private List<String> getTestSuiteNames(String appDirName, String testType, String moduleName, String techReport,
            String testResultPath, String testSuitePath, String rootModulePath, String subModule, String deviceid)
            throws PhrescoException {
        File[] resultFiles = null;
        String name = "";
        String mapKey = constructMapKey(appDirName, moduleName);
        String testSuitesMapKey = mapKey + testType + moduleName + techReport;
        Map<String, List<NodeList>> testResultNameMap = testSuiteMap.get(testSuitesMapKey);
        List<String> resultTestSuiteNames = null;
        if (StringUtils.isNotEmpty(deviceid)) {
            name = "TEST-" + deviceid;
        }
        resultFiles = getTestResultFiles(testResultPath, name);
        if (!ArrayUtils.isEmpty(resultFiles)) {
            QualityUtil.sortResultFile(resultFiles);
            updateCache(appDirName, testType, moduleName, techReport, resultFiles, testSuitePath);
        }
        testResultNameMap = testSuiteMap.get(testSuitesMapKey);
        //}
        if (testResultNameMap != null) {
            resultTestSuiteNames = new ArrayList<String>(testResultNameMap.keySet());
        }

        return resultTestSuiteNames;
    }

    /**
     * Gets the unit test report dir.
     *
     * @param appDirName the app dir name
     * @param option the option
     * @return the unit test report dir
     * @throws PhrescoException the phresco exception
     */
    private String getUnitTestReportDir(String rootModulePath, String subModule, String option)
            throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_UNITTEST_RPT_DIR_START + option
                            + Constants.POM_PROP_KEY_UNITTEST_RPT_DIR_END);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the unit test report dir.
     *
     * @param appDirName the app dir name
     * @return the unit test report dir
     * @throws PhrescoException the phresco exception
     */
    public String getUnitTestReportDir(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_UNITTEST_RPT_DIR);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the unit test suite path.
     *
     * @param appDirName the app dir name
     * @param option the option
     * @return the unit test suite path
     * @throws PhrescoException the phresco exception
     */
    public String getUnitTestSuitePath(String rootModulePath, String subModule, String option)
            throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_UNITTEST_TESTSUITE_XPATH_START + option
                            + Constants.POM_PROP_KEY_UNITTEST_TESTSUITE_XPATH_END);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the unit test suite path.
     *
     * @param appDirName the app dir name
     * @return the unit test suite path
     * @throws PhrescoException the phresco exception
     */
    public String getUnitTestSuitePath(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_UNITTEST_TESTSUITE_XPATH);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    public String getIntegrationTestReportDir(String appDirName) throws PhrescoException {
        try {
            return FrameworkUtil.getInstance().getPomProcessorForIntegration(appDirName)
                    .getProperty(Constants.POM_PROP_KEY_INTGRATIONTEST_RPT_DIR);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the Integration test suite path.
     *
     * @param appDirName the app dir name
     * @return the unit test suite path
     * @throws PhrescoException the phresco exception
     */
    public String getIntegrationTestSuitePath(String appDirName) throws PhrescoException {
        try {
            return FrameworkUtil.getInstance().getPomProcessorForIntegration(appDirName)
                    .getProperty(Constants.POM_PROP_KEY_INTEGRATIONTEST_TESTSUITE_XPATH);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Update cache.
     *
     * @param appDirName the app dir name
     * @param testType the test type
     * @param moduleName the module name
     * @param techReport the tech report
     * @param resultFiles the result files
     * @param testSuitePath the test suite path
     * @throws PhrescoException the phresco exception
     */
    private void updateCache(String appDirName, String testType, String moduleName, String techReport,
            File[] resultFiles, String testSuitePath) throws PhrescoException {
        Map<String, List<NodeList>> multiNodeMap = new HashMap<String, List<NodeList>>(10);
        for (File resultFile : resultFiles) {
            Document doc = getDocument(resultFile);
            NodeList testSuiteNodeList = evaluateTestSuite(doc, testSuitePath);
            if (testSuiteNodeList != null && testSuiteNodeList.getLength() > 0) {
                List<TestSuite> allTestSuites = getTestSuite(testSuiteNodeList);
                for (TestSuite tstSuite : allTestSuites) {
                    List<NodeList> list = new ArrayList<NodeList>();
                    if (multiNodeMap.containsKey(tstSuite.getName())) {
                        list = multiNodeMap.get(tstSuite.getName());
                    }
                    list.add(testSuiteNodeList);
                    multiNodeMap.put(tstSuite.getName(), list);
                }
            }
        }
        String mapKey = constructMapKey(appDirName, moduleName);
        String testSuitesKey = mapKey + testType + moduleName + techReport;
        testSuiteMap.put(testSuitesKey, multiNodeMap);
    }

    /**
     * Gets the document.
     *
     * @param resultFile the result file
     * @return the document
     * @throws PhrescoException the phresco exception
     */
    private Document getDocument(File resultFile) throws PhrescoException {
        InputStream fis = null;
        DocumentBuilder builder = null;
        try {
            fis = new FileInputStream(resultFile);
            DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
            domFactory.setNamespaceAware(false);
            builder = domFactory.newDocumentBuilder();
            Document doc = builder.parse(fis);
            return doc;
        } catch (FileNotFoundException e) {
            throw new PhrescoException(e);
        } catch (ParserConfigurationException e) {
            throw new PhrescoException(e);
        } catch (SAXException e) {
            throw new PhrescoException(e);
        } catch (IOException e) {
            throw new PhrescoException(e);
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                }
            }
        }
    }

    /**
     * Evaluate test suite.
     *
     * @param doc the doc
     * @param testSuitePath the test suite path
     * @return the node list
     * @throws PhrescoException the phresco exception
     */
    private NodeList evaluateTestSuite(Document doc, String testSuitePath) throws PhrescoException {
        XPath xpath = XPathFactory.newInstance().newXPath();
        XPathExpression xPathExpression;
        NodeList testSuiteNode = null;
        try {
            if (StringUtils.isNotEmpty(testSuitePath)) {
                xPathExpression = xpath.compile(testSuitePath);
                testSuiteNode = (NodeList) xPathExpression.evaluate(doc, XPathConstants.NODESET);
            }
        } catch (XPathExpressionException e) {
            throw new PhrescoException(e);
        }
        return testSuiteNode;
    }

    /**
     * Gets the test suite.
     *
     * @param nodelist the nodelist
     * @return the test suite
     * @throws PhrescoException the phresco exception
     */
    private List<TestSuite> getTestSuite(NodeList nodelist) throws PhrescoException {
        List<TestSuite> allTestSuites = new ArrayList<TestSuite>(2);
        TestSuite tstSuite = null;
        for (int i = 0; i < nodelist.getLength(); i++) {
            tstSuite = new TestSuite();
            Node node = nodelist.item(i);
            NamedNodeMap nameNodeMap = node.getAttributes();

            for (int k = 0; k < nameNodeMap.getLength(); k++) {
                Node attribute = nameNodeMap.item(k);
                String attributeName = attribute.getNodeName();
                String attributeValue = attribute.getNodeValue();
                if (FrameworkConstants.ATTR_ASSERTIONS.equals(attributeName)) {
                    tstSuite.setAssertions(attributeValue);
                } else if (FrameworkConstants.ATTR_ERRORS.equals(attributeName)) {
                    tstSuite.setErrors(Float.parseFloat(attributeValue));
                } else if (FrameworkConstants.ATTR_FAILURES.equals(attributeName)) {
                    tstSuite.setFailures(Float.parseFloat(attributeValue));
                } else if (FrameworkConstants.ATTR_FILE.equals(attributeName)) {
                    tstSuite.setFile(attributeValue);
                } else if (FrameworkConstants.ATTR_NAME.equals(attributeName)) {
                    tstSuite.setName(attributeValue);
                } else if (FrameworkConstants.ATTR_TESTS.equals(attributeName)) {
                    tstSuite.setTests(Float.parseFloat(attributeValue));
                } else if (FrameworkConstants.ATTR_TIME.equals(attributeName)) {
                    tstSuite.setTime(attributeValue);
                }
            }
            allTestSuites.add(tstSuite);
        }
        return allTestSuites;
    }

    /**
     * Gets the test result files.
     *
     * @param path the path
     * @return the test result files
     */
    private File[] getTestResultFiles(String path, String name) {
        File testDir = new File(path);
        if (testDir.isDirectory()) {
            FilenameFilter filter = new FileListFilter(name, XML);
            return testDir.listFiles(filter);
        }
        return null;
    }

    /**
     * Gets the functional test suite path.
     *
     * @param appDirName the app dir name
     * @return the functional test suite path
     * @throws PhrescoException the phresco exception
     */
    private String getFunctionalTestSuitePath(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_FUNCTEST_TESTSUITE_XPATH);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the seo test suite path.
     *
     * @param appDirName the app dir name
     * @return the functional test suite path
     * @throws PhrescoException the phresco exception
     */
    private String getseoTestSuitePath(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_SEOTEST_TESTSUITE_XPATH);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the component test suite path.
     *
     * @param appDirName the app dir name
     * @return the component test suite path
     * @throws PhrescoException the phresco exception
     */
    private String getComponentTestSuitePath(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_COMPONENTTEST_TESTSUITE_XPATH);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the functional test report dir.
     *
     * @param appDirName the app dir name
     * @return the functional test report dir
     * @throws PhrescoException the phresco exception
     */
    private String getFunctionalTestReportDir(String rootModulePath, String subModule) throws PhrescoException {
        try {
            String property = Utility.getPomProcessor(rootModulePath, subModule)
                    .getPropertyValue(Constants.POM_PROP_KEY_FUNCTEST_RPT_DIR);
            return property;
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the seo test report dir.
     *
     * @param appDirName the app dir name
     * @return the functional test report dir
     * @throws PhrescoException the phresco exception
     */
    private String getseoTestReportDir(String rootModulePath, String subModule) throws PhrescoException {
        try {
            String property = Utility.getPomProcessor(rootModulePath, subModule)
                    .getPropertyValue(Constants.POM_PROP_KEY_SEOTEST_RPT_DIR);
            return property;
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the component test report dir.
     *
     * @param appDirName the app dir name
     * @return the component test report dir
     * @throws PhrescoException the phresco exception
     */
    private String getComponentTestReportDir(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_COMPONENTTEST_RPT_DIR);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the unit test report options.
     *
     * @param appDirName the app dir name
     * @return the unit test report options
     * @throws PhrescoException the phresco exception
     */
    private String getUnitTestReportOptions(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule).getProperty(Constants.PHRESCO_UNIT_TEST);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the unit test case path.
     *
     * @param appDirName the app dir name
     * @param option the option
     * @return the unit test case path
     * @throws PhrescoException the phresco exception
     */
    private String getUnitTestCasePath(String rootModulePath, String subModule, String option)
            throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_UNITTEST_TESTCASE_PATH_START + option
                            + Constants.POM_PROP_KEY_UNITTEST_TESTCASE_PATH_END);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the unit test case path.
     *
     * @param appDirName the app dir name
     * @return the unit test case path
     * @throws PhrescoException the phresco exception
     */
    private String getUnitTestCasePath(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_UNITTEST_TESTCASE_PATH);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the unit test step node name.
     *
     * @param appDirName the app dir name
     * @param option the option
     * @return the unit test case path
     * @throws PhrescoException the phresco exception
     */
    private String getUnitTestStepNodeName(String rootModulePath, String subModule, String option)
            throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_UNITTEST_TESTCASE_PATH_START + option
                            + Constants.POM_PROP_KEY_UNITTEST_TESTSTEP_XPATH_END);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the unit test function path.
     *
     * @param appDirName the app dir name
     * @return the unit test case path
     * @throws PhrescoException the phresco exception
     */
    private String getUnitTestStepNodeName(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_UNITTEST_TESTSTEP_XPATH);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the functional test case path.
     *
     * @param appDirName the app dir name
     * @return the functional test case path
     * @throws PhrescoException the phresco exception
     */
    private String getFunctionalTestCasePath(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_FUNCTEST_TESTCASE_PATH);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the seo test case path.
     *
     * @param appDirName the app dir name
     * @return the functional test case path
     * @throws PhrescoException the phresco exception
     */
    private String getseoTestCasePath(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_SEOTEST_TESTCASE_PATH);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the functional test step path.
     *
     * @param appDirName the app dir name
     * @return the functional test case path
     * @throws PhrescoException the phresco exception
     */
    private String getFunctionalTestStepNodeName(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_FUNCTEST_TESTSTEP_XPATH);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    private String getIntegrationTestCasePath(String appDirName) throws PhrescoException {
        try {
            return FrameworkUtil.getInstance().getPomProcessorForIntegration(appDirName)
                    .getProperty(Constants.POM_PROP_KEY_INTEGRATIONTEST_TESTCASE_PATH);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the component test case path.
     *
     * @param appDirName the app dir name
     * @return the component test case path
     * @throws PhrescoException the phresco exception
     */
    private String getComponentTestCasePath(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_COMPONENTTEST_TESTCASE_PATH);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Gets the sceen shot dir.
     *
     * @param appDirName the app dir name
     * @return the sceen shot dir
     * @throws PhrescoException the phresco exception
     */
    private String getSceenShotDir(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_SCREENSHOT_DIR);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    /**
     * Performance.
     *
     * @param appDirName the app dir name
     * @param userId the user id
     * @return the response
     */
    @GET
    @Path(REST_API_PERFORMANCE)
    @Produces(MediaType.APPLICATION_JSON)
    public Response performance(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_QUERY_MODULE_NAME) String module) {
        List<String> testResultFiles = null;
        ResponseInfo<Map> responseData = new ResponseInfo<Map>();
        try {

            //         if (StringUtils.isNotEmpty(module)) {
            //            appDirName = appDirName + File.separator + module;
            //         }

            String rootModulePath = "";
            String subModuleName = "";
            if (StringUtils.isNotEmpty(module)) {
                rootModulePath = Utility.getProjectHome() + appDirName;
                subModuleName = module;
            } else {
                rootModulePath = Utility.getProjectHome() + appDirName;
            }
            Map<String, Object> performanceMap = new HashMap<String, Object>();
            MojoProcessor mojo = new MojoProcessor(
                    new File(FrameworkServiceUtil.getPhrescoPluginInfoFilePath(Constants.PHASE_PERFORMANCE_TEST,
                            Constants.PHASE_PERFORMANCE_TEST, rootModulePath, subModuleName)));
            List<String> testAgainsts = new ArrayList<String>();
            Parameter testAgainstParameter = mojo.getParameter(Constants.PHASE_PERFORMANCE_TEST, REQ_TEST_AGAINST);
            if (testAgainstParameter != null && TYPE_LIST.equalsIgnoreCase(testAgainstParameter.getType())) {
                List<Value> values = testAgainstParameter.getPossibleValues().getValue();
                for (Value value : values) {
                    testAgainsts.add(value.getKey());
                }
            }
            boolean resutlAvailable = testResultAvail(rootModulePath, subModuleName, testAgainsts,
                    Constants.PHASE_PERFORMANCE_TEST);
            boolean showDevice = Boolean.parseBoolean(getPerformanceTestShowDevice(rootModulePath, subModuleName));
            if (resutlAvailable) {
                testResultFiles = testResultFiles(rootModulePath, subModuleName, testAgainsts, showDevice,
                        Constants.PHASE_PERFORMANCE_TEST);
            }

            List<String> devices = new ArrayList<String>();
            if (showDevice && CollectionUtils.isNotEmpty(testResultFiles)
                    && StringUtils.isNotEmpty(testResultFiles.get(0))) {
                String testResultPath = getLoadOrPerformanceTestResultPath(rootModulePath, subModuleName, "",
                        testResultFiles.get(0), Constants.PHASE_PERFORMANCE_TEST);
                Document document = getDocument(new File(testResultPath));
                devices = QualityUtil.getDeviceNames(document);
            }

            performanceMap.put(TEST_AGAINSTS, testAgainsts);
            performanceMap.put(RESULT_AVAILABLE, resutlAvailable);
            performanceMap.put(TEST_RESULT_FILES, testResultFiles);
            performanceMap.put(SHOW_DEVICE, showDevice);
            performanceMap.put(DEVICES, devices);

            ResponseInfo<Map> finalOutput = responseDataEvaluation(responseData, null, performanceMap,
                    RESPONSE_STATUS_SUCCESS, PHRQ500001);
            return Response.ok(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        } catch (Exception e) {
            ResponseInfo<Map> finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR,
                    PHRQ510001);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        }
    }

    @POST
    @Path(REST_API_TEST_RESULT_FILES)
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response getTypeFiles(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_ACTION_TYPE) String actionType, List<String> testAgainsts,
            @QueryParam(REST_QUERY_MODULE_NAME) String module) {
        List<String> testResultFiles = null;
        boolean resutlAvailable = false;
        ResponseInfo<List<String>> responseData = new ResponseInfo<List<String>>();
        try {

            String rootModulePath = "";
            String subModuleName = "";
            if (StringUtils.isNotEmpty(module)) {
                rootModulePath = Utility.getProjectHome() + appDirName;
                subModuleName = module;
            } else {
                rootModulePath = Utility.getProjectHome() + appDirName;
            }
            if (actionType.equalsIgnoreCase(Constants.PHASE_PERFORMANCE_TEST)) {
                resutlAvailable = testResultAvail(rootModulePath, subModuleName, testAgainsts,
                        Constants.PHASE_PERFORMANCE_TEST);
            } else if (actionType.equalsIgnoreCase(Constants.PHASE_LOAD_TEST)) {
                resutlAvailable = testResultAvail(rootModulePath, subModuleName, testAgainsts,
                        Constants.PHASE_LOAD_TEST);
            }
            boolean showDevice = Boolean.parseBoolean(getPerformanceTestShowDevice(rootModulePath, subModuleName));
            if (resutlAvailable) {
                testResultFiles = testResultFiles(rootModulePath, subModuleName, testAgainsts, showDevice,
                        actionType);
                ResponseInfo<List<String>> finalOutput = responseDataEvaluation(responseData, null, testResultFiles,
                        RESPONSE_STATUS_SUCCESS, PHRQ500002);
                return Response.ok(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
            }
            ResponseInfo<List<String>> finalOutput = responseDataEvaluation(responseData, null, testResultFiles,
                    RESPONSE_STATUS_FAILURE, PHRQ510002);
            return Response.ok(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        } catch (PhrescoException e) {
            ResponseInfo<List<String>> finalOutput = responseDataEvaluation(responseData, e, null,
                    RESPONSE_STATUS_ERROR, PHRQ510003);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        }
    }

    @GET
    @Path(REST_API_DEVICES)
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response devices(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_QUERY_RESULT_FILE_NAME) String resultFileName,
            @QueryParam(REST_QUERY_MODULE_NAME) String module) throws PhrescoException {
        ResponseInfo<List<String>> responseData = new ResponseInfo<List<String>>();
        List<String> devices = new ArrayList<String>();
        try {
            String rootModulePath = "";
            String subModuleName = "";
            if (StringUtils.isNotEmpty(module)) {
                rootModulePath = Utility.getProjectHome() + appDirName;
                subModuleName = module;
            } else {
                rootModulePath = Utility.getProjectHome() + appDirName;
            }
            String testResultPath = getLoadOrPerformanceTestResultPath(rootModulePath, subModuleName, "",
                    resultFileName, Constants.PHASE_PERFORMANCE_TEST);
            Document document = getDocument(new File(testResultPath));
            devices = QualityUtil.getDeviceNames(document);

            ResponseInfo<List<String>> finalOutput = responseDataEvaluation(responseData, null, devices,
                    RESPONSE_STATUS_SUCCESS, PHRQ500003);
            return Response.ok(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        } catch (Exception e) {
            ResponseInfo<List<String>> finalOutput = responseDataEvaluation(responseData, e, null,
                    RESPONSE_STATUS_ERROR, PHRQ510004);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        }
    }

    public boolean testResultAvail(String rootModulePath, String subModuleName, List<String> testAgainsts,
            String action) throws PhrescoException {
        boolean resultAvailable = false;
        try {
            String reportDir = "";
            String resultExtension = "";
            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName);
            File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModuleName);
            if (Constants.PHASE_PERFORMANCE_TEST.equals(action)) {
                reportDir = FrameworkServiceUtil.getPerformanceTestReportDir(rootModulePath, subModuleName);
                resultExtension = FrameworkServiceUtil.getPerformanceResultFileExtension(rootModulePath,
                        subModuleName);
            } else {
                reportDir = FrameworkServiceUtil.getLoadTestReportDir(rootModulePath, subModuleName);
                resultExtension = FrameworkServiceUtil.getLoadResultFileExtension(rootModulePath, subModuleName);
            }
            for (String testAgainst : testAgainsts) {
                StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
                if (Constants.PHASE_PERFORMANCE_TEST.equals(action)) {
                    reportDir = FrameworkServiceUtil.getPerformanceTestReportDir(rootModulePath, subModuleName);
                } else {
                    reportDir = FrameworkServiceUtil.getLoadTestReportDir(rootModulePath, subModuleName);
                }

                if (StringUtils.isNotEmpty(reportDir) && StringUtils.isNotEmpty(testAgainst)) {
                    Pattern p = Pattern.compile(TEST_DIRECTORY);
                    Matcher matcher = p.matcher(reportDir);
                    reportDir = matcher.replaceAll(testAgainst);
                    sb.append(reportDir);
                }

                File file = new File(sb.toString());
                if (StringUtils.isNotEmpty(resultExtension) && file.exists()) {
                    File[] children = file.listFiles(new XmlNameFileFilter(resultExtension));
                    if (!ArrayUtils.isEmpty(children)) {
                        resultAvailable = true;
                        break;
                    }
                }
            }

            if (CollectionUtils.isEmpty(testAgainsts) && Constants.PHASE_PERFORMANCE_TEST.equals(action)
                    && StringUtils.isNotEmpty(reportDir)) {
                StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
                sb.append(reportDir);
                File file = new File(sb.toString());
                if (StringUtils.isNotEmpty(resultExtension)) {
                    File[] children = file.listFiles(new XmlNameFileFilter(resultExtension));
                    if (!ArrayUtils.isEmpty(children)) {
                        resultAvailable = true;
                    }
                }
            }

        } catch (Exception e) {
            throw new PhrescoException(e);
        }

        return resultAvailable;
    }

    public boolean testResultAvailunit(String rootModulePath, String subModuleName, List<String> testAgainsts,
            String action) throws PhrescoException {
        boolean resultAvailable = false;
        try {
            String reportDir = "";
            String resultExtension = "";
            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName);
            File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModuleName);
            if (Constants.PHASE_UNIT_TEST.equals(action)) {
                reportDir = FrameworkServiceUtil.getUnitTestRptDir(rootModulePath, subModuleName);
                resultExtension = "xml";
            } /*else {
               reportDir = FrameworkServiceUtil.getLoadTestReportDir(rootModulePath, subModuleName);
               resultExtension = FrameworkServiceUtil.getLoadResultFileExtension(rootModulePath, subModuleName);
              }*/
            for (String testAgainst : testAgainsts) {
                StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
                if (Constants.PHASE_UNIT_TEST.equals(action)) {
                    reportDir = FrameworkServiceUtil.getUnitTestRptDir(rootModulePath, subModuleName);
                } /*else {
                   reportDir = FrameworkServiceUtil.getLoadTestReportDir(rootModulePath, subModuleName);
                  }*/

                if (StringUtils.isNotEmpty(reportDir) && StringUtils.isNotEmpty(testAgainst)) {
                    Pattern p = Pattern.compile(TEST_DIRECTORY);
                    Matcher matcher = p.matcher(reportDir);
                    reportDir = matcher.replaceAll(testAgainst);
                    sb.append(reportDir);
                }

                File file = new File(sb.toString());
                if (StringUtils.isNotEmpty(resultExtension) && file.exists()) {
                    File[] children = file.listFiles(new XmlNameFileFilter(resultExtension));
                    if (!ArrayUtils.isEmpty(children)) {
                        resultAvailable = true;
                        break;
                    }
                }
            }

            if (CollectionUtils.isEmpty(testAgainsts) && Constants.PHASE_UNIT_TEST.equals(action)
                    && StringUtils.isNotEmpty(reportDir)) {
                StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
                sb.append(reportDir);
                File file = new File(sb.toString());
                if (StringUtils.isNotEmpty(resultExtension)) {
                    File[] children = file.listFiles(new XmlNameFileFilter(resultExtension));
                    if (!ArrayUtils.isEmpty(children)) {
                        resultAvailable = true;
                    }
                }
            }

        } catch (Exception e) {
            throw new PhrescoException(e);
        }

        return resultAvailable;
    }

    public boolean testResultAvailfunctional(String rootModulePath, String subModuleName, List<String> testAgainsts,
            String action) throws PhrescoException {
        boolean resultAvailable = false;
        try {
            String reportDir = "";
            String resultExtension = "";
            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName);
            File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModuleName);
            if (Constants.PHASE_FUNCTIONAL_TEST.equals(action)) {
                reportDir = FrameworkServiceUtil.getFunctionalTestRptDir(rootModulePath, subModuleName);
                resultExtension = "xml";
            } /*else {
               reportDir = FrameworkServiceUtil.getLoadTestReportDir(rootModulePath, subModuleName);
               resultExtension = FrameworkServiceUtil.getLoadResultFileExtension(rootModulePath, subModuleName);
              }*/
            for (String testAgainst : testAgainsts) {
                StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
                if (Constants.PHASE_FUNCTIONAL_TEST.equals(action)) {
                    reportDir = FrameworkServiceUtil.getFunctionalTestRptDir(rootModulePath, subModuleName);
                } /*else {
                   reportDir = FrameworkServiceUtil.getLoadTestReportDir(rootModulePath, subModuleName);
                  }*/

                if (StringUtils.isNotEmpty(reportDir) && StringUtils.isNotEmpty(testAgainst)) {
                    Pattern p = Pattern.compile(TEST_DIRECTORY);
                    Matcher matcher = p.matcher(reportDir);
                    reportDir = matcher.replaceAll(testAgainst);
                    sb.append(reportDir);
                }

                File file = new File(sb.toString());
                if (StringUtils.isNotEmpty(resultExtension) && file.exists()) {
                    File[] children = file.listFiles(new XmlNameFileFilter(resultExtension));
                    if (!ArrayUtils.isEmpty(children)) {
                        resultAvailable = true;
                        break;
                    }
                }
            }

            if (CollectionUtils.isEmpty(testAgainsts) && Constants.PHASE_FUNCTIONAL_TEST.equals(action)
                    && StringUtils.isNotEmpty(reportDir)) {
                StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
                sb.append(reportDir);
                File file = new File(sb.toString());
                if (StringUtils.isNotEmpty(resultExtension)) {
                    File[] children = file.listFiles(new XmlNameFileFilter(resultExtension));
                    if (!ArrayUtils.isEmpty(children)) {
                        resultAvailable = true;
                    }
                }
            }

        } catch (Exception e) {
            throw new PhrescoException(e);
        }

        return resultAvailable;
    }

    private List<String> testResultFiles(String rootModulePath, String subModuleName, List<String> testAgainsts,
            boolean showDevice, String action) throws PhrescoException {
        List<String> testResultFiles = new ArrayList<String>();
        String reportDir = "";
        String resultExtension = "";
        try {
            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName);
            File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModuleName);
            StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
            if (Constants.PHASE_PERFORMANCE_TEST.equals(action)) {
                reportDir = FrameworkServiceUtil.getPerformanceTestReportDir(rootModulePath, subModuleName);
                resultExtension = FrameworkServiceUtil.getPerformanceResultFileExtension(rootModulePath,
                        subModuleName);
            } else {
                reportDir = FrameworkServiceUtil.getLoadTestReportDir(rootModulePath, subModuleName);
                resultExtension = FrameworkServiceUtil.getLoadResultFileExtension(rootModulePath, subModuleName);
            }

            //test against will be available 
            if (StringUtils.isNotEmpty(reportDir) && CollectionUtils.isNotEmpty(testAgainsts)) {
                Pattern p = Pattern.compile(TEST_DIRECTORY);
                Matcher matcher = p.matcher(reportDir);
                reportDir = matcher.replaceAll(testAgainsts.get(0));
                sb.append(reportDir);
            }

            //for android - test type will not be available --- to get device id from result xml
            if (Constants.PHASE_PERFORMANCE_TEST.equals(action) && showDevice) {
                sb.append(reportDir);
            }

            File file = new File(sb.toString());

            if (StringUtils.isNotEmpty(resultExtension)) {
                File[] resultFiles = file.listFiles(new XmlNameFileFilter(resultExtension));
                if (!ArrayUtils.isEmpty(resultFiles)) {
                    QualityUtil.sortResultFile(resultFiles);
                    for (File resultFile : resultFiles) {
                        if (resultFile.isFile()) {
                            testResultFiles.add(resultFile.getName());
                        }
                    }
                }
            }
        } catch (Exception e) {
            throw new PhrescoException(e);
        }

        return testResultFiles;
    }

    private List<String> testResultFilesunit(String rootModulePath, String subModuleName, List<String> testAgainsts,
            String showDevice, String action) throws PhrescoException {
        List<String> testResultFiles = new ArrayList<String>();
        String reportDir = "";
        String resultExtension = "";
        try {
            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName);
            File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModuleName);
            StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
            if (Constants.PHASE_UNIT_TEST.equals(action)) {
                reportDir = FrameworkServiceUtil.getUnitTestRptDir(rootModulePath, subModuleName);
                resultExtension = "xml";
            } /*else {
               reportDir = FrameworkServiceUtil.getLoadTestReportDir(rootModulePath, subModuleName);
               resultExtension = FrameworkServiceUtil.getLoadResultFileExtension(rootModulePath, subModuleName);
              }
              */
            //test against will be available 
            if (StringUtils.isNotEmpty(reportDir) && CollectionUtils.isNotEmpty(testAgainsts)) {
                Pattern p = Pattern.compile(TEST_DIRECTORY);
                Matcher matcher = p.matcher(reportDir);
                reportDir = matcher.replaceAll(testAgainsts.get(0));
                sb.append(reportDir);
            }

            //for android - test type will not be available --- to get device id from result xml
            if (Constants.PHASE_UNIT_TEST.equals(action) && StringUtils.isNotEmpty(showDevice)) {
                sb.append(reportDir);
            }

            File file = new File(sb.toString());

            if (StringUtils.isNotEmpty(resultExtension)) {
                File[] resultFiles = file.listFiles(new XmlNameFileFilter(resultExtension));
                if (!ArrayUtils.isEmpty(resultFiles)) {
                    QualityUtil.sortResultFile(resultFiles);
                    for (File resultFile : resultFiles) {
                        if (resultFile.isFile()) {
                            testResultFiles.add(resultFile.getName());
                        }
                    }
                }
            }
        } catch (Exception e) {
            throw new PhrescoException(e);
        }

        return testResultFiles;
    }

    private List<String> testResultFilesfunctional(String rootModulePath, String subModuleName,
            List<String> testAgainsts, boolean showDevice, String action) throws PhrescoException {
        List<String> testResultFiles = new ArrayList<String>();
        String reportDir = "";
        String resultExtension = "";
        try {
            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName);
            File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModuleName);
            StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
            if (Constants.PHASE_FUNCTIONAL_TEST.equals(action)) {
                reportDir = FrameworkServiceUtil.getFunctionalTestRptDir(rootModulePath, subModuleName);
                resultExtension = "xml";
            } /*else {
               reportDir = FrameworkServiceUtil.getLoadTestReportDir(rootModulePath, subModuleName);
               resultExtension = FrameworkServiceUtil.getLoadResultFileExtension(rootModulePath, subModuleName);
              }
              */
            //test against will be available 
            if (StringUtils.isNotEmpty(reportDir) && CollectionUtils.isNotEmpty(testAgainsts)) {
                Pattern p = Pattern.compile(TEST_DIRECTORY);
                Matcher matcher = p.matcher(reportDir);
                reportDir = matcher.replaceAll(testAgainsts.get(0));
                sb.append(reportDir);
            }

            //for android - test type will not be available --- to get device id from result xml
            if (Constants.PHASE_FUNCTIONAL_TEST.equals(action) && showDevice) {
                sb.append(reportDir);
            }

            File file = new File(sb.toString());

            if (StringUtils.isNotEmpty(resultExtension)) {
                File[] resultFiles = file.listFiles(new XmlNameFileFilter(resultExtension));
                if (!ArrayUtils.isEmpty(resultFiles)) {
                    QualityUtil.sortResultFile(resultFiles);
                    for (File resultFile : resultFiles) {
                        if (resultFile.isFile()) {
                            testResultFiles.add(resultFile.getName());
                        }
                    }
                }
            }
        } catch (Exception e) {
            throw new PhrescoException(e);
        }

        return testResultFiles;
    }

    private List<String> getScreenShot(String testAgainst, String resultFile, String rootModulePath,
            String subModule, String from) throws PhrescoException {
        List<String> imgSources = new ArrayList<String>();
        try {
            String testDir = "";
            if (PERFORMACE.equals(from)) {
                testDir = FrameworkServiceUtil.getPerformanceTestDir(rootModulePath, subModule);
            } else {
                testDir = FrameworkServiceUtil.getLoadTestDir(rootModulePath, subModule);
            }

            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModule);
            File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModule);
            StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
            sb.append(testDir).append(File.separator).append(testAgainst);
            int lastDot = resultFile.lastIndexOf(".");
            String resultName = resultFile.substring(0, lastDot);

            File testPomFile = new File(sb.toString() + File.separator + POM_XML);
            PomProcessor pomProcessor = new PomProcessor(testPomFile);
            Plugin plugin = pomProcessor.getPlugin(COM_LAZERYCODE_JMETER, JMETER_MAVEN_PLUGIN);
            com.phresco.pom.model.Plugin.Configuration jmeterConfiguration = plugin.getConfiguration();
            List<Element> jmeterConfigs = jmeterConfiguration.getAny();
            for (Element element : jmeterConfigs) {
                if (PLUGIN_TYPES.equalsIgnoreCase(element.getTagName()) && element.hasChildNodes()) {
                    NodeList types = element.getChildNodes();
                    for (int i = 0; i < types.getLength(); i++) {
                        Node pluginType = types.item(i);
                        if (StringUtils.isNotEmpty(pluginType.getTextContent())) {
                            File imgFile = new File(sb.toString() + RESULTS_JMETER_GRAPHS + resultName + HYPHEN
                                    + pluginType.getTextContent() + PNG);
                            if (imgFile.exists()) {
                                InputStream imageStream = new FileInputStream(imgFile);
                                String imgSrc = new String(Base64.encodeBase64(IOUtils.toByteArray(imageStream)));
                                imgSources.add(
                                        imgSrc + "#NAME_SEP#" + resultName + HYPHEN + pluginType.getTextContent());
                            }
                        }
                    }
                }
            }

        } catch (Exception e) {
            throw new PhrescoException(e);
        }

        return imgSources;
    }

    /**
     * Performance.
     *
     * @param appDirName the app dir name
     * @param userId the user id
     * @return the response
     */
    @GET
    @Path(REST_API_PERFORMANCE_RESULTS)
    @Produces(MediaType.APPLICATION_JSON)
    public Response performanceTestResults(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_QUERY_TEST_AGAINST) String testAgainst,
            @QueryParam(REST_QUERY_RESULT_FILE_NAME) String resultFileName,
            @QueryParam(REST_QUERY_DEVICE_ID) String deviceId,
            @QueryParam(REST_QUERY_SHOW_GRAPH_FOR) String showGraphFor, @QueryParam("from") String from,
            @QueryParam(REST_QUERY_MODULE_NAME) String module) {
        //      if (StringUtils.isNotEmpty(module)) {
        //         appDirName = appDirName + File.separator + module;
        //      }

        String rootModulePath = "";
        String subModuleName = "";
        if (StringUtils.isNotEmpty(module)) {
            rootModulePath = Utility.getProjectHome() + appDirName;
            subModuleName = module;
        } else {
            rootModulePath = Utility.getProjectHome() + appDirName;
        }
        ResponseInfo<List<PerformanceTestResult>> responseData = new ResponseInfo<List<PerformanceTestResult>>();
        PerformancResultInfo performanceResultInfo = null;
        StringBuilder graphData = new StringBuilder("[");
        StringBuilder label = new StringBuilder("[");
        int index = 0;
        List<Float> allMin = new ArrayList<Float>();
        List<Float> allMax = new ArrayList<Float>();
        List<Float> allAvg = new ArrayList<Float>();
        try {
            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName);
            ApplicationInfo appInfo = projectInfo.getAppInfos().get(0);
            String techId = appInfo.getTechInfo().getId();
            if (StringUtils.isNotEmpty(resultFileName)) {
                String testResultPath = getLoadOrPerformanceTestResultPath(rootModulePath, subModuleName,
                        testAgainst, resultFileName, from);
                Document document = getDocument(new File(testResultPath));
                performanceResultInfo = QualityUtil.getPerformanceReport(document, techId, deviceId);
                List<PerformanceTestResult> perfromanceTestResult = performanceResultInfo
                        .getPerfromanceTestResult();
                for (PerformanceTestResult performanceTestResult : perfromanceTestResult) {
                    if (REQ_TEST_SHOW_THROUGHPUT_GRAPH.equals(showGraphFor)) {
                        //for ThroughtPut
                        graphData.append(performanceTestResult.getThroughtPut());
                    } else if (REQ_TEST_SHOW_MIN_RESPONSE_GRAPH.equals(showGraphFor)) {
                        //for min response time
                        graphData.append(performanceTestResult.getMin());
                    } else if (REQ_TEST_SHOW_MAX_RESPONSE_GRAPH.equals(showGraphFor)) {
                        //for max response time
                        graphData.append(performanceTestResult.getMax());
                    } else if (REQ_TEST_SHOW_RESPONSE_TIME_GRAPH.equals(showGraphFor)) {
                        //for responseTime
                        graphData.append(performanceTestResult.getAvg());
                    } else if (REQ_TEST_SHOW_ALL_GRAPH.equals(showGraphFor)) {
                        //for ThroughtPut
                        graphData.append(performanceTestResult.getThroughtPut());
                        allMin.add((float) performanceTestResult.getMin() / 1000);
                        allMax.add((float) performanceTestResult.getMax() / 1000);
                        allAvg.add((float) (performanceTestResult.getAvg()) / 1000);
                    }

                    label.append("'");
                    label.append(performanceTestResult.getLabel());
                    label.append("'");
                    if (index < perfromanceTestResult.size() - 1) {
                        graphData.append(Constants.COMMA);
                        label.append(Constants.COMMA);
                    }
                    index++;
                }
                label.append("]");
                graphData.append("]");
            }
            List<String> screenShots = new ArrayList<String>();
            if (StringUtils.isNotEmpty(testAgainst)) {
                if (Constants.PHASE_PERFORMANCE_TEST.equals(from)) {
                    screenShots = getScreenShot(testAgainst, resultFileName, rootModulePath, subModuleName,
                            PERFORMACE);
                } else {
                    screenShots = getScreenShot(testAgainst, resultFileName, rootModulePath, subModuleName, LOAD);
                }
            }
            performanceResultInfo.setGraphData(graphData.toString());
            performanceResultInfo.setLabel(label.toString());
            performanceResultInfo.setGraphAlldata(allMin + ", " + allAvg + ", " + allMax);
            performanceResultInfo.setGraphFor(showGraphFor);
            performanceResultInfo.setImages(screenShots);

            ResponseInfo<List<PerformanceTestResult>> finalOutput = responseDataEvaluation(responseData, null,
                    performanceResultInfo, RESPONSE_STATUS_SUCCESS, PHRQ500004);
            return Response.ok(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        } catch (Exception e) {
            ResponseInfo<List<PerformanceTestResult>> finalOutput = responseDataEvaluation(responseData, e, null,
                    RESPONSE_STATUS_ERROR, PHRQ510005);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        }
    }

    /*@GET
    @Path("/unitTestResults")
    @Produces(MediaType.APPLICATION_JSON)
    public Response unitTestResults(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName, @QueryParam(REST_QUERY_TEST_AGAINST) String testAgainst , 
     @QueryParam(REST_QUERY_RESULT_FILE_NAME) String resultFileName, @QueryParam(REST_QUERY_DEVICE_ID) String deviceId, @QueryParam(REST_QUERY_SHOW_GRAPH_FOR) String showGraphFor, 
     @QueryParam("from") String from, @QueryParam(REST_QUERY_MODULE_NAME) String module) {
           
       String rootModulePath = "";
       String subModuleName = "";
       if (StringUtils.isNotEmpty(module)) {
     rootModulePath = Utility.getProjectHome() + appDirName;
     subModuleName = module;
       } else {
     rootModulePath = Utility.getProjectHome() + appDirName;
       }
       ResponseInfo<List<PerformanceTestResult>> responseData = new ResponseInfo<List<PerformanceTestResult>>();
       PerformancResultInfo performanceResultInfo = null;
        StringBuilder graphData = new StringBuilder("[");
     StringBuilder label = new StringBuilder("[");
        return response;
    }
    */
    private String getLoadOrPerformanceTestResultPath(String rootModulePath, String subModuleName,
            String testAgainst, String resultFileName, String action) throws PhrescoException {
        try {
            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName);
            File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModuleName);

            StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
            String reportDir = "";
            if (Constants.PHASE_PERFORMANCE_TEST.equals(action)) {
                reportDir = FrameworkServiceUtil.getPerformanceTestReportDir(rootModulePath, subModuleName);
            } else {
                reportDir = FrameworkServiceUtil.getLoadTestReportDir(rootModulePath, subModuleName);
            }
            //To change the dir_type based on the selected type
            Pattern p = Pattern.compile(TEST_DIRECTORY);
            Matcher matcher = p.matcher(reportDir);
            if (StringUtils.isNotEmpty(reportDir) && StringUtils.isNotEmpty(testAgainst) && matcher.find()) {
                reportDir = matcher.replaceAll(testAgainst);
            }
            sb.append(reportDir);
            sb.append(File.separator);
            sb.append(resultFileName);

            return sb.toString();
        } catch (Exception e) {
            throw new PhrescoException(e);
        }
    }

    private String getUnitTestResultPath(String rootModulePath, String subModuleName, String testAgainst,
            String resultFileName, String action) throws PhrescoException {
        try {
            ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName);
            File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModuleName);

            StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
            String reportDir = "";
            if (Constants.PHASE_UNIT_TEST.equals(action)) {
                reportDir = FrameworkServiceUtil.getUnitTestRptDir(rootModulePath, subModuleName);
            } /*else {
               reportDir = FrameworkServiceUtil.getLoadTestReportDir(rootModulePath, subModuleName);
              }*/
            //To change the dir_type based on the selected type
            Pattern p = Pattern.compile(TEST_DIRECTORY);
            Matcher matcher = p.matcher(reportDir);
            if (StringUtils.isNotEmpty(reportDir) && StringUtils.isNotEmpty(testAgainst) && matcher.find()) {
                reportDir = matcher.replaceAll(testAgainst);
            }
            sb.append(reportDir);
            sb.append(File.separator);
            sb.append(resultFileName);

            return sb.toString();

        } catch (Exception e) {
            throw new PhrescoException(e);
        }
    }

    private String getPerformanceTestShowDevice(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_PERF_SHOW_DEVICE);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    private String getUnitTestShowDevice(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_UNIT_SHOW_DEVICE);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    private String getFunctionalTestShowDevice(String rootModulePath, String subModule) throws PhrescoException {
        try {
            return Utility.getPomProcessor(rootModulePath, subModule)
                    .getProperty(Constants.POM_PROP_KEY_FUNCTIONAL_SHOW_DEVICE);
        } catch (PhrescoPomException e) {
            throw new PhrescoException(e);
        }
    }

    public class XmlNameFileFilter implements FilenameFilter {
        private String filter_;

        public XmlNameFileFilter(String filter) {
            filter_ = filter;
        }

        public boolean accept(File dir, String name) {
            return name.endsWith(filter_);
        }
    }

    /**
     * load.
     *
     * @param appDirName the app dir name
     * @param userId the user id
     * @return the response
     */
    @GET
    @Path(REST_API_LOAD)
    @Produces(MediaType.APPLICATION_JSON)
    public Response load(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_QUERY_MODULE_NAME) String module) {
        ResponseInfo<Map> responseData = new ResponseInfo<Map>();
        try {
            //         if (StringUtils.isNotEmpty(module)) {
            //            appDirName = appDirName + File.separator + module;
            //         }

            String rootModulePath = "";
            String subModuleName = "";
            if (StringUtils.isNotEmpty(module)) {
                rootModulePath = Utility.getProjectHome() + appDirName;
                subModuleName = module;
            } else {
                rootModulePath = Utility.getProjectHome() + appDirName;
            }
            Map<String, Object> loadMap = new HashMap<String, Object>();
            MojoProcessor mojo = new MojoProcessor(new File(FrameworkServiceUtil.getPhrescoPluginInfoFilePath(
                    Constants.PHASE_LOAD_TEST, Constants.PHASE_LOAD_TEST, rootModulePath, subModuleName)));
            List<String> testAgainsts = new ArrayList<String>();
            Parameter testAgainstParameter = mojo.getParameter(Constants.PHASE_LOAD_TEST, REQ_TEST_AGAINST);
            if (testAgainstParameter != null && TYPE_LIST.equalsIgnoreCase(testAgainstParameter.getType())) {
                List<Value> values = testAgainstParameter.getPossibleValues().getValue();
                for (Value value : values) {
                    testAgainsts.add(value.getKey());
                }
            }
            boolean resutlAvailable = testResultAvail(rootModulePath, subModuleName, testAgainsts,
                    Constants.PHASE_LOAD_TEST);
            List<String> testResultFiles = new ArrayList<String>();
            if (resutlAvailable) {
                testResultFiles = testResultFiles(rootModulePath, subModuleName, testAgainsts, false,
                        Constants.PHASE_LOAD_TEST);
            }

            loadMap.put(TEST_AGAINSTS, testAgainsts);
            loadMap.put(RESULT_AVAILABLE, resutlAvailable);
            loadMap.put(TEST_RESULT_FILES, testResultFiles);

            ResponseInfo<List<String>> finalOutput = responseDataEvaluation(responseData, null, loadMap,
                    RESPONSE_STATUS_SUCCESS, PHRQ600001);
            return Response.ok(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        } catch (Exception e) {
            ResponseInfo<List<String>> finalOutput = responseDataEvaluation(responseData, e, null,
                    RESPONSE_STATUS_ERROR, PHRQ610001);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        }
    }

    /**
     * load.
     *
     * @param appDirName the app dir name
     * @param userId the user id
     * @return the response
     */
    @GET
    @Path(REST_API_LOAD_RESULTS)
    @Produces(MediaType.APPLICATION_JSON)
    public Response loadTestResults(@QueryParam(REST_QUERY_APPDIR_NAME) String appDirName,
            @QueryParam(REST_QUERY_TEST_AGAINST) String testAgainst,
            @QueryParam(REST_QUERY_RESULT_FILE_NAME) String resultFileName) {
        ResponseInfo<List<TestResult>> responseData = new ResponseInfo<List<TestResult>>();
        try {
            String rootModulePath = "";
            String subModuleName = "";
            List<TestResult> testResults = getLoadTestResult(rootModulePath, subModuleName, testAgainst,
                    resultFileName, Constants.PHASE_LOAD_TEST);
            Gson gson = new Gson();
            StringBuilder jSon = new StringBuilder();
            StringBuilder data = new StringBuilder();
            jSon.append(GRAPH_JSON);
            data.append(SQUARE_OPEN);
            for (TestResult testResult : testResults) {
                jSon.append(gson.toJson(testResult));
                data.append(SQUARE_OPEN);
                data.append(testResults.indexOf(testResult));
                data.append(Constants.COMMA);
                data.append(testResult.getTime());
                data.append(SQUARE_CLOSE);
                if (testResults.indexOf(testResult) < testResults.size() - 1) {
                    jSon.append(Constants.COMMA);
                    data.append(Constants.COMMA);
                }
            }
            jSon.append(SQUARE_CLOSE);
            jSon.append(SEMI_COLON);
            data.append(SQUARE_CLOSE);
            data.append(SEMI_COLON);
            StringBuilder script = new StringBuilder();
            script.append(SCRIPT_START);
            script.append(jSon.toString());
            script.append(GRAPH_DATA);
            script.append(data.toString());
            script.append(GRAPH_VOLUME_DATA);
            script.append(data.toString());
            script.append(GRAPH_SUMMARY_DATA);
            script.append(data.toString());
            script.append("var flagData = '';");
            script.append(SCRIPT_END);
            ResponseInfo<List<String>> finalOutput = responseDataEvaluation(responseData, null, testResults,
                    RESPONSE_STATUS_SUCCESS, PHRQ600002);
            return Response.ok(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        } catch (Exception e) {
            ResponseInfo<List<String>> finalOutput = responseDataEvaluation(responseData, e, null,
                    RESPONSE_STATUS_ERROR, PHRQ610002);
            return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, "*").build();
        }
    }

    private List<TestResult> getLoadTestResult(String rootModulePath, String subModuleName, String testAgainst,
            String resultFileName, String action)
            throws TransformerException, PhrescoException, ParserConfigurationException, SAXException, IOException {
        List<TestResult> testResults = new ArrayList<TestResult>(2);
        try {
            String testResultPath = getLoadOrPerformanceTestResultPath(rootModulePath, subModuleName, testAgainst,
                    resultFileName, action);

            if (!new File(testResultPath).exists()) {
                throw new PhrescoException(RESULT_FILE_NOT_FOUND);
            }

            Document doc = getDocument(new File(testResultPath));
            NodeList nodeList = org.apache.xpath.XPathAPI.selectNodeList(doc, XPATH_TEST_RESULT);

            TestResult testResult = null;

            for (int i = 0; i < nodeList.getLength(); i++) {
                testResult = new TestResult();
                Node node = nodeList.item(i);
                NamedNodeMap nameNodeMap = node.getAttributes();

                for (int k = 0; k < nameNodeMap.getLength(); k++) {
                    Node attribute = nameNodeMap.item(k);
                    String attributeName = attribute.getNodeName();
                    String attributeValue = attribute.getNodeValue();

                    if (ATTR_JM_TIME.equals(attributeName)) {
                        testResult.setTime(Integer.parseInt(attributeValue));
                    } else if (ATTR_JM_LATENCY_TIME.equals(attributeName)) {
                        testResult.setLatencyTime(Integer.parseInt(attributeValue));
                    } else if (ATTR_JM_TIMESTAMP.equals(attributeName)) {
                        Date date = new Date(Long.parseLong(attributeValue));
                        DateFormat format = new SimpleDateFormat(DATE_TIME_FORMAT);
                        String strDate = format.format(date);
                        testResult.setTimeStamp(strDate);
                    } else if (ATTR_JM_SUCCESS_FLAG.equals(attributeName)) {
                        testResult.setSuccess(Boolean.parseBoolean(attributeValue));
                    } else if (ATTR_JM_LABEL.equals(attributeName)) {
                        testResult.setLabel(attributeValue);
                    } else if (ATTR_JM_THREAD_NAME.equals(attributeName)) {
                        testResult.setThreadName(attributeValue);
                    }
                }
                testResults.add(testResult);
            }
        } catch (Exception e) {
            throw new PhrescoException(e);
        }
        return testResults;
    }

    /**
     * Sets the sets the failure test cases.
     *
     * @param setFailureTestCases the new sets the failure test cases
     */
    public void setSetFailureTestCases(int setFailureTestCases) {
        this.setFailureTestCases = setFailureTestCases;
    }

    /**
     * Gets the sets the failure test cases.
     *
     * @return the sets the failure test cases
     */
    public int getSetFailureTestCases() {
        return setFailureTestCases;
    }

    /**
     * Sets the error test cases.
     *
     * @param errorTestCases the new error test cases
     */
    public void setErrorTestCases(int errorTestCases) {
        this.errorTestCases = errorTestCases;
    }

    /**
     * Gets the error test cases.
     *
     * @return the error test cases
     */
    public int getErrorTestCases() {
        return errorTestCases;
    }

    /**
     * Sets the node length.
     *
     * @param nodeLength the new node length
     */
    public void setNodeLength(int nodeLength) {
        this.nodeLength = nodeLength;
    }

    /**
     * Gets the node length.
     *
     * @return the node length
     */
    public int getNodeLength() {
        return nodeLength;
    }

    /**
     * Gets the test suite.
     *
     * @return the test suite
     */
    public String getTestSuite() {
        return testSuite;
    }

    /**
     * Sets the test suite.
     *
     * @param testSuite the new test suite
     */
    public void setTestSuite(String testSuite) {
        this.testSuite = testSuite;
    }
}