Esempio n. 1
0
        public override IRequestInfo StoreRequestInfo(SIF_Request request,
                                                      Query q,
                                                      IZone zone)
        {
            // validate that the userdata supplied with the query is serializable
            if (q.UserData != null)
            {
                Type userDataType = q.UserData.GetType();
                if (!userDataType.IsSerializable)
                {
                    throw new ArgumentException
                              ("Query.UserData contains " + userDataType.AssemblyQualifiedName +
                              " which is not serializable");
                }
            }

            try
            {
                RequestCacheFileEntry entry = new RequestCacheFileEntry(true);
                entry.SetObjectType(request.SIF_Query.SIF_QueryObject.ObjectName);
                entry.SetMessageId(request.MsgId);
                entry.SetUserData(q.UserData);
                Store(fFile, entry);
                return(entry);
            }
            catch (Exception thr)
            {
                throw new AdkException
                          ("Error writing to SIF_Request ID cache (MsgId: " + request.MsgId + ") " + thr,
                          zone, thr);
            }
        }
Esempio n. 2
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));
        }
Esempio n. 3
0
 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);
 }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public void testParseFieldRestrictions020()
        {
            String filteredRequest =
                "<SIF_Message xmlns=\"http://www.sifinfo.org/infrastructure/2.x\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" Version=\"2.0r1\">" +
                "<SIF_Request>" +
                "   <SIF_Header>" +
                "      <SIF_MsgId>EC357ED020F811DD9039FE9AB6D9D924</SIF_MsgId>" +
                "      <SIF_Timestamp>2008-05-13T10:28:57.789-05:00</SIF_Timestamp>" +
                "      <SIF_SourceId>DDD7112020E211DD9039DFD0562B2BED</SIF_SourceId>" +
                "      <SIF_DestinationId>Classroll Agent</SIF_DestinationId>" +
                "   </SIF_Header>" +
                "   <SIF_Version>2.*</SIF_Version>" +
                "   <SIF_MaxBufferSize>11984</SIF_MaxBufferSize>" +
                "   <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>" +
                "</SIF_Request>" +
                "</SIF_Message>";


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

            // Assert things about the query
            Assert.AreEqual(StudentDTD.SECTIONINFO, query.ObjectType);
            Assert.AreEqual("SectionInfo", query.ObjectTag);
            IElementDef[] elements = query.FieldRestrictions;

            Assert.IsNotNull(elements);
            Assert.AreEqual(8, elements.Length);

            // Attempt reparsing and then re-asserting:
            query = SaveToXMLAndReparse(query, SifVersion.LATEST);
            // Assert things about the query
            Assert.AreEqual(StudentDTD.SECTIONINFO, query.ObjectType);
            Assert.AreEqual("SectionInfo", query.ObjectTag);
            elements = query.FieldRestrictions;

            Assert.IsNotNull(elements);
            Assert.AreEqual(8, elements.Length);
        }
