How to use UpdateParameter class of org.cerberus.servlet.crud.transversaltables package

Best Cerberus-source code snippet using org.cerberus.servlet.crud.transversaltables.UpdateParameter

Source:UpdateParameter.java Github

copy

Full Screen

...46import org.springframework.web.context.support.WebApplicationContextUtils;47/**48 * @author ip10000349 */50@WebServlet(name = "UpdateParameter", urlPatterns = {"/UpdateParameter"})51public class UpdateParameter extends HttpServlet {52 private static final Logger LOG = LogManager.getLogger(UpdateParameter.class);53 /**54 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>55 * methods.56 *57 * @param request servlet request58 * @param response servlet response59 * @throws ServletException if a servlet-specific error occurs60 * @throws IOException if an I/O error occurs61 */62 protected void processRequest(HttpServletRequest request, HttpServletResponse response)63 throws ServletException, IOException, CerberusException, JSONException {64 JSONObject jsonResponse = new JSONObject();65 Answer ans = new Answer();66 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);67 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));68 ans.setResultMessage(msg);69 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);70 String charset = request.getCharacterEncoding() == null ? "UTF-8" : request.getCharacterEncoding();71 ILogEventService logEventService;72 String id = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("id"), "", charset);73 String value = ParameterParserUtil.parseStringParam(request.getParameter("value"), "");74 String system = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system"), "", charset);75 String system1value = ParameterParserUtil.parseStringParam(request.getParameter("system1Value"), null);76 String system1 = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("system1"), null, charset);77 boolean userHasPermissions = request.isUserInRole("Administrator");78 // Prepare the final answer.79 MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);80 Answer finalAnswer = new Answer(msg1);81 /**82 * Checking all constrains before calling the services.83 */84 if (StringUtil.isNullOrEmpty(id) || StringUtil.isNullOrEmpty(system1)) {85 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);86 msg.setDescription(msg.getDescription().replace("%ITEM%", "Parameter")87 .replace("%OPERATION%", "Update")88 .replace("%REASON%", "Parameter id or system1 is missing!"));89 finalAnswer.setResultMessage(msg);90 } else if (!userHasPermissions) {91 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);92 msg.setDescription(msg.getDescription().replace("%ITEM%", "Parameter")93 .replace("%OPERATION%", "Update")94 .replace("%REASON%", "You don't have the right to do that"));95 finalAnswer.setResultMessage(msg);96 } else {97 /**98 * All data seems cleans so we can call the services.99 */100 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());101 IParameterService parameterService = appContext.getBean(IParameterService.class);102 FactoryParameter factoryparameter = appContext.getBean(FactoryParameter.class);103 Parameter para = factoryparameter.create(system, id, value, "");104 ans = parameterService.save(para, request);105 if (!ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())106 && !ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED.getCode())) {107 /**108 * Object could not be found. We stop here and report the error.109 */110 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, ans);111 } else {112 /**113 * Object updated. Adding Log entry.114 */115 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {116 logEventService = appContext.getBean(LogEventService.class);117 logEventService.createForPrivateCalls("/UpdateParameter", "UPDATE", "Update Parameter : ['" + id + "'|'" + system + "']", request);118 }119 if (system1 != null && system1value != null) {120 Parameter para1 = factoryparameter.create(system1, id, system1value, "");121 ans = parameterService.save(para1, request);122 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {123 /**124 * Object updated. Adding Log entry.125 */126 logEventService = appContext.getBean(LogEventService.class);127 logEventService.createForPrivateCalls("/UpdateParameter", "UPDATE", "Update Parameter : ['" + id + "'|'" + system1 + "']", request);128 }129 }130 }131 }132 /**133 * Formating and returning the json result.134 */135 jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());136 jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());137 response.getWriter().print(jsonResponse);138 response.getWriter().flush();139 }140 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">141 /**...

Full Screen

Full Screen

UpdateParameter

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.Parameter;2import org.cerberus.crud.factory.IFactoryParameter;3import org.cerberus.crud.service.IParameterService;4import org.cerberus.exception.CerberusException;5import org.cerberus.servlet.crud.transversaltables.UpdateParameter;6import org.cerberus.util.ParameterParserUtil;7import org.springframework.beans.factory.annotation.Autowired;8import org.springframework.context.ApplicationContext;9import org.springframework.web.context.support.WebApplicationContextUtils;10import javax.servlet.ServletException;11import javax.servlet.http.HttpServlet;12import javax.servlet.http.HttpServletRequest;13import javax.servlet.http.HttpServletResponse;14import java.io.IOException;15import java.util.logging.Level;16import java.util.logging.Logger;17public class UpdateParameter extends HttpServlet {18 private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(UpdateParameter.class);19 private IParameterService parameterService;20 private IFactoryParameter factoryParameter;21 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {22 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());23 parameterService = appContext.getBean(IParameterService.class);24 factoryParameter = appContext.getBean(IFactoryParameter.class);25 String system = ParameterParserUtil.parseStringParam(request.getParameter("System"), "");26 String parameter = ParameterParserUtil.parseStringParam(request.getParameter("Parameter"), "");27 String value = ParameterParserUtil.parseStringParam(request.getParameter("Value"), "");28 Parameter parameterToUpdate = factoryParameter.create(system, parameter, value);29 try {30 parameterService.updateParameter(parameterToUpdate);31 } catch (CerberusException ex) {32 Logger.getLogger(UpdateParameter.class.getName()).log(Level.SEVERE, null, ex);33 }34 }35}

Full Screen

Full Screen

UpdateParameter

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.crud.transversaltables.UpdateParameter;2import org.cerberus.crud.entity.Parameter;3import org.cerberus.crud.factory.IFactoryParameter;4import org.cerberus.crud.factory.impl.FactoryParameter;5import org.cerberus.crud.service.IParameterService;6import org.cerberus.crud.service.impl.ParameterService;7import org.cerberus.crud.service.impl.ParameterSystemImpl;8import org.cerberus.crud.service.impl.ParameterSystemService;9import org.cerberus.util.answer.AnswerItem;10import org.cerberus.util.answer.AnswerUtil;11import org.springframework.context.ApplicationContext;12import org.springframework.context.support.ClassPathXmlApplicationContext;13String parameter = request.getParameter("parameter");14String value = request.getParameter("value");15UpdateParameter updateParameter = new UpdateParameter();16updateParameter.setParameter(parameter);17Parameter myParameter = new Parameter();18myParameter.setValue(value);19updateParameter.setParameterObject(myParameter);20updateParameter.doPost(request, response);21String result = updateParameter.getResult();22response.getWriter().print(result);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in UpdateParameter

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful