public static Collection<StudentClassEnrollment> getStudentClassEnrollments( RelatedObjectInterface relatedObject) { switch (relatedObject.getType()) { case Class: return EventDAO.getInstance() .getSession() .createQuery( "select distinct e from StudentClassEnrollment e, StudentClassEnrollment f where f.clazz.uniqueId = :classId" + " and e.courseOffering.instructionalOffering = f.courseOffering.instructionalOffering and e.student = f.student") .setLong("classId", relatedObject.getUniqueId()) .setCacheable(true) .list(); case Config: return EventDAO.getInstance() .getSession() .createQuery( "select distinct e from StudentClassEnrollment e, StudentClassEnrollment f where f.clazz.schedulingSubpart.instrOfferingConfig.uniqueId = :configId" + " and e.courseOffering.instructionalOffering = f.courseOffering.instructionalOffering and e.student = f.student") .setLong("configId", relatedObject.getUniqueId()) .setCacheable(true) .list(); case Course: return EventDAO.getInstance() .getSession() .createQuery( "select e from StudentClassEnrollment e where e.courseOffering.uniqueId = :courseId") .setLong("courseId", relatedObject.getUniqueId()) .setCacheable(true) .list(); case Offering: return EventDAO.getInstance() .getSession() .createQuery( "select e from StudentClassEnrollment e where e.courseOffering.instructionalOffering.uniqueId = :offeringId") .setLong("offeringId", relatedObject.getUniqueId()) .setCacheable(true) .list(); default: throw new GwtRpcException("Unsupported related object type " + relatedObject.getType()); } }
@Override public SaveOrApproveEventRpcResponse execute(SaveEventRpcRequest request, EventContext context) { if (request.getEvent().hasContact() && (request.getEvent().getContact().getExternalId() == null || !request .getEvent() .getContact() .getExternalId() .equals(context.getUser().getExternalUserId()))) { switch (request.getEvent().getType()) { case Special: case Course: case Unavailabile: context.checkPermission(Right.EventLookupContact); } } if (request.getEvent().getId() == null) { // new even switch (request.getEvent().getType()) { case Special: context.checkPermission(Right.EventAddSpecial); break; case Course: context.checkPermission(Right.EventAddCourseRelated); break; case Unavailabile: context.checkPermission(Right.EventAddUnavailable); break; default: throw context.getException(); } } else { // existing event context.checkPermission(request.getEvent().getId(), "Event", Right.EventEdit); } // Check main contact email if (request.getEvent().hasContact() && request.getEvent().getContact().hasEmail()) { try { new InternetAddress(request.getEvent().getContact().getEmail(), true); } catch (AddressException e) { throw new GwtRpcException( MESSAGES.badEmailAddress(request.getEvent().getContact().getEmail(), e.getMessage())); } } // Check additional emails if (request.getEvent().hasEmail()) { String suffix = ApplicationProperty.EmailDefaultAddressSuffix.value(); for (String address : request.getEvent().getEmail().split("[\n,]")) { String email = address.trim(); if (email.isEmpty()) continue; if (suffix != null && email.indexOf('@') < 0) email += suffix; try { new InternetAddress(email, true); } catch (AddressException e) { throw new GwtRpcException(MESSAGES.badEmailAddress(address, e.getMessage())); } } } org.hibernate.Session hibSession = SessionDAO.getInstance().getSession(); Transaction tx = hibSession.beginTransaction(); try { Session session = SessionDAO.getInstance().get(request.getSessionId(), hibSession); Date now = new Date(); Event event = null; if (request.getEvent().getId() != null) { event = EventDAO.getInstance().get(request.getEvent().getId(), hibSession); } else { switch (request.getEvent().getType()) { case Special: event = new SpecialEvent(); break; case Course: event = new CourseEvent(); break; case Unavailabile: event = new UnavailableEvent(); break; default: throw new GwtRpcException( MESSAGES.failedSaveEventWrongType(request.getEvent().getType().getName(CONSTANTS))); } } SaveOrApproveEventRpcResponse response = new SaveOrApproveEventRpcResponse(); event.setEventName(request.getEvent().getName()); if (event.getEventName() == null || event.getEventName().isEmpty() && request.getEvent().getType() == EventType.Unavailabile) event.setEventName(MESSAGES.unavailableEventDefaultName()); event.setEmail(request.getEvent().getEmail()); if (context.hasPermission(Right.EventSetExpiration) || event.getExpirationDate() != null) event.setExpirationDate(request.getEvent().getExpirationDate()); event.setSponsoringOrganization( request.getEvent().hasSponsor() ? SponsoringOrganizationDAO.getInstance() .get(request.getEvent().getSponsor().getUniqueId()) : null); if (event instanceof UnavailableEvent) { } else if (event instanceof SpecialEvent) { event.setMinCapacity(request.getEvent().getMaxCapacity()); event.setMaxCapacity(request.getEvent().getMaxCapacity()); } if (event.getAdditionalContacts() == null) { event.setAdditionalContacts(new HashSet<EventContact>()); } if (context.hasPermission(Right.EventLookupContact)) { Set<EventContact> existingContacts = new HashSet<EventContact>(event.getAdditionalContacts()); event.getAdditionalContacts().clear(); if (request.getEvent().hasAdditionalContacts()) for (ContactInterface c : request.getEvent().getAdditionalContacts()) { if (c.getExternalId() == null) continue; EventContact contact = null; for (EventContact x : existingContacts) if (c.getExternalId().equals(x.getExternalUniqueId())) { contact = x; break; } if (contact == null) { contact = (EventContact) hibSession .createQuery("from EventContact where externalUniqueId = :externalId") .setString("externalId", c.getExternalId()) .setMaxResults(1) .uniqueResult(); } if (contact == null) { contact = new EventContact(); contact.setExternalUniqueId(c.getExternalId()); contact.setFirstName(c.getFirstName()); contact.setMiddleName(c.getMiddleName()); contact.setLastName(c.getLastName()); contact.setAcademicTitle(c.getAcademicTitle()); contact.setEmailAddress(c.getEmail()); contact.setPhone(c.getPhone()); hibSession.save(contact); } event.getAdditionalContacts().add(contact); } } EventContact main = event.getMainContact(); if (main == null || main.getExternalUniqueId() == null || !main.getExternalUniqueId().equals(request.getEvent().getContact().getExternalId())) { main = (EventContact) hibSession .createQuery("from EventContact where externalUniqueId = :externalId") .setString("externalId", request.getEvent().getContact().getExternalId()) .setMaxResults(1) .uniqueResult(); if (main == null) { main = new EventContact(); main.setExternalUniqueId(request.getEvent().getContact().getExternalId()); } } main.setFirstName(request.getEvent().getContact().getFirstName()); main.setMiddleName(request.getEvent().getContact().getMiddleName()); main.setLastName(request.getEvent().getContact().getLastName()); main.setAcademicTitle(request.getEvent().getContact().getAcademicTitle()); main.setEmailAddress(request.getEvent().getContact().getEmail()); main.setPhone(request.getEvent().getContact().getPhone()); hibSession.saveOrUpdate(main); event.setMainContact(main); if (event.getNotes() == null) event.setNotes(new HashSet<EventNote>()); if (event.getMeetings() == null) event.setMeetings(new HashSet<Meeting>()); Set<Meeting> remove = new HashSet<Meeting>(event.getMeetings()); TreeSet<Meeting> createdMeetings = new TreeSet<Meeting>(); Set<Meeting> cancelledMeetings = new TreeSet<Meeting>(); Set<Meeting> updatedMeetings = new TreeSet<Meeting>(); for (MeetingInterface m : request.getEvent().getMeetings()) { Meeting meeting = null; if (m.getApprovalStatus() == ApprovalStatus.Deleted) { if (!context.hasPermission(meeting, Right.EventMeetingDelete) && context.hasPermission(meeting, Right.EventMeetingCancel)) { // Cannot delete, but can cancel --> cancel the meeting instead m.setApprovalStatus(ApprovalStatus.Cancelled); } else { continue; } } if (m.getId() != null) for (Iterator<Meeting> i = remove.iterator(); i.hasNext(); ) { Meeting x = i.next(); if (m.getId().equals(x.getUniqueId())) { meeting = x; i.remove(); break; } } if (meeting != null) { if (m.getApprovalStatus().ordinal() != meeting.getApprovalStatus()) { switch (m.getApprovalStatus()) { case Cancelled: switch (meeting.getEvent().getEventType()) { case Event.sEventTypeFinalExam: case Event.sEventTypeMidtermExam: if (!context.hasPermission(meeting, Right.EventMeetingCancelExam)) throw new GwtRpcException( MESSAGES.failedApproveEventNoRightsToCancel(toString(meeting))); break; case Event.sEventTypeClass: if (!context.hasPermission(meeting, Right.EventMeetingCancelClass)) throw new GwtRpcException( MESSAGES.failedApproveEventNoRightsToCancel(toString(meeting))); break; default: if (!context.hasPermission(meeting, Right.EventMeetingCancel)) throw new GwtRpcException( MESSAGES.failedApproveEventNoRightsToCancel(toString(meeting))); break; } meeting.setStatus(Meeting.Status.CANCELLED); meeting.setApprovalDate(now); hibSession.update(meeting); cancelledMeetings.add(meeting); response.addCancelledMeeting(m); } } else { if (m.getStartOffset() != (meeting.getStartOffset() == null ? 0 : meeting.getStartOffset()) || m.getEndOffset() != (meeting.getStopOffset() == null ? 0 : meeting.getStopOffset())) { if (!context.hasPermission(meeting, Right.EventMeetingEdit)) throw new GwtRpcException( MESSAGES.failedSaveEventCanNotEditMeeting(toString(meeting))); meeting.setStartOffset(m.getStartOffset()); meeting.setStopOffset(m.getEndOffset()); hibSession.update(meeting); response.addUpdatedMeeting(m); updatedMeetings.add(meeting); } } } else { response.addCreatedMeeting(m); meeting = new Meeting(); meeting.setEvent(event); Location location = null; if (m.hasLocation()) { if (m.getLocation().getId() != null) location = LocationDAO.getInstance().get(m.getLocation().getId(), hibSession); else if (m.getLocation().getName() != null) location = Location.findByName( hibSession, request.getSessionId(), m.getLocation().getName()); } if (location == null) throw new GwtRpcException(MESSAGES.failedSaveEventNoLocation(toString(m))); meeting.setLocationPermanentId(location.getPermanentId()); meeting.setStatus(Meeting.Status.PENDING); meeting.setApprovalDate(null); if (!context.hasPermission(location, Right.EventLocation)) throw new GwtRpcException(MESSAGES.failedSaveEventWrongLocation(m.getLocationName())); if (request.getEvent().getType() == EventType.Unavailabile && !context.hasPermission(location, Right.EventLocationUnavailable)) throw new GwtRpcException( MESSAGES.failedSaveCannotMakeUnavailable(m.getLocationName())); if (m.getApprovalStatus() == ApprovalStatus.Approved && context.hasPermission(location, Right.EventLocationApprove)) { meeting.setStatus(Meeting.Status.APPROVED); meeting.setApprovalDate(now); } if (context.isPastOrOutside(m.getMeetingDate())) throw new GwtRpcException( MESSAGES.failedSaveEventPastOrOutside(getDateFormat().format(m.getMeetingDate()))); if (!context.hasPermission(location, Right.EventLocationOverbook)) { List<MeetingConflictInterface> conflicts = computeConflicts(hibSession, m, event.getUniqueId()); if (!conflicts.isEmpty()) throw new GwtRpcException( MESSAGES.failedSaveEventConflict(toString(m), toString(conflicts.get(0)))); } m.setApprovalDate(meeting.getApprovalDate()); m.setApprovalStatus(meeting.getApprovalStatus()); meeting.setStartPeriod(m.getStartSlot()); meeting.setStopPeriod(m.getEndSlot()); meeting.setStartOffset(m.getStartOffset()); meeting.setStopOffset(m.getEndOffset()); meeting.setClassCanOverride(true); meeting.setMeetingDate(m.getMeetingDate()); event.getMeetings().add(meeting); createdMeetings.add(meeting); } // automatic approval if (meeting.getApprovalDate() == null) { switch (request.getEvent().getType()) { case Unavailabile: case Class: case FinalExam: case MidtermExam: meeting.setStatus(Meeting.Status.APPROVED); meeting.setApprovalDate(now); break; } } } if (!remove.isEmpty()) { for (Iterator<Meeting> i = remove.iterator(); i.hasNext(); ) { Meeting m = i.next(); if (!context.hasPermission(m, Right.EventMeetingDelete)) { if (m.getStatus() == Status.CANCELLED || m.getStatus() == Status.REJECTED) { i.remove(); continue; } throw new GwtRpcException(MESSAGES.failedSaveEventCanNotDeleteMeeting(toString(m))); } MeetingInterface meeting = new MeetingInterface(); meeting.setId(m.getUniqueId()); meeting.setMeetingDate(m.getMeetingDate()); meeting.setDayOfWeek(Constants.getDayOfWeek(m.getMeetingDate())); meeting.setStartTime(m.getStartTime().getTime()); meeting.setStopTime(m.getStopTime().getTime()); meeting.setDayOfYear( CalendarUtils.date2dayOfYear(session.getSessionStartYear(), m.getMeetingDate())); meeting.setStartSlot(m.getStartPeriod()); meeting.setEndSlot(m.getStopPeriod()); meeting.setStartOffset(m.getStartOffset() == null ? 0 : m.getStartOffset()); meeting.setEndOffset(m.getStopOffset() == null ? 0 : m.getStopOffset()); meeting.setPast(context.isPastOrOutside(m.getStartTime())); meeting.setApprovalDate(m.getApprovalDate()); meeting.setApprovalStatus(m.getApprovalStatus()); if (m.getLocation() != null) { ResourceInterface location = new ResourceInterface(); location.setType(ResourceType.ROOM); location.setId(m.getLocation().getUniqueId()); location.setName(m.getLocation().getLabel()); location.setSize(m.getLocation().getCapacity()); location.setRoomType(m.getLocation().getRoomTypeLabel()); location.setBreakTime(m.getLocation().getEffectiveBreakTime()); location.setMessage(m.getLocation().getEventMessage()); location.setIgnoreRoomCheck(m.getLocation().isIgnoreRoomCheck()); meeting.setLocation(location); } response.addDeletedMeeting(meeting); } event.getMeetings().removeAll(remove); } EventInterface.DateFormatter df = new EventInterface.DateFormatter() { Formats.Format<Date> dfShort = Formats.getDateFormat(Formats.Pattern.DATE_EVENT_SHORT); Formats.Format<Date> dfLong = Formats.getDateFormat(Formats.Pattern.DATE_EVENT_LONG); @Override public String formatFirstDate(Date date) { return dfShort.format(date); } @Override public String formatLastDate(Date date) { return dfLong.format(date); } }; FileItem attachment = (FileItem) context.getAttribute(UploadServlet.SESSION_LAST_FILE); boolean attached = false; if (response.hasCreatedMeetings()) { EventNote note = new EventNote(); note.setEvent(event); note.setNoteType( event.getUniqueId() == null ? EventNote.sEventNoteTypeCreateEvent : EventNote.sEventNoteTypeAddMeetings); note.setTimeStamp(now); note.setUser(context.getUser().getTrueName()); note.setUserId(context.getUser().getTrueExternalUserId()); if (request.hasMessage()) note.setTextNote(request.getMessage()); note.setMeetings( EventInterface.toString(response.getCreatedMeetings(), CONSTANTS, "\n", df)); note.setAffectedMeetings(createdMeetings); event.getNotes().add(note); NoteInterface n = new NoteInterface(); n.setDate(now); n.setMeetings(note.getMeetings()); n.setUser(context.getUser().getTrueName()); n.setType(NoteInterface.NoteType.values()[note.getNoteType()]); n.setNote(note.getTextNote()); if (attachment != null) { note.setAttachedName(attachment.getName()); note.setAttachedFile(attachment.get()); note.setAttachedContentType(attachment.getContentType()); attached = true; n.setAttachment(attachment.getName()); } response.addNote(n); } if (response.hasUpdatedMeetings() || (!response.hasCreatedMeetings() && !response.hasDeletedMeetings() && !response.hasCancelledMeetings())) { EventNote note = new EventNote(); note.setEvent(event); note.setNoteType(EventNote.sEventNoteTypeEditEvent); note.setTimeStamp(now); note.setUser(context.getUser().getTrueName()); note.setUserId(context.getUser().getTrueExternalUserId()); note.setAffectedMeetings(updatedMeetings); if (request.hasMessage()) note.setTextNote(request.getMessage()); if (response.hasUpdatedMeetings()) note.setMeetings( EventInterface.toString(response.getUpdatedMeetings(), CONSTANTS, "\n", df)); event.getNotes().add(note); NoteInterface n = new NoteInterface(); n.setDate(now); n.setMeetings(note.getMeetings()); n.setUser(context.getUser().getTrueName()); n.setType(NoteInterface.NoteType.values()[note.getNoteType()]); n.setNote(note.getTextNote()); if (attachment != null && !attached) { note.setAttachedName(attachment.getName()); note.setAttachedFile(attachment.get()); note.setAttachedContentType(attachment.getContentType()); attached = true; n.setAttachment(attachment.getName()); } response.addNote(n); } if (response.hasDeletedMeetings()) { EventNote note = new EventNote(); note.setEvent(event); note.setNoteType(EventNote.sEventNoteTypeDeletion); note.setTimeStamp(now); note.setUser(context.getUser().getTrueName()); note.setUserId(context.getUser().getTrueExternalUserId()); if (request.hasMessage()) note.setTextNote(request.getMessage()); note.setMeetings( EventInterface.toString(response.getDeletedMeetings(), CONSTANTS, "\n", df)); event.getNotes().add(note); NoteInterface n = new NoteInterface(); n.setDate(now); n.setMeetings(note.getMeetings()); n.setUser(context.getUser().getTrueName()); n.setType(NoteInterface.NoteType.values()[note.getNoteType()]); n.setNote(note.getTextNote()); if (attachment != null && !attached) { note.setAttachedName(attachment.getName()); note.setAttachedFile(attachment.get()); note.setAttachedContentType(attachment.getContentType()); attached = true; n.setAttachment(attachment.getName()); } response.addNote(n); } if (response.hasCancelledMeetings()) { EventNote note = new EventNote(); note.setEvent(event); note.setNoteType(EventNote.sEventNoteTypeCancel); note.setTimeStamp(now); note.setUser(context.getUser().getTrueName()); note.setUserId(context.getUser().getTrueExternalUserId()); note.setAffectedMeetings(cancelledMeetings); if (request.hasMessage()) note.setTextNote(request.getMessage()); note.setMeetings( EventInterface.toString(response.getCancelledMeetings(), CONSTANTS, "\n", df)); event.getNotes().add(note); NoteInterface n = new NoteInterface(); n.setDate(now); n.setMeetings(note.getMeetings()); n.setUser(context.getUser().getTrueName()); n.setType(NoteInterface.NoteType.values()[note.getNoteType()]); n.setNote(note.getTextNote()); if (attachment != null && !attached) { note.setAttachedName(attachment.getName()); note.setAttachedFile(attachment.get()); note.setAttachedContentType(attachment.getContentType()); attached = true; n.setAttachment(attachment.getName()); } response.addNote(n); } if (request.getEvent().getType() == EventType.Course) { CourseEvent ce = (CourseEvent) event; ce.setReqAttendance(request.getEvent().hasRequiredAttendance()); if (ce.getRelatedCourses() == null) ce.setRelatedCourses(new HashSet<RelatedCourseInfo>()); else ce.getRelatedCourses().clear(); if (request.getEvent().hasRelatedObjects()) for (RelatedObjectInterface r : request.getEvent().getRelatedObjects()) { RelatedCourseInfo related = new RelatedCourseInfo(); related.setEvent(ce); if (r.getSelection() != null) { related.setOwnerId(r.getUniqueId()); related.setOwnerType(r.getType().ordinal()); related.setCourse( CourseOfferingDAO.getInstance().get(r.getSelection()[1], hibSession)); } else { switch (r.getType()) { case Course: related.setOwner(CourseOfferingDAO.getInstance().get(r.getUniqueId())); break; case Class: related.setOwner(Class_DAO.getInstance().get(r.getUniqueId())); break; case Config: related.setOwner(InstrOfferingConfigDAO.getInstance().get(r.getUniqueId())); break; case Offering: related.setOwner(InstructionalOfferingDAO.getInstance().get(r.getUniqueId())); break; } } ce.getRelatedCourses().add(related); } } if (event.getUniqueId() == null) { hibSession.save(event); response.setEvent( EventDetailBackend.getEventDetail( SessionDAO.getInstance().get(request.getSessionId(), hibSession), event, context)); } else if (event.getMeetings().isEmpty()) { response.setEvent( EventDetailBackend.getEventDetail( SessionDAO.getInstance().get(request.getSessionId(), hibSession), event, context)); response.getEvent().setId(null); hibSession.delete(event); } else { hibSession.update(event); response.setEvent( EventDetailBackend.getEventDetail( SessionDAO.getInstance().get(request.getSessionId(), hibSession), event, context)); } tx.commit(); new EventEmail(request, response).send(context); return response; } catch (Exception ex) { tx.rollback(); if (ex instanceof GwtRpcException) throw (GwtRpcException) ex; throw new GwtRpcException(ex.getMessage(), ex); } }
private Map<Long, List<Meeting>> computeConflicts(CourseEvent event) { Map<Long, List<Meeting>> conflicts = new HashMap<Long, List<Meeting>>(); org.hibernate.Session hibSession = EventDAO.getInstance().getSession(); // class events for (int t2 = 0; t2 < ExamOwner.sOwnerTypes.length; t2++) { for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, ClassEvent e1 inner join e1.meetings m1, CourseEvent e2 inner join e2.meetings m2 inner join e2.relatedCourses o2, StudentClassEnrollment s2" + " where e2.uniqueId = :eventId and e1.uniqueId != e2.uniqueId and e1.clazz = s1.clazz and s1.student = s2.student" + where(t2, 2) + " and m1.meetingDate = m2.meetingDate and m1.startPeriod < m2.stopPeriod and m2.startPeriod < m1.stopPeriod and m2.approvalStatus <= 1") .setLong("eventId", event.getUniqueId()) .list()) { Long studentId = (Long) o[0]; Meeting meeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(meeting); } } // examination events for (int t1 = 0; t1 < ExamOwner.sOwnerTypes.length; t1++) { for (int t2 = 0; t2 < ExamOwner.sOwnerTypes.length; t2++) { for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, ExamEvent e1 inner join e1.meetings m1 inner join e1.exam.owners o1, CourseEvent e2 inner join e2.meetings m2 inner join e2.relatedCourses o2, StudentClassEnrollment s2" + " where e2.uniqueId = :eventId and e1.uniqueId != e2.uniqueId and s1.student = s2.student" + where(t1, 1) + where(t2, 2) + " and m1.meetingDate = m2.meetingDate and m1.startPeriod < m2.stopPeriod and m2.startPeriod < m1.stopPeriod and m2.approvalStatus <= 1") .setLong("eventId", event.getUniqueId()) .list()) { Long studentId = (Long) o[0]; Meeting meeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(meeting); } } } // course events for (int t1 = 0; t1 < ExamOwner.sOwnerTypes.length; t1++) { for (int t2 = 0; t2 < ExamOwner.sOwnerTypes.length; t2++) { for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, CourseEvent e1 inner join e1.meetings m1 inner join e1.relatedCourses o1, CourseEvent e2 inner join e2.meetings m2 inner join e2.relatedCourses o2, StudentClassEnrollment s2" + " where e2.uniqueId = :eventId and e1.uniqueId != e2.uniqueId and s1.student = s2.student" + where(t1, 1) + where(t2, 2) + " and m1.meetingDate = m2.meetingDate and m1.startPeriod < m2.stopPeriod and m2.startPeriod < m1.stopPeriod and e1.reqAttendance = true and m1.approvalStatus = 1 and m2.approvalStatus <= 1") .setLong("eventId", event.getUniqueId()) .list()) { Long studentId = (Long) o[0]; Meeting meeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(meeting); } } } return conflicts; }
@Override public GwtRpcResponseList<Enrollment> execute( EventEnrollmentsRpcRequest request, EventContext context) { if (request.hasRelatedObjects()) { context.checkPermission(Right.EventAddCourseRelated); Map<Long, List<Meeting>> conflicts = null; HashSet<StudentClassEnrollment> enrollments = new HashSet<StudentClassEnrollment>(); for (RelatedObjectInterface related : request.getRelatedObjects()) { enrollments.addAll(getStudentClassEnrollments(related)); if (request.hasMeetings()) { conflicts = new HashMap<Long, List<Meeting>>(); for (MeetingInterface meeting : request.getMeetings()) if (meeting.getApprovalStatus() == ApprovalStatus.Approved || meeting.getApprovalStatus() == ApprovalStatus.Pending) computeConflicts(conflicts, meeting, related, request.getEventId()); } } return convert( enrollments, conflicts, context.hasPermission(Right.EnrollmentsShowExternalId), context.hasPermission(Right.CourseRequests), context.hasPermission(Right.SchedulingAssistant)); } else if (request.hasEventId()) { org.hibernate.Session hibSession = EventDAO.getInstance().getSession(); Event event = EventDAO.getInstance().get(request.getEventId()); if (event == null) { if (request.getEventId() < 0) { Class_ clazz = Class_DAO.getInstance().get(-request.getEventId()); if (clazz != null) { context.checkPermission(clazz, Right.ClassDetail); Collection<StudentClassEnrollment> enrollments = clazz.getStudentEnrollments(); if (enrollments == null || enrollments.isEmpty()) return null; return convert( enrollments, null, context.hasPermission(Right.EnrollmentsShowExternalId), context.hasPermission(Right.CourseRequests), context.hasPermission(Right.SchedulingAssistant)); } } throw new GwtRpcException(MESSAGES.errorBadEventId()); } context.checkPermission(event, Right.EventDetail); Collection<StudentClassEnrollment> enrollments = event.getStudentClassEnrollments(); if (enrollments == null || enrollments.isEmpty()) return null; if (Event.sEventTypeClass == event.getEventType()) { return convert( enrollments, computeConflicts( event instanceof ClassEvent ? (ClassEvent) event : ClassEventDAO.getInstance().get(event.getUniqueId(), hibSession)), context.hasPermission(Right.EnrollmentsShowExternalId), context.hasPermission(Right.CourseRequests), context.hasPermission(Right.SchedulingAssistant)); } else if (Event.sEventTypeFinalExam == event.getEventType() || Event.sEventTypeMidtermExam == event.getEventType()) { return convert( enrollments, computeConflicts( event instanceof ExamEvent ? (ExamEvent) event : ExamEventDAO.getInstance().get(event.getUniqueId(), hibSession)), context.hasPermission(Right.EnrollmentsShowExternalId), context.hasPermission(Right.CourseRequests), context.hasPermission(Right.SchedulingAssistant)); } else if (Event.sEventTypeCourse == event.getEventType()) { return convert( enrollments, computeConflicts( event instanceof CourseEvent ? (CourseEvent) event : CourseEventDAO.getInstance().get(event.getUniqueId(), hibSession)), context.hasPermission(Right.EnrollmentsShowExternalId), context.hasPermission(Right.CourseRequests), context.hasPermission(Right.SchedulingAssistant)); } } return null; }
public static GwtRpcResponseList<ClassAssignmentInterface.Enrollment> convert( Collection<StudentClassEnrollment> enrollments, Map<Long, List<Meeting>> conflicts, boolean canShowExtId, boolean canRegister, boolean canUseAssistant) { GwtRpcResponseList<ClassAssignmentInterface.Enrollment> converted = new GwtRpcResponseList<ClassAssignmentInterface.Enrollment>(); Map<String, String> approvedBy2name = new Hashtable<String, String>(); Hashtable<Long, ClassAssignmentInterface.Enrollment> student2enrollment = new Hashtable<Long, ClassAssignmentInterface.Enrollment>(); for (StudentClassEnrollment enrollment : enrollments) { ClassAssignmentInterface.Enrollment enrl = student2enrollment.get(enrollment.getStudent().getUniqueId()); if (enrl == null) { ClassAssignmentInterface.Student st = new ClassAssignmentInterface.Student(); st.setId(enrollment.getStudent().getUniqueId()); st.setExternalId(enrollment.getStudent().getExternalUniqueId()); st.setCanShowExternalId(canShowExtId); st.setCanRegister(canRegister); st.setCanUseAssistant(canUseAssistant); st.setName( enrollment .getStudent() .getName(ApplicationProperty.OnlineSchedulingStudentNameFormat.value())); for (AcademicAreaClassification ac : enrollment.getStudent().getAcademicAreaClassifications()) { st.addArea(ac.getAcademicArea().getAcademicAreaAbbreviation()); st.addClassification(ac.getAcademicClassification().getCode()); } for (PosMajor m : enrollment.getStudent().getPosMajors()) { st.addMajor(m.getCode()); } for (StudentGroup g : enrollment.getStudent().getGroups()) { st.addGroup(g.getGroupAbbreviation()); } for (StudentAccomodation a : enrollment.getStudent().getAccomodations()) { st.addAccommodation(a.getAbbreviation()); } enrl = new ClassAssignmentInterface.Enrollment(); enrl.setStudent(st); enrl.setEnrolledDate(enrollment.getTimestamp()); CourseAssignment c = new CourseAssignment(); c.setCourseId(enrollment.getCourseOffering().getUniqueId()); c.setSubject(enrollment.getCourseOffering().getSubjectAreaAbbv()); c.setCourseNbr(enrollment.getCourseOffering().getCourseNbr()); enrl.setCourse(c); student2enrollment.put(enrollment.getStudent().getUniqueId(), enrl); if (enrollment.getCourseRequest() != null) { enrl.setPriority(1 + enrollment.getCourseRequest().getCourseDemand().getPriority()); if (enrollment.getCourseRequest().getCourseDemand().getCourseRequests().size() > 1) { CourseRequest first = null; for (CourseRequest r : enrollment.getCourseRequest().getCourseDemand().getCourseRequests()) { if (first == null || r.getOrder().compareTo(first.getOrder()) < 0) first = r; } if (!first.equals(enrollment.getCourseRequest())) enrl.setAlternative(first.getCourseOffering().getCourseName()); } if (enrollment.getCourseRequest().getCourseDemand().isAlternative()) { CourseDemand first = enrollment.getCourseRequest().getCourseDemand(); demands: for (CourseDemand cd : enrollment.getStudent().getCourseDemands()) { if (!cd.isAlternative() && cd.getPriority().compareTo(first.getPriority()) < 0 && !cd.getCourseRequests().isEmpty()) { for (CourseRequest cr : cd.getCourseRequests()) if (cr.getClassEnrollments().isEmpty()) continue demands; first = cd; } } CourseRequest alt = null; for (CourseRequest r : first.getCourseRequests()) { if (alt == null || r.getOrder().compareTo(alt.getOrder()) < 0) alt = r; } enrl.setAlternative(alt.getCourseOffering().getCourseName()); } enrl.setRequestedDate(enrollment.getCourseRequest().getCourseDemand().getTimestamp()); enrl.setApprovedDate(enrollment.getApprovedDate()); if (enrollment.getApprovedBy() != null) { String name = approvedBy2name.get(enrollment.getApprovedBy()); if (name == null) { TimetableManager mgr = (TimetableManager) EventDAO.getInstance() .getSession() .createQuery("from TimetableManager where externalUniqueId = :externalId") .setString("externalId", enrollment.getApprovedBy()) .setMaxResults(1) .uniqueResult(); if (mgr != null) { name = mgr.getName(); } else { DepartmentalInstructor instr = (DepartmentalInstructor) EventDAO.getInstance() .getSession() .createQuery( "from DepartmentalInstructor where externalUniqueId = :externalId and department.session.uniqueId = :sessionId") .setString("externalId", enrollment.getApprovedBy()) .setLong( "sessionId", enrollment.getStudent().getSession().getUniqueId()) .setMaxResults(1) .uniqueResult(); if (instr != null) name = instr.nameLastNameFirst(); } if (name != null) approvedBy2name.put(enrollment.getApprovedBy(), name); } enrl.setApprovedBy(name == null ? enrollment.getApprovedBy() : name); } } else { enrl.setPriority(-1); } List<Meeting> conf = (conflicts == null ? null : conflicts.get(enrollment.getStudent().getUniqueId())); if (conf != null) { Map<Event, TreeSet<Meeting>> events = new HashMap<Event, TreeSet<Meeting>>(); for (Meeting m : conf) { TreeSet<Meeting> ms = events.get(m.getEvent()); if (ms == null) { ms = new TreeSet<Meeting>(); events.put(m.getEvent(), ms); } ms.add(m); } for (Event confEvent : new TreeSet<Event>(events.keySet())) { Conflict conflict = new Conflict(); conflict.setName(confEvent.getEventName()); conflict.setType(confEvent.getEventTypeAbbv()); String lastDate = null, lastTime = null, lastRoom = null; for (MultiMeeting mm : Event.getMultiMeetings(events.get(confEvent))) { String date = getDateFormat().format(mm.getMeetings().first().getMeetingDate()) + (mm.getMeetings().size() == 1 ? "" : " - " + getDateFormat().format(mm.getMeetings().last().getMeetingDate())); if (lastDate == null) { conflict.setDate(date); } else if (lastDate.equals(date)) { conflict.setDate(conflict.getDate() + "<br>"); } else { conflict.setDate(conflict.getDate() + "<br>" + date); } lastDate = date; String time = mm.getDays(CONSTANTS.days(), CONSTANTS.shortDays()) + " " + (mm.getMeetings().first().isAllDay() ? "All Day" : mm.getMeetings().first().startTime() + " - " + mm.getMeetings().first().stopTime()); if (lastTime == null) { conflict.setTime(time); } else if (lastTime.equals(time)) { conflict.setTime(conflict.getTime() + "<br>"); } else { conflict.setTime(conflict.getTime() + "<br>" + time); } lastTime = time; String room = (mm.getMeetings().first().getLocation() == null ? "" : mm.getMeetings().first().getLocation().getLabel()); if (lastRoom == null) { conflict.setRoom(room); } else if (lastRoom.equals(room)) { conflict.setRoom(conflict.getRoom() + "<br>"); } else { conflict.setRoom(conflict.getRoom() + "<br>" + room); } lastRoom = room; } enrl.addConflict(conflict); } } converted.add(enrl); } ClassAssignmentInterface.ClassAssignment c = enrl.getCourse().addClassAssignment(); c.setClassId(enrollment.getClazz().getUniqueId()); c.setSection(enrollment.getClazz().getClassSuffix(enrollment.getCourseOffering())); if (c.getSection() == null) c.setSection(enrollment.getClazz().getSectionNumberString()); c.setClassNumber(enrollment.getClazz().getSectionNumberString()); c.setSubpart(enrollment.getClazz().getSchedulingSubpart().getItypeDesc()); } return converted; }
public static void computeConflicts( Map<Long, List<Meeting>> conflicts, MeetingInterface meeting, RelatedObjectInterface relatedObject, Long eventId) { org.hibernate.Session hibSession = EventDAO.getInstance().getSession(); switch (relatedObject.getType()) { case Class: // class events for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, ClassEvent e1 inner join e1.meetings m1, StudentClassEnrollment s2" + " where s2.clazz.uniqueId = :classId and e1.clazz = s1.clazz and s1.student = s2.student" + " and m1.meetingDate = :meetingDate and m1.startPeriod < :stopPeriod and :startPeriod < m1.stopPeriod") .setDate("meetingDate", meeting.getMeetingDate()) .setInteger("startPeriod", meeting.getStartSlot()) .setInteger("stopPeriod", meeting.getEndSlot()) .setLong("classId", relatedObject.getUniqueId()) .list()) { Long studentId = (Long) o[0]; Meeting conflictingMeeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(conflictingMeeting); } // exam events for (int t1 = 0; t1 < ExamOwner.sOwnerTypes.length; t1++) { for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, ExamEvent e1 inner join e1.meetings m1 inner join e1.exam.owners o1, StudentClassEnrollment s2" + " where s2.clazz.uniqueId = :classId and s1.student = s2.student" + where(t1, 1) + " and m1.meetingDate = :meetingDate and m1.startPeriod < :stopPeriod and :startPeriod < m1.stopPeriod") .setDate("meetingDate", meeting.getMeetingDate()) .setInteger("startPeriod", meeting.getStartSlot()) .setInteger("stopPeriod", meeting.getEndSlot()) .setLong("classId", relatedObject.getUniqueId()) .list()) { Long studentId = (Long) o[0]; Meeting conflictingMeeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(conflictingMeeting); } } // course events for (int t1 = 0; t1 < ExamOwner.sOwnerTypes.length; t1++) { for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, CourseEvent e1 inner join e1.meetings m1 inner join e1.relatedCourses o1, StudentClassEnrollment s2" + " where s2.clazz.uniqueId = :classId and e1.uniqueId != :eventId and s1.student = s2.student" + where(t1, 1) + " and m1.meetingDate = :meetingDate and m1.startPeriod < :stopPeriod and :startPeriod < m1.stopPeriod and e1.reqAttendance = true and m1.approvalStatus = 1") .setDate("meetingDate", meeting.getMeetingDate()) .setInteger("startPeriod", meeting.getStartSlot()) .setInteger("stopPeriod", meeting.getEndSlot()) .setLong("classId", relatedObject.getUniqueId()) .setLong("eventId", eventId == null ? -1 : eventId) .list()) { Long studentId = (Long) o[0]; Meeting conflictingMeeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(conflictingMeeting); } } break; case Config: // class events for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, ClassEvent e1 inner join e1.meetings m1, StudentClassEnrollment s2" + " where s2.clazz.schedulingSubpart.instrOfferingConfig.uniqueId = :configId and e1.clazz = s1.clazz and s1.student = s2.student" + " and m1.meetingDate = :meetingDate and m1.startPeriod < :stopPeriod and :startPeriod < m1.stopPeriod") .setDate("meetingDate", meeting.getMeetingDate()) .setInteger("startPeriod", meeting.getStartSlot()) .setInteger("stopPeriod", meeting.getEndSlot()) .setLong("configId", relatedObject.getUniqueId()) .list()) { Long studentId = (Long) o[0]; Meeting conflictingMeeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(conflictingMeeting); } // exam events for (int t1 = 0; t1 < ExamOwner.sOwnerTypes.length; t1++) { for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, ExamEvent e1 inner join e1.meetings m1 inner join e1.exam.owners o1, StudentClassEnrollment s2" + " where s2.clazz.schedulingSubpart.instrOfferingConfig.uniqueId = :configId and s1.student = s2.student" + where(t1, 1) + " and m1.meetingDate = :meetingDate and m1.startPeriod < :stopPeriod and :startPeriod < m1.stopPeriod") .setDate("meetingDate", meeting.getMeetingDate()) .setInteger("startPeriod", meeting.getStartSlot()) .setInteger("stopPeriod", meeting.getEndSlot()) .setLong("configId", relatedObject.getUniqueId()) .list()) { Long studentId = (Long) o[0]; Meeting conflictingMeeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(conflictingMeeting); } } // course events for (int t1 = 0; t1 < ExamOwner.sOwnerTypes.length; t1++) { for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, CourseEvent e1 inner join e1.meetings m1 inner join e1.relatedCourses o1, StudentClassEnrollment s2" + " where s2.clazz.schedulingSubpart.instrOfferingConfig.uniqueId = :configId and e1.uniqueId != :eventId and s1.student = s2.student" + where(t1, 1) + " and m1.meetingDate = :meetingDate and m1.startPeriod < :stopPeriod and :startPeriod < m1.stopPeriod and e1.reqAttendance = true and m1.approvalStatus = 1") .setDate("meetingDate", meeting.getMeetingDate()) .setInteger("startPeriod", meeting.getStartSlot()) .setInteger("stopPeriod", meeting.getEndSlot()) .setLong("configId", relatedObject.getUniqueId()) .setLong("eventId", eventId == null ? -1 : eventId) .list()) { Long studentId = (Long) o[0]; Meeting conflictingMeeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(conflictingMeeting); } } break; case Course: // class events for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, ClassEvent e1 inner join e1.meetings m1, StudentClassEnrollment s2" + " where s2.courseOffering.uniqueId = :courseId and e1.clazz = s1.clazz and s1.student = s2.student" + " and m1.meetingDate = :meetingDate and m1.startPeriod < :stopPeriod and :startPeriod < m1.stopPeriod") .setDate("meetingDate", meeting.getMeetingDate()) .setInteger("startPeriod", meeting.getStartSlot()) .setInteger("stopPeriod", meeting.getEndSlot()) .setLong("courseId", relatedObject.getUniqueId()) .list()) { Long studentId = (Long) o[0]; Meeting conflictingMeeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(conflictingMeeting); } // exam events for (int t1 = 0; t1 < ExamOwner.sOwnerTypes.length; t1++) { for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, ExamEvent e1 inner join e1.meetings m1 inner join e1.exam.owners o1, StudentClassEnrollment s2" + " where s2.courseOffering.uniqueId = :courseId and s1.student = s2.student" + where(t1, 1) + " and m1.meetingDate = :meetingDate and m1.startPeriod < :stopPeriod and :startPeriod < m1.stopPeriod") .setDate("meetingDate", meeting.getMeetingDate()) .setInteger("startPeriod", meeting.getStartSlot()) .setInteger("stopPeriod", meeting.getEndSlot()) .setLong("courseId", relatedObject.getUniqueId()) .list()) { Long studentId = (Long) o[0]; Meeting conflictingMeeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(conflictingMeeting); } } // course events for (int t1 = 0; t1 < ExamOwner.sOwnerTypes.length; t1++) { for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, CourseEvent e1 inner join e1.meetings m1 inner join e1.relatedCourses o1, StudentClassEnrollment s2" + " where s2.courseOffering.uniqueId = :courseId and e1.uniqueId != :eventId and s1.student = s2.student" + where(t1, 1) + " and m1.meetingDate = :meetingDate and m1.startPeriod < :stopPeriod and :startPeriod < m1.stopPeriod and e1.reqAttendance = true and m1.approvalStatus = 1") .setDate("meetingDate", meeting.getMeetingDate()) .setInteger("startPeriod", meeting.getStartSlot()) .setInteger("stopPeriod", meeting.getEndSlot()) .setLong("courseId", relatedObject.getUniqueId()) .setLong("eventId", eventId == null ? -1 : eventId) .list()) { Long studentId = (Long) o[0]; Meeting conflictingMeeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(conflictingMeeting); } } break; case Offering: // class events for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, ClassEvent e1 inner join e1.meetings m1, StudentClassEnrollment s2" + " where s2.courseOffering.instructionalOffering.uniqueId = :offeringId and e1.clazz = s1.clazz and s1.student = s2.student" + " and m1.meetingDate = :meetingDate and m1.startPeriod < :stopPeriod and :startPeriod < m1.stopPeriod") .setDate("meetingDate", meeting.getMeetingDate()) .setInteger("startPeriod", meeting.getStartSlot()) .setInteger("stopPeriod", meeting.getEndSlot()) .setLong("offeringId", relatedObject.getUniqueId()) .list()) { Long studentId = (Long) o[0]; Meeting conflictingMeeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(conflictingMeeting); } // exam events for (int t1 = 0; t1 < ExamOwner.sOwnerTypes.length; t1++) { for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, ExamEvent e1 inner join e1.meetings m1 inner join e1.exam.owners o1, StudentClassEnrollment s2" + " where s2.courseOffering.instructionalOffering.uniqueId = :offeringId and s1.student = s2.student" + where(t1, 1) + " and m1.meetingDate = :meetingDate and m1.startPeriod < :stopPeriod and :startPeriod < m1.stopPeriod") .setDate("meetingDate", meeting.getMeetingDate()) .setInteger("startPeriod", meeting.getStartSlot()) .setInteger("stopPeriod", meeting.getEndSlot()) .setLong("offeringId", relatedObject.getUniqueId()) .list()) { Long studentId = (Long) o[0]; Meeting conflictingMeeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(conflictingMeeting); } } // course events for (int t1 = 0; t1 < ExamOwner.sOwnerTypes.length; t1++) { for (Object[] o : (List<Object[]>) hibSession .createQuery( "select s1.student.uniqueId, m1" + " from StudentClassEnrollment s1, CourseEvent e1 inner join e1.meetings m1 inner join e1.relatedCourses o1, StudentClassEnrollment s2" + " where s2.courseOffering.instructionalOffering.uniqueId = :offeringId and e1.uniqueId != :eventId and s1.student = s2.student" + where(t1, 1) + " and m1.meetingDate = :meetingDate and m1.startPeriod < :stopPeriod and :startPeriod < m1.stopPeriod and e1.reqAttendance = true and m1.approvalStatus = 1") .setDate("meetingDate", meeting.getMeetingDate()) .setInteger("startPeriod", meeting.getStartSlot()) .setInteger("stopPeriod", meeting.getEndSlot()) .setLong("offeringId", relatedObject.getUniqueId()) .setLong("eventId", eventId == null ? -1 : eventId) .list()) { Long studentId = (Long) o[0]; Meeting conflictingMeeting = (Meeting) o[1]; List<Meeting> meetings = conflicts.get(studentId); if (meetings == null) { meetings = new ArrayList<Meeting>(); conflicts.put(studentId, meetings); } meetings.add(conflictingMeeting); } } break; } }