Class BaseArchiveService

    • Constructor Detail

      • BaseArchiveService

        public BaseArchiveService()
    • Method Detail

      • exportData

        public void exportData​(Object object,
                               OutputStream outputStream)
        Export the specified entity to an output stream.
        Parameters:
        object - the object to be exported (required)
        outputStream - an output stream (required)
      • exportData

        public void exportData​(Object object,
                               OutputStream outputStream,
                               Map<String,​String> additionalHeaders)
        Export the specified entity to an output stream.
        Parameters:
        object - the object to be exported (required)
        outputStream - an output stream (required)
        additionalHeaders - a map of parameters to add to the header metadata (optional)
      • getDefaultImportOptions

        public Set<? extends IJMImportOption> getDefaultImportOptions​(String metadataImportAction)
        Return the immutable set of import options that make sense as a default for the given import action.
        Parameters:
        metadataImportAction - the import action that will be performed (one of METADATA_IMPORT_ACTION_CREATE, METADATA_IMPORT_ACTION_UPDATE)
        Returns:
        the set of default import options
        Since:
        20.05.0
      • exportAuditLogger

        protected abstract void exportAuditLogger​(Object object)
        Create an entry in the audit log when an export is performed This is called before the postExport method
        Parameters:
        object - Object exported (Optional)
        Since:
        17.10.2
      • importAuditLogger

        protected abstract void importAuditLogger​(ImportAction object)
        Create an entry in the audit log when an import is performed This is called before the postImport method
        Parameters:
        object - ImportAction containing action performed (required)
        Since:
        17.10.2
      • validateImportData

        public abstract void validateImportData​(byte[] importData)
                                         throws Exception
        Validate an archive before it is imported.
        Parameters:
        importData - the import archive as a byte array
        Throws:
        Exception - if an error occurs during validation
      • getImportMetadata

        public abstract Map<String,​String> getImportMetadata​(byte[] importData)
                                                            throws Exception
        Retrieve the set of metadata values describing an archive that is being imported.
        Parameters:
        importData - the import archive as a byte array
        Returns:
        a map of metadata names and their values
        Throws:
        Exception - if an error occurs while the metadata is being loaded
      • importArchive

        public void importArchive​(ImportAction importAction,
                                  Set<? extends Enum> importOptions)
                           throws Exception
        Import the archive from a input stream
        Parameters:
        importAction - the input action object related to this import
        importOptions - a set of import options
        Throws:
        Exception - if an error occurs during import
      • importArchive

        public void importArchive​(ImportAction importAction,
                                  Set<? extends Enum> importOptions,
                                  Map<String,​Object> parameters)
                           throws Exception
        Import the archive from a input stream
        Parameters:
        importAction - the input action object related to this import
        importOptions - a set of import options
        parameters - a set of optional parameters to be used during import
        Throws:
        Exception - if an error occurs during import
      • findFileInArchive

        public byte[] findFileInArchive​(byte[] zipFileData,
                                        String name)
                                 throws IOException
        Find the given file in the archive and return its contents
        Parameters:
        zipFileData - the ZIP file data
        name - the name of the ZIP file entry (required)
        Returns:
        the data for the entry with the given name, or null if not found
        Throws:
        IOException - if an error occurs while reading the ZIP file
        Since:
        20.05.0
      • isGroovySecureAPI

        public boolean isGroovySecureAPI()
        Return true if GroovySecure API is enforced.
        Returns:
        true if GroovySecure API is enforced
        Since:
        5.1.7
      • setGroovySecureAPI

        public void setGroovySecureAPI​(boolean value)
        Set whether the GroovySecureAPI is enforced
        Parameters:
        value - set whether the GroovySecureAPI is enforced
        Since:
        5.1.7
      • writeExportData

        protected abstract void writeExportData​(Object object,
                                                ZipOutputStream zos,
                                                Map<String,​String> additionalHeaders)
                                         throws Exception
        Does the actual export of the data without having to worry about handling errors or preparing and closing the stream
        Parameters:
        object - the non-null object to be exported
        zos - the stream to be written to
        additionalHeaders - the map of additional headers to be included in metadata
        Throws:
        Exception - if an error occurs
      • processImportFile

        protected abstract void processImportFile​(String fileName,
                                                  byte[] fileData)
                                           throws Exception
        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.
        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:
        Exception - if an error occurs
      • performImport

        protected abstract void performImport​(ImportAction importAction,
                                              Set<? extends Enum> importOptions,
                                              Map<String,​Object> parameters)
                                       throws Exception
        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.
        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:
        Exception - If an error occurs. The caller is responsible for rolling back the transaction to avoid contaminating the database.
      • postImport

        protected void postImport​(ImportAction importAction)
        Can be used to do post-import tasks such as form publishing.
      • getEntityName

        protected abstract String getEntityName()
        Return the name identifying the individual entity being exported (e.g. for a client, the client's name)
        Returns:
        the entity name
      • postExport

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

        protected void writeHeaderAttributes​(Element element,
                                             Map<String,​String> additionalHeaders)
      • readMetadataAttributes

        protected void readMetadataAttributes​(Element rootElement,
                                              Map<String,​String> metadataMap)
        Add the metadata shared by all export files to the metadata map
        Parameters:
        rootElement - the root element in the export config file (required)
        metadataMap - the map to add the metadata entries to
      • createChildProperty

        protected void createChildProperty​(Element parent,
                                           String nodeName,
                                           Object source)
      • createChildValue

        protected void createChildValue​(Element parent,
                                        String nodeName,
                                        String value)
      • writeServiceReference

        protected void writeServiceReference​(Element parentElement,
                                             String childElementName,
                                             ServiceDefinition serviceDefinition)
        Creates a child element for a reference to a service definition
        Parameters:
        parentElement - the parent element (required)
        childElementName - the name of the child element wrapping the service data (required)
        serviceDefinition - the service definition (required)
      • readServiceName

        protected String readServiceName​(Element serviceElement)
        Return the service name of the service stored in the specified element
        Parameters:
        serviceElement - the element containing the service name and type
        Returns:
        the service name
      • copyFromElementToEntity

        protected void copyFromElementToEntity​(Element element,
                                               BaseEntity entity,
                                               List<String> exclusions,
                                               List<String> warnings)
        Copies from an XML element to the given entity, using EntityArchiveUtils. If an error occurs, an import warning is added, and the error is swallowed. This allows us to ignore minor schema differences without having to code exclusions for every single potential difference.
        Parameters:
        element - the XML element containing the data
        entity - the entity to copy to
        exclusions - the list of excluded properties
        warnings - the list of import warnings
      • addFormPortals

        protected void addFormPortals​(Form form,
                                      Element parentElement)
      • addFormGroups

        protected void addFormGroups​(Form form,
                                     Element parentElement)
      • addDeploymentSchedule

        protected void addDeploymentSchedule​(Form form,
                                             Element parentElement)
      • importFormPortals

        protected void importFormPortals​(Form form,
                                         Element formElement,
                                         List<String> warnings)
      • importTemplateVersions

        protected int importTemplateVersions​(Form form,
                                             Element formElement,
                                             List<String> warnings)
      • importTemplateVersions

        protected int importTemplateVersions​(Form form,
                                             boolean importAttachments,
                                             boolean importMetadata,
                                             boolean importProperties,
                                             boolean importServices,
                                             boolean importFormDataConfiguration,
                                             boolean importCurrentVersionFlag,
                                             boolean importCategories,
                                             boolean importFormFunctions,
                                             Element formElement,
                                             List<String> warnings)
      • importTemplateVersionData

        protected void importTemplateVersionData​(Element formElement,
                                                 TemplateVersion templateVersion)
      • importOldSchemaConfigMaps

        protected void importOldSchemaConfigMaps​(SchemaSeed schemaSeed,
                                                 Element parentElement,
                                                 List<String> warnings)
      • importPropertyPrefillMaps

        protected void importPropertyPrefillMaps​(SchemaSeed schemaSeed,
                                                 Element parentElement,
                                                 List<String> warnings)
      • importXmlPrefillMaps

        protected void importXmlPrefillMaps​(SchemaSeed schemaSeed,
                                            Element parentElement,
                                            List<String> warnings)
      • importParameterPrefillMaps

        protected void importParameterPrefillMaps​(SchemaSeed schemaSeed,
                                                  Element parentElement,
                                                  List<String> warnings)
      • importSchemaExtractMaps

        protected void importSchemaExtractMaps​(SchemaSeed schemaSeed,
                                               Element parentElement,
                                               List<String> warnings)
      • importDeploymentPlan

        protected void importDeploymentPlan​(Form form,
                                            Element parentElement,
                                            List<String> warnings)
      • importServiceDefinition

        protected void importServiceDefinition​(Client client,
                                               ApplicationPackage application,
                                               boolean preserveExistingServices,
                                               boolean preserveDefaultServices,
                                               boolean preserveServiceConnections,
                                               Element serviceElement,
                                               List<String> warnings)
      • importApplicationPackages

        protected void importApplicationPackages​(Form form,
                                                 Element parentElement,
                                                 List<String> warnings)
      • writeApplicationPackageReference

        protected void writeApplicationPackageReference​(Element parentElement,
                                                        ApplicationPackage applicationPackage)
        Creates a child element for a reference to an application package
        Parameters:
        parentElement - the parent element (required)
        applicationPackage - the application package (required)
      • readClientCodeReference

        protected String readClientCodeReference​(Element element)
      • writeClientCodeReference

        protected void writeClientCodeReference​(Element parentElement,
                                                String clientCode)
      • getFormVersionKey

        @Deprecated
        protected String getFormVersionKey​(Form form,
                                           TemplateVersion version)
        Deprecated.
        use {@link this#getFormVersionKey(String, TemplateVersion) instead and explicitly pass the appropriate form code (generally either the archive form code during import or form.getClientFormCode() during export).
      • getFormVersionKey

        protected String getFormVersionKey​(String formCode,
                                           TemplateVersion version)
        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.
      • updateUnifiedAppFlagAndDoc

        protected void updateUnifiedAppFlagAndDoc​(TemplateVersion formTemplateVersion)