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