Search in sources :

Example 61 with StringAttributeComparator

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

the class EditStudentGroupViewController 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) {
    StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
    OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    // The student group to be edited
    StudentGroup studentGroup = studentGroupDAO.findById(pageRequestContext.getLong("studentgroup"));
    pageRequestContext.getRequest().setAttribute("studentGroup", studentGroup);
    List<StudentGroupStudent> studentGroupStudents = new ArrayList<>(studentGroup.getStudents());
    Collections.sort(studentGroupStudents, new Comparator<StudentGroupStudent>() {

        @Override
        public int compare(StudentGroupStudent o1, StudentGroupStudent o2) {
            int cmp = o1.getStudent().getLastName().compareToIgnoreCase(o2.getStudent().getLastName());
            if (cmp == 0)
                cmp = o1.getStudent().getFirstName().compareToIgnoreCase(o2.getStudent().getFirstName());
            return cmp;
        }
    });
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = studentGroup.getTags().iterator();
    while (tagIterator.hasNext()) {
        Tag tag = tagIterator.next();
        tagsBuilder.append(tag.getText());
        if (tagIterator.hasNext())
            tagsBuilder.append(' ');
    }
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    JSONArray studentGroupStudentsJSON = new JSONArray();
    for (StudentGroupStudent studentGroupStudent : studentGroupStudents) {
        if (studentGroupStudent.getStudent() != null) {
            JSONObject obj = new JSONObject();
            obj.put("id", studentGroupStudent.getId().toString());
            obj.put("studentId", studentGroupStudent.getStudent().getId().toString());
            obj.put("personId", studentGroupStudent.getStudent().getPerson().getId().toString());
            obj.put("firstName", studentGroupStudent.getStudent().getFirstName());
            obj.put("lastName", studentGroupStudent.getStudent().getLastName());
            List<Student> studyProgrammes = getPersonStudyProgrammes(studentGroupStudent.getStudent().getPerson());
            JSONArray studentStudyProgrammeJSON = new JSONArray();
            for (Student student : studyProgrammes) {
                JSONObject spJSON = new JSONObject();
                String studyProgrammeName;
                if (student.getStudyProgramme() != null)
                    studyProgrammeName = student.getStudyProgramme().getName();
                else
                    studyProgrammeName = Messages.getInstance().getText(pageRequestContext.getRequest().getLocale(), "students.editStudent.noStudyProgrammeDropDownItemLabel");
                if (student.getStudyEndDate() != null) {
                    studyProgrammeName += " *";
                }
                spJSON.put("studentId", student.getId());
                spJSON.put("studyProgrammeName", studyProgrammeName);
                studentStudyProgrammeJSON.add(spJSON);
            }
            obj.put("studyProgrammes", studentStudyProgrammeJSON.toString());
            studentGroupStudentsJSON.add(obj);
        }
    }
    setJsDataVariable(pageRequestContext, "studentGroupStudents", studentGroupStudentsJSON.toString());
    Long loggedUserId = pageRequestContext.getLoggedUserId();
    StaffMember user = staffMemberDAO.findById(loggedUserId);
    List<Organization> organizations;
    if (UserUtils.canAccessAllOrganizations(user)) {
        organizations = organizationDAO.listUnarchived();
    } else {
        organizations = Arrays.asList(user.getOrganization());
    }
    Collections.sort(organizations, new StringAttributeComparator("getName"));
    pageRequestContext.getRequest().setAttribute("organizations", organizations);
    pageRequestContext.setIncludeJSP("/templates/students/editstudentgroup.jsp");
}
Also used : Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) ArrayList(java.util.ArrayList) JSONArray(net.sf.json.JSONArray) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) StudentGroupDAO(fi.otavanopisto.pyramus.dao.students.StudentGroupDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) JSONObject(net.sf.json.JSONObject) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup)

Example 62 with StringAttributeComparator

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

the class StudyProgrammeCategoriesSetupWizardViewController method setup.

@Override
public void setup(PageRequestContext requestContext) throws SetupWizardException {
    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(requestContext, "studyProgrammeCategories", jsonStudyProgrammeCategories.toString());
    this.setJsDataVariable(requestContext, "educationTypes", jsonEducationTypes);
}
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)

Example 63 with StringAttributeComparator

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

