T - entity that will be handled by the datatables, represents one entity of any type, such as JPA MongoDB etc.ID - the unique identifier of entity Tpublic abstract class AbstractDataTablesService<T,ID> extends java.lang.Object implements DataTablesService<T,ID>
| Constructor and Description |
|---|
AbstractDataTablesService(GenericDao<T,ID> genericDao,
ApplicationSettings appSettings,
org.springframework.validation.Validator validator,
org.springframework.context.MessageSource messageSource,
QueryHelper queryHelper) |
| Modifier and Type | Method and Description |
|---|---|
T |
add(T transientObject)
Adds an object of type T
|
ID |
addAndReturnID(T transientObject)
Adds an object of type T
|
void |
additionalColumnConfiguration(ColumnConfiguration columnConfiguration,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.springframework.ui.Model model)
Method to handle custom column configurations, such as adding field maps or hiding columns based on user type etc.
|
java.lang.Integer |
adjustColumnPositionDueToInvisibleColumns(ColumnConfiguration columnConfiguration,
java.lang.Integer columnPosition)
Adjusts the column position to account for hidden column missmatch between datatables columns and datatables-editable
columns.
|
Column |
column(java.lang.String fieldName,
java.lang.String fieldLabel,
java.lang.Object value,
java.lang.Object displayValue,
FieldType fieldType,
Entity entity,
Editable editable,
Visible visible,
Sortable sortable,
Searchable searchable,
Required required,
ShowOnForm showOnForm,
java.lang.String url)
Maps a column in the data tables.
|
Column |
column(java.lang.String fieldName,
java.lang.String fieldLabel,
java.lang.Object value,
java.lang.Object displayValue,
FieldType fieldType,
Entity entity,
Editable editable,
Visible visible,
Sortable sortable,
Searchable searchable,
Required required,
ShowOnForm showOnForm,
java.lang.String url,
java.lang.String width)
Maps a column in the data tables, with additional width parameter.
|
protected org.json.JSONObject |
constructJsonObjectResponseFromTableRows(java.util.List<T> filterRows,
JQueryDataTableParamModel param) |
abstract T |
convertColumnsToEntity(ColumnConfiguration rowConfig,
T oldEntity)
Takes a ColumnConfiguration and updates the passed in entity with the new values.
|
abstract ColumnConfiguration |
convertEntityToColumns(T entity)
Takes a T entity and converts it to a ColumnConfiguration; a ColumnConfiguration contains a number of Columns.
|
java.lang.String |
editEntity(ID id,
java.lang.Integer columnPosition,
java.lang.Object value,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.springframework.ui.Model model)
Updates an existing entity of type T, using its primary key, the column position in the datatables of the field being
updated and the updated value.
|
protected java.util.List<T> |
filterRows(java.util.List<T> allTableRows,
JQueryDataTableParamModel param)
Filters the rows based on parameters in JQueryDataTableParamModel
|
T |
find(ID id)
Get a T record using it's id
|
java.util.List<T> |
findAll(java.util.List<T> tableRows,
boolean useCache)
Retrieves all the data in the table.
|
ApplicationSettings |
getAppSettings() |
java.util.List<T> |
getData(java.util.List<T> tableRows,
boolean useCache,
javax.servlet.http.HttpServletRequest request)
Retrieves the data.
|
DtoFieldChangeFactory |
getDtoFieldChangeFactory() |
GenericDao<T,ID> |
getGenericDao() |
org.apache.log4j.Logger |
getLog() |
java.lang.String |
getMessageUsingKey(java.lang.String key)
Gets a message from a resource bundle.
|
java.lang.String |
getQueryUsingKey(java.lang.String key)
Get a query from the passed in QueryHelper
|
org.springframework.validation.Validator |
getValidator() |
java.lang.String |
handleEntityFormEdit(T entity,
ID entityID,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
This method handles the edit of an entity using the form instead of inline editing.
|
protected java.util.List<T> |
handlePagination(java.util.List<T> filterRows,
JQueryDataTableParamModel param) |
java.lang.String |
prepareValidationErrorMessage(org.springframework.validation.BindingResult bindingResult,
T entity)
Prepares a validation error message using Spring's BindingResult from an entity validation.
|
org.json.JSONObject |
processRequestForDataTables(javax.servlet.http.HttpServletRequest request)
Entry point for getting, filtering, sorting, handle pagination and constructing JSONObject; the JSONObject is then written
to the response.
|
java.util.List<T> |
query(java.lang.String queryString,
java.util.Map<java.lang.String,java.lang.Object> queryParameters)
Method for custom query.
|
void |
remove(T persistentObject)
Deletes entity T from table.
|
void |
removeUsingID(ID id)
Deletes an entity using its primary key
|
protected void |
sortRows(java.util.List<T> filterRows,
JQueryDataTableParamModel param) |
<E extends java.lang.Comparable<?>> |
toType(java.lang.Class<E> type,
java.lang.Object value)
Converts the object passed in back to its original type E by casting.
|
T |
update(T transientObject)
Updates an object of type T
|
ID |
updateAndReturnID(T transientObject)
Updates an object of type T
|
java.lang.String |
validateEntity(T entity)
Validates an entity
|
public AbstractDataTablesService(GenericDao<T,ID> genericDao, ApplicationSettings appSettings, org.springframework.validation.Validator validator, org.springframework.context.MessageSource messageSource, QueryHelper queryHelper)
public abstract ColumnConfiguration convertEntityToColumns(T entity)
DataTablesServiceconvertEntityToColumns in interface DataTablesService<T,ID>public abstract T convertColumnsToEntity(ColumnConfiguration rowConfig, T oldEntity)
DataTablesServiceconvertColumnsToEntity in interface DataTablesService<T,ID>oldEntity - the entity that will be updatedpublic void additionalColumnConfiguration(ColumnConfiguration columnConfiguration, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model)
DataTablesServiceadditionalColumnConfiguration in interface DataTablesService<T,ID>columnConfiguration - The ColumnConfiguration from this.convertEntityToColumnsrequest - the HttpServletRequestresponse - the HttpServletResponsemodel - the Modelpublic org.json.JSONObject processRequestForDataTables(javax.servlet.http.HttpServletRequest request)
DataTablesServiceprocessRequestForDataTables in interface DataTablesService<T,ID>public java.util.List<T> getData(java.util.List<T> tableRows, boolean useCache, javax.servlet.http.HttpServletRequest request)
DataTablesServicegetData in interface DataTablesService<T,ID>tableRows - will be null if List is not in sessionuseCache - If true data will be cachedrequest - the HttpServletRequest containing all the information from the request. This can be used when overriding this
method to retrieve query params etc.@Transactional(timeout=60) public java.util.List<T> findAll(java.util.List<T> tableRows, boolean useCache)
DataTablesServicefindAll in interface DataTablesService<T,ID>tableRows - will be null if List is not in sessionuseCache - If true data will be cached@Transactional(timeout=60) public T add(T transientObject)
DataTablesServiceadd in interface DataTablesService<T,ID>transientObject - The object to be added/updated@Transactional(timeout=60) public ID addAndReturnID(T transientObject)
DataTablesServiceaddAndReturnID in interface DataTablesService<T,ID>transientObject - The object to be added/updated@Transactional(timeout=60) public T update(T transientObject)
DataTablesServiceupdate in interface DataTablesService<T,ID>transientObject - The object to be added/updated@Transactional(timeout=60) public ID updateAndReturnID(T transientObject)
DataTablesServiceupdateAndReturnID in interface DataTablesService<T,ID>transientObject - The object to be added/updated@Transactional(timeout=60) public T find(ID id) throws javax.persistence.EntityNotFoundException
DataTablesServicefind in interface DataTablesService<T,ID>id - The unique identifier of the entity T (in most cases the primary key of the entity)javax.persistence.EntityNotFoundException - when no entity with (primary key) ID exists@Transactional(timeout=60) public void remove(T persistentObject) throws javax.persistence.EntityNotFoundException
DataTablesServiceremove in interface DataTablesService<T,ID>javax.persistence.EntityNotFoundException@Transactional(timeout=60) public void removeUsingID(ID id) throws javax.persistence.EntityNotFoundException
DataTablesServiceremoveUsingID in interface DataTablesService<T,ID>id - unique identifierjavax.persistence.EntityNotFoundException - if no enity exists with the specified unique identifier@Transactional(timeout=120,
readOnly=true)
public java.util.List<T> query(java.lang.String queryString,
java.util.Map<java.lang.String,java.lang.Object> queryParameters)
DataTablesServicequery in interface DataTablesService<T,ID>queryString - the query String with named parameters: Select a FROM TableName a WHERE a.field = :namedParamqueryParameters - the named parameters corresponding to the :namedParam in the queryString. The key of the map need correspond to
namedParam while the value is the actual value used in the query.@Transactional(timeout=60) public java.lang.String editEntity(ID id, java.lang.Integer columnPosition, java.lang.Object value, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.ui.Model model)
DataTablesServiceeditEntity in interface DataTablesService<T,ID>id - the unique identifier of the entity TcolumnPosition - the column position in the datatables that matches the field being updatedvalue - the new value of the field * @param request@Transactional(timeout=60) public java.lang.String handleEntityFormEdit(T entity, ID entityID, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
DataTablesServicehandleEntityFormEdit in interface DataTablesService<T,ID>entity - used when all fields on the entity are present on the formentityID - the id of the entity to updaterequest - the request containing all parameterspublic java.lang.Integer adjustColumnPositionDueToInvisibleColumns(ColumnConfiguration columnConfiguration, java.lang.Integer columnPosition)
DataTablesServiceadjustColumnPositionDueToInvisibleColumns in interface DataTablesService<T,ID>columnPosition - the current column to checkpublic java.lang.String validateEntity(T entity)
DataTablesServicevalidateEntity in interface DataTablesService<T,ID>entity - the entity to validatepublic java.lang.String prepareValidationErrorMessage(org.springframework.validation.BindingResult bindingResult,
T entity)
DataTablesServiceprepareValidationErrorMessage in interface DataTablesService<T,ID>bindingResult - the validation result from an entityentity - the entity that was just validated, used to find the labels of particular fields to create prettier error
messages.public Column column(java.lang.String fieldName, java.lang.String fieldLabel, java.lang.Object value, java.lang.Object displayValue, FieldType fieldType, Entity entity, Editable editable, Visible visible, Sortable sortable, Searchable searchable, Required required, ShowOnForm showOnForm, java.lang.String url)
fieldName - Has to be exact match to field on entityfieldLabel - The column label used in the data tablesvalue - The actual value as it's own typedisplayValue - The display value. This can be the same as value any textfieldType - Specifies what type of field, such as ID, DATE,BUTTON etc. See FieldType enum for full list.entity - Defines if the column is part of the JPA entityeditable - Defines if the column can be editedvisible - Defines if the column is visablesortable - Defines if the column can be sortedsearchable - Defines if the column will be part of the searchshowOnForm - Defines if the column will show up on the add new entity formurl - Defines the url of a link. If the FieldType is a select then this url will be the url that provide the data for the
select.public Column column(java.lang.String fieldName, java.lang.String fieldLabel, java.lang.Object value, java.lang.Object displayValue, FieldType fieldType, Entity entity, Editable editable, Visible visible, Sortable sortable, Searchable searchable, Required required, ShowOnForm showOnForm, java.lang.String url, java.lang.String width)
fieldName - Has to be exact match to field on entityfieldLabel - The column label used in the data tablesvalue - The actual value as it's own typedisplayValue - The display value. This can be the same as value any textfieldType - Specifies what type of field, such as ID, DATE,BUTTON etc. See FieldType enum for full list.entity - Defines if the column is part of the JPA entityeditable - Defines if the column can be editedvisible - Defines if the column is visablesortable - Defines if the column can be sortedsearchable - Defines if the column will be part of the searchshowOnForm - Defines if the column will show up on the add new entity formurl - Defines the url of a link. If the FieldType is a select then this url will be the url that provide the data for the
select.width - Defining the width of the column, this parameter may take any CSS value (3em, 20px etc). DataTables applies 'smart' widths
to columns which have not been given a specific width through this interface ensuring that the table remains readable.protected java.util.List<T> filterRows(java.util.List<T> allTableRows, JQueryDataTableParamModel param)
allTableRows - param - protected void sortRows(java.util.List<T> filterRows, JQueryDataTableParamModel param)
protected java.util.List<T> handlePagination(java.util.List<T> filterRows, JQueryDataTableParamModel param)
protected org.json.JSONObject constructJsonObjectResponseFromTableRows(java.util.List<T> filterRows, JQueryDataTableParamModel param) throws org.json.JSONException
org.json.JSONExceptionpublic GenericDao<T,ID> getGenericDao()
getGenericDao in interface DataTablesService<T,ID>public ApplicationSettings getAppSettings()
getAppSettings in interface DataTablesService<T,ID>public org.springframework.validation.Validator getValidator()
getValidator in interface DataTablesService<T,ID>public DtoFieldChangeFactory getDtoFieldChangeFactory()
getDtoFieldChangeFactory in interface DataTablesService<T,ID>public org.apache.log4j.Logger getLog()
getLog in interface DataTablesService<T,ID>public <E extends java.lang.Comparable<?>> E toType(java.lang.Class<E> type,
java.lang.Object value)
type - the type Classvalue - the Object to covertpublic java.lang.String getMessageUsingKey(java.lang.String key)
DataTablesServicegetMessageUsingKey in interface DataTablesService<T,ID>key - The key of the messagepublic java.lang.String getQueryUsingKey(java.lang.String key)
DataTablesServicegetQueryUsingKey in interface DataTablesService<T,ID>