Search in sources :

Example 1 with CourseStudent

use of fi.otavanopisto.pyramus.rest.model.CourseStudent in project muikku by otavanopisto.

the class PyramusWorkspaceSchoolDataBridge method updateWorkspaceStudentActivity.

@Override
public void updateWorkspaceStudentActivity(WorkspaceUser workspaceUser, boolean active) {
    Long courseId = identifierMapper.getPyramusCourseId(workspaceUser.getWorkspaceIdentifier().getIdentifier());
    Long courseStudentId = identifierMapper.getPyramusCourseStudentId(workspaceUser.getIdentifier().getIdentifier());
    CourseStudent courseStudent = pyramusClient.get(String.format("/courses/courses/%d/students/%d", courseId, courseStudentId), CourseStudent.class);
    if (courseStudent != null) {
        Long currentParticipationType = courseStudent.getParticipationTypeId();
        if (pyramusStudentActivityMapper.isActive(currentParticipationType) != active) {
            Long newParticipationType = active ? pyramusStudentActivityMapper.toActive(currentParticipationType) : pyramusStudentActivityMapper.toInactive(currentParticipationType);
            if (newParticipationType == null) {
                newParticipationType = currentParticipationType;
            }
            CourseParticipationType participationType = pyramusClient.get(String.format("/courses/participationTypes/%d", newParticipationType), CourseParticipationType.class);
            if (participationType != null) {
                courseStudent.setParticipationTypeId(participationType.getId());
                pyramusClient.put(String.format("/courses/courses/%d/students/%d", courseId, courseStudentId), courseStudent);
            } else {
                logger.warning(String.format("Could not find participation type %d", newParticipationType));
            }
        }
    }
}
Also used : CourseStudent(fi.otavanopisto.pyramus.rest.model.CourseStudent) CourseParticipationType(fi.otavanopisto.pyramus.rest.model.CourseParticipationType)

Example 2 with CourseStudent

use of fi.otavanopisto.pyramus.rest.model.CourseStudent in project muikku by otavanopisto.

the class PyramusUpdater method updateInactiveWorkspaceStudents.

/**
 * Updates inactive course students from Pyramus
 *
 * @param courseId id of course in Pyramus
 * @return count of updated course students
 */
public int updateInactiveWorkspaceStudents(WorkspaceEntity workspaceEntity) {
    int count = 0;
    Long courseId = identifierMapper.getPyramusCourseId(workspaceEntity.getIdentifier());
    CourseStudent[] nonActiveCourseStudents = pyramusClient.get().get("/courses/courses/" + courseId + "/students?filterArchived=false&activeStudents=false", CourseStudent[].class);
    if (nonActiveCourseStudents != null) {
        for (CourseStudent nonActiveCourseStudent : nonActiveCourseStudents) {
            SchoolDataIdentifier workspaceUserIdentifier = toIdentifier(identifierMapper.getWorkspaceStudentIdentifier(nonActiveCourseStudent.getId()));
            WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
            if (workspaceUserEntity != null) {
                if (nonActiveCourseStudent.getArchived()) {
                    fireCourseStudentRemoved(nonActiveCourseStudent.getId(), nonActiveCourseStudent.getStudentId(), nonActiveCourseStudent.getCourseId());
                    count++;
                } else {
                    fireCourseStudentUpdated(nonActiveCourseStudent, false);
                    count++;
                }
            } else {
                fireCourseStudentDiscovered(nonActiveCourseStudent, false);
                count++;
            }
        }
    }
    return count;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) RoleSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) CourseStudent(fi.otavanopisto.pyramus.rest.model.CourseStudent)

Example 3 with CourseStudent

use of fi.otavanopisto.pyramus.rest.model.CourseStudent in project muikku by otavanopisto.

the class PyramusUpdater method updateCourseStudent.

/**
 * Updates course student from Pyramus
 *
 * @param courseStudentId id of course student in Pyramus
 * @param courseId id of course in Pyramus
 * @param studentId id of student in Pyramus
 * @return returns whether new course student was created or not
 */
public boolean updateCourseStudent(Long courseStudentId, Long courseId, Long studentId) {
    String workspaceIdentifier = identifierMapper.getWorkspaceIdentifier(courseId);
    String identifier = identifierMapper.getWorkspaceStudentIdentifier(courseStudentId);
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, workspaceIdentifier);
    if (workspaceEntity == null) {
        updateCourse(courseId);
        workspaceEntity = workspaceController.findWorkspaceEntityByDataSourceAndIdentifier(SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE, workspaceIdentifier);
    }
    if (workspaceEntity != null) {
        SchoolDataIdentifier workspaceUserIdentifier = new SchoolDataIdentifier(identifier, SchoolDataPyramusPluginDescriptor.SCHOOL_DATA_SOURCE);
        WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
        CourseStudent courseStudent = pyramusClient.get().get("/courses/courses/" + courseId + "/students/" + courseStudentId, CourseStudent.class);
        if (courseStudent != null && !courseStudent.getArchived()) {
            boolean studentActive = isStudentActive(courseStudent.getStudentId());
            if (workspaceUserEntity == null) {
                fireCourseStudentDiscovered(courseStudent, studentActive);
                return true;
            } else {
                fireCourseStudentUpdated(courseStudent, studentActive);
            }
        } else {
            if (workspaceUserEntity != null) {
                fireCourseStudentRemoved(courseStudentId, studentId, courseId);
            }
        }
    }
    return false;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) RoleSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) CourseStudent(fi.otavanopisto.pyramus.rest.model.CourseStudent)