Esempio n. 6
0
        /// <summary>  Called by the Adk to construct a SifMessageInfo</summary>
        /// <param name="msg">The SIF_Message
        /// </param>
        /// <param name="zone">The associated zone
        /// </param>
        public SifMessageInfo(SifMessagePayload msg,
                              IZone zone)
        {
            fZone    = zone;
            fPayload = Adk.Dtd.GetElementType(msg.ElementDef.Name);
            if (zone.Properties.KeepMessageContent)
            {
                try {
                    StringWriter sw     = new StringWriter();
                    SifWriter    writer = new SifWriter(sw);
                    writer.Write(msg);
                    writer.Flush();
                    writer.Close();
                    sw.Close();

                    fMessage = sw.ToString();
                }
                catch {
                    // Do nothing
                }
            }

            //  Set SIF_Header values
            fHeader = msg.Header;
            IList <SifContext> contexts = msg.SifContexts;

            fContexts = new SifContext[contexts.Count];
            contexts.CopyTo(fContexts, 0);

            //  Set information about the message payload
            fPayloadVersion = msg.SifVersion;
            switch (fPayload)
            {
            case SifMessageType.SIF_Request:
            {
                SIF_Request req = (SIF_Request)msg;
                fObjects["SIF_MaxBufferSize"]   = req.SIF_MaxBufferSize;
                fObjects["SIF_RequestVersions"] = req.parseRequestVersions(fZone.Log);
            }
            break;

            case SifMessageType.SIF_Response:
            {
                SIF_Response rsp = (SIF_Response)msg;
                this.SIFRequestMsgId         = rsp.SIF_RequestMsgId;
                fObjects["SIF_PacketNumber"] = rsp.SIF_PacketNumber;
                SetAttribute("SIF_MorePackets", rsp.SIF_MorePackets);
            }
            break;
            }
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        // TODO: Implement

        /*
         * [Test]
         * public void testReportPublishSIFExceptionAfterReportInfo()
         * {
         * ElementDef objType = SifDtd.SIF_REPORTOBJECT;
         * ErrorMessageHandler handler = new ErrorMessageHandler( ErrorMessageHandler.BVR_SET_REPORT_INFO_THROW_EXCEPTION );
         * fZone.setReportPublisher( handler, ADKFlags.PROV_NONE);
         *
         * TestProtocolHandler testProto = new TestProtocolHandler();
         * testProto.open(fZone);
         * MessageDispatcher testDispatcher = new MessageDispatcher( fZone );
         * fZone.setDispatcher(testDispatcher);
         * fZone.setProto(testProto);
         * testDispatcher.dispatch( createSIF_Request( objType, ADK.makeGUID(), fZone ) );
         * String msg = testProto.readMsg();
         * assertNull(testProto.readMsg());
         * fZone.log.info(msg);
         *
         * SIFParser parser = SIFParser.newInstance();
         * SIFElement element = parser.parse(new StringReader(msg), fZone);
         * assertTrue(element instanceof SIF_Response);
         * SIF_Response response = (SIF_Response) element;
         * assertTrue(response.getSIF_Error() != null);
         * assertTrue(response.getSIF_Error().getSIF_Desc().startsWith("Blah"));
         * }
         *
         * public void testReportPublishSIFExceptionAfterReportInfo() throws ADKException, IOException
         * {
         * ElementDef objType = SifDtd.SIF_REPORTOBJECT;
         * ErrorMessageHandler handler = new ErrorMessageHandler( ErrorMessageHandler.BVR_SET_REPORT_INFO_THROW_EXCEPTION );
         * fZone.setReportPublisher( handler, ADKFlags.PROV_NONE);
         *
         * TestProtocolHandler testProto = new TestProtocolHandler();
         * testProto.open(fZone);
         * MessageDispatcher testDispatcher = new MessageDispatcher( fZone );
         * fZone.setDispatcher(testDispatcher);
         * fZone.setProto(testProto);
         * testDispatcher.dispatch( createSIF_Request( objType, ADK.makeGUID(), fZone ) );
         * String msg = testProto.readMsg();
         * assertNull(testProto.readMsg());
         * fZone.log.info(msg);
         *
         * SIFParser parser = SIFParser.newInstance();
         * SIFElement element = parser.parse(new StringReader(msg), fZone);
         * assertTrue(element instanceof SIF_Response);
         * SIF_Response response = (SIF_Response) element;
         * assertTrue(response.getSIF_Error() != null);
         * assertTrue(response.getSIF_Error().getSIF_Desc().startsWith("Blah"));
         * }
         *
         */

        private SIF_Request createSIF_Request(IElementDef objType)
        {
            SIF_Request request = new SIF_Request();

            request.Header.SIF_MsgId    = MSG_GUID;
            request.Header.SIF_SourceId = "foo";
            request.SIF_MaxBufferSize   = 32768;
            request.AddSIF_Version(new SIF_Version(Adk.SifVersion.ToString()));
            SIF_Query       q   = new SIF_Query();
            SIF_QueryObject sqo = new SIF_QueryObject();

            sqo.ObjectName = objType.Name;

            q.SIF_QueryObject = sqo;
            request.SIF_Query = q;

            return(request);
        }
Esempio n. 9
0
        public void testParseFieldRestrictions()
        {
            String filteredRequest = "<SIF_Request>" +
                                     " <SIF_Header>" +
                                     "	 <SIF_MsgId>D59CE61000D011DDB8D4E57E5F08151C</SIF_MsgId>"+
                                     "	 <SIF_Timestamp>2008-04-02T12:21:22.801-05:00</SIF_Timestamp>"+
                                     "	 <SIF_SourceId>318D14F000D011DDB8D4AE35C22E84E0</SIF_SourceId>"+
                                     "	 <SIF_DestinationId>SASIxp</SIF_DestinationId>"+
                                     "  </SIF_Header>" +
                                     "  <SIF_Version>2.*</SIF_Version>" +
                                     "  <SIF_MaxBufferSize>16384</SIF_MaxBufferSize>" +
                                     "  <SIF_Query>" +
                                     "	 <SIF_QueryObject ObjectName=\"StudentSnapshot\">"+
                                     "		<SIF_Element>@SchoolYear</SIF_Element>"+
                                     "		<SIF_Element>@SnapDate</SIF_Element>"+
                                     "		<SIF_Element>@StudentPersonalRefId</SIF_Element>"+
                                     "		<SIF_Element>HomeEnrollment/GradeLevel/Code</SIF_Element>"+
                                     "		<SIF_Element>HomeEnrollment/Status</SIF_Element>"+
                                     "		<SIF_Element>LocalId</SIF_Element>"+
                                     "		<SIF_Element>Address</SIF_Element>"+
                                     "	 </SIF_QueryObject>"+
                                     "  </SIF_Query>" +
                                     "</SIF_Request>";

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

            // Assert things about the query
            Assert.AreEqual(StudentDTD.STUDENTSNAPSHOT, query.ObjectType);
            Assert.AreEqual("StudentSnapshot", query.ObjectTag);
            IElementDef[] elements = query.FieldRestrictions;

            Assert.IsNotNull(elements);
            Assert.AreEqual(7, elements.Length);

            Assert.AreEqual(StudentDTD.STUDENTSNAPSHOT_SCHOOLYEAR, elements[0]);
            Assert.AreEqual(StudentDTD.STUDENTSNAPSHOT_SNAPDATE, elements[1]);
            Assert.AreEqual(StudentDTD.STUDENTSNAPSHOT_STUDENTPERSONALREFID, elements[2]);
            Assert.AreEqual(CommonDTD.GRADELEVEL_CODE, elements[3]);
            Assert.AreEqual(StudentDTD.HOMEENROLLMENT_STATUS, elements[4]);
            Assert.AreEqual(StudentDTD.STUDENTSNAPSHOT_LOCALID, elements[5]);
            Assert.AreEqual(StudentDTD.STUDENTSNAPSHOT_ADDRESS, elements[6]);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        /// <summary>  Constructs a Query object from a SIF_QueryObject.
        ///
        /// This constructor is not typically called by agents but is used internally
        /// by the class framework. The other constructors can be used to safely
        /// create Query instances to request a specific SIF Data Object. Use the
        /// <c>addCondition</c> and <c>setFieldRestrictions</c> methods
        /// to further define the conditions and SIF elements specified by the query.
        ///
        /// </summary>
        /// <param name="query">A SIF_Query object received in a SIF_Request message
        /// </param>
        /// <exception cref="AdkUnknownOperatorException">If one of the operators in the SIF_Query is
        /// unrecognized by the ADK</exception>
        /// <exception cref="AdkSchemaException">If the object or elements defined in the query or
        /// not recognized by the ADK </exception>
        public Query(SIF_Query query)
        {
            SIF_QueryObject qo = query.SIF_QueryObject;

            if (qo == null)
            {
                throw new ArgumentException("SIF_Query must have a SIF_QueryObject element");
            }

            fObjType = Adk.Dtd.LookupElementDef(qo.ObjectName);
            if (fObjType == null)
            {
                throw new AdkSchemaException
                          (qo.ObjectName +
                          " is not a recognized SIF Data Object, or the agent is not configured to support this object type");
            }
            fRoot = null;

            SIF_ConditionGroup cg = query.SIF_ConditionGroup;

            if (cg != null && cg.GetSIF_Conditionses() != null)
            {
                GroupOperator grpOp;

                try
                {
                    grpOp = Condition.ParseGroupOperator(cg.Type);
                }
                catch (AdkUnknownOperatorException)
                {
                    grpOp = GroupOperator.None;
                }

                fRoot = new ConditionGroup(grpOp);

                SIF_Conditions[] sifConds = cg.GetSIF_Conditionses();

                if (sifConds.Length == 1)
                {
                    //  There is one SIF_ConditionGroup with one SIF_Conditions,
                    //  so just add all of the conditions (no nested groups)
                    string typ = sifConds[0].Type;
                    if (typ == null)
                    {
                        throw new AdkSchemaException
                                  ("SIF_Conditions/@Type is a required attribute");
                    }

                    fRoot.fOp = Condition.ParseGroupOperator(typ);
                    SIF_Condition[] clist = sifConds[0].GetSIF_Conditions();
                    PopulateConditions(query, clist, fRoot);
                }
                else
                {
                    //  There are multiple SIF_Conditions, so add each as a nested
                    //  ConditionGroup of the fRoot
                    for (int i = 0; i < sifConds.Length; i++)
                    {
                        ConditionGroup nested =
                            new ConditionGroup(Condition.ParseGroupOperator(sifConds[i].Type));
                        PopulateConditions(query, sifConds[i].GetSIF_Conditions(), nested);
                        fRoot.AddGroup(nested);
                    }
                }
            }

            SifVersion[] reqVersions = null;
            // First, try to get the version from the SIF_Request
            Element parent = query.Parent;

            if (parent != null)
            {
                if (parent is SIF_Request)
                {
                    SIF_Request  request  = (SIF_Request)parent;
                    SifVersion[] versions = request.parseRequestVersions(Adk.Log);
                    if (versions.Length > 0)
                    {
                        reqVersions = versions;
                    }
                }
            }

            if (reqVersions == null)
            {
                SifVersion version = query.EffectiveSIFVersion;
                if (version != null)
                {
                    reqVersions = new SifVersion[] { version };
                }
            }

            if (reqVersions == null || reqVersions.Length == 0)
            {
                throw new ArgumentException(
                          "SIF_Query is not contained in a SIF_Request that has a SIF_Version element; cannot determine version of SIF to associated with this Query object");
            }
            else
            {
                fVersions = reqVersions;
            }

            SIF_Element[] fields = query.SIF_QueryObject.GetSIF_Elements();
            if (fields != null && fields.Length > 0)
            {
                for (int i = 0; i < fields.Length; i++)
                {
                    string xPath = fields[i].TextValue;
                    if (xPath == null || xPath.Length == 0)
                    {
                        continue;
                    }
                    AddFieldRestriction(xPath);
                }
            }
        }
Esempio n. 12
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");
        }
Esempio n. 13
0
        /**
         *  SIF_Request
         */
        public SIF_Ack SifRequest(IZone zone, Query query, String destinationId, String sifMsgId)
        {
            //  Send SIF_Request...
            SIF_Request msg = new SIF_Request();
            // Find the maxmimum requested version and set the version of the message to lower
            // if the version is currently higher than the highest requested version.
            // In other words, if the Adk is initialized to 2.0, but the highest requested version
            // is 1.5r1, set the message version to 1.5r1
            SifVersion highestRequestVersion = SifVersion.SIF11;

            if (query.ObjectType == InfraDTD.SIF_ZONESTATUS)
            {
                // This query will be satisfied by the ZIS. Use the ZIS compatibility
                // version, which returns the highest version supported by the ZIS
                // (Default to Adk.SIFVersion() if not specified in the config)
                highestRequestVersion = ((ZoneImpl)zone).HighestEffectiveZISVersion;
                msg.AddSIF_Version(new SIF_Version(highestRequestVersion));
            }
            else
            {
                SifVersion[] requestVersions = query.SifVersions;
                if (requestVersions.Length > 0)
                {
                    // If the Query has one or more SIFVersions set, use them,
                    // and also add [major].*
                    foreach (SifVersion version in requestVersions)
                    {
                        msg.AddSIF_Version(new SIF_Version(version));
                        if (version.CompareTo(highestRequestVersion) > 0)
                        {
                            highestRequestVersion = version;
                        }
                    }
                }
                else
                {
                    highestRequestVersion = Adk.SifVersion;
                    if (highestRequestVersion.Major == 1)
                    {
                        msg.AddSIF_Version(new SIF_Version(highestRequestVersion));
                    }
                    else
                    {
                        // 2.0 and greater, request all data using
                        // [major].*, with 2.0r1 as the message version
                        // This allows for maximum compatibility will all 2.x providers
                        msg.AddSIF_Version(new SIF_Version(highestRequestVersion.Major + ".*"));
                        msg.SifVersion = SifVersion.GetEarliest(highestRequestVersion.Major);
                    }
                }
            }

            AgentProperties zoneProperties = zone.Properties;

            if (zoneProperties.OverrideSifMessageVersionForSifRequests != null)
            {
                //There is a property in Agent.cfg that can be used to override the message version from the
                //default of 2.0r1 This is needed to pass the test harness for 2.3
                msg.SifVersion = SifVersion.Parse(zoneProperties.OverrideSifMessageVersionForSifRequests);
            }

            else if (msg.SifVersion.CompareTo(highestRequestVersion) > 0)
            {
                // The current version of the SIF_Message is higher than the highest
                // requested version. Back the version number of message down to match
                msg.SifVersion = highestRequestVersion;
            }

            msg.SIF_MaxBufferSize = zone.Properties.MaxBufferSize;

            SIF_Query sifQ = CreateSIF_Query(query, highestRequestVersion, zone);

            msg.SIF_Query = sifQ;

            SIF_Header msgHeader = msg.Header;

            if (destinationId != null)
            {
                msgHeader.SIF_DestinationId = destinationId;
            }
            if (sifMsgId != null)
            {
                msgHeader.SIF_MsgId = sifMsgId;
            }

            // Set the SIF_Context
            msgHeader.SIF_Contexts = new SIF_Contexts(
                new SIF_Context(query.SifContext.Name));

            return(((ZoneImpl)zone).Dispatcher.send(msg));
        }
Esempio n. 14
0
 /// <summary>  Store the request MsgId and associated SIF Data Object type in the cache</summary>
 public abstract IRequestInfo StoreRequestInfo(SIF_Request request,
                                               Query query,
                                               IZone zone);
Esempio n. 15
0
        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();
        }
