public override ISifResponseIterator<StudentPersonal> GetSifResponses(Query query, IZone zone)
        {
            StudentPersonalIterator studentPersonalIterator = null;

            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            if (query.HasConditions)
            {
                string key = ExtractPrimaryKey(query);

                if (key == null)
                {
                    throw new SifException(SifErrorCategoryCode.RequestResponse, SifErrorCodes.REQRSP_UNSUPPORTED_QUERY_9, "SIF Query not supported.", zone);
                }
                else
                {
                    if (log.IsDebugEnabled) log.Debug("SIF Response requested for StudentPersonal with a SIF RefId of " + key + ".");
                    studentPersonalIterator = new StudentPersonalIterator(key);
                }

            }
            else
            {
                if (log.IsDebugEnabled) log.Debug("SIF Response requested for all StudentPersonals.");
                studentPersonalIterator = new StudentPersonalIterator(null);
            }

            return studentPersonalIterator;
        }
        public void OnRequest( IDataObjectOutputStream outStream,
                               Query query,
                               IZone zone,
                               IMessageInfo info )
        {
            // To be a successful publisher of data using the ADK, follow these steps

            // 1) Examine the query conditions. If they are too complex for your agent,
            // 	throw the appropriate SIFException

            // This example agent uses the autoFilter() capability of DataObjectOutputStream. Using
            // this capability, any object can be written to the output stream and the stream will
            // filter out any objects that don't meet the conditions of the Query. However, a more
            // robust agent with large amounts of data would want to pre-filter the data when it does its
            // initial database query.
            outStream.Filter = query;

            Console.WriteLine( "Responding to SIF_Request for StudentPersonal" );

            // 2) Write any data to the output stream
            foreach ( StudentPersonal sp in fData )
            {
                outStream.Write( sp );
            }
        }
        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;
        }
        public void AddFieldRestriction()
        {
            Query q = new Query( StudentDTD.STUDENTPERSONAL );
            q.AddFieldRestriction( StudentDTD.STUDENTPERSONAL_NAME );
            q.AddFieldRestriction( StudentDTD.STUDENTPERSONAL_ADDRESSLIST );

            IElementDef[] restrictions = q.FieldRestrictions;
            Assert.AreEqual( 2, restrictions.Length, "Should have two field restrictions" );
            Assert.AreEqual( StudentDTD.STUDENTPERSONAL_NAME, restrictions[0], "Should be StudentPersonal_Name" );
            Assert.AreEqual( StudentDTD.STUDENTPERSONAL_ADDRESSLIST, restrictions[1],
                             "Should be StudentPersonal_StudentAddress" );
        }
