use of org.cerberus.dto.SummaryStatisticsDTO in project cerberus-source by cerberustesting.
the class ExportServiceFactory method createReportByTagExport.
private void createReportByTagExport(Workbook workbook) {
// handles the export of the execution by tag data
HashMap<String, SummaryStatisticsDTO> summaryMap = new HashMap<String, SummaryStatisticsDTO>();
HashMap<String, HashMap<String, List<TestCaseExecution>>> mapList = new HashMap<String, HashMap<String, List<TestCaseExecution>>>();
List<String> mapCountries = new ArrayList<String>();
List<CellStyle> stylesList = new LinkedList<CellStyle>();
if (exportOptions.contains("chart") || exportOptions.contains("list")) {
// then we need to create the default colors for each cell
try (HSSFWorkbook hwb = new HSSFWorkbook()) {
HSSFPalette palette = hwb.getCustomPalette();
CellStyle okStyle = workbook.createCellStyle();
// get the color which most closely matches the color you want to use
// code to get the style for the cell goes here
okStyle.setFillForegroundColor(palette.findSimilarColor(92, 184, 0).getIndex());
okStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
// okStyle.setFont();
stylesList.add(okStyle);
} catch (IOException e) {
LOG.warn(e.toString());
}
}
for (TestCaseExecution execution : (List<TestCaseExecution>) list) {
if (exportOptions.contains("chart") || exportOptions.contains("summary")) {
String keySummaryTable = execution.getApplication() + " " + execution.getCountry() + " " + execution.getEnvironment();
SummaryStatisticsDTO stats;
String status = execution.getControlStatus();
if (summaryMap.containsKey(keySummaryTable)) {
stats = summaryMap.get(keySummaryTable);
} else {
stats = new SummaryStatisticsDTO();
stats.setApplication(execution.getApplication());
stats.setCountry(execution.getCountry());
stats.setEnvironment(execution.getEnvironment());
}
stats.updateStatisticByStatus(status);
// updates the map
summaryMap.put(keySummaryTable, stats);
}
if (exportOptions.contains("list")) {
if (exportOptions.contains("filter")) {
// filter active
} else {
// all data is saved
}
HashMap<String, List<TestCaseExecution>> listExecution;
List<TestCaseExecution> testCaseList;
String testKey = execution.getTest();
String testCaseKey = execution.getTestCase();
if (mapList.containsKey(testKey)) {
listExecution = mapList.get(testKey);
} else {
listExecution = new HashMap<String, List<TestCaseExecution>>();
}
if (listExecution.containsKey(testCaseKey)) {
testCaseList = listExecution.get(testCaseKey);
} else {
testCaseList = new ArrayList<TestCaseExecution>();
}
testCaseList.add(execution);
listExecution.put(testCaseKey, testCaseList);
mapList.put(testKey, listExecution);
if (mapCountries.indexOf(execution.getCountry()) == -1) {
mapCountries.add(execution.getCountry());
}
}
}
int rowCount = -1;
// Create a blank sheet
Sheet sheet = workbook.createSheet("Report by Tag");
sheet.getPrintSetup().setLandscape(true);
PrintSetup ps = sheet.getPrintSetup();
sheet.setAutobreaks(true);
// ps.setFitHeight((short) 1);
ps.setFitWidth((short) 1);
sheet.setFitToPage(true);
sheet.setColumnWidth(0, 9000);
if (exportOptions.contains("chart")) {
SummaryStatisticsDTO sumsTotal = calculateTotalValues(summaryMap);
Row row = sheet.createRow(++rowCount);
row.createCell(0).setCellValue("Report By Status");
row = sheet.createRow(++rowCount);
row.createCell(0).setCellValue("Status");
row.createCell(1).setCellValue("Total");
row.createCell(2).setCellValue("Percentage");
row = sheet.createRow(++rowCount);
CellStyle okStyle = stylesList.get(0);
Cell cellOk = row.createCell(0);
cellOk.setCellValue("OK");
cellOk.setCellStyle(okStyle);
row.createCell(1).setCellValue(sumsTotal.getOK());
row.createCell(2).setCellValue(sumsTotal.getPercOK());
row = sheet.createRow(++rowCount);
row.createCell(0).setCellValue("KO");
row.createCell(1).setCellValue(sumsTotal.getKO());
row.createCell(2).setCellValue(sumsTotal.getPercKO());
row = sheet.createRow(++rowCount);
row.createCell(0).setCellValue("FA");
row.createCell(1).setCellValue(sumsTotal.getFA());
row.createCell(2).setCellValue(sumsTotal.getPercFA());
row = sheet.createRow(++rowCount);
row.createCell(0).setCellValue("NA");
row.createCell(1).setCellValue(sumsTotal.getNA());
row.createCell(2).setCellValue(sumsTotal.getPercNA());
row = sheet.createRow(++rowCount);
row.createCell(0).setCellValue("NE");
row.createCell(1).setCellValue(sumsTotal.getNE());
row.createCell(2).setCellValue(sumsTotal.getPercNE());
row = sheet.createRow(++rowCount);
row.createCell(0).setCellValue("QU");
row.createCell(1).setCellValue(sumsTotal.getQU());
row.createCell(2).setCellValue(sumsTotal.getPercQU());
row = sheet.createRow(++rowCount);
row.createCell(0).setCellValue("PE");
row.createCell(1).setCellValue(sumsTotal.getPE());
row.createCell(2).setCellValue(sumsTotal.getPercPE());
row = sheet.createRow(++rowCount);
row.createCell(0).setCellValue("CA");
row.createCell(1).setCellValue(sumsTotal.getCA());
row.createCell(2).setCellValue(sumsTotal.getPercCA());
row = sheet.createRow(++rowCount);
row.createCell(0).setCellValue("Total");
row.createCell(1).setCellValue(sumsTotal.getTotal());
sheet.createRow(++rowCount).createCell(0).setCellValue("");
sheet.createRow(++rowCount).createCell(0).setCellValue("");
sheet.createRow(++rowCount).createCell(0).setCellValue("");
sheet.createRow(++rowCount).createCell(0).setCellValue("");
}
if (exportOptions.contains("summary")) {
// draw the table with data
Row row = sheet.createRow(++rowCount);
row.createCell(0).setCellValue("Summary Table");
// start creating data
row = sheet.createRow(++rowCount);
row.createCell(0).setCellValue("Application");
row.createCell(1).setCellValue("Country");
row.createCell(2).setCellValue("Environment");
row.createCell(3).setCellValue("OK");
row.createCell(4).setCellValue("KO");
row.createCell(5).setCellValue("FA");
row.createCell(6).setCellValue("NA");
row.createCell(7).setCellValue("NE");
row.createCell(8).setCellValue("PE");
row.createCell(8).setCellValue("QU");
row.createCell(9).setCellValue("CA");
row.createCell(10).setCellValue("NOT OK");
row.createCell(11).setCellValue("Total");
/*temporary styles*/
CellStyle styleBlue = workbook.createCellStyle();
CellStyle styleGreen = workbook.createCellStyle();
try (HSSFWorkbook hwb = new HSSFWorkbook()) {
HSSFPalette palette = hwb.getCustomPalette();
// get the color which most closely matches the color you want to use
HSSFColor myColor = palette.findSimilarColor(66, 139, 202);
// get the palette index of that color
short palIndex = myColor.getIndex();
// code to get the style for the cell goes here
styleBlue.setFillForegroundColor(palIndex);
styleBlue.setFillPattern(CellStyle.SPARSE_DOTS);
HSSFColor myColorGreen = palette.findSimilarColor(92, 184, 0);
styleGreen.setFillForegroundColor(myColorGreen.getIndex());
styleGreen.setFillPattern(CellStyle.SPARSE_DOTS);
int startRow = (rowCount + 2);
TreeMap<String, SummaryStatisticsDTO> sortedSummaryMap = new TreeMap<String, SummaryStatisticsDTO>(summaryMap);
for (String key : sortedSummaryMap.keySet()) {
row = sheet.createRow(++rowCount);
SummaryStatisticsDTO sumStats = summaryMap.get(key);
// application
row.createCell(0).setCellValue((String) sumStats.getApplication());
// country
row.createCell(1).setCellValue((String) sumStats.getCountry());
// environment
row.createCell(2).setCellValue((String) sumStats.getEnvironment());
// OK
row.createCell(3).setCellValue(sumStats.getOK());
// KO
row.createCell(4).setCellValue(sumStats.getKO());
// FA
row.createCell(5).setCellValue(sumStats.getFA());
// NA
row.createCell(6).setCellValue(sumStats.getNA());
// NE
row.createCell(7).setCellValue(sumStats.getNE());
// PE
row.createCell(8).setCellValue(sumStats.getPE());
// QU
row.createCell(9).setCellValue(sumStats.getQU());
// CA
row.createCell(10).setCellValue(sumStats.getCA());
int rowNumber = row.getRowNum() + 1;
// NOT OK
// row.createCell(11).setCellValue(sumStats.getNotOkTotal());
row.createCell(11).setCellFormula("SUM(E" + rowNumber + ":J" + rowNumber + ")");
// Total
row.createCell(12).setCellFormula("SUM(D" + rowNumber + ",K" + rowNumber + ")");
if (sumStats.getOK() == sumStats.getTotal()) {
for (int i = 0; i < 13; i++) {
row.getCell(i).setCellStyle(styleGreen);
}
}
}
// TODO:FN percentages missing
// Total row
row = sheet.createRow(++rowCount);
row.createCell(0).setCellValue("Total");
row.createCell(1).setCellValue("");
row.createCell(2).setCellValue("");
// OK
row.createCell(3).setCellFormula("SUM(D" + startRow + ":D" + rowCount + ")");
// KO
row.createCell(4).setCellFormula("SUM(E" + startRow + ":E" + rowCount + ")");
// FA
row.createCell(5).setCellFormula("SUM(F" + startRow + ":F" + rowCount + ")");
// NA
row.createCell(6).setCellFormula("SUM(G" + startRow + ":G" + rowCount + ")");
// NE
row.createCell(7).setCellFormula("SUM(H" + startRow + ":H" + rowCount + ")");
// PE
row.createCell(8).setCellFormula("SUM(I" + startRow + ":I" + rowCount + ")");
// QU
row.createCell(9).setCellFormula("SUM(J" + startRow + ":I" + rowCount + ")");
// CA
row.createCell(10).setCellFormula("SUM(K" + startRow + ":J" + rowCount + ")");
int rowNumberTotal = row.getRowNum() + 1;
// NOT OK
row.createCell(11).setCellFormula("SUM(E" + rowNumberTotal + ":J" + rowNumberTotal + ")");
// Total
row.createCell(12).setCellFormula("SUM(D" + rowNumberTotal + ",K" + rowNumberTotal + ")");
for (int i = 0; i < 13; i++) {
row.getCell(i).setCellStyle(styleBlue);
}
// add some empty rows
sheet.createRow(++rowCount).createCell(0).setCellValue("");
sheet.createRow(++rowCount).createCell(0).setCellValue("");
sheet.createRow(++rowCount).createCell(0).setCellValue("");
sheet.createRow(++rowCount).createCell(0).setCellValue("");
} catch (IOException e) {
LOG.warn(e.toString());
}
}
if (exportOptions.contains("list")) {
// exports the data from test cases' executions
Row r = sheet.createRow(++rowCount);
r.createCell(0).setCellValue("Test");
r.createCell(1).setCellValue("Test Case");
r.createCell(2).setCellValue("Description");
r.createCell(3).setCellValue("Application");
r.createCell(4).setCellValue("Environment");
r.createCell(5).setCellValue("Browser");
// creates the country list
// sorts the list of countries
Collections.sort(mapCountries);
int startIndexForCountries = 6;
for (String country : mapCountries) {
r.createCell(startIndexForCountries).setCellValue(country);
startIndexForCountries++;
}
TreeMap<String, HashMap<String, List<TestCaseExecution>>> sortedKeys = new TreeMap<String, HashMap<String, List<TestCaseExecution>>>(mapList);
rowCount++;
for (String keyMapList : sortedKeys.keySet()) {
rowCount = createRow(keyMapList, mapList.get(keyMapList), sheet, rowCount, mapCountries);
}
}
}
use of org.cerberus.dto.SummaryStatisticsDTO in project cerberus-source by cerberustesting.
the class ExportServiceFactory method calculateTotalValues.
private SummaryStatisticsDTO calculateTotalValues(Map<String, SummaryStatisticsDTO> summaryMap) {
int okTotal = 0;
int koTotal = 0;
int naTotal = 0;
int neTotal = 0;
int peTotal = 0;
int quTotal = 0;
int faTotal = 0;
int caTotal = 0;
for (String key : summaryMap.keySet()) {
SummaryStatisticsDTO sumStats = summaryMap.get(key);
// percentage values
okTotal += sumStats.getOK();
koTotal += sumStats.getKO();
naTotal += sumStats.getNA();
neTotal += sumStats.getNE();
peTotal += sumStats.getPE();
quTotal += sumStats.getQU();
faTotal += sumStats.getFA();
caTotal += sumStats.getCA();
}
SummaryStatisticsDTO sumGlobal = new SummaryStatisticsDTO();
sumGlobal.setApplication("Total");
sumGlobal.setOK(okTotal);
sumGlobal.setKO(koTotal);
sumGlobal.setNA(naTotal);
sumGlobal.setNE(neTotal);
sumGlobal.setPE(peTotal);
sumGlobal.setQU(quTotal);
sumGlobal.setFA(faTotal);
sumGlobal.setCA(caTotal);
int notOkTotal = koTotal + naTotal + peTotal + faTotal + caTotal + neTotal + quTotal;
sumGlobal.setNotOKTotal(notOkTotal);
int totalGlobal = notOkTotal + okTotal;
sumGlobal.setTotal(totalGlobal);
sumGlobal.updatePercentageStatistics();
return sumGlobal;
}
use of org.cerberus.dto.SummaryStatisticsDTO in project cerberus-source by cerberustesting.
the class GetReportData 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, ParseException, JSONException {
response.setContentType("text/html;charset=UTF-8");
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
testCaseExecutionService = appContext.getBean(ITestCaseExecutionService.class);
testCaseExecutionInQueueService = appContext.getBean(ITestCaseExecutionQueueService.class);
response.setContentType("application/json");
response.setCharacterEncoding("utf8");
JSONObject jsonResult = new JSONObject();
String tag = request.getParameter("Tag");
boolean split = ParameterParserUtil.parseBooleanParam(request.getParameter("split"), false);
/**
* Get list of execution by tag, env, country, browser
*/
AnswerList<TestCaseExecution> listOfExecution = testCaseExecutionService.readByTagByCriteria(tag, 0, 0, null, null, null);
List<TestCaseExecution> testCaseExecutions = listOfExecution.getDataList();
/**
* Get list of Execution in Queue by Tag
*/
List<TestCaseExecutionQueue> testCaseExecutionsInQueue = testCaseExecutionInQueueService.findTestCaseExecutionInQueuebyTag(tag);
/**
* Feed hash map with execution from the two list (to get only one by
* test,testcase,country,env,browser)
*/
testCaseExecutions = hashExecution(testCaseExecutions, testCaseExecutionsInQueue);
/**
* Geting the global start and end of the execution tag.
*/
long startMin = 0;
long endMax = 0;
for (TestCaseExecution testCaseExecution : testCaseExecutions) {
if ((startMin == 0) || (testCaseExecution.getStart() < startMin)) {
startMin = testCaseExecution.getStart();
}
if ((endMax == 0) || (testCaseExecution.getEnd() > endMax)) {
endMax = testCaseExecution.getEnd();
}
}
if (!split) {
Map<String, JSONObject> axisMap = new HashMap<String, JSONObject>();
for (TestCaseExecution testCaseWithExecution : testCaseExecutions) {
String key;
String controlStatus;
JSONObject control = new JSONObject();
JSONObject function = new JSONObject();
if (testCaseWithExecution.getTestCaseObj().getFunction() != null && !"".equals(testCaseWithExecution.getTestCaseObj().getFunction())) {
key = testCaseWithExecution.getTestCaseObj().getFunction();
} else {
key = testCaseWithExecution.getTest();
}
controlStatus = testCaseWithExecution.getControlStatus();
control.put("value", 1);
control.put("color", getColor(controlStatus));
control.put("label", controlStatus);
function.put("name", key);
if (axisMap.containsKey(key)) {
function = axisMap.get(key);
if (function.has(controlStatus)) {
int prec = function.getJSONObject(controlStatus).getInt("value");
control.put("value", prec + 1);
}
}
function.put(controlStatus, control);
axisMap.put(key, function);
}
jsonResult.put("axis", axisMap.values());
jsonResult.put("tag", tag);
jsonResult.put("start", new Date(startMin));
jsonResult.put("end", new Date(endMax));
} else if (split) {
boolean env = ParameterParserUtil.parseBooleanParam(request.getParameter("env"), false);
boolean country = ParameterParserUtil.parseBooleanParam(request.getParameter("country"), false);
boolean browser = ParameterParserUtil.parseBooleanParam(request.getParameter("browser"), false);
boolean app = ParameterParserUtil.parseBooleanParam(request.getParameter("app"), false);
AnswerList columnExec = testCaseExecutionService.readDistinctColumnByTag(tag, env, country, browser, app);
List<TestCaseExecution> columnTcExec = columnExec.getDataList();
AnswerList columnQueue = testCaseExecutionInQueueService.readDistinctColumnByTag(tag, env, country, browser, app);
List<TestCaseExecutionQueue> columnInQueue = columnQueue.getDataList();
Map<String, TestCaseExecution> testCaseExecutionsList = new LinkedHashMap();
for (TestCaseExecution column : columnTcExec) {
String key = column.getBrowser() + column.getCountry() + column.getEnvironment() + column.getApplication();
testCaseExecutionsList.put(key, column);
}
for (TestCaseExecutionQueue column : columnInQueue) {
TestCaseExecution testCaseExecution = testCaseExecutionInQueueService.convertToTestCaseExecution(column);
String key = testCaseExecution.getBrowser() + testCaseExecution.getCountry() + testCaseExecution.getEnvironment() + testCaseExecution.getApplicationObj().getApplication();
testCaseExecutionsList.put(key, testCaseExecution);
}
List<TestCaseExecution> res = new ArrayList<TestCaseExecution>(testCaseExecutionsList.values());
HashMap<String, SummaryStatisticsDTO> statMap = new HashMap<String, SummaryStatisticsDTO>();
for (TestCaseExecution column : res) {
SummaryStatisticsDTO stat = new SummaryStatisticsDTO();
stat.setEnvironment(column.getEnvironment());
stat.setCountry(column.getCountry());
stat.setRobotDecli(column.getBrowser());
stat.setApplication(column.getApplication());
statMap.put(column.getEnvironment() + "_" + column.getCountry() + "_" + column.getBrowser() + "_" + column.getApplication(), stat);
}
jsonResult.put("contentTable", getStatByEnvCountryBrowser(testCaseExecutions, statMap, env, country, browser, app));
}
response.getWriter().print(jsonResult);
}
use of org.cerberus.dto.SummaryStatisticsDTO in project cerberus-source by cerberustesting.
the class GetReportData method extractSummaryData.
private JSONObject extractSummaryData(HashMap<String, SummaryStatisticsDTO> summaryMap, SummaryStatisticsDTO total) throws JSONException {
JSONObject extract = new JSONObject();
JSONArray dataArray = new JSONArray();
Gson gson = new Gson();
// sort keys
TreeMap<String, SummaryStatisticsDTO> sortedKeys = new TreeMap<String, SummaryStatisticsDTO>(summaryMap);
for (String key : sortedKeys.keySet()) {
SummaryStatisticsDTO sumStats = summaryMap.get(key);
// percentage values
sumStats.updatePercentageStatistics();
dataArray.put(new JSONObject(gson.toJson(sumStats)));
}
total.updatePercentageStatistics();
extract.put("split", dataArray);
extract.put("total", new JSONObject(gson.toJson(total)));
return extract;
}
use of org.cerberus.dto.SummaryStatisticsDTO in project cerberus-source by cerberustesting.
the class GetReportData method getStatByEnvCountryBrowser.
private JSONObject getStatByEnvCountryBrowser(List<TestCaseExecution> testCaseExecutions, HashMap<String, SummaryStatisticsDTO> statMap, boolean env, boolean country, boolean browser, boolean app) throws JSONException {
SummaryStatisticsDTO total = new SummaryStatisticsDTO();
total.setEnvironment("Total");
for (TestCaseExecution testCaseExecution : testCaseExecutions) {
StringBuilder key = new StringBuilder();
key.append((env) ? testCaseExecution.getEnvironment() : "");
key.append("_");
key.append((country) ? testCaseExecution.getCountry() : "");
key.append("_");
key.append((browser) ? testCaseExecution.getBrowser() : "");
key.append("_");
key.append((app) ? testCaseExecution.getApplication() : "");
if (statMap.containsKey(key.toString())) {
statMap.get(key.toString()).updateStatisticByStatus(testCaseExecution.getControlStatus());
}
total.updateStatisticByStatus(testCaseExecution.getControlStatus());
}
return extractSummaryData(statMap, total);
}
Aggregations