diff --git a/Toolbox Migration/src/com/bayer/edam/excelimport/CropAssetCopyTool.java b/Toolbox Migration/src/com/bayer/edam/excelimport/CropAssetCopyTool.java index 777aa3e..ed097d4 100644 --- a/Toolbox Migration/src/com/bayer/edam/excelimport/CropAssetCopyTool.java +++ b/Toolbox Migration/src/com/bayer/edam/excelimport/CropAssetCopyTool.java @@ -24,6 +24,10 @@ public class CropAssetCopyTool { private static Logger log = Logger.getLogger(CropAssetCopyTool.class); + + private static boolean dryRun = true; + + private static String toolboxExportFilePath = "C:\\Temp\\Migration CS - SQL Server\\export-2017-08-15.csv"; private static String assetPath = "D:\\Toolbox\\Assets"; private static String videoPath = "D:\\Toolbox\\Movies\\"; @@ -37,15 +41,17 @@ public class CropAssetCopyTool { private CsvParserSettings parserSettings = new CsvParserSettings(); private List inputRows; - public CropAssetCopyTool() throws ZipException, IOException { + public CropAssetCopyTool() throws IOException { readToolboxExport(); int lineNo = 0; + int noFile = 0; int noContent = 0; int wrongSize = 0; int video = 0; int videosExtracted = 0; int videosZipped = 0; + int zipCorrupt = 0; for (String[] line : inputRows) { lineNo++; @@ -63,43 +69,57 @@ public class CropAssetCopyTool { if (fileLength < 1) { noContent++; log.warn("Skipping '" + filePath + "' (AssetID " + assetId + "), no content"); + + // TODO update spreadsheet? } else if (expectedSize != fileLength) { File videoFile = new File(videoPath + assetId + ".zip"); if (videoFile.exists()) { - ZipFile zipFile = new ZipFile(videoFile.getAbsolutePath()); - @SuppressWarnings("rawtypes") - List fileList = zipFile.getFileHeaders(); - - if (fileList.size() == 1) { - log.info("Extracting " + videoFile.getAbsolutePath()); -// zipFile.extractAll(videoTargetPath); -// -// FileHeader header = (FileHeader) fileList.get(0); -// File srcFile = new File(videoTargetPath + "\\" + header.getFileName()); -// File destFile = new File(videoTargetPath + "\\" + targetName); -// log.info("AssetID " + assetId + ": Moving " + srcFile.getAbsolutePath() + " to " + destFile.getAbsolutePath()); -// -// FileUtils.moveFile(srcFile, destFile); + ZipFile zipFile; + try { + zipFile = new ZipFile(videoFile.getAbsolutePath()); - videosExtracted++; + @SuppressWarnings("rawtypes") + List fileList = zipFile.getFileHeaders(); + + if (fileList.size() == 1) { + log.info("Extracting " + videoFile.getAbsolutePath()); + + if (!dryRun) { + zipFile.extractAll(videoTargetPath); + + FileHeader header = (FileHeader) fileList.get(0); + File srcFile = new File(videoTargetPath + "\\" + header.getFileName()); + File destFile = new File(videoTargetPath + "\\" + targetName); + log.info("AssetID " + assetId + ": Moving " + srcFile.getAbsolutePath() + " to " + destFile.getAbsolutePath()); + + FileUtils.moveFile(srcFile, destFile); + } + + videosExtracted++; + } + else { + log.info("Copy " + videoFile.getAbsolutePath() + " as ZIP"); + if (!dryRun) + FileUtils.copyFileToDirectory(videoFile, videoTargetDir); + + // TODO update spreadsheet + + videosZipped++; + } + + video++; + + } catch (ZipException e) { + log.error("Skipping AssetID " + assetId + " - could not open ZIP file " + videoFile.getAbsolutePath()); } - else { - log.info("Copy " + videoFile.getAbsolutePath() + " as ZIP"); -// FileUtils.copyFileToDirectory(videoFile, videoTargetDir); - - // TODO update spreadsheet - - videosZipped++; - } - - video++; } else { wrongSize++; log.warn("Wrong file size for " + assetId + ": " + expectedSize + " != " + fileLength + " (" + targetName + ")"); + zipCorrupt++; } } else { @@ -108,17 +128,20 @@ public class CropAssetCopyTool { } } else { - log.error("'" + filePath + "' is not a file"); + log.error("'" + filePath + "' not found"); + noFile++; } } log.info("Lines processed: " + lineNo); + log.info("Skipped: File not found: " + noFile); log.info("Skipped: No content: " + noContent); log.info("Wrong size: " + wrongSize); log.info("Videos: " + video); log.info(" Extracted: " + videosExtracted); log.info(" Zipped: " + videosZipped); + log.info(" Corrupt: " + zipCorrupt); // copy files by ID