Exemple #5
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");
                    }
                }
            }
        }
        public void TestToXml010()
        {
            Query q = new Query(StudentDTD.SECTIONINFO);
            q.AddFieldRestriction(StudentDTD.SECTIONINFO_REFID);
            q.AddFieldRestriction( StudentDTD.SECTIONINFO_SCHOOLCOURSEINFOREFID );
            q.AddFieldRestriction( StudentDTD.SECTIONINFO_SCHOOLYEAR );
            q.AddFieldRestriction( StudentDTD.SECTIONINFO_LOCALID );
            q.AddFieldRestriction( "ScheduleInfoList/ScheduleInfo/@TermInfoRefId" );
            q.AddFieldRestriction( StudentDTD.SECTIONINFO_DESCRIPTION );
            q.AddFieldRestriction( StudentDTD.SECTIONINFO_LANGUAGEOFINSTRUCTION);
            q.AddFieldRestriction( StudentDTD.LANGUAGEOFINSTRUCTION_CODE );

            assertSectionInfoQueryXML( q );
        }
        public void testPersistenceWithBadState()
        {
            //create new cache for agent
            RequestCache cache = RequestCache.GetInstance(fAgent);

            //create new queryobject
            SIF_QueryObject obj = new SIF_QueryObject("");
            //create query, telling it what type of query it is(passing it queryobj)
            SIF_Query query = new SIF_Query(obj);
            //create new sif request
            SIF_Request request = new SIF_Request();
            //set query property
            request.SIF_Query = query;

            Query q = new Query(StudentDTD.STUDENTPERSONAL);

            String testStateItem = Adk.MakeGuid();
            String requestMsgId = Adk.MakeGuid();
            String testObjectType = Adk.MakeGuid();

            TestState ts = new TestState();
            ts.State = testStateItem;
            ts.setCreateErrorOnRead(true);

            q.UserData = ts;
            storeRequest(cache, request, q, requestMsgId, testObjectType);

            cache.Close();

            // Create a new instance. This one should retrieve its settings from the persistence mechanism
            cache = RequestCache.GetInstance(fAgent);

            IRequestInfo ri = cache.GetRequestInfo(requestMsgId, null);

            //if state is null, should still return ri object
            Assertion.AssertNotNull("RequestInfo was null", ri);
            Assertion.AssertEquals("MessageId", requestMsgId, ri.MessageId);
            Assertion.AssertEquals("ObjectType", testObjectType, ri.ObjectType);
            ts = (TestState) ri.UserData;
            // In order for this to be a valid test, the TestState class should have thrown
            // an exception during deserialization and should be null here.
            Assertion.AssertNull("UserData should be null", ts);
        }
        /**
           * Stores the items in the cache that will later be asserted
           * @param cache
           */
        private void storeAssertedRequests(RequestCache cache)
        {
            SIF_QueryObject obj = new SIF_QueryObject("");
            SIF_Query query = new SIF_Query(obj);
            SIF_Request request = new SIF_Request();
            request.SIF_Query = query;

            Query q;
            TestState ts;

            fMsgIds = new String[10];
            fStateObjects = new String[10];
            // Add 10 entries to the cache, interspersed with other entries that are removed
            for (int i = 0; i < 10; i++)
            {
                ts = new TestState();
                ts.State = Adk.MakeGuid();
                fStateObjects[i] = ts.State;
                q = new Query(StudentDTD.STUDENTPERSONAL);
                q.UserData = ts;

                String phantom1 = Adk.MakeGuid();
                String phantom2 = Adk.MakeGuid();
                storeRequest(cache, request, q, phantom1, "foo");
                fMsgIds[i] = Adk.MakeGuid();

                storeRequest(cache, request, q, fMsgIds[i], "Object_" + i.ToString());
                storeRequest(cache, request, q, phantom2, "bar");

                cache.GetRequestInfo(phantom1, null);
                cache.GetRequestInfo(phantom2, null);
            }
        }
        public void testPersistenceWithRemoval()
        {
            fRC = RequestCache.GetInstance(fAgent);
            SIF_QueryObject obj = new SIF_QueryObject("");
            SIF_Query query = new SIF_Query(obj);
            SIF_Request request = new SIF_Request();

            request.SIF_Query = query;

            Query q = new Query(StudentDTD.STUDENTPERSONAL);
            String testStateItem = Adk.MakeGuid();
            TestState ts = new TestState();
            ts.State = testStateItem;
            q.UserData = ts;

            fMsgIds = new String[10];
            // Add 10 entries to the cache, interspersed with other entries that are removed
            for (int i = 0; i < 10; i++)
            {
                String phantom1 = Adk.MakeGuid();
                String phantom2 = Adk.MakeGuid();
                storeRequest(fRC, request, q, phantom1, "foo");
                fMsgIds[i] = Adk.MakeGuid();
                storeRequest(fRC, request, q, fMsgIds[i], "Object_" + i);
                storeRequest(fRC, request, q, phantom2, "bar");

                fRC.GetRequestInfo(phantom1, null);
                fRC.GetRequestInfo(phantom2, null);
            }

            // remove every other entry, close, re-open and assert that the correct entries are there
            for (int i = 0; i < 10; i += 2)
            {
                fRC.GetRequestInfo(fMsgIds[i], null);
            }

            Assertion.AssertEquals("Before closing Should have five objects", 5, fRC.ActiveRequestCount);
            fRC.Close();

            // Create a new instance. This one should retrieve its settings from the persistence mechanism
            fRC = RequestCache.GetInstance(fAgent);
            Assertion.AssertEquals("After Re-Openeing Should have five objects", 5, fRC.ActiveRequestCount);
            for (int i = 1; i < 10; i += 2)
            {
                IRequestInfo cachedInfo = fRC.GetRequestInfo(fMsgIds[i], null);
                Assertion.AssertNotNull("No cachedID returned for " + i, cachedInfo);
            }
            Assertion.AssertEquals("Should have zero objects", 0, fRC.ActiveRequestCount);
        }
 public override ISifResponseIterator<SchoolInfo> GetSifResponses(Query query, IZone zone)
 {
     return new SchoolInfoIterator();
 }
