Exemplo n.º 1
0
        public static Query SaveToXMLAndReparse(Query query, SifVersion version)
        {
            String sifQueryXML = query.ToXml(version);
            Console.WriteLine(sifQueryXML);

            SifParser parser = SifParser.NewInstance();
            SIF_Request sifR = (SIF_Request)parser.Parse("<SIF_Request>" + sifQueryXML + "</SIF_Request>", null);

            Query newQuery = new Query(sifR.SIF_Query);
            return newQuery;
        }
Exemplo n.º 2
0
        private void _processSIF_ZoneStatus(SIF_ZoneStatus zoneStatus, IZone zone)
        {
            if (zoneStatus == null)
            {
                return;
            }

            bool sync = getChameleonProperty(zone, "sync", false);
            bool events = getChameleonProperty(zone, "logEvents", true);
            bool logEntry = getChameleonProperty(zone, "sifLogEntrySupport", false);
            ArrayList objectDefs = new ArrayList();

            SIF_Providers providers = zoneStatus.SIF_Providers;
            if (providers != null)
            {
                foreach (SIF_Provider p in providers)
                {
                    foreach (SIF_Object obj in p.SIF_ObjectList)
                    {
                        // Lookup the topic for each provided object in the zone
                        IElementDef def = Adk.Dtd.LookupElementDef(obj.ObjectName);
                        if (def != null)
                        {
                            objectDefs.Add(def);
                            ITopic topic = TopicFactory.GetInstance(def);
                            if (topic.GetSubscriber() == null)
                            {
                                if (events)
                                {
                                    topic.SetSubscriber(fLogger, new SubscriptionOptions( ));
                                }
                                if (sync)
                                {
                                    topic.SetQueryResults(fLogger);
                                }
                            }
                        }
                    }
                }
            }

            if (logEntry)
            {
                ITopic sifLogEntryTopic = TopicFactory.GetInstance(InfraDTD.SIF_LOGENTRY);
                sifLogEntryTopic.SetSubscriber(fLogger, new SubscriptionOptions( ));
            }

            foreach (ITopic topic in TopicFactory.GetAllTopics( SifContext.DEFAULT ))
            {
                try
                {
                    // Join the topic to each zone ( causes the agent to subscribe to the joined objects )
                    // TODO: Add an "isJoinedTo()" API to topic so that it doesn't throw an exception
                    if (topic.ObjectType != InfraDTD.SIF_ZONESTATUS.Name)
                    {
                        topic.Join(zone);
                    }
                }
                catch (Exception ex)
                {
                    zone.Log.Error(ex.Message, ex);
                }
            }

            if (sync)
            {
                if (objectDefs.Count == 0)
                {
                    zone.ServerLog.Log
                        (LogLevel.WARNING, "No objects are being provided in this zone", null,
                          "1001");
                }
                string syncObjects = zone.Properties.GetProperty("chameleon.syncObjects");
                foreach (IElementDef def in objectDefs)
                {
                    if (def.IsSupported(Adk.SifVersion))
                    {
                        if (syncObjects == null ||
                             (syncObjects.Length > 0 && syncObjects.IndexOf(def.Name) > -1))
                        {
                            Query q = new Query(def);

                            // Query by specific parameters
                            string condition =
                                zone.Properties.GetProperty
                                    ("chameleon.syncConditions." + def.Name);
                            if (condition != null && condition.Length > 0)
                            {
                                // The condition should be in the format "path=value" e.g "@RefId=123412341...1234|@Name=asdfasdf"
                                String[] queryConditions = condition.Split('|');
                                foreach (String cond in queryConditions)
                                {
                                    string[] conds = cond.Split('=');
                                    if (conds.Length == 2)
                                    {
                                        q.AddCondition(conds[0], "EQ", conds[1]);
                                    }
                                }
                            }

                            if (logEntry)
                            {
                                zone.ServerLog.Log
                                    (LogLevel.INFO,
                                      "Requesting " + q.ObjectType.Name + " from the zone",
                                      q.ToXml(Adk.SifVersion), "1002");
                            }

                            zone.Query(q);
                        }
                    }
                    else
                    {
                        String debug = "Will not request " + def.Name +
                                       " because it is not supported in " +
                                       Adk.SifVersion.ToString();
                        Console.WriteLine(debug);
                        zone.ServerLog.Log(LogLevel.WARNING, debug, null, "1001");
                    }
                }
            }
        }
Exemplo n.º 3
0
        /**
         * Test SIF Query Pattern support in the ADK
         *
         * @param objectDef
         *            The IElementDef representing the root SIF Object
         * @param def
         *            The IElementDef representing the field being queried (e.g.
         *            CommonDTD.NAME_FIRSTNAME)
         * @param sqp
         *            The expected SIF Query Pattern (e.g. "Name/FirstName") for the
         *            above field def
         * @param version
         *            The version of SIF to test
         */
        private Query testSQP( IElementDef objectDef, IElementDef def, String sqp,
                               SifVersion version )
        {
            Adk.SifVersion = version;
            IElementDef lookedUp = Adk.Dtd.LookupElementDefBySQP( objectDef, sqp );
            Assert.AreEqual( def.Name, lookedUp.Name, "IElementDef" );
            testResolveBySQP( objectDef, sqp, version, def );

            Query q = new Query( objectDef );
            q.AddCondition( def, ComparisonOperators.EQ, "foo" );

            String sifQueryXML = q.ToXml();
            Console.WriteLine( sifQueryXML );

            String searchFor = "<SIF_Element>" + sqp + "</SIF_Element>";
            Assert.IsTrue( sifQueryXML.Contains( searchFor ), "SQP in XML" );

            SifParser parser = SifParser.NewInstance();
            SIF_Request sifR = (SIF_Request) parser.Parse( "<SIF_Request>"
                                                           + sifQueryXML + "</SIF_Request>", null );

            Query newQuery = new Query( sifR.SIF_Query );

            Condition cond = newQuery.HasCondition( sqp );
            Assert.IsNotNull( cond, "hasCondition" );
            Assert.AreEqual( sqp, cond.GetXPath(), "SQP" );
            Assert.AreEqual( def, cond.Field, "IElementDef" );

            return newQuery;
        }
