use of org.cerberus.crud.service.IBuildRevisionInvariantService in project cerberus-source by cerberustesting.
the class CreateBuildRevisionInvariant 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
Integer seq = -1;
boolean seq_error = false;
try {
if (request.getParameter("seq") != null && !request.getParameter("seq").equals("")) {
seq = Integer.valueOf(policy.sanitize(request.getParameter("seq")));
}
} catch (Exception ex) {
seq_error = true;
}
Integer level = -1;
boolean level_error = false;
try {
if (request.getParameter("level") != null && !request.getParameter("level").equals("")) {
level = Integer.valueOf(policy.sanitize(request.getParameter("level")));
}
} catch (Exception ex) {
level_error = true;
}
// Parameter that needs to be secured --> We SECURE+DECODE them
String system = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system"), "", charset);
String versionName = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("versionname"), "", charset);
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(system)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant").replace("%OPERATION%", "Create").replace("%REASON%", "System name is missing!"));
ans.setResultMessage(msg);
} else if (level_error) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant").replace("%OPERATION%", "Create").replace("%REASON%", "Could not manage to convert level to an integer value!"));
ans.setResultMessage(msg);
} else if (seq_error) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant").replace("%OPERATION%", "Create").replace("%REASON%", "Could not manage to convert sequence to an integer value!"));
ans.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IBuildRevisionInvariantService buildRevisionInvariantService = appContext.getBean(IBuildRevisionInvariantService.class);
IFactoryBuildRevisionInvariant factoryBuildRevisionInvariant = appContext.getBean(IFactoryBuildRevisionInvariant.class);
BuildRevisionInvariant buildRevisionInvariantData = factoryBuildRevisionInvariant.create(system, level, seq, versionName);
ans = buildRevisionInvariantService.create(buildRevisionInvariantData);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Object created. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/CreateBuildRevisionInvariant", "CREATE", "Create BuildRevisionInvariant : ['" + system + "'|'" + level + "'|'" + seq + "']", 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.service.IBuildRevisionInvariantService in project cerberus-source by cerberustesting.
the class UpdateBuildRevisionInvariant 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();
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
Integer seq = -1;
boolean seq_error = false;
try {
if (request.getParameter("seq") != null && !request.getParameter("seq").equals("")) {
seq = Integer.valueOf(policy.sanitize(request.getParameter("seq")));
}
} catch (Exception ex) {
seq_error = true;
}
Integer level = -1;
boolean level_error = false;
try {
if (request.getParameter("level") != null && !request.getParameter("level").equals("")) {
level = Integer.valueOf(policy.sanitize(request.getParameter("level")));
}
} catch (Exception ex) {
level_error = true;
}
// Parameter that needs to be secured --> We SECURE+DECODE them
String system = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system"), "", charset);
String versionName = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("versionname"), "", charset);
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(system)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant").replace("%OPERATION%", "Update").replace("%REASON%", "System name is missing!"));
ans.setResultMessage(msg);
} else if (level_error) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant").replace("%OPERATION%", "Update").replace("%REASON%", "Could not manage to convert level to an integer value!"));
ans.setResultMessage(msg);
} else if (seq_error) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant").replace("%OPERATION%", "Update").replace("%REASON%", "Could not manage to convert sequence to an integer value!"));
ans.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IBuildRevisionInvariantService buildRevisionInvariantService = appContext.getBean(IBuildRevisionInvariantService.class);
AnswerItem resp = buildRevisionInvariantService.readByKey(system, level, seq);
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%", "BuildRevisionInvariant").replace("%OPERATION%", "Update").replace("%REASON%", "BuildRevisionInvariant does not exist."));
ans.setResultMessage(msg);
} else {
/**
* The service was able to perform the query and confirm the
* object exist, then we can update it.
*/
BuildRevisionInvariant buildRevisionInvariantData = (BuildRevisionInvariant) resp.getItem();
buildRevisionInvariantData.setSystem(system);
buildRevisionInvariantData.setLevel(level);
buildRevisionInvariantData.setSeq(seq);
buildRevisionInvariantData.setVersionName(versionName);
ans = buildRevisionInvariantService.update(buildRevisionInvariantData.getSystem(), buildRevisionInvariantData.getLevel(), buildRevisionInvariantData.getSeq(), buildRevisionInvariantData);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Update was successful. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateBuildRevisionInvariant", "UPDATE", "Updated BuildRevisionInvariant : ['" + system + "'|'" + level + "'|'" + seq + "']", 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.service.IBuildRevisionInvariantService in project cerberus-source by cerberustesting.
the class DeleteBuildRevisionInvariant 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);
response.setContentType("application/json");
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Parsing and securing all required parameters.
*/
String system = policy.sanitize(request.getParameter("system"));
Integer level = -1;
boolean level_error = false;
try {
if (request.getParameter("level") != null && !request.getParameter("level").equals("")) {
level = Integer.valueOf(policy.sanitize(request.getParameter("level")));
}
} catch (Exception ex) {
level_error = true;
}
Integer seq = -1;
boolean seq_error = false;
try {
if (request.getParameter("seq") != null && !request.getParameter("seq").equals("")) {
seq = Integer.valueOf(policy.sanitize(request.getParameter("seq")));
}
} catch (Exception ex) {
seq_error = true;
}
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(system)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant").replace("%OPERATION%", "Delete").replace("%REASON%", "System is missing!"));
ans.setResultMessage(msg);
} else if (level_error) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant").replace("%OPERATION%", "Delete").replace("%REASON%", "Could not manage to convert level to an integer value!"));
ans.setResultMessage(msg);
} else if (seq_error) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "BuildRevisionInvariant").replace("%OPERATION%", "Delete").replace("%REASON%", "Could not manage to convert sequence to an integer value!"));
ans.setResultMessage(msg);
} else {
/**
* All data seems cleans so we can call the services.
*/
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IBuildRevisionInvariantService buildRevisionInvariantService = appContext.getBean(IBuildRevisionInvariantService.class);
AnswerItem resp = buildRevisionInvariantService.readByKey(system, level, seq);
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%", "BuildRevisionInvariant").replace("%OPERATION%", "Delete").replace("%REASON%", "BuildRevisionInvariant 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.
*/
BuildRevisionInvariant buildRevisionInvariantData = (BuildRevisionInvariant) resp.getItem();
ans = buildRevisionInvariantService.delete(buildRevisionInvariantData);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Delete was successful. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/DeleteBuildRevisionInvariant", "DELETE", "Delete BuildRevisionInvariant : ['" + system + "'|'" + level + "'|'" + seq + "']", request);
}
}
}
/**
* Formating and returning the json result.
*/
jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
jsonResponse.put("message", ans.getResultMessage().getDescription());
response.getWriter().print(jsonResponse.toString());
response.getWriter().flush();
}
use of org.cerberus.crud.service.IBuildRevisionInvariantService in project cerberus-source by cerberustesting.
the class ReadBuildRevisionInvariant method findBuildRevisionInvariantByKey.
private AnswerItem findBuildRevisionInvariantByKey(String system, Integer level, Integer seq, ApplicationContext appContext, boolean userHasPermissions) throws JSONException, CerberusException {
AnswerItem item = new AnswerItem();
JSONObject object = new JSONObject();
IBuildRevisionInvariantService libService = appContext.getBean(IBuildRevisionInvariantService.class);
// finds the project
AnswerItem answer = null;
answer = libService.readByKey(system, level, seq);
if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// if the service returns an OK message then we can get the item and convert it to JSONformat
BuildRevisionInvariant bri = (BuildRevisionInvariant) answer.getItem();
JSONObject response = convertBuildRevisionInvariantToJSONObject(bri);
object.put("contentTable", response);
}
object.put("hasPermissions", userHasPermissions);
item.setItem(object);
item.setResultMessage(answer.getResultMessage());
return item;
}
use of org.cerberus.crud.service.IBuildRevisionInvariantService in project cerberus-source by cerberustesting.
the class DisableEnvironmentV000 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 {
PrintWriter out = response.getWriter();
String charset = request.getCharacterEncoding();
// Loading Services.
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ICountryEnvParamService countryEnvParamService = appContext.getBean(ICountryEnvParamService.class);
IInvariantService invariantService = appContext.getBean(IInvariantService.class);
IBuildRevisionInvariantService buildRevisionInvariantService = appContext.getBean(IBuildRevisionInvariantService.class);
IEmailService emailService = appContext.getBean(IEmailService.class);
ICountryEnvParam_logService countryEnvParam_logService = appContext.getBean(ICountryEnvParam_logService.class);
IParameterService parameterService = appContext.getBean(IParameterService.class);
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(ILogEventService.class);
logEventService.createForPublicCalls("/DisableEnvironmentV000", "CALL", "DisableEnvironmentV000 called : " + request.getRequestURL(), request);
// Parsing all parameters.
String system = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system"), "", charset);
String country = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("country"), "", charset);
String environment = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("environment"), "", charset);
// Defining help message.
String helpMessage = "\nThis servlet is used to inform Cerberus that a system is disabled. For example when a Revision is beeing deployed.\n\nParameter list :\n" + "- system [mandatory] : the system where the Build Revision has been deployed. [" + system + "]\n" + "- country [mandatory] : the country where the Build Revision has been deployed. You can use ALL if you want to perform the action for all countries that exist for the given system and environement. [" + country + "]\n" + "- environment [mandatory] : the environment where the Build Revision has been deployed. [" + environment + "]\n";
// Checking the parameter validity.
boolean error = false;
if (system.equalsIgnoreCase("")) {
out.println("Error - Parameter system is mandatory.");
error = true;
}
if (!system.equalsIgnoreCase("") && !invariantService.isInvariantExist("SYSTEM", system)) {
out.println("Error - System does not exist : " + system);
error = true;
}
if (environment.equalsIgnoreCase("")) {
out.println("Error - Parameter environment is mandatory.");
error = true;
}
if (!environment.equalsIgnoreCase("") && !invariantService.isInvariantExist("ENVIRONMENT", environment)) {
out.println("Error - Environment does not exist : " + environment);
error = true;
}
if (country.equalsIgnoreCase("")) {
out.println("Error - Parameter country is mandatory.");
error = true;
} else if (!country.equalsIgnoreCase(PARAMETERALL)) {
if (!invariantService.isInvariantExist("COUNTRY", country)) {
out.println("Error - Country does not exist : " + country);
error = true;
}
if (!error) {
if (!countryEnvParamService.exist(system, country, environment)) {
out.println("Error - System/Country/Environment does not exist : " + system + "/" + country + "/" + environment);
error = true;
}
}
}
// Starting the database update only when no blocking error has been detected.
if (error == false) {
/**
* Getting the list of objects to treat.
*/
MessageEvent msg = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer finalAnswer = new Answer(msg);
AnswerList answerList = new AnswerList();
if (country.equalsIgnoreCase(PARAMETERALL)) {
country = null;
}
answerList = countryEnvParamService.readByVarious(system, country, environment, null, null, null);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) answerList);
for (CountryEnvParam cepData : (List<CountryEnvParam>) answerList.getDataList()) {
/**
* For each object, we can update it.
*/
cepData.setActive(false);
Answer answerUpdate = countryEnvParamService.update(cepData);
if (!(answerUpdate.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()))) {
/**
* Object could not be updated. We stop here and report the
* error.
*/
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, answerUpdate);
} else {
/**
* Update was successful.
*/
// Adding Log entry.
logEventService.createForPrivateCalls("/DisableEnvironmentV000", "UPDATE", "Updated CountryEnvParam : ['" + cepData.getSystem() + "','" + cepData.getCountry() + "','" + cepData.getEnvironment() + "']", request);
// Adding CountryEnvParam Log entry.
countryEnvParam_logService.createLogEntry(cepData.getSystem(), cepData.getCountry(), cepData.getEnvironment(), "", "", "Disabled.", "PublicCall");
/**
* Email notification.
*/
// Email Calculation.
String eMailContent;
String OutputMessage = "";
MessageEvent me = emailService.generateAndSendDisableEnvEmail(cepData.getSystem(), cepData.getCountry(), cepData.getEnvironment());
if (!"OK".equals(me.getMessage().getCodeString())) {
LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched." + me.getMessage().getDescription());
logEventService.createForPrivateCalls("/DisableEnvironmentV000", "DISABLE", "Warning on Disable environment : ['" + cepData.getSystem() + "','" + cepData.getCountry() + "','" + cepData.getEnvironment() + "'] " + me.getMessage().getDescription(), request);
OutputMessage = me.getMessage().getDescription();
}
if (OutputMessage.equals("")) {
msg = new MessageEvent(MessageEventEnum.GENERIC_OK);
Answer answerSMTP = new AnswerList(msg);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, answerSMTP);
} else {
msg = new MessageEvent(MessageEventEnum.GENERIC_WARNING);
msg.setDescription(msg.getDescription().replace("%REASON%", OutputMessage + " when sending email for " + cepData.getSystem() + "/" + cepData.getCountry() + "/" + cepData.getEnvironment()));
Answer answerSMTP = new AnswerList(msg);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, answerSMTP);
}
}
}
/**
* Formating and returning the result.
*/
out.println(finalAnswer.getResultMessage().getMessage().getCodeString() + " - " + finalAnswer.getResultMessage().getDescription());
} else {
// In case of errors, we display the help message.
out.println(helpMessage);
}
}
Aggregations