Search in sources :

Example 76 with AnswerList

use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.

the class GetEnvironmentsPerBuildRevision method findBuildRevList.

private AnswerItem findBuildRevList(String system, ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    envService = appContext.getBean(IEnvironmentStatisticsService.class);
    cepService = appContext.getBean(ICountryEnvParamService.class);
    AnswerList resp = envService.getEnvironmentStatistics(system);
    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 (BuildRevisionStatisticsEnv buildRevStat : (List<BuildRevisionStatisticsEnv>) resp.getDataList()) {
            jsonArray.put(convertToJSONObject(buildRevStat));
        }
    }
    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 : IEnvironmentStatisticsService(org.cerberus.statistics.IEnvironmentStatisticsService) AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) BuildRevisionStatisticsEnv(org.cerberus.statistics.BuildRevisionStatisticsEnv) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) ICountryEnvParamService(org.cerberus.crud.service.ICountryEnvParamService) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 77 with AnswerList

use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.

the class GetEnvironmentsLastChangePerCountry method findBuildRevList.

private AnswerItem findBuildRevList(String system, String envGp, Integer nbDays, ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    invariantService = appContext.getBean(IInvariantService.class);
    ceplService = appContext.getBean(ICountryEnvParam_logService.class);
    AnswerList resp = invariantService.readCountryListEnvironmentLastChanges(system, nbDays);
    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 (Invariant countryInvariant : (List<Invariant>) resp.getDataList()) {
            JSONObject countryJSON;
            countryJSON = convertToJSONObject(countryInvariant);
            AnswerList resp1 = ceplService.readLastChanges(system, countryInvariant.getValue(), nbDays, envGp);
            JSONArray jsonArray1 = new JSONArray();
            if (resp1.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                // the service was able to perform the query, then we should get all values
                for (CountryEnvParam_log countryepl : (List<CountryEnvParam_log>) resp1.getDataList()) {
                    jsonArray1.put(convertToJSONObject(countryepl));
                }
            }
            countryJSON.put("contentTable", jsonArray1);
            jsonArray.put(countryJSON);
        }
    }
    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 : ICountryEnvParam_logService(org.cerberus.crud.service.ICountryEnvParam_logService) Invariant(org.cerberus.crud.entity.Invariant) AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) IInvariantService(org.cerberus.crud.service.IInvariantService) JSONArray(org.json.JSONArray) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) AnswerItem(org.cerberus.util.answer.AnswerItem) CountryEnvParam_log(org.cerberus.crud.entity.CountryEnvParam_log)

Example 78 with AnswerList

use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.

the class ReadLabel method findLabelList.

// </editor-fold>
private AnswerItem findLabelList(String system, ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    labelService = appContext.getBean(LabelService.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"), "1"));
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "System,Label,Color,Display,parentLabelId,Description");
    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 = labelService.readBySystemByCriteria(system, 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 (Label label : (List<Label>) resp.getDataList()) {
            JSONObject labelObject = convertLabelToJSONObject(label);
            if (!"".equals(label.getParentLabel())) {
                AnswerItem parentLabel = labelService.readByKey(Integer.valueOf(label.getParentLabel()));
                if (parentLabel.getItem() != null) {
                    labelObject.put("labelParentObject", convertLabelToJSONObject((Label) parentLabel.getItem()));
                }
            }
            jsonArray.put(labelObject);
        }
    }
    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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) Label(org.cerberus.crud.entity.Label) AnswerItem(org.cerberus.util.answer.AnswerItem) JSONObject(org.json.JSONObject) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) ILabelService(org.cerberus.crud.service.ILabelService) LabelService(org.cerberus.crud.service.impl.LabelService)

Example 79 with AnswerList

use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.

the class ReadLogEvent method findDistinctValuesOfColumn.