Exemple #11
0
        private bool AddConditions(Query q, String whereClause )
        {
            InitializeComparisonList();
            bool added = true;
            whereClause = whereClause.Trim();
            if( whereClause.Length == 0 ){
            return added;
            }

            string[] whereConditions = Regex.Split(whereClause, "[aA][nN][dD]");
            ComparisonOperators cmpOperator = ComparisonOperators.EQ;
            string[] fields = null;

            if (whereConditions.Length > 0) {
            foreach (String condition in whereConditions) {
                fields = null;
                foreach (KeyValuePair<string, ComparisonOperators> kvp in supportedComparisons) {
                    string cmpString = kvp.Key;
                    cmpOperator = kvp.Value;
                    if (cmpOperator == ComparisonOperators.EQ) {
                        int index = condition.LastIndexOf(cmpString);
                        fields = new string[2];
                        if (index > 0) {
                            fields[0] = condition.Substring(0, index);
                            fields[1] = condition.Substring((index + 1));
                        } else {
                            fields[0] = condition;
                        }

                    }//end if

                    if (fields == null) {
                        fields = Regex.Split(condition, cmpString);
                    }

                    if (fields[0] == condition) {
                        //Means no match found using that current comparison operator
                        //so skip this condition
                        fields = null;
                        continue;
                    }

                    if (fields.Length != 2) {
                        Console.WriteLine("ERROR: Unsupported where clause: " + whereClause);
                        PrintSQLHelp();
                        added = false;
                        break;
                    }

                    string fieldExpr = fields[0].Trim();
                    IElementDef def = Adk.Dtd.LookupElementDefBySQP(q.ObjectType, fieldExpr );
                    if (def == null) {
                        Console.WriteLine("ERROR: Unrecognized field in where clause: " + fieldExpr );
                        PrintSQLHelp();
                        added = false;
                        break;
                    } else {
                        if (fieldExpr.IndexOf('[') > 0)
                        {
                            // If there is a square bracket in the field syntax, use the raw XPath,
                            // rather then the ElementDef because using ElementDef restrictions
                            // does not work for XPath expressions that contain predicates
                            // Note that using raw XPath expressions works fine, but the ADK is no longer
                            // going to be able to use version-independent rendering of the query
                            q.AddCondition(fieldExpr, cmpOperator, fields[1].Trim());
                        }
                        else
                        {
                            q.AddCondition( def, cmpOperator, fields[1].Trim() );

                        }
                        //our condition has been found, no need to check the other comparison
                        //operators for a match so move to the next condition
                        break;
                    }
                }//end foreach
            }//end foreach
            }

            return added;
        }
