Esempio n. 1
0
        public IQueryable<EnhancedStudentInformation> ApplyFilter(IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            //If the Staff USI Isn't set, then no-op.
            if (providerQueryOptions.StaffUSI <= 0)
                return query;

            //The only way a Staff member can be associated with a student at LEA is via the Staff Cohort tables.  Only check that one table.
            if (providerQueryOptions.LocalEducationAgencyId.HasUsableValue() && !providerQueryOptions.SchoolId.HasUsableValue())
            {
                var staffStudentCohorts = StaffStudentCohortRepository.GetAll();
                IQueryable<StaffCohort> staffCohort = StaffCohortRepository.GetAll().Where(sc => sc.StaffUSI == providerQueryOptions.StaffUSI);

                return query.Where(si => staffStudentCohorts
                    .SelectMany(ssc => staffCohort.Where(sc => ssc.StaffCohortId == sc.StaffCohortId).Select(sc => ssc))
                    .Any(ssc => ssc.StudentUSI == si.StudentUSI));
            }

            //At the school level, a staff member can be associated by Cohort or by Section.  This view collapses the two.
            var ssa = StaffStudentAssociationRepository.GetAll();
            return query.Where(student => ssa.Any(ms => ms.StudentUSI == student.StudentUSI
                                                        && ms.SchoolId == student.SchoolId
                //This filters on school id, because if a teacher is a teacher at two schools,
                //We need to filter on the Staff Section records only for the current school.
                                                        && ms.SchoolId == providerQueryOptions.SchoolId.GetValueOrDefault()
                                                        && ms.StaffUSI == providerQueryOptions.StaffUSI));
        }
        public IQueryable<EnhancedStudentInformation> ApplyFilter(IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            if (!providerQueryOptions.LocalEducationAgencyId.HasUsableValue())
                return query;

            return query.Where(student => student.LocalEducationAgencyId == providerQueryOptions.LocalEducationAgencyId.Value);
        }
Esempio n. 3
0
        public IQueryable<EnhancedStudentInformation> ApplyFilter(IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            if (!providerQueryOptions.SchoolId.HasUsableValue())
                return query;

            return query.Where(student => student.SchoolId == providerQueryOptions.SchoolId.GetValueOrDefault());
        }
Esempio n. 4
0
        public IQueryable<EnhancedStudentInformation> ApplyFilter(IQueryable<EnhancedStudentInformation> query,
            StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            if (providerQueryOptions.SchoolCategory == null)
                return query;

            return query.Where(student => student.SchoolCategory.Contains(providerQueryOptions.SchoolCategory));
        }
Esempio n. 5
0
        public IQueryable<EnhancedStudentInformation> ApplyFilter(IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            if (!providerQueryOptions.SchoolMetricStudentListMetricId.HasValue)
                return query;

            var schoolMetricStudentList = SchoolMetricStudentListRepository.GetAll();
            return query.Where(student => schoolMetricStudentList.Any(smsl =>
                smsl.StudentUSI == student.StudentUSI
                && smsl.SchoolId == student.SchoolId
                && smsl.MetricId == providerQueryOptions.SchoolMetricStudentListMetricId.Value));
        }
Esempio n. 6
0
        public IQueryable<EnhancedStudentInformation> ApplyFilter(IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            if (providerQueryOptions.StaffCohortIds == null || !providerQueryOptions.StaffCohortIds.Any())
                return query;

            return from studentItemWithMetrics in query
                from staffStudentCohort in
                    StaffStudentCohortRepository.GetAll()
                        .Where(cohort => cohort.StudentUSI == studentItemWithMetrics.StudentUSI)
                where providerQueryOptions.StaffCohortIds.Contains(staffStudentCohort.StaffCohortId)
                select studentItemWithMetrics;
        }
Esempio n. 7
0
        public IQueryable<EnhancedStudentInformation> ApplyFilter(IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            if (providerQueryOptions.StudentIds == null)
                return query;

            var enumerableStudentIds = providerQueryOptions.StudentIds as long[] ??
                                       providerQueryOptions.StudentIds.ToArray();

            if (!enumerableStudentIds.Any())
                return query;

            return query.Where(metrics => enumerableStudentIds.Contains(metrics.StudentUSI));
        }
