Search in sources :

Example 1 with JSONArrayExtractor

use of fi.otavanopisto.pyramus.util.JSONArrayExtractor 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 2 with JSONArrayExtractor

use of fi.otavanopisto.pyramus.util.JSONArrayExtractor in project pyramus by otavanopisto.

the class EditGradingScaleViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * In order for the JSP page to build the view, gradingScale object is loaded in to "gradingScale" attribute
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    GradingScaleDAO gradingScaleDAO = DAOFactory.getInstance().getGradingScaleDAO();
    Long gradingScaleId = NumberUtils.createLong(pageRequestContext.getRequest().getParameter("gradingScaleId"));
    GradingScale gradingScale = gradingScaleDAO.findById(gradingScaleId);
    pageRequestContext.getRequest().setAttribute("gradingScale", gradingScale);
    String jsonGrades = new JSONArrayExtractor("passingGrade", "name", "qualification", "GPA", "description", "id").extractString(gradingScale.getGrades());
    this.setJsDataVariable(pageRequestContext, "grades", jsonGrades);
    pageRequestContext.setIncludeJSP("/templates/settings/editgradingscale.jsp");
}
Also used : GradingScale(fi.otavanopisto.pyramus.domainmodel.grading.GradingScale) GradingScaleDAO(fi.otavanopisto.pyramus.dao.grading.GradingScaleDAO) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor)

Example 3 with JSONArrayExtractor

use of fi.otavanopisto.pyramus.util.JSONArrayExtractor in project pyramus by otavanopisto.

the class EditSchoolViewController 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) {
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    SchoolFieldDAO schoolFieldDAO = DAOFactory.getInstance().getSchoolFieldDAO();
    SchoolVariableDAO schoolVariableDAO = DAOFactory.getInstance().getSchoolVariableDAO();
    SchoolVariableKeyDAO schoolVariableKeyDAO = DAOFactory.getInstance().getSchoolVariableKeyDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    ContactURLTypeDAO contactURLTypeDAO = DAOFactory.getInstance().getContactURLTypeDAO();
    Long schoolId = NumberUtils.createLong(pageRequestContext.getRequest().getParameter("school"));
    School school = schoolDAO.findById(schoolId);
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = school.getTags().iterator();
    while (tagIterator.hasNext()) {
        Tag tag = tagIterator.next();
        tagsBuilder.append(tag.getText());
        if (tagIterator.hasNext())
            tagsBuilder.append(' ');
    }
    List<ContactURLType> contactURLTypes = contactURLTypeDAO.listUnarchived();
    Collections.sort(contactURLTypes, new StringAttributeComparator("getName"));
    List<SchoolVariableKey> schoolUserEditableVariableKeys = schoolVariableKeyDAO.listUserEditableVariableKeys();
    Collections.sort(schoolUserEditableVariableKeys, new StringAttributeComparator("getVariableName"));
    List<ContactType> contactTypes = contactTypeDAO.listUnarchived();
    Collections.sort(contactTypes, new StringAttributeComparator("getName"));
    String jsonContactTypes = new JSONArrayExtractor("id", "name").extractString(contactTypes);
    List<Address> addresses = school.getContactInfo().getAddresses();
    JSONArray jsonAddresses = new JSONArrayExtractor("id", "defaultAddress", "name", "streetAddress", "postalCode", "city", "country").extract(addresses);
    for (int i = 0; i < jsonAddresses.size(); i++) {
        JSONObject jsonAddress = jsonAddresses.getJSONObject(i);
        if (addresses.get(i).getContactType() != null) {
            jsonAddress.put("contactTypeId", addresses.get(i).getContactType().getId());
        }
    }
    List<Email> emails = school.getContactInfo().getEmails();
    JSONArray jsonEmails = new JSONArrayExtractor("id", "defaultAddress", "address").extract(emails);
    for (int i = 0; i < jsonEmails.size(); i++) {
        JSONObject jsonEmail = jsonEmails.getJSONObject(i);
        if (emails.get(i).getContactType() != null) {
            jsonEmail.put("contactTypeId", emails.get(i).getContactType().getId());
        }
    }
    List<PhoneNumber> phoneNumbers = school.getContactInfo().getPhoneNumbers();
    JSONArray jsonPhoneNumbers = new JSONArrayExtractor("id", "defaultNumber", "number").extract(phoneNumbers);
    for (int i = 0; i < jsonPhoneNumbers.size(); i++) {
        JSONObject jsonPhoneNumber = jsonPhoneNumbers.getJSONObject(i);
        if (phoneNumbers.get(i).getContactType() != null) {
            jsonPhoneNumber.put("contactTypeId", phoneNumbers.get(i).getContactType().getId());
        }
    }
    JSONArray jsonVariableKeys = new JSONArrayExtractor("variableKey", "variableName", "variableType").extract(schoolUserEditableVariableKeys);
    for (int i = 0; i < jsonVariableKeys.size(); i++) {
        JSONObject jsonVariableKey = jsonVariableKeys.getJSONObject(i);
        String key = jsonVariableKey.getString("variableKey");
        String value = schoolVariableDAO.findValueBySchoolAndKey(school, key);
        if (value != null)
            jsonVariableKey.put("variableValue", value);
    }
    this.setJsDataVariable(pageRequestContext, "addresses", jsonAddresses.toString());
    this.setJsDataVariable(pageRequestContext, "emails", jsonEmails.toString());
    this.setJsDataVariable(pageRequestContext, "phoneNumbers", jsonPhoneNumbers.toString());
    this.setJsDataVariable(pageRequestContext, "contactTypes", jsonContactTypes);
    this.setJsDataVariable(pageRequestContext, "variableKeys", jsonVariableKeys.toString());
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    pageRequestContext.getRequest().setAttribute("school", school);
    pageRequestContext.getRequest().setAttribute("variableKeys", schoolUserEditableVariableKeys);
    pageRequestContext.getRequest().setAttribute("schoolFields", schoolFieldDAO.listUnarchived());
    pageRequestContext.setIncludeJSP("/templates/settings/editschool.jsp");
}
Also used : ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) SchoolVariableKeyDAO(fi.otavanopisto.pyramus.dao.base.SchoolVariableKeyDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor) ContactURLTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactURLTypeDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) SchoolVariableDAO(fi.otavanopisto.pyramus.dao.base.SchoolVariableDAO) JSONArray(net.sf.json.JSONArray) SchoolVariableKey(fi.otavanopisto.pyramus.domainmodel.base.SchoolVariableKey) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType) JSONObject(net.sf.json.JSONObject) SchoolFieldDAO(fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag)

