/// <summary> /// Add a condition to this query. /// </summary> /// <param name="condition">The condition to add. This condition is added to the root /// condition group.</param> /// <seealso cref="Query.RootConditionGroup"/> /// <seealso cref="Conditions"/> public void AddCondition(Condition condition) { if (fRoot == null) { fRoot = new ConditionGroup(GroupOperator.And); } fRoot.AddCondition(condition); }
private void PopulateConditions(SIF_Query query, SIF_Condition[] clist, ConditionGroup target) { for (int i = 0; i < clist.Length; i++) { String o = clist[i].SIF_Operator; ComparisonOperators ops = Condition.ParseComparisionOperators(o); String val = clist[i].SIF_Value; String path = clist[i].SIF_Element; target.AddCondition(fObjType, path, ops, val); } }
public void testComplexOrWithGTFilter() { ConditionGroup fail = new ConditionGroup( GroupOperator.None ); // This condition should fail fail.AddCondition( InfrastructureDTD.AUTHENTICATION_REFID, ComparisonOperators.NE, REFID_GUID ); ConditionGroup pass = new ConditionGroup( GroupOperator.Or ); // This condition should fail pass.AddCondition( InfrastructureDTD.AUTHENTICATIONINFO_USERNAME, ComparisonOperators.EQ, "FAIL" ); pass.AddCondition( InfrastructureDTD.AUTHENTICATIONINFO_USERNAME, ComparisonOperators.GT, "a" ); ConditionGroup root = new ConditionGroup( GroupOperator.Or ); root.AddGroup( fail ); root.AddGroup( pass ); Query q = new Query( InfrastructureDTD.AUTHENTICATION, root ); Authentication auth = BuildAuthentication(); Assert.IsTrue( q.Evaluate( auth ) ); }
public void TestToXml() { // From the javadoc example ... // Query for student where the Last Name is Jones and the First Name is // Bob, and the graduation year is 2004, 2005, or 2006 ConditionGroup root = new ConditionGroup( GroupOperator.And ); ConditionGroup grp1 = new ConditionGroup( GroupOperator.And ); ConditionGroup grp2 = new ConditionGroup( GroupOperator.Or ); // For nested elements, you cannot reference a SifDtd constant. Instead, use // the lookupElementDefBySQL function to lookup an IElementDef constant // given a SIF Query Pattern (SQP) IElementDef lname = Adk.Dtd.LookupElementDefBySQP( StudentDTD.STUDENTPERSONAL, "Name/LastName" ); IElementDef fname = Adk.Dtd.LookupElementDefBySQP( StudentDTD.STUDENTPERSONAL, "Name/FirstName" ); grp1.AddCondition( lname, ComparisonOperators.EQ, "Jones" ); grp1.AddCondition( fname, ComparisonOperators.EQ, "Bob" ); grp2.AddCondition( StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, ComparisonOperators.EQ, "2004" ); grp2.AddCondition( StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, ComparisonOperators.EQ, "2005" ); grp2.AddCondition( StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, ComparisonOperators.EQ, "2006" ); // Add condition groups to the root group root.AddGroup( grp1 ); root.AddGroup( grp2 ); // Query for student with the conditions prepared above by passing the // root ConditionGroup to the constructor Query query = new Query( StudentDTD.STUDENTPERSONAL, root ); query.AddFieldRestriction( StudentDTD.STUDENTPERSONAL_NAME ); // Now, call toXML() on the query object, reparse back into a Query object and assert all values String sifQueryXML = query.ToXml( SifVersion.LATEST ); Console.WriteLine( sifQueryXML ); SifParser parser = SifParser.NewInstance(); SIF_Request sifR = (SIF_Request) parser.Parse( "<SIF_Request>" + sifQueryXML + "</SIF_Request>", null ); Query reparsedQuery = new Query( sifR.SIF_Query ); Assert.AreEqual( StudentDTD.STUDENTPERSONAL, reparsedQuery.ObjectType, "Object Type should be StudentPersonal" ); Assert.AreEqual( 1, reparsedQuery.FieldRestrictions.Length, "Should have one field restriction" ); Assert.AreEqual( StudentDTD.STUDENTPERSONAL_NAME, reparsedQuery.FieldRestrictions[0], "Should be for StudentPersonal/Name" ); ConditionGroup newRoot = reparsedQuery.RootConditionGroup; Assert.AreEqual( StudentDTD.STUDENTPERSONAL, reparsedQuery.ObjectType, "Should be StudentPersonal" ); Assert.AreEqual( GroupOperator.And, newRoot.Operator, "Root should be an AND conditon" ); ConditionGroup[] groups = reparsedQuery.RootConditionGroup.Groups; Assert.AreEqual( 2, groups.Length, "Should have two groups" ); Assert.AreEqual( GroupOperator.And, groups[0].Operator, "First group should be AND" ); Assert.AreEqual( GroupOperator.Or, groups[1].Operator, "Second group should be OR" ); // Assert the first group conditions Condition[] newGrp1Conditions = groups[0].Conditions; Assert.AreEqual( 2, newGrp1Conditions.Length, "First group should have two conditions" ); // Assert the first condition Assert.AreEqual( ComparisonOperators.EQ, newGrp1Conditions[1].Operators, "First Condition EQ" ); Assert.AreEqual( lname, newGrp1Conditions[0].Field, "First Condition Field" ); Assert.AreEqual( "Jones", newGrp1Conditions[0].Value, "First Condition Value" ); // Assert the second condition Assert.AreEqual( ComparisonOperators.EQ, newGrp1Conditions[0].Operators, "Second Condition EQ" ); Assert.AreEqual( fname, newGrp1Conditions[1].Field, "First Condition Field" ); Assert.AreEqual( "Bob", newGrp1Conditions[1].Value, "First Condition Value" ); // Assert the second group conditions Condition[] newGrp2Conditions = groups[1].Conditions; Assert.AreEqual( 3, newGrp2Conditions.Length, "Second group should have three conditions" ); // Assert the first condition Assert.AreEqual( ComparisonOperators.EQ, newGrp2Conditions[0].Operators, "First Condition EQ" ); Assert.AreEqual( StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, newGrp2Conditions[0].Field, "First Condition Field" ); Assert.AreEqual( "2004", newGrp2Conditions[0].Value, "First Condition Value" ); // Assert the second condition Assert.AreEqual( ComparisonOperators.EQ, newGrp2Conditions[1].Operators, "Second Condition EQ" ); Assert.AreEqual( StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, newGrp2Conditions[1].Field, "Second Condition Field" ); Assert.AreEqual( "2005", newGrp2Conditions[1].Value, "Second Condition Value" ); // Assert the third condition Assert.AreEqual( ComparisonOperators.EQ, newGrp2Conditions[2].Operators, "Third Condition EQ" ); Assert.AreEqual( StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, newGrp2Conditions[2].Field, "Third Condition Field" ); Assert.AreEqual( "2006", newGrp2Conditions[2].Value, "Third Condition Value" ); }