Search in sources :

Example 1 with CountryEnvParam_log

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

the class CountryEnvParam_logDAO method readByKey.

@Override
public AnswerItem readByKey(long id) {
    AnswerItem ans = new AnswerItem();
    CountryEnvParam_log result = null;
    final String query = "SELECT * FROM countryenvparam_log WHERE id = ?";
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setLong(1, id);
            ResultSet resultSet = preStat.executeQuery();
            try {
                if (resultSet.first()) {
                    result = loadFromResultSet(resultSet);
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                    msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
                    ans.setItem(result);
                } else {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to close connection : " + exception.toString());
        }
    }
    // sets the message
    ans.setResultMessage(msg);
    return ans;
}
Also used : SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) AnswerItem(org.cerberus.util.answer.AnswerItem) CountryEnvParam_log(org.cerberus.crud.entity.CountryEnvParam_log) IFactoryCountryEnvParam_log(org.cerberus.crud.factory.IFactoryCountryEnvParam_log)

Example 2 with CountryEnvParam_log

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

the class CountryEnvParam_logDAO method readByVariousByCriteria.

@Override
public AnswerList readByVariousByCriteria(String system, String country, String environment, String build, String revision, int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) {
    AnswerList response = new AnswerList();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    List<CountryEnvParam_log> countryEnvParamLogList = new ArrayList<CountryEnvParam_log>();
    StringBuilder searchSQL = new StringBuilder();
    List<String> individalColumnSearchValues = new ArrayList<String>();
    StringBuilder query = new StringBuilder();
    // SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that
    // were applied -- used for pagination p
    query.append("SELECT SQL_CALC_FOUND_ROWS * FROM countryenvparam_log ");
    searchSQL.append(" where 1=1 ");
    if (!StringUtil.isNullOrEmpty(searchTerm)) {
        searchSQL.append(" and (`id` like ?");
        searchSQL.append(" or `system` like ?");
        searchSQL.append(" or `Country` like ?");
        searchSQL.append(" or `Environment` like ?");
        searchSQL.append(" or `Build` like ?");
        searchSQL.append(" or `Revision` like ?");
        searchSQL.append(" or `Chain` like ?");
        searchSQL.append(" or `Description` like ?");
        searchSQL.append(" or `datecre` like ?");
        searchSQL.append(" or `Creator` like ?)");
    }
    if (individualSearch != null && !individualSearch.isEmpty()) {
        searchSQL.append(" and ( 1=1 ");
        for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {
            searchSQL.append(" and ");
            searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));
            individalColumnSearchValues.addAll(entry.getValue());
        }
        searchSQL.append(" )");
    }
    if (!StringUtil.isNullOrEmpty(system)) {
        searchSQL.append(" and (`system` = ?)");
    }
    if (!StringUtil.isNullOrEmpty(country)) {
        searchSQL.append(" and (`country` = ?)");
    }
    if (!StringUtil.isNullOrEmpty(environment)) {
        searchSQL.append(" and (`environment` = ?)");
    }
    if (!StringUtil.isNullOrEmpty(build)) {
        searchSQL.append(" and (`build` = ?)");
    }
    if (!StringUtil.isNullOrEmpty(revision)) {
        searchSQL.append(" and (`revision` = ?)");
    }
    query.append(searchSQL);
    if (!StringUtil.isNullOrEmpty(column)) {
        query.append(" order by `").append(column).append("` ").append(dir);
    }
    if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {
        query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);
    } else {
        query.append(" limit ").append(start).append(" , ").append(amount);
    }
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query.toString());
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            int i = 1;
            if (!Strings.isNullOrEmpty(searchTerm)) {
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
                preStat.setString(i++, "%" + searchTerm + "%");
            }
            for (String individualColumnSearchValue : individalColumnSearchValues) {
                preStat.setString(i++, individualColumnSearchValue);
            }
            if (!StringUtil.isNullOrEmpty(system)) {
                preStat.setString(i++, system);
            }
            if (!StringUtil.isNullOrEmpty(country)) {
                preStat.setString(i++, country);
            }
            if (!StringUtil.isNullOrEmpty(environment)) {
                preStat.setString(i++, environment);
            }
            if (!StringUtil.isNullOrEmpty(build)) {
                preStat.setString(i++, build);
            }
            if (!StringUtil.isNullOrEmpty(revision)) {
                preStat.setString(i++, revision);
            }
            ResultSet resultSet = preStat.executeQuery();
            try {
                // gets the data
                while (resultSet.next()) {
                    countryEnvParamLogList.add(this.loadFromResultSet(resultSet));
                }
                // get the total number of rows
                resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");
                int nrTotalRows = 0;
                if (resultSet != null && resultSet.next()) {
                    nrTotalRows = resultSet.getInt(1);
                }
                if (countryEnvParamLogList.size() >= MAX_ROW_SELECTED) {
                    // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.
                    LOG.error("Partial Result in the query.");
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
                    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
                    response = new AnswerList(countryEnvParamLogList, nrTotalRows);
                } else if (countryEnvParamLogList.size() <= 0) {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
                    response = new AnswerList(countryEnvParamLogList, nrTotalRows);
                } else {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                    msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
                    response = new AnswerList(countryEnvParamLogList, nrTotalRows);
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
            } finally {
                if (resultSet != null) {
                    resultSet.close();
                }
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
    } finally {
        try {
            if (!this.databaseSpring.isOnTransaction()) {
                if (connection != null) {
                    connection.close();
                }
            }
        } catch (SQLException exception) {
            LOG.error("Unable to close connection : " + exception.toString());
        }
    }
    response.setResultMessage(msg);
    response.setDataList(countryEnvParamLogList);
    return response;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) CountryEnvParam_log(org.cerberus.crud.entity.CountryEnvParam_log) IFactoryCountryEnvParam_log(org.cerberus.crud.factory.IFactoryCountryEnvParam_log) ResultSet(java.sql.ResultSet) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 3 with CountryEnvParam_log

