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);
}
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();
}
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);
}
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();
}
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();
}
Aggregations