Exemple #12
0
        public void testComplexAndQuery()
        {
            String sifQuery = "<SIF_Request><SIF_Query>" +
                              "    <SIF_QueryObject ObjectName=\"StudentSchoolEnrollment\"/>" +
                              "    <SIF_ConditionGroup Type=\"None\">" +
                              "           <SIF_Conditions Type=\"And\">" +
                              "             <SIF_Condition>" +
                              "                 <SIF_Element>@MembershipType</SIF_Element>" +
                              "                 <SIF_Operator>EQ</SIF_Operator>" +
                              "                 <SIF_Value>Home</SIF_Value>" +
                              "              </SIF_Condition>" +
                              "              <SIF_Condition>" +
                              "                 <SIF_Element>@RefId</SIF_Element>" +
                              "                 <SIF_Operator>EQ</SIF_Operator>" +
                              "                 <SIF_Value>49B02D134D6D445DA7B5C76160BF3902</SIF_Value>" +
                              "              </SIF_Condition>" +
                              "              <SIF_Condition>" +
                              "                 <SIF_Element>@SchoolInfoRefId</SIF_Element>" +
                              "                 <SIF_Operator>EQ</SIF_Operator>" +
                              "                 <SIF_Value>EF8850D522E54688B036B08F9C4C1312</SIF_Value>" +
                              "              </SIF_Condition>" +
                              "              <SIF_Condition>" +
                              "                 <SIF_Element>@SchoolYear</SIF_Element>" +
                              "                 <SIF_Operator>EQ</SIF_Operator>" +
                              "                 <SIF_Value>2006</SIF_Value>" +
                              "              </SIF_Condition>" +
                              "              <SIF_Condition>" +
                              "                 <SIF_Element>@StudentPersonalRefId</SIF_Element>" +
                              "                 <SIF_Operator>EQ</SIF_Operator>" +
                              "                 <SIF_Value>1AA295D3BC5146FA9058BB62FB6CC602</SIF_Value>" +
                              "              </SIF_Condition>" +
                              "              <SIF_Condition>" +
                              "                 <SIF_Element>@TimeFrame</SIF_Element>" +
                              "                 <SIF_Operator>EQ</SIF_Operator>" +
                              "                 <SIF_Value>Historical</SIF_Value>" +
                              "              </SIF_Condition>" +
                              "              <SIF_Condition>" +
                              "                <SIF_Element>EntryDate</SIF_Element>" +
                              "                 <SIF_Operator>EQ</SIF_Operator>" +
                              "                 <SIF_Value>2005-08-28</SIF_Value>" +
                              "              </SIF_Condition>" +
                              "           </SIF_Conditions>" +
                              "        </SIF_ConditionGroup>" +
                              "     </SIF_Query></SIF_Request>";

            SifParser parser = SifParser.NewInstance();
            SIF_Request sifR = (SIF_Request) parser.Parse( sifQuery, null, 0, SifVersion.LATEST );
            Query query = new Query( sifR.SIF_Query );

            String sse =
                "<StudentSchoolEnrollment RefId=\"49B02D134D6D445DA7B5C76160BF3902\" StudentPersonalRefId=\"1AA295D3BC5146FA9058BB62FB6CC602\" SchoolInfoRefId=\"EF8850D522E54688B036B08F9C4C1312\" MembershipType=\"Home\" TimeFrame=\"Historical\" SchoolYear=\"2006\">" +
                "<EntryDate>2005-08-28</EntryDate>" +
                "</StudentSchoolEnrollment>";

            SifDataObject sdo = (SifDataObject) parser.Parse( sse, null, 0, SifVersion.SIF20r1 );

            Assert.IsTrue( query.Evaluate( sdo ) );
        }
Exemple #13
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;
        }
Exemple #14
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;
        }
Exemple #15
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);
        }
