Search in sources :

Example 6 with CampaignParameter

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

the class ReadCampaignParameter method findParameterListByCampaign.

// </editor-fold>
private AnswerItem findParameterListByCampaign(ApplicationContext appContext, HttpServletRequest request, HttpServletResponse response, String campaign) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject jsonResponse = new JSONObject();
    campaignParameterService = appContext.getBean(ICampaignParameterService.class);
    int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));
    int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));
    String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
    int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "0"));
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "campaignparameterid,campaign,parameter,value");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
    AnswerList resp = campaignParameterService.readByCampaignByCriteria(campaign, 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 (CampaignParameter param : (List<CampaignParameter>) resp.getDataList()) {
            jsonArray.put(convertProjectToJSONObject(param));
        }
    }
    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) JSONObject(org.json.JSONObject) ICampaignParameterService(org.cerberus.crud.service.ICampaignParameterService) JSONArray(org.json.JSONArray) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) AnswerItem(org.cerberus.util.answer.AnswerItem) CampaignParameter(org.cerberus.crud.entity.CampaignParameter)

Example 7 with CampaignParameter

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

the class ReadCampaign method findCampaignByKey.

private AnswerItem findCampaignByKey(String key, Boolean userHasPermissions, ApplicationContext appContext, HttpServletRequest request) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    campaignService = appContext.getBean(ICampaignService.class);
    AnswerItem answer = campaignService.readByKey(key);
    Campaign p;
    if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        p = (Campaign) answer.getItem();
        JSONObject response = convertCampaigntoJSONObject(p);
        if (request.getParameter("parameter") != null) {
            ICampaignParameterService campaignParameterService = appContext.getBean(ICampaignParameterService.class);
            AnswerList resp = campaignParameterService.readByCampaign(key);
            if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                // the service was able to perform the query, then we should get all values
                JSONArray a = new JSONArray();
                for (Object c : resp.getDataList()) {
                    CampaignParameter cc = (CampaignParameter) c;
                    a.put(convertCampaignParametertoJSONObject(cc));
                }
                response.put("parameter", a);
            }
        }
        if (request.getParameter("label") != null) {
            ICampaignLabelService campaignLabelService = appContext.getBean(ICampaignLabelService.class);
            AnswerList resp = campaignLabelService.readByVarious(key);
            if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                // the service was able to perform the query, then we should get all values
                JSONArray a = new JSONArray();
                for (Object c : resp.getDataList()) {
                    CampaignLabel cc = (CampaignLabel) c;
                    a.put(convertCampaignLabeltoJSONObject(cc));
                }
                response.put("label", a);
            }
        }
        if (request.getParameter("testcase") != null) {
            ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);
            String[] campaignList = new String[1];
            campaignList[0] = key;
            AnswerItem<List<TestCase>> resp = testCaseService.findTestCaseByCampaignNameAndCountries(key, null);
            if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                // the service was able to perform the query, then we should get all values
                JSONArray a = new JSONArray();
                for (Object c : resp.getItem()) {
                    TestCase cc = (TestCase) c;
                    a.put(convertTestCasetoJSONObject(cc));
                }
                response.put("testcase", a);
            }
        }
        object.put("contentTable", response);
    }
    object.put("hasPermissions", userHasPermissions);
    item.setItem(object);
    item.setResultMessage(answer.getResultMessage());
    return item;
}
Also used : ICampaignService(org.cerberus.crud.service.ICampaignService) AnswerList(org.cerberus.util.answer.AnswerList) ICampaignParameterService(org.cerberus.crud.service.ICampaignParameterService) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) CampaignParameter(org.cerberus.crud.entity.CampaignParameter) Campaign(org.cerberus.crud.entity.Campaign) JSONObject(org.json.JSONObject) TestCase(org.cerberus.crud.entity.TestCase) ITestCaseService(org.cerberus.crud.service.ITestCaseService) JSONObject(org.json.JSONObject) ICampaignLabelService(org.cerberus.crud.service.ICampaignLabelService) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) CampaignLabel(org.cerberus.crud.entity.CampaignLabel)