Example 4 with CourseStudent

use of fi.otavanopisto.pyramus.rest.model.CourseStudent in project muikku by otavanopisto.

the class PyramusUpdater method updateActiveWorkspaceStudents.

/**
 * Updates active course students from Pyramus
 *
 * @param courseId id of course in Pyramus
 * @return count of updated course students
 */
public int updateActiveWorkspaceStudents(WorkspaceEntity workspaceEntity) {
    int count = 0;
    Long courseId = identifierMapper.getPyramusCourseId(workspaceEntity.getIdentifier());
    CourseStudent[] courseStudents = pyramusClient.get().get("/courses/courses/" + courseId + "/students?filterArchived=false&activeStudents=true", CourseStudent[].class);
    if (courseStudents != null) {
        for (CourseStudent courseStudent : courseStudents) {
            SchoolDataIdentifier workspaceUserIdentifier = toIdentifier(identifierMapper.getWorkspaceStudentIdentifier(courseStudent.getId()));
            WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findWorkspaceUserEntityByWorkspaceUserIdentifierIncludeArchived(workspaceUserIdentifier);
            if (courseStudent.getArchived()) {
                if (workspaceUserEntity != null) {
                    fireCourseStudentRemoved(courseStudent.getId(), courseStudent.getStudentId(), courseStudent.getCourseId());
                    count++;
                }
            } else {
                if (workspaceUserEntity == null) {
                    fireCourseStudentDiscovered(courseStudent, true);
                    count++;
                } else {
                    fireCourseStudentUpdated(courseStudent, true);
                }
            }
        }
    }
    return count;
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) RoleSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) CourseStudent(fi.otavanopisto.pyramus.rest.model.CourseStudent)

Example 5 with CourseStudent

use of fi.otavanopisto.pyramus.rest.model.CourseStudent in project muikku by otavanopisto.

the class PyramusMocksRest method mockWorkspaceUsers.

public static void mockWorkspaceUsers(List<String> payloads) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper().registerModule(new JSR310Module()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    Long courseId = 1l;
    Long teacherRoleId = 7l;
    CourseStaffMember courseStaffMember = new CourseStaffMember(1l, courseId, 4l, teacherRoleId);
    CourseStaffMember[] courseStaffMembers = { courseStaffMember };
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/staffMembers", courseId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(courseStaffMembers)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/staffMembers/%d", courseId, courseStaffMember.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(courseStaffMember)).withStatus(200)));
    addPayload(payloads, objectMapper.writeValueAsString(new WebhookCourseStaffMemberCreatePayload(courseStaffMember.getId(), courseId, courseStaffMember.getStaffMemberId())));
    OffsetDateTime enrolmentTime = OffsetDateTime.of(1999, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
    CourseStudent courseStudent = new CourseStudent(2l, courseId, 1l, enrolmentTime, false, null, null, false, null, null);
    CourseStudent[] students = { courseStudent };
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/students", courseId))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(students)).withStatus(200)));
    stubFor(get(urlEqualTo(String.format("/1/courses/courses/%d/students/%d", courseId, courseStudent.getId()))).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(objectMapper.writeValueAsString(courseStudent)).withStatus(200)));
    addPayload(payloads, objectMapper.writeValueAsString(new WebhookCourseStudentCreatePayload(courseStudent.getId(), courseId, courseStudent.getStudentId())));
}
Also used : WebhookCourseStudentCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookCourseStudentCreatePayload) OffsetDateTime(java.time.OffsetDateTime) CourseStaffMember(fi.otavanopisto.pyramus.rest.model.CourseStaffMember) CourseStudent(fi.otavanopisto.pyramus.rest.model.CourseStudent) JSR310Module(com.fasterxml.jackson.datatype.jsr310.JSR310Module) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebhookCourseStaffMemberCreatePayload(fi.otavanopisto.pyramus.webhooks.WebhookCourseStaffMemberCreatePayload)

Aggregations

CourseStudent (fi.otavanopisto.pyramus.rest.model.CourseStudent)8 RoleSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier)3 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)3 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)3 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JSR310Module (com.fasterxml.jackson.datatype.jsr310.JSR310Module)2 CourseStaffMember (fi.otavanopisto.pyramus.rest.model.CourseStaffMember)2 WebhookCourseStaffMemberCreatePayload (fi.otavanopisto.pyramus.webhooks.WebhookCourseStaffMemberCreatePayload)2 WebhookCourseStudentCreatePayload (fi.otavanopisto.pyramus.webhooks.WebhookCourseStudentCreatePayload)2 OffsetDateTime (java.time.OffsetDateTime)2 MockCourseStudent (fi.otavanopisto.muikku.mock.model.MockCourseStudent)1 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)1 CourseAssessment (fi.otavanopisto.pyramus.rest.model.CourseAssessment)1 CourseParticipationType (fi.otavanopisto.pyramus.rest.model.CourseParticipationType)1 CourseStaffMemberRole (fi.otavanopisto.pyramus.rest.model.CourseStaffMemberRole)1 Email (fi.otavanopisto.pyramus.rest.model.Email)1 Person (fi.otavanopisto.pyramus.rest.model.Person)1 StaffMember (fi.otavanopisto.pyramus.rest.model.StaffMember)1 Student (fi.otavanopisto.pyramus.rest.model.Student)1