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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations