Skip to content
Snippets Groups Projects
Commit 54e1cee8 authored by felmer's avatar felmer
Browse files

Code Review: createMoveAndProcess() refactored to improve readability

SVN: 1430
parent 1504073b
No related branches found
No related tags found
No related merge requests found
...@@ -96,16 +96,39 @@ public class MonitorStarter ...@@ -96,16 +96,39 @@ public class MonitorStarter
private IPathHandler createIncomingMovingPathHandler(String sourceHost, File manualInterventionDir, private IPathHandler createIncomingMovingPathHandler(String sourceHost, File manualInterventionDir,
RegexFileFilter manualInterventionFilter, RegexFileFilter cleansingFilter) RegexFileFilter manualInterventionFilter, RegexFileFilter cleansingFilter)
{ {
IPathHandler moveFromIncoming = createPathMoverToLocal(sourceHost, inProgressDir);
IPathHandler processMoved = IPathHandler processMoved =
createProcessMovedFile(readyToMoveDir, tempDir, parameters.tryGetExtraCopyStore(), factory); createProcessMovedFile(readyToMoveDir, tempDir, parameters.tryGetExtraCopyStore(), factory);
IPathHandler moveAndProcess = createMoveAndProcess(moveFromIncoming, inProgressDir, processMoved); IPathHandler moveAndProcess = createMoveAndProcess(sourceHost, processMoved);
IPathHandler manualInterventionMover = createPathMoverToLocal(sourceHost, manualInterventionDir); IPathHandler manualInterventionMover = createPathMoverToLocal(sourceHost, manualInterventionDir);
CleansingPathHandlerDecorator cleansingOrMover = CleansingPathHandlerDecorator cleansingOrMover =
new CleansingPathHandlerDecorator(cleansingFilter, moveAndProcess); new CleansingPathHandlerDecorator(cleansingFilter, moveAndProcess);
return new GatePathHandlerDecorator(manualInterventionFilter, cleansingOrMover, manualInterventionMover); return new GatePathHandlerDecorator(manualInterventionFilter, cleansingOrMover, manualInterventionMover);
} }
private IPathHandler createMoveAndProcess(String sourceHost, final IPathHandler processMoved)
{
final IPathHandler moveFromIncoming = createPathMoverToLocal(sourceHost, inProgressDir);
IPathHandler moveAndProcess = new IPathHandler()
{
public boolean handle(File path)
{
boolean ok = moveFromIncoming.handle(path);
if (ok)
{
// create path in destination directory
File movedFile = new File(inProgressDir, path.getName());
File markFile = new File(inProgressDir, Constants.IS_FINISHED_PREFIX + path.getName());
assert movedFile.exists();
assert markFile.exists();
markFile.delete(); // process even if mark file could not be deleted
ok = processMoved.handle(movedFile);
}
return ok;
}
};
return moveAndProcess;
}
private static IPathHandler createProcessMovedFile(File destDirectory, File tempDir, private static IPathHandler createProcessMovedFile(File destDirectory, File tempDir,
FileStore extraCopyStoreOrNull, IFileSysOperationsFactory factory) FileStore extraCopyStoreOrNull, IFileSysOperationsFactory factory)
{ {
...@@ -159,29 +182,6 @@ public class MonitorStarter ...@@ -159,29 +182,6 @@ public class MonitorStarter
}; };
} }
private static IPathHandler createMoveAndProcess(final IPathHandler moveFromIncoming, final File destinationDir,
final IPathHandler processMovedFile)
{
return new IPathHandler()
{
public boolean handle(File path)
{
boolean ok = moveFromIncoming.handle(path);
if (ok)
{
// create path in destination directory
File movedFile = new File(destinationDir, path.getName());
File markFile = new File(destinationDir, Constants.IS_FINISHED_PREFIX + path.getName());
assert movedFile.exists();
assert markFile.exists();
markFile.delete(); // process even if mark file could not be deleted
ok = processMovedFile.handle(movedFile);
}
return ok;
}
};
}
private IPathHandler createPathMoverToLocal(String sourceHost, final File localDestDir) private IPathHandler createPathMoverToLocal(String sourceHost, final File localDestDir)
{ {
if (parameters.getTreatIncomingAsRemote()) if (parameters.getTreatIncomingAsRemote())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment