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