Search in sources :

Example 11 with Invariant

use of org.cerberus.crud.entity.Invariant in project cerberus-source by cerberustesting.

the class FindInvariantByID method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException, JSONException {
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
    String idName = policy.sanitize(request.getParameter("idName"));
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    response.setContentType("application/json");
    response.setCharacterEncoding("utf8");
    // Calling Servlet Transversal Util.
    ServletUtil.servletStart(request);
    IInvariantService invariantService = appContext.getBean(InvariantService.class);
    JSONArray array = new JSONArray();
    // TODO: handle if the response does not turn ok
    AnswerList answer = invariantService.readByIdname(idName);
    for (Invariant myInvariant : (List<Invariant>) answer.getDataList()) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("value", myInvariant.getValue());
        jsonObject.put("description", myInvariant.getDescription());
        array.put(jsonObject);
    }
    response.getWriter().print(array.toString());
}
Also used : Invariant(org.cerberus.crud.entity.Invariant) ApplicationContext(org.springframework.context.ApplicationContext) AnswerList(org.cerberus.util.answer.AnswerList) PolicyFactory(org.owasp.html.PolicyFactory) JSONObject(org.json.JSONObject) IInvariantService(org.cerberus.crud.service.IInvariantService) JSONArray(org.json.JSONArray) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List)

Example 12 with Invariant

use of org.cerberus.crud.entity.Invariant in project cerberus-source by cerberustesting.

the class GetInvariantList method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String id = request.getParameter("idName");
    String idName = ParameterParserUtil.parseStringParam(id, "");
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IInvariantService invariantService = appContext.getBean(InvariantService.class);
    JSONObject jsonResponse = new JSONObject();
    String action = request.getParameter("action");
    try {
        if (request.getParameter("action") != null) {
            // retrieve all the information in one client call
            if ("getNInvariant".equals(action)) {
                // gets a list of invariants
                JSONObject listOfInvariants = new JSONObject(idName);
                for (int i = 0; i < listOfInvariants.length(); i++) {
                    String invariantName = (String) listOfInvariants.get(String.valueOf(i));
                    JSONArray array = new JSONArray();
                    // TODO: handle if the response does not turn ok
                    AnswerList answer = invariantService.readByIdname(invariantName);
                    for (Invariant myInvariant : (List<Invariant>) answer.getDataList()) {
                        array.put(myInvariant.getValue());
                    }
                    jsonResponse.put(invariantName, array);
                }
            }
        } else {
            // gets one item
            // TODO: handle if the response does not turn ok
            AnswerList answer = invariantService.readByIdname(idName);
            for (Invariant myInvariant : (List<Invariant>) answer.getDataList()) {
                jsonResponse.put(myInvariant.getValue(), myInvariant.getValue());
            }
        }
        response.setContentType("application/json");
        response.getWriter().print(jsonResponse.toString());
    } catch (JSONException e) {
        LOG.warn(e);
        response.setContentType("text/html");
        response.getWriter().print(e.getMessage());
    }
}
Also used : Invariant(org.cerberus.crud.entity.Invariant) ApplicationContext(org.springframework.context.ApplicationContext) AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) IInvariantService(org.cerberus.crud.service.IInvariantService) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List)

Example 13 with Invariant

use of org.cerberus.crud.entity.Invariant in project cerberus-source by cerberustesting.

the class InvariantService method readToHashMapGp1IntegerByIdname.

@Override
public HashMap<String, Integer> readToHashMapGp1IntegerByIdname(String idName, Integer defaultValue) {
    HashMap<String, Integer> result = new HashMap<String, Integer>();
    // TODO: handle if the response does not turn ok
    AnswerList answer = readByIdname(idName);
    for (Invariant inv : (List<Invariant>) answer.getDataList()) {
        int gp1ToInt = ParameterParserUtil.parseIntegerParam(inv.getGp1(), defaultValue);
        result.put(inv.getValue(), gp1ToInt);
    }
    return result;
}
Also used : Invariant(org.cerberus.crud.entity.Invariant) AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with Invariant

use of org.cerberus.crud.entity.Invariant in project cerberus-source by cerberustesting.

the class ReadTestCaseExecution method findValuesForColumnFilter.

/**
 * Find Values to display for Column Filter
 *
 * @param system
 * @param test
 * @param appContext
 * @param request
 * @param columnName
 * @return
 * @throws JSONException
 */
