Ejemplo n.º 1
0
        public void testCreateWithSIF_Query()
        {
            SIF_Query q = new SIF_Query(new SIF_QueryObject(
                                            ReportingDTD.STUDENTLOCATOR.Name));
            SIF_ConditionGroup scg = new SIF_ConditionGroup();

            scg.SetType(ConditionType.NONE);

            SIF_Condition sifCondition = new SIF_Condition(
                "RequestingAgencyId[@Type=\"School\"]", Operators.EQ, "2001");
            SIF_Conditions conds = new SIF_Conditions(ConditionType.NONE);

            conds.AddChild(sifCondition);
            scg.AddSIF_Conditions(conds);
            q.SIF_ConditionGroup = scg;

            Query query = new Query(q);

            Assert.IsTrue(query.HasConditions);
            ConditionGroup[] conditions = query.Conditions;
            Assert.AreEqual(1, conditions.Length, "One Condition Group");
            Assert.AreEqual(GroupOperator.None, conditions[0].Operator, "None");
            Condition condition = conditions[0].Conditions[0];

            Assert.AreEqual("2001", condition.Value, "RequestingAgencyId");
            Assert.AreEqual(ComparisonOperators.EQ, condition.Operators, "RequestingAgencyId");
            Assert.AreEqual(ReportingDTD.STUDENTLOCATOR_REQUESTINGAGENCYID, condition.Field, "RequestingAgencyId");
        }
