use of fi.otavanopisto.pyramus.domainmodel.base.Municipality 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.Municipality in project pyramus by otavanopisto.
the class MunicipalitiesViewController method process.
/**
* Processes the page request by including the corresponding JSP page to the response.
*
* @param pageRequestContext Page request context
*/
public void process(PageRequestContext pageRequestContext) {
MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
List<Municipality> municipalities = municipalityDAO.listUnarchived();
Collections.sort(municipalities, new StringAttributeComparator("getName"));
String jsonMunicipalities = new JSONArrayExtractor("name", "code", "id").extractString(municipalities);
this.setJsDataVariable(pageRequestContext, "municipalities", jsonMunicipalities);
pageRequestContext.setIncludeJSP("/templates/settings/municipalities.jsp");
}
use of fi.otavanopisto.pyramus.domainmodel.base.Municipality 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.Municipality 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.Municipality in project pyramus by otavanopisto.
the class MunicipalityDAO method findByCode.
/**
* Returns the municipality corresponding to the given code.
*
* @param code
* The municipality code
*
* @return The municipality corresponding to the given code
*/
public Municipality findByCode(String code) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Municipality> criteria = criteriaBuilder.createQuery(Municipality.class);
Root<Municipality> root = criteria.from(Municipality.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(Municipality_.code), code));
return getSingleResult(entityManager.createQuery(criteria));
}
Aggregations