Package org.ametys.plugins.forms.jcr
Class FormPropertiesManager
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.plugins.forms.jcr.FormPropertiesManager
-
- All Implemented Interfaces:
PluginAware
,Component
,LogEnabled
,Serviceable
public class FormPropertiesManager extends AbstractLogEnabled implements Serviceable, Component, PluginAware
Form properties manager : stores and retrieves form properties.
-
-
Field Summary
Fields Modifier and Type Field Description protected String
_pluginName
The plugin name.protected Repository
_repository
The JCR repository.protected AmetysObjectResolver
_resolver
The resolver for ametys objectsprotected SiteManager
_siteManager
The Site manager.static String
FIELD_PROPERTY_ID
"ID" field property name.static String
FIELD_PROPERTY_LABEL
"Label" field property name.static String
FIELD_PROPERTY_NAME
"Name" field property name.static String
FIELD_PROPERTY_PREFIX
Field properties prefix.static String
FIELD_PROPERTY_TYPE
"Type" field property name.static String
FORM_PROPERTY_EMAILS
"Emails" property name.static String
FORM_PROPERTY_ID
"ID" property name.static String
FORM_PROPERTY_LABEL
"Label" property name.static String
FORM_PROPERTY_LIMIT
"Limit" property name.static String
FORM_PROPERTY_NO_REMAINING_PLACES
"No remaining places" property name.static String
FORM_PROPERTY_RECEIPT_BODY
"Receipt field ID" property name.static String
FORM_PROPERTY_RECEIPT_FIELD_ID
"Receipt field ID" property name.static String
FORM_PROPERTY_RECEIPT_FROM_ADDRESS
"Receipt field ID" property name.static String
FORM_PROPERTY_RECEIPT_SUBJECT
"Receipt field ID" property name.static String
FORM_PROPERTY_REDIRECT_TO
The uuid of the page where to redirect tostatic String
FORM_PROPERTY_REMAINING_PLACES
"Remaining places" property name.static String
FORM_PROPERTY_WORKFLOW_NAME
"Workflow name" property name.static String
FORMS_NODE
Forms node name.static String
LANGUAGE_PROPERTY
Language propertystatic Pattern
OPTION_VALUE_PATTERN
Pattern for options valuestatic String
PLUGINS_NODE
Plugins root node name.static String
ROLE
The avalon component ROLE.static String
ROOT_REPO
JCR relative path to root node.static String
SITE_PROPERTY
Site property
-
Constructor Summary
Constructors Constructor Description FormPropertiesManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Node
_createOrGetFormsNode(Node baseNode)
Get or create the forms node in a content node.protected Field
_extractField(Node fieldNode)
Extracts a field from a JCR Node.protected void
_extractFields(Node formNode, Form form)
Extracts a form from a JCR Node.protected Form
_extractForm(Node formNode)
Extracts a form from a JCR Node.protected void
_fillFieldNode(Node fieldNode, Field field)
Fill a field node.protected void
_fillFormNode(Node formNode, Form form)
Fill a form node.protected Map<String,String>
_getFieldProperties(Node node)
Get additional configuration from properties.protected Collection<String>
_getMultipleProperty(Node node, String propertyName)
Get the values of a string array property.protected String
_getNotExistingNodeName(Node container, String baseName)
Get a name for a node which doesn't already exist in this node.protected String
_getSingleProperty(Node node, String propertyName, String defaultValue)
Get a single property value.protected Node
_storeField(Node formNode, Field field)
Store a field node.protected Node
_storeForm(Node contentNode, Form form)
Persist the form in a repository node.protected void
_updateFields(Form form, Node formNode)
Update the field nodes of a form.void
createForm(String siteName, Form form, Content content)
Store the properties of a form in the repository.String
getDisplayValue(Field field, String value)
Get the value for displayForm
getForm(String id)
Get a form from the repository.Form
getForm(String siteName, String id)
Get a form from the repository.Content
getFormContent(String formId)
Get the content containing the form with the given idList<Node>
getFormContentNodes(String siteName, String language)
Get all the contents containing at least one form of the given site with the given languageList<Form>
getForms(Node node)
Extract all the form objects from a nodeList<Form>
getForms(Content content)
Get the forms in a specified content.Node
getMostRecentFormFrozenContent(String formId)
Get the most recent frozen node that contain the form of the given idvoid
remove(Form form, Content content)
Remove a formvoid
service(ServiceManager serviceManager)
void
setPluginInfo(String pluginName, String featureName, String id)
Sets the plugin info relative to the current component.
Note : The feature name may be null if the targeted component in declared at plugin level.void
updateForm(String siteName, Form form, Content content)
Update the properties of a form in the repository.-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
OPTION_VALUE_PATTERN
public static final Pattern OPTION_VALUE_PATTERN
Pattern for options value
-
ROOT_REPO
public static final String ROOT_REPO
JCR relative path to root node.- See Also:
- Constant Field Values
-
PLUGINS_NODE
public static final String PLUGINS_NODE
Plugins root node name.- See Also:
- Constant Field Values
-
FORMS_NODE
public static final String FORMS_NODE
Forms node name.- See Also:
- Constant Field Values
-
LANGUAGE_PROPERTY
public static final String LANGUAGE_PROPERTY
Language property- See Also:
- Constant Field Values
-
SITE_PROPERTY
public static final String SITE_PROPERTY
Site property- See Also:
- Constant Field Values
-
FORM_PROPERTY_ID
public static final String FORM_PROPERTY_ID
"ID" property name.- See Also:
- Constant Field Values
-
FORM_PROPERTY_LABEL
public static final String FORM_PROPERTY_LABEL
"Label" property name.- See Also:
- Constant Field Values
-
FORM_PROPERTY_RECEIPT_FIELD_ID
public static final String FORM_PROPERTY_RECEIPT_FIELD_ID
"Receipt field ID" property name.- See Also:
- Constant Field Values
-
FORM_PROPERTY_RECEIPT_FROM_ADDRESS
public static final String FORM_PROPERTY_RECEIPT_FROM_ADDRESS
"Receipt field ID" property name.- See Also:
- Constant Field Values
-
FORM_PROPERTY_RECEIPT_SUBJECT
public static final String FORM_PROPERTY_RECEIPT_SUBJECT
"Receipt field ID" property name.- See Also:
- Constant Field Values
-
FORM_PROPERTY_RECEIPT_BODY
public static final String FORM_PROPERTY_RECEIPT_BODY
"Receipt field ID" property name.- See Also:
- Constant Field Values
-
FORM_PROPERTY_REDIRECT_TO
public static final String FORM_PROPERTY_REDIRECT_TO
The uuid of the page where to redirect to- See Also:
- Constant Field Values
-
FORM_PROPERTY_EMAILS
public static final String FORM_PROPERTY_EMAILS
"Emails" property name.- See Also:
- Constant Field Values
-
FORM_PROPERTY_WORKFLOW_NAME
public static final String FORM_PROPERTY_WORKFLOW_NAME
"Workflow name" property name.- See Also:
- Constant Field Values
-
FIELD_PROPERTY_ID
public static final String FIELD_PROPERTY_ID
"ID" field property name.- See Also:
- Constant Field Values
-
FIELD_PROPERTY_TYPE
public static final String FIELD_PROPERTY_TYPE
"Type" field property name.- See Also:
- Constant Field Values
-
FIELD_PROPERTY_NAME
public static final String FIELD_PROPERTY_NAME
"Name" field property name.- See Also:
- Constant Field Values
-
FIELD_PROPERTY_LABEL
public static final String FIELD_PROPERTY_LABEL
"Label" field property name.- See Also:
- Constant Field Values
-
FIELD_PROPERTY_PREFIX
public static final String FIELD_PROPERTY_PREFIX
Field properties prefix.- See Also:
- Constant Field Values
-
FORM_PROPERTY_LIMIT
public static final String FORM_PROPERTY_LIMIT
"Limit" property name.- See Also:
- Constant Field Values
-
FORM_PROPERTY_REMAINING_PLACES
public static final String FORM_PROPERTY_REMAINING_PLACES
"Remaining places" property name.- See Also:
- Constant Field Values
-
FORM_PROPERTY_NO_REMAINING_PLACES
public static final String FORM_PROPERTY_NO_REMAINING_PLACES
"No remaining places" property name.- See Also:
- Constant Field Values
-
_repository
protected Repository _repository
The JCR repository.
-
_siteManager
protected SiteManager _siteManager
The Site manager.
-
_resolver
protected AmetysObjectResolver _resolver
The resolver for ametys objects
-
_pluginName
protected String _pluginName
The plugin name.
-
-
Constructor Detail
-
FormPropertiesManager
public FormPropertiesManager()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
setPluginInfo
public void setPluginInfo(String pluginName, String featureName, String id)
Description copied from interface:PluginAware
Sets the plugin info relative to the current component.
Note : The feature name may be null if the targeted component in declared at plugin level.- Specified by:
setPluginInfo
in interfacePluginAware
- Parameters:
pluginName
- Unique identifier for the plugin hosting the extensionfeatureName
- Unique feature identifier (unique for a given pluginName)id
- Unique identifier of this component
-
getForm
public Form getForm(String id) throws FormsException
Get a form from the repository.- Parameters:
id
- the form ID.- Returns:
- the Form or null if no form with this ID exists.
- Throws:
FormsException
- if an error occurs.
-
getForm
public Form getForm(String siteName, String id) throws FormsException
Get a form from the repository.- Parameters:
siteName
- the site name.id
- the form ID.- Returns:
- the Form or null if no form with this ID exists.
- Throws:
FormsException
- if an error occurs.
-
getMostRecentFormFrozenContent
public Node getMostRecentFormFrozenContent(String formId) throws FormsException
Get the most recent frozen node that contain the form of the given id- Parameters:
formId
- the id of the form- Returns:
- the list of frozen content nodes containing the form
- Throws:
FormsException
- if an error occurs while retrieving the forms' frozen content nodes
-
getForms
public List<Form> getForms(Content content) throws FormsException
Get the forms in a specified content.- Parameters:
content
- the content.- Returns:
- the forms as a list.
- Throws:
FormsException
- if an error occurs.
-
getFormContentNodes
public List<Node> getFormContentNodes(String siteName, String language) throws FormsException
Get all the contents containing at least one form of the given site with the given language- Parameters:
siteName
- the site name.language
- the language- Returns:
- the forms' list or null if none was found
- Throws:
FormsException
- if an error occurs.
-
getFormContent
public Content getFormContent(String formId) throws FormsException
Get the content containing the form with the given id- Parameters:
formId
- the id of the form- Returns:
- the
Content
containing the form ornull
if not found - Throws:
FormsException
- if something goes wrong when either querying the form JCR node or finding its parentContent
-
getForms
public List<Form> getForms(Node node) throws FormsException, RepositoryException
Extract all the form objects from a node- Parameters:
node
- the node- Returns:
- the forms list of this node
- Throws:
FormsException
- if an error occursRepositoryException
- if an error occurs when getting the properties of a node
-
createForm
public void createForm(String siteName, Form form, Content content) throws FormsException
Store the properties of a form in the repository.- Parameters:
siteName
- the site name.form
- the form object.content
- the form content.- Throws:
FormsException
- if an error occurs storing the form.
-
updateForm
public void updateForm(String siteName, Form form, Content content) throws FormsException
Update the properties of a form in the repository.- Parameters:
siteName
- the site name.form
- the form object.content
- the form content.- Throws:
FormsException
- if an error occurs storing the form.
-
getDisplayValue
public String getDisplayValue(Field field, String value)
Get the value for display- Parameters:
field
- The fieldvalue
- The value- Returns:
- The value to display
-
_extractForm
protected Form _extractForm(Node formNode) throws RepositoryException
Extracts a form from a JCR Node.- Parameters:
formNode
- the form node.- Returns:
- the Form object.
- Throws:
RepositoryException
- if a repository error occurs.
-
_extractFields
protected void _extractFields(Node formNode, Form form) throws RepositoryException
Extracts a form from a JCR Node.- Parameters:
formNode
- the form node.form
- the form object.- Throws:
RepositoryException
- if a repository error occurs.
-
_extractField
protected Field _extractField(Node fieldNode) throws RepositoryException
Extracts a field from a JCR Node.- Parameters:
fieldNode
- the field node.- Returns:
- the Field object.
- Throws:
RepositoryException
- if a repository error occurs.
-
_storeForm
protected Node _storeForm(Node contentNode, Form form) throws RepositoryException
Persist the form in a repository node.- Parameters:
contentNode
- the content node in which the form is to be stored.form
- the form object to persist.- Returns:
- the newly created form node.
- Throws:
RepositoryException
- if a repository error occurs while filling the node.
-
_fillFormNode
protected void _fillFormNode(Node formNode, Form form) throws RepositoryException, FormsException
Fill a form node.- Parameters:
formNode
- the form node.form
- the form object.- Throws:
RepositoryException
- if a repository error occurs while filling the node.FormsException
- if a forms error occurs while filling the node.
-
_storeField
protected Node _storeField(Node formNode, Field field) throws RepositoryException, FormsException
Store a field node.- Parameters:
formNode
- the form node.field
- the field.- Returns:
- the newly created field node.
- Throws:
RepositoryException
- if a repository error occurs while filling the node.FormsException
- if a forms error occurs while filling the node.
-
_fillFieldNode
protected void _fillFieldNode(Node fieldNode, Field field) throws RepositoryException, FormsException
Fill a field node.- Parameters:
fieldNode
- the field node.field
- the field object.- Throws:
RepositoryException
- if a repository error occurs while filling the node.FormsException
- if a forms error occurs while filling the node.
-
_updateFields
protected void _updateFields(Form form, Node formNode) throws RepositoryException, FormsException
Update the field nodes of a form.- Parameters:
form
- the new form object.formNode
- the node of the form to update.- Throws:
RepositoryException
- if a repository error occurs while updating the fields.FormsException
- if a forms error occurs while updating the fields.
-
_getNotExistingNodeName
protected String _getNotExistingNodeName(Node container, String baseName) throws RepositoryException
Get a name for a node which doesn't already exist in this node.- Parameters:
container
- the container node.baseName
- the base wanted node name.- Returns:
- the name, free to be taken.
- Throws:
RepositoryException
- if a repository error occurs.
-
_getSingleProperty
protected String _getSingleProperty(Node node, String propertyName, String defaultValue) throws RepositoryException
Get a single property value.- Parameters:
node
- the JCR node.propertyName
- the name of the property to get.defaultValue
- the default value if the property does not exist.- Returns:
- the single property value.
- Throws:
RepositoryException
- if a repository error occurs.
-
_getMultipleProperty
protected Collection<String> _getMultipleProperty(Node node, String propertyName) throws RepositoryException
Get the values of a string array property.- Parameters:
node
- the node.propertyName
- the name of the property to get.- Returns:
- the values.
- Throws:
RepositoryException
- if a repository error occurs.
-
_getFieldProperties
protected Map<String,String> _getFieldProperties(Node node) throws RepositoryException
Get additional configuration from properties.- Parameters:
node
- the JCR node.- Returns:
- the additional configuration as a Map.
- Throws:
RepositoryException
- if a repository error occurs.
-
remove
public void remove(Form form, Content content) throws FormsException
Remove a form- Parameters:
form
- The form to removecontent
- The content holding the form- Throws:
FormsException
- of an exception occurs when manipulating the forms' repository nodes
-
_createOrGetFormsNode
protected Node _createOrGetFormsNode(Node baseNode) throws RepositoryException
Get or create the forms node in a content node.- Parameters:
baseNode
- the content base node.- Returns:
- the forms node.
- Throws:
RepositoryException
- if an error occurs.
-
-