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