use of fi.otavanopisto.pyramus.domainmodel.students.StudentGroup in project pyramus by otavanopisto.
the class EditCourseJSONRequestController method processSignupStudentGroups.
private void processSignupStudentGroups(JSONRequestContext requestContext, Course course, StaffMember loggedUser) {
CourseSignupStudentGroupDAO courseSignupStudentGroupDAO = DAOFactory.getInstance().getCourseSignupStudentGroupDAO();
StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
List<CourseSignupStudentGroup> signupStudentGroups = courseSignupStudentGroupDAO.listByCourse(course);
Integer studentGroupsRowCount = requestContext.getInteger("signupStudentGroupsTable.rowCount");
if (studentGroupsRowCount != null) {
Set<Long> studentGroupIdsPresent = new HashSet<>();
for (int i = 0; i < studentGroupsRowCount; i++) {
Long studentGroupId = requestContext.getLong(String.format("signupStudentGroupsTable.%d.studentGroupId", i));
if (studentGroupId != null) {
studentGroupIdsPresent.add(studentGroupId);
}
}
// Create missing groups
studentGroupIdsPresent.forEach(studentGroupId -> {
if (signupStudentGroups.stream().noneMatch(signupStudentGroup -> Objects.equals(signupStudentGroup.getStudentGroup().getId(), studentGroupId))) {
StudentGroup studentGroup = studentGroupDAO.findById(studentGroupId);
if ((studentGroup != null) && UserUtils.canAccessOrganization(loggedUser, studentGroup.getOrganization())) {
courseSignupStudentGroupDAO.create(course, studentGroup);
} else {
throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Invalid organization.");
}
}
});
// Remove groups that don't exist anymore
signupStudentGroups.stream().filter(signupStudentGroup -> !studentGroupIdsPresent.contains(signupStudentGroup.getStudentGroup().getId())).forEach(signupStudentGroup -> {
if (UserUtils.canAccessOrganization(loggedUser, signupStudentGroup.getStudentGroup().getOrganization())) {
courseSignupStudentGroupDAO.delete(signupStudentGroup);
} else {
throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Invalid organization.");
}
});
}
}
use of fi.otavanopisto.pyramus.domainmodel.students.StudentGroup in project pyramus by otavanopisto.
the class StudentGroupsAutoCompleteBinaryRequestController method process.
/**
* Processes a binary request.
* The request should contain the following parameters:
* <dl>
* <dt><code>text</code></dt>
* <dd>Already typed characters.</dd>
* </dl>
*
* @param binaryRequestContext The context of the binary request.
*/
public void process(BinaryRequestContext binaryRequestContext) {
StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
String text = binaryRequestContext.getString("text");
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.append("<ul>");
if (!StringUtils.isBlank(text)) {
text = QueryParser.escape(StringUtils.trim(text)) + '*';
StaffMember loggedUser = staffMemberDAO.findById(binaryRequestContext.getLoggedUserId());
Organization organization = UserUtils.canAccessAllOrganizations(loggedUser) ? null : loggedUser.getOrganization();
List<StudentGroup> studentGroups = studentGroupDAO.searchStudentGroupsBasic(100, 0, organization, text).getResults();
for (StudentGroup studentGroup : studentGroups) {
addResult(resultBuilder, studentGroup);
}
}
resultBuilder.append("</ul>");
try {
binaryRequestContext.setResponseContent(resultBuilder.toString().getBytes("UTF-8"), "text/html;charset=UTF-8");
} catch (UnsupportedEncodingException e) {
throw new SmvcRuntimeException(e);
}
}
use of fi.otavanopisto.pyramus.domainmodel.students.StudentGroup in project pyramus by otavanopisto.
the class ManageStudentGroupContactEntriesViewController method process.
/**
* Processes the page request.
*
* In parameters
* - person
*
* Page parameters
* - person - Person object
* - contactEntries - List of StudentContactLogEntry objects
*
* @param pageRequestContext pageRequestContext
*/
public void process(PageRequestContext pageRequestContext) {
StudentGroupContactLogEntryDAO logEntryDAO = DAOFactory.getInstance().getStudentGroupContactLogEntryDAO();
StudentGroupContactLogEntryCommentDAO entryCommentDAO = DAOFactory.getInstance().getStudentGroupContactLogEntryCommentDAO();
StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
Long studentGroupId = pageRequestContext.getLong("studentgroup");
StudentGroup studentGroup = studentGroupDAO.findById(studentGroupId);
pageRequestContext.getRequest().setAttribute("studentGroup", studentGroup);
final Map<Long, List<StudentGroupContactLogEntryComment>> contactEntryComments = new HashMap<>();
List<StudentGroupContactLogEntry> contactLogEntries = logEntryDAO.listByStudentGroup(studentGroup);
for (int j = 0; j < contactLogEntries.size(); j++) {
StudentGroupContactLogEntry entry = contactLogEntries.get(j);
List<StudentGroupContactLogEntryComment> listComments = entryCommentDAO.listByEntry(entry);
Collections.sort(listComments, new Comparator<StudentGroupContactLogEntryComment>() {
public int compare(StudentGroupContactLogEntryComment o1, StudentGroupContactLogEntryComment o2) {
Date d1 = o1.getCommentDate();
Date d2 = o2.getCommentDate();
int val = d1 == null ? d2 == null ? 0 : 1 : d2 == null ? -1 : d1.compareTo(d2);
if (val == 0)
return o1.getId().compareTo(o2.getId());
else
return val;
}
});
contactEntryComments.put(entry.getId(), listComments);
}
// Now we can sort entries based on date of entry and/or dates of the comments on the entry
Collections.sort(contactLogEntries, new Comparator<StudentGroupContactLogEntry>() {
private Date getDateForEntry(StudentGroupContactLogEntry entry) {
Date d = entry.getEntryDate();
List<StudentGroupContactLogEntryComment> comments = contactEntryComments.get(entry.getId());
for (int i = 0; i < comments.size(); i++) {
StudentGroupContactLogEntryComment comment = comments.get(i);
if (d == null) {
d = comment.getCommentDate();
} else {
if (d.before(comment.getCommentDate()))
d = comment.getCommentDate();
}
}
return d;
}
public int compare(StudentGroupContactLogEntry o1, StudentGroupContactLogEntry o2) {
Date d1 = getDateForEntry(o1);
Date d2 = getDateForEntry(o2);
int val = d1 == null ? d2 == null ? 0 : 1 : d2 == null ? -1 : d2.compareTo(d1);
if (val == 0)
return o2.getId().compareTo(o1.getId());
else
return val;
}
});
pageRequestContext.getRequest().setAttribute("contactEntries", contactLogEntries);
pageRequestContext.getRequest().setAttribute("contactEntryComments", contactEntryComments);
pageRequestContext.setIncludeJSP("/templates/students/managestudentgroupcontactentries.jsp");
}
use of fi.otavanopisto.pyramus.domainmodel.students.StudentGroup in project pyramus by otavanopisto.
the class ViewStudentGroupViewController 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();
StudentGroupContactLogEntryDAO contactLogEntryDAO = DAOFactory.getInstance().getStudentGroupContactLogEntryDAO();
StudentGroupContactLogEntryCommentDAO contactLogEntryCommentDAO = DAOFactory.getInstance().getStudentGroupContactLogEntryCommentDAO();
// 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;
}
});
final Map<Long, List<StudentGroupContactLogEntryComment>> contactEntryComments = new HashMap<>();
List<StudentGroupContactLogEntry> contactLogEntries = contactLogEntryDAO.listByStudentGroup(studentGroup);
for (int j = 0; j < contactLogEntries.size(); j++) {
StudentGroupContactLogEntry entry = contactLogEntries.get(j);
List<StudentGroupContactLogEntryComment> listComments = contactLogEntryCommentDAO.listByEntry(entry);
Collections.sort(listComments, new Comparator<StudentGroupContactLogEntryComment>() {
public int compare(StudentGroupContactLogEntryComment o1, StudentGroupContactLogEntryComment o2) {
Date d1 = o1.getCommentDate();
Date d2 = o2.getCommentDate();
int val = d1 == null ? d2 == null ? 0 : 1 : d2 == null ? -1 : d1.compareTo(d2);
if (val == 0)
return o1.getId().compareTo(o2.getId());
else
return val;
}
});
contactEntryComments.put(entry.getId(), listComments);
}
// Now we can sort entries based on date of entry and/or dates of the comments on the entry
Collections.sort(contactLogEntries, new Comparator<StudentGroupContactLogEntry>() {
private Date getDateForEntry(StudentGroupContactLogEntry entry) {
Date d = entry.getEntryDate();
List<StudentGroupContactLogEntryComment> comments = contactEntryComments.get(entry.getId());
for (int i = 0; i < comments.size(); i++) {
StudentGroupContactLogEntryComment comment = comments.get(i);
if (d == null) {
d = comment.getCommentDate();
} else {
if (d.before(comment.getCommentDate()))
d = comment.getCommentDate();
}
}
return d;
}
public int compare(StudentGroupContactLogEntry o1, StudentGroupContactLogEntry o2) {
Date d1 = getDateForEntry(o1);
Date d2 = getDateForEntry(o2);
int val = d1 == null ? d2 == null ? 0 : 1 : d2 == null ? -1 : d2.compareTo(d1);
if (val == 0)
return o2.getId().compareTo(o1.getId());
else
return val;
}
});
pageRequestContext.getRequest().setAttribute("contactEntries", contactLogEntries);
pageRequestContext.getRequest().setAttribute("contactEntryComments", contactEntryComments);
pageRequestContext.getRequest().setAttribute("studentGroupStudents", studentGroupStudents);
pageRequestContext.setIncludeJSP("/templates/students/viewstudentgroup.jsp");
}
use of fi.otavanopisto.pyramus.domainmodel.students.StudentGroup in project pyramus by otavanopisto.
the class ViewStudentGroupViewController method checkAccess.
@Override
protected boolean checkAccess(RequestContext requestContext) {
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
StudentGroupDAO studentGroupDAO = DAOFactory.getInstance().getStudentGroupDAO();
StaffMember loggedUser = staffMemberDAO.findById(requestContext.getLoggedUserId());
StudentGroup studentGroup = studentGroupDAO.findById(requestContext.getLong("studentgroup"));
return Permissions.instance().hasEnvironmentPermission(loggedUser, PyramusViewPermissions.VIEW_STUDENTGROUP) && UserUtils.canAccessOrganization(loggedUser, studentGroup.getOrganization());
}
Aggregations