Search in sources :

Example 6 with Municipality

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");
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) UserVariableKey(fi.otavanopisto.pyramus.domainmodel.users.UserVariableKey) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) StudentStudyEndReasonDAO(fi.otavanopisto.pyramus.dao.students.StudentStudyEndReasonDAO) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) ContactURLTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactURLTypeDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) MunicipalityDAO(fi.otavanopisto.pyramus.dao.base.MunicipalityDAO) StudentEducationalLevelDAO(fi.otavanopisto.pyramus.dao.students.StudentEducationalLevelDAO) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) StudentExaminationTypeDAO(fi.otavanopisto.pyramus.dao.students.StudentExaminationTypeDAO) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) NationalityDAO(fi.otavanopisto.pyramus.dao.base.NationalityDAO) LanguageDAO(fi.otavanopisto.pyramus.dao.base.LanguageDAO) StudentActivityTypeDAO(fi.otavanopisto.pyramus.dao.students.StudentActivityTypeDAO) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType) UserVariableKeyDAO(fi.otavanopisto.pyramus.dao.users.UserVariableKeyDAO) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Person(fi.otavanopisto.pyramus.domainmodel.base.Person)

Example 7 with Municipality

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");
}
Also used : Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) MunicipalityDAO(fi.otavanopisto.pyramus.dao.base.MunicipalityDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor)

Example 8 with Municipality

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();
}
Also used : Status(javax.ws.rs.core.Response.Status) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) StudentExaminationType(fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType) StudentStudyEndReason(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StudentEducationalLevel(fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) School(fi.otavanopisto.pyramus.domainmodel.base.School) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) StudentActivityType(fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) PUT(javax.ws.rs.PUT)

Example 9 with Municipality

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();
}
Also used : Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) StudentExaminationType(fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType) StudentStudyEndReason(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason) StudentEducationalLevel(fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) School(fi.otavanopisto.pyramus.domainmodel.base.School) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) StudentActivityType(fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) POST(javax.ws.rs.POST)

Example 10 with Municipality

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));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality)

Aggregations

Municipality (fi.otavanopisto.pyramus.domainmodel.base.Municipality)23 Language (fi.otavanopisto.pyramus.domainmodel.base.Language)14 Nationality (fi.otavanopisto.pyramus.domainmodel.base.Nationality)14 MunicipalityDAO (fi.otavanopisto.pyramus.dao.base.MunicipalityDAO)13 StudyProgramme (fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme)13 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)13 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)12 School (fi.otavanopisto.pyramus.domainmodel.base.School)12 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)10 StudentActivityType (fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType)10 StudentEducationalLevel (fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel)10 StudentExaminationType (fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType)10 StudentStudyEndReason (fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason)10 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)9 StudyProgrammeDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO)9 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)9 LanguageDAO (fi.otavanopisto.pyramus.dao.base.LanguageDAO)8 NationalityDAO (fi.otavanopisto.pyramus.dao.base.NationalityDAO)8 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)7 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)7