use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme in project pyramus by otavanopisto.
the class SearchStudentsViewController method process.
/**
* Processes the page request.
*
* @param pageRequestContext Request context
*/
public void process(PageRequestContext pageRequestContext) {
StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
NationalityDAO nationalityDAO = DAOFactory.getInstance().getNationalityDAO();
LanguageDAO languageDAO = DAOFactory.getInstance().getLanguageDAO();
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
User loggedUser = staffMemberDAO.findById(pageRequestContext.getLoggedUserId());
List<StudyProgramme> studyProgrammes = UserUtils.canAccessAllOrganizations(loggedUser) ? studyProgrammeDAO.listUnarchived() : studyProgrammeDAO.listByOrganization(loggedUser.getOrganization(), Archived.UNARCHIVED);
Collections.sort(studyProgrammes, new StringAttributeComparator("getName"));
List<Nationality> nationalities = nationalityDAO.listUnarchived();
Collections.sort(nationalities, new StringAttributeComparator("getName"));
List<Municipality> municipalities = municipalityDAO.listUnarchived();
Collections.sort(municipalities, new StringAttributeComparator("getName"));
List<Language> languages = languageDAO.listUnarchived();
Collections.sort(languages, new StringAttributeComparator("getName"));
pageRequestContext.getRequest().setAttribute("nationalities", nationalities);
pageRequestContext.getRequest().setAttribute("municipalities", municipalities);
pageRequestContext.getRequest().setAttribute("languages", languages);
pageRequestContext.getRequest().setAttribute("studyProgrammes", studyProgrammes);
pageRequestContext.setIncludeJSP("/templates/students/searchstudents.jsp");
}
use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme in project pyramus by otavanopisto.
the class CreateStudentViewController method process.
public void process(PageRequestContext pageRequestContext) {
StudentActivityTypeDAO studentActivityTypeDAO = DAOFactory.getInstance().getStudentActivityTypeDAO();
StudentEducationalLevelDAO studentEducationalLevelDAO = DAOFactory.getInstance().getStudentEducationalLevelDAO();
StudentExaminationTypeDAO studentExaminationTypeDAO = DAOFactory.getInstance().getStudentExaminationTypeDAO();
StudentStudyEndReasonDAO studyEndReasonDAO = DAOFactory.getInstance().getStudentStudyEndReasonDAO();
UserVariableKeyDAO variableKeyDAO = DAOFactory.getInstance().getUserVariableKeyDAO();
StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
NationalityDAO nationalityDAO = DAOFactory.getInstance().getNationalityDAO();
SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
LanguageDAO languageDAO = DAOFactory.getInstance().getLanguageDAO();
ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
ContactURLTypeDAO contactURLTypeDAO = DAOFactory.getInstance().getContactURLTypeDAO();
PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
User loggedUser = staffMemberDAO.findById(pageRequestContext.getLoggedUserId());
Long personId = pageRequestContext.getLong("personId");
if (personId != null) {
Person person = personDAO.findById(personId);
StaffMember staffMember = staffMemberDAO.findByPerson(person);
pageRequestContext.getRequest().setAttribute("person", person);
pageRequestContext.getRequest().setAttribute("staffMember", staffMember);
String emails = new JSONArrayExtractor("defaultAddress", "contactType", "address").extractString(staffMember.getContactInfo().getEmails());
String addresses = new JSONArrayExtractor("defaultAddress", "name", "contactType", "streetAddress", "postalCode", "city", "country").extractString(staffMember.getContactInfo().getAddresses());
String phones = new JSONArrayExtractor("defaultNumber", "contactType", "number").extractString(staffMember.getContactInfo().getPhoneNumbers());
setJsDataVariable(pageRequestContext, "createstudent_emails", emails);
setJsDataVariable(pageRequestContext, "createstudent_addresses", addresses);
setJsDataVariable(pageRequestContext, "createstudent_phones", phones);
}
List<StudyProgramme> studyProgrammes = UserUtils.canAccessAllOrganizations(loggedUser) ? studyProgrammeDAO.listUnarchived() : studyProgrammeDAO.listByOrganization(loggedUser.getOrganization(), Archived.UNARCHIVED);
Collections.sort(studyProgrammes, new StringAttributeComparator("getName"));
List<Nationality> nationalities = nationalityDAO.listUnarchived();
Collections.sort(nationalities, new StringAttributeComparator("getName"));
List<Municipality> municipalities = municipalityDAO.listUnarchived();
Collections.sort(municipalities, new StringAttributeComparator("getName"));
List<Language> languages = languageDAO.listUnarchived();
Collections.sort(languages, new StringAttributeComparator("getName"));
List<School> schools = schoolDAO.listUnarchived();
Collections.sort(schools, new StringAttributeComparator("getName"));
List<ContactURLType> contactURLTypes = contactURLTypeDAO.listUnarchived();
Collections.sort(contactURLTypes, new StringAttributeComparator("getName"));
List<ContactType> contactTypes = contactTypeDAO.listUnarchived();
Collections.sort(contactTypes, new StringAttributeComparator("getName"));
List<UserVariableKey> userVariableKeys = variableKeyDAO.listByUserEditable(Boolean.TRUE);
Collections.sort(userVariableKeys, new StringAttributeComparator("getVariableName"));
List<Curriculum> curriculums = curriculumDAO.listUnarchived();
Collections.sort(curriculums, new StringAttributeComparator("getName"));
String jsonContactTypes = new JSONArrayExtractor("name", "id").extractString(contactTypes);
String jsonVariableKeys = new JSONArrayExtractor("variableKey", "variableName", "variableType").extractString(userVariableKeys);
setJsDataVariable(pageRequestContext, "contactTypes", jsonContactTypes);
setJsDataVariable(pageRequestContext, "variableKeys", jsonVariableKeys);
pageRequestContext.getRequest().setAttribute("schools", schools);
pageRequestContext.getRequest().setAttribute("activityTypes", studentActivityTypeDAO.listUnarchived());
pageRequestContext.getRequest().setAttribute("contactURLTypes", contactURLTypes);
pageRequestContext.getRequest().setAttribute("examinationTypes", studentExaminationTypeDAO.listUnarchived());
pageRequestContext.getRequest().setAttribute("educationalLevels", studentEducationalLevelDAO.listUnarchived());
pageRequestContext.getRequest().setAttribute("nationalities", nationalities);
pageRequestContext.getRequest().setAttribute("municipalities", municipalities);
pageRequestContext.getRequest().setAttribute("languages", languages);
pageRequestContext.getRequest().setAttribute("studyProgrammes", studyProgrammes);
pageRequestContext.getRequest().setAttribute("curriculums", curriculums);
pageRequestContext.getRequest().setAttribute("studyEndReasons", studyEndReasonDAO.listByParentReason(null));
pageRequestContext.getRequest().setAttribute("variableKeys", userVariableKeys);
pageRequestContext.setIncludeJSP("/templates/students/createstudent.jsp");
}
use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme in project pyramus by otavanopisto.
the class StudentRESTService method updateStudent.
@Path("/students/{ID:[0-9]*}")
@PUT
@RESTPermit(handling = Handling.INLINE)
public Response updateStudent(@PathParam("ID") Long id, fi.otavanopisto.pyramus.rest.model.Student entity) {
if (entity == null) {
return Response.status(Status.BAD_REQUEST).build();
}
Student student = studentController.findStudentById(id);
Status studentStatus = checkStudent(student);
if (studentStatus != Status.OK)
return Response.status(studentStatus).build();
if (!restSecurity.hasPermission(new String[] { StudentPermissions.UPDATE_STUDENT, StudentPermissions.STUDENT_OWNER }, entity, Style.OR)) {
return Response.status(Status.FORBIDDEN).build();
}
Long personId = entity.getPersonId();
Long studyProgrammeId = entity.getStudyProgrammeId();
String firstName = StringUtils.trim(entity.getFirstName());
String lastName = StringUtils.trim(entity.getLastName());
String nickname = StringUtils.trim(entity.getNickname());
if (personId == null || studyProgrammeId == null) {
return Response.status(Status.BAD_REQUEST).build();
}
if (StringUtils.isBlank(firstName) || StringUtils.isBlank(lastName)) {
return Response.status(Status.BAD_REQUEST).build();
}
Person person = personController.findPersonById(personId);
if (person == null) {
return Response.status(Status.BAD_REQUEST).build();
}
StudyProgramme studyProgramme = studyProgrammeController.findStudyProgrammeById(studyProgrammeId);
if (studyProgramme == null) {
return Response.status(Status.BAD_REQUEST).build();
}
if (!sessionController.hasEnvironmentPermission(OrganizationPermissions.ACCESS_ALL_ORGANIZATIONS)) {
// Needs to be member of both organizations
if (!(UserUtils.isMemberOf(sessionController.getUser(), studyProgramme.getOrganization()) && UserUtils.isMemberOf(sessionController.getUser(), student.getOrganization()))) {
return Response.status(Status.FORBIDDEN).build();
}
}
if (!userController.checkUserVariableKeysExist(entity.getVariables().keySet())) {
return Response.status(Status.BAD_REQUEST).build();
}
StudentActivityType activityType = entity.getActivityTypeId() != null ? studentActivityTypeController.findStudentActivityTypeById(entity.getActivityTypeId()) : null;
StudentExaminationType examinationType = entity.getExaminationTypeId() != null ? studentExaminationTypeController.findStudentExaminationTypeById(entity.getExaminationTypeId()) : null;
StudentEducationalLevel educationalLevel = entity.getEducationalLevelId() != null ? studentEducationalLevelController.findStudentEducationalLevelById(entity.getEducationalLevelId()) : null;
Nationality nationality = entity.getNationalityId() != null ? nationalityController.findNationalityById(entity.getNationalityId()) : null;
Municipality municipality = entity.getMunicipalityId() != null ? municipalityController.findMunicipalityById(entity.getMunicipalityId()) : null;
Language language = entity.getLanguageId() != null ? languageController.findLanguageById(entity.getLanguageId()) : null;
School school = entity.getSchoolId() != null ? schoolController.findSchoolById(entity.getSchoolId()) : null;
StudentStudyEndReason studyEndReason = entity.getStudyEndReasonId() != null ? studentStudyEndReasonController.findStudentStudyEndReasonById(entity.getStudyEndReasonId()) : null;
Curriculum curriculum = entity.getCurriculumId() != null ? curriculumController.findCurriculumById(entity.getCurriculumId()) : null;
// TODO lodging cannot be updated via boolean
studentController.updateStudent(student, firstName, lastName, nickname, entity.getAdditionalInfo(), toDate(entity.getStudyTimeEnd()), activityType, examinationType, educationalLevel, entity.getEducation(), nationality, municipality, language, school, curriculum, entity.getPreviousStudies(), toDate(entity.getStudyStartDate()), toDate(entity.getStudyEndDate()), studyEndReason, entity.getStudyEndText());
studentController.updateStudyProgramme(student, studyProgramme);
studentController.updateStudentPerson(student, person);
userController.updateUserVariables(student, entity.getVariables());
studentController.updateStudentTags(student, entity.getTags());
studentController.updateStudentAdditionalContactInfo(student, entity.getAdditionalContactInfo());
return Response.ok(objectFactory.createModel(student)).build();
}
use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme in project pyramus by otavanopisto.
the class StudentRESTService method createStudent.
@Path("/students")
@POST
@RESTPermit(StudentPermissions.CREATE_STUDENT)
public Response createStudent(fi.otavanopisto.pyramus.rest.model.Student entity) {
Long personId = entity.getPersonId();
Long studyProgrammeId = entity.getStudyProgrammeId();
String firstName = StringUtils.trim(entity.getFirstName());
String lastName = StringUtils.trim(entity.getLastName());
String nickname = StringUtils.trim(entity.getNickname());
Boolean lodging = entity.getLodging();
if (personId == null || studyProgrammeId == null || lodging == null) {
return Response.status(Status.BAD_REQUEST).build();
}
if (StringUtils.isBlank(firstName) || StringUtils.isBlank(lastName)) {
return Response.status(Status.BAD_REQUEST).build();
}
Person person = personController.findPersonById(personId);
if (person == null) {
return Response.status(Status.BAD_REQUEST).build();
}
StudyProgramme studyProgramme = studyProgrammeController.findStudyProgrammeById(studyProgrammeId);
if (studyProgramme == null) {
return Response.status(Status.BAD_REQUEST).build();
}
if (!sessionController.hasEnvironmentPermission(OrganizationPermissions.ACCESS_ALL_ORGANIZATIONS)) {
if (!(studyProgramme.getOrganization() != null && UserUtils.isMemberOf(sessionController.getUser(), studyProgramme.getOrganization()))) {
return Response.status(Status.FORBIDDEN).build();
}
}
if (!userController.checkUserVariableKeysExist(entity.getVariables().keySet())) {
return Response.status(Status.BAD_REQUEST).build();
}
StudentActivityType activityType = entity.getActivityTypeId() != null ? studentActivityTypeController.findStudentActivityTypeById(entity.getActivityTypeId()) : null;
StudentExaminationType examinationType = entity.getExaminationTypeId() != null ? studentExaminationTypeController.findStudentExaminationTypeById(entity.getExaminationTypeId()) : null;
StudentEducationalLevel educationalLevel = entity.getEducationalLevelId() != null ? studentEducationalLevelController.findStudentEducationalLevelById(entity.getEducationalLevelId()) : null;
Nationality nationality = entity.getNationalityId() != null ? nationalityController.findNationalityById(entity.getNationalityId()) : null;
Municipality municipality = entity.getMunicipalityId() != null ? municipalityController.findMunicipalityById(entity.getMunicipalityId()) : null;
Language language = entity.getLanguageId() != null ? languageController.findLanguageById(entity.getLanguageId()) : null;
School school = entity.getSchoolId() != null ? schoolController.findSchoolById(entity.getSchoolId()) : null;
StudentStudyEndReason studyEndReason = entity.getStudyEndReasonId() != null ? studentStudyEndReasonController.findStudentStudyEndReasonById(entity.getStudyEndReasonId()) : null;
Curriculum curriculum = entity.getCurriculumId() != null ? curriculumController.findCurriculumById(entity.getCurriculumId()) : null;
Student student = studentController.createStudent(person, firstName, lastName, nickname, entity.getAdditionalInfo(), toDate(entity.getStudyTimeEnd()), activityType, examinationType, educationalLevel, entity.getEducation(), nationality, municipality, language, school, studyProgramme, curriculum, entity.getPreviousStudies(), toDate(entity.getStudyStartDate()), toDate(entity.getStudyEndDate()), studyEndReason, entity.getStudyEndText());
if (Boolean.TRUE.equals(lodging) && entity.getStudyStartDate() != null)
studentController.addLodgingPeriod(student, toDate(entity.getStudyStartDate()), toDate(entity.getStudyEndDate()));
userController.updateUserVariables(student, entity.getVariables());
studentController.updateStudentTags(student, entity.getTags());
studentController.updateStudentAdditionalContactInfo(student, entity.getAdditionalContactInfo());
return Response.ok(objectFactory.createModel(student)).build();
}
use of fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme in project pyramus by otavanopisto.
the class CourseSignupRESTService method createSignupStudyProgramme.
/**
* Creates a signup study programme.
*
* Organization information within entity is not used.
*/
@Path("/courses/{COURSEID:[0-9]*}/signupStudyProgrammes")
@POST
@RESTPermit(CourseSignupGroupPermissions.CREATE_SIGNUP_STUDYPROGRAMME)
public Response createSignupStudyProgramme(@PathParam("COURSEID") Long pathCourseId, fi.otavanopisto.pyramus.rest.model.course.CourseSignupStudyProgramme entity) {
if (entity == null) {
return Response.status(Status.BAD_REQUEST).build();
}
Long courseId = entity.getCourseId();
Long studyProgrammeId = entity.getStudyProgrammeId();
if (courseId == null || studyProgrammeId == null || !courseId.equals(pathCourseId)) {
return Response.status(Status.BAD_REQUEST).build();
}
Course course = courseController.findCourseById(courseId);
StudyProgramme studyProgramme = studyProgrammeController.findStudyProgrammeById(studyProgrammeId);
if (course == null || studyProgramme == null) {
return Response.status(Status.NOT_FOUND).build();
}
User loggedUser = sessionController.getUser();
if (UserUtils.canAccessOrganization(loggedUser, course.getOrganization()) && UserUtils.canAccessOrganization(loggedUser, studyProgramme.getOrganization())) {
return Response.ok(objectFactory.createModel(courseSignupStudyProgrammeDAO.create(course, studyProgramme))).build();
} else {
return Response.status(Status.FORBIDDEN).build();
}
}
Aggregations