Example 4 with JSONArrayExtractor

use of fi.otavanopisto.pyramus.util.JSONArrayExtractor in project pyramus by otavanopisto.

the class EducationTypesViewController 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) {
    EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
    List<EducationType> educationTypes = educationTypeDAO.listUnarchived();
    Collections.sort(educationTypes, new StringAttributeComparator("getName"));
    String jsonEducationTypes = new JSONArrayExtractor("name", "code", "id").extractString(educationTypes);
    this.setJsDataVariable(pageRequestContext, "educationTypes", jsonEducationTypes);
    pageRequestContext.setIncludeJSP("/templates/settings/educationtypes.jsp");
}
Also used : EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor)

Example 5 with JSONArrayExtractor

use of fi.otavanopisto.pyramus.util.JSONArrayExtractor in project pyramus by otavanopisto.

the class StudyProgrammeCategoriesViewController 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) {
    StudyProgrammeCategoryDAO studyProgrammeCategoryDAO = DAOFactory.getInstance().getStudyProgrammeCategoryDAO();
    EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
    List<EducationType> educationTypes = educationTypeDAO.listUnarchived();
    Collections.sort(educationTypes, new StringAttributeComparator("getName"));
    List<StudyProgrammeCategory> studyProgrammeCategories = studyProgrammeCategoryDAO.listUnarchived();
    JSONArray jsonStudyProgrammeCategories = new JSONArrayExtractor("name", "id").extract(studyProgrammeCategories);
    for (int i = 0; i < jsonStudyProgrammeCategories.size(); i++) {
        JSONObject jsonStudyProgrammeCategory = jsonStudyProgrammeCategories.getJSONObject(i);
        if (studyProgrammeCategories.get(i).getEducationType() != null) {
            jsonStudyProgrammeCategory.put("educationTypeId", studyProgrammeCategories.get(i).getEducationType().getId());
        }
    }
    String jsonEducationTypes = new JSONArrayExtractor("name", "id").extractString(educationTypes);
    this.setJsDataVariable(pageRequestContext, "studyProgrammeCategories", jsonStudyProgrammeCategories.toString());
    this.setJsDataVariable(pageRequestContext, "educationTypes", jsonEducationTypes);
    pageRequestContext.setIncludeJSP("/templates/settings/studyprogrammecategories.jsp");
}
Also used : EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) JSONObject(net.sf.json.JSONObject) StudyProgrammeCategory(fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory) StudyProgrammeCategoryDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) JSONArray(net.sf.json.JSONArray) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor)

Aggregations

JSONArrayExtractor (fi.otavanopisto.pyramus.util.JSONArrayExtractor)37 StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)18 JSONObject (net.sf.json.JSONObject)12 JSONArray (net.sf.json.JSONArray)10 EducationTypeDAO (fi.otavanopisto.pyramus.dao.base.EducationTypeDAO)7 EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)7 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)6 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)6 SchoolDAO (fi.otavanopisto.pyramus.dao.base.SchoolDAO)5 School (fi.otavanopisto.pyramus.domainmodel.base.School)5 ContactTypeDAO (fi.otavanopisto.pyramus.dao.base.ContactTypeDAO)4 ContactURLTypeDAO (fi.otavanopisto.pyramus.dao.base.ContactURLTypeDAO)4 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)4 SchoolFieldDAO (fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO)4 StudyProgrammeCategoryDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeCategoryDAO)4 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)4 ContactURLType (fi.otavanopisto.pyramus.domainmodel.base.ContactURLType)4 DefaultsDAO (fi.otavanopisto.pyramus.dao.base.DefaultsDAO)3 SchoolVariableKeyDAO (fi.otavanopisto.pyramus.dao.base.SchoolVariableKeyDAO)3 StudyProgrammeDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO)3