Search in sources :

Example 1 with BuildRevisionBatch

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

the class BuildRevisionBatchDAO method readByKey.

@Override
public AnswerItem readByKey(long id) {
    AnswerItem ans = new AnswerItem();
    BuildRevisionBatch result = null;
    final String query = "SELECT * FROM buildrevisionbatch 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 : BuildRevisionBatch(org.cerberus.crud.entity.BuildRevisionBatch) IFactoryBuildRevisionBatch(org.cerberus.crud.factory.IFactoryBuildRevisionBatch) 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)

Example 2 with BuildRevisionBatch

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

the class BuildRevisionBatchDAO method readByVariousByCriteria.

@Override
public AnswerList readByVariousByCriteria(String system, String country, String environment, int start, int amount, String column, String dir, String searchTerm, String individualSearch) {
    AnswerList response = new AnswerList();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    List<BuildRevisionBatch> resultList = new ArrayList<BuildRevisionBatch>();
    StringBuilder searchSQL = new StringBuilder();
    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 buildrevisionbatch ");
    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 `Batch` like ?");
        searchSQL.append(" or `DateBatch` like ?)");
    }
    if (!StringUtil.isNullOrEmpty(individualSearch)) {
        searchSQL.append(" and ( ? )");
    }
    if (!StringUtil.isNullOrEmpty(system)) {
        searchSQL.append(" and (`system` = ?)");
    }
    if (!StringUtil.isNullOrEmpty(country)) {
        searchSQL.append(" and (`country` = ?)");
    }
    if (!StringUtil.isNullOrEmpty(environment)) {
        searchSQL.append(" and (`environment` = ?)");
    }
    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 + "%");
            }
            if (!StringUtil.isNullOrEmpty(individualSearch)) {
                preStat.setString(i++, individualSearch);
            }
            if (!StringUtil.isNullOrEmpty(system)) {
                preStat.setString(i++, system);
            }
            if (!StringUtil.isNullOrEmpty(country)) {
                preStat.setString(i++, country);
            }
            if (!StringUtil.isNullOrEmpty(environment)) {
                preStat.setString(i++, environment);
            }
            ResultSet resultSet = preStat.executeQuery();
            try {
                // gets the data
                while (resultSet.next()) {
                    resultList.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 (resultList.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(resultList, nrTotalRows);
                } else if (resultList.size() <= 0) {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
                    response = new AnswerList(resultList, nrTotalRows);
                } else {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                    msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
                    response = new AnswerList(resultList, 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(resultList);
    return response;
}
Also used : BuildRevisionBatch(org.cerberus.crud.entity.BuildRevisionBatch) IFactoryBuildRevisionBatch(org.cerberus.crud.factory.IFactoryBuildRevisionBatch) AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 3 with BuildRevisionBatch

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

the class FactoryBuildRevisionBatch method create.

@Override
public BuildRevisionBatch create(String system, String country, String environment, String build, String revision, String batch) {
    BuildRevisionBatch newObject = new BuildRevisionBatch();
    newObject.setSystem(system);
    newObject.setCountry(country);
    newObject.setEnvironment(environment);
    newObject.setBuild(build);
    newObject.setRevision(revision);
    newObject.setBatch(batch);
    return newObject;
}
Also used : BuildRevisionBatch(org.cerberus.crud.entity.BuildRevisionBatch) IFactoryBuildRevisionBatch(org.cerberus.crud.factory.IFactoryBuildRevisionBatch)

Example 4 with BuildRevisionBatch

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

the class FactoryBuildRevisionBatch method create.

@Override
public BuildRevisionBatch create(long id, String system, String country, String environment, String build, String revision, String batch, Timestamp dateBatch) {
    BuildRevisionBatch newObject = new BuildRevisionBatch();
    newObject.setId(id);
    newObject.setSystem(system);
    newObject.setCountry(country);
    newObject.setEnvironment(environment);
    newObject.setBuild(build);
    newObject.setRevision(revision);
    newObject.setBatch(batch);
    newObject.setDateBatch(dateBatch);
    return newObject;
}
Also used : BuildRevisionBatch(org.cerberus.crud.entity.BuildRevisionBatch) IFactoryBuildRevisionBatch(org.cerberus.crud.factory.IFactoryBuildRevisionBatch)

Example 5 with BuildRevisionBatch

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

the class ReadBuildRevisionBatch method findBuildRevisionBatchList.

// </editor-fold>
private AnswerItem findBuildRevisionBatchList(String system, String country, String environment, ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    brbService = appContext.getBean(IBuildRevisionBatchService.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,Batch,DateBatch");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
    AnswerList resp = brbService.readByVariousByCriteria(system, country, environment, startPosition, length, columnName, sort, searchParameter, "");
    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 (BuildRevisionBatch brb : (List<BuildRevisionBatch>) resp.getDataList()) {
            jsonArray.put(convertToJSONObject(brb));
        }
    }
    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 : BuildRevisionBatch(org.cerberus.crud.entity.BuildRevisionBatch) AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) AnswerItem(org.cerberus.util.answer.AnswerItem) IBuildRevisionBatchService(org.cerberus.crud.service.IBuildRevisionBatchService)

Aggregations

BuildRevisionBatch (org.cerberus.crud.entity.BuildRevisionBatch)5 IFactoryBuildRevisionBatch (org.cerberus.crud.factory.IFactoryBuildRevisionBatch)4 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 MessageEvent (org.cerberus.engine.entity.MessageEvent)2 AnswerItem (org.cerberus.util.answer.AnswerItem)2 AnswerList (org.cerberus.util.answer.AnswerList)2 List (java.util.List)1 IBuildRevisionBatchService (org.cerberus.crud.service.IBuildRevisionBatchService)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1