public async Task ProcessEventsSetsEventTypeToAttendanceForZoomOrTeamsEvents() { var eventAggregator = new MockEventAggregator(); var moodleAdapter = new MoodleAdapter(eventAggregator, new MockIdentityResolver(), CreateLogger()); CaliperActor caliperActor = new CaliperActor { Id = "1", ActorType = "http://purl.imsglobal.org/caliper/v1/lis/Person", Name = "John Doe", Extensions = new CaliperActorExtensions { Email = "*****@*****.**" } }; string zoomActivityType = "zoom"; string studentRole = "http://purl.imsglobal.org/vocab/lis/v2/membership#Learner"; CaliperEventBatchDto zoomEvents = EventBatch(caliperActor, "any", "http://purl.imsglobal.org/caliper/v1/lis/" + zoomActivityType, "COMP0101", MoodleAdapter.COURSE_GROUP_TYPE, studentRole); await moodleAdapter.ProcessEvents(zoomEvents); Assert.Single(eventAggregator.processedEvents); var processedEvent = eventAggregator.processedEvents[0]; Assert.Equal(EventType.Attendance, processedEvent.EventType); }
public async Task ProcessEvents(CaliperEventBatchDto caliperEventBatch) { var filteredCaliperEvents = caliperEventBatch.Data.Where(e => IsAboutStudent(e) && IsAboutCourse(e)); foreach (var caliperEvent in filteredCaliperEvents) { string studentEmail = caliperEvent.Actor.Extensions.Email; string studentId = await _identityResolver.GetUserIdByEmail(studentEmail); if (studentId != null) { //TODO cleaner way to get firstname/lastname var studentName = caliperEvent.Actor.Name.Split(' ', 2); string caliperActivityType = caliperEvent.Object.ObjectType; string activityTypeWithoutUrl = caliperActivityType.Substring(caliperActivityType.LastIndexOf('/') + 1); var studentEvent = new StudentEvent { CourseID = caliperEvent.Group.Name, //TODO don't have this hardcoded in case of live lecture links EventType = activityTypeWithoutUrl == "zoom" || activityTypeWithoutUrl == "teams" ? EventType.Attendance : EventType.Engagement, ActivityName = caliperEvent.Object.Name, ActivityType = activityTypeWithoutUrl, Student = new Student { ID = studentId, FirstName = studentName[0], LastName = studentName[1], Email = studentEmail }, Timestamp = caliperEvent.EventTime }; await _eventAggregator.ProcessEvent(studentEvent); } else { _logger.LogError($"Event for student with email '{studentEmail}' ignored as no student ID could be resolved."); } } }
public async Task ProcessEvents(CaliperEventBatchDto caliperEventBatch) { var filteredCaliperEvents = caliperEventBatch.Data.Where(e => IsAboutStudent(e) && IsAboutCourse(e)); foreach (var caliperEvent in filteredCaliperEvents) { //TODO cleaner way to get firstname/lastname var studentName = caliperEvent.Actor.Name.Split(' ', 2); string caliperActivityType = caliperEvent.Object.ObjectType; string activityTypeWithoutUrl = caliperActivityType.Substring(caliperActivityType.LastIndexOf('/') + 1); var studentEvent = new StudentEvent { CourseID = caliperEvent.Group.Name, //TODO don't have this hardcoded in case of live lecture links EventType = EventType.Engagement, ActivityName = caliperEvent.Object.Name, ActivityType = activityTypeWithoutUrl, Student = new Student { ID = caliperEvent.Actor.Id, FirstName = studentName[0], LastName = studentName[1], Email = caliperEvent.Actor.Extensions.Email }, Timestamp = caliperEvent.EventTime }; await _eventAggregator.ProcessEvent(studentEvent); } }
public async Task ProcessEventsAcceptsEventsAboutStudentsInteractingWithCourses() { var eventAggregator = new MockEventAggregator(); var moodleAdapter = new MoodleAdapter(eventAggregator); CaliperActor caliperActor = new CaliperActor { Id = "1", ActorType = "http://purl.imsglobal.org/caliper/v1/lis/Person", Name = "John Doe", Extensions = new CaliperActorExtensions { Email = "*****@*****.**" } }; string activityType = "survey"; string studentRole = "http://purl.imsglobal.org/vocab/lis/v2/membership#Learner"; CaliperEventBatchDto eventsWithStudentRole = EventBatch(caliperActor, "any", "http://purl.imsglobal.org/caliper/v1/lis/" + activityType, "COMP0101", MoodleAdapter.COURSE_GROUP_TYPE, studentRole); await moodleAdapter.ProcessEvents(eventsWithStudentRole); Assert.Single(eventAggregator.processedEvents); var processedEvent = eventAggregator.processedEvents[0]; CaliperEventDto submittedEvent = eventsWithStudentRole.Data[0]; Assert.Equal(submittedEvent.Actor.Name, processedEvent.Student.FirstName + " " + processedEvent.Student.LastName); Assert.Equal(submittedEvent.Actor.Extensions.Email, processedEvent.Student.Email); Assert.Equal(submittedEvent.Actor.Id, processedEvent.Student.ID); Assert.Equal(submittedEvent.Object.Name, processedEvent.ActivityName); Assert.Equal(activityType, processedEvent.ActivityType); Assert.Equal(submittedEvent.Group.Name, processedEvent.CourseID); Assert.Equal(submittedEvent.EventTime, processedEvent.Timestamp); }
public async Task ProcessEventsIgnoresEventsIfActorNotStudent() { var eventAggregator = new MockEventAggregator(); var moodleAdapter = new MoodleAdapter(eventAggregator, new MockIdentityResolver(), CreateLogger()); CaliperActor caliperActor = new CaliperActor { Id = "1", ActorType = "http://purl.imsglobal.org/caliper/v1/lis/Person", Name = "John Doe", Extensions = new CaliperActorExtensions { Email = "*****@*****.**" } }; string instructorRole = "http://purl.imsglobal.org/vocab/lis/v2/membership#Instructor"; CaliperEventBatchDto eventsWithInstructorRole = EventBatch(caliperActor, "any", "http://purl.imsglobal.org/caliper/v1/lis/url", "COMP0101", MoodleAdapter.COURSE_GROUP_TYPE, instructorRole); await moodleAdapter.ProcessEvents(eventsWithInstructorRole); Assert.Empty(eventAggregator.processedEvents); }
public async Task ProcessEventsIgnoresEventIfStudentIdCouldNotBeResolvedThroughEmail() { var eventAggregator = new MockEventAggregator(); var failingIdentityResolver = new FailingIdentityResolver(); var moodleAdapter = new MoodleAdapter(eventAggregator, failingIdentityResolver, CreateLogger()); CaliperActor caliperActor = new CaliperActor { Id = "1", ActorType = "http://purl.imsglobal.org/caliper/v1/lis/Person", Name = "John Doe", Extensions = new CaliperActorExtensions { Email = "*****@*****.**" } }; string activityType = "survey"; string studentRole = "http://purl.imsglobal.org/vocab/lis/v2/membership#Learner"; CaliperEventBatchDto eventsThatShouldBeIgnored = EventBatch(caliperActor, "any", "http://purl.imsglobal.org/caliper/v1/lis/" + activityType, "COMP0101", MoodleAdapter.COURSE_GROUP_TYPE, studentRole); await moodleAdapter.ProcessEvents(eventsThatShouldBeIgnored); Assert.Empty(eventAggregator.processedEvents); }
public async Task CaliperEvent([FromBody] CaliperEventBatchDto caliperEventBatch) { await _moodleAdapter.ProcessEvents(caliperEventBatch); }
public async Task <IActionResult> CaliperEvent([FromHeader(Name = CALIPER_API_KEY_HEADER)] string incomingApiKey, [FromBody] CaliperEventBatchDto caliperEventBatch) { if (incomingApiKey == null || incomingApiKey != _caliperApiKey) { return(Unauthorized()); } await _moodleAdapter.ProcessEvents(caliperEventBatch); return(Ok()); }