use of org.cerberus.crud.entity.Label in project cerberus-source by cerberustesting.
the class CreateLabel 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
* @throws org.cerberus.exception.CerberusException
* @throws org.json.JSONException
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException, JSONException {
JSONObject jsonResponse = new JSONObject();
Answer ans = new Answer();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
ans.setResultMessage(msg);
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
String charset = request.getCharacterEncoding();
response.setContentType("application/json");
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Parsing and securing all required parameters.
*/
// Parameter that are already controled by GUI (no need to decode) --> We SECURE them
String id = policy.sanitize(request.getParameter("id"));
String system = policy.sanitize(request.getParameter("system"));
String type = policy.sanitize(request.getParameter("type"));
String longDesc = policy.sanitize(request.getParameter("longdesc"));
String reqtype = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("reqtype"), "", charset);
String reqstatus = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("reqstatus"), "", charset);
String reqcriticity = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("reqcriticity"), "", charset);
// Parameter that needs to be secured --> We SECURE+DECODE them
String label = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("label"), "", charset);
String color = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("color"), "", charset);
String parentLabel = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("parentLabel"), "", charset);
String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), "", charset);
String usr = request.getUserPrincipal().getName();
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(label)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Label").replace("%OPERATION%", "Create").replace("%REASON%", "Label is missing!"));
ans.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ILabelService labelService = appContext.getBean(ILabelService.class);
IFactoryLabel factoryLabel = appContext.getBean(IFactoryLabel.class);
Timestamp creationDate = new Timestamp(new Date().getTime());
Label labelData = factoryLabel.create(0, system, label, type, color, parentLabel, reqtype, reqstatus, reqcriticity, description, longDesc, usr, creationDate, usr, creationDate);
ans = labelService.create(labelData);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Object created. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/CreateLabel", "CREATE", "Create Label : ['" + label + "'] for System : [" + system + "]", request);
}
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", ans.getResultMessage().getDescription());
response.getWriter().print(jsonResponse);
response.getWriter().flush();
}
use of org.cerberus.crud.entity.Label in project cerberus-source by cerberustesting.
the class FactoryLabel method create.
@Override
public Label create(Integer id, String system, String label, String type, String color, String parentLabel, String reqType, String reqStatus, String reqCriticity, String description, String longDesc, String usrCreated, Timestamp dateCreated, String usrModif, Timestamp dateModif) {
Label labelObject = new Label();
labelObject.setColor(color);
labelObject.setDateCreated(dateCreated);
labelObject.setDateModif(dateModif);
labelObject.setId(id);
labelObject.setLabel(label);
labelObject.setType(type);
labelObject.setParentLabel(parentLabel);
labelObject.setSystem(system);
labelObject.setUsrCreated(usrCreated);
labelObject.setUsrModif(usrModif);
labelObject.setDescription(description);
labelObject.setLongDesc(longDesc);
labelObject.setReqCriticity(reqCriticity);
labelObject.setReqStatus(reqStatus);
labelObject.setReqType(reqType);
return labelObject;
}
use of org.cerberus.crud.entity.Label in project cerberus-source by cerberustesting.
the class TestCaseLabelDAO method readByTestTestCase.
@Override
public AnswerList readByTestTestCase(String test, String testCase) {
AnswerList response = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<TestCaseLabel> objectList = new ArrayList<>();
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 testcaselabel tel ");
query.append(" LEFT OUTER JOIN label lab on lab.id = tel.labelId ");
query.append(" WHERE 1=1");
if (!Strings.isNullOrEmpty(test)) {
query.append(" AND tel.test = ?");
}
if (testCase != null) {
query.append(" AND tel.testcase = ?");
}
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
try (Connection connection = databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query.toString());
Statement stm = connection.createStatement()) {
int i = 1;
if (!Strings.isNullOrEmpty(test)) {
preStat.setString(i++, test);
}
if (testCase != null) {
preStat.setString(i++, testCase);
}
try (ResultSet resultSet = preStat.executeQuery();
ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()")) {
// gets the data
while (resultSet.next()) {
Label label = labelDAO.loadFromResultSet(resultSet);
TestCaseLabel tcl = this.loadFromResultSet(resultSet, label);
objectList.add(tcl);
}
// get the total number of rows
int nrTotalRows = 0;
if (rowSet != null && rowSet.next()) {
nrTotalRows = rowSet.getInt(1);
}
if (objectList.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(objectList, nrTotalRows);
} else if (objectList.size() <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
response = new AnswerList(objectList, nrTotalRows);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
response = new AnswerList(objectList, nrTotalRows);
}
response.setDataList(objectList);
} 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 readByTestTestCase TestCaseLabel: " + e.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
response.setResultMessage(msg);
}
return response;
}
use of org.cerberus.crud.entity.Label in project cerberus-source by cerberustesting.
the class CampaignLabelDAO method loadFromResultSet.
@Override
public CampaignLabel loadFromResultSet(ResultSet rs) throws SQLException {
int campaignlabelid = ParameterParserUtil.parseIntegerParam(rs.getString("cpl.campaignlabelid"), 0);
String campaign = ParameterParserUtil.parseStringParam(rs.getString("cpl.campaign"), "");
int labelid = ParameterParserUtil.parseIntegerParam(rs.getString("cpl.labelid"), 0);
String usrModif = ParameterParserUtil.parseStringParam(rs.getString("cpl.UsrModif"), "");
String usrCreated = ParameterParserUtil.parseStringParam(rs.getString("cpl.UsrCreated"), "");
Timestamp dateModif = rs.getTimestamp("cpl.DateModif");
Timestamp dateCreated = rs.getTimestamp("cpl.DateCreated");
Integer id = ParameterParserUtil.parseIntegerParam(rs.getString("lab.id"), 0);
String system = ParameterParserUtil.parseStringParam(rs.getString("lab.system"), "");
String label = ParameterParserUtil.parseStringParam(rs.getString("lab.label"), "");
String type = ParameterParserUtil.parseStringParam(rs.getString("lab.type"), "");
String color = ParameterParserUtil.parseStringParam(rs.getString("lab.color"), "");
String reqType = ParameterParserUtil.parseStringParam(rs.getString("lab.ReqType"), "");
String reqStatus = ParameterParserUtil.parseStringParam(rs.getString("lab.ReqStatus"), "");
String reqCriticity = ParameterParserUtil.parseStringParam(rs.getString("lab.ReqCriticity"), "");
String parentLabel = ParameterParserUtil.parseStringParam(rs.getString("lab.parentLabel"), "");
String description = ParameterParserUtil.parseStringParam(rs.getString("lab.description"), "");
String longDesc = ParameterParserUtil.parseStringParam(rs.getString("lab.LongDesc"), "");
String usrCreated1 = ParameterParserUtil.parseStringParam(rs.getString("lab.usrCreated"), "");
Timestamp dateCreated1 = rs.getTimestamp("lab.dateCreated");
String usrModif1 = ParameterParserUtil.parseStringParam(rs.getString("lab.usrModif"), "");
Timestamp dateModif1 = rs.getTimestamp("lab.dateModif");
factoryLabel = new FactoryLabel();
Label labelObj = factoryLabel.create(id, system, label, type, color, parentLabel, reqType, reqStatus, reqCriticity, description, longDesc, usrCreated1, dateCreated1, usrModif1, dateModif1);
factoryCampaignLabel = new FactoryCampaignLabel();
CampaignLabel res = factoryCampaignLabel.create(campaignlabelid, campaign, labelid, usrCreated, dateCreated, usrModif, dateModif);
res.setLabel(labelObj);
return res;
}
use of org.cerberus.crud.entity.Label in project cerberus-source by cerberustesting.
the class LabelDAO method readByKey.
@Override
public AnswerItem<Label> readByKey(Integer id) {
AnswerItem<Label> ans = new AnswerItem();
Label result = null;
final String query = "SELECT * FROM `label` lab 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);
LOG.debug("SQL.param.label : " + id);
}
try (Connection connection = databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query)) {
// prepare and execute query
preStat.setInt(1, id);
try (ResultSet resultSet = preStat.executeQuery()) {
// parse query
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()));
}
} catch (Exception e) {
LOG.warn("Unable to readByKey Label: " + e.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
ans.setResultMessage(msg);
}
return ans;
}
Aggregations