Search in sources :

Example 1 with CourseComponent

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent in project pyramus by otavanopisto.

the class CoursesService method createCourse.

public CourseEntity createCourse(@WebParam(name = "moduleId") Long moduleId, @WebParam(name = "name") String name, @WebParam(name = "nameExtension") String nameExtension, @WebParam(name = "subjectId") Long subjectId, @WebParam(name = "courseNumber") Integer courseNumber, @WebParam(name = "beginDate") Date beginDate, @WebParam(name = "endDate") Date endDate, @WebParam(name = "courseLength") Double courseLength, @WebParam(name = "courseLengthTimeUnitId") Long courseLengthTimeUnitId, @WebParam(name = "description") String description, @WebParam(name = "creatingUserId") Long creatingUserId) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    CourseComponentDAO componentDAO = DAOFactory.getInstance().getCourseComponentDAO();
    CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
    CourseEducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getCourseEducationTypeDAO();
    CourseEducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getCourseEducationSubtypeDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
    Module module = moduleId == null ? null : moduleDAO.findById(moduleId);
    Subject subject = subjectId == null ? null : subjectDAO.findById(subjectId);
    EducationalTimeUnit courseLengthTimeUnit = courseLengthTimeUnitId == null ? null : educationalTimeUnitDAO.findById(courseLengthTimeUnitId);
    User creatingUser = userDAO.findById(creatingUserId);
    if (module != null) {
        name = name == null ? module.getName() : name;
        subject = subject == null ? module.getSubject() : subject;
        courseNumber = courseNumber == null ? module.getCourseNumber() : courseNumber;
        if (courseLength == null && module.getCourseLength() != null) {
            courseLength = module.getCourseLength().getUnits();
            courseLengthTimeUnit = module.getCourseLength().getUnit();
        }
        description = description == null ? module.getDescription() : description;
    }
    CourseState state = defaultsDAO.getDefaults().getInitialCourseState();
    CourseType type = null;
    // Course creation
    Course course = courseDAO.create(module, name, nameExtension, state, type, subject, courseNumber, beginDate, endDate, courseLength, courseLengthTimeUnit, null, null, null, null, null, null, description, null, null, null, null, creatingUser);
    validateEntity(course);
    if (module != null) {
        // Course Description copying from module to course
        descriptionDAO.copy(module, course);
        // Curriculums
        courseDAO.updateCurriculums(course, new HashSet<Curriculum>(module.getCurriculums()));
        // Components
        List<ModuleComponent> moduleComponents = module.getModuleComponents();
        if (moduleComponents != null) {
            for (ModuleComponent moduleComponent : moduleComponents) {
                EducationalLength educationalLength = moduleComponent.getLength();
                CourseComponent courseComponent = componentDAO.create(course, educationalLength == null ? null : educationalLength.getUnits(), educationalLength == null ? null : educationalLength.getUnit(), moduleComponent.getName(), moduleComponent.getDescription());
                validateEntity(courseComponent);
            }
        }
        // Education types
        List<CourseEducationType> typesInModule = module.getCourseEducationTypes();
        if (typesInModule != null) {
            for (CourseEducationType typeInModule : typesInModule) {
                CourseEducationType typeInCourse = educationTypeDAO.create(course, typeInModule.getEducationType());
                validateEntity(typeInCourse);
                // Education subtypes
                List<CourseEducationSubtype> subTypesInModule = typeInModule.getCourseEducationSubtypes();
                if (subTypesInModule != null) {
                    for (CourseEducationSubtype subtypeInModule : subTypesInModule) {
                        CourseEducationSubtype courseEducationSubtype = educationSubtypeDAO.create(typeInCourse, subtypeInModule.getEducationSubtype());
                        validateEntity(courseEducationSubtype);
                    }
                }
            }
        }
    }
    return EntityFactoryVault.buildFromDomainObject(course);
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) CourseType(fi.otavanopisto.pyramus.domainmodel.courses.CourseType) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) EducationalLength(fi.otavanopisto.pyramus.domainmodel.base.EducationalLength) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseEducationTypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) CourseEducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationSubtypeDAO) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) ModuleComponent(fi.otavanopisto.pyramus.domainmodel.modules.ModuleComponent) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module)

Example 2 with CourseComponent

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent in project pyramus by otavanopisto.

the class CourseComponentDAO method listByCourse.

