Class AbstractExporterPlugin

    • Constructor Detail

      • AbstractExporterPlugin

        protected AbstractExporterPlugin()
        Create a new AbstractExporterPlugin.
    • Method Detail

      • getMainType

        public Plugin.MainType getMainType()
        Description copied from interface: Plugin
        Get the type of the plugin. This method must always return the same value.
        Specified by:
        getMainType in interface Plugin
        Returns:
        MainType.EXPORT
      • run

        public void run​(Request request,
                        Response response,
                        ProgressReporter progress)
        Checks the SAVE_AS parameter for the path to save the exported data. If the file doesn't exists it is created. If the file exists the OVERWRITE parameter is checked if overwriting is ok. Files marked for deletion will always be overwritten. If no path has been specified an error response is sent.

        Then, the subclass is called to generate the export. The following methods are called:

        1. begin(DbControl)
        2. performExport(ExportOutputStream, ProgressReporter)
        3. end(boolean) (after the DbControl has been committed)
        4. getSuccessMessage() (only if no error ocurred)
        Specified by:
        run in interface Plugin
        Parameters:
        request - Request object with the command and parameters
        response - Response object in for the plugin to response through
        progress - A ProgressReporter where the plugin can report its progess, can be null
      • begin

        protected void begin​(DbControl dc)
        Called just before the export starts. A subclass may override this method if it needs to initialise some resources.
        Parameters:
        dc - The DbControl that is used to write to the database. A subclass may use this read from the database as well
        See Also:
        end(boolean)
      • getSaveTo

        protected File getSaveTo()
        Get the file object that the current export is writing to. This method may return a file object that already exists in the database, a new file that is saved when the transaction is committed or null if the export is a 'download immediately' export.
        Returns:
        A file object or null
        Since:
        2.7
      • end

        protected void end​(boolean success)
        Called just after everything has been committed to the database, or immediately after an error has ocurred. A subclass should clean up any resources aquired in the begin(DbControl) method here.
        Parameters:
        success - TRUE if the file was parsed successfully, FALSE otherwise
        See Also:
        begin(DbControl)
      • getSuccessMessage

        protected String getSuccessMessage()
        Called if the export was successful to let the subclass generate a simple message that is sent back to the core and user interface. An example message might by: 178 reporters exported successfully. The default implementation always return null.
      • getSaveAsParameter

        protected PluginParameter<String> getSaveAsParameter​(String label,
                                                             String description,
                                                             String defaultValue,
                                                             boolean required)
        Get a plugin parameter that asks for the path to a file where the exported data should be saved. If no path is specified by the user the data will be downloaded immediately.
        Parameters:
        label - The parameter label, or null to use the default (Save as)
        description - The parameter description, or null to use the default (The path to the file where the exported data should be placed. Leave empty to download immediately.)
        defaultValue - A default filename, or null to not use any default
        required - If the parameter is required or optional
      • getSaveAsPath

        protected Path getSaveAsPath​(DbControl dc)
        Get the configured path where the exported data should be saved.
        Parameters:
        dc - A DbControl which is needed to find the currently logged in user if the path starts with '~/' = Home directory of logged in user
        Returns:
        A path or null if no path has been specified
      • getOverwriteParameter

        protected PluginParameter<Boolean> getOverwriteParameter​(String label,
                                                                 String description)
        Get a plugin parameter that asks if existing files can be overwritten or not.
        Parameters:
        label - The parameter label, or null to use the default (Overwrite)
        description - The parameter description, or null to use the default (If it is allowed to overwrite an existing file or not.)
      • getOverwrite

        public boolean getOverwrite()
        Get the configured value for the overwrite parameter.
        Returns:
        A boolean, if no values has been specified false is returned
        See Also:
        getOverwriteParameter(String, String)
      • pathCanBeUsed

        protected boolean pathCanBeUsed​(String strPath,
                                        boolean overwrite)
        See if file path already exists and if it's allowed to overwrite it.
        Parameters:
        strPath - The file path to be checked.
        overwrite - TRUE If it is allowed to overwrite the file, FALSE otherwise.
        Returns:
        FALSE If the file path exists and isn't allowed to be overwritten or TRUE otherwise.