use of org.cerberus.crud.entity.CountryEnvParam_log 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 4 with CountryEnvParam_log

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

the class FactoryCountryEnvParam_log method create.

@Override
public CountryEnvParam_log create(String system, String country, String environment, String build, String revision, int chain, String description, String creator) {
    CountryEnvParam_log newCountryEnvParamLog = new CountryEnvParam_log();
    newCountryEnvParamLog.setSystem(system);
    newCountryEnvParamLog.setCountry(country);
    newCountryEnvParamLog.setEnvironment(environment);
    newCountryEnvParamLog.setBuild(build);
    newCountryEnvParamLog.setRevision(revision);
    newCountryEnvParamLog.setChain(chain);
    newCountryEnvParamLog.setDescription(description);
    newCountryEnvParamLog.setCreator(creator);
    return newCountryEnvParamLog;
}
Also used : IFactoryCountryEnvParam_log(org.cerberus.crud.factory.IFactoryCountryEnvParam_log) CountryEnvParam_log(org.cerberus.crud.entity.CountryEnvParam_log)

Example 5 with CountryEnvParam_log

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

the class ReadCountryEnvParam_log method findCountryEnvParamList.

// </editor-fold>
private AnswerItem findCountryEnvParamList(String system, String country, String environment, ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    ceplService = appContext.getBean(ICountryEnvParam_logService.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"), "ID,system,country,Environment,Build,Revision,Chain,Disable,datecre,creator");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
    Map<String, List<String>> individualSearch = new HashMap<String, List<String>>();
    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(",")));
            individualSearch.put(columnToSort[a], search);
        }
    }
    AnswerList resp = ceplService.readByVariousByCriteria(system, country, environment, null, null, 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 (CountryEnvParam_log cepl : (List<CountryEnvParam_log>) resp.getDataList()) {
            jsonArray.put(convertCountryEnvParamtoJSONObject(cepl));
        }
    }
    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) AnswerItem(org.cerberus.util.answer.AnswerItem) CountryEnvParam_log(org.cerberus.crud.entity.CountryEnvParam_log) ICountryEnvParam_logService(org.cerberus.crud.service.ICountryEnvParam_logService) JSONObject(org.json.JSONObject) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

CountryEnvParam_log (org.cerberus.crud.entity.CountryEnvParam_log)7 IFactoryCountryEnvParam_log (org.cerberus.crud.factory.IFactoryCountryEnvParam_log)5 AnswerList (org.cerberus.util.answer.AnswerList)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 MessageEvent (org.cerberus.engine.entity.MessageEvent)3 AnswerItem (org.cerberus.util.answer.AnswerItem)3 ICountryEnvParam_logService (org.cerberus.crud.service.ICountryEnvParam_logService)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Invariant (org.cerberus.crud.entity.Invariant)1 IInvariantService (org.cerberus.crud.service.IInvariantService)1