Best Cerberus-source code snippet using org.cerberus.servlet.crud.transversaltables.ReadInvariant.findInvariantListByIdName
Source:ReadInvariant.java
...95 }96 } else if (request.getParameter("value") == null) {97 //loads the list of invariants98 String idName = policy.sanitize(request.getParameter("idName"));99 answer = findInvariantListByIdName(appContext, access, idName);100 jsonResponse = (JSONObject) answer.getItem();101 } else {102 String idName = request.getParameter("idName");103 String value = request.getParameter("value");104 try {105 answer = findInvariantListBykey(appContext, idName, value);106 JSONObject inv = new JSONObject();107 inv = convertInvariantToJSONObject((Invariant) answer.getItem());108 inv.put("hasPermissionsUpdate", invariantService.hasPermissionsUpdate((Invariant) answer.getItem(), request));109 jsonResponse.put("contentTable", inv);110 } catch (CerberusException e) {111 answer = new AnswerItem<>();112 MessageEvent msg = new MessageEvent(MessageEventEnum.ACTION_FAILED);113 answer.setResultMessage(msg);114 }115 }116 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());117 jsonResponse.put("message", answer.getResultMessage().getDescription());118 jsonResponse.put("sEcho", echo); //TODO:FN check if this makes sense119 response.getWriter().print(jsonResponse.toString());120 } catch (JSONException e) {121 LOG.warn(e);122 //returns a default error message with the json format that is able to be parsed by the client-side123 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());124 }125 }126 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">127 /**128 * Handles the HTTP <code>GET</code> method.129 *130 * @param request servlet request131 * @param response servlet response132 * @throws ServletException if a servlet-specific error occurs133 * @throws IOException if an I/O error occurs134 */135 @Override136 protected void doGet(HttpServletRequest request, HttpServletResponse response)137 throws ServletException, IOException {138 processRequest(request, response);139 }140 /**141 * Handles the HTTP <code>POST</code> method.142 *143 * @param request servlet request144 * @param response servlet response145 * @throws ServletException if a servlet-specific error occurs146 * @throws IOException if an I/O error occurs147 */148 @Override149 protected void doPost(HttpServletRequest request, HttpServletResponse response)150 throws ServletException, IOException {151 processRequest(request, response);152 }153 /**154 * Returns a short description of the servlet.155 *156 * @return a String containing servlet description157 */158 @Override159 public String getServletInfo() {160 return "Short description";161 }// </editor-fold>162 private AnswerItem<JSONObject> findInvariantListByIdName(ApplicationContext appContext, String access, String idName) throws JSONException {163 AnswerList<Invariant> answerService;164 AnswerItem<JSONObject> answer = new AnswerItem<>();165 JSONObject object = new JSONObject();166 //finds the list of invariants by idname167 invariantService = appContext.getBean(InvariantService.class);168 answerService = invariantService.readByIdname(idName);169 JSONArray jsonArray = new JSONArray();170 if (answerService.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {171 //if the service returns an OK message then we can get the item and convert it to JSONformat172 for (Invariant inv : answerService.getDataList()) {173 jsonArray.put(convertInvariantToJSONObject(inv));174 }175 }176 object.put("contentTable", jsonArray);...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!