Exemple #16
0
        public void TestToXml030()
        {
            string queryStr =    @"<SIF_Query>
                                         <SIF_QueryObject ObjectName='SectionInfo'>
                                            <SIF_Element>@RefId</SIF_Element>
                                            <SIF_Element>@SchoolCourseInfoRefId</SIF_Element>
                                            <SIF_Element>@SchoolYear</SIF_Element>
                                            <SIF_Element>LocalId</SIF_Element>
                                            <SIF_Element>ScheduleInfoList/ScheduleInfo/@TermInfoRefId</SIF_Element>
                                            <SIF_Element>Description</SIF_Element>
                                            <SIF_Element>LanguageOfInstruction</SIF_Element>
                                            <SIF_Element>LanguageOfInstruction/Code</SIF_Element>
                                         </SIF_QueryObject>
                                      </SIF_Query>";

            SifParser parser = SifParser.NewInstance();
            SIF_Query sifQuery = (SIF_Query)parser.Parse( queryStr );
            Query q = new Query( sifQuery );
            assertSectionInfoQueryXML( q );
        }
Exemple #17
0
        public void TestToXml020()
        {
            Query q = new Query(StudentDTD.SECTIONINFO);
            q.AddFieldRestriction( "@RefId");
            q.AddFieldRestriction( "@SchoolCourseInfoRefId" );
            q.AddFieldRestriction( "@SchoolYear" );
            q.AddFieldRestriction( "LocalId" );
            q.AddFieldRestriction("ScheduleInfoList/ScheduleInfo/@TermInfoRefId");
            q.AddFieldRestriction( "Description" );
            q.AddFieldRestriction( "LanguageOfInstruction" );
            q.AddFieldRestriction("LanguageOfInstruction");
            q.AddFieldRestriction("LanguageOfInstruction/Code");

            assertSectionInfoQueryXML(q);
        }
 /// <summary>
 /// Return an iterator of responses for the StudentPersonal SIF Data Object.
 /// </summary>
 /// <param name="query">Specific query to be executed.</param>
 /// <param name="zone">Zone to use.</param>
 /// <returns>Iterator of responses for the StudentPersonal SIF Data Object.</returns>
 public override ISifResponseIterator<StudentPersonal> GetSifResponses(Query query, IZone zone)
 {
     return new StudentPersonalIterator();
 }
 /// <summary>
 /// Filter the SIF Request to a student whose SIF RefId is 7C834EA9EDA12090347F83297E1C290C.
 /// </summary>
 /// <param name="query">SIF Query that contains the filter condition.</param>
 /// <param name="zone">Zone to make the SIF Request on.</param>
 protected override void AddToBroadcastRequestQuery(Query query, IZone zone)
 {
     if (log.IsDebugEnabled) log.Debug("Added a condition to the request query for StudentPersonal SIF RefId of 7C834EA9EDA12090347F83297E1C290C.");
     query.AddCondition(StudentDTD.STUDENTPERSONAL_REFID, ComparisonOperators.EQ, "7C834EA9EDA12090347F83297E1C290C");
 }
 /// <summary>
 /// Open the SIFResponseSender to send SIF_Response messages to a specific zone.
 /// </summary>
 /// <param name="zone">The zone to send messages to</param>
 /// <param name="sifRequestMsgId">The SIF_MsgId from the original SIF_Request message.
 /// You can obtain this by accessing the value returned from <see cref="OpenADK.Library.SifMessageInfo.MsgId"/>
 /// on the SIFMessageInfo parameter passed to the Publisher.onRequest
 /// method. NOTE: Do not call <see cref="OpenADK.Library.SifMessageInfo.SIFRequestMsgId"/>
 /// as it will return a <c>null</c> value and is only intended to be called
 /// on SIF_Response messages.</param>
 /// <param name="sifRequestSourceId">The SIF_SourceId from the original SIF_Request message.
 /// You can obtain this by accessing the value returned from <see cref="OpenADK.Library.SifMessageInfo.SourceId"/>
 /// on the SIFMessageInfo parameter passed to the Publisher.onRequest
 /// method.</param>
 /// <param name="sifVersion">The SIF_Version value from the original SIF_Request message.
 /// You can obtain this by accessing the value returned from <see cref="OpenADK.Library.SifMessageInfo.SIFRequestVersions"/>
 /// on the SIFMessageInfo parameter passed to the Publisher.onRequest
 /// method.</param>
 /// <param name="maxBufferSize">The SIF_MaxBufferSize value from the original SIF_Request.
 /// You can obtain this by accessing the value returned from <see cref="OpenADK.Library.SifMessageInfo.MaxBufferSize"/>
 /// on the SIFMessageInfo parameter passed to the Publisher.onRequest
 /// method.</param>
 /// <param name="query">An optional array of ElementDef constants, obtained or 
 ///	reconstructed from the <see cref="OpenADK.Library.Query.FieldRestrictions"/>
 ///	property from the original SIF_Request, that identify the subset of SIF elements 
 ///	to include in the data objects written to SIF_Response messages. If this array 
 ///	is provided, data objects will only have those elements specified; otherwise 
 ///	data objects contain all of their elements.</param>
 ///	<exception cref="System.ArgumentException">thrown if any of the parameter are invalid</exception>
 ///	<exception cref="AdkException">thrown if an error occurs preparing the output stream</exception>
 public void Open(
     IZone zone,
     String sifRequestMsgId,
     String sifRequestSourceId,
     SifVersion sifVersion,
     int maxBufferSize,
     Query query)
 {
     fZone = zone;
     fOut = DataObjectOutputStreamImpl.NewInstance();
     fOut.Initialize
         (zone, query, sifRequestSourceId, sifRequestMsgId, sifVersion,
           maxBufferSize);
 }