Esempio n. 16
0
	private void SetRequestPolicy( SIF_Request request, IZone zone )
	{
		SIF_Query query = request.SIF_Query;
		if( query == null ) {
			// SIF_ExtendedQuery and SIF_Example are not supported by ADK Policy yet
			return;
		}
		
		//
		// Object Request Policy
		//
		// Determine if there is policy in effect for this Query
		//
		String objectName = query.SIF_QueryObject.ObjectName;
		ObjectRequestPolicy requestPolicy = fPolicyFactory.GetRequestPolicy( zone, objectName );
		if( requestPolicy != null ){
			
			//
			// SIF_Request/SIF_Version policy
			//
			String requestVersions = requestPolicy.RequestVersion;
			if( requestVersions != null ){
				if( (Adk.Debug & AdkDebugFlags.Policy ) > 0 ){
					zone.Log.Info( "POLICY: Setting SIF_Request/SIF_Version to " + requestVersions );
				}
				// Clear the list of SIF Versions
				foreach( SIF_Version existingVersion in request.GetSIF_Versions() ){
					request.RemoveChild( existingVersion );
				}
				
				// The version will be a comma-delimited list. Set each of these
				// as SIF_Version elements, but also try to derive the most logical
				// version element to set the SIF Message/@Version attribute to
				// NOTE: Someone could theoretically set versions incorrectly, such
				// as "1.1,1.5r1". Multiple SIF_Version elements are not supported in
				// SIF 1.x, but we won't bother with validating incorrect settings. Policy
				// is power in the configurator's hands to use or abuse.

				String[] versions = requestVersions.Split( ',' );
				String lowestVersion = versions[0];
				foreach( String version in versions ){
				    String ver = version.Trim();
                    request.AddSIF_Version(new SIF_Version(ver));
                    if (lowestVersion.CompareTo(ver) > 0)
                    {
                        lowestVersion = ver;
					}
				}
				
				// Determine how the SIF_Message/@Version should be set to
				//  * If the policy is set to a single version, use it 
				//  * If a list, use the lowest
				//  * If *, ignore
				//  * if [major].*, use the lowest version supported
				if( lowestVersion.Length > 0  ){
					SifVersion newMsgVersion = null;
					if( lowestVersion.EndsWith( "*" ) ){
						try
						{
							// 2.*, requests go out with a message version of 2.0r1
							int major = int.Parse(  lowestVersion.Substring( 0, 1 ) );
							newMsgVersion = SifVersion.GetEarliest( major );
							
						} catch( FormatException iae ){
							zone.Log.Warn( 
									"POLICY: Error parsing ObjectRequestPolicy version '" + 
									requestVersions + "' : " + 
									iae.Message, iae );
						}
						
					} else {
						try
						{
							newMsgVersion = SifVersion.Parse( lowestVersion );
						} catch( FormatException iae ){
							zone.Log.Warn( 
									"POLICY: Error parsing ObjectRequestPolicy version '" + 
									requestVersions + "' : " + 
									iae.Message, iae );
						}
					}
					if( newMsgVersion != null ){
						if( (Adk.Debug & AdkDebugFlags.Policy ) > 0 ){
							zone.Log.Info( "POLICY: Setting SIF_Messaage/@Version to " + newMsgVersion );
						}
						request.SifVersion = newMsgVersion;
					}
				}
			}
			
			//
			// SIF_DestinationID policy
			//
			String requestSourceId = requestPolicy.RequestSourceId ;
			if( requestSourceId != null ){
				if( (Adk.Debug & AdkDebugFlags.Policy) > 0 ){
					zone.Log.Info( "POLICY: Setting SIF_Request SIF_DestinationID to " + requestPolicy.RequestSourceId );
				}
				request.SIF_Header.SIF_DestinationId = requestSourceId;
			}
		}
	}