Uploaded image for project: 'Magnolia Data Module (closed)'
  1. Magnolia Data Module (closed)
  2. MGNLDATA-178

Remove fixed repository name in ImportHandler

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Obsolete
    • Neutral
    • 1.7.x
    • 1.7.4
    • None
    • Yes

    Description

      In it's current version the ImportHandler standard implementation is limited to the data repository (otherwise you have to override the backup method) if you use the backup mechanism because the backup method uses a fixed name for the repository:

      HierarchyManager hm = MgnlContext.getSystemContext().getHierarchyManager(DataModule.getRepository());

      This should be like the rest of the code:

      HierarchyManager hm = MgnlContext.getSystemContext().getHierarchyManager(repository);

      It's even possible to remove the deprecated HierarchyManager in the backup method:

      Replace

      DataTransporter.executeExport(stream, false, false, hm.getWorkspace().getSession(), target.getTargetPath(), repository, ".gz");

      with

      DataTransporter.executeExport(stream, false, false, MgnlContext.getJCRSession(repository), target.getTargetPath(), repository, ".gz");

      and catch the exception.

      The full method could be like this:

      protected void backup(ImportTarget target) throws ImportException {
      File backupDir = new File(Path.getAppRootDir(), "backup");
      backupDir.mkdir();
      backupFile = new File(backupDir, target.name + "-" + FastDateFormat.getInstance("yyyy-MM-dd_hh-mm-ss").format(System.currentTimeMillis()) + ".gz");
      OutputStream stream;
      try

      { stream = new FileOutputStream(backupFile); }

      catch (FileNotFoundException e)

      { throw new ImportException("can't create backup file [" + backupFile + "] "); }

      // export data
      try

      { DataTransporter.executeExport(stream, false, false, MgnlContext.getJCRSession(repository), target.getTargetPath(), repository, ".gz"); }

      catch (RepositoryException e)

      { throw new ImportException("can't get JCR session for repository " + repository, e); }

      catch (IOException e)

      { throw new ImportException("can't export data for backuping", e); }

      IOUtils.closeQuietly(stream);
      }

      The use case is when you extend an ImportHandler and use a target workspace other than data (e. g. DMS). This currently works only if you also overwrite the backup method.

      Checklists

        Acceptance criteria

        Attachments

          Activity

            People

              Unassigned Unassigned
              lfischer Lars Fischer
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: