use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.
the class CourseStudentDAO method listByStudent.
public List<CourseStudent> listByStudent(Student student) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<CourseStudent> criteria = criteriaBuilder.createQuery(CourseStudent.class);
Root<CourseStudent> root = criteria.from(CourseStudent.class);
Join<CourseStudent, Student> studentJoin = root.join(CourseStudent_.student);
Join<CourseStudent, Course> courseJoin = root.join(CourseStudent_.course);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CourseStudent_.student), student), criteriaBuilder.equal(root.get(CourseStudent_.archived), Boolean.FALSE), criteriaBuilder.equal(courseJoin.get(Course_.archived), Boolean.FALSE), criteriaBuilder.equal(studentJoin.get(Student_.archived), Boolean.FALSE)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.
the class CourseRESTService method findCourseStudentById.
@Path("/courses/{CID:[0-9]*}/students/{ID:[0-9]*}")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response findCourseStudentById(@PathParam("CID") Long courseId, @PathParam("ID") Long id) {
Course course = courseController.findCourseById(courseId);
if (course == null) {
return Response.status(Status.NOT_FOUND).build();
}
fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent courseStudent = courseController.findCourseStudentById(id);
if (courseStudent == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (!courseStudent.getCourse().getId().equals(courseId)) {
return Response.status(Status.NOT_FOUND).build();
}
if (courseStudent.getArchived() || courseStudent.getStudent().getArchived() || courseStudent.getCourse().getArchived()) {
return Response.status(Status.NOT_FOUND).build();
}
if (!restSecurity.hasPermission(new String[] { CoursePermissions.FIND_COURSESTUDENT, PersonPermissions.PERSON_OWNER }, courseStudent.getStudent().getPerson(), Style.OR)) {
return Response.status(Status.FORBIDDEN).build();
}
if (!restSecurity.hasPermission(new String[] { StudentPermissions.FIND_STUDENT, UserPermissions.USER_OWNER }, courseStudent.getStudent(), Style.OR)) {
return Response.status(Status.FORBIDDEN).build();
}
return Response.status(Status.OK).entity(objectFactory.createModel(courseStudent)).build();
}
use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.
the class CourseRESTService method isActiveStudent.
private boolean isActiveStudent(CourseStudent courseStudent) {
Student student = courseStudent.getStudent();
Date studyStartDate = student.getStudyStartDate();
Date studyEndDate = student.getStudyEndDate();
if (studyStartDate == null && studyEndDate == null) {
// It's a never ending study programme
return true;
}
boolean hasStarted = studyStartDate != null && studyStartDate.before(new Date());
boolean hasFinished = studyEndDate != null && studyEndDate.before(new Date());
return hasStarted && !hasFinished;
}
use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.
the class CourseRESTService method createCourseStudent.
@Path("/courses/{COURSEID:[0-9]*}/students")
@POST
@RESTPermit(handling = Handling.INLINE)
public // @RESTPermit (CoursePermissions.CREATE_COURSESTUDENT)
Response createCourseStudent(@PathParam("COURSEID") Long courseId, fi.otavanopisto.pyramus.rest.model.CourseStudent entity) {
if (entity == null) {
return Response.status(Status.BAD_REQUEST).entity("Request payload missing").build();
}
if (entity.getStudentId() == null) {
return Response.status(Status.BAD_REQUEST).entity("studentId is missing").build();
}
if (entity.getLodging() == null) {
return Response.status(Status.BAD_REQUEST).entity("lodging is missing").build();
}
if (entity.getEnrolmentTime() == null) {
return Response.status(Status.BAD_REQUEST).entity("enrolmentTime is missing").build();
}
if (!restSecurity.hasPermission(new String[] { CoursePermissions.CREATE_COURSESTUDENT, UserPermissions.USER_OWNER }, entity, Style.OR)) {
return Response.status(Status.FORBIDDEN).build();
}
Course course = courseController.findCourseById(courseId);
if (course == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (course.isCourseTemplate()) {
return Response.status(Status.BAD_REQUEST).entity("Cannot add student to a course template").build();
}
Student student = studentController.findStudentById(entity.getStudentId());
if (student == null) {
return Response.status(Status.BAD_REQUEST).entity("could not find the student #" + entity.getStudentId()).build();
}
if (courseController.findCourseStudentByCourseAndStudent(course, student) != null) {
return Response.status(Status.BAD_REQUEST).entity("student #" + entity.getStudentId() + " is already on course #" + courseId).build();
}
BillingDetails billingDetails = null;
if (entity.getBillingDetailsId() != null) {
billingDetails = commonController.findBillingDetailsById(entity.getBillingDetailsId());
if (billingDetails == null) {
return Response.status(Status.BAD_REQUEST).entity("could not find billingDetails #" + entity.getBillingDetailsId()).build();
}
}
fi.otavanopisto.pyramus.domainmodel.courses.CourseEnrolmentType enrolmentType;
if (entity.getEnrolmentTypeId() != null) {
enrolmentType = courseController.findCourseEnrolmentTypeById(entity.getEnrolmentTypeId());
if (enrolmentType == null) {
return Response.status(Status.BAD_REQUEST).entity("could not find enrolmentType #" + entity.getEnrolmentTypeId()).build();
}
} else {
enrolmentType = courseController.getDefaultCourseEnrolmentType();
}
fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality optionality = entity.getOptionality() != null ? fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality.valueOf(entity.getOptionality().name()) : null;
fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType participantionType;
if (entity.getParticipationTypeId() != null) {
participantionType = courseController.findCourseParticipationTypeById(entity.getParticipationTypeId());
if (participantionType == null) {
return Response.status(Status.BAD_REQUEST).entity("could not find participationType #" + entity.getParticipationTypeId()).build();
}
} else {
participantionType = courseController.getDefaultCourseParticipationType();
}
// TODO: Add support for room, organization, additionalInfo and lodging fee
String organization = null;
String additionalInfo = null;
Room room = null;
BigDecimal lodgingFee = null;
Currency lodgingFeeCurrency = null;
BigDecimal reservationFee = null;
Currency reservationFeeCurrency = null;
try {
return Response.status(Status.OK).entity(objectFactory.createModel(courseController.createCourseStudent(course, student, enrolmentType, participantionType, toDate(entity.getEnrolmentTime()), entity.getLodging(), optionality, billingDetails, lodgingFee, lodgingFeeCurrency, reservationFee, reservationFeeCurrency, organization, additionalInfo, room))).build();
} catch (DuplicateCourseStudentException dcse) {
logger.log(Level.SEVERE, "Attempt to add CourseStudent when it already exists (student=" + entity.getStudentId() + ", course=" + courseId + ".", dcse);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity("Student is already member of the course.").build();
}
}
use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.
the class CourseAssessmentDAO method listByStudentAndSubject.
/**
* Lists all student's course assessments excluding archived ones
*
* @return list of all students course assessments
*/
public List<CourseAssessment> listByStudentAndSubject(Student student, Subject subject) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<CourseAssessment> criteria = criteriaBuilder.createQuery(CourseAssessment.class);
Root<CourseAssessment> root = criteria.from(CourseAssessment.class);
Join<CourseAssessment, CourseStudent> courseStudentJoin = root.join(CourseAssessment_.courseStudent);
Join<CourseStudent, Course> courseJoin = courseStudentJoin.join(CourseStudent_.course);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(courseStudentJoin.get(CourseStudent_.student), student), criteriaBuilder.equal(root.get(CourseAssessment_.archived), Boolean.FALSE), criteriaBuilder.equal(courseStudentJoin.get(CourseStudent_.archived), Boolean.FALSE), criteriaBuilder.equal(courseJoin.get(Course_.archived), Boolean.FALSE), criteriaBuilder.equal(courseJoin.get(Course_.subject), subject)));
return entityManager.createQuery(criteria).getResultList();
}
Aggregations