From ec442cbb4935030ad446fc4fe42eb297ef3e1455 Mon Sep 17 00:00:00 2001 From: Sweidan Omar Date: Tue, 25 Jan 2022 14:41:45 +0000 Subject: [PATCH] #311 git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C32888 --- .../jobs/steps/MoveJpegToIsilonStep.java | 72 ++++++++++++------- .../server/steps/MoveJpegToIsilonStep.java | 72 ++++++++++++------- 2 files changed, 94 insertions(+), 50 deletions(-) diff --git a/server/-product/production/LOCAL/jobs/steps/MoveJpegToIsilonStep.java b/server/-product/production/LOCAL/jobs/steps/MoveJpegToIsilonStep.java index 48580358..8f4aa3d7 100644 --- a/server/-product/production/LOCAL/jobs/steps/MoveJpegToIsilonStep.java +++ b/server/-product/production/LOCAL/jobs/steps/MoveJpegToIsilonStep.java @@ -1,5 +1,6 @@ package user.jobengine.server.steps; +import java.io.File; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.FileVisitor; @@ -41,42 +42,63 @@ public class MoveJpegToIsilonStep extends JobStep { sourceStoreUri.setProtocol(RemoteStoreProtocol.valueOf(sourceProtocol)); FileVisitor visitor = new SimpleFileVisitor() { - boolean isFolderDateBeforeNow = false; String fileNamePattern = "yyyymmdd"; SimpleDateFormat dateFormatter = new SimpleDateFormat(fileNamePattern); Date currentDate = new Date(); // initializes with the current date Date dateFromFileName; + boolean isRootFolder = true; @Override - public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { - try { - if (Files.isDirectory(path)) { - dateFromFileName = dateFormatter.parse(path.toString().substring(0, 8)); + public FileVisitResult preVisitDirectory(Path folder, BasicFileAttributes attrs) throws IOException { + FileVisitResult result = null; + boolean isDateParseable = true; + + if (folder != null) { + String splitter = File.separator.replace("\\", "\\\\"); + String[] parentFolderSegments = folder.toString().split(splitter); + + try { + dateFromFileName = dateFormatter.parse(parentFolderSegments[parentFolderSegments.length - 1]); + if (!(dateFromFileName.compareTo(currentDate) > 0)) { - isFolderDateBeforeNow = false; - return FileVisitResult.SKIP_SUBTREE; + if (isRootFolder) { + result = FileVisitResult.CONTINUE; + isRootFolder = false; + } else { + result = FileVisitResult.SKIP_SUBTREE; + } } else { - isFolderDateBeforeNow = true; - return FileVisitResult.CONTINUE; + result = FileVisitResult.CONTINUE; } - } else { - if (isFolderDateBeforeNow) { - String fileExtension = FilenameUtils.getExtension(path.toString()); - - if (fileExtension.equals("jpg") || fileExtension.equals("jpeg")) { - logger.info("path: {}", path.toString()); - foundItems.add(path.toString()); - StoreUri targetStoreUri = getManager() - .createStoreUri(RemoteStoreProtocol.valueOf(targetProtocol), targetUri); - targetStoreUri.setProtocol(RemoteStoreProtocol.valueOf(targetProtocol)); - targetStoreUri.setRootPath(targetFolder); - - copyFile(path, Paths.get(targetStoreUri.getRootPath())); - } + } catch (ParseException e) { + isDateParseable = false; + logger.info("Illegal argument to parse as date: {}", + parentFolderSegments[parentFolderSegments.length - 1]); + } finally { + isRootFolder = false; + if (!isDateParseable) { + result = FileVisitResult.CONTINUE; } } - } catch (ParseException e) { - logger.info("Illegal argument to parse as date: {}", path.getFileName().toString().substring(0, 8)); + } + return result; + } + + @Override + public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { + logger.info("path: {}", path.toString()); + try { + String fileExtension = FilenameUtils.getExtension(path.toString()); + + if (fileExtension.equals("jpg") || fileExtension.equals("jpeg")) { + foundItems.add(path.toString()); + StoreUri targetStoreUri = getManager() + .createStoreUri(RemoteStoreProtocol.valueOf(targetProtocol), targetUri); + targetStoreUri.setProtocol(RemoteStoreProtocol.valueOf(targetProtocol)); + targetStoreUri.setRootPath(targetFolder); + + copyFile(path, Paths.get(targetStoreUri.getRootPath())); + } } catch (Exception e) { logger.info("Exception: {}", e.getStackTrace()); } diff --git a/server/user.jobengine.executors/src/user/jobengine/server/steps/MoveJpegToIsilonStep.java b/server/user.jobengine.executors/src/user/jobengine/server/steps/MoveJpegToIsilonStep.java index 48580358..8f4aa3d7 100644 --- a/server/user.jobengine.executors/src/user/jobengine/server/steps/MoveJpegToIsilonStep.java +++ b/server/user.jobengine.executors/src/user/jobengine/server/steps/MoveJpegToIsilonStep.java @@ -1,5 +1,6 @@ package user.jobengine.server.steps; +import java.io.File; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.FileVisitor; @@ -41,42 +42,63 @@ public class MoveJpegToIsilonStep extends JobStep { sourceStoreUri.setProtocol(RemoteStoreProtocol.valueOf(sourceProtocol)); FileVisitor visitor = new SimpleFileVisitor() { - boolean isFolderDateBeforeNow = false; String fileNamePattern = "yyyymmdd"; SimpleDateFormat dateFormatter = new SimpleDateFormat(fileNamePattern); Date currentDate = new Date(); // initializes with the current date Date dateFromFileName; + boolean isRootFolder = true; @Override - public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { - try { - if (Files.isDirectory(path)) { - dateFromFileName = dateFormatter.parse(path.toString().substring(0, 8)); + public FileVisitResult preVisitDirectory(Path folder, BasicFileAttributes attrs) throws IOException { + FileVisitResult result = null; + boolean isDateParseable = true; + + if (folder != null) { + String splitter = File.separator.replace("\\", "\\\\"); + String[] parentFolderSegments = folder.toString().split(splitter); + + try { + dateFromFileName = dateFormatter.parse(parentFolderSegments[parentFolderSegments.length - 1]); + if (!(dateFromFileName.compareTo(currentDate) > 0)) { - isFolderDateBeforeNow = false; - return FileVisitResult.SKIP_SUBTREE; + if (isRootFolder) { + result = FileVisitResult.CONTINUE; + isRootFolder = false; + } else { + result = FileVisitResult.SKIP_SUBTREE; + } } else { - isFolderDateBeforeNow = true; - return FileVisitResult.CONTINUE; + result = FileVisitResult.CONTINUE; } - } else { - if (isFolderDateBeforeNow) { - String fileExtension = FilenameUtils.getExtension(path.toString()); - - if (fileExtension.equals("jpg") || fileExtension.equals("jpeg")) { - logger.info("path: {}", path.toString()); - foundItems.add(path.toString()); - StoreUri targetStoreUri = getManager() - .createStoreUri(RemoteStoreProtocol.valueOf(targetProtocol), targetUri); - targetStoreUri.setProtocol(RemoteStoreProtocol.valueOf(targetProtocol)); - targetStoreUri.setRootPath(targetFolder); - - copyFile(path, Paths.get(targetStoreUri.getRootPath())); - } + } catch (ParseException e) { + isDateParseable = false; + logger.info("Illegal argument to parse as date: {}", + parentFolderSegments[parentFolderSegments.length - 1]); + } finally { + isRootFolder = false; + if (!isDateParseable) { + result = FileVisitResult.CONTINUE; } } - } catch (ParseException e) { - logger.info("Illegal argument to parse as date: {}", path.getFileName().toString().substring(0, 8)); + } + return result; + } + + @Override + public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { + logger.info("path: {}", path.toString()); + try { + String fileExtension = FilenameUtils.getExtension(path.toString()); + + if (fileExtension.equals("jpg") || fileExtension.equals("jpeg")) { + foundItems.add(path.toString()); + StoreUri targetStoreUri = getManager() + .createStoreUri(RemoteStoreProtocol.valueOf(targetProtocol), targetUri); + targetStoreUri.setProtocol(RemoteStoreProtocol.valueOf(targetProtocol)); + targetStoreUri.setRootPath(targetFolder); + + copyFile(path, Paths.get(targetStoreUri.getRootPath())); + } } catch (Exception e) { logger.info("Exception: {}", e.getStackTrace()); } -- 2.54.0