the class CreateUserViewController 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) {
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    ContactURLTypeDAO contactURLTypeDAO = DAOFactory.getInstance().getContactURLTypeDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    StaffMember loggedUser = staffMemberDAO.findById(pageRequestContext.getLoggedUserId());
    Long studentId = pageRequestContext.getLong("studentId");
    boolean hasInternalAuthenticationStrategies = AuthenticationProviderVault.getInstance().hasInternalStrategies();
    if (studentId != null) {
        Student student = studentDAO.findById(studentId);
        pageRequestContext.getRequest().setAttribute("person", student.getPerson());
        pageRequestContext.getRequest().setAttribute("student", student);
        String emails = new JSONArrayExtractor("defaultAddress", "contactType", "address").extractString(student.getContactInfo().getEmails());
        String addresses = new JSONArrayExtractor("defaultAddress", "name", "contactType", "streetAddress", "postalCode", "city", "country").extractString(student.getContactInfo().getAddresses());
        String phones = new JSONArrayExtractor("defaultNumber", "contactType", "number").extractString(student.getContactInfo().getPhoneNumbers());
        setJsDataVariable(pageRequestContext, "createuser_emails", emails);
        setJsDataVariable(pageRequestContext, "createuser_addresses", addresses);
        setJsDataVariable(pageRequestContext, "createuser_phones", phones);
    }
    List<ContactURLType> contactURLTypes = contactURLTypeDAO.listUnarchived();
    Collections.sort(contactURLTypes, new StringAttributeComparator("getName"));
    List<ContactType> contactTypes = contactTypeDAO.listUnarchived();
    Collections.sort(contactTypes, new StringAttributeComparator("getName"));
    List<Organization> organizations;
    if (UserUtils.canAccessAllOrganizations(loggedUser)) {
        organizations = organizationDAO.listUnarchived();
    } else {
        organizations = Arrays.asList(loggedUser.getOrganization());
    }
    Collections.sort(organizations, new StringAttributeComparator("getName"));
    pageRequestContext.getRequest().setAttribute("contactTypes", contactTypes);
    pageRequestContext.getRequest().setAttribute("contactURLTypes", contactURLTypes);
    pageRequestContext.getRequest().setAttribute("hasInternalAuthenticationStrategies", hasInternalAuthenticationStrategies);
    pageRequestContext.getRequest().setAttribute("organizations", organizations);
    pageRequestContext.setIncludeJSP("/templates/users/createuser.jsp");
}
Also used : ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) ContactURLTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactURLTypeDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO)

Example 64 with StringAttributeComparator

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

