Search in sources :

Example 26 with EducationType

use of fi.otavanopisto.pyramus.domainmodel.base.EducationType in project pyramus by otavanopisto.

the class CommonRESTService method listEducationTypes.

@Path("/educationTypes/{ID}/subtypes")
@GET
@RESTPermit(CommonPermissions.LIST_EDUCATIONSUBTYPES)
public Response listEducationTypes(@PathParam("ID") Long educationTypeId) {
    if (educationTypeId == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    EducationType educationType = commonController.findEducationTypeById(educationTypeId);
    if (educationType == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    List<EducationSubtype> educationSubtypes = commonController.listEducationSubtypesByEducationType(educationType);
    if (educationSubtypes.isEmpty()) {
        return Response.noContent().build();
    }
    return Response.ok(objectFactory.createModel(educationSubtypes)).build();
}
Also used : EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 27 with EducationType

use of fi.otavanopisto.pyramus.domainmodel.base.EducationType in project pyramus by otavanopisto.

the class CommonRESTService method updateSubject.

@Path("/subjects/{ID:[0-9]*}")
@PUT
@RESTPermit(CommonPermissions.UPDATE_SUBJECT)
public Response updateSubject(@PathParam("ID") Long id, fi.otavanopisto.pyramus.rest.model.Subject entity) {
    Subject subject = commonController.findSubjectById(id);
    if (subject == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (subject.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    String name = entity.getName();
    String code = entity.getCode();
    if (entity.getEducationTypeId() == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    if (StringUtils.isBlank(name) || StringUtils.isBlank(code)) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    EducationType educationType = commonController.findEducationTypeById(entity.getEducationTypeId());
    if (educationType == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    return Response.ok(objectFactory.createModel(commonController.updateSubject(subject, code, name, educationType))).build();
}
Also used : EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) PUT(javax.ws.rs.PUT)

Example 28 with EducationType

use of fi.otavanopisto.pyramus.domainmodel.base.EducationType in project pyramus by otavanopisto.

the class StudentRESTService method getStudentCourseStats.

@Path("/students/{STUDENTID:[0-9]*}/courseStats")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response getStudentCourseStats(@PathParam("STUDENTID") Long studentId, @QueryParam("educationTypeCode") String educationTypeCode, @QueryParam("educationSubtypeCode") String educationSubtypeCode) {
    StudentCourseStats response = new StudentCourseStats();
    Student student = studentController.findStudentById(studentId);
    if (student == null) {
        return Response.status(Status.NOT_FOUND).entity("Not found").build();
    }
    if (!restSecurity.hasPermission(new String[] { StudentPermissions.FIND_STUDENT, UserPermissions.USER_OWNER }, student, Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    EducationType educationType = commonController.findEducationTypeByCode(educationTypeCode);
    if (educationType == null) {
        return Response.status(Status.BAD_REQUEST).entity("Education type does not exist").build();
    }
    EducationSubtype educationSubtype = commonController.findEducationSubtypeByCode(educationType, educationSubtypeCode);
    if (educationSubtype == null) {
        return Response.status(Status.BAD_REQUEST).entity("Education subtype does not exist").build();
    }
    // TODO StudentTOR might be able to solve this more elegantly
    int numCompletedCourses = assessmentController.getAcceptedCourseCount(student, null, educationType, educationSubtype, student.getCurriculum());
    numCompletedCourses += assessmentController.getAcceptedTransferCreditCount(student, null, true, student.getCurriculum());
    double numCreditPoints = 0;
    try {
        StudentTOR studentTOR = StudentTORController.constructStudentTOR(student);
        numCreditPoints = studentTOR.getTotalCourseLengths(TORCourseLengthUnit.op);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Fetching number of credit points failed", e);
    }
    response.setNumberCompletedCourses(numCompletedCourses);
    response.setNumberCreditPoints(numCreditPoints);
    return Response.ok(response).build();
}
Also used : EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) StudentTOR(fi.otavanopisto.pyramus.tor.StudentTOR) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) StudentCourseStats(fi.otavanopisto.pyramus.rest.model.StudentCourseStats) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 29 with EducationType

use of fi.otavanopisto.pyramus.domainmodel.base.EducationType in project pyramus by otavanopisto.

the class CoursesService method addCourseEducationType.

public CourseEducationTypeEntity addCourseEducationType(@WebParam(name = "courseId") Long courseId, @WebParam(name = "educationTypeId") Long educationTypeId) {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    CourseEducationTypeDAO courseEducationTypeDAO = DAOFactory.getInstance().getCourseEducationTypeDAO();
    EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
    Course course = courseDAO.findById(courseId);
    EducationType educationType = educationTypeDAO.findById(educationTypeId);
    CourseEducationType courseEducationType = courseEducationTypeDAO.create(course, educationType);
    validateEntity(courseEducationType);
    return EntityFactoryVault.buildFromDomainObject(courseEducationType);
}
Also used : CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseEducationTypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO) CourseEducationTypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course)

Example 30 with EducationType

use of fi.otavanopisto.pyramus.domainmodel.base.EducationType in project pyramus by otavanopisto.

the class BaseService method listEducationTypes.

public EducationTypeEntity[] listEducationTypes() {
    EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
    List<EducationType> educationTypes = educationTypeDAO.listUnarchived();
    Collections.sort(educationTypes, new StringAttributeComparator("getName"));
    return (EducationTypeEntity[]) EntityFactoryVault.buildFromDomainObjects(educationTypes);
}
Also used : EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO)

Aggregations

EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)66 EducationTypeDAO (fi.otavanopisto.pyramus.dao.base.EducationTypeDAO)42 EducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype)24 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)23 SubjectDAO (fi.otavanopisto.pyramus.dao.base.SubjectDAO)20 EducationSubtypeDAO (fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO)17 HashMap (java.util.HashMap)17 StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)16 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)13 Date (java.util.Date)13 Path (javax.ws.rs.Path)13 List (java.util.List)12 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)11 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)10 CourseEducationType (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType)10 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)10 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)9 Map (java.util.Map)9 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)8 CourseDescriptionCategoryDAO (fi.otavanopisto.pyramus.dao.courses.CourseDescriptionCategoryDAO)8