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