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.
-
-
Field Summary
Fields Modifier and Type Field Description 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 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.protected boolean
_isSameType(org.ametys.plugins.forms.table.FormTableManager.DbColumn column, FieldValue newColumn, String dbType)
Test if two columns have the same type.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 tableList<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.Map<String,String>
getSelectStatement(String siteName, String formId)
Get the SELECT statement for retrieving the form entries from the database.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
-
-
Constructor Detail
-
FormTableManager
public FormTableManager()
-
-
Method Detail
-
service
public void service(ServiceManager smanager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
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.
-
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(org.ametys.plugins.forms.table.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.
-
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
-
-