use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.
the class TransferCreditDAO method create.
public TransferCredit create(String courseName, Integer courseNumber, Double courseLength, EducationalTimeUnit courseLengthUnit, School school, Subject subject, CourseOptionality optionality, Student student, StaffMember assessingUser, Grade grade, Date date, String verbalAssessment, Curriculum curriculum, boolean offCurriculum, TransferCreditFunding funding) {
TransferCredit transferCredit = new TransferCredit();
EducationalLength length = new EducationalLength();
length.setUnits(courseLength);
length.setUnit(courseLengthUnit);
transferCredit.setAssessor(assessingUser);
transferCredit.setDate(date);
transferCredit.setGrade(grade);
transferCredit.setCourseLength(length);
transferCredit.setCourseName(courseName);
transferCredit.setCourseNumber(courseNumber);
transferCredit.setSchool(school);
transferCredit.setStudent(student);
transferCredit.setSubject(subject);
transferCredit.setOptionality(optionality);
transferCredit.setVerbalAssessment(verbalAssessment);
transferCredit.setCurriculum(curriculum);
transferCredit.setOffCurriculum(offCurriculum);
transferCredit.setFunding(funding);
transferCredit.setArchived(Boolean.FALSE);
EntityManager entityManager = getEntityManager();
entityManager.persist(length);
entityManager.persist(transferCredit);
if (student != null)
transferCreditCreatedEvent.fire(new TransferCreditEvent(student.getId(), transferCredit.getId()));
return transferCredit;
}
use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.
the class TransferCreditDAO method listByStudent.
/**
* Lists all student's transfer credits excluding archived ones
*
* @return list of all students transfer credits
*/
public List<TransferCredit> listByStudent(Student student) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<TransferCredit> criteria = criteriaBuilder.createQuery(TransferCredit.class);
Root<TransferCredit> root = criteria.from(TransferCredit.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(TransferCredit_.archived), Boolean.FALSE), criteriaBuilder.equal(root.get(TransferCredit_.student), student)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.
the class TransferCreditDAO method listByStudentAndSubject.
/**
* Lists all student's transfer credits excluding archived ones
*
* @return list of all students transfer credits
*/
public List<TransferCredit> listByStudentAndSubject(Student student, Subject subject) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<TransferCredit> criteria = criteriaBuilder.createQuery(TransferCredit.class);
Root<TransferCredit> root = criteria.from(TransferCredit.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(TransferCredit_.archived), Boolean.FALSE), criteriaBuilder.equal(root.get(TransferCredit_.student), student), criteriaBuilder.equal(root.get(TransferCredit_.subject), subject)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.
the class TransferCreditEntityFactory method buildFromDomainObject.
public TransferCreditEntity buildFromDomainObject(Object domainObject) {
if (domainObject == null)
return null;
TransferCredit transferCredit = (TransferCredit) domainObject;
GradeEntity grade = EntityFactoryVault.buildFromDomainObject(transferCredit.getGrade());
UserEntity assessingUser = EntityFactoryVault.buildFromDomainObject(transferCredit.getAssessor());
return new TransferCreditEntity(transferCredit.getId(), transferCredit.getStudent().getId(), transferCredit.getDate(), grade, transferCredit.getVerbalAssessment(), assessingUser, transferCredit.getArchived(), transferCredit.getCourseName(), transferCredit.getCourseNumber(), transferCredit.getCourseLength().getUnits(), transferCredit.getCourseLength().getUnit().getId(), transferCredit.getSchool().getId(), transferCredit.getSubject().getId(), transferCredit.getOptionality().toString());
}
use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit 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();
}
Aggregations