}
if (dbconnected)
{
JDBInterfaceLog il = new JDBInterfaceLog(getHostID(), getSessionID());
JeMail mail = new JeMail(getHostID(), getSessionID());
JDBInterface inter = new JDBInterface(getHostID(), getSessionID());
IncommingMaterialDefinition imd = new IncommingMaterialDefinition(getHostID(), getSessionID());
IncommingProcessOrderStatusChange iposc = new IncommingProcessOrderStatusChange(getHostID(), getSessionID());
IncommingProductionDeclarationConfirmation ipd = new IncommingProductionDeclarationConfirmation(getHostID(), getSessionID());
IncommingProcessOrder ipo = new IncommingProcessOrder(getHostID(), getSessionID());
IncommingPalletStatusChange ipsc = new IncommingPalletStatusChange(getHostID(), getSessionID());
IncommingBatchStatusChange bsc = new IncommingBatchStatusChange(getHostID(), getSessionID());
IncommingInspectionResult iirslt = new IncommingInspectionResult(getHostID(), getSessionID());
IncommingDespatchConfirmation idc = new IncommingDespatchConfirmation(getHostID(), getSessionID());
IncommingQMInspectionRequest iireq = new IncommingQMInspectionRequest(getHostID(), getSessionID());
GenericMessageHeader gmh = new GenericMessageHeader();
LinkedList<String> filenames = new LinkedList<String>();
BasicFileAttributes attrs;
while (true)
{
com.commander4j.util.JWait.milliSec(100);
if (allDone)
{
if (dbconnected)
{
Common.hostList.getHost(hostID).disconnect(getSessionID());
}
return;
}
if (InboundMessageCollectionThread.recoveringFiles == false)
{
dir = new File(inputPath);
chld = dir.listFiles((FileFilter) FileFileFilter.FILE);
if (chld == null)
{
allDone = true;
} else
{
Arrays.sort(chld, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
filenames.clear();
for (int i = 0; (i < chld.length) & (i < maxfiles); i++)
{
fileName = chld[i].getName();
try
{
attrs = Files.readAttributes(chld[i].getAbsoluteFile().toPath(), BasicFileAttributes.class);
if (attrs.size() > 0)
{
if (fileName.indexOf(".xml") > 0)
{
filenames.addFirst(fileName);
com.commander4j.util.JWait.milliSec(50);
}
} else
{
try
{
chld[i].delete();
}
catch (Exception ex)
{
}
}
} catch (IOException e)
{
}
}
if (filenames.size() > 0)
{
logger.debug("Begin processing " + String.valueOf(filenames.size()) + " files.");
for (int i = filenames.size() - 1; i >= 0; i--)
{
if (allDone)
{
if (dbconnected)
{
Common.hostList.getHost(hostID).disconnect(getSessionID());
}
return;
}
fromFile = filenames.get(i);
try
{
logger.debug("<--- START OF PROCESSING " + fromFile + " ---->");
logger.debug("Reading message header : " + inputPath + fromFile);
if (gmh.readAddressInfo(inputPath + fromFile, getSessionID()) == true)
{
messageProcessedOK = true;
errorMessage = "";
if (gmh.getInterfaceType().length() == 0)
{
messageProcessedOK = false;
errorMessage = "Unrecognised Commander4j XML message format in file " + fromFile;
logger.debug(errorMessage);
String datetime = "";
datetime = JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime());
gmh.setMessageDate(datetime);
gmh.setInterfaceDirection("Unknown");
gmh.setMessageInformation(fromFile);
gmh.setInterfaceType("Unknown");
gmh.setMessageRef("Unknown");
} else
{
if (gmh.getInterfaceDirection().equals("Input") == false)
{
messageProcessedOK = false;
errorMessage = "Inbound message ignored - Interface Direction = " + gmh.getInterfaceDirection();
} else
{
String interfaceType = gmh.getInterfaceType();
logger.debug("Processing " + interfaceType + " started.");
if (interfaceType.equals("Despatch Confirmation") == true)
{
messageProcessedOK = idc.processMessage(gmh);
errorMessage = idc.getErrorMessage();
}
if (interfaceType.equals("Material Definition") == true)
{
messageProcessedOK = imd.processMessage(gmh);
errorMessage = imd.getErrorMessage();
}
if (interfaceType.equals("Process Order") == true)
{
messageProcessedOK = ipo.processMessage(gmh);
errorMessage = ipo.getErrorMessage();
}
if (interfaceType.equals("Pallet Status Change") == true)
{
messageProcessedOK = ipsc.processMessage(gmh);
errorMessage = ipsc.getErrorMessage();
}
if (interfaceType.equals("Batch Status Change") == true)
{
messageProcessedOK = bsc.processMessage(gmh);
errorMessage = bsc.getErrorMessage();
}
if (interfaceType.equals("Process Order Status Change") == true)
{
messageProcessedOK = iposc.processMessage(gmh);
errorMessage = iposc.getErrorMessage();
}
if (interfaceType.equals("Production Declaration") == true)
{
messageProcessedOK = ipd.processMessage(gmh);
errorMessage = ipd.getErrorMessage();
}
if (interfaceType.equals("QM Inspection Request") == true)
{
messageProcessedOK = iireq.processMessage(gmh);
errorMessage = iireq.getErrorMessage();
}
if (interfaceType.equals("QM Inspection Result") == true)
{
messageProcessedOK = iirslt.processMessage(gmh);
errorMessage = iirslt.getErrorMessage();
}
GenericMessageHeader.updateStats("Input", interfaceType, messageProcessedOK.toString());
logger.debug("Processing " + interfaceType + " finished.");
}
}
logger.debug(" === RESULT " + messageProcessedOK.toString() + " ===");
if (messageProcessedOK)
{
il.write(gmh, GenericMessageHeader.msgStatusSuccess, "Processed OK", "DB Update", fromFile);
reader.deleteFile(backupPath + gmh.getInterfaceType() + File.separator + fromFile);
reader.move_FileToDirectory(inputPath + fromFile, backupPath + gmh.getInterfaceType(), true);
} else
{
il.write(gmh, GenericMessageHeader.msgStatusError, errorMessage, "DB Update", fromFile);
if (inter.getInterfaceProperties(gmh.getInterfaceType(), "Input") == true)
{
if (inter.getEmailError() == true)
{
String emailaddresses = inter.getEmailAddresses();
StringConverter stringConverter = new StringConverter();
ArrayConverter arrayConverter = new ArrayConverter(String[].class, stringConverter);
arrayConverter.setDelimiter(';');
arrayConverter.setAllowedChars(new char[]
{ '@', '_' });
String[] emailList = (String[]) arrayConverter.convert(String[].class, emailaddresses);
if (emailList.length > 0)
{
String siteName = Common.hostList.getHost(getHostID()).getSiteDescription();
String attachedFilename = Common.base_dir + java.io.File.separator + inputPath + fromFile;
logger.debug("Attaching file " + Common.base_dir + java.io.File.separator + inputPath + fromFile);
mail.postMail(emailList, "Error Processing Incoming " + gmh.getInterfaceType() + " for [" + siteName + "] on " + JUtility.getClientName(), errorMessage, fromFile, attachedFilename);
com.commander4j.util.JWait.milliSec(2000);
}
}
}