Search in sources :

Example 21 with Parameter

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

the class ReadParameter method findParameterList.

private AnswerItem findParameterList(String system1, ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    parameterService = appContext.getBean(ParameterService.class);
    int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));
    int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));
    /*int sEcho  = Integer.valueOf(request.getParameter("sEcho"));*/
    String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
    int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "2"));
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "para,valC,valS,descr");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
    List<String> individualLike = new ArrayList(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));
    Map<String, List<String>> 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);
            }
        }
    }
    AnswerList resp = parameterService.readWithSystem1BySystemByCriteria("", system1, startPosition, length, columnName, sort, searchParameter, individualSearch);
    JSONArray jsonArray = new JSONArray();
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (Parameter param : (List<Parameter>) resp.getDataList()) {
            param = parameterService.secureParameter(param);
            jsonArray.put(convertParameterToJSONObject(param));
        }
    }
    object.put("hasPermissions", userHasPermissions);
    object.put("contentTable", jsonArray);
    object.put("iTotalRecords", resp.getTotalRows());
    object.put("iTotalDisplayRecords", resp.getTotalRows());
    item.setItem(object);
    item.setResultMessage(resp.getResultMessage());
    return item;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) ParameterService(org.cerberus.crud.service.impl.ParameterService) IParameterService(org.cerberus.crud.service.IParameterService) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) JSONObject(org.json.JSONObject) Parameter(org.cerberus.crud.entity.Parameter) AnswerList(org.cerberus.util.answer.AnswerList)

Example 22 with Parameter

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

the class ReadParameter method findParameterBySystemByKey.

private AnswerItem findParameterBySystemByKey(String system1, String key, Boolean userHasPermissions, ApplicationContext appContext) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    parameterService = appContext.getBean(ParameterService.class);
    AnswerItem answer = parameterService.readWithSystem1ByKey("", key, system1);
    Parameter p = null;
    if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        p = (Parameter) answer.getItem();
        JSONObject response = convertParameterToJSONObject(parameterService.secureParameter(p));
        object.put("contentTable", response);
    }
    object.put("hasPermissions", userHasPermissions);
    object.put("isSecured", parameterService.isToSecureParameter(p));
    object.put("isSystemManaged", parameterService.isSystemManaged(p));
    item.setItem(object);
    item.setResultMessage(answer.getResultMessage());
    return item;
}
Also used : JSONObject(org.json.JSONObject) ParameterService(org.cerberus.crud.service.impl.ParameterService) IParameterService(org.cerberus.crud.service.IParameterService) Parameter(org.cerberus.crud.entity.Parameter) AnswerItem(org.cerberus.util.answer.AnswerItem)

Aggregations

Parameter (org.cerberus.crud.entity.Parameter)22 CerberusException (org.cerberus.exception.CerberusException)12 MessageEvent (org.cerberus.engine.entity.MessageEvent)9 SQLException (java.sql.SQLException)8 AnswerItem (org.cerberus.util.answer.AnswerItem)8 IFactoryParameter (org.cerberus.crud.factory.IFactoryParameter)7 FactoryParameter (org.cerberus.crud.factory.impl.FactoryParameter)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 IParameterService (org.cerberus.crud.service.IParameterService)4 JSONObject (org.json.JSONObject)4 File (java.io.File)3 MessageGeneral (org.cerberus.engine.entity.MessageGeneral)3 AnswerList (org.cerberus.util.answer.AnswerList)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ParameterService (org.cerberus.crud.service.impl.ParameterService)2