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