Class FormVersionArchiveService


  • public class FormVersionArchiveService
    extends BaseArchiveService
    Provides a form and template version archive export and import service.
    • Field Detail

      • FORM_VERSION_CONFIG_FILENAME

        public static final String FORM_VERSION_CONFIG_FILENAME
        The form version configuration file name
        See Also:
        Constant Field Values
      • METADATA_FORM_CODE

        public static final String METADATA_FORM_CODE
        The name of the metadata value storing the form code of the form to be imported to
        See Also:
        Constant Field Values
      • METADATA_FORM_NAME

        public static final String METADATA_FORM_NAME
        The name of the metadata value storing the name of the form to be imported to
        See Also:
        Constant Field Values
      • METADATA_FORM_VERSION_NUMBER

        public static final String METADATA_FORM_VERSION_NUMBER
        The name of the metadata value storing the version number to be imported (set only if the archive contains a single form version)
        See Also:
        Constant Field Values
      • METADATA_CLIENT_CODE

        public static final String METADATA_CLIENT_CODE
        The name of the metadata value storing the client code of the form to be imported to
        See Also:
        Constant Field Values
    • Constructor Detail

      • FormVersionArchiveService

        public FormVersionArchiveService()
    • Method Detail

      • getImportMetadata

        public Map<String,​String> getImportMetadata​(byte[] importData,
                                                          String newClientCode,
                                                          String newFormCode)
                                                   throws IOException,
                                                          ImportValidationException
        Retrieve the set of metadata values describing a form version archive that is being imported.
        Parameters:
        importData - the import archive as a byte array
        newClientCode - the client code of the client to import to
        newFormCode - the form code for the form to be created
        Returns:
        a map of metadata names and their values
        Throws:
        IOException - if an error occurs while parsing the import archive
        ImportValidationException - if the XML file describing the client was not found in the archive
      • setNewClientCode

        public void setNewClientCode​(String newClientCode)
        Set the client code of the client to be imported to (relevant only if a client code different to the one in the archive is to be used)
        Parameters:
        newClientCode - the client code
      • setNewFormCode

        public void setNewFormCode​(String newFormCode)
        Set the form code of the form to be created
        Parameters:
        newFormCode - the form code
        Since:
        4.1.3
      • postExport

        protected void postExport​(Object exportObject)
        Description copied from class: BaseArchiveService
        Called after the export has been done, and the file created. Can be used to do service-specific activities such as logging.
        Overrides:
        postExport in class BaseArchiveService
        Parameters:
        exportObject - the object that was passed to exportData
      • processImportFile

        protected void processImportFile​(String fileName,
                                         byte[] fileData)
                                  throws UnsupportedEncodingException
        Description copied from class: BaseArchiveService
        For a given file in the imported archive, the service stores its contents as it sees fit, preserving what it will need to recreate entities later. This operation happens before the database transaction wrapping the actual import to the SFM database.
        Specified by:
        processImportFile in class BaseArchiveService
        Parameters:
        fileName - the full file name of the ZIP file entry (e.g. form/TestForm.pdf)
        fileData - the file data of the ZIP file entry
        Throws:
        UnsupportedEncodingException
      • performImport

        protected void performImport​(ImportAction importAction,
                                     Set<? extends Enum> importOptions,
                                     Map<String,​Object> parameters)
                              throws ParseException
        Description copied from class: BaseArchiveService
        Performs the act of importing the data contained in the archive to the SFM database. When this method will be called, the caller is expected to have established a transaction, and will also handle errors thrown by this method.
        Specified by:
        performImport in class BaseArchiveService
        Parameters:
        importAction - the import action related to this import
        importOptions - the set of import options that should be applied
        parameters - optional parameters to be used during import
        Throws:
        ParseException
      • getEntityName

        protected String getEntityName()
        Description copied from class: BaseArchiveService
        Return the name identifying the individual entity being exported (e.g. for a client, the client's name)
        Specified by:
        getEntityName in class BaseArchiveService
        Returns:
        the entity name
      • getFormVersionKey

        protected String getFormVersionKey​(String formCode,
                                           TemplateVersion version)
        Description copied from class: BaseArchiveService
        Make sure to pass in the appropriate form code. For example, during application package import, form codes may automatically be changed to unique ones. However, in the archive the old form codes are used as directory names, so this method must be used. Note that the form version archive service uses a different key.
        Overrides:
        getFormVersionKey in class BaseArchiveService
      • exportAuditLogger

        protected void exportAuditLogger​(Object object)
        Create an entry in the audit log when an export is performed
        Specified by:
        exportAuditLogger in class BaseArchiveService
        Parameters:
        object - Object of type (Pair) that was exported (Optional)
        Since:
        17.10.2
      • importAuditLogger

        protected void importAuditLogger​(ImportAction importAction)
        Create an entry in the audit log when an import is performed
        Specified by:
        importAuditLogger in class BaseArchiveService
        Parameters:
        importAction - ImportAction containing action performed (required)
        Since:
        17.10.2