List<Sample> samples = new ArrayList<Sample>();
XSSFSheet sheet = wb.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
XSSFRow glrow = sheet.getRow(1);
//process global headers
XSSFCell pairedCell = glrow.getCell(0);
boolean paired = pairedCell.getBooleanCellValue();
log.info("Got paired: " + paired);
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());
}
XSSFCell plateBarcodeCell = glrow.getCell(5);
String plateBarcode = null;
if (getCellValueAsString(plateBarcodeCell) != null) {
plateBarcode = getCellValueAsString(plateBarcodeCell);
}
if (plateBarcode == null) {
throw new InputFormException("Cannot resolve plate barcode from: '" + getCellValueAsString(plateBarcodeCell) + "'");
}
else {
log.info("Got plate barcode: " + plateBarcode);
}
//process entries
Simple384WellPlate libraryPlate = null;
//Map<String, Pool<Plate<LinkedList<Library>, Library>>> pools = new HashMap<String, Pool<Plate<LinkedList<Library>, Library>>>();
Map<String, PlatePool> pools = new HashMap<String, PlatePool>();
for (int ri = 4; ri < rows; ri++) {
XSSFRow row = sheet.getRow(ri);
// Ax - plate position
XSSFCell platePosCell = row.getCell(0);
String platePos = getCellValueAsString(platePosCell);
if (platePos != null && libraryPlate == null) {
//plated libraries - process as plate
libraryPlate = new Simple384WellPlate();
libraryPlate.setIdentificationBarcode(plateBarcode);
libraryPlate.setCreationDate(new Date());
}
//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) {
XSSFCell entityIDCell = row.getCell(2);
XSSFCell poolNumberCell = row.getCell(3);
XSSFCell sampleQcCell = row.getCell(4);
//XSSFCell sampleAmountCell = row.getCell(5);
//XSSFCell sampleWaterAmountCell = row.getCell(6);
XSSFCell libraryDescriptionCell = row.getCell(7);
XSSFCell barcodeKitCell = row.getCell(8);
XSSFCell barcodeTagsCell = row.getCell(9);
XSSFCell libraryQcCell = row.getCell(10);
XSSFCell libraryQcInsertSizeCell = row.getCell(11);
XSSFCell libraryQcMolarityCell = row.getCell(12);
XSSFCell libraryQcPassFailCell = row.getCell(13);
//XSSFCell libraryAmountCell = row.getCell(14);
//XSSFCell libraryWaterAmountCell = row.getCell(15);
//XSSFCell dilutionQcCell = row.getCell(16);
XSSFCell dilutionMolarityCell = row.getCell(17);
//XSSFCell dilutionAmountCell = row.getCell(18);
//XSSFCell dilutionWaterAmountCell = row.getCell(19);
XSSFCell poolQcCell = row.getCell(20);
//XSSFCell poolAverageInsertSizeCell = row.getCell(21);
XSSFCell poolConvertedMolarityCell = row.getCell(22);
//add pool, if any
if (getCellValueAsString(poolNumberCell) != null) {
String poolNum = getCellValueAsString(poolNumberCell);
if (!pools.containsKey(poolNum)) {