How to use processRequest method of org.cerberus.servlet.crud.testexecution.ReadTagStat class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.testexecution.ReadTagStat.processRequest

Source:ReadTagStat.java Github

copy

Full Screen

...81 * @throws ServletException if a servlet-specific error occurs82 * @throws IOException if an I/O error occurs83 * @throws org.cerberus.exception.CerberusException84 */85 protected void processRequest(HttpServletRequest request, HttpServletResponse response)86 throws ServletException, IOException, CerberusException {87 String echo = request.getParameter("sEcho");88 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());89 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);90 response.setContentType("application/json");91 response.setCharacterEncoding("utf8");92 // Calling Servlet Transversal Util.93 ServletUtil.servletStart(request);94 // Default message to unexpected error.95 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);96 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));97 /**98 * Parsing and securing all required parameters.99 */100 factoryTestCase = appContext.getBean(IFactoryTestCase.class);101 List<String> system = ParameterParserUtil.parseListParam(request.getParameterValues("system"), new ArrayList<String>(), "UTF8");102 String from = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("from"), "2020-01-01T01:01:01.001Z", "UTF8");103 String to = ParameterParserUtil.parseStringParamAndDecode(request.getParameter("to"), "2020-06-01T01:01:01.001Z", "UTF8");104 LOG.debug("from : " + from);105 LOG.debug("to : " + to);106 Date fromD;107 try {108 TimeZone tz = TimeZone.getTimeZone("UTC");109 DateFormat df = new SimpleDateFormat(DATE_FORMAT);110 df.setTimeZone(tz);111 fromD = df.parse(from);112 } catch (ParseException ex) {113 fromD = Date.from(ZonedDateTime.now().minusMonths(1).toInstant());114 LOG.debug("Exception when parsing date", ex);115 }116 Date toD;117 try {118 TimeZone tz = TimeZone.getTimeZone("UTC");119 DateFormat df = new SimpleDateFormat(DATE_FORMAT);120 df.setTimeZone(tz);121 toD = df.parse(to);122 } catch (ParseException ex) {123 toD = Date.from(ZonedDateTime.now().toInstant());124 LOG.debug("Exception when parsing date", ex);125 }126 LOG.debug("from : " + fromD);127 LOG.debug("to : " + toD);128 List<String> gp1 = ParameterParserUtil.parseListParam(request.getParameterValues("group1s"), new ArrayList<String>(), "UTF8");129 List<String> gp2 = ParameterParserUtil.parseListParam(request.getParameterValues("group2s"), new ArrayList<String>(), "UTF8");130 List<String> gp3 = ParameterParserUtil.parseListParam(request.getParameterValues("group3s"), new ArrayList<String>(), "UTF8");131 List<String> defaultCampaigns = new ArrayList<>();132 if (gp1.isEmpty() && gp2.isEmpty() && gp3.isEmpty()) {133 // If none of the groups are defined we allow not to filter per campaign.134 defaultCampaigns.add("");135 }136 List<String> campaigns = ParameterParserUtil.parseListParam(request.getParameterValues("campaigns"), defaultCampaigns, "UTF8");137 List<String> countries = ParameterParserUtil.parseListParam(request.getParameterValues("countries"), new ArrayList<String>(), "UTF8");138 Boolean countriesDefined = (request.getParameterValues("countries") != null);139 LOG.debug("countries : " + countries);140 List<String> environments = ParameterParserUtil.parseListParam(request.getParameterValues("environments"), new ArrayList<String>(), "UTF8");141 Boolean environmentsDefined = (request.getParameterValues("environments") != null);142 LOG.debug("environments : " + environments);143 List<String> robotDeclis = ParameterParserUtil.parseListParam(request.getParameterValues("robotDeclis"), new ArrayList<String>(), "UTF8");144 Boolean robotDeclisDefined = (request.getParameterValues("robotDeclis") != null);145 LOG.debug("robotDeclis : " + robotDeclis);146 // Init Answer with potencial error from Parsing parameter.147 AnswerItem<JSONObject> answer = new AnswerItem<>(msg);148 // get all TestCase Execution Data.149 HashMap<String, Boolean> countryMap = new HashMap<>();150 HashMap<String, Boolean> environmentMap = new HashMap<>();151 HashMap<String, Boolean> robotDecliMap = new HashMap<>();152 tagService = appContext.getBean(ITagService.class);153// List<TestCaseExecution> exeL = testCaseExecutionService.readByCriteria(null, null, null, null, ltc, fromD, toD);154 List<Tag> tagExeL = tagService.convert(tagService.readByVarious(campaigns, gp1, gp2, gp3, new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), fromD, toD));155 for (Tag tagExe : tagExeL) {156 if (tagExe.getCountryList() != null) {157 countryMap.put(tagExe.getCountryList(), countries.contains(formatedJSONArray(tagExe.getCountryList())));158 }159 if (tagExe.getEnvironmentList() != null) {160 environmentMap.put(tagExe.getEnvironmentList(), environments.contains(formatedJSONArray(tagExe.getEnvironmentList())));161 }162 if (tagExe.getRobotDecliList() != null) {163 robotDecliMap.put(tagExe.getRobotDecliList(), robotDeclis.contains(formatedJSONArray(tagExe.getRobotDecliList())));164 }165 }166 LOG.debug(countryMap);167 LOG.debug(environmentMap);168 LOG.debug(robotDecliMap);169 try {170 JSONObject jsonResponse = new JSONObject();171 answer = findExeStatList(appContext, request, tagExeL, countryMap, countries, countriesDefined, environmentMap, environments, environmentsDefined, robotDecliMap, robotDeclis, robotDeclisDefined);172 jsonResponse = (JSONObject) answer.getItem();173 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());174 jsonResponse.put("message", answer.getResultMessage().getDescription());175 jsonResponse.put("sEcho", echo);176 response.getWriter().print(jsonResponse.toString());177 } catch (JSONException e) {178 LOG.warn(e);179 //returns a default error message with the json format that is able to be parsed by the client-side180 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());181 }182 }183 private AnswerItem<JSONObject> findExeStatList(ApplicationContext appContext, HttpServletRequest request,184 List<Tag> tagExeList,185 HashMap<String, Boolean> countryMap, List<String> countries, Boolean countriesDefined,186 HashMap<String, Boolean> environmentMap, List<String> environments, Boolean environmentsDefined,187 HashMap<String, Boolean> robotDecliMap, List<String> robotDeclis, Boolean robotDeclisDefined) throws JSONException {188 // Default message to unexpected error.189 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);190 msg.setDescription(msg.getDescription().replace("%ITEM%", "Tag").replace("%OPERATION%", "Read"));191 AnswerItem<JSONObject> item = new AnswerItem<>(msg);192 JSONObject object = new JSONObject();193 testCaseExecutionHttpStatService = appContext.getBean(ITestCaseExecutionHttpStatService.class);194 applicationService = appContext.getBean(IApplicationService.class);195 testCaseService = appContext.getBean(ITestCaseService.class);196 factoryTestCase = appContext.getBean(IFactoryTestCase.class);197 HashMap<String, JSONArray> curveMap = new HashMap<>();198 HashMap<String, JSONObject> curveObjMap = new HashMap<>();199 String curveKey = "";200 JSONArray curArray = new JSONArray();201 JSONObject curveObj = new JSONObject();202 JSONObject pointObj = new JSONObject();203 HashMap<String, JSONObject> curveStatusObjMap = new HashMap<>();204 List<String> curveBarMap = new ArrayList<>();205 HashMap<String, Tag> curveTagObjMap = new HashMap<>();206 HashMap<String, List<Integer>> curveTagObjValMap = new HashMap<>();207 HashMap<String, Integer> curveTagObjValTotMap = new HashMap<>();208 String curveKeyStatus = "";209 JSONObject curveStatObj = new JSONObject();210 for (Tag exeCur : tagExeList) {211 if ((countries.isEmpty() || countries.contains(formatedJSONArray(exeCur.getCountryList())))212 && (environments.isEmpty() || environments.contains(formatedJSONArray(exeCur.getEnvironmentList())))213 && (robotDeclis.isEmpty() || robotDeclis.contains(formatedJSONArray(exeCur.getRobotDecliList())))) {214 /**215 * Curves of tag response time.216 */217 curveKey = exeCur.getCampaign() + "|" + exeCur.getCountryList() + "|" + exeCur.getEnvironmentList() + "|" + exeCur.getRobotDecliList() + "|";218 long y = 0;219 long ymin = 0;220 y = exeCur.getDateEndQueue().getTime() - exeCur.getDateCreated().getTime();221 ymin = y / 60000;222 if (!countryMap.containsKey(exeCur.getCountryList())) {223 countryMap.put(exeCur.getCountryList(), false);224 }225 if (!environmentMap.containsKey(exeCur.getEnvironmentList())) {226 environmentMap.put(exeCur.getEnvironmentList(), false);227 }228 if (!robotDecliMap.containsKey(exeCur.getRobotDecliList())) {229 robotDecliMap.put(exeCur.getRobotDecliList(), false);230 }231 if (y > 0) {232 countryMap.put(exeCur.getCountryList(), true);233 environmentMap.put(exeCur.getEnvironmentList(), true);234 robotDecliMap.put(exeCur.getRobotDecliList(), true);235 pointObj = new JSONObject();236 Date d = new Date(exeCur.getDateCreated().getTime());237// TimeZone tz = TimeZone.getTimeZone("UTC");238 DateFormat df = new SimpleDateFormat(DATE_FORMAT);239// df.setTimeZone(tz);240 pointObj.put("x", df.format(d));241 pointObj.put("y", ymin);242 pointObj.put("tag", exeCur.getTag());243 pointObj.put("ciRes", exeCur.getCiResult());244 pointObj.put("ciSc", exeCur.getCiScore());245 pointObj.put("ciScT", exeCur.getCiScoreThreshold());246 pointObj.put("nbExe", exeCur.getNbExe());247 pointObj.put("nbExeU", exeCur.getNbExeUsefull());248 pointObj.put("description", exeCur.getDescription());249 pointObj.put("comment", exeCur.getComment());250 if (curveMap.containsKey(curveKey)) {251 curArray = curveMap.get(curveKey);252 } else {253 curArray = new JSONArray();254 curveObj = new JSONObject();255 curveObj.put("key", curveKey);256 curveObj.put("campaign", exeCur.getCampaign());257 curveObj.put("country", formatedJSONArray(exeCur.getCountryList()));258 curveObj.put("environment", formatedJSONArray(exeCur.getEnvironmentList()));259 curveObj.put("robotdecli", formatedJSONArray(exeCur.getRobotDecliList()));260 curveObj.put("system", formatedJSONArray(exeCur.getSystemList()));261 curveObj.put("application", formatedJSONArray(exeCur.getApplicationList()));262 curveObj.put("unit", "duration");263 curveObjMap.put(curveKey, curveObj);264 }265 curArray.put(pointObj);266 curveMap.put(curveKey, curArray);267 }268 /**269 * Bar Charts per control status.270 */271 curveBarMap.add(exeCur.getTag());272 curveTagObjMap.put(exeCur.getTag(), exeCur);273 curveKeyStatus = "RETRY";274 List<Integer> tempList;275 Integer myVal = exeCur.getNbExe() + exeCur.getNbQE() + exeCur.getNbQU() - exeCur.getNbExeUsefull();276 if (curveTagObjValMap.containsKey(curveKeyStatus)) {277 tempList = curveTagObjValMap.get(curveKeyStatus);278 tempList.add(myVal);279 } else {280 tempList = new ArrayList<>();281 tempList.add(myVal);282 }283 curveTagObjValMap.put(curveKeyStatus, tempList);284 if (curveTagObjValTotMap.containsKey(curveKeyStatus)) {285 curveTagObjValTotMap.put(curveKeyStatus, curveTagObjValTotMap.get(curveKeyStatus) + myVal);286 } else {287 curveTagObjValTotMap.put(curveKeyStatus, myVal);288 }289 for (TestCaseExecution.ControlStatus ctrlStat : TestCaseExecution.ControlStatus.values()) {290 curveKeyStatus = ctrlStat.name();291 myVal = 0;292 switch (curveKeyStatus) {293 case TestCaseExecution.CONTROLSTATUS_CA:294 myVal = exeCur.getNbCA();295 break;296 case TestCaseExecution.CONTROLSTATUS_FA:297 myVal = exeCur.getNbFA();298 break;299 case TestCaseExecution.CONTROLSTATUS_KO:300 myVal = exeCur.getNbKO();301 break;302 case TestCaseExecution.CONTROLSTATUS_NA:303 myVal = exeCur.getNbNA();304 break;305 case TestCaseExecution.CONTROLSTATUS_NE:306 myVal = exeCur.getNbNE();307 break;308 case TestCaseExecution.CONTROLSTATUS_OK:309 myVal = exeCur.getNbOK();310 break;311 case TestCaseExecution.CONTROLSTATUS_PE:312 myVal = exeCur.getNbPE();313 break;314 case TestCaseExecution.CONTROLSTATUS_QE:315 myVal = exeCur.getNbQE();316 break;317 case TestCaseExecution.CONTROLSTATUS_QU:318 myVal = exeCur.getNbQU();319 break;320 case TestCaseExecution.CONTROLSTATUS_WE:321 myVal = exeCur.getNbWE();322 break;323 }324 if (curveTagObjValMap.containsKey(curveKeyStatus)) {325 tempList = curveTagObjValMap.get(curveKeyStatus);326 tempList.add(myVal);327 } else {328 tempList = new ArrayList<>();329 tempList.add(myVal);330 }331 curveTagObjValMap.put(curveKeyStatus, tempList);332 if (curveTagObjValTotMap.containsKey(curveKeyStatus)) {333 curveTagObjValTotMap.put(curveKeyStatus, curveTagObjValTotMap.get(curveKeyStatus) + myVal);334 } else {335 curveTagObjValTotMap.put(curveKeyStatus, myVal);336 }337 }338 }339 }340 /**341 * Feed Curves of testcase response time to JSON.342 */343 JSONArray curvesArray = new JSONArray();344 for (Map.Entry<String, JSONObject> entry : curveObjMap.entrySet()) {345 String key = entry.getKey();346 JSONObject val = entry.getValue();347 JSONObject localcur = new JSONObject();348 localcur.put("key", val);349 localcur.put("points", curveMap.get(key));350 curvesArray.put(localcur);351 }352 object.put("curvesTime", curvesArray);353 JSONObject objectdist = getAllDistinct(countryMap, environmentMap, robotDecliMap, countriesDefined, environmentsDefined, robotDeclisDefined);354 object.put("distinct", objectdist);355 /**356 * Bar Charts per control status to JSON.357 */358 curvesArray = new JSONArray();359 for (String entry : curveBarMap) {360 curvesArray.put(entry);361 }362 object.put("curvesTag", curvesArray);363 curvesArray = new JSONArray();364 JSONObject objStat = new JSONObject();365 JSONObject objStatKey = new JSONObject();366 JSONArray curvesArray1 = new JSONArray();367 for (TestCaseExecution.ControlStatus ctrlStat : TestCaseExecution.ControlStatus.values()) {368 objStat = new JSONObject();369 objStatKey = new JSONObject();370 objStatKey.put("key", ctrlStat.name());371 objStatKey.put("unit", "nbExe");372 objStatKey.put("totalExe", curveTagObjValTotMap.get(ctrlStat.name()));373 objStat.put("key", objStatKey);374 curvesArray1 = new JSONArray();375 if (curveTagObjValMap.containsKey(ctrlStat.name())) {376 for (Integer myInt : curveTagObjValMap.get(ctrlStat.name())) {377 curvesArray1.put(myInt);378 }379 }380 objStat.put("points", curvesArray1);381 if (curveTagObjValTotMap.containsKey(ctrlStat.name())) {382 if (curveTagObjValTotMap.get(ctrlStat.name()) > 0) {383 curvesArray.put(objStat);384 }385 }386 }387 objStat = new JSONObject();388 objStatKey = new JSONObject();389 objStatKey.put("key", "RETRY");390 objStatKey.put("unit", "nbExe");391 objStatKey.put("totalExe", curveTagObjValTotMap.get("RETRY"));392 objStat.put("key", objStatKey);393 curvesArray1 = new JSONArray();394 if (curveTagObjValMap.containsKey("RETRY")) {395 for (Integer myInt : curveTagObjValMap.get("RETRY")) {396 curvesArray1.put(myInt);397 }398 }399 objStat.put("points", curvesArray1);400 if (curveTagObjValTotMap.containsKey("RETRY")) {401 if (curveTagObjValTotMap.get("RETRY") > 0) {402 curvesArray.put(objStat);403 }404 }405 object.put("curvesTagStatus", curvesArray);406 item.setItem(object);407 return item;408 }409 private JSONObject getAllDistinct(410 HashMap<String, Boolean> countryMap,411 HashMap<String, Boolean> environmentMap,412 HashMap<String, Boolean> robotDecliMap,413 Boolean countriesDefined,414 Boolean environmentsDefined,415 Boolean robotDeclisDefined) throws JSONException {416 JSONObject objectdist = new JSONObject();417 JSONArray objectCdinst = new JSONArray();418 for (Map.Entry<String, Boolean> country : countryMap.entrySet()) {419 String key = country.getKey();420 JSONObject objectcount = new JSONObject();421 objectcount.put("name", formatedJSONArray(key));422 objectcount.put("hasData", countryMap.containsKey(key));423 if (countriesDefined) {424 objectcount.put("isRequested", countryMap.get(key));425 } else {426 objectcount.put("isRequested", true);427 }428 objectCdinst.put(objectcount);429 }430 objectdist.put("countries", objectCdinst);431 JSONArray objectdinst = new JSONArray();432 for (Map.Entry<String, Boolean> env : environmentMap.entrySet()) {433 String key = env.getKey();434 JSONObject objectcount = new JSONObject();435 objectcount.put("name", formatedJSONArray(key));436 objectcount.put("hasData", environmentMap.containsKey(key));437 if (environmentsDefined) {438 objectcount.put("isRequested", environmentMap.get(key));439 } else {440 objectcount.put("isRequested", true);441 }442 objectdinst.put(objectcount);443 }444 objectdist.put("environments", objectdinst);445 objectdinst = new JSONArray();446 for (Map.Entry<String, Boolean> env : robotDecliMap.entrySet()) {447 String key = env.getKey();448 JSONObject objectcount = new JSONObject();449 objectcount.put("name", formatedJSONArray(key));450 objectcount.put("hasData", robotDecliMap.containsKey(key));451 if (robotDeclisDefined) {452 objectcount.put("isRequested", robotDecliMap.get(key));453 } else {454 objectcount.put("isRequested", true);455 }456 objectdinst.put(objectcount);457 }458 objectdist.put("robotDeclis", objectdinst);459 return objectdist;460 }461 private String formatedJSONArray(String in) {462 if ((in == null) || (in.equals("[]"))) {463 return "";464 } else {465 return in.replace("\"]", "").replace("[\"", "").replace("\",\"", "|");466 }467 }468 private String getKeyCurve(TestCaseExecutionHttpStat stat, String party, String type, String unit) {469 return type + "/" + party + "/" + unit + "/" + stat.getTest() + "/" + stat.getTestCase() + "/" + stat.getCountry() + "/" + stat.getEnvironment() + "/" + stat.getRobotDecli() + "/" + stat.getSystem() + "/" + stat.getApplication();470 }471 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">472 /**473 * Handles the HTTP <code>GET</code> method.474 *475 * @param request servlet request476 * @param response servlet response477 * @throws ServletException if a servlet-specific error occurs478 * @throws IOException if an I/O error occurs479 */480 @Override481 protected void doGet(HttpServletRequest request, HttpServletResponse response)482 throws ServletException, IOException {483 try {484 processRequest(request, response);485 } catch (CerberusException ex) {486 LOG.warn(ex);487 }488 }489 /**490 * Handles the HTTP <code>POST</code> method.491 *492 * @param request servlet request493 * @param response servlet response494 * @throws ServletException if a servlet-specific error occurs495 * @throws IOException if an I/O error occurs496 */497 @Override498 protected void doPost(HttpServletRequest request, HttpServletResponse response)499 throws ServletException, IOException {500 try {501 processRequest(request, response);502 } catch (CerberusException ex) {503 LOG.warn(ex);504 }505 }506 /**507 * Returns a short description of the servlet.508 *509 * @return a String containing servlet description510 */511 @Override512 public String getServletInfo() {513 return "Short description";514 }// </editor-fold>515}...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.crud.testexecution.ReadTagStat;2ReadTagStat readTagStat = new ReadTagStat();3readTagStat.processRequest(request, response);4JSONObject result = readTagStat.getJsonResult();5out.println(result.toString());6{"tag":"1.0.0","nbExecuted":0,"nbOK":0,"nbKO":0,"nbFA":0,"nbNA":0,"nbNE":0,"nbPE":0,"nbQU":0,"nbWE":0,"nbCA":0,"nbQA":0,"nbQE":0,"nbTO":0,"nbCO":0,"nbNA":0,"nbWE":0,"nbFA":0,"nbOK":0,"nbKO":0,"nbPE":0,"nbQU":0,"nbNE":0,"nbCA":0,"nbQA":0,"nbQE":0,"nbTO":0,"nbCO":0,"nbNA":0,"nbWE":0,"nbFA":0,"nbOK":0,"nbKO":0,"nbPE":0,"nbQU":0,"nbNE":0,"nbCA":0,"nbQA":0,"nbQE":0,"nbTO":0,"nbCO":0,"nbNA":0,"nbWE":0,"nbFA":0,"nbOK":0,"nbKO":0,"nbPE":0,"nbQU":0,"nbNE":0,"nbCA":0,"nbQA":0,"nbQE":0,"nbTO":0,"nbCO":0,"nbNA":0,"nbWE":0,"nbFA":0,"nbOK":0,"nbKO":0,"nbPE":0,"nbQU":0,"nbNE":0,"nbCA":0,"nbQA":0,"nbQE":0,"nbTO":0,"nbCO":0,"nbNA":0,"nbWE":0,"nbFA":0,"nbOK":0,"nbKO":0,"nbPE":0,"nbQU":0,"nbNE":0,"nbCA":0,"nbQA":0,"nbQE":0,"nbTO":0,"nbCO":0

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.crud.testexecution.ReadTagStat2import java.io.File3import java.io.PrintWriter4import java.sql.Timestamp5import java.time.LocalDateTime6import java.time.format.DateTimeFormatter7def file = new File(filename)8def writer = new PrintWriter(file)9def now = Timestamp.valueOf(LocalDateTime.now())10def formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss")11def date = now.toLocalDateTime().format(formatter)

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful