Package com.storedobject.ui.common
Class ExcelDataUpload
java.lang.Object
com.storedobject.vaadin.View
com.storedobject.ui.TextView
com.storedobject.ui.UploadProcessorView
com.storedobject.ui.common.ExcelDataUpload
- All Implemented Interfaces:
Executable
,Reentrant
,StyledBuilder
,HasLogic
,StyledBuilder
,Transactional
,ClickHandler
,CloseableView
,ExecutableView
,HTMLGenerator
,ValueChangeHandler
,com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<? extends com.vaadin.flow.component.Component>>
,com.vaadin.flow.component.HasValue.ValueChangeListener
,Serializable
,Runnable
,EventListener
Upload data contain in an Excel file and typically create entries in the system. The Excel file may contain
data rows in a specified area called "data boundary" and you can use the method
setDataBoundary(String)
to define the "data boundary". If the "data boundary" is not specified, the whole Excel sheet data will be
considered as the "data boundary". Processing of the data is done in the processData(ArrayList)
method
and data from the "data boundary" is passed to that method as a parameter.- Author:
- Syam
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.storedobject.vaadin.ClickHandler
ClickHandler.ModifiedClickEvent<C extends com.vaadin.flow.component.Component>
Nested classes/interfaces inherited from interface com.storedobject.common.StyledBuilder
StyledBuilder.Style
-
Field Summary
Fields inherited from interface com.storedobject.vaadin.HTMLGenerator
CHAR_ENTITIES
Fields inherited from interface com.storedobject.common.StyledBuilder
EMPTY_STRINGS
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
If additional fields are required, create it in this method.void
checkForDuplicates
(int index) Check whether a specific data column contains duplicate values or not.void
checkForDuplicates
(int[] indices) Check whether a specific set of data columns contains duplicate values or not.void
checkForDuplicates
(int[] indices, boolean mainDataRowsOnly) Check whether a specific set of data columns contains duplicate values or not.void
checkForDuplicates
(int index, boolean mainDataRowsOnly) Check whether a specific data column contains duplicate values or not.void
checkForDuplicates
(int index, boolean mainDataRowsOnly, boolean ignoreEmpty) Check whether a specific data column contains duplicate values or not.void
checkForNullObjects
(int index) Check whether a specific data column contains nullStoredObject
or not.void
checkForNullObjects
(int index, boolean mainDataRowsOnly) Check whether a specific data column contains nullStoredObject
or not.void
codeData
(int index) Convert data to code by invokingStoredObject.toCode(String)
.void
convertCell
(String cellName, Class<?> type) Convert the value corresponding to a cell name variable defined viadefineCell(String, String)
.void
convertData
(int index, Class<?> type) Convert data to another type.void
convertData
(int index, Class<?> type, boolean allowNulls, boolean mainRowsOnly) Convert data to another type.void
convertDataToChoice
(int index, Class<? extends StoredObject> objectClass, String choiceFieldName) Convert data to 'choice value'.void
convertDataToChoice
(int index, Class<? extends StoredObject> objectClass, String choiceFieldName, boolean mainRowsOnly) Convert data to 'choice value'.<T extends StoredObject>
TconvertObject
(Object value, Class<T> objectClass) Converts the given value to an object.<O> Object
convertValue
(Object value, Class<O> type) Convert a given value to a specific type.void
defineCell
(String cellName, String cellAddress) Define a cell name.void
fillBlankData
(int index, String value) Fill blank data with the given value.getCellValue
(String cellName) Get the value corresponding to a cell name variable defined viadefineCell(String, String)
.getExcelCell
(int dataRow, int columnIndex) Get the name of the Excel cell address for the given data row.getExcelColumn
(int columnIndex) Get the column name of the Excel cell address for the given data row.int
getExcelRow
(int dataRow) Get the Excel row number for the given data row.<T extends StoredObject>
TConverts the given value to an object.protected void
initUI()
This method is invoked when the view wants to determine its "content" to be displayed and nothing exists at that moment.boolean
isMainDataRow
(int row) Check whether the given row is a main data row or not.void
packData
(int index) Pack string data (Strip off all whitespaces).boolean
Whether numeric values from the Excel should be formatted while populating the data or not.protected final void
process
(InputStream content, String mimeType) protected void
processData
(ArrayList<Object[]> data) Override this method for processing data.void
saveObjects
(int index) Save all objects at the given index in the 'data'.void
setDataBoundary
(String rangeAddress) Data boundary can be set using this method.Methods inherited from class com.storedobject.ui.UploadProcessorView
getFileCount, getFileName, getProgressCaption, getTopComponent, getUploadComponent, setMaxFiles, setProcessor, setProcessor, uploadAborted
Methods inherited from class com.storedobject.ui.TextView
abort, add, clean, clearContent, close, decorateComponent, error, error, execute, getApplication, getBottomComponent, getInternalStyledBuilder, isNewLine, message, message, newLine, popup, process, readyForProcessing, remove, setApplication, setCaption, setIndeterminate, setProgress, setProgressCaption, setText, setValue, startProcess, warning, warning
Methods inherited from class com.storedobject.vaadin.View
aborted, addClosedListener, addOpenedListener, createCloseableView, createWindow, execute, execute, executing, focus, focus, focusAny, getCaption, getComponent, getContent, getCreatedBy, getEmbeddedView, getMenuItem, getMenuItem, getView, invoke, isFullScreen, isScrollable, isWindowMode, select, setComponent, setCreatedBy, setDefaultPadding, setEmbeddedView, setFirstFocus, setFullScreen, setScrollable, setWindowMode, skipFirstFocus
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.storedobject.vaadin.ClickHandler
clicked, doubleClicked, onComponentEvent, rightClicked
Methods inherited from interface com.storedobject.common.Executable
act
Methods inherited from interface com.storedobject.vaadin.ExecutableView
abort, clean, clearAlerts, clicked, close, createMenuItem, error, execute, getApplication, getCaption, getMenuIconName, getMenuItem, getView, getView, invoke, isCloseable, isFullScreen, isHomeView, log, log, message, returnedFrom, run, setCaption, setClickable, speak, trackValueChange, tray, valueChanged, warning
Methods inherited from interface com.storedobject.vaadin.HTMLGenerator
getPrintText
Methods inherited from interface com.storedobject.common.Reentrant
isReentrant
Methods inherited from interface com.storedobject.common.StyledBuilder
append, newLine, setValue
Methods inherited from interface com.storedobject.ui.StyledBuilder
append, append, append, appendHTML, appendIcon, appendWithTag, appendWithTag, blackMessage, blueMessage, clear, drawLine, getHTML, getValue, isEmpty, redMessage, setValue, space, update
Methods inherited from interface com.storedobject.ui.Transactional
commit, execute, getLogic, getTransactionManager, run, setLogic, transact, transact, transactControl, transactControl
Methods inherited from interface com.storedobject.vaadin.ValueChangeHandler
valueChanged
-
Constructor Details
-
ExcelDataUpload
-
ExcelDataUpload
public ExcelDataUpload()Constructor. When created this way, it expects an Excel file containing class name in cell "A1", attribute names in the second row (A2:...) and "data boundary" starting from cell "A3".
-
-
Method Details
-
initUI
protected void initUI()Description copied from class:View
This method is invoked when the view wants to determine its "content" to be displayed and nothing exists at that moment.View.setComponent(Component)
may be called from within this method. -
buildFields
protected void buildFields()If additional fields are required, create it in this method. -
process
- Overrides:
process
in classUploadProcessorView
-
setDataBoundary
Data boundary can be set using this method. For example: setDataBoundary("A5:H136"). The full rectangular boundary may not have to be specified. Only the starting line needs to be specified and the rest will be detected automatically. For example: setBoundary("A5:H5"). If no gaps (blank cells) exist near the boundary area, you may even specify the starting cell. For example: setBoundary("A5"). If no data boundary is set, it will try to detect automatically starting from cell "A1".- Parameters:
rangeAddress
- Range address in Excel format.
-
processData
-
saveObjects
public void saveObjects(int index) Save all objects at the given index in the 'data'.- Parameters:
index
- Index
-
getExcelRow
public int getExcelRow(int dataRow) Get the Excel row number for the given data row. (Used for locating some specific cell for debugging/displaying).- Parameters:
dataRow
- Data row index.- Returns:
- Excel's row number.
-
getExcelColumn
Get the column name of the Excel cell address for the given data row. (Used for locating some specific cell for debugging/displaying).- Parameters:
columnIndex
- Data column index.- Returns:
- Column name of the Excel cell address.
-
getExcelCell
Get the name of the Excel cell address for the given data row. (Used for locating some specific cell for debugging/displaying).- Parameters:
dataRow
- Data row index.columnIndex
- Data column index.- Returns:
- Name of the Excel cell address.
-
isMainDataRow
Check whether the given row is a main data row or not. By default, every data row is considered as main data row. However, an extended class can override this.- Parameters:
row
- Row number.- Returns:
- True/false.
- Throws:
SOException
- If an error occurs while determining the row status.
-
checkForNullObjects
Check whether a specific data column contains nullStoredObject
or not.- Parameters:
index
- Index to the data.- Throws:
SOException
- If the cell contains invalid data.
-
checkForNullObjects
Check whether a specific data column contains nullStoredObject
or not.- Parameters:
index
- Index to the data.mainDataRowsOnly
- Whether to check in main data rows only or not.- Throws:
SOException
- If the cell contains invalid data.
-
checkForDuplicates
Check whether a specific data column contains duplicate values or not.- Parameters:
index
- Index to the data.- Throws:
SOException
- If the cell contains invalid data.
-
checkForDuplicates
Check whether a specific data column contains duplicate values or not.- Parameters:
index
- Index to the data.mainDataRowsOnly
- Whether to check in main data rows only or not.- Throws:
SOException
- If the cell contains invalid data.
-
checkForDuplicates
public void checkForDuplicates(int index, boolean mainDataRowsOnly, boolean ignoreEmpty) throws SOException Check whether a specific data column contains duplicate values or not.- Parameters:
index
- Index to the data.mainDataRowsOnly
- Whether to check in main data rows only or not.ignoreEmpty
- Whether to ignore empty values or not (Only in the case of textual data).- Throws:
SOException
- If the cell contains invalid data.
-
checkForDuplicates
Check whether a specific set of data columns contains duplicate values or not.- Parameters:
indices
- Indices to a set of data.- Throws:
SOException
- If the cell contains invalid data.
-
checkForDuplicates
Check whether a specific set of data columns contains duplicate values or not.- Parameters:
indices
- Indices to a set of data.mainDataRowsOnly
- Whether to check in main data rows only or not.- Throws:
SOException
- If the cell contains invalid data.
-
fillBlankData
Fill blank data with the given value.- Parameters:
index
- Index of the data column to be filled.value
- Value to fill the blank data.
-
getObject
Converts the given value to an object. The default implementation returns the value from the static method get(String), if available. One may override this method to create the object on the fly.- Type Parameters:
T
- Type of Stored object- Parameters:
value
- Value to be converted.objectClass
- Object class.- Returns:
- Stored object.
-
convertData
Convert data to another type. All data corresponding to the index will be converted.- Parameters:
index
- Index of the data to be converted.type
- Class to which data to be converted.
-
convertData
public void convertData(int index, Class<?> type, boolean allowNulls, boolean mainRowsOnly) throws SOException Convert data to another type.- Parameters:
index
- Index of the data to be converted.type
- Class to which data to be converted.allowNulls
- Whether to allow nulls or not.mainRowsOnly
- Whether to consider in main data rows only or not.- Throws:
SOException
-
packData
public void packData(int index) Pack string data (Strip off all whitespaces).- Parameters:
index
- Index of the data to be converted.
-
codeData
public void codeData(int index) Convert data to code by invokingStoredObject.toCode(String)
.- Parameters:
index
- Index of the data to be converted.
-
convertDataToChoice
public void convertDataToChoice(int index, Class<? extends StoredObject> objectClass, String choiceFieldName) Convert data to 'choice value'. All data corresponding to the index will be converted.- Parameters:
index
- Index of the data to be converted.objectClass
- Class to which data to be converted.choiceFieldName
- Name of the Choice Field.
-
convertDataToChoice
public void convertDataToChoice(int index, Class<? extends StoredObject> objectClass, String choiceFieldName, boolean mainRowsOnly) Convert data to 'choice value'. All data corresponding to the index will be converted.- Parameters:
index
- Index of the data to be converted.objectClass
- Class to which data to be converted.choiceFieldName
- Name of the Choice Field.mainRowsOnly
- Whether applicable to main rows only or not
-
convertValue
-
convertCell
Convert the value corresponding to a cell name variable defined viadefineCell(String, String)
. This can be used only after data is populated.- Parameters:
cellName
- Cell name.type
- Type to which data needs to be converted.
-
defineCell
Define a cell name. A cell name acts like a "variable" that points to an Excel cell. The value can be retrieved viagetCellValue(String)
. This should be used before the data is populated.- Parameters:
cellName
- Cell name to be defined.cellAddress
- Excel cell address to which this variable should be mapped.
-
getCellValue
Get the value corresponding to a cell name variable defined viadefineCell(String, String)
. This can be used only after data is populated.- Parameters:
cellName
- Cell name.- Returns:
- Value.
-
convertObject
Converts the given value to an object. The default implementation returns the value from the static method get(String), if available - parameter to the 'get' method is created by converting 'value' to a 'string'. One may override this method to create the object on the fly.- Type Parameters:
T
- Type of Stored object- Parameters:
value
- Value to be converted.objectClass
- Object class.- Returns:
- Stored object.
-
populateNumericValuesUntouched
public boolean populateNumericValuesUntouched()Whether numeric values from the Excel should be formatted while populating the data or not.- Returns:
- True/false. Default is false means numeric values are converted and will appear as String values
in the data passed to
processData(ArrayList)
.
-