List of usage examples for org.apache.poi.xssf.usermodel XSSFCell getBooleanCellValue
@Override public boolean getBooleanCellValue()
From source file:uk.ac.bbsrc.tgac.miso.core.util.FormUtils.java
License:Open Source License
private static List<Sample> processSampleInputXLSX(XSSFWorkbook wb, User u, RequestManager manager, MisoNamingScheme<Library> libraryNamingScheme) throws Exception { ((RequestManagerAwareNamingScheme) libraryNamingScheme).setRequestManager(manager); List<Sample> samples = new ArrayList<Sample>(); XSSFSheet sheet = wb.getSheetAt(0);/* w ww . j a v a 2 s . co m*/ int rows = sheet.getPhysicalNumberOfRows(); XSSFRow glrow = sheet.getRow(1); //process global headers XSSFCell pairedCell = glrow.getCell(0); boolean paired; if (getCellValueAsString(pairedCell) != null) { paired = pairedCell.getBooleanCellValue(); log.info("Got paired: " + paired); } else { throw new InputFormException("'Paired' cell is empty. Please specify TRUE or FALSE."); } XSSFCell platformCell = glrow.getCell(1); PlatformType pt = null; if (getCellValueAsString(platformCell) != null) { pt = PlatformType.get(getCellValueAsString(platformCell)); } if (pt == null) { throw new InputFormException( "Cannot resolve Platform type from: '" + getCellValueAsString(platformCell) + "'"); } else { log.info("Got platform type: " + pt.getKey()); } XSSFCell typeCell = glrow.getCell(2); LibraryType lt = null; if (getCellValueAsString(typeCell) != null) { String[] split = getCellValueAsString(typeCell).split("-"); String plat = split[0]; String type = split[1]; if (getCellValueAsString(platformCell).equals(plat)) { lt = manager.getLibraryTypeByDescriptionAndPlatform(type, pt); } else { throw new InputFormException("Selected library type '" + getCellValueAsString(typeCell) + "' doesn't match platform type: '" + getCellValueAsString(platformCell) + "'"); } } if (lt == null) { throw new InputFormException( "Cannot resolve Library type from: '" + getCellValueAsString(typeCell) + "'"); } else { log.info("Got library type: " + lt.getDescription()); } XSSFCell selectionCell = glrow.getCell(3); LibrarySelectionType ls = null; if (getCellValueAsString(selectionCell) != null) { ls = manager.getLibrarySelectionTypeByName(getCellValueAsString(selectionCell)); } if (ls == null) { throw new InputFormException( "Cannot resolve Library Selection type from: '" + getCellValueAsString(selectionCell) + "'"); } else { log.info("Got library selection type: " + ls.getName()); } XSSFCell strategyCell = glrow.getCell(4); LibraryStrategyType lst = null; if (getCellValueAsString(strategyCell) != null) { lst = manager.getLibraryStrategyTypeByName(getCellValueAsString(strategyCell)); } if (lst == null) { throw new InputFormException( "Cannot resolve Library Strategy type from: '" + getCellValueAsString(strategyCell) + "'"); } else { log.info("Got library strategy type: " + lst.getName()); } //process entries Plate<LinkedList<Sample>, Sample> samplePlate = null; Map<String, Pool<Dilution>> pools = new HashMap<String, Pool<Dilution>>(); for (int ri = 4; ri < rows; ri++) { XSSFRow row = sheet.getRow(ri); // Ax - plate position XSSFCell platePosCell = row.getCell(0); if (getCellValueAsString(platePosCell) != null && samplePlate == null) { //plated samples - process as plate samplePlate = new PlateImpl<Sample>(); } //cell defs XSSFCell sampleAliasCell = row.getCell(2); Sample s = null; if (getCellValueAsString(sampleAliasCell) != null) { String salias = getCellValueAsString(sampleAliasCell); Collection<Sample> ss = manager.listSamplesByAlias(salias); if (!ss.isEmpty()) { if (ss.size() == 1) { s = ss.iterator().next(); log.info("Got sample: " + s.getAlias()); } else { throw new InputFormException( "Multiple samples retrieved with this alias: '" + salias + "'. Cannot process."); } } else { throw new InputFormException("No such sample '" + salias + "'in database. Samples need to be created before using the form input functionality"); } } else { log.info("Blank sample row found. Ending import."); break; } //sample OK - good to go if (s != null) { String projectAliasCell = getCellValueAsString(row.getCell(1)); String poolNumberCell = getCellValueAsString(row.getCell(3)); String sampleQcCell = getCellValueAsString(row.getCell(4)); //String sampleAmountCell = getCellValueAsString(row.getCell(5)); //String sampleWaterAmountCell = getCellValueAsString(row.getCell(6)); String libraryDescriptionCell = getCellValueAsString(row.getCell(7)); String barcodeKitCell = getCellValueAsString(row.getCell(8)); String barcodeTagsCell = getCellValueAsString(row.getCell(9)); String libraryQcCell = getCellValueAsString(row.getCell(10)); String libraryQcInsertSizeCell = getCellValueAsString(row.getCell(11)); String libraryQcMolarityCell = getCellValueAsString(row.getCell(12)); String libraryQcPassFailCell = getCellValueAsString(row.getCell(13)); //String libraryAmountCell = getCellValueAsString(row.getCell(14)); //String libraryWaterAmountCell = getCellValueAsString(row.getCell(15)); //String dilutionQcCell = getCellValueAsString(row.getCell(16)); String dilutionMolarityCell = getCellValueAsString(row.getCell(17)); //String dilutionAmountCell = getCellValueAsString(row.getCell(18)); //String dilutionWaterAmountCell = getCellValueAsString(row.getCell(19)); String poolQcCell = getCellValueAsString(row.getCell(20)); //String poolAverageInsertSizeCell = getCellValueAsString(row.getCell(21)); String poolConvertedMolarityCell = getCellValueAsString(row.getCell(22)); //add pool, if any processPool(poolNumberCell, poolConvertedMolarityCell, pools); processSampleQC(sampleQcCell, s, u, manager); Library library = processLibrary(libraryQcCell, libraryDescriptionCell, libraryQcPassFailCell, s, pt, lt, ls, lst, paired, libraryNamingScheme); if (library != null) { processLibraryQC(libraryQcCell, libraryQcMolarityCell, libraryQcInsertSizeCell, library, u, manager); processBarcodes(barcodeKitCell, barcodeTagsCell, library, manager); processDilutions(dilutionMolarityCell, library, pools.get(poolNumberCell), u); log.info("Added library: " + library.toString()); s.addLibrary(library); } samples.add(s); } } return samples; }
From source file:uk.ac.bbsrc.tgac.miso.core.util.FormUtils.java
License:Open Source License
private static String getCellValueAsString(XSSFCell cell) { if (cell != null) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_BLANK: return null; case XSSFCell.CELL_TYPE_BOOLEAN: return String.valueOf(cell.getBooleanCellValue()); case XSSFCell.CELL_TYPE_ERROR: return cell.getErrorCellString(); case XSSFCell.CELL_TYPE_FORMULA: return cell.getRawValue(); case XSSFCell.CELL_TYPE_NUMERIC: return String.valueOf(cell.getNumericCellValue()); case XSSFCell.CELL_TYPE_STRING: return cell.getStringCellValue(); default:/* w ww.j a va 2 s . c o m*/ return null; } } return null; }
From source file:uk.ac.bbsrc.tgac.miso.spring.util.FormUtils.java
License:Open Source License
private static List<Sample> processSampleInputXLSX(XSSFWorkbook wb, User u, SampleService sampleService, LibraryService libraryService, QualityControlService qcService, NamingScheme namingScheme, IndexService indexService) throws Exception { List<Sample> samples = new ArrayList<>(); XSSFSheet sheet = wb.getSheetAt(0);//from ww w. j ava 2s . co m int rows = sheet.getPhysicalNumberOfRows(); XSSFRow glrow = sheet.getRow(1); // process global headers XSSFCell pairedCell = glrow.getCell(0); boolean paired; if (getCellValueAsString(pairedCell) != null) { paired = pairedCell.getBooleanCellValue(); log.info("Got paired: " + paired); } else { throw new InputFormException("'Paired' cell is empty. Please specify TRUE or FALSE."); } XSSFCell platformCell = glrow.getCell(1); PlatformType pt = null; if (getCellValueAsString(platformCell) != null) { pt = PlatformType.get(getCellValueAsString(platformCell)); } if (pt == null) { throw new InputFormException( "Cannot resolve Platform type from: '" + getCellValueAsString(platformCell) + "'"); } else { log.info("Got platform type: " + pt.getKey()); } XSSFCell typeCell = glrow.getCell(2); LibraryType lt = null; if (getCellValueAsString(typeCell) != null) { String[] split = getCellValueAsString(typeCell).split("-"); String plat = split[0]; String type = split[1]; if (getCellValueAsString(platformCell).equals(plat)) { lt = libraryService.getLibraryTypeByDescriptionAndPlatform(type, pt); } else { throw new InputFormException("Selected library type '" + getCellValueAsString(typeCell) + "' doesn't match platform type: '" + getCellValueAsString(platformCell) + "'"); } } if (lt == null) { throw new InputFormException( "Cannot resolve Library type from: '" + getCellValueAsString(typeCell) + "'"); } else { log.info("Got library type: " + lt.getDescription()); } XSSFCell selectionCell = glrow.getCell(3); LibrarySelectionType ls = null; if (getCellValueAsString(selectionCell) != null) { ls = libraryService.getLibrarySelectionTypeByName(getCellValueAsString(selectionCell)); } if (ls == null) { throw new InputFormException( "Cannot resolve Library Selection type from: '" + getCellValueAsString(selectionCell) + "'"); } else { log.info("Got library selection type: " + ls.getName()); } XSSFCell strategyCell = glrow.getCell(4); LibraryStrategyType lst = null; if (getCellValueAsString(strategyCell) != null) { lst = libraryService.getLibraryStrategyTypeByName(getCellValueAsString(strategyCell)); } if (lst == null) { throw new InputFormException( "Cannot resolve Library Strategy type from: '" + getCellValueAsString(strategyCell) + "'"); } else { log.info("Got library strategy type: " + lst.getName()); } // process entries Map<String, Pool> pools = new HashMap<>(); for (int ri = 4; ri < rows; ri++) { XSSFRow row = sheet.getRow(ri); // cell defs XSSFCell sampleAliasCell = row.getCell(2); Sample s = null; if (getCellValueAsString(sampleAliasCell) != null) { String salias = getCellValueAsString(sampleAliasCell); Collection<Sample> ss = sampleService.getByAlias(salias); if (!ss.isEmpty()) { if (ss.size() == 1) { s = ss.iterator().next(); log.info("Got sample: " + s.getAlias()); } else { throw new InputFormException( "Multiple samples retrieved with this alias: '" + salias + "'. Cannot process."); } } else { throw new InputFormException("No such sample '" + salias + "'in database. Samples need to be created before using the form input functionality"); } } else { log.info("Blank sample row found. Ending import."); break; } // sample OK - good to go if (s != null) { String poolNumberCell = getCellValueAsString(row.getCell(3)); String sampleQcCell = getCellValueAsString(row.getCell(4)); String libraryDescriptionCell = getCellValueAsString(row.getCell(7)); String indexKitCell = getCellValueAsString(row.getCell(8)); String indexTagsCell = getCellValueAsString(row.getCell(9)); String libraryQcCell = getCellValueAsString(row.getCell(10)); String libraryQcInsertSizeCell = getCellValueAsString(row.getCell(11)); String libraryQcMolarityCell = getCellValueAsString(row.getCell(12)); String libraryQcPassFailCell = getCellValueAsString(row.getCell(13)); String dilutionMolarityCell = getCellValueAsString(row.getCell(17)); String poolConvertedMolarityCell = getCellValueAsString(row.getCell(22)); // add pool, if any processPool(poolNumberCell, poolConvertedMolarityCell, pools); processSampleQC(sampleQcCell, s, u, qcService); Library library = processLibrary(libraryQcCell, libraryDescriptionCell, libraryQcPassFailCell, s, pt, lt, ls, lst, paired, namingScheme); if (library != null) { processLibraryQC(libraryQcCell, libraryQcMolarityCell, libraryQcInsertSizeCell, library, u, qcService); processIndices(indexKitCell, indexTagsCell, library, indexService); processDilutions(dilutionMolarityCell, library, pools.get(poolNumberCell), u); log.info("Added library: " + library.toString()); s.addLibrary(library); } samples.add(s); } } return samples; }