Example 8 with CampaignParameter

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

the class CampaignParameterDAO method findAll.

@Override
public List<CampaignParameter> findAll() throws CerberusException {
    boolean throwEx = false;
    final String query = "SELECT * FROM campaignparameter c";
    List<CampaignParameter> campaignParameterList = new ArrayList<CampaignParameter>();
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        try (ResultSet resultSet = preStat.executeQuery()) {
            while (resultSet.next()) {
                campaignParameterList.add(this.loadFromResultSet(resultSet));
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
            campaignParameterList = null;
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
        campaignParameterList = null;
    }
    if (throwEx) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
    }
    return campaignParameterList;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IFactoryCampaignParameter(org.cerberus.crud.factory.IFactoryCampaignParameter) CampaignParameter(org.cerberus.crud.entity.CampaignParameter)

Example 9 with CampaignParameter

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

the class CampaignParameterDAO method readByCampaign.

@Override
public AnswerList readByCampaign(String campaign) {
    AnswerList answer = new AnswerList();
    MessageEvent msg;
    List<CampaignParameter> result = new ArrayList<CampaignParameter>();
    final String query = "SELECT * FROM campaignparameter  WHERE campaign = ?";
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        preStat.setString(1, campaign);
        try (ResultSet resultSet = preStat.executeQuery()) {
            while (resultSet.next()) {
                result.add(this.loadFromResultSet(resultSet));
            }
            if (result.isEmpty()) {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
            } else {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
            result.clear();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
    }
    answer.setTotalRows(result.size());
    answer.setDataList(result);
    answer.setResultMessage(msg);
    return answer;
}
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) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IFactoryCampaignParameter(org.cerberus.crud.factory.IFactoryCampaignParameter) CampaignParameter(org.cerberus.crud.entity.CampaignParameter)

Example 10 with CampaignParameter

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

the class CampaignParameterDAO method findCampaignParametersByCampaign.

@Override
public List<CampaignParameter> findCampaignParametersByCampaign(String campaign) throws CerberusException {
    boolean throwEx = false;
    final String query = "SELECT * FROM campaignparameter c WHERE c.campaign = ?";
    List<CampaignParameter> campaignParameterList = new ArrayList<CampaignParameter>();
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        preStat.setString(1, campaign);
        try (ResultSet resultSet = preStat.executeQuery()) {
            while (resultSet.next()) {
                campaignParameterList.add(this.loadFromResultSet(resultSet));
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
            campaignParameterList = null;
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
        campaignParameterList = null;
    }
    if (throwEx) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
    }
    return campaignParameterList;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IFactoryCampaignParameter(org.cerberus.crud.factory.IFactoryCampaignParameter) CampaignParameter(org.cerberus.crud.entity.CampaignParameter)

Aggregations

CampaignParameter (org.cerberus.crud.entity.CampaignParameter)12 ArrayList (java.util.ArrayList)10 IFactoryCampaignParameter (org.cerberus.crud.factory.IFactoryCampaignParameter)8 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)6 MessageEvent (org.cerberus.engine.entity.MessageEvent)6 CerberusException (org.cerberus.exception.CerberusException)5 AnswerList (org.cerberus.util.answer.AnswerList)5 ICampaignParameterService (org.cerberus.crud.service.ICampaignParameterService)4 MessageGeneral (org.cerberus.engine.entity.MessageGeneral)4 AnswerItem (org.cerberus.util.answer.AnswerItem)4 JSONArray (org.json.JSONArray)4 JSONObject (org.json.JSONObject)4 List (java.util.List)3 Campaign (org.cerberus.crud.entity.Campaign)3 CampaignLabel (org.cerberus.crud.entity.CampaignLabel)3 ICampaignLabelService (org.cerberus.crud.service.ICampaignLabelService)3 ICampaignService (org.cerberus.crud.service.ICampaignService)3