public class FormTableManager extends Object implements Component, Serviceable
Modifier and Type | Class and Description |
---|---|
(package private) class |
FormTableManager.DbColumn
Class representing a db column.
|
(package private) class |
FormTableManager.DbColumnModifications
Class storing modifications to do on columns.
|
Modifier and Type | Field and Description |
---|---|
private static 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' datasource
|
static String |
ID_FIELD
ID field name.
|
static String |
ROLE
Avalon Role
|
static int |
TABLE_CREATED_AND_UP_TO_DATE
Constant for table state
|
static int |
TABLE_CREATED_BUT_NEED_UPDATE
Constant for table state
|
static int |
TABLE_NOT_CREATED
Constant for table state
|
static String |
TABLE_PREFIX
Prefix for database tables
|
static int |
TABLE_UNKOWN_STATUS
Constant for table state
|
static String |
WORKFLOW_ID_FIELD
Workflow id column name.
|
Constructor and Description |
---|
FormTableManager() |
Modifier and Type | Method and 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 query
|
protected 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 table
|
void |
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 forms
|
void |
deleteEntry(String siteName,
String formId,
List<Integer> entries)
Delete a list of entries of a form
|
boolean |
dropTable(String table)
Drop the table by its name
|
void |
dropWorkflowIdColumn(String formId)
Delete the workflow id column of the given table
|
private AmetysObjectResolver |
getAmetysObjectResolver() |
Map<String,FieldValue> |
getColumns(Form form)
Form to tableinfo.
|
List<Map<String,Object>> |
getColumns(String siteName,
String formId)
Get the columns information of a form
|
List<Map<String,Object>> |
getContentForms(List<String> contentIds,
String currentLanguage)
Get the forms of contents
|
static 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 names
|
int |
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 entries
|
boolean |
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 tables
|
void |
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
|
public static final String FORMS_POOL_CONFIG_PARAM
public static final String TABLE_PREFIX
public static final String ID_FIELD
public static final String CREATION_DATE_FIELD
public static final String WORKFLOW_ID_FIELD
public static final String FILE_NAME_COLUMN_SUFFIX
public static final int TABLE_CREATED_AND_UP_TO_DATE
public static final int TABLE_CREATED_BUT_NEED_UPDATE
public static final int TABLE_NOT_CREATED
public static final int TABLE_UNKOWN_STATUS
private ServiceManager _manager
private FormPropertiesManager _formPropertiesManager
private AmetysObjectResolver _resolver
private I18nUtils _i18nUtils
private JdbcWorkflowStore _jdbcWorkflowStore
private SQLDatabaseTypeExtensionPoint _sqlDatabaseTypeExtensionPoint
public FormTableManager()
public void service(ServiceManager smanager) throws ServiceException
service
in interface Serviceable
ServiceException
private SQLDatabaseTypeExtensionPoint getSQLDatabaseTypeExtensionPoint()
private I18nUtils getI18nUtils()
private AmetysObjectResolver getAmetysObjectResolver()
private FormPropertiesManager getFormPropertiesManager()
private JdbcWorkflowStore getJdbcWorkflowStore()
public boolean createTable(Form form)
form
- informations used to create tablepublic boolean dropTable(String table)
table
- the name of the table to droppublic List<String> getTableNames()
public List<UserEntry> getSubmissions(Form form, Map<String,FieldValue> columns, int offset, int length, List<Integer> entryIds) throws FormsException
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 retrieveFormsException
- if an error occurs.private String _getSubmissionsQuery(int offset, int length, String tableName, String dbType)
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 usedpublic int getTotalSubmissions(String formId) throws FormsException
formId
- the id of the formFormsException
- if an error occurs.public List<Map<String,Object>> getContentForms(List<String> contentIds, String currentLanguage) throws FormsException, URISyntaxException
contentIds
- The ids of contentscurrentLanguage
- The current languageFormsException
- if an error occurred while getting content' formURISyntaxException
- if an error occurred when URL encoding form's labelpublic List<Map<String,Object>> getColumns(String siteName, String formId) throws FormsException
siteName
- The site nameformId
- the identifier of formFormsException
- if an error occurredpublic void removeTables(List<String> tableNames) throws FormsException
tableNames
- the names of the tables to deleteFormsException
- if the drop of the tables is not successfulpublic Map<String,FieldValue> getColumns(Form form)
form
- the form.protected String _getColumnType(int sqlType, String dbType)
sqlType
- the sqltype value.dbType
- the database type.protected String _getColumnTypeName(int sqlType, String dbType)
sqlType
- the SQL type value.dbType
- the database type.protected boolean _isSameType(FormTableManager.DbColumn column, FieldValue newColumn, String dbType)
column
- the column retrieved from the database.newColumn
- the new column.dbType
- the database type.private boolean _createTable(String formId, Map<String,FieldValue> columns)
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 FormTableManager.DbColumnModifications _getColumnsToModify(Connection con, Map<String,FormTableManager.DbColumn> existingColumns, Map<String,FieldValue> newColumns)
private Map<String,FormTableManager.DbColumn> _getExistingColumns(Connection con, String table) throws SQLException
SQLException
private void _moveColumns(Connection con, Map<String,FormTableManager.DbColumn> columnsToRemove, Map<String,FormTableManager.DbColumn> existingColumns, String tableName) throws SQLException
SQLException
private void _addColumns(Connection con, Map<String,FieldValue> columnsToAdd, String tableName) throws SQLException
SQLException
private String _getNewName(Connection con, String currentName, Set<String> existingColumnNames)
con
- the connection.currentName
- the current name.existingColumnNames
- the names of the existing columnspublic static int getFieldSqlType(Field.FieldType fieldType)
fieldType
- the fieldTypes
.public void addWorkflowIdColumn(String formId) throws FormsException
formId
- the id of the form to alterFormsException
- if an error occurspublic void dropWorkflowIdColumn(String formId) throws FormsException
formId
- the id of the form to alterFormsException
- if an error occurspublic void setWorkflowId(Form form, long entryId, long newWorkflowId) throws FormsException
form
- the formentryId
- the id of the entrynewWorkflowId
- the new workflow idFormsException
- if an error occurspublic List<Integer> getWorkflowIds(String formId, Integer entryId) throws FormsException
formId
- the id of the formentryId
- the entry to get the workflow id from. If null, all the workflow ids are returnedFormsException
- if an error occurs.public boolean hasWorkflowIdColumn(String formId) throws SQLException
formId
- the id of the formSQLException
- if a database access error occurspublic void deleteEntry(String siteName, String formId, List<Integer> entries) throws ProcessingException, FormsException
siteName
- The site nameformId
- The form identries
- The list of entries to deleteProcessingException
- if the given parameters are wrongFormsException
- if an error occurs when deleting the form submissionpublic void clearEntries(String siteName, List<String> formIds) throws ProcessingException, FormsException
siteName
- the name of the site.formIds
- the list of form idsProcessingException
- if an error occurs.FormsException
- if an error occurs.public Map<String,String> getSelectStatement(String siteName, String formId) throws ProcessingException
siteName
- The site nameformId
- The form idProcessingException
- if the given parameters are wrong