Ejemplo n.º 2
0
        /**
       * 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);
            }
        }
Ejemplo n.º 3
0
        public void CustomSIFElementEncoding()
        {
            SIF_Query q = new SIF_Query();

            q.SIF_QueryObject = new SIF_QueryObject(StudentDTD.STUDENTPERSONAL.Name);
            SIF_Conditions conditions = new SIF_Conditions(ConditionType.NONE);

            conditions.AddSIF_Condition("Name[@Type=\"05\"]/LastName", Operators.EQ, "Cookie");
            q.SetSIF_ConditionGroup(ConditionType.NONE, conditions);

            string xml;

            using (StringWriter w = new StringWriter())
            {
                SifWriter writer = new SifWriter(w);
                writer.Write(q);
                writer.Flush();
                writer.Close();
                xml = w.ToString();
            }

            Console.WriteLine(xml);
            // Mainly, just check to make sure that the single quotes didn't get encoded
            int index = xml.IndexOf("&quot;");

            Assert.AreEqual(-1, index, "Single quotes should not be encoded");
        }
Ejemplo n.º 4
0
 private void PopulateConditions(SIF_Query query,
                                 SIF_Condition[] clist,
                                 ConditionGroup target)
 {
     for (int i = 0; i < clist.Length; i++)
     {
         String o = clist[i].SIF_Operator;
         ComparisonOperators ops = Condition.ParseComparisionOperators(o);
         String val  = clist[i].SIF_Value;
         String path = clist[i].SIF_Element;
         target.AddCondition(fObjType, path, ops, val);
     }
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public void SDOParse()
        {
            ReportManifest rm = new ReportManifest();

            rm.RefId = "C234516384746B387459000F84723A00";
            rm.ReportAuthorityInfoRefId = "84756373645746363738484848484832";
            SIF_Version version = new SIF_Version();

            version.SifVersion = SifVersion.LATEST;
            rm.SIF_Version     = version.ToString();

            rm.SetReceivingAuthority("84756373645746363738484848484812", "");
            rm.ReportName  = "December 1 IDEA Students";
            rm.Description = "A report of all IDEA-eligible students receiving services on December 1";

            ReportingPeriod period = new ReportingPeriod();

            period.BeginReportDate = new DateTime?(new DateTime(2003, 12, 01));
            period.EndReportDate   = new DateTime?(new DateTime(2003, 12, 01));
            period.BeginSubmitDate = new DateTime?(new DateTime(2003, 12, 01));
            period.EndSubmitDate   = new DateTime?(new DateTime(2003, 12, 01));
            period.DueDate         = new DateTime?(new DateTime(2003, 12, 01));
            rm.ReportingPeriod     = period;

            rm.SetReportDefinitionSource(ReportDefinitionSourceType.URL, "http://www.state.edu/IDEAEligible.html");
            SIF_QueryGroup group = new SIF_QueryGroup();

            rm.SIF_QueryGroup = group;

            SIF_Query query = new SIF_Query();

            query.SetSIF_QueryObject("StudentPersonal");
            group.Add(query);

            query = new SIF_Query();
            group.Add(query);
            query.SetSIF_QueryObject("StudentSchoolEnrollment");

            SIF_ConditionGroup condGroup = new SIF_ConditionGroup();
            SIF_Conditions     conds     = new SIF_Conditions();

            conds.AddSIF_Condition("EntryDate", Operators.EQ, "20031201");
            condGroup.AddChild(conds);
            query.SIF_ConditionGroup = condGroup;

            // NOTE: This will currently fail every time, due to a bug in
            // CompareGraphTo
            AdkObjectParseHelper.runParsingTest(rm, SifVersion.LATEST);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns the XML representation of this Query in the format required by SIF
        /// for the specified version
        /// </summary>
        /// <param name="version">The SIF Version to render the Query in. The ADK will attempt to render
        /// the query path using the proper element or attribute names for the version of SIF
        /// </param>
        /// <returns>a string containing the XML representation as a SIF_Query element. If an error
        /// occurs during the conversion, an empty string ("") is returned.
        /// </returns>
        public String ToXml(SifVersion version)
        {
            // Create a SIF_Query object
            SIF_Query sifQ = SIFPrimitives.CreateSIF_Query(this, version, true);

            try
            {
                using (StringWriter outStream = new StringWriter())
                {
                    SifWriter w = new SifWriter(outStream);
                    w.Write(sifQ);
                    w.Flush();
                    return(outStream.ToString());
                }
            }
            catch (Exception e)
            {
                Adk.Log.Warn("Error creating XML equivalent of Query: " + e, e);
                return("");
            }
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        /**
         * Creates a SIF_Query element from the specified Adk query object using
         * the specified version of SIF
         * @param query The Query to convert to a SIF_Query
         * @param version The version of SIF to render the SIF_Query xml in
         * @param allowFieldRestrictions True if the field restrictions in the query should be rendered
         * @return a SIF_Query object
         */
        public static SIF_Query CreateSIF_Query(Query query, SifVersion version, bool allowFieldRestrictions)
        {
            SIF_QueryObject sqo  = new SIF_QueryObject(query.ObjectType.Tag(version));
            SIF_Query       sifQ = new SIF_Query(sqo);

            if (query.HasConditions)
            {
                sifQ.SIF_ConditionGroup = createConditionGroup(query, version);
            }

            if (allowFieldRestrictions && query.HasFieldRestrictions)
            {
                foreach (ElementRef elementRef in query.FieldRestrictionRefs)
                {
                    String      path  = null;
                    IElementDef field = elementRef.Field;
                    if (field != null)
                    {
                        if (!field.IsSupported(version))
                        {
                            continue;
                        }
                        path = field.GetSQPPath(version);
                    }
                    if (path == null)
                    {
                        path = elementRef.XPath;
                    }
                    if (path != null)
                    {
                        path = Adk.Dtd.TranslateSQP(query.ObjectType, path, version);
                        sqo.AddSIF_Element(new SIF_Element(path));
                    }
                }
            }

            return(sifQ);
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
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);
                }
            }
        }
Ejemplo n.º 14
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));
        }