Exemplo n.º 4
0
        private Query testResolveBySQP( IElementDef objectDef, String sqp,
                                        SifVersion version, IElementDef resolvedNestedElement )
        {
            Adk.SifVersion = version;

            Query q = new Query( objectDef );
            q.AddCondition( sqp, ComparisonOperators.EQ, "foo" );
            String sifQueryXML = q.ToXml();
            Console.WriteLine( sifQueryXML );

            String searchFor = "<SIF_Element>" + sqp + "</SIF_Element>";
            // The .Net ADK doesn't encode apostrophes when they are in
            // element content, so the following line is different than
            // the java test
            //searchFor = searchFor.Replace( "'", "&apos;" );
            Assert.IsTrue( sifQueryXML.Contains( searchFor ), "SQP in XML" );

            SifParser parser = SifParser.NewInstance();
            SIF_Request sifR = (SIF_Request) parser.Parse( "<SIF_Request>"
                                                           + sifQueryXML + "</SIF_Request>", null );

            Query newQuery = new Query( sifR.SIF_Query );

            Condition cond = newQuery.HasCondition( sqp );
            Assert.IsNotNull( cond, "hasCondition" );
            Assert.AreEqual( sqp, cond.GetXPath(), "SQP" );
            Assert.AreEqual( sqp, cond.GetXPath( newQuery,
                                                 version ), "Version-Specific SQP" );

            return newQuery;
        }
Exemplo n.º 5
0
        private void assertSectionInfoQueryXML( Query q )
        {
            String sif15Xml = q.ToXml( SifVersion.SIF15r1 );
            Console.WriteLine("SIF1.5 SectionInfo Query \r\n {0}", sif15Xml);
            String sif20Xml = q.ToXml( SifVersion.SIF21 );
            Console.WriteLine( "SIF2.0 SectionInfo Query \r\n {0}", sif20Xml );

            Assert.IsTrue( sif15Xml.IndexOf( "<SIF_QueryObject ObjectName=\"SectionInfo\">" ) > 0 );
            Assert.IsTrue(sif20Xml.IndexOf("<SIF_QueryObject ObjectName=\"SectionInfo\">") > 0);

            Assert.IsTrue(sif15Xml.IndexOf("<SIF_Element>@RefId</SIF_Element>") > 0);
            Assert.IsTrue(sif20Xml.IndexOf("<SIF_Element>@RefId</SIF_Element>") > 0);

            Assert.IsTrue(sif15Xml.IndexOf("<SIF_Element>@SchoolCourseInfoRefId</SIF_Element>") > 0);
            Assert.IsTrue(sif20Xml.IndexOf("<SIF_Element>@SchoolCourseInfoRefId</SIF_Element>") > 0);

            Assert.IsTrue(sif15Xml.IndexOf("<SIF_Element>@SchoolYear</SIF_Element>") == -1 );
            Assert.IsTrue(sif20Xml.IndexOf("<SIF_Element>@SchoolYear</SIF_Element>") > 0);

            Assert.IsTrue(sif15Xml.IndexOf("<SIF_Element>ScheduleInfo/@TermInfoRefId</SIF_Element>") > 0);
            Assert.IsTrue(sif20Xml.IndexOf("<SIF_Element>ScheduleInfoList/ScheduleInfo/@TermInfoRefId</SIF_Element>") > 0);

            Assert.IsTrue(sif15Xml.IndexOf("<SIF_Element>Description</SIF_Element>") == -1 );
            Assert.IsTrue(sif20Xml.IndexOf("<SIF_Element>Description</SIF_Element>") > 0);

            Assert.IsTrue(sif15Xml.IndexOf("<SIF_Element>LanguageOfInstruction</SIF_Element>") > 0);
            Assert.IsTrue(sif20Xml.IndexOf("<SIF_Element>LanguageOfInstruction</SIF_Element>") > 0);

            Assert.IsTrue(sif15Xml.IndexOf("<SIF_Element>LanguageOfInstruction/Code</SIF_Element>") == -1 );
            Assert.IsTrue(sif20Xml.IndexOf("<SIF_Element>LanguageOfInstruction/Code</SIF_Element>") > 0);
        }
Exemplo n.º 6
0
        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" );
        }
Exemplo n.º 7
0
        public void testQuery010()
        {
            Query q = new Query( StudentDTD.STUDENTPERSONAL );
            q.AddCondition( "Demographics/Ethnicity", ComparisonOperators.EQ, "W" );
            Console.WriteLine( q.ToXml() );

            q = SaveToXMLAndReparse( q, SifVersion.SIF15r1 );

            Condition c = q.HasCondition( "Demographics/Ethnicity" );
            Assert.IsNotNull( c, "Condition didn't resolve" );
        }