Class BaseArchiveService

Direct Known Subclasses:
ApplicationPackageArchiveService, ClientArchiveService, ConfigurationServiceArchiveService, FormVersionArchiveService, GroupArchiveService, LibraryArchiveService, MetadataTagArchiveService, PortalArchiveService, RoleArchiveService, ScheduledServiceJobArchiveService, SecurityManagerArchiveService, ServiceArchiveService, ServiceConnectionArchiveService, TPacArchiveService

public abstract class BaseArchiveService extends CayenneService
Provides the base class for the set of archive services. Each service is responsible for exporting and importing a set of SFM entities (e.g. client or form and template versions).
  • Field Details

  • Constructor Details

    • BaseArchiveService

      public BaseArchiveService()
  • Method Details

    • 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
    • getImportOptionEnum

      public IJMImportOption getImportOptionEnum()
      Return a value from the import option enum, if this service has import options. Can be used to call IJMImportOption.defaultForImportAction(String)
      Returns:
      one of the import options
    • 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
    • readServiceReference

      protected ServiceDefinition readServiceReference(Element serviceElement, Client client)
      Read a service definition defined in a special service element
      Parameters:
      serviceElement - the element holding the service type and name (generally created by writeServiceReference(Element, String, ServiceDefinition)
      client - the target client of the import, if any
      Returns:
      the service element if found, or null otherwise
      Throws:
      ApplicationException - if a service was found, but the service type was different
    • getByteArrayForZipEntry

      protected byte[] getByteArrayForZipEntry(ZipEntry entry, ZipInputStream zis) throws IOException
      Throws:
      IOException
    • getByteArrayForElement

      protected byte[] getByteArrayForElement(Element element) throws UnsupportedEncodingException
      Throws:
      UnsupportedEncodingException
    • getElementForByteArray

      protected Element getElementForByteArray(byte[] byteData) throws UnsupportedEncodingException
      Throws:
      UnsupportedEncodingException
    • copyFromElementToEntity

      protected void copyFromElementToEntity(Element element, BaseEntity entity, List<String> warnings)
    • 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
    • addService

      protected void addService(ServiceDefinition serviceDefinition, ZipOutputStream zos, Element parentElement)
    • addServiceConnection

      protected void addServiceConnection(ZipOutputStream zos, ServiceConnection connection, Element parentElement)
    • addForm

      protected void addForm(ZipOutputStream zos, Form form, TemplateVersion version, Element parentElement) throws IOException
      Throws:
      IOException
    • addFormPortals

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

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

      protected void addDeploymentSchedule(Form form, Element parentElement)
    • addTemplateVersion

      protected void addTemplateVersion(Form form, TemplateVersion version, ZipOutputStream zos, Element parentElement) throws IOException
      Throws:
      IOException
    • addTemplateVersionData

      protected void addTemplateVersionData(TemplateVersion version, ZipOutputStream zos, Element parentElement) throws IOException
      Throws:
      IOException
    • addFormFunctions

      protected void addFormFunctions(TemplateVersion version, ZipOutputStream zos, Element parentElement)
    • addVersionAttachments

      protected void addVersionAttachments(Form form, TemplateVersion version, ZipOutputStream zos, Element parentElement)
    • addVersionMetadataValues

      protected void addVersionMetadataValues(Form form, TemplateVersion version, ZipOutputStream zos, Element parentElement)
    • addVersionPropertyValues

      protected void addVersionPropertyValues(Form form, TemplateVersion version, ZipOutputStream zos, Element parentElement)
    • addVersionCategories

      protected void addVersionCategories(TemplateVersion version, ZipOutputStream zos, Element parentElement)
    • addSchemaSeed

      protected void addSchemaSeed(Form form, TemplateVersion version, ZipOutputStream zos, Element parentElement) throws IOException
      Throws:
      IOException
    • addPropertyPrefillMaps

      protected void addPropertyPrefillMaps(Form form, SchemaSeed schemaSeed, ZipOutputStream zos, Element parentElement)
    • addXmlPrefillMaps

      protected void addXmlPrefillMaps(TemplateVersion version, SchemaSeed schemaSeed, ZipOutputStream zos, Element parentElement)
    • addParameterPrefillMaps

      protected void addParameterPrefillMaps(SchemaSeed schemaSeed, ZipOutputStream zos, Element parentElement)
    • addSchemaExtractMaps

      protected void addSchemaExtractMaps(SchemaSeed schemaSeed, ZipOutputStream zos, Element parentElement)
    • importFormGroups

      protected void importFormGroups(Form form, Element formElement, List<String> warnings) throws ParseException
      Throws:
      ParseException
    • 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)
    • importFormFunctions

      protected void importFormFunctions(TemplateVersion version, Element parentElement, List<String> warnings)
    • importVersionAttachments

      protected void importVersionAttachments(Form form, TemplateVersion version, Element parentElement, List<String> warnings)
    • importVersionMetadata

      protected void importVersionMetadata(Form form, TemplateVersion version, Element parentElement, List<String> warnings)
    • importVersionProperties

      protected void importVersionProperties(Form form, TemplateVersion version, Element parentElement, List<String> warnings)
    • importVersionCategories

      protected void importVersionCategories(Form form, TemplateVersion version, Element parentElement, List<String> warnings)
    • importSchemaSeed

      protected void importSchemaSeed(Form form, TemplateVersion version, Element formElement, Element parentElement, List<String> warnings)
    • 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)
    • importServiceConnection

      protected ServiceConnection importServiceConnection(Client client, ServiceDefinition serviceDefinition, boolean preserveServiceConnections, Element connectionElement, List<String> warnings)
    • importServiceParameters

      protected void importServiceParameters(ServiceDefinition serviceDefinition, Element parentElement, List<String> warnings)
    • importApplicationPackages

      protected void importApplicationPackages(ServiceDefinition serviceDefinition, Element parentElement, List<String> warnings)
    • importApplicationPackages

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

      protected ApplicationPackage readApplicationPackageReference(Element parentElement, Client targetClient)
    • 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)
    • getFormData

      protected BaseArchiveService.FormData getFormData(Element formElement, Form form, TemplateVersion version)
    • getFormVersionKey

      @Deprecated protected String getFormVersionKey(Form form, TemplateVersion version)
      Deprecated.
      use
      invalid @link
      {@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)
    • transform

      protected ArrayList<String> transform(String script)
      Transform a groovy script with JAVA EE code into equivalent Jakarta EE
      Parameters:
      script - string containing groovy script
      Returns:
      Jakarta equivalent script or null if no conversion is needed.
      Since:
      23.4.0
    • getTransformerServiceInstalled

      protected ServiceDefinition getTransformerServiceInstalled()
      Search and retrieve ServiceDefinition for transformer service
      Returns:
      Service definition or null if not found.
      Since:
      23.4.0