long pauseLong = filePause != null ? filePause.longValue() : 0;
File baseDir = new File(path);
if (baseDir.isDirectory() && baseDir.canRead()) {
File[] fileArray = baseDir.listFiles();
FastList files = FastList.newInstance();
for (int a=0; a<fileArray.length; a++){
if (fileArray[a].getName().toUpperCase().endsWith("XML")) {
files.add(fileArray[a]);
}
}
int passes=0;
int initialListSize = files.size();
int lastUnprocessedFilesCount = 0;
FastList unprocessedFiles = FastList.newInstance();
while (files.size()>0 &&
files.size() != lastUnprocessedFilesCount) {
lastUnprocessedFilesCount = files.size();
unprocessedFiles = FastList.newInstance();
Iterator filesItr = files.iterator();
while (filesItr.hasNext()) {
Map parseEntityXmlFileArgs = UtilMisc.toMap("mostlyInserts", mostlyInserts,
"createDummyFks", createDummyFks,
"checkDataOnly", checkDataOnly,
"maintainTimeStamps", maintainTimeStamps,
"txTimeout", txTimeout,
"userLogin", userLogin);
File f = (File) filesItr.next();
try {
URL furl = f.toURI().toURL();
parseEntityXmlFileArgs.put("url", furl);
Map outputMap = dispatcher.runSync("parseEntityXmlFile", parseEntityXmlFileArgs);
Long numberRead = (Long) outputMap.get("rowProcessed");
messages.add("Got " + numberRead.longValue() + " entities from " + f);
if (deleteFiles) {
messages.add("Deleting " + f);
f.delete();
}
} catch(Exception e) {
unprocessedFiles.add(f);
messages.add("Failed " + f + " adding to retry list for next pass");
}
// pause in between files
if (pauseLong > 0) {
Debug.log("Pausing for [" + pauseLong + "] seconds - " + UtilDateTime.nowTimestamp());
try {
Thread.sleep((pauseLong * 1000));
} catch(InterruptedException ie) {
Debug.log("Pause finished - " + UtilDateTime.nowTimestamp());
}
}
}
files = unprocessedFiles;
passes++;
messages.add("Pass " + passes + " complete");
Debug.logInfo("Pass " + passes + " complete", module);
}
lastUnprocessedFilesCount=unprocessedFiles.size();
messages.add("---------------------------------------");
messages.add("Succeeded: " + (initialListSize-lastUnprocessedFilesCount) + " of " + initialListSize);
messages.add("Failed: " + lastUnprocessedFilesCount + " of " + initialListSize);
messages.add("---------------------------------------");
messages.add("Failed Files:");
Iterator unprocessedFilesItr = unprocessedFiles.iterator();
while (unprocessedFilesItr.hasNext()) {
File file = (File) unprocessedFilesItr.next();
messages.add("" + file);
}
} else {