[MGNLDATA-178] Remove fixed repository name in ImportHandler Created: 21/May/13  Updated: 15/Mar/21  Resolved: 15/Mar/21

Status: Closed
Project: Magnolia Data Module (closed)
Component/s: None
Affects Version/s: 1.7.4
Fix Version/s: 1.7.x

Type: Improvement Priority: Neutral
Reporter: Lars Fischer Assignee: Unassigned
Resolution: Obsolete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File ImportHandler.patch    
Template:
Patch included:
Yes
Acceptance criteria:
Empty

 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.


Generated at Mon Feb 12 05:12:07 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.