the class EditUserViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param requestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    // TODO loggedUserRole vs. user role
    StaffMemberDAO staffDAO = DAOFactory.getInstance().getStaffMemberDAO();
    UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
    UserVariableKeyDAO variableKeyDAO = DAOFactory.getInstance().getUserVariableKeyDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    ContactURLTypeDAO contactURLTypeDAO = DAOFactory.getInstance().getContactURLTypeDAO();
    UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
    OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
    StaffMember loggedUser = staffDAO.findById(pageRequestContext.getLoggedUserId());
    StaffMember user = staffDAO.findById(pageRequestContext.getLong("userId"));
    if (!UserUtils.canAccessOrganization(loggedUser, user.getOrganization())) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Cannot access users' organization.");
    }
    String username = "";
    boolean hasInternalAuthenticationStrategies = AuthenticationProviderVault.getInstance().hasInternalStrategies();
    if (hasInternalAuthenticationStrategies) {
        // TODO: Support for multiple internal authentication providers
        List<InternalAuthenticationProvider> internalAuthenticationProviders = AuthenticationProviderVault.getInstance().getInternalAuthenticationProviders();
        if (internalAuthenticationProviders.size() == 1) {
            InternalAuthenticationProvider internalAuthenticationProvider = internalAuthenticationProviders.get(0);
            if (internalAuthenticationProvider != null) {
                UserIdentification userIdentification = userIdentificationDAO.findByAuthSourceAndPerson(internalAuthenticationProvider.getName(), user.getPerson());
                if (internalAuthenticationProvider.canUpdateCredentials()) {
                    if (userIdentification != null) {
                        username = internalAuthenticationProvider.getUsername(userIdentification.getExternalId());
                    }
                }
            }
        }
    }
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = user.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<ContactType> contactTypes = contactTypeDAO.listUnarchived();
    Collections.sort(contactTypes, new StringAttributeComparator("getName"));
    List<UserVariableKey> userVariableKeys = variableKeyDAO.listUserEditableUserVariableKeys();
    Collections.sort(userVariableKeys, new StringAttributeComparator("getVariableName"));
    JSONArray variables = new JSONArray();
    for (UserVariableKey userVariableKey : userVariableKeys) {
        UserVariable userVariable = userVariableDAO.findByUserAndVariableKey(user, userVariableKey);
        JSONObject variable = new JSONObject();
        variable.put("type", userVariableKey.getVariableType());
        variable.put("name", userVariableKey.getVariableName());
        variable.put("key", userVariableKey.getVariableKey());
        variable.put("value", userVariable != null ? userVariable.getValue() : "");
        variables.add(variable);
    }
    setJsDataVariable(pageRequestContext, "variables", variables.toString());
    List<Organization> organizations;
    if (UserUtils.canAccessAllOrganizations(loggedUser)) {
        organizations = organizationDAO.listUnarchived();
    } else {
        organizations = Arrays.asList(loggedUser.getOrganization());
    }
    Collections.sort(organizations, new StringAttributeComparator("getName"));
    JSONArray propertiesJSON = new JSONArray();
    for (EntityProperty prop : StaffMemberProperties.listProperties()) {
        String value = user.getProperties().get(prop.getKey());
        JSONObject propertyJSON = new JSONObject();
        propertyJSON.put("type", prop.getType());
        propertyJSON.put("name", Messages.getInstance().getText(pageRequestContext.getRequest().getLocale(), prop.getLocaleKey()));
        propertyJSON.put("key", prop.getKey());
        propertyJSON.put("value", value != null ? value : "");
        propertiesJSON.add(propertyJSON);
    }
    setJsDataVariable(pageRequestContext, "properties", propertiesJSON.toString());
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    pageRequestContext.getRequest().setAttribute("user", user);
    pageRequestContext.getRequest().setAttribute("hasInternalAuthenticationStrategies", hasInternalAuthenticationStrategies);
    pageRequestContext.getRequest().setAttribute("username", username);
    pageRequestContext.getRequest().setAttribute("contactTypes", contactTypes);
    pageRequestContext.getRequest().setAttribute("contactURLTypes", contactURLTypes);
    pageRequestContext.getRequest().setAttribute("organizations", organizations);
    pageRequestContext.setIncludeJSP("/templates/users/edituser.jsp");
}
Also used : ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) UserVariableKey(fi.otavanopisto.pyramus.domainmodel.users.UserVariableKey) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) UserVariable(fi.otavanopisto.pyramus.domainmodel.users.UserVariable) EntityProperty(fi.otavanopisto.pyramus.framework.EntityProperty) ContactURLTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactURLTypeDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) InternalAuthenticationProvider(fi.otavanopisto.pyramus.plugin.auth.InternalAuthenticationProvider) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO) UserIdentificationDAO(fi.otavanopisto.pyramus.dao.users.UserIdentificationDAO) JSONArray(net.sf.json.JSONArray) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType) UserVariableKeyDAO(fi.otavanopisto.pyramus.dao.users.UserVariableKeyDAO) JSONObject(net.sf.json.JSONObject) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) UserIdentification(fi.otavanopisto.pyramus.domainmodel.users.UserIdentification)

Aggregations

StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)64 JSONArrayExtractor (fi.otavanopisto.pyramus.util.JSONArrayExtractor)18 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)17 EducationTypeDAO (fi.otavanopisto.pyramus.dao.base.EducationTypeDAO)16 EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)16 JSONArray (net.sf.json.JSONArray)16 JSONObject (net.sf.json.JSONObject)16 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)13 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)13 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)13 HashMap (java.util.HashMap)13 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)12 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)12 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)12 SubjectDAO (fi.otavanopisto.pyramus.dao.base.SubjectDAO)11 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)10 EducationSubtypeDAO (fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO)9 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)9 SchoolDAO (fi.otavanopisto.pyramus.dao.base.SchoolDAO)8 ResourceCategoryDAO (fi.otavanopisto.pyramus.dao.resources.ResourceCategoryDAO)8