Bugfix for --002+ filenames

This commit is contained in:
gexce
2017-09-01 11:43:27 +02:00
parent 5e8acbf9f3
commit dad2a73bfe
@@ -38,18 +38,18 @@ public class CropAssetCopyTool {
private static Logger log = Logger.getLogger(CropAssetCopyTool.class);
private static boolean dryRun = true;
private static boolean dryRun = false;
private static int skipLines = 0;
private static String toolboxExportFilePath = "C:\\Temp\\Migration CS - SQL Server\\export-2017-08-15.csv";
private static String toolboxExportUpdateFilePath = "C:\\Temp\\Migration CS - SQL Server\\export-2017-08-15-update.csv";
private static String logfilePath = "C:\\Temp\\Migration CS - SQL Server\\export-2017-08-15-update.copytool.log";
private static String assetPath = "D:\\Toolbox\\Assets";
private static String videoPath = "D:\\Toolbox\\Movies\\";
private static String toolboxExportFilePath = "C:\\Temp\\Migration CS - PhotoGallery\\export - 2017-08-28 - logos and tags not included in first migration.csv";
private static String toolboxExportUpdateFilePath = "C:\\Temp\\Migration CS - PhotoGallery\\export - 2017-08-28 - logos and tags not included in first migration-update.csv";
private static String logfilePath = "C:\\Temp\\Migration CS - PhotoGallery\\export - 2017-08-28 - logos and tags not included in first migration.copytool.log";
private static String assetPath = "D:\\ToolboxLogosAndTags";
// private static String videoPath = "D:\\Toolbox\\Movies\\";
private static File targetDir = new File("D:\\UploadAssets");
private static String videoTargetPath = "D:\\UploadVideos";
private static File targetDir = new File("D:\\ToolboxLogosAndTags-renamed");
// private static String videoTargetPath = "D:\\UploadVideos";
private CsvParserSettings parserSettings = new CsvParserSettings();
@@ -93,7 +93,7 @@ public class CropAssetCopyTool {
log.debug("Processing AssetID " + assetId + ", line " + lineNo);
String targetName = line[1];
long expectedSize = Long.parseLong(line[15]);
// long expectedSize = Long.parseLong(line[15]);
String filePath = assetPath + "\\" + assetId;
File file = new File(filePath);
@@ -105,61 +105,61 @@ public class CropAssetCopyTool {
log.warn("Line " + lineNo + ", AssetID " + assetId + " - Skipping file '" + filePath + "', no content. Removing file from list.");
linesForDeletion.add(line);
}
else if (expectedSize != fileLength) {
File videoFile = new File(videoPath + assetId + ".zip");
if (videoFile.exists()) {
ZipFile zipFile;
try {
zipFile = new ZipFile(videoFile.getAbsolutePath());
@SuppressWarnings("unchecked")
List<FileHeader> fileList = (List<FileHeader>) zipFile.getFileHeaders();
FileHeader header = null;
if (fileList.size() == 1) {
header = fileList.get(0);
}
else {
for (FileHeader hdr : fileList) {
if (hdr.getFileName().indexOf('/') < 0) {
header = hdr;
break;
}
}
}
log.debug("Extracting " + videoFile.getAbsolutePath());
if (!dryRun) {
zipFile.extractFile(header, videoTargetPath);
File srcFile = new File(videoTargetPath + "\\" + header.getFileName());
File destFile = new File(videoTargetPath + "\\" + targetName);
log.info("Line " + lineNo + ", AssetID " + assetId + ": Moving " + srcFile.getAbsolutePath() + " to " + destFile.getAbsolutePath());
try {
FileUtils.moveFile(srcFile, destFile);
}
catch (IOException ioe) {
log.error("Line " + lineNo + ", AssetID " + assetId + " - IOException: '" + ioe.getMessage() + "'");
ioe.printStackTrace();
}
}
video++;
} catch (ZipException e) {
zipCorrupt++;
log.error("Skipping line " + lineNo + ", AssetID " + assetId + " - could not open ZIP file " + videoFile.getAbsolutePath());
linesForDeletion.add(line);
}
}
else {
wrongSize++;
log.debug("Wrong file size for " + assetId + ": expected " + expectedSize + ", found " + fileLength + " (" + targetName + ")");
}
}
// else if (expectedSize != fileLength) {
//
// File videoFile = new File(videoPath + assetId + ".zip");
// if (videoFile.exists()) {
//
// ZipFile zipFile;
// try {
// zipFile = new ZipFile(videoFile.getAbsolutePath());
//
// @SuppressWarnings("unchecked")
// List<FileHeader> fileList = (List<FileHeader>) zipFile.getFileHeaders();
//
// FileHeader header = null;
//
// if (fileList.size() == 1) {
// header = fileList.get(0);
// }
// else {
// for (FileHeader hdr : fileList) {
// if (hdr.getFileName().indexOf('/') < 0) {
// header = hdr;
// break;
// }
// }
// }
//
// log.debug("Extracting " + videoFile.getAbsolutePath());
// if (!dryRun) {
// zipFile.extractFile(header, videoTargetPath);
// File srcFile = new File(videoTargetPath + "\\" + header.getFileName());
// File destFile = new File(videoTargetPath + "\\" + targetName);
// log.info("Line " + lineNo + ", AssetID " + assetId + ": Moving " + srcFile.getAbsolutePath() + " to " + destFile.getAbsolutePath());
//
// try {
// FileUtils.moveFile(srcFile, destFile);
// }
// catch (IOException ioe) {
// log.error("Line " + lineNo + ", AssetID " + assetId + " - IOException: '" + ioe.getMessage() + "'");
// ioe.printStackTrace();
// }
// }
//
// video++;
//
// } catch (ZipException e) {
// zipCorrupt++;
// log.error("Skipping line " + lineNo + ", AssetID " + assetId + " - could not open ZIP file " + videoFile.getAbsolutePath());
// linesForDeletion.add(line);
// }
// }
// else {
// wrongSize++;
// log.debug("Wrong file size for " + assetId + ": expected " + expectedSize + ", found " + fileLength + " (" + targetName + ")");
// }
// }
else {
File targetFile = new File(targetDir + "\\" + targetName);
@@ -168,8 +168,8 @@ public class CropAssetCopyTool {
String oldName = FilenameUtils.removeExtension(targetFile.getName());
String extension = FilenameUtils.getExtension(targetFile.getName());
String newName = oldName + "--002." + extension;
if (oldName.length() > 5 && oldName.charAt(oldName.length() - 4) == '-'
&& oldName.charAt(oldName.length() - 3) == '-'
if (oldName.length() > 5 && oldName.charAt(oldName.length() - 5) == '-'
&& oldName.charAt(oldName.length() - 4) == '-'
&& StringUtils.isNumeric(oldName.substring(oldName.length() - 3))) {
int num = Integer.parseInt(oldName.substring(oldName.length() - 3));
num++;