Exemple #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");
        }
        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);
        }
        private static SIF_ConditionGroup createConditionGroup(Query query, SifVersion effectiveVersion)
        {
            // Create the hierarchy SIF_ConditionGroup
            //                              >    SIF_Conditons
            //                                        > SIF_Condition

            // From
            //                       ConditionGroup
            //								> [ConditionGroup (Optional)]
            //										> Condition

            SIF_ConditionGroup returnGroup = new SIF_ConditionGroup();

            returnGroup.Type = ConditionType.NONE.ToString();
            ConditionGroup cg = query.RootConditionGroup;

            ConditionGroup[] groups = cg.Groups;
            if (groups != null && groups.Length > 0)
            {
                //
                //	There's one or more ConditionGroups...
                //  These get translated to SIF_Conditions elements
                //
                if (cg.Operator == GroupOperator.Or)
                {
                    returnGroup.Type = ConditionType.OR.ToString();
                }
                else if (cg.Operator == GroupOperator.And)
                {
                    returnGroup.Type = ConditionType.AND.ToString();
                }

                foreach (ConditionGroup group in groups)
                {
                    returnGroup.AddSIF_Conditions(createConditions(query, group, effectiveVersion));
                }
            }
            else
            {
                //
                //	There are no SIF_Conditions groups, so build one...
                //
                returnGroup.AddSIF_Conditions(createConditions(query, cg, effectiveVersion));
            }
            return(returnGroup);
        }
Exemple #4
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);
                }
            }
        }