Exemple #21
0
 private bool AddSelectFields(Query q, String selectClause )
 {
     if( selectClause.Length == 0 || selectClause.IndexOf( "*" ) > -1 ){
     return true;
     }
     string[] fields = selectClause.Split(new char[] { ',' });
     foreach(string field in fields){
     string val = field.Trim();
     if( val.Length > 0 ){
         IElementDef restriction = Adk.Dtd.LookupElementDefBySQP( q.ObjectType, val );
         if( restriction == null ){
             Console.WriteLine( "ERROR: Unrecognized SELECT field: " + val );
             PrintSQLHelp();
             return false;
         } else {
             q.AddFieldRestriction(restriction);
         }
     }
     }
     return true;
 }
        private string ExtractPrimaryKey(Query query)
        {
            string key = null;

            // Unable to manage complex queries (containing more than just primary keys).
            if (query.Conditions.Length == 1)
            {
                ConditionGroup conditions = query.Conditions[0];

                // StudentPersonal has only a single primary key.
                if (conditions.Size() == 1)
                {
                    Condition condition = conditions.HasCondition(StudentDTD.STUDENTPERSONAL_REFID);
                    //Condition condition = conditions.HasCondition("@RefId");

                    if ((ComparisonOperators.EQ.Equals(condition.Operators)))
                    {
                        key = condition.Value;
                    }

                }

            }

            return key;
        }
        // TODO: Implement
        /*

        private SIF_Request createSIF_Request( ElementDef objectType, String refId, Zone zone )
        {
           SIF_Request request = new SIF_Request();
           request.getHeader().setSIF_MsgId( MSG_GUID );
           request.getHeader().setSIF_SourceId( "foo" );
           request.setSIF_MaxBufferSize("32768");
           request.setSIF_Version( ADK.getSIFVersion().toString() );
           Query query = new Query(objectType);
           query.addCondition(SifDtd.SIF_REPORTOBJECT_REFID, Condition.EQ, refId);

           SIF_Query q = SIFPrimitives.createSIF_Query(query, zone);
           SIF_QueryObject sqo = new SIF_QueryObject();
           sqo.setObjectName( objectType.name() );

           q.setSIF_QueryObject(sqo);
           request.setSIF_Query(q);

           return request;
        }

         */
        private SIF_Response createSIF_Response(IElementDef objType, bool storeInRequestCache, ISerializable stateObject)
        {
            SIF_Request req = createSIF_Request(objType);

             if (storeInRequestCache)
             {
            Query q = new Query(objType);
            q.UserData = stateObject;
            RequestCache.GetInstance(fAgent).StoreRequestInfo(req, q, fZone);
             }

             SIF_Response resp = new SIF_Response();
             resp.SIF_RequestMsgId = req.Header.SIF_MsgId;
             SIF_ObjectData sod = new SIF_ObjectData();
             resp.SIF_ObjectData = sod;

             Object responseObject = null;
             try
             {
            responseObject = ClassFactory.CreateInstance(objType.FQClassName, false);
             }
             catch (Exception cfe)
             {
            throw new AdkException("Unable to create instance of " + objType.Name, fZone, cfe);
             }

             sod.AddChild((SifElement)responseObject);
             return resp;
        }
 public override ISifResponseIterator<StudentSchoolEnrollment> GetSifResponses(Query query, IZone zone)
 {
     return new StudentSchoolEnrollmentIterator();
 }
        public void testWithLegacyFile()
        {
            //assertStoredRequests(fRC, true);
            // Copy the legacy requests.adk file to the agent work directory
            //FileInfo legacyFile = new FileInfo("requests.adk");

            //Assertion.Assert("Saved legacy file does [not?] exist", legacyFile.Exists);
            //FileInfo copiedFile = new FileInfo(fAgent.HomeDir + Path.DirectorySeparatorChar + "work" + Path.DirectorySeparatorChar + "requests.adk");
            //if (copiedFile.Exists)
            //{
            //   copiedFile.Delete();
            //}

            //// Copy the file
            //legacyFile.CopyTo(copiedFile.FullName, true);

            // Now open up an instance of the request cache and verify that the contents are there

            fRC = RequestCache.GetInstance(fAgent);
            SIF_QueryObject obj = new SIF_QueryObject("");
            SIF_Query query = new SIF_Query(obj);
            SIF_Request request = new SIF_Request();
            request.SIF_Query = query;

            Query q;
            TestState ts;

            fMsgIds = new String[10];
            fStateObjects = new String[10];
            // Add 10 entries to the cache
            for (int i = 0; i < 10; i++)
            {
                ts = new TestState();
                ts.State = Adk.MakeGuid();
                fStateObjects[i] = (String) ts.State;
                q = new Query(StudentDTD.STUDENTPERSONAL);
                q.UserData = ts;
                fMsgIds[i] = Adk.MakeGuid();
                storeRequest(fRC, request, q, fMsgIds[i], "Object_" + i.ToString());
            }

            Assertion.AssertEquals("Active request count", 10, fRC.ActiveRequestCount);

            // Lookup each setting,
            for (int i = 0; i < 10; i++)
            {
                IRequestInfo reqInfo = fRC.LookupRequestInfo(fMsgIds[i], null);
                Assertion.AssertEquals("Initial lookup", "Object_" + i.ToString(), reqInfo.ObjectType);
            }

            // Lookup each setting,
            for (int i = 0; i < 10; i++)
            {
                IRequestInfo reqInfo = fRC.GetRequestInfo(fMsgIds[i], null);
                Assertion.AssertEquals("Initial lookup", "Object_" + i.ToString(), reqInfo.ObjectType);
            }

            // all messages should now be removed from the queue
            Assertion.AssertEquals("Cache should be empty", 0, fRC.ActiveRequestCount);

            // Now run one of our other tests
            testPersistence();
        }
