use of org.cerberus.crud.entity.SqlLibrary in project cerberus-source by cerberustesting.
the class CreateSqlLibrary 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();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
Answer ans = new Answer();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
ans.setResultMessage(msg);
response.setContentType("text/html;charset=UTF-8");
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("name"), null, charset);
String type = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("type"), null, charset);
String database = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("database"), null, charset);
String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("description"), null, charset);
// Parameter that we cannot secure as we need the html --> We DECODE them
String script = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("script"), null, charset);
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(name)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "SqlLibrary").replace("%OPERATION%", "Create").replace("%REASON%", "SqlLibrary name is missing!"));
ans.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
ISqlLibraryService sqlLibraryService = appContext.getBean(ISqlLibraryService.class);
IFactorySqlLibrary factorySqlLibrary = appContext.getBean(IFactorySqlLibrary.class);
SqlLibrary sqlLib = factorySqlLibrary.create(name, type, database, script, description);
ans = sqlLibraryService.create(sqlLib);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/CreateSqlLibrary", "CREATE", "Create SQLLibrary : " + name, 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.SqlLibrary in project cerberus-source by cerberustesting.
the class DeleteSqlLibrary 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();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
Answer ans = new Answer();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
ans.setResultMessage(msg);
response.setContentType("application/json");
String charset = request.getCharacterEncoding();
String name = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("name"), null, charset);
ISqlLibraryService sqlLibraryService = appContext.getBean(ISqlLibraryService.class);
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(name)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "SqlLibrary").replace("%OPERATION%", "Delete").replace("%REASON%", "SqlLibrary ID (name) is missing!"));
ans.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
AnswerItem resp = sqlLibraryService.readByKey(name);
if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
/**
* Object could not be found. We stop here and report the error.
*/
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "SqlLibrary").replace("%OPERATION%", "Delete").replace("%REASON%", "SqlLibrary does not exist."));
ans.setResultMessage(msg);
} else {
/**
* The service was able to perform the query and confirm the
* object exist, then we can delete it.
*/
SqlLibrary sql = (SqlLibrary) resp.getItem();
ans = sqlLibraryService.delete(sql);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/DeleteSqlLibrary", "DELETE", "Delete SQLLibrary : " + name, 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.SqlLibrary in project cerberus-source by cerberustesting.
the class ReadSqlLibrary method findSqlLibraryBySystemByKey.
private AnswerItem findSqlLibraryBySystemByKey(String key, ApplicationContext appContext, boolean userHasPermissions) throws JSONException {
sqlLibraryService = appContext.getBean(SqlLibraryService.class);
AnswerItem resp = sqlLibraryService.readByKey(key);
SqlLibrary p = null;
if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// the service was able to perform the query, then we should get all values
p = (SqlLibrary) resp.getItem();
}
JSONObject item = convertSqlLibraryToJSONObject(p);
item.put("hasPermissions", userHasPermissions);
resp.setItem(item);
return resp;
}
use of org.cerberus.crud.entity.SqlLibrary in project cerberus-source by cerberustesting.
the class FactorySqlLibrary method create.
@Override
public SqlLibrary create(String name, String type, String database, String script, String description) {
SqlLibrary sqlLibrary = new SqlLibrary();
sqlLibrary.setName(name);
sqlLibrary.setType(type);
sqlLibrary.setDatabase(database);
sqlLibrary.setScript(script);
sqlLibrary.setDescription(description);
return sqlLibrary;
}
use of org.cerberus.crud.entity.SqlLibrary in project cerberus-source by cerberustesting.
the class SqlLibraryDAO method findAllSqlLibrary.
@Override
public List<SqlLibrary> findAllSqlLibrary() {
List<SqlLibrary> list = null;
final String query = "SELECT * FROM SqlLibrary";
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
ResultSet resultSet = preStat.executeQuery();
list = new ArrayList<SqlLibrary>();
try {
while (resultSet.next()) {
list.add(this.loadSqlLibraryFromResultSet(resultSet));
}
} 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());
}
}
return list;
}
Aggregations