Ejemplo n.º 15
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;
			}
		}
	}
        public void testSifResponseSender010()
        {
            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>";

            string sectionInfoStr =
                @"<SectionInfo RefId='D9C9889878144863B190C7D3428D7953' SchoolCourseInfoRefId='587F89D23EDD4761A59C04BA0D39E8D9' SchoolYear='2008'>
                                                  <LocalId>1</LocalId>
                                                  <Description>section 19</Description>
                                                  <ScheduleInfoList>
                                                    <ScheduleInfo TermInfoRefId='0D8165B1ADB34780BD1DFF9E38A7B935'>
                                                      <TeacherList>
                                                        <StaffPersonalRefId>F9D3916707634682B84C530BCF96B5CA</StaffPersonalRefId>
                                                      </TeacherList>
                                                      <SectionRoomList>
                                                        <RoomInfoRefId>EED167D761CD493EA94A875F56ABB0CB</RoomInfoRefId>
                                                      </SectionRoomList>
                                                      <MeetingTimeList>
                                                        <MeetingTime>
                                                          <TimetableDay>R</TimetableDay>
                                                          <TimetablePeriod>6</TimetablePeriod>
                                                        </MeetingTime>
                                                        <MeetingTime>
                                                          <TimetableDay>F</TimetableDay>
                                                          <TimetablePeriod>6</TimetablePeriod>
                                                        </MeetingTime>
                                                        <MeetingTime>
                                                          <TimetableDay>W</TimetableDay>
                                                          <TimetablePeriod>6</TimetablePeriod>
                                                        </MeetingTime>
                                                        <MeetingTime>
                                                          <TimetableDay>M</TimetableDay>
                                                          <TimetablePeriod>6</TimetablePeriod>
                                                        </MeetingTime>
                                                        <MeetingTime>
                                                          <TimetableDay>T</TimetableDay>
                                                          <TimetablePeriod>6</TimetablePeriod>
                                                        </MeetingTime>
                                                      </MeetingTimeList>
                                                    </ScheduleInfo>
                                                  </ScheduleInfoList>
                                                  <MediumOfInstruction><Code>0605</Code></MediumOfInstruction>
                                                  <LanguageOfInstruction><Code>eng</Code></LanguageOfInstruction>
                                                  <SummerSchool>No</SummerSchool>
                                                </SectionInfo>";


            SifParser   parser   = SifParser.NewInstance();
            SIF_Query   sifquery = (SIF_Query)parser.Parse(queryStr);
            SectionInfo section  = (SectionInfo)parser.Parse(sectionInfoStr);
            Query       query    = new Query(sifquery);

            String     SifRequestMsgId = Adk.MakeGuid();
            String     sourceId        = "TEST_SOURCEID";
            SifVersion testVersion     = SifVersion.LATEST;
            int        maxBufferSize   = int.MaxValue;

            MessageDispatcher testDispatcher = new MessageDispatcher(Zone);

            Zone.SetDispatcher(testDispatcher);
            Zone.Connect(ProvisioningFlags.None);
            InMemoryProtocolHandler testProto = (InMemoryProtocolHandler)Zone.ProtocolHandler;

            testProto.clear();

            SifResponseSender srs = new SifResponseSender();

            srs.Open(Zone, SifRequestMsgId, sourceId, testVersion, maxBufferSize, query);
            srs.Write(section);
            srs.Close();

            // Retrieve the SIF_Response message off the protocol handler and asssert the results
            SIF_Response response = (SIF_Response)testProto.readMsg();

            Assert.AreEqual(SifRequestMsgId, response.SIF_RequestMsgId);
            Assert.AreEqual(1, response.SIF_PacketNumber.Value);
            Assert.AreEqual("No", response.SIF_MorePackets);

            SIF_Header header = response.SIF_Header;

            Assert.AreEqual(sourceId, header.SIF_DestinationId);

            SifDataObject responseObject = (SifDataObject)response.SIF_ObjectData.GetChildList()[0];

            Assert.IsNotNull(responseObject);

            Console.Out.WriteLine(responseObject.ToXml());

            SifXPathContext context = SifXPathContext.NewSIFContext(responseObject);

            foreach (ElementRef reference in query.FieldRestrictionRefs)
            {
                Element found = context.GetElementOrAttribute(reference.XPath);
                Assert.IsNotNull(found, reference.XPath);
            }


            Element sectionInfoList =
                responseObject.GetElementOrAttribute("ScheduleInfoList/ScheduleInfo/SectionInfoList");

            Assert.IsNull(sectionInfoList);
        }
Ejemplo n.º 17
0
 ///<summary>Sets the value of the <c>&lt;SIF_QueryGroup&gt;</c> element.</summary>
 /// <param name="SifQuery">A SIF_Query</param>
 ///<remarks>
 /// <para>This form of <c>setSIF_QueryGroup</c> is provided as a convenience method
 /// that is functionally equivalent to the <c>SIF_QueryGroup</c></para>
 /// <para>Version: 2.6</para>
 /// <para>Since: 2.3</para>
 /// </remarks>
 public void SetSIF_QueryGroup(SIF_Query SifQuery)
 {
     RemoveChild(ReportingDTD.REPORTMANIFEST_SIF_QUERYGROUP);
     AddChild(ReportingDTD.REPORTMANIFEST_SIF_QUERYGROUP, new SIF_QueryGroup(SifQuery));
 }