Esempio n. 8
0
        public IQueryable<EnhancedStudentInformation> ApplyFilter(IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            if (providerQueryOptions.TeacherSectionIds == null || !providerQueryOptions.TeacherSectionIds.Any())
                return query;

            return from studentItemWithMetrics in query
                from teacherStudentSection in
                    TeacherStudentSectionRepository.GetAll()
                        .Where(section => section.StudentUSI == studentItemWithMetrics.StudentUSI)
                where
                    providerQueryOptions.TeacherSectionIds.Contains(teacherStudentSection.TeacherSectionId)
                select studentItemWithMetrics;
        }
Esempio n. 9
0
        public IQueryable<EnhancedStudentInformation> ApplyFilter(IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            if (providerQueryOptions.GradeLevel == null || !providerQueryOptions.GradeLevel.Any())
                return query;

            var studentsWithinGradeLevel = ExpressionExtensions.False<EnhancedStudentInformation>();
            foreach (var gradeLevel in providerQueryOptions.GradeLevel)
            {
                var levelForClosure = gradeLevel;
                studentsWithinGradeLevel = studentsWithinGradeLevel.Or(x => x.GradeLevel == levelForClosure);
            }

            return query.Where(studentsWithinGradeLevel);
        }
        protected override void EstablishContext()
        {
            queryOptions = GetStudentMetricsProviderQueryOptions();

            if (sortColumn != null && sortColumn.MetricVariantId == SpecialMetricVariantSortingIds.Designations)
            {
                studentAccomodationCountAndMaxValueRepository =
                    mocks.StrictMock<IRepository<StudentAccommodationCountAndMaxValue>>();
                Expect.Call(studentAccomodationCountAndMaxValueRepository.GetAll())
                      .Return(GetStudentAccommodationCountAndMaxValue())
                      .Repeat.AtLeastOnce();
            }

            enhancedStudentInformationRepository = mocks.StrictMock<IRepository<EnhancedStudentInformation>>();
            Expect.Call(enhancedStudentInformationRepository.GetAll()).Return(GetEnhancedStudentInformation()).Repeat.AtLeastOnce();
            
			studentMetricRepository = mocks.StrictMock<IRepository<StudentMetric>>();
            Expect.Call(studentMetricRepository.GetAll()).Return(GetStudentMetric()).Repeat.AtLeastOnce();

            if (queryOptions.MetricVariantIds != null && queryOptions.MetricVariantIds.Any())
            {
                //This is only used for doing the sort column, the above condition needs more work
                stateAssessmentMetricIdGroupingProvider = mocks.StrictMock<IStateAssessmentMetricIdGroupingProvider>();
                Expect.Call(stateAssessmentMetricIdGroupingProvider.GetMetricVariantGroupIds())
                      .Return(GetStateAssessmentMetricIdGrouping())
                      .Repeat.AtLeastOnce();
            }

            if (sortColumn != null && sortColumn.MetricVariantId == SpecialMetricVariantSortingIds.SchoolMetricStudentList)
            {
                //This is only used for doing the sort column, the above condition needs more work
                schoolMetricStudentListRepository = mocks.StrictMock<IRepository<SchoolMetricStudentList>>();
                Expect.Call(schoolMetricStudentListRepository.GetAll())
                      .Return(GetSchoolMetricStudentList())
                      .Repeat.AtLeastOnce();
            }

            studentMetricFilter = mocks.StrictMock<IStudentMetricFilter>();
            Expect.Call(studentMetricFilter.ApplyFilter(null, null)).IgnoreArguments().Return(null).WhenCalled(_ => _.ReturnValue = (IQueryable<EnhancedStudentInformation>)_.Arguments[0]).Repeat.AtLeastOnce();
            
            studentMetricsProvider = new StudentMetricsProvider(studentAccomodationCountAndMaxValueRepository,
                                                                enhancedStudentInformationRepository,
                                                                studentMetricRepository,
                                                                schoolMetricStudentListRepository,
                                                                stateAssessmentMetricIdGroupingProvider,
                                                                new[] { studentMetricFilter }
                                                                );

            
        }
 protected override void ExecuteTest()
 {
     Result = StudentWatchListManager.CreateStudentMetricsProviderQueryOptions(
         SuppliedWatchListData,
         SuppliedMetricVariantIds,
         SuppliedSchoolId,
         SuppliedLocalEducationAgencyId,
         SuppliedStaffUsi,
         SuppliedStudentIds,
         SuppliedSectionOrCohortId,
         SuppliedStudentListType,
         SuppliedDemographicOptionGroups,
         SuppliedSchoolCategory,
         SuppliedGradeLevel
         );
 }
