Class FormTableManager
java.lang.Object
org.ametys.plugins.forms.content.table.FormTableManager
- All Implemented Interfaces:
Component
,Serviceable
Class that handles creation and deletion of a table used by a form.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Creation date field name.static final String
Suffix for filename column.static final String
The id of the configuration parameter used for the forms' datasourcestatic final String
ID field name.static final String
Current user login field name.static final String
Current user population id field name.static final String
Avalon Rolestatic final int
Constant for table statestatic final int
Constant for table statestatic final int
Constant for table statestatic final String
Prefix for database tablesstatic final int
Constant for table statestatic final String
Workflow id column name. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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 UserEntry
_getUserEntryFromResultSet
(ResultSet rs, Form form, Map<String, FieldValue> columns, String dbType) Get a user entry from a result setprotected boolean
_isSameType
(org.ametys.plugins.forms.content.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
Drop the table by its namevoid
dropWorkflowIdColumn
(String formId) Delete the workflow id column of the given tablegetColumns
(String siteName, String formId) Get the columns information of a formgetColumns
(Form form) Form to tableinfo.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.getSelectStatement
(String siteName, String formId) Get the SELECT statement for retrieving the form entries from the database.getSubmission
(Form form, Map<String, FieldValue> columns, Integer entryId) Get the submission for a form.getSubmissions
(Form form, Map<String, FieldValue> columns, int offset, int length, List<Integer> entryIds) Get all the submissions for a form.Get all the table namesint
getTotalSubmissions
(String formId) Get the total count of submissions for a form.getUserAnwsers
(List<Form> forms, UserIdentity user) Get the user answers from a list of formsgetWorkflowIds
(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 Details
-
ROLE
Avalon Role -
FORMS_POOL_CONFIG_PARAM
The id of the configuration parameter used for the forms' datasource- See Also:
-
TABLE_PREFIX
Prefix for database tables- See Also:
-
ID_FIELD
ID field name.- See Also:
-
CREATION_DATE_FIELD
Creation date field name.- See Also:
-
LOGIN_FIELD
Current user login field name.- See Also:
-
POPULATION_ID_FIELD
Current user population id field name.- See Also:
-
WORKFLOW_ID_FIELD
Workflow id column name.- See Also:
-
FILE_NAME_COLUMN_SUFFIX
Suffix for filename column.- See Also:
-
TABLE_CREATED_AND_UP_TO_DATE
Constant for table state- See Also:
-
TABLE_CREATED_BUT_NEED_UPDATE
Constant for table state- See Also:
-
TABLE_NOT_CREATED
Constant for table state- See Also:
-
TABLE_UNKOWN_STATUS
Constant for table state- See Also:
-
-
Constructor Details
-
FormTableManager
public FormTableManager()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
createTable
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
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
Get all the table names- Returns:
- the list of all the forms' table names
-
getUserAnwsers
Get the user answers from a list of forms- Parameters:
forms
- the list of formsuser
- the user- Returns:
- the list of common answer
- Throws:
FormsException
- if an forms error occurred
-
getSubmissions
public List<UserEntry> getSubmissions(Form form, Map<String, FieldValue> columns, int offset, int length, List<Integer> entryIds) throws FormsExceptionGet 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.
-
getSubmission
public UserEntry getSubmission(Form form, Map<String, FieldValue> columns, Integer entryId) throws FormsExceptionGet the submission for a form.- Parameters:
form
- the form object.columns
- the columnsentryId
- the id of the submission to retrieve- Returns:
- the submission.
- Throws:
FormsException
- if an error occurs.
-
_getUserEntryFromResultSet
protected UserEntry _getUserEntryFromResultSet(ResultSet rs, Form form, Map<String, FieldValue> columns, String dbType) throws SQLException, IOExceptionGet a user entry from a result set- Parameters:
rs
- the result setform
- the formcolumns
- the columnsdbType
- the db type- Returns:
- the user entry
- Throws:
SQLException
- if a sql error occurredIOException
- is a io error occurred
-
getTotalSubmissions
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
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
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
Form to tableinfo.- Parameters:
form
- the form.- Returns:
- the tableinfo.
-
_getColumnType
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
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.content.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
Get the SQL type corresponding to a field type.- Parameters:
fieldType
- the field- Returns:
- the sql type as indicated in
Types
.
-
addWorkflowIdColumn
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
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
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
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
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
-