Exemple #26
0
        public void testSQP060()
        {
            // TT 217 Presumptive Query Syntax support
            Query q = new Query( ReportingDTD.STUDENTLOCATOR );
            q.AddCondition( "RequestingAgencyId/@Type", ComparisonOperators.EQ,
                            "LEA" );
            q.AddCondition( "RequestingAgencyId", ComparisonOperators.EQ, "0001" );

            q = SaveToXMLAndReparse( q, SifVersion.LATEST );

            Condition c = q.HasCondition( ReportingDTD.REQUESTINGAGENCYID_TYPE );
            Assert.IsNotNull( c );
            String xPath = c.GetXPath( q, SifVersion.LATEST );
            Assert.AreEqual( "RequestingAgencyId/@Type", xPath, "RequestingAgencyID/@Type XPath" );

            c = q.HasCondition( ReportingDTD.REQUESTINGAGENCYID );
            Assert.IsNotNull( c );
            xPath = c.GetXPath( q, SifVersion.LATEST );
            Assert.AreEqual( "RequestingAgencyId", xPath, "RequestingAgencyIDe XPath" );
        }
 private void storeRequest(
     RequestCache rc,
     SIF_Request request,
     Query q,
     String msgID,
     String objectName)
 {
     //request.getSIF_Query().getSIF_QueryObject().setObjectName(objectName);
     request.SIF_Query.SIF_QueryObject.ObjectName = objectName;
     request.Header.SIF_MsgId = msgID;
     rc.StoreRequestInfo(request, q, null);
 }
