Search in sources :

Example 16 with EducationType

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

the class CommonRESTService method createSubject.

@Path("/subjects")
@POST
@RESTPermit(CommonPermissions.CREATE_SUBJECT)
public Response createSubject(fi.otavanopisto.pyramus.rest.model.Subject entity) {
    if (entity == null) {
        return Response.status(Status.BAD_REQUEST).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().entity(objectFactory.createModel(commonController.createSubject(code, name, educationType))).build();
}
Also used : EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) POST(javax.ws.rs.POST)

Example 17 with EducationType

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

the class CommonRESTService method updateEducationType.

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

Example 18 with EducationType

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

the class CommonRESTService method updateEducationSubtype.

@Path("/educationTypes/{EDUCATIONTYPEID}/subtypes/{EDUCATIONSUBTYPEID:[0-9]*}")
@PUT
@RESTPermit(CommonPermissions.UPDATE_EDUCATIONSUBTYPE)
public Response updateEducationSubtype(@PathParam("EDUCATIONTYPEID") Long educationTypeId, @PathParam("EDUCATIONSUBTYPEID") Long educationSubtypeId, fi.otavanopisto.pyramus.rest.model.EducationSubtype entity) {
    if (educationTypeId == null || educationSubtypeId == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    String name = entity.getName();
    String code = entity.getCode();
    if (StringUtils.isBlank(name) || StringUtils.isBlank(code)) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    EducationSubtype educationSubtype = commonController.findEducationSubtypeById(educationSubtypeId);
    if (educationSubtype == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (educationSubtype.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!educationSubtype.getEducationType().getId().equals(educationTypeId)) {
        return Response.status(Status.NOT_FOUND).build();
    }
    EducationType educationType = commonController.findEducationTypeById(entity.getEducationTypeId());
    if (educationType == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    if (educationType.getArchived()) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    return Response.ok().entity(objectFactory.createModel(commonController.updateEducationSubtype(educationSubtype, educationType, name, code))).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) PUT(javax.ws.rs.PUT)

Example 19 with EducationType

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

the class CourseChangeModuleDialogViewController method process.

public void process(PageRequestContext pageRequestContext) {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
    Long courseId = pageRequestContext.getLong("course");
    if (courseId == null) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, "Missing courseId parameter");
    }
    Course course = courseDAO.findById(courseId);
    List<EducationType> educationTypes = educationTypeDAO.listUnarchived();
    Collections.sort(educationTypes, new StringAttributeComparator("getName"));
    // Subjects
    Map<Long, List<Subject>> subjectsByEducationType = new HashMap<>();
    List<Subject> subjectsByNoEducationType = subjectDAO.listByEducationType(null);
    Collections.sort(subjectsByNoEducationType, new StringAttributeComparator("getName"));
    for (EducationType educationType : educationTypes) {
        List<Subject> subjectsOfType = subjectDAO.listByEducationType(educationType);
        if (subjectsOfType != null && !subjectsOfType.isEmpty()) {
            Collections.sort(subjectsOfType, new StringAttributeComparator("getName"));
            subjectsByEducationType.put(educationType.getId(), subjectsOfType);
        }
    }
    List<Curriculum> curriculums = curriculumDAO.listUnarchived();
    Collections.sort(curriculums, new StringAttributeComparator("getName"));
    pageRequestContext.getRequest().setAttribute("educationTypes", educationTypes);
    pageRequestContext.getRequest().setAttribute("course", course);
    pageRequestContext.getRequest().setAttribute("curriculums", curriculums);
    pageRequestContext.getRequest().setAttribute("subjectsByNoEducationType", subjectsByNoEducationType);
    pageRequestContext.getRequest().setAttribute("subjectsByEducationType", subjectsByEducationType);
    pageRequestContext.setIncludeJSP("/templates/courses/changemodule.jsp");
}
Also used : CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) HashMap(java.util.HashMap) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) List(java.util.List) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course)

Example 20 with EducationType

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

the class SearchCoursesViewController method process.

public void process(PageRequestContext pageRequestContext) {
    CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
    EducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getEducationSubtypeDAO();
    List<EducationType> educationTypes = educationTypeDAO.listUnarchived();
    Collections.sort(educationTypes, new StringAttributeComparator("getName"));
    // Subjects
    Map<Long, List<Subject>> subjectsByEducationType = new HashMap<>();
    List<Subject> subjectsByNoEducationType = subjectDAO.listByEducationType(null);
    Collections.sort(subjectsByNoEducationType, new StringAttributeComparator("getName"));
    Map<Long, List<EducationSubtype>> educationSubtypesByEduType = new HashMap<>();
    for (EducationType educationType : educationTypes) {
        List<Subject> subjectsOfType = subjectDAO.listByEducationType(educationType);
        if (subjectsOfType != null && !subjectsOfType.isEmpty()) {
            Collections.sort(subjectsOfType, new StringAttributeComparator("getName"));
            subjectsByEducationType.put(educationType.getId(), subjectsOfType);
        }
        List<EducationSubtype> educationSubtypes = educationSubtypeDAO.listByEducationType(educationType);
        educationSubtypesByEduType.put(educationType.getId(), educationSubtypes);
    }
    pageRequestContext.getRequest().setAttribute("educationTypes", educationTypes);
    pageRequestContext.getRequest().setAttribute("educationSubtypes", educationSubtypesByEduType);
    pageRequestContext.getRequest().setAttribute("subjectsByNoEducationType", subjectsByNoEducationType);
    pageRequestContext.getRequest().setAttribute("subjectsByEducationType", subjectsByEducationType);
    pageRequestContext.getRequest().setAttribute("states", courseStateDAO.listUnarchived());
    pageRequestContext.setIncludeJSP("/templates/courses/searchcourses.jsp");
}
Also used : EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) HashMap(java.util.HashMap) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) EducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO) CourseStateDAO(fi.otavanopisto.pyramus.dao.courses.CourseStateDAO) List(java.util.List) 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