<%
for (int i = 0; i < fileCount; i++) {
try {
Properties sql = new Properties();
sql.load(new FileInputStream(sqlFiles[i]));
String testCat = sql.getProperty("Category");
String testName = sql.getProperty("Name");
files.put(testCat + testName, sql);
}
catch (Exception e) {} // don't care if we couldn't open one entry
}
Properties sql = null;
Enumeration keys = files.keys();
String curCat = "";
Vector sorted = new Vector();
while (keys.hasMoreElements()) {
sorted.add(keys.nextElement());
}
sortedkeys = sorted.toArray();
java.util.Arrays.sort(sortedkeys);
boolean expandCat = false;
boolean ulOpen = false;
String catExp = (String) session.getAttribute("catExp");
for (int i = 0; i < sortedkeys.length; i++) {
sql = (Properties) files.get(sortedkeys[i]);
String testCat = sql.getProperty("Category");
String testName = sql.getProperty("Name");
String provide = sql.getProperty("Provides");
if (provide != null)
provides.put(provide, new Integer(i));
if ((testCat != null) && (!testCat.equalsIgnoreCase(curCat))) {
if (ulOpen) out.println("");
expandCat = (testCat.equals(catExp));
out.println("");
curCat = testCat;
out.println("");
ulOpen = true;
}
if (!expandCat)
continue;
%>
- <%= testName %>
<%
}
if (ulOpen)
out.println(" ");
}
String numStr = request.getParameter("exec");
String stageStr = request.getParameter("stage");
if (numStr != null) {
int num = Integer.parseInt(numStr);
int stage = (stageStr != null) ? Integer.parseInt(stageStr) : 1;
if (num < sqlFiles.length) {
Properties sqlTest = (Properties) files.get(sortedkeys[num]);
String require = sqlTest.getProperty("Requires");
if ((require != null) && (session.getAttribute(require) == null)) {
Integer reqExec = (Integer)provides.get(require);
if (reqExec != null)
sqlTest = (Properties) files.get(sortedkeys[reqExec.intValue()]);
}
String testName = sqlTest.getProperty("Name");
String testDesc = sqlTest.getProperty("Description");
%>
|
Executing |
<%= testName %> |
Description |
<%= testDesc %> |
<%
Vector props = new Vector();
String prop = null;
int j = 0;
do {
//out.println("Trying to get val" + Integer.toString(j));
prop = request.getParameter("val" + Integer.toString(j));
if (prop != null) {
props.add(prop);
//out.println("Adding: " + prop + "");
}
j++;
}
while (prop != null);
Object[] params = props.toArray();
String testSQL = "";
for (int i = stage; testSQL != null; i++) {
String suffix = ((i < 2) ? "" : Integer.toString(i));
testSQL = sqlTest.getProperty("SQL" + suffix);
if (testSQL != null) {
testSQL = testSQL.replaceAll("\'", "\'\'");
}
String heading = sqlTest.getProperty("Heading" + suffix);
String linkColumn = sqlTest.getProperty("LinkColumn" + suffix);
String importFile = sqlTest.getProperty("ImportFile" + suffix);
String importSQL = sqlTest.getProperty("ImportSQL" + suffix);
String importDupCheck = sqlTest.getProperty("ImportDupCheck" + suffix);
String exportFile = sqlTest.getProperty("ExportFile" + suffix);
String formField = sqlTest.getProperty("Form" + suffix + ".0");
String sessionField = sqlTest.getProperty("SetSession" + suffix + ".0");
// see if we have a form
if (heading != null) {
%>
<%= heading %>
<%
}
if (importFile != null) {
String fileName = importFile;
String iSQL = "";
int separator = fileName.indexOf('|');
if (separator > -1) {
fileName = importFile.substring(0, separator);
iSQL = importFile.substring(separator + 1);
}
try {
CSVFileReader fin = new CSVFileReader(new File(sqlPath+"/"+fileName), '|', false);
iSQL = iSQL.replaceAll("\'", "\'\'");
iSQL = replaceSessionTags(session, iSQL);
if (importDupCheck != null) {
importDupCheck = importDupCheck.replaceAll("\'", "\'\'");
importDupCheck = replaceSessionTags(session, importDupCheck);
}
for (boolean more = fin.begin(); more; more = fin.next()) {
boolean execute = true;
if (importDupCheck != null) {
MessageFormat format = new MessageFormat(importDupCheck);
String dcSQL = format.format(fin.getFields());
//out.print(dcSQL);
execute = (runSQL(dcSQL, linkColumn, num, i + 1, null) == 0);
}
if (execute) {
MessageFormat format = new MessageFormat(iSQL);
String rSQL = format.format(fin.getFields());
runSQL(rSQL, linkColumn, num, i + 1, out);
}
}
}
catch (Exception e) { e.printStackTrace(); }
}
if (importSQL != null) {
String sourceSQL = importSQL;
String iSQL = "";
int separator = sourceSQL.indexOf('|');
if (separator > -1) {
sourceSQL = importSQL.substring(0, separator);
iSQL = importSQL.substring(separator + 1);
}
try {
importSQL(sourceSQL, iSQL, importDupCheck, out);
}
catch (Exception e) { e.printStackTrace(); }
}
if (exportFile != null) {
String fileName = exportFile;
String iSQL = "";
int separator = fileName.indexOf('|');
if (separator > -1) {
fileName = exportFile.substring(0, separator);
iSQL = exportFile.substring(separator + 1);
}
try {
FileWriter fout = new FileWriter(new File(sqlPath+"/"+fileName));
iSQL = replaceSessionTags(session, iSQL);
exportSQL(iSQL, fout, out);
fout.close();
}
catch (Exception e) { e.printStackTrace(); }
}
if (sessionField != null) {
j = 0;
do {
sessionField = replaceSessionTags(session, sessionField);
MessageFormat format = new MessageFormat(sessionField);
sessionField = format.format(params);
String fieldName = sessionField;
String fieldValue = "";
int separator = sessionField.indexOf('|');
if (separator > -1) {
fieldName = sessionField.substring(0, separator);
fieldValue = sessionField.substring(separator + 1);
}
session.setAttribute(fieldName, fieldValue);
sessionField = sqlTest.getProperty("SetSession" + suffix + "." + Integer.toString(++j));
} while (sessionField != null);
}
if (formField != null) {
%>
<%
break;
}
// assert we have an SQL String to execute
if (testSQL == null)
break;
testSQL = replaceSessionTags(session, testSQL);
MessageFormat format = new MessageFormat(testSQL);
testSQL = format.format(params);
runSQL(testSQL, linkColumn, num, i + 1, out);
if (linkColumn != null) {
break;
}
String nextStage = sqlTest.getProperty("Next" + suffix);
try {
i = Integer.parseInt(nextStage) - 1;
}
catch (Exception e) {}
String newZero = sqlTest.getProperty("NewZero" + suffix);
try {
params[0] = params[Integer.parseInt(newZero)];
}
catch (Exception e) {}
}
}
}
%>
|