private AnswerItem findValuesForColumnFilter(String system, String test, ApplicationContext appContext, HttpServletRequest request, String columnName) throws JSONException {
    AnswerItem answer = new AnswerItem();
    JSONObject object = new JSONObject();
    AnswerList values = new AnswerList();
    Map<String, List<String>> individualSearch = new HashMap<>();
    testCaseService = appContext.getBean(TestCaseService.class);
    invariantService = appContext.getBean(InvariantService.class);
    buildRevisionInvariantService = appContext.getBean(BuildRevisionInvariantService.class);
    applicationService = appContext.getBean(ApplicationService.class);
    LOG.debug(columnName);
    switch(columnName) {
        /**
         * Columns from Status
         */
        case "exe.controlStatus":
            List<String> dataList = new ArrayList<>();
            dataList.add(TestCaseExecution.CONTROLSTATUS_CA);
            dataList.add(TestCaseExecution.CONTROLSTATUS_FA);
            dataList.add(TestCaseExecution.CONTROLSTATUS_KO);
            dataList.add(TestCaseExecution.CONTROLSTATUS_NA);
            dataList.add(TestCaseExecution.CONTROLSTATUS_NE);
            dataList.add(TestCaseExecution.CONTROLSTATUS_OK);
            dataList.add(TestCaseExecution.CONTROLSTATUS_PE);
            values.setDataList(dataList);
            MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
            msg.setDescription(msg.getDescription().replace("%ITEM%", "execution").replace("%OPERATION%", "SELECT"));
            values.setResultMessage(msg);
            break;
        /**
         * For columns test and testcase, get distinct values from test
         * table
         */
        case "exe.test":
        case "exe.testcase":
        case "exe.status":
            values = testCaseService.readDistinctValuesByCriteria(system, test, "", null, columnName.replace("exe.", "tec."));
            break;
        /**
         * For columns country, environment get values from invariant
         */
        case "exe.country":
        case "exe.environment":
            try {
                /**
                 */
                AnswerList<Invariant> invariants = invariantService.readByIdname(columnName.replace("exe.", ""));
                List<Invariant> invariantList = invariantService.convert(invariants);
                List<String> stringResult = new ArrayList();
                for (Invariant inv : invariantList) {
                    stringResult.add(inv.getValue());
                }
                values.setDataList(stringResult);
                values.setTotalRows(invariantList.size());
                values.setResultMessage(invariants.getResultMessage());
            } catch (CerberusException ex) {
                LOG.warn(ex);
            }
            break;
        /**
         * For columns build, revision get values from
         * buildrevisioninvariant
         */
        case "exe.build":
        case "exe.revision":
            individualSearch = new HashMap<>();
            individualSearch.put("level", new ArrayList(Arrays.asList(columnName.equals("exe.build") ? "1" : "2")));
            values = buildRevisionInvariantService.readDistinctValuesByCriteria(system, "", individualSearch, "versionName");
            break;
        /**
         * For columns application get values from application
         */
        case "exe.application":
            values = applicationService.readDistinctValuesByCriteria(system, "", null, columnName.replace("exe.", ""));
            break;
        /**
         * For all other columns, get distinct values from testcaseexecution
         */
        default:
            String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
            String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "tec.test,tec.testcase,application,project,ticket,description,behaviororvalueexpected,readonly,bugtrackernewurl,deploytype,mavengroupid");
            String[] columnToSort = sColumns.split(",");
            List<String> individualLike = new ArrayList(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));
            individualSearch = new HashMap<>();
            for (int a = 0; a < columnToSort.length; a++) {
                if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {
                    List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));
                    if (individualLike.contains(columnToSort[a])) {
                        individualSearch.put(columnToSort[a] + ":like", search);
                    } else {
                        individualSearch.put(columnToSort[a], search);
                    }
                }
            }
            values = testCaseExecutionService.readDistinctValuesByCriteria(system, test, searchParameter, individualSearch, columnName);
    }
    object.put("distinctValues", values.getDataList());
    answer.setItem(object);
    answer.setResultMessage(values.getResultMessage());
    return answer;
}
Also used : Invariant(org.cerberus.crud.entity.Invariant) AnswerList(org.cerberus.util.answer.AnswerList) CerberusException(org.cerberus.exception.CerberusException) BuildRevisionInvariantService(org.cerberus.crud.service.impl.BuildRevisionInvariantService) IBuildRevisionInvariantService(org.cerberus.crud.service.IBuildRevisionInvariantService) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) ITestCaseService(org.cerberus.crud.service.ITestCaseService) TestCaseService(org.cerberus.crud.service.impl.TestCaseService) AnswerItem(org.cerberus.util.answer.AnswerItem) JSONObject(org.json.JSONObject) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) ArrayList(java.util.ArrayList) InvariantService(org.cerberus.crud.service.impl.InvariantService) BuildRevisionInvariantService(org.cerberus.crud.service.impl.BuildRevisionInvariantService) IInvariantService(org.cerberus.crud.service.IInvariantService) IBuildRevisionInvariantService(org.cerberus.crud.service.IBuildRevisionInvariantService) ApplicationService(org.cerberus.crud.service.impl.ApplicationService) IApplicationService(org.cerberus.crud.service.IApplicationService)

Example 15 with Invariant

use of org.cerberus.crud.entity.Invariant in project cerberus-source by cerberustesting.

the class ReadTestCaseExecution method getCountryList.

private JSONObject getCountryList(HttpServletRequest request, ApplicationContext appContext) {
    JSONObject countryList = new JSONObject();
    try {
        IInvariantService invariantService = appContext.getBean(InvariantService.class);
        // TODO: handle if the response does not turn ok
        AnswerList answer = invariantService.readByIdname("COUNTRY");
        for (Invariant country : (List<Invariant>) answer.getDataList()) {
            countryList.put(country.getValue(), ParameterParserUtil.parseStringParam(request.getParameter(country.getValue()), "off"));
        }
    } catch (JSONException ex) {
        LOG.warn(ex);
    }
    return countryList;
}
Also used : Invariant(org.cerberus.crud.entity.Invariant) AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) IInvariantService(org.cerberus.crud.service.IInvariantService) JSONException(org.json.JSONException) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

Invariant (org.cerberus.crud.entity.Invariant)28 AnswerList (org.cerberus.util.answer.AnswerList)18 IInvariantService (org.cerberus.crud.service.IInvariantService)15 JSONObject (org.json.JSONObject)15 ArrayList (java.util.ArrayList)13 List (java.util.List)11 MessageEvent (org.cerberus.engine.entity.MessageEvent)10 IFactoryInvariant (org.cerberus.crud.factory.IFactoryInvariant)8 JSONArray (org.json.JSONArray)8 ApplicationContext (org.springframework.context.ApplicationContext)8 Connection (java.sql.Connection)7 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 SQLException (java.sql.SQLException)7 AnswerItem (org.cerberus.util.answer.AnswerItem)7 JSONException (org.json.JSONException)7 HashMap (java.util.HashMap)6 CerberusException (org.cerberus.exception.CerberusException)5 PolicyFactory (org.owasp.html.PolicyFactory)4 IOException (java.io.IOException)3