[mapguide-commits] r8507 - in trunk/Tools/Maestro: OSGeo.MapGuide.MaestroAPI.Expressions OSGeo.MapGuide.MaestroAPI.Tests
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Mon Jan 19 03:25:58 PST 2015
Author: jng
Date: 2015-01-19 03:25:57 -0800 (Mon, 19 Jan 2015)
New Revision: 8507
Added:
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoBinaryLogicalOperator.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoComparisonCondition.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoDistanceCondition.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoGeometricCondition.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoInCondition.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoLogicalOperator.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoNullCondition.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoSearchCondition.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoSpatialCondition.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoUnaryLogicalOperator.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/FilterTests.cs
Modified:
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoExpression.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoFilter.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoFilterGrammar.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoFunction.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/OSGeo.MapGuide.MaestroAPI.Expressions.csproj
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/ExpressionTests.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/OSGeo.MapGuide.MaestroAPI.Tests.csproj
Log:
#2525: Add filter parsing support with some tests to exercise parsing
Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoBinaryLogicalOperator.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoBinaryLogicalOperator.cs (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoBinaryLogicalOperator.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -0,0 +1,62 @@
+#region Disclaimer / License
+
+// Copyright (C) 2015, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+//
+// This library 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 2.1 of the License, or (at your option) any later version.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#endregion Disclaimer / License
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.MaestroAPI.Expressions
+{
+ public enum BinaryLogicalOperations
+ {
+ And,
+ Or
+ }
+
+ public class FdoBinaryLogicalOperator : FdoLogicalOperator
+ {
+ public FdoFilter Left { get; private set; }
+
+ public BinaryLogicalOperations Operator { get; private set; }
+
+ public FdoFilter Right { get; private set; }
+
+ public FdoBinaryLogicalOperator(Irony.Parsing.ParseTreeNode node)
+ {
+ this.Left = FdoFilter.ParseNode(node.ChildNodes[0]);
+ var opName = node.ChildNodes[1].ChildNodes[0].Token.ValueString;
+ switch (opName.ToUpper())
+ {
+ case "AND":
+ this.Operator = BinaryLogicalOperations.And;
+ break;
+ case "OR":
+ this.Operator = BinaryLogicalOperations.Or;
+ break;
+ default:
+ throw new FdoParseException("Unknown operator: " + opName);
+ }
+ this.Right = FdoFilter.ParseNode(node.ChildNodes[2]);
+ }
+ }
+}
Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoComparisonCondition.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoComparisonCondition.cs (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoComparisonCondition.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -0,0 +1,83 @@
+#region Disclaimer / License
+
+// Copyright (C) 2015, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+//
+// This library 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 2.1 of the License, or (at your option) any later version.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#endregion Disclaimer / License
+using Irony.Parsing;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.MaestroAPI.Expressions
+{
+ public enum ComparisonOperations
+ {
+ EqualsTo,
+ NotEqualsTo,
+ GreaterThan,
+ GreaterThanOrEqualTo,
+ LessThan,
+ LessThanOrEqualTo,
+ Like
+ }
+
+ public class FdoComparisonCondition : FdoSearchCondition
+ {
+ public FdoExpression Left { get; private set; }
+
+ public ComparisonOperations Operator { get; private set; }
+
+ public FdoExpression Right { get; private set; }
+
+ public FdoComparisonCondition(ParseTreeNode node)
+ {
+ this.Left = FdoExpression.ParseNode(node.ChildNodes[0]);
+ var opName = node.ChildNodes[1].ChildNodes[0].Token.ValueString;
+ switch (opName.ToUpper())
+ {
+ case "=":
+ this.Operator = ComparisonOperations.EqualsTo;
+ break;
+ case "<>":
+ this.Operator = ComparisonOperations.NotEqualsTo;
+ break;
+ case ">":
+ this.Operator = ComparisonOperations.GreaterThan;
+ break;
+ case ">=":
+ this.Operator = ComparisonOperations.GreaterThanOrEqualTo;
+ break;
+ case "<":
+ this.Operator = ComparisonOperations.LessThan;
+ break;
+ case "<=":
+ this.Operator = ComparisonOperations.LessThanOrEqualTo;
+ break;
+ case "LIKE":
+ this.Operator = ComparisonOperations.Like;
+ break;
+ default:
+ throw new FdoParseException("Unknown operator: " + opName);
+ }
+ this.Right = FdoExpression.ParseNode(node.ChildNodes[2]);
+ }
+ }
+}
Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoDistanceCondition.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoDistanceCondition.cs (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoDistanceCondition.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -0,0 +1,66 @@
+#region Disclaimer / License
+
+// Copyright (C) 2015, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+//
+// This library 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 2.1 of the License, or (at your option) any later version.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#endregion Disclaimer / License
+using Irony.Parsing;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.MaestroAPI.Expressions
+{
+ public enum DistanceOperations
+ {
+ Beyond,
+ WithinDistance
+ }
+
+ public class FdoDistanceCondition : FdoGeometricCondition
+ {
+ public FdoIdentifier Identifier { get; private set; }
+
+ public DistanceOperations Operator { get; private set; }
+
+ public FdoExpression Expression { get; private set; }
+
+ public FdoDataValue Distance { get; private set; }
+
+ internal FdoDistanceCondition(ParseTreeNode node)
+ {
+ this.Identifier = new FdoIdentifier(node.ChildNodes[0]);
+ var opName = node.ChildNodes[1].ChildNodes[0].Token.ValueString;
+ switch(opName.ToUpper())
+ {
+ case "WITHINDISTANCE":
+ this.Operator = DistanceOperations.WithinDistance;
+ break;
+ case "BEYOND":
+ this.Operator = DistanceOperations.Beyond;
+ break;
+ default:
+ throw new FdoParseException("Unknown operator: " + opName);
+ }
+ this.Expression = FdoExpression.ParseNode(node.ChildNodes[2]);
+ this.Distance = FdoDataValue.ParseDataNode(node.ChildNodes[3].ChildNodes[0]);
+ }
+ }
+}
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoExpression.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoExpression.cs 2015-01-18 16:20:44 UTC (rev 8506)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoExpression.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -45,7 +45,7 @@
}
}
- protected static FdoExpression ParseNode(ParseTreeNode child)
+ internal static FdoExpression ParseNode(ParseTreeNode child)
{
if (child.Term.Name == FdoTerminalNames.Expression)
{
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoFilter.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoFilter.cs 2015-01-18 16:20:44 UTC (rev 8506)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoFilter.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -19,6 +19,7 @@
//
#endregion Disclaimer / License
+using Irony.Parsing;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -27,7 +28,41 @@
namespace OSGeo.MapGuide.MaestroAPI.Expressions
{
- public class FdoFilter
+ public abstract class FdoFilter
{
+ public static FdoFilter Parse(string str)
+ {
+ Parser p = new Parser(new FdoFilterGrammar());
+ var tree = p.Parse(str);
+ if (tree.Root.Term.Name == FdoTerminalNames.Filter)
+ {
+ var child = tree.Root.ChildNodes[0];
+ return ParseNode(child);
+ }
+ else
+ {
+ throw new FdoParseException();
+ }
+ }
+
+ internal static FdoFilter ParseNode(ParseTreeNode child)
+ {
+ if (child.Term.Name == FdoTerminalNames.Filter)
+ {
+ return ParseNode(child.ChildNodes[0]);
+ }
+ else
+ {
+ switch (child.Term.Name)
+ {
+ case FdoTerminalNames.LogicalOperator:
+ return FdoLogicalOperator.ParseLogicalOperatorNode(child);
+ case FdoTerminalNames.SearchCondition:
+ return FdoSearchCondition.ParseSearchNode(child);
+ default:
+ throw new FdoParseException("Unknown terminal: " + child.Term.Name);
+ }
+ }
+ }
}
}
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoFilterGrammar.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoFilterGrammar.cs 2015-01-18 16:20:44 UTC (rev 8506)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoFilterGrammar.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -97,9 +97,9 @@
DistanceCondition |
SpatialCondition;
DistanceCondition.Rule = Identifier + DistanceOperations + Expression + Distance;
- NullCondition.Rule = Identifier + "NULL";
+ NullCondition.Rule = Identifier + ToTerm("NULL");
SpatialCondition.Rule = Identifier + SpatialOperations + Expression;
- UnaryLogicalOperator.Rule = "NOT" + Filter;
+ UnaryLogicalOperator.Rule = ToTerm("NOT") + Filter;
BinaryLogicalOperations.Rule =
ToTerm("AND") |
ToTerm("OR");
@@ -150,9 +150,11 @@
String |
//Blob |
//Clob |
- "NULL" |
- "TRUE" |
- "FALSE";
+ Boolean |
+ "NULL";
+ Boolean.Rule =
+ ToTerm("TRUE") |
+ ToTerm("FALSE");
DateTime.Rule =
"DATE" + String |
"TIME" + String |
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoFunction.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoFunction.cs 2015-01-18 16:20:44 UTC (rev 8506)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoFunction.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -30,13 +30,13 @@
{
public class FdoFunction : FdoExpression
{
- public string Name { get; private set; }
+ public FdoIdentifier Identifier { get; private set; }
public List<FdoExpression> Arguments { get; private set; }
internal FdoFunction(ParseTreeNode node)
{
- this.Name = node.ChildNodes[0].Token.Text;
+ this.Identifier = new FdoIdentifier(node.ChildNodes[0]);
this.Arguments = new List<FdoExpression>();
ProcessArguments(node.ChildNodes[1]);
}
Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoGeometricCondition.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoGeometricCondition.cs (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoGeometricCondition.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -0,0 +1,53 @@
+#region Disclaimer / License
+
+// Copyright (C) 2015, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+//
+// This library 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 2.1 of the License, or (at your option) any later version.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#endregion Disclaimer / License
+using Irony.Parsing;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.MaestroAPI.Expressions
+{
+ public abstract class FdoGeometricCondition : FdoSearchCondition
+ {
+ internal static FdoSearchCondition ParseGeometricNode(ParseTreeNode node)
+ {
+ if (node.Term.Name == FdoTerminalNames.GeometricCondition)
+ {
+ return ParseGeometricNode(node.ChildNodes[0]);
+ }
+ else
+ {
+ switch (node.Term.Name)
+ {
+ case FdoTerminalNames.DistanceCondition:
+ return new FdoDistanceCondition(node);
+ case FdoTerminalNames.SpatialCondition:
+ return new FdoSpatialCondition(node);
+ default:
+ throw new FdoParseException("Unknown terminal: " + node.Term.Name);
+ }
+ }
+ }
+ }
+}
Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoInCondition.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoInCondition.cs (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoInCondition.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -0,0 +1,64 @@
+#region Disclaimer / License
+
+// Copyright (C) 2015, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+//
+// This library 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 2.1 of the License, or (at your option) any later version.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#endregion Disclaimer / License
+using Irony.Parsing;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.MaestroAPI.Expressions
+{
+ public class FdoInCondition : FdoSearchCondition
+ {
+ public FdoIdentifier Identifier { get; private set; }
+
+ public List<FdoValueExpression> ValueList { get; private set; }
+
+ public FdoInCondition(ParseTreeNode node)
+ {
+ this.Identifier = new FdoIdentifier(node.ChildNodes[0]);
+ this.ValueList = new List<FdoValueExpression>();
+ ProcessValueList(node.ChildNodes[2]);
+ }
+
+ private void ProcessNodeList(ParseTreeNodeList list)
+ {
+ foreach (ParseTreeNode child in list)
+ {
+ if (child.Term.Name == FdoTerminalNames.ValueExpressionCollection)
+ {
+ ProcessNodeList(child.ChildNodes);
+ }
+ else
+ {
+ this.ValueList.Add(FdoValueExpression.ParseValueNode(child));
+ }
+ }
+ }
+
+ private void ProcessValueList(ParseTreeNode node)
+ {
+ ProcessNodeList(node.ChildNodes);
+ }
+ }
+}
Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoLogicalOperator.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoLogicalOperator.cs (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoLogicalOperator.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -0,0 +1,53 @@
+#region Disclaimer / License
+
+// Copyright (C) 2015, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+//
+// This library 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 2.1 of the License, or (at your option) any later version.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#endregion Disclaimer / License
+using Irony.Parsing;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.MaestroAPI.Expressions
+{
+ public abstract class FdoLogicalOperator : FdoFilter
+ {
+ internal static FdoLogicalOperator ParseLogicalOperatorNode(ParseTreeNode node)
+ {
+ if (node.Term.Name == FdoTerminalNames.LogicalOperator)
+ {
+ return ParseLogicalOperatorNode(node.ChildNodes[0]);
+ }
+ else
+ {
+ switch (node.Term.Name)
+ {
+ case FdoTerminalNames.BinaryLogicalOperator:
+ return new FdoBinaryLogicalOperator(node);
+ case FdoTerminalNames.UnaryLogicalOperator:
+ return new FdoUnaryLogicalOperator(node);
+ default:
+ throw new FdoParseException("Unknown terminal: " + node.Term.Name);
+ }
+ }
+ }
+ }
+}
Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoNullCondition.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoNullCondition.cs (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoNullCondition.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -0,0 +1,40 @@
+#region Disclaimer / License
+
+// Copyright (C) 2015, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+//
+// This library 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 2.1 of the License, or (at your option) any later version.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#endregion Disclaimer / License
+using Irony.Parsing;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.MaestroAPI.Expressions
+{
+ public class FdoNullCondition : FdoSearchCondition
+ {
+ public FdoIdentifier Identifier { get; private set; }
+
+ public FdoNullCondition(ParseTreeNode node)
+ {
+ this.Identifier = new FdoIdentifier(node.ChildNodes[0]);
+ }
+ }
+}
Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoSearchCondition.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoSearchCondition.cs (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoSearchCondition.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -0,0 +1,57 @@
+#region Disclaimer / License
+
+// Copyright (C) 2015, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+//
+// This library 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 2.1 of the License, or (at your option) any later version.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#endregion Disclaimer / License
+using Irony.Parsing;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.MaestroAPI.Expressions
+{
+ public abstract class FdoSearchCondition : FdoFilter
+ {
+ internal static FdoSearchCondition ParseSearchNode(ParseTreeNode node)
+ {
+ if (node.Term.Name == FdoTerminalNames.SearchCondition)
+ {
+ return ParseSearchNode(node.ChildNodes[0]);
+ }
+ else
+ {
+ switch (node.Term.Name)
+ {
+ case FdoTerminalNames.InCondition:
+ return new FdoInCondition(node);
+ case FdoTerminalNames.ComparisonCondition:
+ return new FdoComparisonCondition(node);
+ case FdoTerminalNames.GeometricCondition:
+ return FdoGeometricCondition.ParseGeometricNode(node);
+ case FdoTerminalNames.NullCondition:
+ return new FdoNullCondition(node);
+ default:
+ throw new FdoParseException("Unknown terminal: " + node.Term.Name);
+ }
+ }
+ }
+ }
+}
Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoSpatialCondition.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoSpatialCondition.cs (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoSpatialCondition.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -0,0 +1,95 @@
+#region Disclaimer / License
+
+// Copyright (C) 2015, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+//
+// This library 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 2.1 of the License, or (at your option) any later version.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#endregion Disclaimer / License
+using Irony.Parsing;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.MaestroAPI.Expressions
+{
+ public enum SpatialOperations
+ {
+ Contains,
+ Crosses,
+ Disjoint,
+ Equals,
+ Intersects,
+ Overlaps,
+ Touches,
+ Within,
+ CoveredBy,
+ Inside
+ }
+
+ public class FdoSpatialCondition : FdoGeometricCondition
+ {
+ public FdoIdentifier Identifier { get; private set; }
+
+ public SpatialOperations Operator { get; private set; }
+
+ public FdoExpression Expression { get; private set; }
+
+ internal FdoSpatialCondition(ParseTreeNode node)
+ {
+ this.Identifier = new FdoIdentifier(node.ChildNodes[0]);
+ var opName = node.ChildNodes[1].ChildNodes[0].Token.ValueString;
+ switch (opName.ToUpper())
+ {
+ case "CONTAINS":
+ this.Operator = SpatialOperations.Contains;
+ break;
+ case "CROSSES":
+ this.Operator = SpatialOperations.Crosses;
+ break;
+ case "DISJOINT":
+ this.Operator = SpatialOperations.Disjoint;
+ break;
+ case "EQUALS":
+ this.Operator = SpatialOperations.Equals;
+ break;
+ case "INTERSECTS":
+ this.Operator = SpatialOperations.Intersects;
+ break;
+ case "OVERLAPS":
+ this.Operator = SpatialOperations.Overlaps;
+ break;
+ case "TOUCHES":
+ this.Operator = SpatialOperations.Touches;
+ break;
+ case "WITHIN":
+ this.Operator = SpatialOperations.Within;
+ break;
+ case "COVEREDBY":
+ this.Operator = SpatialOperations.CoveredBy;
+ break;
+ case "INSIDE":
+ this.Operator = SpatialOperations.Inside;
+ break;
+ default:
+ throw new FdoParseException("Unknown operator: " + opName);
+ }
+ this.Expression = FdoExpression.ParseNode(node.ChildNodes[2]);
+ }
+ }
+}
Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoUnaryLogicalOperator.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoUnaryLogicalOperator.cs (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/FdoUnaryLogicalOperator.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -0,0 +1,40 @@
+#region Disclaimer / License
+
+// Copyright (C) 2015, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+//
+// This library 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 2.1 of the License, or (at your option) any later version.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#endregion Disclaimer / License
+using Irony.Parsing;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.MaestroAPI.Expressions
+{
+ public class FdoUnaryLogicalOperator : FdoLogicalOperator
+ {
+ public FdoFilter NegatedFilter { get; private set; }
+
+ public FdoUnaryLogicalOperator(ParseTreeNode node)
+ {
+ this.NegatedFilter = FdoFilter.ParseNode(node.ChildNodes[1]);
+ }
+ }
+}
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/OSGeo.MapGuide.MaestroAPI.Expressions.csproj
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/OSGeo.MapGuide.MaestroAPI.Expressions.csproj 2015-01-18 16:20:44 UTC (rev 8506)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Expressions/OSGeo.MapGuide.MaestroAPI.Expressions.csproj 2015-01-19 11:25:57 UTC (rev 8507)
@@ -56,19 +56,29 @@
<Link>SignedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="FdoBinaryExpression.cs" />
+ <Compile Include="FdoBinaryLogicalOperator.cs" />
+ <Compile Include="FdoComparisonCondition.cs" />
<Compile Include="FdoDataValue.cs" />
+ <Compile Include="FdoDistanceCondition.cs" />
<Compile Include="FdoExpression.cs" />
<Compile Include="FdoExpressionGrammar.cs" />
<Compile Include="FdoFilterGrammar.cs" />
<Compile Include="FdoFilter.cs" />
<Compile Include="FdoFunction.cs" />
+ <Compile Include="FdoGeometricCondition.cs" />
<Compile Include="FdoGeometryValue.cs" />
<Compile Include="FdoIdentifier.cs" />
+ <Compile Include="FdoInCondition.cs" />
<Compile Include="FdoLiteralValue.cs" />
+ <Compile Include="FdoLogicalOperator.cs" />
+ <Compile Include="FdoNullCondition.cs" />
<Compile Include="FdoParameter.cs" />
<Compile Include="FdoParseException.cs" />
+ <Compile Include="FdoSearchCondition.cs" />
+ <Compile Include="FdoSpatialCondition.cs" />
<Compile Include="FdoTerminalNames.cs" />
<Compile Include="FdoUnaryExpression.cs" />
+ <Compile Include="FdoUnaryLogicalOperator.cs" />
<Compile Include="FdoValueExpression.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/ExpressionTests.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/ExpressionTests.cs 2015-01-18 16:20:44 UTC (rev 8506)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/ExpressionTests.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -141,12 +141,12 @@
expr = FdoExpression.Parse("CurrentDate()");
Assert.IsInstanceOf<FdoFunction>(expr);
- Assert.AreEqual("CurrentDate", ((FdoFunction)expr).Name);
+ Assert.AreEqual("CurrentDate", ((FdoFunction)expr).Identifier.Name);
Assert.AreEqual(0, ((FdoFunction)expr).Arguments.Count);
expr = FdoExpression.Parse("Concat(RNAME, ' ', RBILAD)");
Assert.IsInstanceOf<FdoFunction>(expr);
- Assert.AreEqual("Concat", ((FdoFunction)expr).Name);
+ Assert.AreEqual("Concat", ((FdoFunction)expr).Identifier.Name);
Assert.AreEqual(3, ((FdoFunction)expr).Arguments.Count);
Assert.IsInstanceOf<FdoIdentifier>(((FdoFunction)expr).Arguments[0]);
Assert.IsInstanceOf<FdoStringValue>(((FdoFunction)expr).Arguments[1]);
Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/FilterTests.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/FilterTests.cs (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/FilterTests.cs 2015-01-19 11:25:57 UTC (rev 8507)
@@ -0,0 +1,380 @@
+#region Disclaimer / License
+
+// Copyright (C) 2015, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+//
+// This library 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 2.1 of the License, or (at your option) any later version.
+//
+// This library 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 this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+#endregion Disclaimer / License
+using NUnit.Framework;
+using OSGeo.MapGuide.MaestroAPI.Expressions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.MaestroAPI.Tests
+{
+ [TestFixture]
+ public class FilterTests
+ {
+ [Test]
+ public void TestFilterParse()
+ {
+ FdoFilter filter = null;
+ FdoFilter left = null;
+ FdoFilter right = null;
+
+ filter = FdoFilter.Parse("A = 'B'");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.EqualsTo, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("(A = 'B')");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.EqualsTo, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("A <> 'B'");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.NotEqualsTo, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("(A <> 'B')");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.NotEqualsTo, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("A > 2.3");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.GreaterThan, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("(A > 2.3)");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.GreaterThan, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("A >= 2.3");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.GreaterThanOrEqualTo, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("(A >= 2.3)");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.GreaterThanOrEqualTo, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("A < 2.3");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.LessThan, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("(A < 2.3)");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.LessThan, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("A <= 2.3");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.LessThanOrEqualTo, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("(A <= 2.3)");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.LessThanOrEqualTo, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("A LIKE 'B%'");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.Like, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("(A LIKE 'B%')");
+ Assert.IsInstanceOf<FdoComparisonCondition>(filter);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)filter).Left);
+ Assert.AreEqual(ComparisonOperations.Like, ((FdoComparisonCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)filter).Right);
+
+ filter = FdoFilter.Parse("NOT (A LIKE 'B%')");
+ Assert.IsInstanceOf<FdoUnaryLogicalOperator>(filter);
+ var subExpr = ((FdoUnaryLogicalOperator)filter).NegatedFilter;
+ Assert.IsInstanceOf<FdoComparisonCondition>(subExpr);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)subExpr).Left);
+ Assert.AreEqual(ComparisonOperations.Like, ((FdoComparisonCondition)subExpr).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)subExpr).Right);
+
+ filter = FdoFilter.Parse("NAME NULL");
+ Assert.IsInstanceOf<FdoNullCondition>(filter);
+ Assert.AreEqual("NAME", ((FdoNullCondition)filter).Identifier.Name);
+
+ filter = FdoFilter.Parse("NOT NAME NULL");
+ Assert.IsInstanceOf<FdoUnaryLogicalOperator>(filter);
+ subExpr = ((FdoUnaryLogicalOperator)filter).NegatedFilter;
+ Assert.AreEqual("NAME", ((FdoNullCondition)subExpr).Identifier.Name);
+
+ filter = FdoFilter.Parse("A = 'B' OR B = 'C'");
+ left = ((FdoBinaryLogicalOperator)filter).Left;
+ right = ((FdoBinaryLogicalOperator)filter).Right;
+ Assert.IsInstanceOf<FdoBinaryLogicalOperator>(filter);
+ Assert.IsInstanceOf<FdoComparisonCondition>(left);
+ Assert.AreEqual(BinaryLogicalOperations.Or, ((FdoBinaryLogicalOperator)filter).Operator);
+ Assert.IsInstanceOf<FdoComparisonCondition>(right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)left).Left);
+ Assert.AreEqual(ComparisonOperations.EqualsTo, ((FdoComparisonCondition)left).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)left).Right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)right).Left);
+ Assert.AreEqual(ComparisonOperations.EqualsTo, ((FdoComparisonCondition)right).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)right).Right);
+
+ filter = FdoFilter.Parse("A = 'B' AND B = 'C'");
+ left = ((FdoBinaryLogicalOperator)filter).Left;
+ right = ((FdoBinaryLogicalOperator)filter).Right;
+ Assert.IsInstanceOf<FdoBinaryLogicalOperator>(filter);
+ Assert.IsInstanceOf<FdoComparisonCondition>(left);
+ Assert.AreEqual(BinaryLogicalOperations.And, ((FdoBinaryLogicalOperator)filter).Operator);
+ Assert.IsInstanceOf<FdoComparisonCondition>(right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)left).Left);
+ Assert.AreEqual(ComparisonOperations.EqualsTo, ((FdoComparisonCondition)left).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)left).Right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)right).Left);
+ Assert.AreEqual(ComparisonOperations.EqualsTo, ((FdoComparisonCondition)right).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)right).Right);
+
+ filter = FdoFilter.Parse("(A = 'B') OR (B = 'C')");
+ left = ((FdoBinaryLogicalOperator)filter).Left;
+ right = ((FdoBinaryLogicalOperator)filter).Right;
+ Assert.IsInstanceOf<FdoBinaryLogicalOperator>(filter);
+ Assert.IsInstanceOf<FdoComparisonCondition>(left);
+ Assert.AreEqual(BinaryLogicalOperations.Or, ((FdoBinaryLogicalOperator)filter).Operator);
+ Assert.IsInstanceOf<FdoComparisonCondition>(right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)left).Left);
+ Assert.AreEqual(ComparisonOperations.EqualsTo, ((FdoComparisonCondition)left).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)left).Right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)right).Left);
+ Assert.AreEqual(ComparisonOperations.EqualsTo, ((FdoComparisonCondition)right).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)right).Right);
+
+ filter = FdoFilter.Parse("(A = 'B') AND (B = 'C')");
+ left = ((FdoBinaryLogicalOperator)filter).Left;
+ right = ((FdoBinaryLogicalOperator)filter).Right;
+ Assert.IsInstanceOf<FdoBinaryLogicalOperator>(filter);
+ Assert.IsInstanceOf<FdoComparisonCondition>(left);
+ Assert.AreEqual(BinaryLogicalOperations.And, ((FdoBinaryLogicalOperator)filter).Operator);
+ Assert.IsInstanceOf<FdoComparisonCondition>(right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)left).Left);
+ Assert.AreEqual(ComparisonOperations.EqualsTo, ((FdoComparisonCondition)left).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)left).Right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)right).Left);
+ Assert.AreEqual(ComparisonOperations.EqualsTo, ((FdoComparisonCondition)right).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)right).Right);
+
+ filter = FdoFilter.Parse("(A <> 'B') OR (B LIKE 'C%')");
+ left = ((FdoBinaryLogicalOperator)filter).Left;
+ right = ((FdoBinaryLogicalOperator)filter).Right;
+ Assert.IsInstanceOf<FdoBinaryLogicalOperator>(filter);
+ Assert.IsInstanceOf<FdoComparisonCondition>(left);
+ Assert.AreEqual(BinaryLogicalOperations.Or, ((FdoBinaryLogicalOperator)filter).Operator);
+ Assert.IsInstanceOf<FdoComparisonCondition>(right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)left).Left);
+ Assert.AreEqual(ComparisonOperations.NotEqualsTo, ((FdoComparisonCondition)left).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)left).Right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)right).Left);
+ Assert.AreEqual(ComparisonOperations.Like, ((FdoComparisonCondition)right).Operator);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoComparisonCondition)right).Right);
+
+ filter = FdoFilter.Parse("(A < 2.2) OR (B > 1.4)");
+ left = ((FdoBinaryLogicalOperator)filter).Left;
+ right = ((FdoBinaryLogicalOperator)filter).Right;
+ Assert.IsInstanceOf<FdoBinaryLogicalOperator>(filter);
+ Assert.IsInstanceOf<FdoComparisonCondition>(left);
+ Assert.AreEqual(BinaryLogicalOperations.Or, ((FdoBinaryLogicalOperator)filter).Operator);
+ Assert.IsInstanceOf<FdoComparisonCondition>(right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)left).Left);
+ Assert.AreEqual(ComparisonOperations.LessThan, ((FdoComparisonCondition)left).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)left).Right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)right).Left);
+ Assert.AreEqual(ComparisonOperations.GreaterThan, ((FdoComparisonCondition)right).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)right).Right);
+
+ filter = FdoFilter.Parse("(A < 2.2) AND (B > 1.4)");
+ left = ((FdoBinaryLogicalOperator)filter).Left;
+ right = ((FdoBinaryLogicalOperator)filter).Right;
+ Assert.IsInstanceOf<FdoBinaryLogicalOperator>(filter);
+ Assert.IsInstanceOf<FdoComparisonCondition>(left);
+ Assert.AreEqual(BinaryLogicalOperations.And, ((FdoBinaryLogicalOperator)filter).Operator);
+ Assert.IsInstanceOf<FdoComparisonCondition>(right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)left).Left);
+ Assert.AreEqual(ComparisonOperations.LessThan, ((FdoComparisonCondition)left).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)left).Right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)right).Left);
+ Assert.AreEqual(ComparisonOperations.GreaterThan, ((FdoComparisonCondition)right).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)right).Right);
+
+ filter = FdoFilter.Parse("(A <= 2.2) OR (B >= 1.4)");
+ left = ((FdoBinaryLogicalOperator)filter).Left;
+ right = ((FdoBinaryLogicalOperator)filter).Right;
+ Assert.IsInstanceOf<FdoBinaryLogicalOperator>(filter);
+ Assert.IsInstanceOf<FdoComparisonCondition>(left);
+ Assert.AreEqual(BinaryLogicalOperations.Or, ((FdoBinaryLogicalOperator)filter).Operator);
+ Assert.IsInstanceOf<FdoComparisonCondition>(right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)left).Left);
+ Assert.AreEqual(ComparisonOperations.LessThanOrEqualTo, ((FdoComparisonCondition)left).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)left).Right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)right).Left);
+ Assert.AreEqual(ComparisonOperations.GreaterThanOrEqualTo, ((FdoComparisonCondition)right).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)right).Right);
+
+ filter = FdoFilter.Parse("(A <= 2.2) AND (B >= 1.4)");
+ left = ((FdoBinaryLogicalOperator)filter).Left;
+ right = ((FdoBinaryLogicalOperator)filter).Right;
+ Assert.IsInstanceOf<FdoBinaryLogicalOperator>(filter);
+ Assert.IsInstanceOf<FdoComparisonCondition>(left);
+ Assert.AreEqual(BinaryLogicalOperations.And, ((FdoBinaryLogicalOperator)filter).Operator);
+ Assert.IsInstanceOf<FdoComparisonCondition>(right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)left).Left);
+ Assert.AreEqual(ComparisonOperations.LessThanOrEqualTo, ((FdoComparisonCondition)left).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)left).Right);
+ Assert.IsInstanceOf<FdoIdentifier>(((FdoComparisonCondition)right).Left);
+ Assert.AreEqual(ComparisonOperations.GreaterThanOrEqualTo, ((FdoComparisonCondition)right).Operator);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoComparisonCondition)right).Right);
+
+ filter = FdoFilter.Parse("A IN ('A', 'B', 'C')");
+ Assert.IsInstanceOf<FdoInCondition>(filter);
+ Assert.AreEqual("A", ((FdoInCondition)filter).Identifier.Name);
+ Assert.AreEqual(3, ((FdoInCondition)filter).ValueList.Count);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoInCondition)filter).ValueList[0]);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoInCondition)filter).ValueList[1]);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoInCondition)filter).ValueList[2]);
+
+ filter = FdoFilter.Parse("A IN (1, 2.0, '3', TRUE, FALSE)");
+ Assert.IsInstanceOf<FdoInCondition>(filter);
+ Assert.AreEqual("A", ((FdoInCondition)filter).Identifier.Name);
+ Assert.AreEqual(5, ((FdoInCondition)filter).ValueList.Count);
+ Assert.IsInstanceOf<FdoInt32Value>(((FdoInCondition)filter).ValueList[0]);
+ Assert.IsInstanceOf<FdoDoubleValue>(((FdoInCondition)filter).ValueList[1]);
+ Assert.IsInstanceOf<FdoStringValue>(((FdoInCondition)filter).ValueList[2]);
+ Assert.IsInstanceOf<FdoBooleanValue>(((FdoInCondition)filter).ValueList[3]);
+ Assert.IsInstanceOf<FdoBooleanValue>(((FdoInCondition)filter).ValueList[4]);
+
+ filter = FdoFilter.Parse("Geometry CONTAINS GeomFromText('POINT (1 1)')");
+ Assert.IsInstanceOf<FdoSpatialCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoSpatialCondition)filter).Identifier.Name);
+ Assert.AreEqual(SpatialOperations.Contains, ((FdoSpatialCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoSpatialCondition)filter).Expression);
+
+ filter = FdoFilter.Parse("Geometry CROSSES GeomFromText('POINT (1 1)')");
+ Assert.IsInstanceOf<FdoSpatialCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoSpatialCondition)filter).Identifier.Name);
+ Assert.AreEqual(SpatialOperations.Crosses, ((FdoSpatialCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoSpatialCondition)filter).Expression);
+
+ filter = FdoFilter.Parse("Geometry DISJOINT GeomFromText('POINT (1 1)')");
+ Assert.IsInstanceOf<FdoSpatialCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoSpatialCondition)filter).Identifier.Name);
+ Assert.AreEqual(SpatialOperations.Disjoint, ((FdoSpatialCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoSpatialCondition)filter).Expression);
+
+ filter = FdoFilter.Parse("Geometry EQUALS GeomFromText('POINT (1 1)')");
+ Assert.IsInstanceOf<FdoSpatialCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoSpatialCondition)filter).Identifier.Name);
+ Assert.AreEqual(SpatialOperations.Equals, ((FdoSpatialCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoSpatialCondition)filter).Expression);
+
+ filter = FdoFilter.Parse("Geometry INTERSECTS GeomFromText('POINT (1 1)')");
+ Assert.IsInstanceOf<FdoSpatialCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoSpatialCondition)filter).Identifier.Name);
+ Assert.AreEqual(SpatialOperations.Intersects, ((FdoSpatialCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoSpatialCondition)filter).Expression);
+
+ filter = FdoFilter.Parse("Geometry OVERLAPS GeomFromText('POINT (1 1)')");
+ Assert.IsInstanceOf<FdoSpatialCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoSpatialCondition)filter).Identifier.Name);
+ Assert.AreEqual(SpatialOperations.Overlaps, ((FdoSpatialCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoSpatialCondition)filter).Expression);
+
+ filter = FdoFilter.Parse("Geometry TOUCHES GeomFromText('POINT (1 1)')");
+ Assert.IsInstanceOf<FdoSpatialCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoSpatialCondition)filter).Identifier.Name);
+ Assert.AreEqual(SpatialOperations.Touches, ((FdoSpatialCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoSpatialCondition)filter).Expression);
+
+ filter = FdoFilter.Parse("Geometry WITHIN GeomFromText('POINT (1 1)')");
+ Assert.IsInstanceOf<FdoSpatialCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoSpatialCondition)filter).Identifier.Name);
+ Assert.AreEqual(SpatialOperations.Within, ((FdoSpatialCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoSpatialCondition)filter).Expression);
+
+ filter = FdoFilter.Parse("Geometry COVEREDBY GeomFromText('POINT (1 1)')");
+ Assert.IsInstanceOf<FdoSpatialCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoSpatialCondition)filter).Identifier.Name);
+ Assert.AreEqual(SpatialOperations.CoveredBy, ((FdoSpatialCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoSpatialCondition)filter).Expression);
+
+ filter = FdoFilter.Parse("Geometry INSIDE GeomFromText('POINT (1 1)')");
+ Assert.IsInstanceOf<FdoSpatialCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoSpatialCondition)filter).Identifier.Name);
+ Assert.AreEqual(SpatialOperations.Inside, ((FdoSpatialCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoSpatialCondition)filter).Expression);
+
+ filter = FdoFilter.Parse("Geometry BEYOND GeomFromText('POINT (1 1)') 2.0");
+ Assert.IsInstanceOf<FdoDistanceCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoDistanceCondition)filter).Identifier.Name);
+ Assert.AreEqual(DistanceOperations.Beyond, ((FdoDistanceCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoDistanceCondition)filter).Expression);
+ Assert.AreEqual(DataType.Double, ((FdoDistanceCondition)filter).Distance.DataType);
+ Assert.AreEqual(2.0, ((FdoDoubleValue)((FdoDistanceCondition)filter).Distance).Value);
+
+ filter = FdoFilter.Parse("Geometry BEYOND GeomFromText('POINT (1 1)') 5");
+ Assert.IsInstanceOf<FdoDistanceCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoDistanceCondition)filter).Identifier.Name);
+ Assert.AreEqual(DistanceOperations.Beyond, ((FdoDistanceCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoDistanceCondition)filter).Expression);
+ Assert.AreEqual(DataType.Int32, ((FdoDistanceCondition)filter).Distance.DataType);
+ Assert.AreEqual(5, ((FdoInt32Value)((FdoDistanceCondition)filter).Distance).Value);
+
+ filter = FdoFilter.Parse("Geometry WITHINDISTANCE GeomFromText('POINT (1 1)') 2.0");
+ Assert.IsInstanceOf<FdoDistanceCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoDistanceCondition)filter).Identifier.Name);
+ Assert.AreEqual(DistanceOperations.WithinDistance, ((FdoDistanceCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoDistanceCondition)filter).Expression);
+ Assert.AreEqual(DataType.Double, ((FdoDistanceCondition)filter).Distance.DataType);
+ Assert.AreEqual(2.0, ((FdoDoubleValue)((FdoDistanceCondition)filter).Distance).Value);
+
+ filter = FdoFilter.Parse("Geometry WITHINDISTANCE GeomFromText('POINT (1 1)') 5");
+ Assert.IsInstanceOf<FdoDistanceCondition>(filter);
+ Assert.AreEqual("Geometry", ((FdoDistanceCondition)filter).Identifier.Name);
+ Assert.AreEqual(DistanceOperations.WithinDistance, ((FdoDistanceCondition)filter).Operator);
+ Assert.IsInstanceOf<FdoGeometryValue>(((FdoDistanceCondition)filter).Expression);
+ Assert.AreEqual(DataType.Int32, ((FdoDistanceCondition)filter).Distance.DataType);
+ Assert.AreEqual(5, ((FdoInt32Value)((FdoDistanceCondition)filter).Distance).Value);
+ }
+ }
+}
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/OSGeo.MapGuide.MaestroAPI.Tests.csproj
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/OSGeo.MapGuide.MaestroAPI.Tests.csproj 2015-01-18 16:20:44 UTC (rev 8506)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/OSGeo.MapGuide.MaestroAPI.Tests.csproj 2015-01-19 11:25:57 UTC (rev 8507)
@@ -63,6 +63,7 @@
<Compile Include="CrossConnection\ResourceRebaserTests.cs" />
<Compile Include="ExpressionTests.cs" />
<Compile Include="FeatureReaderTests.cs" />
+ <Compile Include="FilterTests.cs" />
<Compile Include="Mapping\RuntimeMapTests.cs" />
<Compile Include="MiscTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
More information about the mapguide-commits
mailing list