List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet rowIterator
@Override
public Iterator<Row> rowIterator()
From source file:com.photon.phresco.framework.commons.FrameworkUtil.java
License:Apache License
public boolean deleteTestCasesFromXls(String filePath, String testSuiteName, String testCaseId) { boolean hasTrue = false; List<TestCase> testCases = new ArrayList<TestCase>(); TestCase tstCase = new TestCase(); Iterator<Row> rowIterator; try {//from ww w . j a v a 2 s . com FileInputStream myInput = new FileInputStream(filePath); HSSFWorkbook myWorkBook = new HSSFWorkbook(myInput); int numberOfSheets = myWorkBook.getNumberOfSheets(); for (int j = 0; j < numberOfSheets; j++) { HSSFSheet mySheet = myWorkBook.getSheetAt(j); if (mySheet.getSheetName().equals(testSuiteName)) { rowIterator = mySheet.rowIterator(); for (int i = 0; i <= 23; i++) { rowIterator.next(); } while (rowIterator.hasNext()) { Row next = rowIterator.next(); if (testCaseId.equalsIgnoreCase(getValue(next.getCell(3)))) { tstCase = readTest(next); mySheet.removeRow(next); int rowNum = next.getRowNum(); int newNum = rowNum + 1; HSSFRow row = mySheet.getRow(newNum); if (row != null) { mySheet.shiftRows(newNum, mySheet.getLastRowNum(), -1); } hasTrue = true; break; } } } } if (hasTrue) { for (int j = 0; j < numberOfSheets; j++) { HSSFSheet myHSSFSheet = myWorkBook.getSheetAt(j); if (myHSSFSheet.getSheetName().equals(testSuiteName)) { rowIterator = myHSSFSheet.rowIterator(); for (int i = 0; i <= 23; i++) { rowIterator.next(); } while (rowIterator.hasNext()) { Row next = rowIterator.next(); TestCase createObject = readTest(next); if (StringUtils.isNotEmpty(createObject.getTestCaseId())) { testCases.add(createObject); } } float totalPass = 0; float totalFail = 0; float totalNotApplicable = 0; float totalBlocked = 0; int totalTestCases = testCases.size(); for (TestCase testCase : testCases) { String testCaseStatus = testCase.getStatus(); if (testCaseStatus.equalsIgnoreCase("success")) { totalPass = totalPass + 1; } else if (testCaseStatus.equalsIgnoreCase("failure")) { totalFail = totalFail + 1; } else if (testCaseStatus.equalsIgnoreCase("notApplicable")) { totalNotApplicable = totalNotApplicable + 1; } else if (testCaseStatus.equalsIgnoreCase("blocked")) { totalBlocked = totalBlocked + 1; } } // if(tstCase.getStatus().equalsIgnoreCase("success")) { // totalPass = totalPass - 1; // } else if (tstCase.getStatus().equalsIgnoreCase("failure")) { // totalFail = totalFail - 1; // } else if (tstCase.getStatus().equalsIgnoreCase("notApplicable")) { // totalNotApplicable = totalNotApplicable - 1; // } else if (tstCase.getStatus().equalsIgnoreCase("blocked")) { // totalBlocked = totalBlocked - 1; // } HSSFSheet mySheet1 = myWorkBook.getSheetAt(0); rowIterator = mySheet1.rowIterator(); for (int i = 0; i <= 2; i++) { rowIterator.next(); } while (rowIterator.hasNext()) { Row next1 = rowIterator.next(); if (StringUtils.isNotEmpty(getValue(next1.getCell(2))) && !getValue(next1.getCell(2)).equalsIgnoreCase("Total")) { TestSuite createObject = createObject(next1); if (StringUtils.isNotEmpty(tstCase.getTestCaseId()) && createObject.getName().equals(testSuiteName)) { updateIndex(totalPass, totalFail, totalNotApplicable, totalBlocked, next1, totalTestCases, "delete"); } } } } } myInput.close(); FileOutputStream outFile = new FileOutputStream(filePath); myWorkBook.write(outFile); outFile.close(); } } catch (Exception e) { } return hasTrue; }
From source file:com.photon.phresco.framework.commons.FrameworkUtil.java
License:Apache License
private void updateIndexPage(String fileName, com.photon.phresco.commons.model.TestCase tstCase, List<TestCase> testCases, HSSFWorkbook myWorkBook) throws UnknownHostException, PhrescoException { Iterator<Row> rowIterator; float totalPass = 0; float totalFail = 0; float totalNotApplicable = 0; float totalBlocked = 0; for (TestCase testCase : testCases) { String testCaseStatus = testCase.getStatus(); String testId = tstCase.getTestCaseId(); String status = tstCase.getStatus(); if (testCaseStatus.equalsIgnoreCase("success") && !testCase.getTestCaseId().equalsIgnoreCase(testId)) { totalPass = totalPass + 1;/*from www . jav a 2 s . co m*/ } else if (testCaseStatus.equalsIgnoreCase("failure") && !testCase.getTestCaseId().equalsIgnoreCase(testId)) { totalFail = totalFail + 1; } else if (testCaseStatus.equalsIgnoreCase("notApplicable") && !testCase.getTestCaseId().equalsIgnoreCase(testId)) { totalNotApplicable = totalNotApplicable + 1; } else if (testCaseStatus.equalsIgnoreCase("blocked") && !testCase.getTestCaseId().equalsIgnoreCase(testId)) { totalBlocked = totalBlocked + 1; } if (testCase.getTestCaseId().equalsIgnoreCase(testId) && !testCase.getStatus().equalsIgnoreCase("success") && status.equalsIgnoreCase("success")) { totalPass = totalPass + 1; } else if (testCase.getTestCaseId().equalsIgnoreCase(testId) && !testCase.getStatus().equalsIgnoreCase("failure") && status.equalsIgnoreCase("failure")) { totalFail = totalFail + 1; } else if (testCase.getTestCaseId().equalsIgnoreCase(testId) && !testCase.getStatus().equalsIgnoreCase("notApplicable") && status.equalsIgnoreCase("notApplicable")) { totalNotApplicable = totalNotApplicable + 1; } else if (testCase.getTestCaseId().equalsIgnoreCase(testId) && !testCase.getStatus().equalsIgnoreCase("blocked") && status.equalsIgnoreCase("blocked")) { totalBlocked = totalBlocked + 1; } } HSSFSheet mySheet1 = myWorkBook.getSheetAt(0); rowIterator = mySheet1.rowIterator(); for (int i = 0; i <= 2; i++) { rowIterator.next(); } while (rowIterator.hasNext()) { Row next1 = rowIterator.next(); if (StringUtils.isNotEmpty(getValue(next1.getCell(2))) && !getValue(next1.getCell(2)).equalsIgnoreCase("Total")) { TestSuite createObject = createObject(next1); if (StringUtils.isNotEmpty(tstCase.getTestCaseId()) && createObject.getName().equals(fileName)) { updateIndex(totalPass, totalFail, totalNotApplicable, totalBlocked, next1, 0, ""); } } } }
From source file:com.photon.phresco.framework.commons.FrameworkUtil.java
License:Apache License
private void readTestFromSheet(com.photon.phresco.commons.model.TestCase tstCase, List<TestCase> testCases, HSSFSheet mySheet) { Iterator<Row> rowIterator = mySheet.rowIterator(); for (int i = 0; i <= 23; i++) { rowIterator.next();/*w w w .j a v a 2 s. c om*/ } while (rowIterator.hasNext()) { Row next = rowIterator.next(); if (StringUtils.isNotEmpty(getValue(next.getCell(1)))) { TestCase createObject = readTest(next); testCases.add(createObject); if (tstCase != null && createObject.getTestCaseId().equals(tstCase.getTestCaseId())) { Cell preConditionsCell = next.getCell(5); preConditionsCell.setCellValue(tstCase.getPreconditions()); Cell stepsCell = next.getCell(6); stepsCell.setCellValue(tstCase.getSteps()); Cell expectedCell = next.getCell(9); expectedCell.setCellValue(tstCase.getExpectedResult()); Cell actualCell = next.getCell(10); actualCell.setCellValue(tstCase.getActualResult()); Cell statusCell = next.getCell(11); statusCell.setCellValue(tstCase.getStatus()); Cell commentCell = next.getCell(12); commentCell.setCellValue(tstCase.getBugComment()); } } } }
From source file:com.photon.phresco.framework.commons.FrameworkUtil.java
License:Apache License
private void writeTestCaseToXLS(String testSuiteName, String[] cellValue, String status, int numCol, int cellno, CellStyle[] tryStyle, StringBuilder sb) throws PhrescoException { Iterator<Row> rowIterator; try {//from www . ja va 2 s .co m FileInputStream myInput = new FileInputStream(sb.toString()); HSSFWorkbook myWorkBook = new HSSFWorkbook(myInput); int numberOfSheets = myWorkBook.getNumberOfSheets(); for (int j = 0; j < numberOfSheets; j++) { HSSFSheet myHssfSheet = myWorkBook.getSheetAt(j); if (myHssfSheet.getSheetName().equals(testSuiteName)) { rowIterator = myHssfSheet.rowIterator(); Row next; for (Cell cell : myHssfSheet.getRow((myHssfSheet.getLastRowNum()) - 1)) { tryStyle[cellno] = cell.getCellStyle(); cellno = cellno + 1; if (cellno == 15) { break; } } float totalPass = 0; float totalFail = 0; float totalNotApp = 0; float totalBlocked = 0; float notExecuted = 0; float totalTestCases = 0; for (int i = 0; i <= 22; i++) { rowIterator.next(); } do { next = rowIterator.next(); if (StringUtils.isNotEmpty(getValue(next.getCell(1))) && !getValue(next.getCell(0)).equalsIgnoreCase("S.NO")) { String value = getValue(next.getCell(11)); if (StringUtils.isNotEmpty(value)) { if (value.equalsIgnoreCase("success")) { totalPass = totalPass + 1; } else if (value.equalsIgnoreCase("failure")) { totalFail = totalFail + 1; } else if (value.equalsIgnoreCase("notApplicable")) { totalNotApp = totalNotApp + 1; } else if (value.equalsIgnoreCase("blocked")) { totalBlocked = totalBlocked + 1; } } else { notExecuted = notExecuted + 1; } } } while (rowIterator.hasNext()); //to update the status in the index page if (status.equalsIgnoreCase("success")) { totalPass = totalPass + 1; } else if (status.equalsIgnoreCase("failure")) { totalFail = totalFail + 1; } else if (status.equalsIgnoreCase("notApplicable")) { totalNotApp = totalNotApp + 1; } else if (status.equalsIgnoreCase("blocked")) { totalBlocked = totalBlocked + 1; } else { notExecuted = notExecuted + 1; } totalTestCases = totalPass + totalFail + totalNotApp + totalBlocked + notExecuted; HSSFSheet mySheetHssf = myWorkBook.getSheetAt(0); rowIterator = mySheetHssf.rowIterator(); for (int i = 0; i <= 2; i++) { rowIterator.next(); } while (rowIterator.hasNext()) { Row next1 = rowIterator.next(); if (StringUtils.isNotEmpty(getValue(next1.getCell(2))) && !getValue(next1.getCell(2)).equalsIgnoreCase("Total")) { TestSuite createObject = createObject(next1); if (createObject.getName().equals(testSuiteName)) { addCalculationsToIndex(totalPass, totalFail, totalNotApp, totalBlocked, notExecuted, totalTestCases, next1); } } } Row r = null; if (myHssfSheet.getSheetName().equalsIgnoreCase("Index")) { r = myHssfSheet.createRow(next.getRowNum() - 1); } else { r = myHssfSheet.createRow(next.getRowNum() + 1); } for (int i = 0; i < numCol; i++) { Cell cell = r.createCell(i); cell.setCellValue(cellValue[i]); if (tryStyle[i] != null) { cell.setCellStyle(tryStyle[i]); } } FileOutputStream fileOut = new FileOutputStream(sb.toString()); myWorkBook.write(fileOut); myInput.close(); fileOut.close(); } } } catch (PhrescoException e) { throw new PhrescoException(e); } catch (FileNotFoundException e) { throw new PhrescoException(e); } catch (IOException e) { throw new PhrescoException(e); } }
From source file:com.photon.phresco.service.tools.AdminConfigGenerator.java
License:Apache License
public void publish(boolean overwrite) throws PhrescoException { List<AdminConfigInfo> adminConfigInfos = new ArrayList<AdminConfigInfo>(); HSSFSheet sheet = workBook.getSheet(PROPERTY); Iterator<Row> rowIterator = sheet.rowIterator(); for (int i = 0; i < NO_OF_ROWS_TO_SKIP; i++) { rowIterator.next();// w w w . ja v a 2 s.c om } AdminConfigInfo adminConfigInfo = new AdminConfigInfo(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); adminConfigInfo = createAdminConfig(row); System.out.println("admin config info-->" + adminConfigInfo.getId() + "---" + adminConfigInfo.getKey() + "---" + adminConfigInfo.getValue() + "--" + adminConfigInfo.getDescription()); adminConfigInfos.add(adminConfigInfo); //dataManager.addAdminConfigInfo(adminConfigInfos); } dataManager.addAdminConfigInfo(adminConfigInfos); //System.out.println ("admin config info-->"+adminConfigInfo.getKey()+"---"+adminConfigInfo.getValue()); //adminConfigInfos.add(adminConfigInfo); //Data Persistence //dataManager.addAdminConfigInfo(adminConfigInfos); //dataManager.addAdminConfigInfo(adminConfigInfo); //addAdminConfigInfo writesJson(adminConfigInfos, outFile); //uploadToRepository(configInfos, overwrite); }
From source file:com.photon.phresco.service.tools.JsLibraryGenerator.java
License:Apache License
private void generate(String tech) throws PhrescoException { ModuleGroup moduleGroup = new ModuleGroup(); List<ModuleGroup> jsLibs = new ArrayList<ModuleGroup>(); workBook = getWorkBook(tech);/* w ww. j a v a 2 s . c o m*/ HSSFSheet sheet = workBook.getSheet(JSLIBRARY); Iterator<Row> rowIterator = sheet.rowIterator(); for (int i = 0; i < noOfRowsToSkip; i++) { rowIterator.next(); } while (rowIterator.hasNext()) { Row row = rowIterator.next(); moduleGroup = createJSLibrary(row, tech); jsLibs.add(moduleGroup); } serviceManager = ServiceClientFactory.getServiceManager(context); RestClient<ModuleGroup> techClient = serviceManager.getRestClient("component/modules"); ClientResponse response = techClient.create(jsLibs); System.out.println(tech + "Uploaded Successfully................"); System.out.println(response.getStatus()); // writeTo(libraries, tech); // uploadToRepository(libraries, tech); }
From source file:com.photon.phresco.service.tools.PilotProjectGenerator.java
License:Apache License
private void createPilots(String tech, HSSFWorkbook workBook) throws PhrescoException { HSSFSheet sheet = workBook.getSheet(SHEET_NAME_PILOTS); Iterator<Row> rowsIter = sheet.rowIterator(); // Skipping first row for (int i = 0; i < NO_OF_ROWS_TO_SKIP; i++) { rowsIter.next();// w w w .ja v a 2 s . c om } while (rowsIter.hasNext()) { Row row = rowsIter.next(); createPilots(tech, row); } }
From source file:com.photon.phresco.service.tools.PilotProjectGenerator.java
License:Apache License
private void generateJSLibrary(HSSFWorkbook workBook, String tech) { HSSFSheet sheet = workBook.getSheet(SHEET_NAME_JSLIBRARY); Iterator<Row> rowsIter = sheet.rowIterator(); for (int i = 0; i < NO_OF_ROWS_TO_SKIP; i++) { rowsIter.next();/*from w w w . j a v a 2 s . c o m*/ } while (rowsIter.hasNext()) { Row row = rowsIter.next(); createJSLibrary(tech, row); } }
From source file:com.photon.phresco.service.tools.PilotProjectGenerator.java
License:Apache License
private void generateModule(HSSFWorkbook workBook, String tech) throws PhrescoException { HSSFSheet sheet = workBook.getSheet(SHEET_NAME_MODULE); Iterator<Row> rowsIter = sheet.rowIterator(); for (int i = 0; i < NO_OF_ROWS_TO_SKIP; i++) { rowsIter.next();/* w w w . j a v a 2 s . com*/ } while (rowsIter.hasNext()) { Row row = rowsIter.next(); createModule(tech, row); } }
From source file:com.photon.phresco.service.tools.TechnologyDataGenerator.java
License:Apache License
private List<ModuleGroup> createModules(String tech, HSSFWorkbook workBook) throws PhrescoException { List<ModuleGroup> moduleGroups = new ArrayList<ModuleGroup>(); HSSFSheet sheet = workBook.getSheet(SHEET_NAME_MODULE); Modules modules = new Modules(); Iterator<Row> rowsIter = sheet.rowIterator(); // Skipping first row for (int i = 0; i < NO_OF_ROWS_TO_SKIP; i++) { rowsIter.next();/*from w ww . j a va2 s . co m*/ } while (rowsIter.hasNext()) { Row row = rowsIter.next(); ModuleGroup module = createModuleGroup(tech, row); if (module != null) { moduleGroups.add(module); } } return moduleGroups; }