public String readCGCell(Row row, int cellIdx, DataDto dto, CellType cellType) { Cell cell = row.getCell(cellIdx); if (null == cell) { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getConfidenceGrade() + " cell is null."); return null; } if (cell.getCellType() != Cell.CELL_TYPE_STRING) { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getConfidenceGrade() + " CG cell is not of type String."); return null; } RichTextString cg = cell.getRichStringCellValue(); return cg.getString(); }
protected void updateDtoConfidenceGrade( Row row, int cellIdx, DataDto dto, CellType cellType, String editedCGString) { if (null == editedCGString) { return; } if (editedCGString.isEmpty()) { return; } if (editedCGString.equals(dto.getConfidenceGrade())) { return; } // value has changed so convert it to CG index and store it as an edit ConfidenceGrade confidenceGrade = confidenceGradeService.getConfidenceGrade(editedCGString); if (null == confidenceGrade) { metaData.addWarning( row.getRowNum(), cellIdx, dto.getValue(), editedCGString, "This is not a valid value for a Confidence Grade. It cannot be changed."); return; } if (CellType.INPUT == cellType) { // value has changed so store it as an edit. dto.setUpdatedConfidenceGrade("" + confidenceGrade.getId()); } }
public boolean hasData(Company company, GroupEntry ge, Map<String, DataDto> dataLookup) { for (FormDisplayCell cell : cells) { if (null != cell) { if (cell.getCellType().equals(CellType.COPYCELL) || cell.getCellType().equals(CellType.INPUT)) { DataKey key = new DataKey(cell.getCellContents()); // for // data // cells // getCellContents() // is // the // key. key.setCompanyId(company.getId()); if (null != ge) { key.setGroupEntryId(ge.getId()); } if (key.isCg()) { key.setCg(false); DataDto dto = dataLookup.get(key.getKey(true)); if (null != dto && !dto.getConfidenceGrade().isEmpty()) { return true; } } else { DataDto dto = dataLookup.get(key.getKey(true)); if (null != dto && !dto.getValue().isEmpty()) { return true; } } } } } return false; }
protected void reportInvalidChange( int row, int col, DataDto dto, CellType cellType, String editedValueString) { if (null == editedValueString) { return; } if (null == dto) { return; } if (editedValueString.equals(dto.getValue())) { return; } // value has changed so report it. if (CellType.COPYCELL == cellType) { if (null == dto.getItem() || null == dto.getIntervalDto()) { metaData.addWarning( row, col, dto.getValue(), editedValueString, "Historic values cannot be changed on import."); } else { metaData.addWarning( row, col, dto.getValue(), editedValueString, "Historic values cannot be changed on import. Item: " + dto.getItem().getCode() + " Interval: " + dto.getIntervalDto().getName()); } } }
public void readUnchangableCell(Row row, int cellIdx, FormDisplayCell tableCell, DataDto dto) { Cell cell = row.getCell(cellIdx); if (null == cell) { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getValue() + " cell is null."); } if (cell.getCellType() != Cell.CELL_TYPE_NUMERIC && cell.getCellType() != Cell.CELL_TYPE_FORMULA) { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getValue() + " cell is is not numeric."); } double editedValue = cell.getNumericCellValue(); if ("0.00%".equals(cell.getCellStyle().getDataFormatString())) { // Percent editedValue = editedValue * 100; } String editedValueString = formatter.formatValueToAtLeastDP(dto, editedValue); if (!editedValueString.equals(dto.getValue()) && !editedValueString.isEmpty()) { // value has changed so log a warning metaData.addWarning( row.getRowNum(), cellIdx, dto.getValue(), editedValueString, "This is a " + tableCell.getCellType().name() + " cell. It cannot be changed."); } }
protected void updateDtoValue(DataDto dto, CellType cellType, String editedValueString) { if (null == editedValueString) { return; } if (null == dto) { return; } if (editedValueString.equals(dto.getValue())) { return; } // value has changed so store it as an edit. Blank value is valid. if (CellType.INPUT == cellType || CellType.COPYCELL == cellType) { if (dto.getItem().getUnit().equals("%")) { editedValueString = String.valueOf(Double.parseDouble(editedValueString) / 100); } dto.setUpdatedValue(editedValueString); } }
public String readDataCell(Row row, int cellIdx, DataDto dto, CellType cellType) { Cell cell = row.getCell(cellIdx); if (null == cell) { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getValue() + " cell is null."); return null; } String editedValueString = null; if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC || cell.getCellType() == Cell.CELL_TYPE_FORMULA) { try { double editedValue = cell.getNumericCellValue(); if ("0.00%".equals(cell.getCellStyle().getDataFormatString())) { // Percent editedValue = editedValue * 100; } editedValueString = formatter.formatValueToAtLeastDP(dto, editedValue); } catch (IllegalStateException e) { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getValue() + " cell is not numeric. CELL TYPE is " + cell.getCellType() + ". Cannot read cell."); metaData.addWarning( row.getRowNum(), cellIdx, " current value: " + dto.getValue() + " cell is not numeric. CELL TYPE is " + cell.getCellType() + ". Cannot read cell."); } } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) { RichTextString editedValue = cell.getRichStringCellValue(); if (editedValue.getString().isEmpty()) { editedValueString = ""; } else { if (isNumberInString(editedValue.getString())) { editedValueString = editedValue.getString(); } else { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getValue() + " data '" + editedValue.getString() + "' is not numeric. CELL TYPE is " + cell.getCellType()); } } } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) { editedValueString = ""; } else { log.warn( "Table import. Table " + metaData.getTableName() + " Cell at row: " + (row.getRowNum() + 1) + " col: " + (cellIdx + 1) + " current value: " + dto.getValue() + " cell is not numeric. CELL TYPE is " + cell.getCellType()); } return editedValueString; }