use of fi.otavanopisto.pyramus.rest.model.hops.StudyActivityItemRestModel in project pyramus by otavanopisto.
the class MuikkuRESTService method getTransferCreditActivityItem.
private StudyActivityItemRestModel getTransferCreditActivityItem(TransferCredit transferCredit) {
StudyActivityItemRestModel item = new StudyActivityItemRestModel();
item.setCourseName(transferCredit.getCourseName());
if (transferCredit.getCourseNumber() != null && transferCredit.getCourseNumber() > 0) {
item.setCourseNumber(transferCredit.getCourseNumber());
}
item.setDate(transferCredit.getDate());
if (transferCredit.getGrade() != null) {
item.setGrade(transferCredit.getGrade().getName());
}
item.setStatus(StudyActivityItemStatus.TRANSFERRED);
item.setSubject(transferCredit.getSubject().getCode());
return item;
}
use of fi.otavanopisto.pyramus.rest.model.hops.StudyActivityItemRestModel in project pyramus by otavanopisto.
the class MuikkuRESTService method getStudentStudyActivity.
@Path("/students/{ID:[0-9]*}/studyActivity")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response getStudentStudyActivity(@PathParam("ID") Long id) {
// Access check
Student student = studentController.findStudentById(id);
if (student == null || student.getArchived()) {
return Response.status(Status.NOT_FOUND).build();
}
if (!restSecurity.hasPermission(new String[] { MuikkuPermissions.GET_STUDENT_COURSE_ACTIVITY, UserPermissions.USER_OWNER }, student, Style.OR)) {
return Response.status(Status.FORBIDDEN).build();
}
if (!sessionController.hasEnvironmentPermission(OrganizationPermissions.ACCESS_ALL_ORGANIZATIONS)) {
if (!UserUtils.isMemberOf(sessionController.getUser(), student.getOrganization())) {
return Response.status(Status.FORBIDDEN).build();
}
}
Map<String, StudyActivityItemRestModel> items = new HashMap<>();
// Transfer credits
List<TransferCredit> transferCredits = transferCreditDAO.listByStudent(student);
transferCredits.sort(Comparator.comparing(TransferCredit::getDate).reversed());
for (TransferCredit transferCredit : transferCredits) {
String key = getActivityItemKey(transferCredit.getSubject(), transferCredit.getCourseNumber());
StudyActivityItemRestModel item = getTransferCreditActivityItem(transferCredit);
if (!items.containsKey(key) || items.get(key).getDate().getTime() < item.getDate().getTime()) {
items.put(key, item);
}
}
// Course assessments
List<CourseAssessment> courseAssessments = courseAssessmentDAO.listByStudent(student);
courseAssessments.sort(Comparator.comparing(CourseAssessment::getDate).reversed());
for (CourseAssessment courseAssessment : courseAssessments) {
Course course = courseAssessment.getCourseStudent().getCourse();
String key = getActivityItemKey(course.getSubject(), course.getCourseNumber());
StudyActivityItemRestModel item = getCourseAssessmentActivityItem(courseAssessment);
if (!items.containsKey(key) || items.get(key).getDate().getTime() < item.getDate().getTime()) {
items.put(key, item);
}
}
// Linked credits
List<CreditLink> creditLinks = creditLinkDAO.listByStudent(student);
for (CreditLink creditLink : creditLinks) {
Credit credit = creditLink.getCredit();
if (credit.getCreditType() == CreditType.CourseAssessment) {
CourseAssessment courseAssessment = (CourseAssessment) credit;
Course course = courseAssessment.getCourseStudent().getCourse();
String key = getActivityItemKey(course.getSubject(), course.getCourseNumber());
StudyActivityItemRestModel item = getCourseAssessmentActivityItem(courseAssessment);
if (!items.containsKey(key) || items.get(key).getDate().getTime() < item.getDate().getTime()) {
items.put(key, item);
}
} else if (credit.getCreditType() == CreditType.TransferCredit) {
TransferCredit transferCredit = (TransferCredit) credit;
String key = getActivityItemKey(transferCredit.getSubject(), transferCredit.getCourseNumber());
StudyActivityItemRestModel item = getTransferCreditActivityItem(transferCredit);
if (!items.containsKey(key) || items.get(key).getDate().getTime() < item.getDate().getTime()) {
items.put(key, item);
}
}
}
// Courses
List<CourseStudent> courseStudents = courseStudentDAO.listByStudent(student);
for (CourseStudent courseStudent : courseStudents) {
Course course = courseStudent.getCourse();
String key = getActivityItemKey(course.getSubject(), course.getCourseNumber());
if (!items.containsKey(key)) {
StudyActivityItemRestModel item = new StudyActivityItemRestModel();
item.setCourseId(course.getId());
item.setCourseName(course.getName());
if (course.getCourseNumber() != null && course.getCourseNumber() > 0) {
item.setCourseNumber(course.getCourseNumber());
}
item.setDate(courseStudent.getEnrolmentTime());
item.setStatus(StudyActivityItemStatus.ONGOING);
item.setSubject(course.getSubject().getCode());
items.put(key, item);
}
}
return Response.ok(items.values()).build();
}
use of fi.otavanopisto.pyramus.rest.model.hops.StudyActivityItemRestModel in project pyramus by otavanopisto.
the class MuikkuRESTService method getCourseAssessmentActivityItem.
private StudyActivityItemRestModel getCourseAssessmentActivityItem(CourseAssessment courseAssessment) {
Course course = courseAssessment.getCourseStudent().getCourse();
StudyActivityItemRestModel item = new StudyActivityItemRestModel();
item.setCourseId(course.getId());
item.setCourseName(course.getName());
if (course.getCourseNumber() != null && course.getCourseNumber() > 0) {
item.setCourseNumber(course.getCourseNumber());
}
item.setDate(courseAssessment.getDate());
if (courseAssessment.getGrade() != null) {
item.setGrade(courseAssessment.getGrade().getName());
}
item.setStatus(StudyActivityItemStatus.GRADED);
item.setSubject(course.getSubject().getCode());
return item;
}
Aggregations