use of org.cerberus.crud.entity.Campaign in project cerberus-source by cerberustesting.
the class CampaignDAO method readByKeyTech.
@Override
public AnswerItem readByKeyTech(int key) {
AnswerItem<Campaign> ans = new AnswerItem<>();
MessageEvent msg = null;
StringBuilder query = new StringBuilder();
query.append("SELECT * FROM campaign cpg WHERE campaignid = ?");
try (Connection connection = databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query.toString())) {
// Prepare and execute query
preStat.setInt(1, key);
try (ResultSet resultSet = preStat.executeQuery()) {
while (resultSet.next()) {
ans.setItem(loadFromResultSet(resultSet));
}
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "SELECT");
} 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()));
}
} catch (Exception e) {
LOG.warn("Unable to execute query : " + e.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
// We always set the result message
ans.setResultMessage(msg);
}
return ans;
}
use of org.cerberus.crud.entity.Campaign in project cerberus-source by cerberustesting.
the class EmailService method generateAndSendNotifyEndTagExecution.
@Override
public MessageEvent generateAndSendNotifyEndTagExecution(String tag, String campaign) {
try {
Campaign myCampaign = campaignService.convert(campaignService.readByKey(campaign));
if (!StringUtil.isNullOrEmpty(myCampaign.getDistribList())) {
if (myCampaign.getNotifyEndTagExecution().equalsIgnoreCase(Campaign.NOTIFYSTARTTAGEXECUTION_Y) || myCampaign.getNotifyEndTagExecution().equalsIgnoreCase(Campaign.NOTIFYSTARTTAGEXECUTION_CIKO)) {
// Flag is activated.
JSONObject jsonResponse = new JSONObject();
jsonResponse = ciService.getCIResult(tag);
if (myCampaign.getNotifyEndTagExecution().equalsIgnoreCase(Campaign.NOTIFYSTARTTAGEXECUTION_Y) || (myCampaign.getNotifyEndTagExecution().equalsIgnoreCase(Campaign.NOTIFYSTARTTAGEXECUTION_CIKO) && jsonResponse.getString("result").equalsIgnoreCase("KO"))) {
// Flag is Y or CIKO with KO result.
Email email = null;
try {
email = emailGenerationService.generateNotifyEndTagExecution(tag, campaign, myCampaign.getDistribList(), jsonResponse.getString("result"), (double) jsonResponse.get("CI_finalResult"));
} catch (Exception ex) {
LOG.warn("Exception generating email for End Tag Execution :" + ex);
return new MessageEvent(MessageEventEnum.GENERIC_ERROR).resolveDescription("REASON", ex.toString());
}
try {
this.sendHtmlMail(email);
} catch (Exception ex) {
LOG.warn("Exception sending email for End Tag Execution :" + ex);
return new MessageEvent(MessageEventEnum.GENERIC_ERROR).resolveDescription("REASON", ex.toString());
}
}
}
}
} catch (Exception ex) {
LOG.warn("Exception generating email for End Tag Execution :" + ex);
return new MessageEvent(MessageEventEnum.GENERIC_ERROR).resolveDescription("REASON", ex.toString());
}
return new MessageEvent(MessageEventEnum.GENERIC_OK);
}
use of org.cerberus.crud.entity.Campaign in project cerberus-source by cerberustesting.
the class FactoryCampaign method create.
@Override
public Campaign create(Integer campaignID, String campaign, String distribList, String notifyStartTagExecution, String notifyEndTagExecution, String description) {
Campaign newObject = new Campaign();
newObject.setCampaignID(campaignID);
newObject.setCampaign(campaign);
newObject.setDistribList(distribList);
newObject.setNotifyStartTagExecution(notifyStartTagExecution);
newObject.setNotifyEndTagExecution(notifyEndTagExecution);
newObject.setDescription(description);
return newObject;
}
use of org.cerberus.crud.entity.Campaign in project cerberus-source by cerberustesting.
the class CreateCampaign method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
final void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException, CerberusException, JSONException {
JSONObject jsonResponse = new JSONObject();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
Answer ans = null;
Answer finalAnswer = new Answer();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
response.setContentType("application/json");
response.setCharacterEncoding("utf8");
String charset = request.getCharacterEncoding();
// Parameter that are already controled by GUI (no need to decode) --> We SECURE them
// Parameter that needs to be secured --> We SECURE+DECODE them
String name = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("Campaign"), null, charset);
String notifyStart = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("NotifyStart"), "N", charset);
String notifyEnd = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("NotifyEnd"), "N", charset);
String desc = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("Description"), null, charset);
// Parameter that we cannot secure as we need the html --> We DECODE them
String distribList = ParameterParserUtil.parseStringParam(request.getParameter("DistribList"), "");
// String battery = ParameterParserUtil.parseStringParam(request.getParameter("Batteries"), null);
String parameter = ParameterParserUtil.parseStringParam(request.getParameter("Parameters"), null);
String label = ParameterParserUtil.parseStringParam(request.getParameter("Labels"), null);
if (StringUtil.isNullOrEmpty(name)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Campaign").replace("%OPERATION%", "Create").replace("%REASON%", "Campaign name is missing!"));
finalAnswer.setResultMessage(msg);
} else {
ICampaignService campaignService = appContext.getBean(ICampaignService.class);
IFactoryCampaign factoryCampaign = appContext.getBean(IFactoryCampaign.class);
Campaign camp = factoryCampaign.create(0, name, distribList, notifyStart, notifyEnd, desc);
finalAnswer = campaignService.create(camp);
if (finalAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/CreateCampaign", "CREATE", "Create Campaign : " + camp.getCampaign(), request);
if (parameter != null) {
JSONArray parameters = new JSONArray(parameter);
ICampaignParameterService campaignParameterService = appContext.getBean(ICampaignParameterService.class);
IFactoryCampaignParameter factoryCampaignParameter = appContext.getBean(IFactoryCampaignParameter.class);
ans = campaignParameterService.deleteByCampaign(name);
int i = 0;
while (i < parameters.length() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
JSONArray bat = parameters.getJSONArray(i);
CampaignParameter co = factoryCampaignParameter.create(0, bat.getString(0), bat.getString(2), bat.getString(3));
ans = campaignParameterService.create(co);
i++;
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Adding Log entry.
*/
logEventService.createForPrivateCalls("/CreateCampaign", "CREATE", "Update Campaign Parameter : " + co.getCampaign() + ", " + co.getValue(), request);
}
}
}
if (label != null) {
JSONArray labels = new JSONArray(label);
ICampaignLabelService campaignLabelService = appContext.getBean(ICampaignLabelService.class);
IFactoryCampaignLabel factoryCampaignLabel = appContext.getBean(IFactoryCampaignLabel.class);
ArrayList<CampaignLabel> arr = new ArrayList<>();
for (int i = 0; i < labels.length(); i++) {
JSONArray bat = labels.getJSONArray(i);
CampaignLabel co = factoryCampaignLabel.create(0, bat.getString(0), Integer.valueOf(bat.getString(2)), request.getRemoteUser(), null, request.getRemoteUser(), null);
arr.add(co);
}
finalAnswer = campaignLabelService.compareListAndUpdateInsertDeleteElements(name, arr);
if (finalAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Adding Log entry.
*/
logEventService.createForPrivateCalls("/CreateCampaign", "CREATE", "Create Campaign Label : " + camp.getCampaign(), request);
}
}
if (ans != null && !ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
finalAnswer = ans;
}
}
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
use of org.cerberus.crud.entity.Campaign in project cerberus-source by cerberustesting.
the class ReadCampaign method findCampaignList.
// </editor-fold>
private AnswerItem findCampaignList(Boolean userHasPermissions, ApplicationContext appContext, HttpServletRequest request) throws JSONException {
AnswerItem item = new AnswerItem();
AnswerList answer = new AnswerList();
JSONObject resp = new JSONObject();
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"), "1"));
String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "campaignid,campaign,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(",")));
campaignService = appContext.getBean(ICampaignService.class);
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);
}
}
}
answer = campaignService.readByCriteria(startPosition, length, columnName, sort, searchParameter, individualSearch);
// boolean userHasPermissions = request.isUserInRole("TestAdmin");
JSONArray jsonArray = new JSONArray();
if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// the service was able to perform the query, then we should get all values
for (Campaign campaign : (List<Campaign>) answer.getDataList()) {
jsonArray.put(convertCampaigntoJSONObject(campaign));
}
}
resp.put("contentTable", jsonArray);
resp.put("hasPermissions", userHasPermissions);
resp.put("iTotalRecords", answer.getTotalRows());
resp.put("iTotalDisplayRecords", answer.getTotalRows());
item.setItem(resp);
item.setResultMessage(answer.getResultMessage());
return item;
}
Aggregations