private AnswerItem findDistinctValuesOfColumn(ApplicationContext appContext, HttpServletRequest request, String columnName) throws JSONException {
    AnswerItem answer = new AnswerItem();
    JSONObject object = new JSONObject();
    logEventService = appContext.getBean(ILogEventService.class);
    String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "Time,login,Page,Action,log");
    String[] columnToSort = sColumns.split(",");
    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 logList = logEventService.readDistinctValuesByCriteria(searchParameter, individualSearch, columnName);
    object.put("distinctValues", logList.getDataList());
    answer.setItem(object);
    answer.setResultMessage(logList.getResultMessage());
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ILogEventService(org.cerberus.crud.service.ILogEventService) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 80 with AnswerList

use of org.cerberus.util.answer.AnswerList in project cerberus-source by cerberustesting.

the class ReadUser method findUserList.

// </editor-fold>
private AnswerItem findUserList(ApplicationContext appContext, HttpServletRequest request, HttpServletResponse response) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject jsonResponse = new JSONObject();
    userService = appContext.getBean(UserService.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"), "1"));
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "userID,login,name");
    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 = userService.readByCriteria(startPosition, length, columnName, sort, searchParameter, individualSearch);
    JSONArray jsonArray = new JSONArray();
    boolean userHasPermissions = request.isUserInRole("IntegratorRO");
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (User user : (List<User>) resp.getDataList()) {
            JSONObject res = convertUserToJSONObject(user);
            if (request.getParameter("systems") != null) {
                IUserSystemService userSystemService = appContext.getBean(IUserSystemService.class);
                AnswerList a = userSystemService.readByUser(user.getLogin());
                if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && a.getDataList() != null) {
                    JSONArray JSONsystems = new JSONArray();
                    List<UserSystem> systems = a.getDataList();
                    for (UserSystem u : systems) {
                        JSONsystems.put(convertUserSystemToJSONObject(u));
                    }
                    res.put("systems", JSONsystems);
                }
            }
            if (request.getParameter("groups") != null) {
                IUserGroupService userGroupService = appContext.getBean(UserGroupService.class);
                AnswerList a = userGroupService.readByUser(user.getLogin());
                if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && a.getDataList() != null) {
                    JSONArray JSONgroups = new JSONArray();
                    List<UserGroup> groups = a.getDataList();
                    for (UserGroup u : groups) {
                        JSONgroups.put(convertUserGroupToJSONObject(u));
                    }
                    res.put("groups", JSONgroups);
                }
            }
            jsonArray.put(res);
        }
    }
    jsonResponse.put("hasPermissions", userHasPermissions);
    jsonResponse.put("contentTable", jsonArray);
    jsonResponse.put("iTotalRecords", resp.getTotalRows());
    jsonResponse.put("iTotalDisplayRecords", resp.getTotalRows());
    item.setItem(jsonResponse);
    item.setResultMessage(resp.getResultMessage());
    return item;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) User(org.cerberus.crud.entity.User) UserSystem(org.cerberus.crud.entity.UserSystem) IUserService(org.cerberus.crud.service.IUserService) UserService(org.cerberus.crud.service.impl.UserService) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) IUserGroupService(org.cerberus.crud.service.IUserGroupService) UserGroup(org.cerberus.crud.entity.UserGroup) JSONObject(org.json.JSONObject) AnswerList(org.cerberus.util.answer.AnswerList) IUserSystemService(org.cerberus.crud.service.IUserSystemService)

Aggregations

AnswerList (org.cerberus.util.answer.AnswerList)258 ArrayList (java.util.ArrayList)197 MessageEvent (org.cerberus.engine.entity.MessageEvent)152 List (java.util.List)146 Connection (java.sql.Connection)120 PreparedStatement (java.sql.PreparedStatement)120 ResultSet (java.sql.ResultSet)120 SQLException (java.sql.SQLException)120 JSONObject (org.json.JSONObject)90 AnswerItem (org.cerberus.util.answer.AnswerItem)89 Map (java.util.Map)69 HashMap (java.util.HashMap)65 JSONArray (org.json.JSONArray)62 Statement (java.sql.Statement)35 CerberusException (org.cerberus.exception.CerberusException)20 Invariant (org.cerberus.crud.entity.Invariant)18 IInvariantService (org.cerberus.crud.service.IInvariantService)15 TestCase (org.cerberus.crud.entity.TestCase)14 LinkedHashMap (java.util.LinkedHashMap)11 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)11