Esempio n. 12
0
        protected virtual IQueryable<StudentMetric> FilterByMetrics(IQueryable<StudentMetric> query, StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            // in cases where there have been no students specified, should return no metrics unless GetAllMetrics option is used
            //   This is used to prevent accidentally selecting the whole database.  There is not currently a use case where you need to
            //   select all metrics, you only need to select the metrics for the current page of users.
            if (!providerQueryOptions.GetAllMetrics &&
                (providerQueryOptions.StudentIds == null || !providerQueryOptions.StudentIds.Any()))
                query = query.Where(metrics => false);

            if (providerQueryOptions.MetricVariantIds != null)
            {
                var enumerableMetricVariantIds = providerQueryOptions.MetricVariantIds as int[] ??
                                                 providerQueryOptions.MetricVariantIds.ToArray();

                var groupingIds = StateAssessmentMetricIdGroupingProvider.GetMetricVariantGroupIds();
                enumerableMetricVariantIds = enumerableMetricVariantIds.Concat(groupingIds).ToArray();

                if (enumerableMetricVariantIds.Any())
                    query = query.Where(metrics => enumerableMetricVariantIds.Contains(metrics.MetricVariantId));
            }
            return query;
        }
Esempio n. 13
0
 /// <summary>
 /// Applies the query options and security.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <param name="providerQueryOptions">The provider query options.</param>
 /// <returns></returns>
 protected virtual IQueryable<EnhancedStudentInformation> ApplyQueryOptionsAndSecurity(
     IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
 {
     foreach (var filter in StudentMetricFilter)
     {
         query = filter.ApplyFilter(query, providerQueryOptions);
     }
     
     return query;
 }
Esempio n. 14
0
        public IQueryable<StudentMetric> GetStudentsWithMetrics(StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            var studentThatWillBeShown = ApplyQueryOptionsAndSecurity(EnhancedStudentInformationRepository.GetAll(),
                providerQueryOptions);
            var query = from studentMetrics in StudentMetricRepository.GetAll()
                join esi in studentThatWillBeShown on new {studentMetrics.StudentUSI, studentMetrics.SchoolId} equals
                    new {esi.StudentUSI, esi.SchoolId}
                select studentMetrics;

            return FilterByMetrics(query, providerQueryOptions);
        }
Esempio n. 15
0
 public IQueryable<EnhancedStudentInformation> GetOrderedStudentList(
     StudentMetricsProviderQueryOptions providerQueryOptions, MetadataColumn sortColumn = null,
     string sortDirection = "", int? schoolMetricStudentListMetricId = null)
 {
     var query = ApplyQueryOptionsAndSecurity(EnhancedStudentInformationRepository.GetAll(), providerQueryOptions);
     return SortStudents(query, sortColumn, sortDirection, schoolMetricStudentListMetricId);
 }
Esempio n. 16
0
 public IQueryable<EnhancedStudentInformation> ApplyFilter(IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
 {
     return ApplySecurityFilter(query, providerQueryOptions);
 }
        protected override void ExecuteTest()
        {
            var queryOptions = new StudentMetricsProviderQueryOptions
            {
                MetricOptionGroups = new[]
                {
                    new MetricFilterOptionGroup
                    {
                        MetricFilterOptions = new[]
                        {
                            new MetricFilterOption
                            {
                                MetricId = 1,
                                MaxExclusiveMetricInstanceExtendedProperty = "Test",
                            }
                        }
                    }
                }
            };

            studentResults = filter.ApplyFilter(query, queryOptions);
        }
 /// <summary>
 /// Gets the student list. This is broken out into its own method so
 /// other projects can change how this data is retrieved.
 /// </summary>
 /// <param name="queryOptions">The query options.</param>
 /// <param name="sortColumn">The sort column.</param>
 /// <param name="sortDirection">The sort direction.</param>
 /// <returns></returns>
 protected virtual IQueryable<EnhancedStudentInformation> GetStudentList(
     StudentMetricsProviderQueryOptions queryOptions, MetadataColumn sortColumn = null, string sortDirection = "")
 {
     return StudentMetricsProvider.GetOrderedStudentList(queryOptions, sortColumn, sortDirection);
 }
        protected override void ExecuteTest()
        {
            var queryOptions = new StudentMetricsProviderQueryOptions
            {
                MetricOptionGroups = new[]
                {
                    new MetricFilterOptionGroup
                    {
                        MetricFilterOptions = new[]
                        {
                            new MetricFilterOption
                            {
                                MetricId = 1,
                                MetricStateNotEqualTo = 1
                            }
                        }
                    }
                }
            };

            studentResults = filter.ApplyFilter(query, queryOptions);
        }
        protected override void ExecuteTest()
        {

            var queryOptions = new StudentMetricsProviderQueryOptions
            {
                MetricOptionGroups = new[]
                {
                    new MetricFilterOptionGroup
                    {
                        MetricFilterOptions = new[]
                            {
                                new MetricFilterOption
                                {
                                    MetricId = 1,
                                    ValueLessThan = 5.0d,
                                },
                            }
                    }
                }
            };

            studentResults = filter.ApplyFilter(query, queryOptions);
        }
        protected override void ExecuteTest()
        {

            var queryOptions = new StudentMetricsProviderQueryOptions
            {
                MetricOptionGroups = new[]
                {
                    new MetricFilterOptionGroup
                    {
                        MetricFilterOptions = new[]
                            {
                                new MetricFilterOption
                                {
                                    MetricId = 1,
                                    MetricInstanceEqualTo = SuppliedMetricInstanceValue1,
                                },
                            }
                    }
                }
            };

            studentResults = filter.ApplyFilter(query, queryOptions);
        }
        protected StudentMetricsProviderQueryOptions GetStudentListWithMetricsQueryOptions(StudentListType studentListType)
        {
            var suppliedStudentUSIs = new List<long>();
            var suppliedStaffUsi = 0;

            var queryOptions = new StudentMetricsProviderQueryOptions
            {
                SchoolId = suppliedSchoolId,
                StaffUSI = suppliedStaffUsi,
                StudentIds = suppliedStudentUSIs
            };

            switch (studentListType)
            {
                case StudentListType.Section:
                    queryOptions.TeacherSectionIds = new[]
                    {
                        (long)suppliedSectionId
                    };

                    break;
                case StudentListType.Cohort:
                    queryOptions.StaffCohortIds = new[]
                    {
                        (long)suppliedSectionId
                    };

                    break;
            }

            return queryOptions;
        }
        protected override void ExecuteTest()
        {
            var queryOptions = new StudentMetricsProviderQueryOptions
            {
                MetricOptionGroups = new[] {new MetricFilterOptionGroup()}
            };

            studentResults = filter.ApplyFilter(query, queryOptions);
        }
Esempio n. 24
0
        protected virtual IEnumerable<StudentMetric> GetStudentListWithMetrics(long staffUSI, int schoolId, IEnumerable<long> students)
        {
            var queryOptions = new StudentMetricsProviderQueryOptions
                {
                    SchoolId = schoolId,
                    StaffUSI = staffUSI,
                    StudentIds = students
                };

            return StudentListWithMetricsProvider.GetStudentsWithMetrics(queryOptions);
        }
Esempio n. 25
0
        protected virtual List<EnhancedStudentInformation> GetStudentListEntities(int schoolId, long staffUSI, 
            StudentListIdentity studentListIdentity, List<MetadataColumnGroup> listMetadata, 
            List<long> customStudentIdList, int? sortColumn, string sortDirection)
        {
            var queryOptions = new StudentMetricsProviderQueryOptions
                {
                    MetricVariantIds = listMetadata.GetMetricVariantIds(),
                    SchoolId = schoolId,
                    StaffUSI = staffUSI,
                    StudentIds = customStudentIdList
                };

            switch (studentListIdentity.StudentListType)
            {
                case StudentListType.Section:
                    queryOptions.TeacherSectionIds = new[]
                    {
                        studentListIdentity.Id
                    };

                    break;
                case StudentListType.Cohort:
                    queryOptions.StaffCohortIds = new[]
                    {
                        studentListIdentity.Id
                    };

                    break;
            }

            return
                StudentListWithMetricsProvider.GetOrderedStudentList(queryOptions, GetSortColumn(listMetadata, sortColumn), sortDirection).ToList();
        }
 /// <summary>
 /// Gets the student metrics. This is broken out into its own method so
 /// other projects can change how this data is retrieved.
 /// </summary>
 /// <param name="queryOptions">The query options.</param>
 /// <returns></returns>
 protected virtual IQueryable<StudentMetric> GetStudentMetrics(StudentMetricsProviderQueryOptions queryOptions)
 {
     return StudentMetricsProvider.GetStudentsWithMetrics(queryOptions);
 }
Esempio n. 27
0
        public IQueryable<EnhancedStudentInformation> ApplyFilter(IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            if (providerQueryOptions.MetricOptionGroups == null)
                return query;

            foreach (var metricFilterOptionGroup in providerQueryOptions.MetricOptionGroups)
            {
                if (metricFilterOptionGroup.MetricFilterOptions == null ||
                    !metricFilterOptionGroup.MetricFilterOptions.Any())
                    continue;

                var studentsWithinMetrics = ExpressionExtensions.False<EnhancedStudentInformation>();

                foreach (var metricFilterOption in metricFilterOptionGroup.MetricFilterOptions)
                {
                    var studentsMeetingCurrentOption = ExpressionExtensions.True<EnhancedStudentInformation>();

                    if (metricFilterOption.MetricStateEqualTo.HasValue)
                    {
                        var metricStateTypeId = metricFilterOption.MetricStateEqualTo.Value;

                        studentsMeetingCurrentOption =
                            studentsMeetingCurrentOption.And(information => StudentMetricRepository.GetAll()
                                .Any(
                                    data =>
                                        data.StudentUSI == information.StudentUSI &&
                                        data.SchoolId == information.SchoolId &&
                                        data.MetricId == metricFilterOption.MetricId &&
                                        data.MetricStateTypeId == metricStateTypeId));
                    }

                    if (metricFilterOption.MetricStateNotEqualTo.HasValue)
                    {
                        var metricStateTypeId = metricFilterOption.MetricStateNotEqualTo.Value;

                        studentsMeetingCurrentOption =
                            studentsMeetingCurrentOption.And(information => StudentMetricRepository.GetAll()
                                .Any(
                                    data =>
                                        data.StudentUSI == information.StudentUSI &&
                                        data.SchoolId == information.SchoolId &&
                                        data.MetricId == metricFilterOption.MetricId &&
                                        data.MetricStateTypeId != metricStateTypeId));
                    }

                    if (metricFilterOption.MinInclusiveMetricInstanceExtendedProperty != null)
                    {
                        studentsMeetingCurrentOption =
                            studentsMeetingCurrentOption.And(
                                information => MetricInstanceExtendedPropertyWithValueToFloatRepository.GetAll()
                                    .SelectMany(metricInstanceExtProp => StudentMetricRepository.GetAll().Select(setKey => new { metricInstanceExtProp, setKey }))
                                    .Any(data => data.metricInstanceExtProp.MetricId == metricFilterOption.MetricId &&
                                                 data.setKey.MetricId == data.metricInstanceExtProp.MetricId &&
                                                 data.metricInstanceExtProp.MetricInstanceSetKey == data.setKey.MetricInstanceSetKey &&
                                                 data.setKey.StudentUSI == information.StudentUSI &&
                                                 data.setKey.SchoolId == information.SchoolId &&
                                                 data.metricInstanceExtProp.Name == metricFilterOption.MinInclusiveMetricInstanceExtendedProperty &&
                                                 data.setKey.ValueSortOrder >= data.metricInstanceExtProp.ValueToFloat));
                    }

                    if (metricFilterOption.MaxExclusiveMetricInstanceExtendedProperty != null)
                    {
                        studentsMeetingCurrentOption =
                            studentsMeetingCurrentOption.And(
                                information => MetricInstanceExtendedPropertyWithValueToFloatRepository.GetAll()
                                    .SelectMany(metricInstanceExtProp => StudentMetricRepository.GetAll().Select(setKey => new { metricInstanceExtProp, setKey }))
                                    .Any(data => data.metricInstanceExtProp.MetricId == metricFilterOption.MetricId &&
                                                 data.setKey.MetricId == data.metricInstanceExtProp.MetricId &&
                                                 data.metricInstanceExtProp.MetricInstanceSetKey == data.setKey.MetricInstanceSetKey &&
                                                 data.setKey.StudentUSI == information.StudentUSI &&
                                                 data.setKey.SchoolId == information.SchoolId &&
                                                 data.metricInstanceExtProp.Name == metricFilterOption.MaxExclusiveMetricInstanceExtendedProperty &&
                                                 data.setKey.ValueSortOrder < data.metricInstanceExtProp.ValueToFloat));
                    }

                    if (metricFilterOption.MetricInstanceEqualTo != null)
                    {
                        studentsMeetingCurrentOption = studentsMeetingCurrentOption.And(
                            information => StudentMetricRepository.GetAll()
                                .SelectMany(
                                    metricInstance =>
                                        StudentMetricRepository.GetAll().Select(setKey => new { metricInstance, setKey }))
                                .Any(data => data.metricInstance.MetricId == metricFilterOption.MetricId &&
                                             data.setKey.MetricId == data.metricInstance.MetricId &&
                                             data.metricInstance.MetricInstanceSetKey ==
                                             data.setKey.MetricInstanceSetKey &&
                                             data.setKey.StudentUSI == information.StudentUSI &&
                                             data.setKey.SchoolId == information.SchoolId &&
                                             data.setKey.Value == metricFilterOption.MetricInstanceEqualTo));
                    }

                    if (metricFilterOption.ValueGreaterThanEqualTo.HasValue)
                    {
                        studentsMeetingCurrentOption =
                            studentsMeetingCurrentOption.And(information => StudentMetricRepository.GetAll()
                                .Any(data => data.StudentUSI == information.StudentUSI &&
                                             data.SchoolId == information.SchoolId &&
                                             data.MetricId == metricFilterOption.MetricId &&
                                             data.ValueSortOrder >= metricFilterOption.ValueGreaterThanEqualTo.Value));
                    }

                    if (metricFilterOption.ValueGreaterThan.HasValue)
                    {
                        studentsMeetingCurrentOption =
                            studentsMeetingCurrentOption.And(information => StudentMetricRepository.GetAll()
                                .Any(data => data.StudentUSI == information.StudentUSI &&
                                             data.SchoolId == information.SchoolId &&
                                             data.MetricId == metricFilterOption.MetricId &&
                                             data.ValueSortOrder > metricFilterOption.ValueGreaterThan.Value));
                    }

                    if (metricFilterOption.ValueLessThan.HasValue)
                    {
                        studentsMeetingCurrentOption =
                            studentsMeetingCurrentOption.And(information => StudentMetricRepository.GetAll()
                                .Any(data => data.StudentUSI == information.StudentUSI &&
                                             data.SchoolId == information.SchoolId &&
                                             data.MetricId == metricFilterOption.MetricId &&
                                             data.ValueSortOrder < metricFilterOption.ValueLessThan.Value));
                    }

                    if (metricFilterOption.ValueLessThanEqualTo.HasValue)
                    {
                        studentsMeetingCurrentOption =
                            studentsMeetingCurrentOption.And(information => StudentMetricRepository.GetAll()
                                .Any(data => data.StudentUSI == information.StudentUSI &&
                                             data.SchoolId == information.SchoolId &&
                                             data.MetricId == metricFilterOption.MetricId &&
                                             data.ValueSortOrder <= metricFilterOption.ValueLessThanEqualTo.Value));
                    }

                    studentsWithinMetrics = studentsWithinMetrics.Or(studentsMeetingCurrentOption);
                }

                query = query.Where(studentsWithinMetrics);
            }

            return query;
        }
Esempio n. 28
0
        public IQueryable<EnhancedStudentInformation> ApplySecurityFilter(IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            //The only user that can see everyone are state employees...
            if (CurrentUserClaimInterrogator.HasClaimForStateAgency(EdFiClaimTypes.ViewAllStudents))
                return query;

            //Start off with a lit of empty students we're allowed to see...
            var studentsTheUserCanSee = ExpressionExtensions.False<EnhancedStudentInformation>();

            if (UserInformation.Current == null)
                return query.Where(studentsTheUserCanSee);

            var staffUsi = UserInformation.Current.StaffUSI;

            //Walk through all their associated ed-orgs...
            foreach (var associatedOrganization in UserInformation.Current.AssociatedOrganizations)
            {
                //Find what they have permissions to, and let them see just those students.
                foreach (var claimType in associatedOrganization.ClaimTypes)
                {
                    var educationOrganizationId = associatedOrganization.EducationOrganizationId;

                    // TODO: Find the value for the state id...in dev it is set to int.MaxValue so this will work for now
                    if (educationOrganizationId == int.MaxValue)
                        continue;

                    int[] leaIds;
                    switch (associatedOrganization.Category)
                    {
                        case EducationOrganizationCategory.LocalEducationAgency:
                            leaIds = new[] { educationOrganizationId };
                            break;
                        default:
                            leaIds = new int[0];
                            break;
                    }

                    switch (claimType)
                    {

                            //People with ViewAllStudents can see any user associated with their ed-org
                        case EdFiClaimTypes.ViewAllStudents:
                            //subsonic's contains is broken, so while we don't need this if statement for it to work in linq, we do
                            // need it for it to work with subsonic.  Once we get off subsonic we just need the if statement.
                            if (leaIds.Any())
                            {
                                studentsTheUserCanSee = studentsTheUserCanSee.Or(
                                    student => student.SchoolId == educationOrganizationId
                                               || leaIds.Contains(student.LocalEducationAgencyId));
                            }
                            else
                            {
                                studentsTheUserCanSee = studentsTheUserCanSee.Or(
                                    student => student.SchoolId == educationOrganizationId);
                            }
                            break;
                            //People with ViewMyStudents can see their students, or students that are part of their cohort.
                        case EdFiClaimTypes.ViewMyStudents:
                            //Logically, the goal of this code is to do studentsTheUserCanSee.Or(student => myStudents.Contains(student.StudentUSI)), but we have
                            //   to hack around subsonic, so this is phrased oddly.
                            studentsTheUserCanSee =
                                studentsTheUserCanSee.Or(student => StaffStudentAssociationRepository.GetAll()
                                    .Any(ssa => ssa.StudentUSI == student.StudentUSI
                                                && ssa.StaffUSI == staffUsi
                                                && ssa.SchoolId == educationOrganizationId));

                            break;
                    }
                }
            }

            return query.Where(studentsTheUserCanSee);
        }
        /// <summary>
        /// Gets the EdFiGridWatchListModel; the structure will be determined
        /// by the logged in user.
        /// </summary>
        /// <param name="staffUSI">The staff USI.</param>
        /// <param name="schoolId">The school identifier.</param>
        /// <param name="localEducationAgencyId">The local education agency identifier.</param>
        /// <param name="sectionId">The section identifier.</param>
        /// <param name="watchListSelections">The watch list selections.</param>
        /// <returns>
        /// An <see cref="EdFiGridWatchListModel" /> loaded with data for the currently logged in user.
        /// </returns>
        public virtual EdFiGridWatchListModel GetEdFiGridWatchListModel(long staffUSI, int? schoolId, int? localEducationAgencyId = null, long? sectionId = null, List<NameValuesType> watchListSelections = null)
        {
            var watchListDataState = new WatchListDataState();

            var defaultStudentMetricsProviderOptions = new StudentMetricsProviderQueryOptions
            {
                StaffUSI = staffUSI,
                SchoolId = schoolId,
                LocalEducationAgencyId = localEducationAgencyId,
                GetAllMetrics = true
            };

            watchListDataState.Students = GetStudentList(defaultStudentMetricsProviderOptions);
            watchListDataState.Metrics = GetStudentMetrics(defaultStudentMetricsProviderOptions);

            var grades = watchListDataState.Students.Select(data => new { data.GradeLevel, data.GradeLevelSortOrder }).Distinct().OrderBy(order => order.GradeLevelSortOrder).ToList();
            watchListDataState.Grades = grades.Select(data => new EdFiGridWatchListSelectionItemModel { DisplayValue = data.GradeLevel, Name = data.GradeLevel }).ToList();

            watchListDataState.MetricIds = watchListDataState.Metrics.Select(data => data.MetricId).Distinct().ToList();

            var results = new List<TeacherSection>();

            if (schoolId.HasUsableValue())
            {
                results = (TeacherSectionRepository.GetAll()
                    .Where(data => data.StaffUSI == staffUSI && data.SchoolId == schoolId)
                    .OrderBy(data => data.SubjectArea).ThenBy(data => data.CourseTitle)
                    .ThenBy(data => data.ClassPeriod).ThenBy(data => data.LocalCourseCode)
                    .ThenBy(data => data.TeacherSectionId)).ToList();
            }

            if (sectionId.HasUsableValue())
            {
                watchListDataState.CurrentSectionId = sectionId.Value;
            }

            watchListDataState.Sections = results.ToDictionary(
                key => key.TeacherSectionId,
                value => String.Format(SectionDescriptionFormat, value.SubjectArea, value.LocalCourseCode, value.CourseTitle, value.ClassPeriod, value.TermType)
            );

            // determine if the section id has a value and if that value is
            // contained in the sections dictionary above; if not the section
            // id is really a watch list id
            var isWatchListSection = sectionId.HasUsableValue() && (!(sectionId.Value <= int.MaxValue ? (int?) sectionId.Value : null).HasValue || !watchListDataState.Sections.ContainsKey((int) sectionId.Value));

            MetricBasedWatchList watchList = null;
            List<NameValuesType> watchListSelectedOptions = null;

            if (isWatchListSection)
            {
                watchList = GetWatchListData(sectionId.Value);
                watchListSelectedOptions = GetWatchListSelectionData(sectionId.Value);
            }

            var isWatchListChanged = false;
            // if this parameter is set then we are coming back from a watch
            // list and need to reset to the last values selected
            if (watchListSelections != null)
            {
                isWatchListChanged = IsWatchListChanged(watchListSelections, watchListSelectedOptions);
                watchListSelectedOptions = watchListSelections;
            }

            var searchLinkRequest = new WatchListLinkRequest
            {
                LocalEducationAgencyId = localEducationAgencyId,
                SchoolId = schoolId,
                StaffUSI = staffUSI,
                MetricBasedWatchListId = (int?)sectionId,
                ResourceName = "MetricsBasedWatchListSearch"
            };

            // create the watch list model
            var watchListModel = new EdFiGridWatchListModel
            {
                WatchListName = (watchList != null && watchList.WatchListName != string.Empty ? watchList.WatchListName : "New Dynamic List"),
                WatchListDescription = (watchList != null ? watchList.WatchListDescription : string.Empty),
                WatchListUrl = GeneralLinks.MetricsBasedWatchList("MetricsBasedWatchList"),
                WatchListSearchUrl = WatchListLinkProvider.GenerateLink(searchLinkRequest),
                IsWatchListChanged = isWatchListChanged,
                IsWatchListShared = watchList != null && watchList.IsWatchListShared,
                Tabs = TabFactory.CreateAllTabs(watchListDataState)
            };

            // load any available selections into the model
            if (watchListSelectedOptions != null)
            {
                LoadWatchListSelections(watchListModel, watchListSelectedOptions);
            }

            return watchListModel;
        }
Esempio n. 30
0
        public IQueryable<EnhancedStudentInformation> ApplyFilter(IQueryable<EnhancedStudentInformation> query, StudentMetricsProviderQueryOptions providerQueryOptions)
        {
            if (providerQueryOptions.DemographicOptionGroups == null || !providerQueryOptions.DemographicOptionGroups.Any())
                return query;

            const string yes = "YES";

            foreach (var demographicOptionGroup in providerQueryOptions.DemographicOptionGroups)
            {
                if (demographicOptionGroup.SelectedOptions == null || !demographicOptionGroup.SelectedOptions.Any())
                {
                    continue;
                }

                var studentsWithinDemographics = ExpressionExtensions.False<EnhancedStudentInformation>();
                foreach (var selectedOption in demographicOptionGroup.SelectedOptions)
                {
                    var filterValue = selectedOption;
                    switch (filterValue.ToLowerInvariant().Trim())
                    {
                        case "female":
                        case "male":
                            studentsWithinDemographics =
                                studentsWithinDemographics.Or(information => information.Gender == filterValue);
                            break;
                        case "hispanic/latino":
                            studentsWithinDemographics = studentsWithinDemographics.Or(information => information.HispanicLatinoEthnicity == yes);
                            break;
                        case "late enrollment":
                            studentsWithinDemographics = studentsWithinDemographics.Or(information => information.LateEnrollment == yes);
                            break;
                        case "two or more":
                            studentsWithinDemographics = studentsWithinDemographics.Or(
                                information => information.Race.Contains(",") && information.HispanicLatinoEthnicity != yes);
                            break;
                        default:
                            var raceOrStudentIndicatorValue = filterValue;

                            //See if it's a indicator value
                            studentsWithinDemographics =
                                studentsWithinDemographics.Or(
                                    information => StudentIndicatorRepository.GetAll()
                                        .Any(data => data.StudentUSI == information.StudentUSI
                                                     && (data.EducationOrganizationId == information.SchoolId || data.EducationOrganizationId == information.LocalEducationAgencyId)
                                                     && data.Status
                                                     && data.Name == raceOrStudentIndicatorValue));

                            //Or it might be a race value
                            studentsWithinDemographics =
                                studentsWithinDemographics.Or(
                                    information =>
                                        information.Race == raceOrStudentIndicatorValue &&
                                        information.HispanicLatinoEthnicity != yes);
                            break;
                    }
                }

                query = query.Where(studentsWithinDemographics);
            }

            return query;
        }