Exemple #28
0
        /// <summary>  Initialize and start the agent
        /// </summary>
        /// <param name="args">Command-line arguments (run with no arguments to display help)
        /// </param>
        public virtual void StartAgent(string[] args)
        {
            Console.WriteLine("Initializing agent...");

            //  Read the configuration file
            fCfg = new AgentConfig();
            Console.Out.WriteLine("Reading configuration file...");
            fCfg.Read("agent.cfg", false);

            //  Override the SourceId passed to the constructor with the SourceId
            //  specified in the configuration file
            this.Id = fCfg.SourceId;

            //  Inform the ADK of the version of SIF specified in the sifVersion=
            //  attribute of the <agent> element
            SifVersion version = fCfg.Version;
            Adk.SifVersion = version;

            //  Now call the superclass initialize once the configuration file has been read
            base.Initialize();

            //  Ask the AgentConfig instance to "apply" all configuration settings
            //  to this Agent; for example, all <property> elements that are children
            //  of the root <agent> node are parsed and applied to this Agent's
            //  AgentProperties object; all <zone> elements are parsed and registered
            //  with the Agent's ZoneFactory, and so on.
            //
            fCfg.Apply(this, true);

            // Create the logging object
            fLogger = new ObjectLogger(this);

            Query zoneQuery = new Query(InfraDTD.SIF_ZONESTATUS);
            zoneQuery.AddFieldRestriction(InfraDTD.SIF_ZONESTATUS_SIF_PROVIDERS);
            //zoneQuery.AddFieldRestriction( SifDtd.SIF_ZONESTATUS_SIF_SIFNODES );
            zoneQuery.UserData = fRequestState;

            ITopic zoneTopic = TopicFactory.GetInstance(InfraDTD.SIF_ZONESTATUS);

            zoneTopic.SetQueryResults(this);

            // Now, connect to all zones and just get the zone status
            foreach (IZone zone in this.ZoneFactory.GetAllZones())
            {
                if (getChameleonProperty(zone, "logRaw", false))
                {
                    zone.Properties.KeepMessageContent = true;
                    zone.AddMessagingListener(fLogger);
                }
                zone.Connect(ProvisioningFlags.Register);
                zoneTopic.Join(zone);
            }

            Console.WriteLine();
            Console.WriteLine("Requesting SIF_ZoneStatus from all zones...");
            zoneTopic.Query(zoneQuery);
        }
 /// <summary>
 /// Return an iterator of responses for the Identity SIF Object.
 /// </summary>
 /// <param name="query">Specific query to be executed.</param>
 /// <param name="zone">Zone to use.</param>
 /// <returns>Iterator of responses for the Identity SIF Object.</returns>
 public override ISifResponseIterator<Identity> GetSifResponses(Query query, IZone zone)
 {
     return new IdentityIterator();
 }
Exemple #30
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" );
        }