Interface ImportExportDelegate<R>

Type Parameters:
R - The resource config type, matching the owning ResourceTypeMeta
All Known Implementing Classes:
DefaultImportExportDelegate

public interface ImportExportDelegate<R>
Delegate that controls how a resource type participates in the gateway import/export system (.gwex files). Each ResourceTypeMeta returns a delegate from ResourceTypeMeta.getImportExportDelegate().

The delegate controls the data — parsing resources from the ZIP, what gets written during export, how resources are prepared and ordered during import, and what post-push work happens. The ImportExportManager controls the mechanics — conflict resolution (create vs modify), ChangeOperation construction, user choices (skip, rename, overwrite), collection remapping, and session management.

Full Lifecycle

  1. Upload: Manager walks the ZIP, identifies resource type paths, calls parseImport(List, ResourceReader) — the delegate decodes resources and returns ImportExportDelegate.ResourceEntrys. The manager uses these to build the interactive manifest (parseability, conflicts, dependencies).
  2. Export: Manager calls onExport(List, ResourceWriter) — the delegate writes resource files and additional data to the ZIP.
  3. Apply: Manager resolves user choices (skip, rename, remap), then calls prepareImport(List, ImportContext, ResourceReader) — the delegate can reorder, transform, or read additional data. The manager constructs ChangeOperations and pushes.
  4. Post-apply: Manager calls afterImport(List, ImportContext, ResourceReader) — the delegate performs post-push work (e.g., restoring persisted tag values).

Usage Options

  • Do nothing — getImportExportDelegate() returns DefaultImportExportDelegate by default. Standard resource file copy/push behavior.
  • Extend default + add extra data — Extend DefaultImportExportDelegate, call super, then write/read additional associated data (e.g., memory tag values).
  • Replace entirely — Implement ImportExportDelegate from scratch for resource types with completely custom storage, decoding, or ordering requirements.
  • Exclude from import/export — Return null from getImportExportDelegate() to skip this resource type entirely. It won't appear in the export tree and will be ignored during import parsing.
See Also:
  • Method Details

    • onExport

      void onExport(List<ImportExportDelegate.ResourceEntry<R>> resources, ResourceWriter writer) throws IOException
      Called during export with all resources of this type selected for export. The delegate writes all necessary data for these resources into the .gwex file.
      Parameters:
      resources - all resources of this type selected for export, with decoded configs and collection names
      writer - provides methods for writing resource files and additional data to the .gwex ZIP
      Throws:
      IOException
    • parseImport

      Parse resources of this type from the .gwex ZIP. Called at upload time (before any user interaction). The delegate owns all decoding — it reads the raw resource files from the ZIP via the reader and decodes them using whatever codec or logic it needs.

      The returned ImportExportDelegate.ResourceEntrys are used by the manager to build the interactive manifest (parseability status, conflict detection, dependency warnings). If a resource cannot be parsed, the delegate should not include it in the returned list — the manager will mark it as non-importable.

      Parameters:
      resourcePaths - the resource paths identified in the .gwex ZIP for this type, paired with their collection names
      reader - provides methods for reading resource files from the ZIP
      Returns:
      the parsed resource entries with decoded configs
      Throws:
      IOException
    • prepareImport

      Called during import before the manager pushes resources. The delegate can reorder resources, read additional data from the .gwex, and transform resource data.

      By the time this method is called, the manager has already applied user choices: skipped resources are excluded and renamed resources have their new name. Each resource still carries the collection it was exported from — the manager rewrites collections on the returned list, so a delegate cannot see or influence where a remapped resource lands.

      The returned list determines the order resources are pushed. The manager handles constructing the correct ChangeOperation (create vs modify) for each resource based on current gateway state.

      Parameters:
      resources - all resources of this type being imported, with decoded configs and their source collection names
      context - metadata from the .gwex's exportinfo.json
      reader - provides methods for reading resource files and additional data from the .gwex ZIP
      Returns:
      the (possibly reordered or modified) list of resources to push
      Throws:
      IOException
    • afterImport

      default void afterImport(List<ImportExportDelegate.ResourceEntry<R>> resources, ImportContext context, ResourceReader reader) throws IOException
      Called after the manager has pushed all resources of this type and the CompletableFuture has completed (subsystem listeners fired, resources initialized). Use this for post-push work that requires the resources to be live.

      The default implementation is a no-op.

      Parameters:
      resources - the resources that were imported (same list returned from prepareImport(List, ImportContext, ResourceReader))
      context - metadata from the .gwex's exportinfo.json
      reader - provides methods for reading resource files and additional data from the .gwex ZIP
      Throws:
      IOException