use of org.cerberus.crud.entity.Parameter in project cerberus-source by cerberustesting.
the class ParameterDAO method findAllParameter.
@Override
public List<Parameter> findAllParameter() throws CerberusException {
boolean throwExep = true;
List<Parameter> result = null;
Parameter paramet;
final String query = "SELECT * FROM parameter p ";
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
ResultSet resultSet = preStat.executeQuery();
try {
result = new ArrayList<Parameter>();
while (resultSet.next()) {
String system = resultSet.getString("system");
String param = resultSet.getString("param");
String value = resultSet.getString("value");
String desc = resultSet.getString("description");
paramet = factoryParameter.create(system, param, value, desc);
result.add(paramet);
throwExep = false;
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
if (throwExep) {
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND);
mes.setDescription(mes.getDescription() + " Parameter table empty.");
throw new CerberusException(mes);
}
return result;
}
use of org.cerberus.crud.entity.Parameter in project cerberus-source by cerberustesting.
the class ParameterDAO method findAllParameterWithSystem1.
@Override
public List<Parameter> findAllParameterWithSystem1(String mySystem, String mySystem1) throws CerberusException {
boolean throwExep = true;
List<Parameter> result = null;
Parameter paramet;
StringBuilder mySQL = new StringBuilder();
mySQL.append("SELECT par.param param, par.`value` valC, par2.`value` valS, par2.description FROM parameter par ");
mySQL.append("LEFT OUTER JOIN ( SELECT * from parameter par2 WHERE par2.system= ? ) as par2 ON par.param = par.param ");
mySQL.append(" WHERE par.system= ?; ");
final String query = mySQL.toString();
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
preStat.setString(1, mySystem1);
preStat.setString(1, mySystem);
try {
ResultSet resultSet = preStat.executeQuery();
try {
result = new ArrayList<Parameter>();
while (resultSet.next()) {
String param = resultSet.getString("param");
String valueC = resultSet.getString("valC");
String valueS = resultSet.getString("valS");
String desc = resultSet.getString("description");
paramet = factoryParameter.create(param, "", valueC, desc, mySystem, valueS);
result.add(paramet);
throwExep = false;
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
if (throwExep) {
MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND);
mes.setDescription(mes.getDescription() + " Parameter table empty.");
throw new CerberusException(mes);
}
return result;
}
use of org.cerberus.crud.entity.Parameter in project cerberus-source by cerberustesting.
the class TestDataLibDAO method uploadFile.
@Override
public Answer uploadFile(int id, FileItem file) {
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", "cerberus_testdatalibcsv_path Parameter not found");
AnswerItem a = parameterService.readByKey("", "cerberus_testdatalibcsv_path");
if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
Parameter p = (Parameter) a.getItem();
String uploadPath = p.getValue();
File appDir = new File(uploadPath + File.separator + id);
if (!appDir.exists()) {
try {
appDir.mkdirs();
} catch (SecurityException se) {
LOG.warn("Unable to create testdatalib csv dir: " + se.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", se.toString());
a.setResultMessage(msg);
}
}
if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
deleteFolder(appDir, false);
File picture = new File(uploadPath + File.separator + id + File.separator + file.getName());
try {
file.write(picture);
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("DESCRIPTION", "TestDataLib CSV file uploaded");
msg.setDescription(msg.getDescription().replace("%ITEM%", "testDatalib CSV").replace("%OPERATION%", "Upload"));
} catch (Exception e) {
LOG.warn("Unable to upload testdatalib csv file: " + e.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
}
}
} else {
LOG.warn("cerberus_testdatalibCSV_path Parameter not found");
}
a.setResultMessage(msg);
return a;
}
use of org.cerberus.crud.entity.Parameter in project cerberus-source by cerberustesting.
the class AndroidAppiumService method swipe.
@Override
public MessageEvent swipe(Session session, SwipeAction action) {
try {
SwipeAction.Direction direction = this.getDirectionForSwipe(session, action);
// Get the parametrized swipe duration
Parameter duration = parameters.findParameterByKey(CERBERUS_APPIUM_SWIPE_DURATION_PARAMETER, "");
// Do the swipe thanks to the Appium driver
TouchAction dragNDrop = new TouchAction(session.getAppiumDriver()).press(direction.getX1(), direction.getY1()).waitAction(Duration.ofMillis(duration == null ? DEFAULT_CERBERUS_APPIUM_SWIPE_DURATION : Integer.parseInt(duration.getValue()))).moveTo(direction.getX2(), direction.getY2()).release();
dragNDrop.perform();
return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SWIPE).resolveDescription("DIRECTION", action.getActionType().name());
} catch (IllegalArgumentException e) {
return new MessageEvent(MessageEventEnum.ACTION_FAILED_SWIPE).resolveDescription("DIRECTION", action.getActionType().name()).resolveDescription("REASON", "Unknown direction");
} catch (Exception e) {
LOG.warn("Unable to swipe screen due to " + e.getMessage(), e);
return new MessageEvent(MessageEventEnum.ACTION_FAILED_SWIPE).resolveDescription("DIRECTION", action.getActionType().name()).resolveDescription("REASON", e.getMessage());
}
}
use of org.cerberus.crud.entity.Parameter in project cerberus-source by cerberustesting.
the class UpdateParameter 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
*/
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();
ILogEventService logEventService;
String id = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("id"), "", charset);
String value = ParameterParserUtil.parseStringParam(request.getParameter("value"), "");
String system = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system"), "", charset);
String system1value = ParameterParserUtil.parseStringParam(request.getParameter("system1Value"), null);
String system1 = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system1"), null, charset);
boolean userHasPermissions = request.isUserInRole("Administrator");
// Prepare the final answer.
MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer finalAnswer = new Answer(msg1);
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(id) || StringUtil.isNullOrEmpty(system1)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Parameter").replace("%OPERATION%", "Update").replace("%REASON%", "Parameter id or system1 is missing!"));
finalAnswer.setResultMessage(msg);
} else if (!userHasPermissions) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Parameter").replace("%OPERATION%", "Update").replace("%REASON%", "You don't have the right to do that"));
finalAnswer.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IParameterService parameterService = appContext.getBean(IParameterService.class);
FactoryParameter factoryparameter = appContext.getBean(FactoryParameter.class);
Parameter para = factoryparameter.create(system, id, value, "");
ans = parameterService.save(para);
if (!ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && !ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED.getCode())) {
/**
* Object could not be found. We stop here and report the error.
*/
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
} else {
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateParameter", "UPDATE", "Update Parameter : ['" + id + "','" + system + "']", request);
}
if (system1 != null && system1value != null) {
Parameter para1 = factoryparameter.create(system1, id, system1value, "");
ans = parameterService.save(para1);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Object updated. Adding Log entry.
*/
logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateParameter", "UPDATE", "Update Parameter : ['" + id + "','" + system1 + "']", request);
}
}
}
}
/**
* 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();
}
Aggregations