public List<CourseComponent> listByCourse(Course course) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CourseComponent> criteria = criteriaBuilder.createQuery(CourseComponent.class);
    Root<CourseComponent> root = criteria.from(CourseComponent.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CourseComponent_.archived), Boolean.FALSE), criteriaBuilder.equal(root.get(CourseComponent_.course), course)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent)

Example 3 with CourseComponent

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent in project pyramus by otavanopisto.

the class CourseComponentResourceDAO method delete.

@Override
public void delete(CourseComponentResource courseComponentResource) {
    EntityManager entityManager = getEntityManager();
    CourseComponent courseComponent = courseComponentResource.getCourseComponent();
    courseComponent.removeResource(courseComponentResource);
    entityManager.persist(courseComponent);
    entityManager.remove(courseComponentResource);
}
Also used : EntityManager(javax.persistence.EntityManager) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent)

Example 4 with CourseComponent

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent in project pyramus by otavanopisto.

the class CourseRESTService method updateCourseComponent.

@Path("/courses/{COURSEID:[0-9]*}/components/{COMPONENTID:[0-9]*}")
@PUT
@RESTPermit(CoursePermissions.UPDATE_COURSECOMPONENT)
public Response updateCourseComponent(@PathParam("COURSEID") Long courseId, @PathParam("COMPONENTID") Long courseComponentId, fi.otavanopisto.pyramus.rest.model.CourseComponent courseComponentEntity) {
    if (courseComponentEntity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    CourseComponent courseComponent = courseController.findCourseComponentById(courseComponentId);
    if (courseComponent == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!courseComponent.getId().equals(courseComponentEntity.getId())) {
        return Response.status(Status.BAD_REQUEST).entity(String.format("Cannot update id (%d !=%d)", courseComponent.getId(), courseComponentEntity.getId())).build();
    }
    Course course = courseController.findCourseById(courseId);
    if (course == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (StringUtils.isBlank(courseComponent.getName())) {
        return Response.status(Status.BAD_REQUEST).entity("name is required").build();
    }
    EducationalTimeUnit componentLengthTimeUnit = null;
    if (courseComponentEntity.getLength() != null) {
        if (courseComponentEntity.getLengthUnitId() == null) {
            return Response.status(Status.BAD_REQUEST).entity("lengthUnitId is required when length is defined").build();
        }
        componentLengthTimeUnit = commonController.findEducationalTimeUnitById(courseComponentEntity.getLengthUnitId());
        if (componentLengthTimeUnit == null) {
            return Response.status(Status.BAD_REQUEST).entity("lengthUnitId is required when length is defined").build();
        }
    }
    return Response.status(Status.OK).entity(objectFactory.createModel(courseController.updateCourseComponent(courseComponent, courseComponentEntity.getLength(), componentLengthTimeUnit, courseComponentEntity.getName(), courseComponentEntity.getDescription()))).build();
}
Also used : Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) PUT(javax.ws.rs.PUT)

Example 5 with CourseComponent

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent in project pyramus by otavanopisto.

the class CourseRESTService method findCourseComponentById.

@Path("/courses/{CID:[0-9]*}/components/{ID:[0-9]*}")
@GET
@RESTPermit(CoursePermissions.FIND_COURSECOMPONENT)
public Response findCourseComponentById(@PathParam("CID") Long courseId, @PathParam("ID") Long componentId) {
    Course course = courseController.findCourseById(courseId);
    if (course == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    CourseComponent component = courseController.findCourseComponentById(componentId);
    if (component == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (component.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!component.getCourse().getId().equals(courseId)) {
        return Response.status(Status.NOT_FOUND).build();
    }
    return Response.status(Status.OK).entity(objectFactory.createModel(component)).build();
}
Also used : Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Aggregations

CourseComponent (fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent)16 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)10 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)8 CourseComponentDAO (fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO)7 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)6 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)5 CourseEducationType (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType)5 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)5 SubjectDAO (fi.otavanopisto.pyramus.dao.base.SubjectDAO)4 CourseDescriptionDAO (fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO)4 CourseStaffMemberDAO (fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO)4 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)4 CourseEducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype)4 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)4 EducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype)4 EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)4 Organization (fi.otavanopisto.pyramus.domainmodel.base.Organization)4 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)4 CourseParticipationType (fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType)4 CourseState (fi.otavanopisto.pyramus.domainmodel.courses.CourseState)4