Package org.ametys.plugins.forms.table
Class FormTableManager
- java.lang.Object
-
- org.ametys.plugins.forms.table.FormTableManager
-
- All Implemented Interfaces:
Component
,Serviceable
public class FormTableManager extends Object implements Component, Serviceable
Class that handles creation and deletion of a table used by a form.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
FormTableManager.DbColumn
Class representing a db column.(package private) class
FormTableManager.DbColumnModifications
Class storing modifications to do on columns.
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.Logger
__logger
private FormPropertiesManager
_formPropertiesManager
private I18nUtils
_i18nUtils
private JdbcWorkflowStore
_jdbcWorkflowStore
private ServiceManager
_manager
private AmetysObjectResolver
_resolver
private SQLDatabaseTypeExtensionPoint
_sqlDatabaseTypeExtensionPoint
static String
CREATION_DATE_FIELD
Creation date field name.static String
FILE_NAME_COLUMN_SUFFIX
Suffix for filename column.static String
FORMS_POOL_CONFIG_PARAM
The id of the configuration parameter used for the forms' datasourcestatic String
ID_FIELD
ID field name.static String
ROLE
Avalon Rolestatic int
TABLE_CREATED_AND_UP_TO_DATE
Constant for table statestatic int
TABLE_CREATED_BUT_NEED_UPDATE
Constant for table statestatic int
TABLE_NOT_CREATED
Constant for table statestatic String
TABLE_PREFIX
Prefix for database tablesstatic int
TABLE_UNKOWN_STATUS
Constant for table statestatic String
WORKFLOW_ID_FIELD
Workflow id column name.
-
Constructor Summary
Constructors Constructor Description FormTableManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
_addColumns(Connection con, Map<String,FieldValue> columnsToAdd, String tableName)
private boolean
_alterTable(String formId, Map<String,FieldValue> newColumns)
private int
_checkTableStatus(String formId, Map<String,FieldValue> newColumns)
private boolean
_createOrUpdateTable(String formId, Map<String,FieldValue> columns)
private boolean
_createTable(String formId, Map<String,FieldValue> columns)
private FormTableManager.DbColumnModifications
_getColumnsToModify(Connection con, Map<String,FormTableManager.DbColumn> existingColumns, Map<String,FieldValue> newColumns)
protected String
_getColumnType(int sqlType, String dbType)
Get the full column type corresponding to the database type (with precision).protected String
_getColumnTypeName(int sqlType, String dbType)
Get the column type name (without precision) corresponding to the SQL type.private Map<String,FormTableManager.DbColumn>
_getExistingColumns(Connection con, String table)
private String
_getNewName(Connection con, String currentName, Set<String> existingColumnNames)
Get the new name of a column to be moved.private String
_getSubmissionsQuery(int offset, int length, String tableName, String dbType)
Get the submissions queryprotected boolean
_isSameType(FormTableManager.DbColumn column, FieldValue newColumn, String dbType)
Test if two columns have the same type.private void
_moveColumns(Connection con, Map<String,FormTableManager.DbColumn> columnsToRemove, Map<String,FormTableManager.DbColumn> existingColumns, String tableName)
void
addWorkflowIdColumn(String formId)
Add a workflow id column to the given tablevoid
clearEntries(String siteName, List<String> formIds)
Clear all entries of the forms corresponding to the given list of ids.boolean
createTable(Form form)
Create database table to store results of content formsvoid
deleteEntry(String siteName, String formId, List<Integer> entries)
Delete a list of entries of a formboolean
dropTable(String table)
Drop the table by its namevoid
dropWorkflowIdColumn(String formId)
Delete the workflow id column of the given tableprivate AmetysObjectResolver
getAmetysObjectResolver()
List<Map<String,Object>>
getColumns(String siteName, String formId)
Get the columns information of a formMap<String,FieldValue>
getColumns(Form form)
Form to tableinfo.List<Map<String,Object>>
getContentForms(List<String> contentIds, String currentLanguage)
Get the forms of contentsstatic int
getFieldSqlType(Field.FieldType fieldType)
Get the SQL type corresponding to a field type.private FormPropertiesManager
getFormPropertiesManager()
private I18nUtils
getI18nUtils()
private JdbcWorkflowStore
getJdbcWorkflowStore()
Map<String,String>
getSelectStatement(String siteName, String formId)
Get the SELECT statement for retrieving the form entries from the database.private SQLDatabaseTypeExtensionPoint
getSQLDatabaseTypeExtensionPoint()
List<UserEntry>
getSubmissions(Form form, Map<String,FieldValue> columns, int offset, int length, List<Integer> entryIds)
Get all the submissions for a form.List<String>
getTableNames()
Get all the table namesint
getTotalSubmissions(String formId)
Get the total count of submissions for a form.List<Integer>
getWorkflowIds(String formId, Integer entryId)
Get the workflow id of the given form entry or of all the entriesboolean
hasWorkflowIdColumn(String formId)
Does the given form have a workflow id column in its SQL table ?void
removeTables(List<String> tableNames)
Remove a list of tablesvoid
service(ServiceManager smanager)
void
setWorkflowId(Form form, long entryId, long newWorkflowId)
Set a new workflow id to the column that has the given old workflow id
-
-
-
Field Detail
-
FORMS_POOL_CONFIG_PARAM
public static final String FORMS_POOL_CONFIG_PARAM
The id of the configuration parameter used for the forms' datasource- See Also:
- Constant Field Values
-
TABLE_PREFIX
public static final String TABLE_PREFIX
Prefix for database tables- See Also:
- Constant Field Values
-
ID_FIELD
public static final String ID_FIELD
ID field name.- See Also:
- Constant Field Values
-
CREATION_DATE_FIELD
public static final String CREATION_DATE_FIELD
Creation date field name.- See Also:
- Constant Field Values
-
WORKFLOW_ID_FIELD
public static final String WORKFLOW_ID_FIELD
Workflow id column name.- See Also:
- Constant Field Values
-
FILE_NAME_COLUMN_SUFFIX
public static final String FILE_NAME_COLUMN_SUFFIX
Suffix for filename column.- See Also:
- Constant Field Values
-
TABLE_CREATED_AND_UP_TO_DATE
public static final int TABLE_CREATED_AND_UP_TO_DATE
Constant for table state- See Also:
- Constant Field Values
-
TABLE_CREATED_BUT_NEED_UPDATE
public static final int TABLE_CREATED_BUT_NEED_UPDATE
Constant for table state- See Also:
- Constant Field Values
-
TABLE_NOT_CREATED
public static final int TABLE_NOT_CREATED
Constant for table state- See Also:
- Constant Field Values
-
TABLE_UNKOWN_STATUS
public static final int TABLE_UNKOWN_STATUS
Constant for table state- See Also:
- Constant Field Values
-
__logger
private static org.slf4j.Logger __logger
-
_manager
private ServiceManager _manager
-
_formPropertiesManager
private FormPropertiesManager _formPropertiesManager
-
_resolver
private AmetysObjectResolver _resolver
-
_i18nUtils
private I18nUtils _i18nUtils
-
_jdbcWorkflowStore
private JdbcWorkflowStore _jdbcWorkflowStore
-
_sqlDatabaseTypeExtensionPoint
private SQLDatabaseTypeExtensionPoint _sqlDatabaseTypeExtensionPoint
-
-
Constructor Detail
-
FormTableManager
public FormTableManager()
-
-
Method Detail
-
service
public void service(ServiceManager smanager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
getSQLDatabaseTypeExtensionPoint
private SQLDatabaseTypeExtensionPoint getSQLDatabaseTypeExtensionPoint()
-
getI18nUtils
private I18nUtils getI18nUtils()
-
getAmetysObjectResolver
private AmetysObjectResolver getAmetysObjectResolver()
-
getFormPropertiesManager
private FormPropertiesManager getFormPropertiesManager()
-
getJdbcWorkflowStore
private JdbcWorkflowStore getJdbcWorkflowStore()
-
createTable
public boolean createTable(Form form)
Create database table to store results of content forms- Parameters:
form
- informations used to create table- Returns:
- true if the table was created false else
-
dropTable
public boolean dropTable(String table)
Drop the table by its name- Parameters:
table
- the name of the table to drop- Returns:
- true if the table was dropped, false otherwise
-
getTableNames
public List<String> getTableNames()
Get all the table names- Returns:
- the list of all the forms' table names
-
getSubmissions
public List<UserEntry> getSubmissions(Form form, Map<String,FieldValue> columns, int offset, int length, List<Integer> entryIds) throws FormsException
Get all the submissions for a form.- Parameters:
form
- the form object.columns
- the columnsoffset
- The number of results to ignore.length
- The maximum number of results to returnentryIds
- the ids of the submissions to retrieve- Returns:
- the list of submissions.
- Throws:
FormsException
- if an error occurs.
-
_getSubmissionsQuery
private String _getSubmissionsQuery(int offset, int length, String tableName, String dbType)
Get the submissions query- Parameters:
offset
- The number of results to ignore.length
- The maximum number of results to returntableName
- the name of the tabledbType
- the type of the database used- Returns:
- the string query for getting the submissions of a form
-
getTotalSubmissions
public int getTotalSubmissions(String formId) throws FormsException
Get the total count of submissions for a form.- Parameters:
formId
- the id of the form- Returns:
- the total count of submissions, or -1 if an error occurs.
- Throws:
FormsException
- if an error occurs.
-
getContentForms
public List<Map<String,Object>> getContentForms(List<String> contentIds, String currentLanguage) throws FormsException, URISyntaxException
Get the forms of contents- Parameters:
contentIds
- The ids of contentscurrentLanguage
- The current language- Returns:
- The forms
- Throws:
FormsException
- if an error occurred while getting content' formURISyntaxException
- if an error occurred when URL encoding form's label
-
getColumns
public List<Map<String,Object>> getColumns(String siteName, String formId) throws FormsException
Get the columns information of a form- Parameters:
siteName
- The site nameformId
- the identifier of form- Returns:
- The columns
- Throws:
FormsException
- if an error occurred
-
removeTables
public void removeTables(List<String> tableNames) throws FormsException
Remove a list of tables- Parameters:
tableNames
- the names of the tables to delete- Throws:
FormsException
- if the drop of the tables is not successful
-
getColumns
public Map<String,FieldValue> getColumns(Form form)
Form to tableinfo.- Parameters:
form
- the form.- Returns:
- the tableinfo.
-
_getColumnType
protected String _getColumnType(int sqlType, String dbType)
Get the full column type corresponding to the database type (with precision).- Parameters:
sqlType
- the sqltype value.dbType
- the database type.- Returns:
- the real column type identifier (to be included in CREATE statement).
-
_getColumnTypeName
protected String _getColumnTypeName(int sqlType, String dbType)
Get the column type name (without precision) corresponding to the SQL type.- Parameters:
sqlType
- the SQL type value.dbType
- the database type.- Returns:
- the real column type name (without precision).
-
_isSameType
protected boolean _isSameType(FormTableManager.DbColumn column, FieldValue newColumn, String dbType)
Test if two columns have the same type.- Parameters:
column
- the column retrieved from the database.newColumn
- the new column.dbType
- the database type.- Returns:
- true if the two columns have the same type.
-
_createTable
private boolean _createTable(String formId, Map<String,FieldValue> columns)
-
_alterTable
private boolean _alterTable(String formId, Map<String,FieldValue> newColumns)
-
_checkTableStatus
private int _checkTableStatus(String formId, Map<String,FieldValue> newColumns)
-
_createOrUpdateTable
private boolean _createOrUpdateTable(String formId, Map<String,FieldValue> columns)
-
_getColumnsToModify
private FormTableManager.DbColumnModifications _getColumnsToModify(Connection con, Map<String,FormTableManager.DbColumn> existingColumns, Map<String,FieldValue> newColumns)
-
_getExistingColumns
private Map<String,FormTableManager.DbColumn> _getExistingColumns(Connection con, String table) throws SQLException
- Throws:
SQLException
-
_moveColumns
private void _moveColumns(Connection con, Map<String,FormTableManager.DbColumn> columnsToRemove, Map<String,FormTableManager.DbColumn> existingColumns, String tableName) throws SQLException
- Throws:
SQLException
-
_addColumns
private void _addColumns(Connection con, Map<String,FieldValue> columnsToAdd, String tableName) throws SQLException
- Throws:
SQLException
-
_getNewName
private String _getNewName(Connection con, String currentName, Set<String> existingColumnNames)
Get the new name of a column to be moved.- Parameters:
con
- the connection.currentName
- the current name.existingColumnNames
- the names of the existing columns- Returns:
- the new name.
-
getFieldSqlType
public static int getFieldSqlType(Field.FieldType fieldType)
Get the SQL type corresponding to a field type.- Parameters:
fieldType
- the field- Returns:
- the sql type as indicated in
Types
.
-
addWorkflowIdColumn
public void addWorkflowIdColumn(String formId) throws FormsException
Add a workflow id column to the given table- Parameters:
formId
- the id of the form to alter- Throws:
FormsException
- if an error occurs
-
dropWorkflowIdColumn
public void dropWorkflowIdColumn(String formId) throws FormsException
Delete the workflow id column of the given table- Parameters:
formId
- the id of the form to alter- Throws:
FormsException
- if an error occurs
-
setWorkflowId
public void setWorkflowId(Form form, long entryId, long newWorkflowId) throws FormsException
Set a new workflow id to the column that has the given old workflow id- Parameters:
form
- the formentryId
- the id of the entrynewWorkflowId
- the new workflow id- Throws:
FormsException
- if an error occurs
-
getWorkflowIds
public List<Integer> getWorkflowIds(String formId, Integer entryId) throws FormsException
Get the workflow id of the given form entry or of all the entries- Parameters:
formId
- the id of the formentryId
- the entry to get the workflow id from. If null, all the workflow ids are returned- Returns:
- the list of workflow ids
- Throws:
FormsException
- if an error occurs.
-
hasWorkflowIdColumn
public boolean hasWorkflowIdColumn(String formId) throws SQLException
Does the given form have a workflow id column in its SQL table ?- Parameters:
formId
- the id of the form- Returns:
- true if the form has a workflow id column, false otherwise
- Throws:
SQLException
- if a database access error occurs
-
deleteEntry
public void deleteEntry(String siteName, String formId, List<Integer> entries) throws ProcessingException, FormsException
Delete a list of entries of a form- Parameters:
siteName
- The site nameformId
- The form identries
- The list of entries to delete- Throws:
ProcessingException
- if the given parameters are wrongFormsException
- if an error occurs when deleting the form submission
-
clearEntries
public void clearEntries(String siteName, List<String> formIds) throws ProcessingException, FormsException
Clear all entries of the forms corresponding to the given list of ids.- Parameters:
siteName
- the name of the site.formIds
- the list of form ids- Throws:
ProcessingException
- if an error occurs.FormsException
- if an error occurs.
-
getSelectStatement
public Map<String,String> getSelectStatement(String siteName, String formId) throws ProcessingException
Get the SELECT statement for retrieving the form entries from the database.- Parameters:
siteName
- The site nameformId
- The form id- Returns:
- A result map with the SQL query and the table name
- Throws:
ProcessingException
- if the given parameters are wrong
-
-