summaryrefslogtreecommitdiffstats
path: root/src/wcps/server
diff options
context:
space:
mode:
authorAndrei Aiordachioaie <a.aiordachioaie@jacobs-university.de>2009-06-08 17:49:13 +0200
committerAndrei Aiordachioaie <a.aiordachioaie@jacobs-university.de>2009-07-07 10:55:14 +0200
commitd2b0e006273d55c170ed6cd56f9509bc1eaa90eb (patch)
treeb778bcbf3211d2ff5d5a0dee8daaad480095aa8c /src/wcps/server
parente60efdbfb39124b6a36465e17fe2ad349580c18b (diff)
Implemented Condense Expression and Constant Coverage Expression. WCPS Grammar modified
Diffstat (limited to 'src/wcps/server')
-rw-r--r--src/wcps/server/cli/f_grammar.java66
-rw-r--r--src/wcps/server/cli/grammar.java16
-rw-r--r--src/wcps/server/cli/xml.java105
-rw-r--r--src/wcps/server/core/AxisIterator.java23
-rw-r--r--src/wcps/server/core/BooleanScalarExpr.java2
-rw-r--r--src/wcps/server/core/ComplexConstant.java57
-rw-r--r--src/wcps/server/core/CondenseOperation.java71
-rw-r--r--src/wcps/server/core/CondenseScalarExpr.java91
-rw-r--r--src/wcps/server/core/ConstantCoverageExpr.java142
-rw-r--r--src/wcps/server/core/ConstantList.java115
-rw-r--r--src/wcps/server/core/ConstructCoverageExpr.java33
-rw-r--r--src/wcps/server/core/CoverageExpr.java5
-rw-r--r--src/wcps/server/core/NumericScalarExpr.java24
-rw-r--r--src/wcps/server/core/ScalarExpr.java4
-rw-r--r--src/wcps/server/core/SliceCoverageExpr.java27
-rw-r--r--src/wcps/server/core/VariableReference.java62
-rw-r--r--src/wcps/server/core/WCPS.java10
-rw-r--r--src/wcps/server/core/XmlQuery.java86
-rw-r--r--src/wcps/server/test/FullTestsOnline.java323
-rw-r--r--src/wcps/server/test/GrammarTest.java4
-rw-r--r--src/wcps/server/test/GrammarTestOnline.java7
-rw-r--r--src/wcps/server/test/XmlTestOnline.java7
22 files changed, 1173 insertions, 107 deletions
diff --git a/src/wcps/server/cli/f_grammar.java b/src/wcps/server/cli/f_grammar.java
new file mode 100644
index 0000000..6468767
--- /dev/null
+++ b/src/wcps/server/cli/f_grammar.java
@@ -0,0 +1,66 @@
+package wcps.server.cli;
+
+import grammar.*;
+import grammar.wcpsParser.*;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import org.antlr.runtime.ANTLRInputStream;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.RecognitionException;
+import org.apache.commons.io.FileUtils;
+
+/** Test the WCPS grammar parser (generated by ANTLR).
+ * Input the path that contains an Abstract Syntax query.
+ * Outputs the corresponding XML tree.
+ *
+ * @author Andrei Aiordachioaie
+ */
+public class f_grammar {
+
+ private static String query;
+ private static String path;
+
+ public static void main(String[] args) throws RecognitionException, IOException
+ {
+ if (args.length != 1)
+ {
+ System.err.println("AbstractGrammarGen: no parameter to specify input file !");
+ path = "test/test-tmp/29.test";
+ query = FileUtils.readFileToString(new File(path));
+ }
+ else
+ {
+ path = args[0];
+ query = FileUtils.readFileToString(new File(path));
+ }
+
+ System.out.println("Running with the following query: " + query);
+
+ String xmlString = runQuery(query);
+ System.out.println("Output XML: \n****************\n" + xmlString);
+
+ System.exit(0);
+
+ }
+
+ public static String runQuery(String query) throws IOException, RecognitionException
+ {
+ InputStream stream = new ByteArrayInputStream(query.getBytes()); // defaults to ISO-1
+ ANTLRInputStream inputStream = new ANTLRInputStream(stream);
+// wcpsLexer lexer = new wcpsLexer( inputStream );
+ wcpsLexer lexer = new wcpsLexer( inputStream );
+
+ CommonTokenStream tokenStream = new CommonTokenStream(lexer);
+// wcpsParser parser = new wcpsParser(tokenStream);
+ wcpsParser parser = new wcpsParser(tokenStream);
+
+ wcpsRequest_return rrequest = parser.wcpsRequest();
+ WCPSRequest request = rrequest.value;
+
+ String result = request.toXML();
+ return result;
+ }
+
+}
diff --git a/src/wcps/server/cli/grammar.java b/src/wcps/server/cli/grammar.java
index eabee72..29961a2 100644
--- a/src/wcps/server/cli/grammar.java
+++ b/src/wcps/server/cli/grammar.java
@@ -24,22 +24,30 @@ public class grammar {
if (args.length != 1)
{
System.err.println("AbstractGrammarGen: no query as parameter !");
- query = "for r in (rgb) return encode( r * ((r.green > 130) and " +
- "(r.red < 110)), \"jpeg\")";
+ query = "for a in (rgb) return " +
+ "condense + over $x x(1:10), $y y(25:75) " +
+ "using $x * (a[x($x), y($y)]).red";
}
else
query = args[0];
System.out.println("Running with the following query: " + query);
- String xmlString = runQuery(query);
+ String xmlString = convertAbstractQueryToXml(query);
System.out.println("Output XML: \n****************\n" + xmlString);
System.exit(0);
}
- public static String runQuery(String query) throws IOException, RecognitionException
+ /** Converts a WCPS abstract syntax query to an XML query
+ *
+ * @param query Abstract Syntax query
+ * @return String XML query
+ * @throws java.io.IOException
+ * @throws org.antlr.runtime.RecognitionException
+ */
+ public static String convertAbstractQueryToXml(String query) throws IOException, RecognitionException
{
InputStream stream = new ByteArrayInputStream(query.getBytes()); // defaults to ISO-1
ANTLRInputStream inputStream = new ANTLRInputStream(stream);
diff --git a/src/wcps/server/cli/xml.java b/src/wcps/server/cli/xml.java
index 10c201c..b4f5639 100644
--- a/src/wcps/server/cli/xml.java
+++ b/src/wcps/server/cli/xml.java
@@ -23,6 +23,7 @@
package wcps.server.cli;
+import java.io.IOException;
import wcps.server.core.CachedMetadataSource;
import wcps.server.core.DbMetadataSource;
import wcps.server.core.ProcessCoveragesRequest;
@@ -31,7 +32,9 @@ import wcps.server.core.WCPS;
import java.io.File;
import java.io.FileInputStream;
+import java.io.StringReader;
import java.util.Properties;
+import org.xml.sax.InputSource;
/**
* This is a small application around the WCPS core. It takes XML requests as files and runs them
@@ -43,27 +46,13 @@ import java.util.Properties;
public class xml
{
private static WCPS wcps;
+ private static DbMetadataSource metadataSource;
- public static void main(String[] args)
- {
- if (args.length < 1)
- {
- System.err.println("WCPS CLI: no input files");
-
- System.err.println("\nWCPS CLI Usage: java wcps.server.cli.xml input.xml");
- System.err.println("Where input.xml contains a ProcessCoverages Request ");
- System.exit(1);
-
- args = new String[1];
- args[0] = "old_testing/testcases/1.test.xml";
- }
- if (args.length > 1)
- {
- System.err.println("WCPS: no input files");
- System.exit(1);
- }
-
- String pcSchemaFileName =
+ private static void initMetadata()
+ {
+ File cwd = new File(".");
+ System.out.println("Working in " + cwd.getAbsolutePath());
+ String pcSchemaFileName = "src/conf/" +
"xml" + File.separator + "ogc" + File.separator + "wcps"
+ File.separator + "1.0.0" + File.separator + "wcpsProcessCoverages.xsd";
File pcSchemaFile = new File(pcSchemaFileName);
@@ -75,7 +64,7 @@ public class xml
System.exit(1);
}
- DbMetadataSource metadataSource = null;
+ metadataSource = null;
try
{
@@ -95,14 +84,38 @@ public class xml
e.printStackTrace(System.err);
System.exit(1);
}
+ }
+
+ public static void main(String[] args)
+ {
+ if (args.length < 1)
+ {
+ System.err.println("WCPS CLI: no input files");
+
+ System.err.println("\nWCPS CLI Usage: java wcps.server.cli.xml input.xml");
+ System.err.println("Where input.xml contains a ProcessCoverages Request ");
+// System.exit(1);
+
+ args = new String[1];
+ args[0] = "test/testcases-wcps_dollar/25.test.xml";
+ }
+ if (args.length > 1)
+ {
+ System.err.println("WCPS: no input files");
+ System.exit(1);
+ }
+
+ initMetadata();
for (int i = 0; i < args.length; i++)
{
File fileIn = null;
+ InputSource is = null;
try
{
fileIn = new File(args[i]);
+ is = new InputSource(new FileInputStream(fileIn));
}
catch (Exception fnfe)
{
@@ -111,9 +124,11 @@ public class xml
System.exit(1);
}
- boolean ok = processCoverage(fileIn, i);
-
- if (!ok)
+
+ String result = processCoverage(is, i);
+ if (result != null)
+ System.out.println(result);
+ else
{
System.err.println("WCPS: " + args[i] + " failed");
System.exit(1);
@@ -125,30 +140,18 @@ public class xml
}
- private static boolean processCoverage(File in, int i)
+ private static String processCoverage(InputSource is, int i)
{
+ String result = null;
+
try
{
-
- ProcessCoveragesRequest r =
- wcps.pcPrepare("http://kahlua.eecs.jacobs-university.de:7001",
- "RASSERVICE", in);
-
+ ProcessCoveragesRequest r = wcps.pcPrepare("http://kahlua.eecs.jacobs-university.de:9001",
+ "RASSERVICE", is);
System.err.println("Request " + i);
-
- System.out.println(r.getRasqlQuery());
-
-
-/* Iterator<byte[]> results = r.execute().iterator();
-
- int j = 0;
- while( results.hasNext() ) {
- String outFileName = "WCPS-" + i + "-" + j++;
- FileOutputStream out = new FileOutputStream( outFileName );
- out.write( results.next() );
- out.close();
- System.out.println( "WCPS: " + outFileName + " written" );
- }*/
+ String rasql = r.getRasqlQuery();
+ String mime = r.getMime();
+ result = "[" + mime + "] " + rasql;
}
catch (Exception e)
{
@@ -157,7 +160,17 @@ public class xml
e.printStackTrace(System.err);
}
- return true;
-
+ return result;
}
+
+ /** Converts a WCPS XML query into a RasQL query string **/
+ public static String convertXmlToRasql(String query)
+ {
+ String rasql = null;
+ if (metadataSource == null)
+ initMetadata();
+ InputSource is = new InputSource(new StringReader(query));
+ rasql = processCoverage(is, 1);
+ return rasql;
+ }
}
diff --git a/src/wcps/server/core/AxisIterator.java b/src/wcps/server/core/AxisIterator.java
index 6cca180..2b66f4d 100644
--- a/src/wcps/server/core/AxisIterator.java
+++ b/src/wcps/server/core/AxisIterator.java
@@ -28,13 +28,12 @@ import org.w3c.dom.*;
public class AxisIterator implements IRasNode
{
- private String var;
+ private String var, varTranslation;
private AxisName axis;
private NumericScalarExpr hi,lo;
- public AxisIterator(Node node, XmlQuery xq) throws WCPSException
+ public AxisIterator(Node node, XmlQuery xq, String newIteratorName) throws WCPSException
{
-
while ((node != null) && node.getNodeName().equals("#text"))
{
node = node.getNextSibling();
@@ -48,6 +47,9 @@ public class AxisIterator implements IRasNode
if (nodeName.equals("iteratorVar"))
{
var = node.getTextContent();
+ // This variable will be referenced later on. Translate it.
+ xq.addReferenceVariable(var, newIteratorName);
+ varTranslation = xq.getReferenceVariableName(var);
}
else if (nodeName.equals("axis"))
{
@@ -75,10 +77,16 @@ public class AxisIterator implements IRasNode
public String toRasQL()
{
- String result = var + " in [" + lo.toRasQL() + ":" + hi.toRasQL() + "]";
+ String result = varTranslation + " in [" + lo.toRasQL() + ":" + hi.toRasQL() + "]";
return result;
}
+ /** Sets a new name for the iterator variable, to be used in the rasql query**/
+ public void setVariableTranslation(String newName)
+ {
+ varTranslation = newName;
+ }
+
/** Return the Higher bound for the axis iterator.
* This only works for constant expressions.
* TODO: implement arbitrary expressions.
@@ -99,6 +107,7 @@ public class AxisIterator implements IRasNode
return SDU.str2integer(lo.toRasQL()).get(0);
}
+ /* Return the variable name used in this axis */
public String getVar()
{
return var;
@@ -108,4 +117,10 @@ public class AxisIterator implements IRasNode
{
return axis.toRasQL();
}
+
+ /* Returns the m-interval that this axis iterates over in a string form */
+ public String getInterval()
+ {
+ return lo.toRasQL() + ":" + hi.toRasQL();
+ }
}
diff --git a/src/wcps/server/core/BooleanScalarExpr.java b/src/wcps/server/core/BooleanScalarExpr.java
index ac21b5f..747577f 100644
--- a/src/wcps/server/core/BooleanScalarExpr.java
+++ b/src/wcps/server/core/BooleanScalarExpr.java
@@ -41,7 +41,7 @@ public class BooleanScalarExpr implements IRasNode
simple = false;
- System.out.println("Parsing boolean scalar operation ...");
+ System.err.println("Parsing boolean scalar operation ...");
if (nodeName.equals("booleanConstant"))
{
diff --git a/src/wcps/server/core/ComplexConstant.java b/src/wcps/server/core/ComplexConstant.java
index 39afd64..d396aec 100644
--- a/src/wcps/server/core/ComplexConstant.java
+++ b/src/wcps/server/core/ComplexConstant.java
@@ -29,6 +29,63 @@ public class ComplexConstant implements IRasNode
{
private String re, im;
+ public ComplexConstant(String str) throws WCPSException
+ {
+ boolean ok = true;
+ // We only accept the following String representation of a complex number: {re,im}
+ if (str.startsWith("{") && str.endsWith("}"))
+ {
+ str = str.substring(1,str.length()-2);
+ if (str.indexOf(",") != -1 && str.lastIndexOf(",") != str.indexOf(","))
+ {
+ int comma = str.indexOf(",");
+ re = str.substring(0, comma-1);
+ im = str.substring(comma+1, str.length()-comma-1);
+ }
+ else
+ ok = false;
+ }
+ else
+ ok = false;
+ if (ok == false)
+ throw new WCPSException("Could not parse Complex Constant !");
+
+ // parse the real part
+ try
+ {
+ Integer real = Integer.parseInt(re);
+ }
+ catch (NumberFormatException e)
+ {
+ try
+ {
+ Float real = Float.parseFloat(re);
+ }
+ catch (NumberFormatException e2)
+ {
+ throw new WCPSException("Could not parse float or integer " +
+ "number for real part of complex number:" + re);
+ }
+ }
+ // parse the imaginary part
+ try
+ {
+ Integer imag = Integer.parseInt(im);
+ }
+ catch (NumberFormatException e)
+ {
+ try
+ {
+ Float imag = Float.parseFloat(im);
+ }
+ catch (NumberFormatException e2)
+ {
+ throw new WCPSException("Could not parse float or integer " +
+ "number for imaginary part of complex number" + im);
+ }
+ }
+ }
+
public ComplexConstant(Node node, XmlQuery xq) throws WCPSException
{
System.err.println("Parsing complex constant: " + node.getNodeName());
diff --git a/src/wcps/server/core/CondenseOperation.java b/src/wcps/server/core/CondenseOperation.java
new file mode 100644
index 0000000..07bc921
--- /dev/null
+++ b/src/wcps/server/core/CondenseOperation.java
@@ -0,0 +1,71 @@
+/*
+ * This file is part of PetaScope.
+ *
+ * PetaScope is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * PetaScope is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with PetaScope. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For more information please see <http://www.PetaScope.org>
+ * or contact Peter Baumann via <baumann@rasdaman.com>.
+ *
+ * Copyright 2009 Jacobs University Bremen, Peter Baumann.
+ */
+
+
+package wcps.server.core;
+
+import org.w3c.dom.*;
+
+public class CondenseOperation implements IRasNode
+{
+ private String name;
+
+ public CondenseOperation(Node node, XmlQuery xq) throws WCPSException
+ {
+ while ((node != null) && node.getNodeName().equals("#text"))
+ {
+ node = node.getNextSibling();
+ }
+
+ System.err.println("Parsing condense Operation: " + node.getNodeName());
+
+ String text = node.getNodeName();
+ this.name = formatOperation(text);
+
+ if (name == null)
+ throw new WCPSException("Unknown condense operation: " + text);
+ }
+
+ private String formatOperation(String name)
+ {
+ String shortOp = null;
+ if (name.equals("opPlus"))
+ shortOp = "+";
+ if (name.equals("opMult"))
+ shortOp = "*";
+ if (name.equals("opMin"))
+ shortOp = "min";
+ if (name.equals("opMax"))
+ shortOp = "max";
+ if (name.equals("opAnd"))
+ shortOp = "and";
+ if (name.equals("opOr"))
+ shortOp = "or";
+
+ return shortOp;
+ }
+
+ public String toRasQL()
+ {
+ return name;
+ }
+}
diff --git a/src/wcps/server/core/CondenseScalarExpr.java b/src/wcps/server/core/CondenseScalarExpr.java
index 86d14a7..5418260 100644
--- a/src/wcps/server/core/CondenseScalarExpr.java
+++ b/src/wcps/server/core/CondenseScalarExpr.java
@@ -23,18 +23,103 @@
package wcps.server.core;
+import java.util.Vector;
import org.w3c.dom.*;
-// TODO: implement CondenseScalarExprType
public class CondenseScalarExpr implements IRasNode
{
+ private CondenseOperation op;
+ private Vector<AxisIterator> iterators;
+ private IRasNode using;
+ private IRasNode where;
+ private String axisIteratorString;
+ private String newIteratorName;
+
public CondenseScalarExpr(Node node, XmlQuery xq) throws WCPSException
{
- throw new WCPSException("Method not implemented");
+ if (node.getNodeName().equals("condense"))
+ node = node.getFirstChild();
+ while ((node != null) && node.getNodeName().equals("#text"))
+ {
+ node = node.getNextSibling();
+ }
+
+ iterators = new Vector();
+ newIteratorName = xq.registerNewExpressionWithVariables();
+ System.err.println("Parsing Condense Scalar Expression: " + node.getNodeName());
+
+ while (node != null)
+ {
+ String name = node.getNodeName();
+ if (op == null)
+ {
+ op = new CondenseOperation(node, xq);
+ }
+ else
+ if (name.equals("iterator"))
+ {
+ AxisIterator it = new AxisIterator(node.getFirstChild(), xq, newIteratorName);
+ iterators.add(it);
+ }
+ else
+ if (name.equals("where"))
+ {
+ where = new BooleanScalarExpr(node.getFirstChild(), xq);
+ }
+ else
+ {
+ // TODO (HACK) Settle on either CoverageExpr or ScalarExpr
+ /* Discussion:
+ * CoverageExpr allows expressions like c[$x,15].
+ * ScalarExpr allows constants.
+ * They do not like each other
+ * Handle this in the grammar in a more explicit way.
+ */
+ try
+ {
+ using = new CoverageExpr(node, xq);
+ }
+ catch (WCPSException e)
+ {
+ using = new ScalarExpr(node, xq);
+ }
+ }
+
+ node = node.getNextSibling();
+ while ((node != null) && node.getNodeName().equals("#text"))
+ {
+ node = node.getNextSibling();
+ }
+ }
+
+ buildAxisIteratorDomain();
}
public String toRasQL()
{
- return "";
+ String result = "condense " + op.toRasQL() + " over ";
+ result += axisIteratorString;
+ if (where != null)
+ result += where.toRasQL();
+ result += " using " + using.toRasQL();
+ return result;
}
+
+ /* Concatenates all the AxisIterators into one large multi-dimensional object,
+ * that will be used to build to RasQL query */
+ private void buildAxisIteratorDomain()
+ {
+ axisIteratorString = "";
+ axisIteratorString += newIteratorName + " in [";
+
+ for (int i = 0; i < iterators.size(); i++)
+ {
+ if (i > 0)
+ axisIteratorString += ", ";
+ AxisIterator ai = iterators.elementAt(i);
+ axisIteratorString += ai.getInterval();
+ }
+
+ axisIteratorString += "]";
+ }
}
diff --git a/src/wcps/server/core/ConstantCoverageExpr.java b/src/wcps/server/core/ConstantCoverageExpr.java
index 17634bf..fca04c2 100644
--- a/src/wcps/server/core/ConstantCoverageExpr.java
+++ b/src/wcps/server/core/ConstantCoverageExpr.java
@@ -23,24 +23,156 @@
package wcps.server.core;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Vector;
import org.w3c.dom.*;
-// TODO: implement class ConstantCoverageExprType
public class ConstantCoverageExpr implements IRasNode, ICoverageInfo
{
+ private String covName;
+ private Vector<AxisIterator> iterators;
+ private ConstantList valueList;
+ private CoverageInfo info;
+ private String axisIteratorString;
+ private int requiredListSize = 1;
+
public ConstantCoverageExpr(Node node, XmlQuery xq)
throws WCPSException
- {
- throw new WCPSException("Method not implemented");
+ {
+ while ((node != null) && node.getNodeName().equals("#text"))
+ {
+ node = node.getNextSibling();
+ }
+
+ iterators = new Vector();
+ System.err.println("Parsing Constant Coverage Expr: " + node.getNodeName());
+
+ while (node != null)
+ {
+ String name = node.getNodeName();
+ if (name.equals("name"))
+ covName = node.getTextContent();
+ else
+ if (name.equals("axisIterator"))
+ {
+ AxisIterator it = new AxisIterator(node.getFirstChild(), xq, "temp");
+ iterators.add(it);
+ }
+ else
+ {
+ valueList = new ConstantList(node, xq);
+ node = valueList.getLastNode();
+ }
+
+ node = node.getNextSibling();
+ while ((node != null) && node.getNodeName().equals("#text"))
+ {
+ node = node.getNextSibling();
+ }
+ }
+
+ buildMetadata(xq);
+ buildAxisIteratorDomain();
+
+ // Sanity check: dimensions should match number of constants in the list
+ if (valueList.getSize() != requiredListSize)
+ throw new WCPSException("The number of constants in the list do " +
+ "not match the dimensions specified !");
+ // Sanity check: metadata should have already been build
+ if (info == null)
+ throw new WCPSException("Could not build constant coverage metadata !!!");
}
+
public String toRasQL()
{
- return "";
+ String result = "< ";
+ result += axisIteratorString + " ";
+ result += valueList.toRasQL();
+ result += ">";
+
+ return result;
}
public CoverageInfo getCoverageInfo()
{
- return null;
+ return info;
}
+
+ /* Concatenates all the AxisIterators into one large multi-dimensional object,
+ * that will be used to build to RasQL query. Also counts how many elements
+ * fit in the specified dimensions. */
+ private void buildAxisIteratorDomain()
+ {
+ requiredListSize = 1;
+ axisIteratorString = "";
+ axisIteratorString += "[";
+
+ for (int i = 0; i < iterators.size(); i++)
+ {
+ if (i > 0)
+ axisIteratorString += ", ";
+ AxisIterator ai = iterators.elementAt(i);
+ axisIteratorString += ai.getInterval();
+ requiredListSize *= (ai.getHigh().intValue() - ai.getLow().intValue() + 1);
+ }
+
+ axisIteratorString += "]";
+
+ System.err.println("Axes for ConstantCoverage tell us that the constant" +
+ "list should have exactly " + requiredListSize + " elements !");
+ }
+
+ /** Builds full metadata for the newly constructed coverage **/
+ private void buildMetadata(XmlQuery xq) throws WCPSException
+ {
+ List<CellDomainElement> cellDomainList = new LinkedList<CellDomainElement>();
+ List<RangeElement> rangeList = new LinkedList<RangeElement>();
+ HashSet<String> nullSet = new HashSet<String>();
+ String nullDefault = "0";
+ nullSet.add(nullDefault);
+ HashSet<InterpolationMethod> interpolationSet = new HashSet<InterpolationMethod>();
+ InterpolationMethod interpolationDefault = new InterpolationMethod("none", "none");
+ interpolationSet.add(interpolationDefault);
+ String coverageName = covName;
+ List<DomainElement> domainList = new LinkedList<DomainElement>();
+
+ Iterator<AxisIterator> i = iterators.iterator();
+ while (i.hasNext())
+ {
+ // Build domain metadata
+ AxisIterator ai = i.next();
+ cellDomainList.add(new CellDomainElement( ai.getLow(), ai.getHigh()));
+ String axisName = ai.getVar();
+ String axisType = ai.getAxisType();
+ String crs = DomainElement.IMAGE_CRS;
+ HashSet<String> crsset = new HashSet<String>();
+ crsset.add(crs);
+ DomainElement domain = new DomainElement(axisName, axisType,
+ ai.getLow().doubleValue(), ai.getHigh().doubleValue(),
+ null, null, crsset);
+ domainList.add(domain);
+ }
+ // TODO: check element datatypes and their consistency
+ // "unsigned int" is default datatype
+ rangeList.add(new RangeElement("dynamic_type", "unsigned int"));
+
+ try
+ {
+ Metadata metadata = new Metadata(cellDomainList, rangeList, nullSet,
+ nullDefault, interpolationSet, interpolationDefault,
+ coverageName, domainList);
+ // Let the top-level query know the full metadata about us
+ xq.getMetadataSource().addDynamicMetadata(covName, metadata);
+ info = new CoverageInfo(metadata);
+ }
+ catch (InvalidMetadataException e)
+ {
+ throw new WCPSException("Could not build coverage '" + covName
+ + "' metadata !", e);
+ }
+ }
}
diff --git a/src/wcps/server/core/ConstantList.java b/src/wcps/server/core/ConstantList.java
new file mode 100644
index 0000000..a14e10b
--- /dev/null
+++ b/src/wcps/server/core/ConstantList.java
@@ -0,0 +1,115 @@
+/*
+ * This file is part of PetaScope.
+ *
+ * PetaScope is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * PetaScope is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with PetaScope. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For more information please see <http://www.PetaScope.org>
+ * or contact Peter Baumann via <baumann@rasdaman.com>.
+ *
+ * Copyright 2009 Jacobs University Bremen, Peter Baumann.
+ */
+
+
+package wcps.server.core;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import org.w3c.dom.*;
+
+public class ConstantList implements IRasNode
+{
+ private ArrayList<String> list;
+ private String val;
+ private Node lastNode;
+
+ public ConstantList(Node node, XmlQuery xq) throws WCPSException
+ {
+ list = new ArrayList<String>();
+
+ while ((node != null) && node.getNodeName().equals("#text"))
+ {
+ node = node.getNextSibling();
+ }
+ System.err.println("Trying to parse ConstantList ");
+
+ while (node != null)
+ {
+ String nodeName = node.getNodeName();
+
+ if (nodeName.equals("value"))
+ {
+ val = node.getTextContent();
+ checkConstant(val);
+ list.add(val);
+ lastNode = node;
+ }
+ else
+ throw new WCPSException("Unknown node in ConstantList: " + nodeName);
+
+ node = node.getNextSibling();
+ while ((node != null) && node.getNodeName().equals("#text"))
+ {
+ node = node.getNextSibling();
+ }
+ }
+
+ System.err.println("Parsed constant list with " + list.size() + " elements !");
+ }
+
+ private void checkConstant(String val) throws WCPSException
+ {
+ boolean ok = false;
+ try
+ {
+ Integer.parseInt(val);
+ ok = true;
+ }
+ catch (NumberFormatException e1){}
+ try
+ {
+ Float.parseFloat(val);
+ ok = true;
+ }
+ catch (NumberFormatException e2){}
+ try
+ {
+ new ComplexConstant(val);
+ ok = true;
+ }
+ catch (WCPSException e1){}
+
+ if (ok == false)
+ throw new WCPSException("'" + val + "' is not an integer, float, or complex constant !");
+ }
+
+ public String toRasQL()
+ {
+ String result = list.get(0);
+ for (int i = 1; i < list.size(); i++)
+ result += ", " + list.get(i);
+ return result;
+ }
+
+ /** Size of all elements in the constant list **/
+ public int getSize()
+ {
+ return list.size();
+ }
+
+ /** Return the last node of the constant list. **/
+ public Node getLastNode()
+ {
+ return lastNode;
+ }
+}
diff --git a/src/wcps/server/core/ConstructCoverageExpr.java b/src/wcps/server/core/ConstructCoverageExpr.java
index 377066f..b93b5de 100644
--- a/src/wcps/server/core/ConstructCoverageExpr.java
+++ b/src/wcps/server/core/ConstructCoverageExpr.java
@@ -37,6 +37,8 @@ public class ConstructCoverageExpr implements IRasNode, ICoverageInfo
private Vector<AxisIterator> iterators;
private IRasNode values;
private CoverageInfo info;
+ private String axisIteratorString;
+ private String newIteratorName;
public ConstructCoverageExpr(Node node, XmlQuery xq)
@@ -49,6 +51,7 @@ public class ConstructCoverageExpr implements IRasNode, ICoverageInfo
iterators = new Vector();
System.err.println("Parsing Construct Coverage Expr: " + node.getNodeName());
+ newIteratorName = xq.registerNewExpressionWithVariables();
while (node != null)
{
@@ -58,11 +61,11 @@ public class ConstructCoverageExpr implements IRasNode, ICoverageInfo
else
if (name.equals("axisIterator"))
{
- AxisIterator it = new AxisIterator(node.getFirstChild(), xq);
+ AxisIterator it = new AxisIterator(node.getFirstChild(), xq, newIteratorName);
iterators.add(it);
// Top level structures need to know about these iterators
CoverageIterator dyn = new CoverageIterator(it.getVar(), covName);
- xq.addDynamicIterator(dyn);
+ xq.addDynamicCoverageIterator(dyn);
}
else
{
@@ -83,6 +86,8 @@ public class ConstructCoverageExpr implements IRasNode, ICoverageInfo
}
}
+ buildAxisIteratorDomain();
+
// Sanity check: metadata should have already been build
if (info == null)
throw new WCPSException("Could not build coverage metadata !!!");
@@ -91,11 +96,7 @@ public class ConstructCoverageExpr implements IRasNode, ICoverageInfo
public String toRasQL()
{
String result = "marray ";
- result += iterators.elementAt(0).toRasQL();
- for (int i = 1; i < iterators.size(); i++)
- {
- result += ", " + iterators.elementAt(i).toRasQL();
- }
+ result += axisIteratorString;
result += " values " + values.toRasQL();
return result;
@@ -106,6 +107,24 @@ public class ConstructCoverageExpr implements IRasNode, ICoverageInfo
return info;
}
+ /* Concatenates all the AxisIterators into one large multi-dimensional object,
+ * that will be used to build to RasQL query */
+ private void buildAxisIteratorDomain()
+ {
+ axisIteratorString = "";
+ axisIteratorString += newIteratorName + " in [";
+
+ for (int i = 0; i < iterators.size(); i++)
+ {
+ if (i > 0)
+ axisIteratorString += ", ";
+ AxisIterator ai = iterators.elementAt(i);
+ axisIteratorString += ai.getInterval();
+ }
+
+ axisIteratorString += "]";
+ }
+
/** Builds full metadata for the newly constructed coverage **/
private void buildMetadata(XmlQuery xq) throws WCPSException
{
diff --git a/src/wcps/server/core/CoverageExpr.java b/src/wcps/server/core/CoverageExpr.java
index bb6f5c1..236c188 100644
--- a/src/wcps/server/core/CoverageExpr.java
+++ b/src/wcps/server/core/CoverageExpr.java
@@ -34,6 +34,7 @@ public class CoverageExpr implements IRasNode, ICoverageInfo
private IRasNode child;
private String childInfo;
private CoverageInfo info;
+// private String var;
private boolean simpleCoverage; // True is the coverage is just a string
public CoverageExpr(Node node, XmlQuery xq) throws WCPSException
@@ -102,6 +103,10 @@ public class CoverageExpr implements IRasNode, ICoverageInfo
// TODO: implement class ConstantCoverageExprType
child = new ConstantCoverageExpr(node.getFirstChild(), xq);
}
+// else if (nodeName.equals("variableRef"))
+// {
+// child = new VariableReference(node, xq);
+// }
else
{ // Try one of the groups
child = null;
diff --git a/src/wcps/server/core/NumericScalarExpr.java b/src/wcps/server/core/NumericScalarExpr.java
index c241ac6..6a7abff 100644
--- a/src/wcps/server/core/NumericScalarExpr.java
+++ b/src/wcps/server/core/NumericScalarExpr.java
@@ -38,7 +38,7 @@ public class NumericScalarExpr implements IRasNode
op = "";
- System.out.println("Trying to parse numeric scalar expression ...");
+ System.err.println("Trying to parse numeric scalar expression ...");
if (nodeName.equals("numericConstant"))
{
@@ -91,7 +91,21 @@ public class NumericScalarExpr implements IRasNode
System.err.println("Failed to parse a numeric expression pair !");
}
}
-
+ else if (nodeName.equals("variableRef"))
+ {
+ try
+ {
+ op = code(nodeName);
+ twoChildren = false;
+ first = new VariableReference(node, xq);
+ System.err.println("Matched variable reference: " + first.toRasQL());
+ }
+ catch (WCPSException e)
+ {
+ System.err.println("Failed to match variable reference: "
+ + e.toString());
+ }
+ }
else
{
throw new WCPSException("Unexpected Numeric Scalar Expression node : "
@@ -102,7 +116,9 @@ public class NumericScalarExpr implements IRasNode
public String toRasQL()
{
String result = "";
- if (op.equals("value"))
+ if (op.equals("variable"))
+ result = first.toRasQL();
+ else if (op.equals("value"))
result = value;
else if ((twoChildren==false) && (op.equals("-")))
result = "-" + first.toRasQL();
@@ -133,6 +149,8 @@ public class NumericScalarExpr implements IRasNode
if (name.equals("condense") || name.equals("reduce")
|| name.equals("complexConstant"))
op = "child";
+ if (name.equals("variableRef"))
+ op = "variable";
return op;
}
diff --git a/src/wcps/server/core/ScalarExpr.java b/src/wcps/server/core/ScalarExpr.java
index 6247db7..a5338f1 100644
--- a/src/wcps/server/core/ScalarExpr.java
+++ b/src/wcps/server/core/ScalarExpr.java
@@ -27,11 +27,7 @@ import org.w3c.dom.*;
public class ScalarExpr implements IRasNode
{
-// private IRasNode first, second;
private IRasNode child;
-// private String op;
-// private String type; // can be simple (just a value), unary, binary, function or defered
-// private String value;
public ScalarExpr(Node node, XmlQuery xq) throws WCPSException
{
diff --git a/src/wcps/server/core/SliceCoverageExpr.java b/src/wcps/server/core/SliceCoverageExpr.java
index ef20c86..a2c4f79 100644
--- a/src/wcps/server/core/SliceCoverageExpr.java
+++ b/src/wcps/server/core/SliceCoverageExpr.java
@@ -97,19 +97,30 @@ public class SliceCoverageExpr implements IRasNode, ICoverageInfo
Iterator<DimensionPointElement> i = axisList.iterator();
DimensionPointElement axis;
int axisId;
- int slicingPos;
+ int slicingPosInt;
+ String slicingPosStr;
while (i.hasNext())
{
axis = i.next();
axisId = coverageInfo.getDomainIndexByName(axis.getAxisName());
- slicingPos = Integer.parseInt(axis.getSlicingPosition());
- dim[axisId] = "" + slicingPos;
- coverageInfo.setCellDimension(
- axisId,
- new CellDomainElement(
- BigInteger.valueOf(slicingPos), BigInteger.valueOf(slicingPos)));
- }
+ slicingPosStr = axis.getSlicingPosition();
+ dim[axisId] = slicingPosStr;
+ // Slicing position can be a constant number or a variable reference
+ try
+ {
+ slicingPosInt = Integer.parseInt(slicingPosStr);
+ }
+ catch (NumberFormatException e)
+ {
+ slicingPosInt = 1;
+ }
+ coverageInfo.setCellDimension(
+ axisId,
+ new CellDomainElement(
+ BigInteger.valueOf(slicingPosInt), BigInteger.valueOf(slicingPosInt)));
+
+ }
}
diff --git a/src/wcps/server/core/VariableReference.java b/src/wcps/server/core/VariableReference.java
new file mode 100644
index 0000000..09a1a3e
--- /dev/null
+++ b/src/wcps/server/core/VariableReference.java
@@ -0,0 +1,62 @@
+/*
+ * This file is part of PetaScope.
+ *
+ * PetaScope is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * PetaScope is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with PetaScope. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For more information please see <http://www.PetaScope.org>
+ * or contact Peter Baumann via <baumann@rasdaman.com>.
+ *
+ * Copyright 2009 Jacobs University Bremen, Peter Baumann.
+ */
+
+
+package wcps.server.core;
+
+import org.w3c.dom.*;
+
+public class VariableReference implements IRasNode
+{
+ private String name;
+ private String translatedName;
+
+ public VariableReference(Node node, XmlQuery xq) throws WCPSException
+ {
+ System.err.println("Parsing variable reference: " + node.getNodeName());
+
+ while ((node != null) && node.getNodeName().equals("#text"))
+ {
+ node = node.getNextSibling();
+ }
+
+ if (node != null && node.getNodeName().equals("variableRef"))
+ {
+ name = node.getTextContent();
+ translatedName = xq.getReferenceVariableName(name);
+ System.err.println("Variable " + name + " has been renamed into " +
+ translatedName);
+ }
+ else
+ throw new WCPSException("Could not find any variable reference !");
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String toRasQL()
+ {
+ return translatedName;
+ }
+}
diff --git a/src/wcps/server/core/WCPS.java b/src/wcps/server/core/WCPS.java
index 5677d18..ce6cf5e 100644
--- a/src/wcps/server/core/WCPS.java
+++ b/src/wcps/server/core/WCPS.java
@@ -62,18 +62,20 @@ public class WCPS
{
try
{
+ System.out.println("WCPS: Loading and parsing XML Schema ...");
DocumentBuilderFactory dbconfig = DocumentBuilderFactory.newInstance();
dbconfig.setValidating(false); // use XML schema not DTD
dbconfig.setIgnoringComments(true); // comments are not relevant
dbconfig.setIgnoringElementContentWhitespace(true); // remve the ignorable whitespace
- Schema wcpsProcessCoverageSchema =
- SchemaFactory.newInstance(
- XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(pcSchema);
+// Schema wcpsProcessCoverageSchema =
+// SchemaFactory.newInstance(
+// XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(pcSchema);
- dbconfig.setSchema(wcpsProcessCoverageSchema);
+// dbconfig.setSchema(wcpsProcessCoverageSchema);
wcpsDocumentBuilder = dbconfig.newDocumentBuilder();
+ System.out.println("WCPS: Finished loading the schema !");
}
catch (Exception e)
{
diff --git a/src/wcps/server/core/XmlQuery.java b/src/wcps/server/core/XmlQuery.java
index 603f4b1..d6355da 100644
--- a/src/wcps/server/core/XmlQuery.java
+++ b/src/wcps/server/core/XmlQuery.java
@@ -26,13 +26,14 @@ package wcps.server.core;
import org.w3c.dom.*;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
/**
*
* @author Andrei Aiordachioaie
*/
-class XmlQuery implements IRasNode
+public class XmlQuery implements IRasNode
{
private String mime;
private ArrayList<CoverageIterator> iterators;
@@ -40,6 +41,25 @@ class XmlQuery implements IRasNode
private IRasNode coverageExpr;
private IDynamicMetadataSource meta;
private ArrayList<CoverageIterator> dynamicIterators;
+ /* Variables used in the XML query are renamed. The renaming is explained below.
+ *
+ * Variables declared in the same expression (construct, const, condense)
+ will be collapsed into one multidimensional variable name. For
+ "construct img over $px x(1:10), $py y(1:10) values ... ", the variables could
+ be translated as: $px -> "iteratorA[0]", $py -> "iteratorA[1]".
+ * Variables declared in different expression will have different prefixes,
+ built from "varPrefix" + "varStart".
+ *
+
+ * Used in condenser, construct and constant coverage expressions. */
+
+ // VariableIndexCount stores the dimensionality of each renamed variable
+ private HashMap<String, Integer> varDimension;
+ // VariableNewName is used to translate the old var name into the multi-dim var name
+ private HashMap<String, String> variableTranslator;
+
+ private String varPrefix = "i";
+ private char varSuffix = 'i';
public String getMimeType()
{
@@ -50,6 +70,19 @@ class XmlQuery implements IRasNode
{
super();
this.meta = source;
+ iterators = new ArrayList<CoverageIterator>();
+ dynamicIterators = new ArrayList<CoverageIterator>();
+ variableTranslator = new HashMap<String, String>();
+ varDimension = new HashMap<String, Integer>();
+ }
+
+ public XmlQuery(Node node) throws WCPSException
+ {
+ iterators = new ArrayList<CoverageIterator>();
+ dynamicIterators = new ArrayList<CoverageIterator>();
+ variableTranslator = new HashMap<String, String>();
+ varDimension = new HashMap<String, Integer>();
+ this.startParsing(node);
}
public void startParsing(Node node) throws WCPSException
@@ -57,8 +90,7 @@ class XmlQuery implements IRasNode
System.err.println("Processing XML Request: " + node.getNodeName());
Node x = node.getFirstChild();
- iterators = new ArrayList<CoverageIterator>();
- dynamicIterators = new ArrayList<CoverageIterator>();
+
while (x != null)
{
@@ -97,11 +129,6 @@ class XmlQuery implements IRasNode
}
}
- public XmlQuery(Node node) throws WCPSException
- {
- this.startParsing(node);
- }
-
public Boolean isIteratorDefined(String iteratorName)
{
Iterator<CoverageIterator> it = iterators.iterator();
@@ -123,10 +150,10 @@ class XmlQuery implements IRasNode
return false;
}
- /* Stores information about dynamically created iterators.
+ /* Stores information about dynamically created iterators, as metadata.
* For example, from a Construct Coverage expression.
*/
- public void addDynamicIterator(CoverageIterator i)
+ public void addDynamicCoverageIterator(CoverageIterator i)
{
dynamicIterators.add(i);
}
@@ -168,6 +195,45 @@ class XmlQuery implements IRasNode
return false;
}
+ /** Creates a new (translated) variable name for an expression that
+ * has referenceable variables.
+ * @return String a new variable name assigned
+ */
+ public String registerNewExpressionWithVariables()
+ {
+ String name = varPrefix + varSuffix;
+ varDimension.put(name, 0);
+ varSuffix++;
+ return name;
+ }
+
+ /** Remember a variable that can be referenced in the future. This function
+ * assigns it a index code, that should then be used to reference that variable
+ * in the RasQL query.
+ *
+ * If the variable is already referenced, then this function does nothing.
+ * @param name Variable name
+ */
+ public boolean addReferenceVariable(String name, String translatedName)
+ {
+ if (varDimension.containsKey(translatedName) == false)
+ return false;
+
+ Integer index = varDimension.get(translatedName);
+ Integer newIndex = index + 1;
+ varDimension.put(translatedName, newIndex);
+ variableTranslator.put(name, translatedName + "[" + index + "]");
+
+ return true;
+ }
+
+ /** Retrieve the translated name assigned to a specific reference (scalar) variable */
+ public String getReferenceVariableName(String name) throws WCPSException
+ {
+ String newName = variableTranslator.get(name);
+ return newName;
+ }
+
public String toRasQL()
{
String result = "select " + coverageExpr.toRasQL() + " from ";
diff --git a/src/wcps/server/test/FullTestsOnline.java b/src/wcps/server/test/FullTestsOnline.java
new file mode 100644
index 0000000..1255789
--- /dev/null
+++ b/src/wcps/server/test/FullTestsOnline.java
@@ -0,0 +1,323 @@
+/*
+ * This file is part of PetaScope.
+ *
+ * PetaScope is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * PetaScope is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with PetaScope. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For more information please see <http://www.PetaScope.org>
+ * or contact Peter Baumann via <baumann@rasdaman.com>.
+ *
+ * Copyright 2009 Jacobs University Bremen, Peter Baumann.
+ */
+
+
+package wcps.server.test;
+
+//~--- non-JDK imports --------------------------------------------------------
+
+import org.apache.commons.io.FileUtils;
+
+//~--- JDK imports ------------------------------------------------------------
+
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import wcps.server.cli.grammar;
+import wcps.server.cli.xml;
+
+/**
+ * Runs all available tests against a deployed version of Petascope,
+ * available at some URL. In particular, here are the steps for each test:
+ * 1) Convert abstract syntax query to XML query
+ * 2) Convert XML query to a RasQL query
+ * 3) Send abstract syntax query to PetaScope WCPS
+ * 4) Send XML query to PetaScope WCPS
+ *
+ * Assumes that a tests succeeds if the server does not throw or display
+ * an error. Saves the intermediate results in a specified path.
+ *
+ * @author Andrei Aiordachioaie
+ */
+public class FullTestsOnline
+{
+ public final String PetascopeURL = "http://localhost:8080/PetaScope/WCPService";
+// public final String PetascopeURL = "http://localhost:8080/petascope/wcps/";
+// public final String PetascopeURL = "http://kahlua.eecs.jacobs-university.de:8080/petascope/wcps/";
+
+ // Tests are read from this folder
+ String folder = "test/testcases-wcps/";
+ // How many tests we have to run
+ int numTests = 0;
+ // Files are written in this folder
+ String outputFolder = "test/test-tmp/";
+ // How many successes?
+ int passCount = 0;
+ // message for tests
+ String[][] errors;
+ // success code
+ boolean[] ok;
+ // partial success codes
+ boolean[][] partialOk;
+ // queries
+ String[] queries;
+ // tests
+ File[] tests;
+
+ public FullTestsOnline()
+ {
+ // Find out how many grammar tests we have to run
+ File dir = new File(folder);
+ System.out.println("Looking for tests in " + dir.getAbsolutePath() + "\n");
+ TestFileFilter filter = new TestFileFilter();
+ tests = dir.listFiles(filter);
+ numTests = tests.length;
+
+ ok = new boolean[numTests];
+ partialOk = new boolean[5][numTests];
+ errors = new String[5][numTests];
+ queries = new String[numTests];
+ }
+
+ public void printResults()
+ {
+ HashMap strMap = new HashMap<Boolean,String>();
+ strMap.put(true, "ok");
+ strMap.put(false, "failed");
+
+ System.out.println("\n \nRESULTS \n");
+
+ for (int i = 0; i < numTests; i++)
+ {
+ String tname = tests[i].getName();
+ tname = tname.substring(0, tname.length() - 5);
+
+ if ( ok[i] == true )
+ {
+ System.out.println("*** Test '" + tname + "' ok");
+// System.out.println("\t" + queries[i]);
+ }
+ else
+ {
+ System.out.println("*** Test '" + tname + "' FAILED");
+ System.out.println("\t * Abstract Syntax -> Xml: " + strMap.get(partialOk[1][i]));
+ if (partialOk[1][i] == false)
+ System.out.println("\t\t" + errors[1][i]);
+// System.out.println("\t * Xml -> RasQL: " + strMap.get(partialOk[2][i]));
+// if (partialOk[2][i] == false)
+// System.out.println("\t\t" + errors[2][i]);
+ System.out.println("\t * Running Abstract Syntax query: " + strMap.get(partialOk[3][i]));
+ if (partialOk[3][i] == false)
+ System.out.println("\t\t" + errors[3][i]);
+ System.out.println("\t * Running XML query: " + strMap.get(partialOk[4][i]));
+ if (partialOk[4][i] == false)
+ System.out.println("\t\t" + errors[4][i]);
+ }
+ }
+ System.out.println("\n\nRESULTS\n");
+ System.out.println("Tested PetaScope implementation from: " + PetascopeURL);
+ System.out.println("Tests succeeded: " + String.valueOf(passCount));
+ System.out.println("Tests failed: " + String.valueOf(numTests - passCount));
+ }
+
+ public void runAllTests()
+ {
+ String abstractQuery = "";
+ String xmlQuery = "";
+ String rasqlQuery = "";
+ String tname = "";
+
+ for (int i = 0; i < numTests; i++)
+ {
+ ok[i] = false;
+ partialOk[1][i] = false;
+ partialOk[2][i] = true;
+ partialOk[3][i] = false;
+ partialOk[4][i] = false;
+ errors[1][i] = "";
+ errors[2][i] = "";
+ errors[3][i] = "";
+ errors[4][i] = "";
+
+ tname = tests[i].getName();
+ tname = tname.substring(0, tname.length() - 5);
+ System.out.println("Running test '" + tname + "'...");
+ // First of all: read file contents
+ try
+ {
+ abstractQuery = FileUtils.readFileToString(tests[i]);
+ queries[i] = abstractQuery;
+ }
+ catch (IOException e)
+ {
+ errors[1][i] = "Could not read file " + tests[i].getName();
+ continue;
+ }
+ // Step 1: Convert abstract syntax query to XML query, and save files
+ try
+ {
+ xmlQuery = grammar.convertAbstractQueryToXml(abstractQuery);
+ // Copy abstract syntax query to output folder
+ File abstractFile = new File(outputFolder + tname + ".test");
+ FileUtils.writeStringToFile(abstractFile, abstractQuery);
+ // Save XML query to a file in output folder
+ File xmlFile = new File(outputFolder + tname + ".xml");
+ FileUtils.writeStringToFile(xmlFile, xmlQuery);
+
+ partialOk[1][i] = true;
+ }
+ catch (Exception e)
+ {
+ errors[1][i] = e.getMessage();
+ }
+ // Step 2: Convert XML query to RasQL query, and save files
+// try
+// {
+// rasqlQuery = xml.convertXmlToRasql(xmlQuery);
+// // Save XML query to a file in output folder
+// File rasqlFile = new File(outputFolder + tname + ".rasql");
+// FileUtils.writeStringToFile(rasqlFile, rasqlQuery);
+//
+// partialOk[2][i] = true;
+// }
+// catch (Exception e)
+// {
+// errors[2][i] = e.getMessage();
+// }
+ // Step 3: Send abstract syntax query to PetaScope WCPS
+ try
+ {
+ String err = runOneTest("query", abstractQuery);
+
+ if ( err == null )
+ partialOk[3][i] = true;
+ else
+ errors[3][i] = err;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ // Step 4: Send XML query to PetaScope WCPS
+ try
+ {
+ String err = runOneTest("xml", xmlQuery);
+
+ if ( err == null )
+ partialOk[4][i] = true;
+ else
+ errors[4][i] = err;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ // Wrap up
+ ok[i] = partialOk[1][i] && partialOk[2][i] && partialOk[3][i] && partialOk[4][i];
+ if ( ok[i] == true )
+ passCount++;
+ }
+ }
+
+ /**
+ * Send an request to the WCPS server.
+ * Returns a message on error and null otherwise.
+ */
+ public String runOneTest(String param, String query) throws MalformedURLException, IOException
+ {
+// System.out.println("--------------------");
+// System.out.println(query);
+// System.out.println("\t--------------------");
+
+ // connect to the servlet
+ URL servlet = new URL(PetascopeURL);
+ HttpURLConnection conn = (HttpURLConnection) servlet.openConnection();
+
+ // inform the connection that we will send output and accept input
+ conn.setDoInput(true);
+ conn.setDoOutput(true);
+
+ // Don't use a cached version of URL connection.
+ conn.setUseCaches(false);
+ conn.setDefaultUseCaches(false);
+
+ // Send POST request
+ conn.setRequestMethod("POST");
+
+ // Specify the content type that we will send binary data
+ conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+
+ String data = param + "=" + URLEncoder.encode(query);
+ DataOutputStream out = new DataOutputStream(conn.getOutputStream());
+
+ out.writeBytes(data);
+ out.flush();
+ out.close();
+
+ BufferedReader cgiOutput = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+ String line1 = cgiOutput.readLine();
+ String line2 = cgiOutput.readLine();
+ String line3 = cgiOutput.readLine();
+
+ System.out.println("\t" + line1);
+ System.out.println("\t" + line2);
+ System.out.println("\t" + line3);
+
+ if ( (line1 != null) && (line2 != null) && (line3 != null) && line2.equals("<h1>An error has occured</h1>") )
+ {
+ while (cgiOutput.ready())
+ System.out.println("\t" + cgiOutput.readLine());
+// System.out.println("Error executing query: ");
+ String error = line3.substring(10, line3.length() - 4);
+
+// System.out.println("\t" + error);
+ return error;
+ }
+ else
+ return null;
+
+ }
+
+ public static void main(String args[])
+ {
+ FullTestsOnline tester = new FullTestsOnline();
+
+ tester.runAllTests();
+ tester.printResults();
+ }
+
+ /* Accept all files with extension TEST. */
+ private class TestFileFilter implements FilenameFilter
+ {
+ @Override
+ public boolean accept(File dir, String name)
+ {
+ if ( name.endsWith("test") )
+ {
+ return true;
+ }
+
+ return false;
+ }
+ }
+
+}
diff --git a/src/wcps/server/test/GrammarTest.java b/src/wcps/server/test/GrammarTest.java
index 5ee33eb..d213777 100644
--- a/src/wcps/server/test/GrammarTest.java
+++ b/src/wcps/server/test/GrammarTest.java
@@ -37,7 +37,7 @@ import wcps.server.cli.grammar;
public class GrammarTest
{
// Put new test cases in this folder following the current naming scheme
- String folder = "test/testcases-wcps/";
+ String folder = "test/testcases-wcps_dollar/";
// How many tests we have to run
int numTests = 0;
// tests
@@ -119,7 +119,7 @@ public class GrammarTest
}
try
{
- grammar.runQuery(query);
+ grammar.convertAbstractQueryToXml(query);
ok[i] = true;
}
catch (Exception e)
diff --git a/src/wcps/server/test/GrammarTestOnline.java b/src/wcps/server/test/GrammarTestOnline.java
index fb7388e..8cdc73f 100644
--- a/src/wcps/server/test/GrammarTestOnline.java
+++ b/src/wcps/server/test/GrammarTestOnline.java
@@ -47,7 +47,7 @@ public class GrammarTestOnline {
// Put new test cases in this folder
// public final String PetascopeURL = "http://localhost:8080/PetaScope/WCPService";
// public final String PetascopeURL = "http://localhost:8080/petascope/wcps/";
- public final String PetascopeURL = "http://kahlua.eecs.jacobs-university.de:8080/petascope/wcps/";
+ public final String PetascopeURL = "http://kahlua.eecs.jacobs-university.de:8080/petascope-new/wcps/";
String folder = "test/testcases-wcps/";
// How many tests we have to run
@@ -81,6 +81,7 @@ public class GrammarTestOnline {
}
}
System.out.println("\n\nRESULTS\n");
+ System.out.println("Tested PetaScope implementation from: " + PetascopeURL);
System.out.println("Tests succeeded: " + String.valueOf(passCount));
System.out.println("Tests failed: " + String.valueOf(numTests - passCount));
}
@@ -89,7 +90,7 @@ public class GrammarTestOnline {
// Find out how many tests we have to run
File dir = new File(folder);
System.out.println("Looking for tests in " + dir.getAbsolutePath() + "\n");
- XmlFileFilter filter = new XmlFileFilter();
+ TestFileFilter filter = new TestFileFilter();
tests = dir.listFiles(filter);
numTests = tests.length;
// numTests = 3;
@@ -99,7 +100,7 @@ public class GrammarTestOnline {
}
/* Accept all files with extension TEST. */
- private class XmlFileFilter implements FilenameFilter {
+ private class TestFileFilter implements FilenameFilter {
@Override
public boolean accept(File dir, String name) {
diff --git a/src/wcps/server/test/XmlTestOnline.java b/src/wcps/server/test/XmlTestOnline.java
index 5727df8..752c3c2 100644
--- a/src/wcps/server/test/XmlTestOnline.java
+++ b/src/wcps/server/test/XmlTestOnline.java
@@ -46,7 +46,7 @@ public class XmlTestOnline {
// Put new test cases in this folder
// public final String PetascopeURL = "http://localhost:8080/PetaScope/WCPService";
// public final String PetascopeURL = "http://localhost:8080/petascope/wcps/";
- public final String PetascopeURL = "http://kahlua.eecs.jacobs-university.de:8080/petascope/wcps/";
+ public final String PetascopeURL = "http://kahlua.eecs.jacobs-university.de:8080/petascope-new/wcps/";
String folder = "test/testcases-wcps/";
// How many tests we have to run
@@ -68,7 +68,7 @@ public class XmlTestOnline {
for (int i = 0; i < numTests; i++) {
String tname = tests[i].getName();
- tname = tname.substring(0, tname.length() - 9);
+ tname = tname.substring(0, tname.length() - 4);
if (ok[i] == true)
{
System.out.println("*** Test '" + tname + "' ok");
@@ -80,6 +80,7 @@ public class XmlTestOnline {
}
}
System.out.println("\n\nRESULTS\n");
+ System.out.println("Tested PetaScope implementation from: " + PetascopeURL);
System.out.println("Tests succeeded: " + String.valueOf(passCount));
System.out.println("Tests failed: " + String.valueOf(numTests - passCount));
}
@@ -116,7 +117,7 @@ public class XmlTestOnline {
{
ok[i] = false;
tname = tests[i].getName();
- tname = tname.substring(0, tname.length() - 9);
+ tname = tname.substring(0, tname.length() - 4);
System.out.println("Running test '" + tname + "'...");
try {
query = FileUtils.readFileToString(tests[i]);