use of org.cerberus.crud.service.IBuildRevisionParametersService in project cerberus-source by cerberustesting.
the class NewRelease 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();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPublicCalls("/NewRelease", "CALL", "NewRelease called : " + request.getRequestURL(), request);
IApplicationService MyApplicationService = appContext.getBean(ApplicationService.class);
IUserService MyUserService = appContext.getBean(UserService.class);
IProjectService MyProjectService = appContext.getBean(ProjectService.class);
IBuildRevisionParametersService buildRevisionParametersService = appContext.getBean(IBuildRevisionParametersService.class);
IFactoryBuildRevisionParameters factoryBuildRevisionParameters = appContext.getBean(IFactoryBuildRevisionParameters.class);
// Parsing all parameters.
String application = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("application"), "", charset);
String release = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("release"), "", charset);
String project = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("project"), "", charset);
String ticket = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("ticket"), "", charset);
String bug = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("bug"), "", charset);
String subject = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("subject"), "", charset);
String owner = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("owner"), "", charset);
String link = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("link"), "", charset);
// Those Parameters could be used later when Cerberus send the deploy request to Jenkins.
String jenkinsbuildid = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("jenkinsbuildid"), "", charset);
String mavengroupid = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavengroupid"), "", charset);
String mavenartifactid = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavenartifactid"), "", charset);
String mavenversion = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavenversion"), "", charset);
String repositoryurl = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("repositoryurl"), "", charset);
String helpMessage = "\nThis servlet is used to create or update a release entry in a 'NONE' build and 'NONE' revision.\n\nParameter list :\n" + "- application [mandatory] : the application that produced the release. This parameter must match the application list in Cerberus. [" + application + "]\n" + "- release : release number or svn number. This should be unique at the application level. 2 calls on the same application and release will update the other parameters on the same entry. [" + release + "]\n" + "- project : Project reference. [" + project + "]\n" + "- ticket : Ticket Reference. [" + ticket + "]\n" + "- bug : Bug reference. [" + bug + "]\n" + "- subject : A short description of the change. [" + subject + "]\n" + "- owner : User name of the developper/ person who did the commit. [" + owner + "]\n" + "- link : URL Link on detail documentation on the release. [" + link + "]\n\n" + "The following optional parameters could be used later when Cerberus send the deploy request to Jenkins.\n" + "- jenkinsbuildid : Jenkins Build ID. [" + jenkinsbuildid + "]\n" + "- mavengroupid : Maven Group ID. [" + mavengroupid + "]\n" + "- mavenartifactid : Maven Artifact ID. [" + mavenartifactid + "]\n" + "- repositoryurl : Repository URL. [" + repositoryurl + "]\n" + "- mavenversion : Maven Version. [" + mavenversion + "]\n";
DatabaseSpring database = appContext.getBean(DatabaseSpring.class);
Connection connection = database.connect();
try {
boolean error = false;
// Checking the parameter validity. If application has been entered, does it exist ?
if (!application.equalsIgnoreCase("") && !MyApplicationService.exist(application)) {
out.println("Error - Application does not exist : " + application);
error = true;
}
if (application.equalsIgnoreCase("")) {
out.println("Error - Parameter application is mandatory.");
error = true;
}
// Checking the parameter validity. If owner has been entered, does it exist ?
if (!owner.equalsIgnoreCase("")) {
if (MyUserService.isUserExist(owner)) {
// We get the exact name from Cerberus.
owner = MyUserService.findUserByKey(owner).getLogin();
} else {
out.println("Warning - User does not exist : " + owner);
}
}
// Checking the parameter validity. If project has been entered, does it exist ?
if (!project.equalsIgnoreCase("") && !MyProjectService.exist(project)) {
out.println("Warning - Project does not exist : " + project);
}
// Starting the database update only when no blocking error has been detected.
if (error == false) {
// In case the bugID is not defined, we try to guess it from the subject. should be between # and a space or CR.
if (StringUtil.isNullOrEmpty(bug)) {
String[] columns = subject.split("#");
if (columns.length >= 2) {
for (int i = 1; i < columns.length; i++) {
String[] columnsbis = columns[i].split(" ");
if (columnsbis.length >= 1) {
if (!columnsbis[0].contains(";")) {
// Bug number should not include ;
bug = columnsbis[0];
}
}
}
}
}
// Transaction and database update.
// Duplicate entry Verification. On the build/relivion not yet assigned (NONE/NONE),
// we verify that the application + release has not been submitted yet.
// if it exist, we update it in stead of inserting a new row.
// That correspond in the cases where the Jenkins pipe is executed several times
// on a single svn commit.
/**
* Verify if the entry already exists if already exists, update
* it else create it
*/
AnswerItem answer = buildRevisionParametersService.readByVarious2("NONE", "NONE", release, application);
BuildRevisionParameters buildRevisionParameters = (BuildRevisionParameters) answer.getItem();
if (answer.getResultMessage().getCode() == new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).getCode() && buildRevisionParameters != null) {
out.println("Warning - Release entry already exist. Updating the existing entry : " + buildRevisionParameters.getId());
if (!project.isEmpty()) {
buildRevisionParameters.setProject(project);
}
if (!ticket.isEmpty()) {
buildRevisionParameters.setTicketIdFixed(ticket);
}
if (!bug.isEmpty()) {
buildRevisionParameters.setBugIdFixed(bug);
}
if (!subject.isEmpty()) {
buildRevisionParameters.setSubject(subject);
}
if (!owner.isEmpty()) {
buildRevisionParameters.setReleaseOwner(owner);
}
if (!link.isEmpty()) {
buildRevisionParameters.setLink(link);
}
if (!jenkinsbuildid.isEmpty()) {
buildRevisionParameters.setJenkinsBuildId(jenkinsbuildid);
}
if (!mavengroupid.isEmpty()) {
buildRevisionParameters.setMavenGroupId(mavengroupid);
}
if (!mavenartifactid.isEmpty()) {
buildRevisionParameters.setMavenArtifactId(mavenartifactid);
}
if (!mavenversion.isEmpty()) {
buildRevisionParameters.setMavenVersion(mavenversion);
}
if (!repositoryurl.isEmpty()) {
buildRevisionParameters.setRepositoryUrl(repositoryurl);
}
buildRevisionParametersService.update(buildRevisionParameters);
} else if (answer.getResultMessage().getCode() == new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND).getCode()) {
buildRevisionParametersService.create(factoryBuildRevisionParameters.create(0, "NONE", "NONE", release, application, project, ticket, bug, link, owner, subject, null, jenkinsbuildid, mavengroupid, mavenartifactid, mavenversion, repositoryurl));
out.println("Release Inserted : '" + release + "' on '" + application + "' for user '" + owner + "'");
} else {
out.println("A problem occured : '" + answer.getResultMessage().getDescription());
}
} else {
// In case of errors, we display the help message.
out.println(helpMessage);
}
} catch (Exception e) {
LOG.warn(Infos.getInstance().getProjectNameAndVersion() + " - Exception catched.", e);
out.print("Error while inserting the release : ");
out.println(e.toString());
} finally {
out.close();
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
}
use of org.cerberus.crud.service.IBuildRevisionParametersService in project cerberus-source by cerberustesting.
the class DeleteBuildRevisionParameters 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());
ILogEventService logEventService = appContext.getBean(LogEventService.class);
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);
Integer brpid = 0;
String[] myId = request.getParameterValues("id");
StringBuilder output_message = new StringBuilder();
MessageEvent final_msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
int massErrorCounter = 0;
for (String myId1 : myId) {
/**
* Parsing and securing all required parameters.
*/
brpid = 0;
boolean brpid_error = true;
try {
if (myId1 != null && !myId1.equals("")) {
brpid = Integer.valueOf(policy.sanitize(myId1));
brpid_error = false;
}
} catch (Exception ex) {
brpid_error = true;
}
/**
* Checking all constrains before calling the services.
*/
if (brpid_error) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Delete").replace("%REASON%", "BuildRevisionParameters ID (id) : Could not manage to convert id to an integer value or id is missing."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>id : ").append(myId1).append(" - ").append(msg.getDescription());
} else {
/**
* All data seems cleans so we can call the services.
*/
IBuildRevisionParametersService brpService = appContext.getBean(IBuildRevisionParametersService.class);
AnswerItem resp = brpService.readByKeyTech(brpid);
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%", OBJECT_NAME).replace("%OPERATION%", "Delete").replace("%REASON%", "BuildRevisionParameter does not exist."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>id : ").append(myId1).append(" - ").append(msg.getDescription());
} else {
/**
* The service was able to perform the query and confirm the
* object exist, then we can delete it.
*/
BuildRevisionParameters brpData = (BuildRevisionParameters) resp.getItem();
ans = brpService.delete(brpData);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Delete was successful. Adding Log entry.
*/
logEventService.createForPrivateCalls("/DeleteBuildRevisionParameters", "DELETE", "Delete BuildRevisionParameters : ['" + brpid + "'|'" + brpData.getRelease() + "']", request);
} else {
massErrorCounter++;
output_message.append("<br>id : ").append(myId1).append(" - ").append(ans.getResultMessage().getDescription());
}
}
}
}
if (myId.length > 1) {
if (massErrorCounter == myId.length) {
// All updates are in ERROR.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update").replace("%REASON%", massErrorCounter + " objects(s) out of " + myId.length + " failed to update due to an issue.<br>") + output_message.toString());
ans.setResultMessage(msg);
} else if (massErrorCounter > 0) {
// At least 1 update in error
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update").replace("%REASON%", massErrorCounter + " objects(s) out of " + myId.length + " failed to update due to an issue.<br>") + output_message.toString());
ans.setResultMessage(msg);
} else {
// No error detected.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update") + "\n\nAll " + myId.length + " object(s) updated successfuly.");
ans.setResultMessage(msg);
}
logEventService.createForPrivateCalls("/DeleteBuildRevisionParameters", "MASSUPDATE", msg.getDescription(), 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.IBuildRevisionParametersService in project cerberus-source by cerberustesting.
the class ReadBuildRevisionParameters method findlastBuildRevisionParametersBySystem.
private AnswerItem findlastBuildRevisionParametersBySystem(String system, ApplicationContext appContext, boolean userHasPermissions) throws JSONException, CerberusException {
AnswerItem item = new AnswerItem();
JSONObject object = new JSONObject();
IBuildRevisionParametersService libService = appContext.getBean(IBuildRevisionParametersService.class);
// finds the project
AnswerItem answer = libService.readLastBySystem(system);
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
BuildRevisionParameters brp = (BuildRevisionParameters) answer.getItem();
JSONObject response = convertBuildRevisionParametersToJSONObject(brp);
object.put("contentTable", response);
}
object.put("hasPermissions", userHasPermissions);
item.setItem(object);
item.setResultMessage(answer.getResultMessage());
return item;
}
use of org.cerberus.crud.service.IBuildRevisionParametersService in project cerberus-source by cerberustesting.
the class UpdateBuildRevisionParameters 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());
ILogEventService logEventService = appContext.getBean(LogEventService.class);
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
// Parameter that needs to be secured --> We SECURE+DECODE them
String build = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("build"), "", charset);
String revision = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("revision"), "", charset);
String release = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("release"), "", charset);
// Parameter that we cannot secure as we need the html --> We DECODE them
Integer brpid = 0;
String[] myId = request.getParameterValues("id");
StringBuilder output_message = new StringBuilder();
int massErrorCounter = 0;
for (String myId1 : myId) {
brpid = 0;
boolean brpid_error = true;
try {
if (myId1 != null && !myId1.equals("")) {
brpid = Integer.valueOf(policy.sanitize(myId1));
brpid_error = false;
}
} catch (Exception ex) {
brpid_error = true;
}
/**
* Checking all constrains before calling the services.
*/
if (brpid_error) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "Could not manage to convert id to an integer value or id is missing."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>id : ").append(myId1).append(" - ").append(msg.getDescription());
} else {
/**
* All data seems cleans so we can call the services.
*/
IBuildRevisionParametersService brpService = appContext.getBean(IBuildRevisionParametersService.class);
AnswerItem resp = brpService.readByKeyTech(brpid);
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%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "BuildRevisionParameters does not exist."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>id : ").append(myId1).append(" - ").append(msg.getDescription());
} else {
/**
* The service was able to perform the query and confirm the
* object exist, then we can update it.
*/
BuildRevisionParameters brpData = (BuildRevisionParameters) resp.getItem();
/**
* Before updating, we check that the old entry can be
* modified. If old entry point to a build/revision that
* already been deployed, we cannot update it.
*/
if (brpService.check_buildRevisionAlreadyUsed(brpData.getApplication(), brpData.getBuild(), brpData.getRevision())) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Update").replace("%REASON%", "Could not update this release as its original build " + brpData.getBuild() + " revision " + brpData.getRevision() + " has already been deployed in an environment."));
ans.setResultMessage(msg);
massErrorCounter++;
output_message.append("<br>id : ").append(myId1).append(" - ").append(msg.getDescription());
} else {
brpData.setBuild(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("build"), brpData.getBuild(), charset));
brpData.setRevision(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("revision"), brpData.getRevision(), charset));
brpData.setRelease(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("release"), brpData.getRelease(), charset));
brpData.setApplication(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("application"), brpData.getApplication(), charset));
brpData.setProject(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("project"), brpData.getProject(), charset));
brpData.setTicketIdFixed(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("ticketidfixed"), brpData.getTicketIdFixed(), charset));
brpData.setBugIdFixed(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("bugidfixed"), brpData.getBugIdFixed(), charset));
brpData.setLink(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("link"), brpData.getLink(), charset));
brpData.setReleaseOwner(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("releaseowner"), brpData.getReleaseOwner(), charset));
brpData.setSubject(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("subject"), brpData.getSubject(), charset));
brpData.setJenkinsBuildId(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("jenkinsbuildid"), brpData.getJenkinsBuildId(), charset));
brpData.setMavenGroupId(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavengroupid"), brpData.getMavenGroupId(), charset));
brpData.setMavenArtifactId(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavenartifactid"), brpData.getMavenArtifactId(), charset));
brpData.setMavenVersion(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavenversion"), brpData.getMavenVersion(), charset));
brpData.setRepositoryUrl(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("repositoryurl"), brpData.getRepositoryUrl(), charset));
ans = brpService.update(brpData);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Update was successful. Adding Log entry.
*/
logEventService.createForPrivateCalls("/UpdateBuildRevisionParameters", "UPDATE", "Updated BuildRevisionParameters : ['" + brpid + "'|'" + build + "'|'" + revision + "'|'" + release + "']", request);
} else {
massErrorCounter++;
output_message.append("<br>id : ").append(myId1).append(" - ").append(ans.getResultMessage().getDescription());
}
}
}
}
}
if (myId.length > 1) {
if (massErrorCounter == myId.length) {
// All updates are in ERROR.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update").replace("%REASON%", massErrorCounter + " objects(s) out of " + myId.length + " failed to update due to an issue.<br>") + output_message.toString());
ans.setResultMessage(msg);
} else if (massErrorCounter > 0) {
// At least 1 update in error
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update").replace("%REASON%", massErrorCounter + " objects(s) out of " + myId.length + " failed to update due to an issue.<br>") + output_message.toString());
ans.setResultMessage(msg);
} else {
// No error detected.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "Mass Update") + "\n\nAll " + myId.length + " object(s) updated successfuly.");
ans.setResultMessage(msg);
}
logEventService.createForPrivateCalls("/UpdateBuildRevisionParameters", "MASSUPDATE", msg.getDescription(), 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.IBuildRevisionParametersService in project cerberus-source by cerberustesting.
the class CreateBuildRevisionParameters 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
// Parameter that needs to be secured --> We SECURE+DECODE them
String build = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("build"), "", charset);
String revision = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("revision"), "", charset);
String release = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("release"), "", charset);
String application = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("application"), "", charset);
String project = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("project"), "", charset);
String ticketidfixed = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("ticketidfixed"), "", charset);
String bugidfixed = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("bugidfixed"), "", charset);
String releaseowner = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("releaseowner"), "", charset);
String subject = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("subject"), "", charset);
String jenkinsbuildid = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("jenkinsbuildid"), "", charset);
String mavenGroupID = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavengroupid"), "", charset);
String mavenArtifactID = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavenartifactid"), "", charset);
String mavenVersion = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("mavenversion"), "", charset);
// Parameter that we cannot secure as we need the html --> We DECODE them
String link = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("link"), "", charset);
String repositoryUrl = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("repositoryurl"), "", charset);
/**
* Checking all constrains before calling the services.
*/
if (false) {
// No constrain on that Create operation.
} else {
/**
* All data seems cleans so we can call the services.
*/
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IBuildRevisionParametersService buildRevisionParametersService = appContext.getBean(IBuildRevisionParametersService.class);
IFactoryBuildRevisionParameters buildRevisionParametersFactory = appContext.getBean(IFactoryBuildRevisionParameters.class);
BuildRevisionParameters brpData = buildRevisionParametersFactory.create(0, build, revision, release, application, project, ticketidfixed, bugidfixed, link, releaseowner, subject, null, jenkinsbuildid, mavenGroupID, mavenArtifactID, mavenVersion, repositoryUrl);
ans = buildRevisionParametersService.create(brpData);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Object created. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/CreateBuildRevisionParameters", "CREATE", "Create BuildRevisionParameters : ['" + build + "']", 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();
}
Aggregations