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));
}
}
}
}
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;
}
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;
}
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;
}
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())));
}
Aggregations