Package com.avoka.fc.core.service.form
Class FormService
- java.lang.Object
-
- com.avoka.fc.core.service.BaseService
-
- com.avoka.fc.core.service.CayenneService
-
- com.avoka.fc.core.service.form.FormService
-
public class FormService extends CayenneService
Provides Form creation and template version creation services.
-
-
Constructor Summary
Constructors Constructor Description FormService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
changeTemplateVersion(Form form, String versionNumber)
Changes the current version of a form immediately.void
changeTemplateVersion(TemplateVersionDeployment deployment)
Changes the current version of a template immediately.List<SchemaExtractMapBean>
convertSchemaExtractMappings(List<Pair<String,String>> oldMappings)
Utility method to convert a list of older data extract mappings (Pair) to the new bean Form
createNewForm(FormBean formBean)
Create a new form instance given a form bean.TemplateVersion
createTemplateVersion(TemplateVersionBean templateVersionBean)
Create a TemplateVersion instance from a given templateVersion Bean.void
ensureHasValidReceiptRenderService(TemplateVersion templateVersion)
Ensure the form template has a valid receipt render service for the current server, if the template version has not receipt render service defined.String
generateClientUniqueFormName(Client client, String name)
Create a form name unique within the organization by appending a number starting at 2 to the name.String
generateNormalizedName(String formName)
Generates a normalized name for a given form name.String
generateUniqueFormCode(String formCode)
Generates a globally unique form code based on a suggested form code.String
generateUniqueFormCode(String formCode, List<String> forbiddenFormCodes)
Generates a globally unique form code based on a suggested form code.Portal
getDefaultRenderPortal(Form form)
Return the portal that is the "default" for rendering thie form.TemplateVersion
getFormVersionToRender(Form form, HttpServletRequest request)
Returns the form version that shall be used to fulfil a form render request.String
getSelectedFormVersionAttributeName(Form form)
Get the full name of the session attribute holding the selected form version for a particular form.TemplateVersion
getVersionWithHighestNumber(Form form)
Find the form version with the highest version number for the given form.boolean
initialiseFarDataVersion(TemplateVersion version)
Initialise the FAR data version attribute for a form version, if not already populated.void
initialiseTemplateVersion(TemplateVersion templateVersion, Form form)
Initialises the version properties and metadata values for a new template version, based on existing client properties and metadata values Note that this method assumes that the template version does not yet have any version property values or metadata values for the given form.void
updateVersionCategories(TemplateVersion version, Collection<String> categoryIds)
Updates the form version to be associated with the specified set of categories.-
Methods inherited from class com.avoka.fc.core.service.CayenneService
commitChanges, deleteObject, deleteObjects, findObject, getDataContext, getDataDomain, getObjectForPK, getObjectStore, newObject, performNamedQuery, performNamedQuery, performNamedQuery, performNonSelectingQuery, performNonSelectingQuery, performNonSelectingQuery, performNonSelectingQuery, performQuery, performQuery, refetchEntity, refetchObject, registerNewObject, rollbackChanges, toMap, toMap
-
Methods inherited from class com.avoka.fc.core.service.BaseService
getLogger
-
-
-
-
Method Detail
-
createNewForm
public Form createNewForm(FormBean formBean)
Create a new form instance given a form bean. Note that this method contains database transactions.- Parameters:
formBean
- the form bean- Returns:
- a Form instance
-
createTemplateVersion
public TemplateVersion createTemplateVersion(TemplateVersionBean templateVersionBean)
Create a TemplateVersion instance from a given templateVersion Bean. Note that this method contains database transactions.- Parameters:
templateVersionBean
- a templateVersion Bean- Returns:
- the TemplateVersion instance
-
initialiseTemplateVersion
public void initialiseTemplateVersion(TemplateVersion templateVersion, Form form)
Initialises the version properties and metadata values for a new template version, based on existing client properties and metadata values Note that this method assumes that the template version does not yet have any version property values or metadata values for the given form. If this is not the case, please do not use this method.- Parameters:
templateVersion
- the non-null template versionform
- the non-null form that is using the same template as the template version
-
generateNormalizedName
public String generateNormalizedName(String formName)
Generates a normalized name for a given form name.- Parameters:
formName
- a form name- Returns:
- the normalized form name
-
generateUniqueFormCode
public String generateUniqueFormCode(String formCode)
Generates a globally unique form code based on a suggested form code.- Parameters:
formCode
- the suggested form code- Returns:
- a globally unique form code that does not equal any of the form codes existing in the database
-
generateUniqueFormCode
public String generateUniqueFormCode(String formCode, List<String> forbiddenFormCodes)
Generates a globally unique form code based on a suggested form code.- Parameters:
formCode
- the suggested form codeforbiddenFormCodes
- a list of form codes to avoid, in addition to all form codes existing in the database- Returns:
- a globally unique form code that does not equal any of the form codes existing in the database or any of the forbidden form codes
-
generateClientUniqueFormName
public String generateClientUniqueFormName(Client client, String name)
Create a form name unique within the organization by appending a number starting at 2 to the name.- Parameters:
client
- the organization (required)name
- the name we want to start with- Returns:
- a unique form name
- Since:
- 4.1.3
-
getDefaultRenderPortal
public Portal getDefaultRenderPortal(Form form)
Return the portal that is the "default" for rendering thie form. This is primarily useful in the admin console, where we want to display action links to render a form, and must hence decide what portal to use. The rule is to use self-service portals first (pick the default portal if possible), otherwise a web plugin portal and only use a Field Worker portal as a last resort.- Parameters:
form
- the form (required)- Returns:
- the default portal to be used for rendering, or null if none was found
-
changeTemplateVersion
public void changeTemplateVersion(TemplateVersionDeployment deployment)
Changes the current version of a template immediately. The TemplateVersionDeployment record is updated with the current date and the status. Note: Do not use this method to apply scheduled changes, as the deployment date will be overwritten.- Parameters:
deployment
- a non-null template version deployment to be applied immediately
-
getSelectedFormVersionAttributeName
public String getSelectedFormVersionAttributeName(Form form)
Get the full name of the session attribute holding the selected form version for a particular form. This name is constructed fromParams.SESSION_SELECTED_FORM_VERSION_PREFIX
and the form code.- Parameters:
form
- the form (required)- Returns:
- the name of the session attribute that will be used for this form
- Since:
- 4.1.0
-
getFormVersionToRender
public TemplateVersion getFormVersionToRender(Form form, HttpServletRequest request) throws ApplicationException
Returns the form version that shall be used to fulfil a form render request.- Parameters:
form
- the form (required)request
- the HTTP servlet request (required)- Returns:
- a template version associated with the form
- Throws:
ApplicationException
- if an error occurs- Since:
- 4.1.0
-
changeTemplateVersion
public void changeTemplateVersion(Form form, String versionNumber)
Changes the current version of a form immediately. A TemplateVersionDeployment record is created for auditing purposes.- Parameters:
form
- the form (required)versionNumber
- a valid version number
-
updateVersionCategories
public void updateVersionCategories(TemplateVersion version, Collection<String> categoryIds)
Updates the form version to be associated with the specified set of categories. Any other category associations will be removed.- Parameters:
version
- the form version (required)categoryIds
- the set of categories to be associated with the version (client must match the client associated with the version)- Since:
- 3.6.0
-
ensureHasValidReceiptRenderService
public void ensureHasValidReceiptRenderService(TemplateVersion templateVersion)
Ensure the form template has a valid receipt render service for the current server, if the template version has not receipt render service defined.- Parameters:
templateVersion
- the form template version to check- Since:
- 4.1.1
-
initialiseFarDataVersion
public boolean initialiseFarDataVersion(TemplateVersion version)
Initialise the FAR data version attribute for a form version, if not already populated. This method performs a database commit.- Parameters:
version
- (required; should be a Composer Smartform where the FAR data version is currently null or blank)- Returns:
- true if the FAR data version was updated; false if it was not updated for whatever reason (already set/none available/error)
- Since:
- 4.2.1
-
convertSchemaExtractMappings
public List<SchemaExtractMapBean> convertSchemaExtractMappings(List<Pair<String,String>> oldMappings)
Utility method to convert a list of older data extract mappings (Pair) to the new bean - Parameters:
oldMappings
- the mappings (required)- Returns:
- the list of scheme extract map beans corresponding to the old mappings
- Since:
- 4.3.0
-
getVersionWithHighestNumber
public TemplateVersion getVersionWithHighestNumber(Form form)
Find the form version with the highest version number for the given form. Because version numbers can be in the format "a.b.c.d" with a, b, c, d being possibly multi-digit numbers, simple string comparisons are not good enough. If the form is null or has no version, null is returned.- Parameters:
form
- the form (required)- Returns:
- the form version with the highest version number
- Since:
- 5.1.5.1
-
-