List of usage examples for org.hibernate Query setDate
@Deprecated @SuppressWarnings("unchecked") default Query<R> setDate(String name, Date val)
From source file:org.sakaiproject.sitestats.impl.StatsManagerImpl.java
License:Educational Community License
public List<SiteActivity> getSiteActivityGrpByDate(final String siteId, final List<String> events, final Date iDate, final Date fDate) { if (siteId == null) { throw new IllegalArgumentException("Null siteId"); } else {/* w ww. j a v a 2 s .c o m*/ String iDateStr = ""; String fDateStr = ""; if (iDate != null) iDateStr = "and s.date >= :idate "; if (fDate != null) fDateStr = "and s.date < :fdate "; final String hql = "select s.siteId, sum(s.count),s.date " + "from SiteActivityImpl as s " + "where s.siteId = :siteid " + "and s.eventId in (:eventlist) " + iDateStr + fDateStr + "group by s.siteId, s.date"; HibernateCallback hcb = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query q = session.createQuery(hql); q.setFlushMode(FlushMode.NEVER); q.setString("siteid", siteId); if (events != null && events.size() > 0) q.setParameterList("eventlist", events); else q.setParameterList("eventlist", M_ers.getEventIds()); if (iDate != null) q.setDate("idate", iDate); if (fDate != null) { // adjust final date Calendar c = Calendar.getInstance(); c.setTime(fDate); c.add(Calendar.DAY_OF_YEAR, 1); Date fDate2 = c.getTime(); q.setDate("fdate", fDate2); } List<Object[]> records = q.list(); List<SiteActivity> results = new ArrayList<SiteActivity>(); if (records.size() > 0) { for (Iterator<Object[]> iter = records.iterator(); iter.hasNext();) { Object[] s = iter.next(); SiteActivity c = new SiteActivityImpl(); c.setSiteId((String) s[0]); c.setCount(((Long) s[1]).longValue()); Date recDate = (Date) s[2]; c.setDate(recDate); c.setEventId(null); results.add(c); } return results; } else return results; } }; return (List<SiteActivity>) getHibernateTemplate().execute(hcb); } }
From source file:org.sakaiproject.sitestats.impl.StatsManagerImpl.java
License:Educational Community License
public long getTotalSiteActivity(final String siteId, final List<String> events, final Date iDate, final Date fDate) { if (siteId == null) { throw new IllegalArgumentException("Null siteId"); } else {// www . jav a2 s . c o m String iDateStr = ""; String fDateStr = ""; if (iDate != null) iDateStr = "and ss.date >= :idate "; if (fDate != null) fDateStr = "and ss.date < :fdate "; final String hql = "select sum(ss.count) " + "from SiteActivityImpl as ss " + "where ss.eventId in (:eventlist) " + "and ss.siteId = :siteid " + iDateStr + fDateStr + "group by ss.siteId"; HibernateCallback hcb = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query q = session.createQuery(hql); q.setString("siteid", siteId); if (events != null && events.size() > 0) q.setParameterList("eventlist", events); else q.setParameterList("eventlist", M_ers.getEventIds()); if (iDate != null) q.setDate("idate", iDate); if (fDate != null) { // adjust final date Calendar c = Calendar.getInstance(); c.setTime(fDate); c.add(Calendar.DAY_OF_YEAR, 1); Date fDate2 = c.getTime(); q.setDate("fdate", fDate2); } List<Object[]> res = q.list(); if (res.size() > 0) return res.get(0); else return Long.valueOf(0); } }; return ((Long) getHibernateTemplate().execute(hcb)).longValue(); } }
From source file:org.sakaiproject.sitestats.impl.StatsUpdateManagerImpl.java
License:Educational Community License
private Map<UniqueVisitsKey, Integer> doGetSiteUniqueVisits(Session session, Map<UniqueVisitsKey, Integer> map) { Iterator<UniqueVisitsKey> i = map.keySet().iterator(); while (i.hasNext()) { UniqueVisitsKey key = i.next();/*from w ww.j av a 2 s.com*/ Query q = session.createQuery("select count(distinct s.userId) " + "from EventStatImpl as s " + "where s.siteId = :siteid " + "and s.eventId = 'pres.begin' " + "and s.date = :idate"); q.setString("siteid", key.siteId); q.setDate("idate", key.date); Integer uv = 1; try { uv = (Integer) q.uniqueResult(); } catch (ClassCastException ex) { uv = (int) ((Long) q.uniqueResult()).longValue(); } catch (HibernateException ex) { try { List visits = q.list(); if ((visits != null) && (visits.size() > 0)) { LOG.debug("More than 1 result when unique result expected.", ex); uv = (Integer) q.list().get(0); } else { LOG.debug("No result found", ex); uv = 1; } } catch (Exception e3) { uv = 1; } } catch (Exception ex2) { LOG.debug("Probably ddbb error when loading data at java object", ex2); } int uniqueVisits = uv == null ? 1 : uv.intValue(); map.put(key, Integer.valueOf((int) uniqueVisits)); } return map; }
From source file:org.sakaiproject.tool.assessment.facade.AssessmentGradingFacadeQueries.java
License:Educational Community License
public int getLateSubmissionsNumberByAgentId(final Long publishedAssessmentId, final String agentIdString, final Date dueDate) { final HibernateCallback hcb = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query q = session.createQuery( "from AssessmentGradingData a where a.publishedAssessmentId=? and a.agentId=? and a.forGrade=? and a.submittedDate>?"); q.setLong(0, publishedAssessmentId.longValue()); q.setString(1, agentIdString); q.setBoolean(2, true);/*from www.j ava 2s .c o m*/ q.setDate(3, dueDate); return q.list(); }; }; List assessmentGradings = getHibernateTemplate().executeFind(hcb); return assessmentGradings.size(); }
From source file:org.unitime.banner.model.dao.BannerResponseDAO.java
License:Apache License
public List find(Long sessionId, Date startDate, Date stopDate, String searchSubject, Set subjects, Long searchManager, Long searchDepartment, String searchCourseNumber, String searchCrn, String searchXlst, String searchMessage, int maxResults, boolean showHistory, boolean actionAudit, boolean actionUpdate, boolean actionDelete, boolean typeSuccess, boolean typeError, boolean typeWarning) throws LoggableException { List queueOuts = null;/*w w w .j a va 2s . co m*/ Transaction tx = null; try { tx = getSession().beginTransaction(); String whereHql = " where rp.termCode=:termCode "; org.hibernate.Session hibSession = new BannerResponseDAO().getSession(); BannerSession bs = BannerSession.findBannerSessionForSession(sessionId, hibSession); String joinHql = ""; if ((searchManager != null && searchManager > 0) || (searchDepartment != null && searchDepartment > 0)) { joinHql += " SubjectArea as sa " + " inner join sa.department as dept "; whereHql += " and sa.session = :sessionId " + "and sa.subjectAreaAbbreviation = rp.subjectCode "; if (searchDepartment != null && searchDepartment > 0) { whereHql += " and dept.uniqueId = :departmentId "; } } if (searchManager != null && searchManager > 0) { joinHql += " inner join dept.timetableManagers as mgr "; whereHql += " and mgr.uniqueId=:managerId"; } if (startDate != null) { whereHql += " and rp.activityDate >= :startDate"; } String fromHql = " from "; if (joinHql.length() > 0) { fromHql += joinHql + ","; } fromHql += " BannerResponse as rp"; if (stopDate != null) { whereHql += " and rp.activityDate <= :stopDate"; } if (searchSubject != null && searchSubject != "") { whereHql += " and upper(rp.subjectCode) = upper(:searchSubject) "; } else { int i = 1; for (Iterator it = subjects.iterator(); it.hasNext();) { SubjectArea s = (SubjectArea) it.next(); if (i == 1) { whereHql += " and ( rp.subjectCode in ( "; } else { whereHql += " , "; } whereHql += " '" + s.getSubjectAreaAbbreviation() + "'"; i++; } if (i > 1) { whereHql += "))"; } } if (searchCourseNumber != null && searchCourseNumber != "") { whereHql += " and upper(rp.courseNumber) = upper(:searchCourseNumber) "; } if (searchCrn != null && searchCrn != "") { whereHql += " and rp.crn = upper(:searchCrn) "; } if (searchXlst != null && searchXlst != "") { whereHql += " and upper(rp.xlstGroup) like upper(:searchXlst) "; } if ((actionUpdate || actionAudit || actionDelete) && !(actionUpdate && actionAudit && actionDelete)) { whereHql += " and rp.action in ("; if (actionUpdate) { whereHql += "'UPDATE'"; } if (actionAudit) { if (!whereHql.endsWith("(")) whereHql += ","; whereHql += "'AUDIT'"; } if (actionDelete) { if (!whereHql.endsWith("(")) whereHql += ","; whereHql += "'DELETE'"; } whereHql += ") "; } if ((typeError || typeSuccess || typeWarning) && !(typeError && typeSuccess && typeWarning)) { whereHql += " and rp.type in ("; if (typeError) { whereHql += "'ERROR'"; } if (typeSuccess) { if (!whereHql.endsWith("(")) whereHql += ","; whereHql += "'SUCCESS'"; } if (typeWarning) { if (!whereHql.endsWith("(")) whereHql += ","; whereHql += "'WARNING'"; } whereHql += ") "; } if (searchMessage != null && searchMessage != "") { whereHql += " and upper(rp.message) like upper(:searchMessage) "; } if (!showHistory) { whereHql += " and rp.queueId = (select max(queueId) from BannerResponse rp3 where rp3.termCode = rp.termCode and rp3.crn = rp.crn and ((rp3.xlstGroup is null and rp.xlstGroup is null) or (rp3.xlstGroup = rp.xlstGroup))) "; } String hql = "select rp " + fromHql + whereHql + " order by rp.activityDate desc, rp.sequenceNumber desc "; Query query = getSession().createQuery(hql); query.setString("termCode", bs.getBannerTermCode()); if (startDate != null) { query.setDate("startDate", startDate); } if (stopDate != null) { query.setDate("stopDate", stopDate); } if ((searchManager != null && searchManager > 0) || (searchDepartment != null && searchDepartment > 0)) { query.setLong("sessionId", sessionId); if (searchDepartment != null && searchDepartment > 0) { query.setLong("departmentId", searchDepartment); } } if (searchManager != null && searchManager > 0) { query.setLong("managerId", searchManager); } if (searchSubject != null && searchSubject != "") { query.setString("searchSubject", searchSubject); } if (searchCourseNumber != null && searchCourseNumber != "") { query.setString("searchCourseNumber", searchCourseNumber); } if (searchCrn != null && searchCrn != "") { query.setString("searchCrn", searchCrn); } if (searchXlst != null && searchXlst != "") { query.setString("searchXlst", searchXlst.replace("*", "%")); } if (searchMessage != null && searchMessage != "") { query.setString("searchMessage", searchMessage.replace('*', '%')); } if (maxResults < 0) maxResults = 0; if (maxResults > 0) { query.setMaxResults(maxResults); } query.setCacheable(false); queueOuts = query.list(); tx.commit(); } catch (HibernateException e) { tx.rollback(); throw new LoggableException(e); } finally { getSession().close(); } return queueOuts; }
From source file:org.unitime.colleague.model.dao.ColleagueResponseDAO.java
License:Apache License
public List find(Long sessionId, Date startDate, Date stopDate, String searchSubject, Set subjects, Long searchManager, Long searchDepartment, String searchCourseNumber, String searchColleagueId, String searchMessage, int maxResults, boolean showHistory, boolean actionAudit, boolean actionUpdate, boolean actionDelete, boolean typeSuccess, boolean typeError, boolean typeWarning) throws LoggableException { List queueOuts = null;//from w w w . ja v a2 s. c o m Transaction tx = null; try { tx = getSession().beginTransaction(); String whereHql = " where rp.termCode=:termCode "; org.hibernate.Session hibSession = new ColleagueResponseDAO().getSession(); ColleagueSession bs = ColleagueSession.findColleagueSessionForSession(sessionId, hibSession); String joinHql = ""; if ((searchManager != null && searchManager > 0) || (searchDepartment != null && searchDepartment > 0)) { joinHql += " SubjectArea as sa " + " inner join sa.department as dept "; whereHql += " and sa.session = :sessionId " + "and sa.subjectAreaAbbreviation = rp.subjectCode "; if (searchDepartment != null && searchDepartment > 0) { whereHql += " and dept.uniqueId = :departmentId "; } } if (searchManager != null && searchManager > 0) { joinHql += " inner join dept.timetableManagers as mgr "; whereHql += " and mgr.uniqueId=:managerId"; } if (startDate != null) { whereHql += " and rp.activityDate >= :startDate"; } String fromHql = " from "; if (joinHql.length() > 0) { fromHql += joinHql + ","; } fromHql += " ColleagueResponse as rp"; if (stopDate != null) { whereHql += " and rp.activityDate <= :stopDate"; } if (searchSubject != null && searchSubject != "") { whereHql += " and upper(rp.subjectCode) = upper(:searchSubject) "; } else { int i = 1; for (Iterator it = subjects.iterator(); it.hasNext();) { SubjectArea s = (SubjectArea) it.next(); if (i == 1) { whereHql += " and ( rp.subjectCode in ( "; } else { whereHql += " , "; } whereHql += " '" + s.getSubjectAreaAbbreviation() + "'"; i++; } if (i > 1) { whereHql += "))"; } } if (searchCourseNumber != null && searchCourseNumber != "") { whereHql += " and upper(rp.courseNumber) = upper(:searchCourseNumber) "; } if (searchColleagueId != null && searchColleagueId != "") { whereHql += " and rp.colleagueId = upper(:searchColleagueId) "; } if ((actionUpdate || actionAudit || actionDelete) && !(actionUpdate && actionAudit && actionDelete)) { whereHql += " and rp.action in ("; if (actionUpdate) { whereHql += "'UPDATE'"; } if (actionAudit) { if (!whereHql.endsWith("(")) whereHql += ","; whereHql += "'AUDIT'"; } if (actionDelete) { if (!whereHql.endsWith("(")) whereHql += ","; whereHql += "'DELETE'"; } whereHql += ") "; } if ((typeError || typeSuccess || typeWarning) && !(typeError && typeSuccess && typeWarning)) { whereHql += " and rp.type in ("; if (typeError) { whereHql += "'ERROR'"; } if (typeSuccess) { if (!whereHql.endsWith("(")) whereHql += ","; whereHql += "'SUCCESS'"; } if (typeWarning) { if (!whereHql.endsWith("(")) whereHql += ","; whereHql += "'WARNING'"; } whereHql += ") "; } if (searchMessage != null && searchMessage != "") { whereHql += " and upper(rp.message) like upper(:searchMessage) "; } if (!showHistory) { whereHql += " and rp.queueId = (select max(queueId) from ColleagueResponse rp3 where rp3.termCode = rp.termCode and rp3.colleagueId = rp.colleagueId) "; } String hql = "select rp " + fromHql + whereHql + " order by rp.activityDate desc, rp.sequenceNumber desc "; Query query = getSession().createQuery(hql); query.setString("termCode", bs.getColleagueTermCode()); if (startDate != null) { query.setDate("startDate", startDate); } if (stopDate != null) { query.setDate("stopDate", stopDate); } if ((searchManager != null && searchManager > 0) || (searchDepartment != null && searchDepartment > 0)) { query.setLong("sessionId", sessionId); if (searchDepartment != null && searchDepartment > 0) { query.setLong("departmentId", searchDepartment); } } if (searchManager != null && searchManager > 0) { query.setLong("managerId", searchManager); } if (searchSubject != null && searchSubject != "") { query.setString("searchSubject", searchSubject); } if (searchCourseNumber != null && searchCourseNumber != "") { query.setString("searchCourseNumber", searchCourseNumber); } if (searchColleagueId != null && searchColleagueId != "") { query.setString("searchColleagueId", searchColleagueId); } if (searchMessage != null && searchMessage != "") { query.setString("searchMessage", searchMessage.replace('*', '%')); } if (maxResults < 0) maxResults = 0; if (maxResults > 0) { query.setMaxResults(maxResults); } query.setCacheable(false); queueOuts = query.list(); tx.commit(); } catch (HibernateException e) { tx.rollback(); throw new LoggableException(e); } finally { getSession().close(); } return queueOuts; }
From source file:org.unitime.timetable.events.EventRoomAvailabilityBackend.java
License:Open Source License
@Override public EventRoomAvailabilityRpcResponse execute(EventRoomAvailabilityRpcRequest request, EventContext context) { EventRoomAvailabilityRpcResponse response = new EventRoomAvailabilityRpcResponse(); Session session = SessionDAO.getInstance().get(request.getSessionId()); String nameFormat = context.getUser().getProperty(UserProperty.NameFormat); if (request.hasDates() && request.hasLocations()) { for (int idx = 0; idx < request.getLocations().size(); idx += 1000) { String dates = ""; for (int i = 0; i < request.getDates().size(); i++) dates += (dates.isEmpty() ? "" : ",") + ":d" + i; String locations = ""; for (int i = idx; i + idx < request.getLocations().size() && i < 1000; i++) locations += (locations.isEmpty() ? "" : ",") + ":l" + i; Query query = EventDAO.getInstance().getSession().createQuery("select m from Meeting m, Location l " + "where m.startPeriod<:stopTime and m.stopPeriod>:startTime and m.approvalStatus <= 1 and " + "l.session.uniqueId = :sessionId and l.permanentId in (" + locations + ") and l.ignoreRoomCheck = false and " + "m.locationPermanentId = l.permanentId and m.meetingDate in (" + dates + ")"); query.setInteger("startTime", request.getStartSlot()); query.setInteger("stopTime", request.getEndSlot()); query.setLong("sessionId", request.getSessionId()); for (int i = 0; i < request.getDates().size(); i++) { Date date = CalendarUtils.dateOfYear2date(session.getSessionStartYear(), request.getDates().get(i)); query.setDate("d" + i, date); }/*from w ww .j a v a 2 s . c om*/ for (int i = idx; i + idx < request.getLocations().size() && i < 1000; i++) query.setLong("l" + i, request.getLocations().get(idx + i)); for (Meeting m : (List<Meeting>) query.list()) { MeetingConflictInterface conflict = new MeetingConflictInterface(); if (request.hasEventId() && m.getEvent().getUniqueId().equals(request.getEventId())) continue; conflict.setEventId(m.getEvent().getUniqueId()); conflict.setName(m.getEvent().getEventName()); conflict.setType(EventInterface.EventType.values()[m.getEvent().getEventType()]); conflict.setLimit(m.getEvent().getMaxCapacity()); if (m.getEvent().getSponsoringOrganization() != null) { SponsoringOrganizationInterface sponsor = new SponsoringOrganizationInterface(); sponsor.setEmail(m.getEvent().getSponsoringOrganization().getEmail()); sponsor.setName(m.getEvent().getSponsoringOrganization().getName()); sponsor.setUniqueId(m.getEvent().getSponsoringOrganization().getUniqueId()); conflict.setSponsor(sponsor); } if (Event.sEventTypeClass == m.getEvent().getEventType()) { ClassEvent ce = (m.getEvent() instanceof ClassEvent ? (ClassEvent) m.getEvent() : ClassEventDAO.getInstance().get(m.getEvent().getUniqueId())); Class_ clazz = ce.getClazz(); conflict.setEnrollment(clazz.getEnrollment()); if (clazz.getDisplayInstructor()) { for (ClassInstructor i : clazz.getClassInstructors()) { ContactInterface instructor = new ContactInterface(); instructor.setFirstName(i.getInstructor().getFirstName()); instructor.setMiddleName(i.getInstructor().getMiddleName()); instructor.setLastName(i.getInstructor().getLastName()); instructor.setAcademicTitle(i.getInstructor().getAcademicTitle()); instructor.setEmail(i.getInstructor().getEmail()); instructor.setFormattedName(i.getInstructor().getName(nameFormat)); conflict.addInstructor(instructor); } } } else if (Event.sEventTypeFinalExam == m.getEvent().getEventType() || Event.sEventTypeMidtermExam == m.getEvent().getEventType()) { ExamEvent xe = (m.getEvent() instanceof ExamEvent ? (ExamEvent) m.getEvent() : ExamEventDAO.getInstance().get(m.getEvent().getUniqueId())); conflict.setEnrollment(xe.getExam().countStudents()); for (DepartmentalInstructor i : xe.getExam().getInstructors()) { ContactInterface instructor = new ContactInterface(); instructor.setFirstName(i.getFirstName()); instructor.setMiddleName(i.getMiddleName()); instructor.setLastName(i.getLastName()); instructor.setAcademicTitle(i.getAcademicTitle()); instructor.setEmail(i.getEmail()); instructor.setFormattedName(i.getName(nameFormat)); conflict.addInstructor(instructor); } } else if (Event.sEventTypeCourse == m.getEvent().getEventType()) { CourseEvent ce = (m.getEvent() instanceof CourseEvent ? (CourseEvent) m.getEvent() : CourseEventDAO.getInstance().get(m.getEvent().getUniqueId())); int enrl = 0; for (RelatedCourseInfo owner : ce.getRelatedCourses()) { enrl += owner.countStudents(); } conflict.setEnrollment(enrl); } conflict.setId(m.getUniqueId()); conflict.setMeetingDate(m.getMeetingDate()); conflict.setDayOfYear( CalendarUtils.date2dayOfYear(session.getSessionStartYear(), m.getMeetingDate())); conflict.setStartOffset(m.getStartOffset() == null ? 0 : m.getStartOffset()); conflict.setEndOffset(m.getStopOffset() == null ? 0 : m.getStopOffset()); conflict.setStartSlot(m.getStartPeriod()); conflict.setEndSlot(m.getStopPeriod()); conflict.setApprovalDate(m.getApprovalDate()); conflict.setApprovalStatus(m.getApprovalStatus()); response.addOverlap( CalendarUtils.date2dayOfYear(session.getSessionStartYear(), m.getMeetingDate()), m.getLocationPermanentId(), conflict); } query = EventDAO.getInstance().getSession().createQuery( "from Location where session.uniqueId = :sessionId and permanentId in (" + locations + ")"); for (int i = idx; i + idx < request.getLocations().size() && i < 1000; i++) query.setLong("l" + i, request.getLocations().get(idx + i)); for (Location location : (List<Location>) query.setLong("sessionId", request.getSessionId()) .setCacheable(true).list()) { if (context.hasPermission(location, request.getEventType() == EventType.Unavailabile ? Right.EventLocationUnavailable : Right.EventLocation)) { Set<MeetingConflictInterface> conflicts = generateUnavailabilityMeetings(location, request.getDates(), request.getStartSlot(), request.getEndSlot()); if (conflicts != null && !conflicts.isEmpty()) for (MeetingConflictInterface conflict : conflicts) response.addOverlap(conflict.getDayOfYear(), location.getPermanentId(), conflict); } else { for (Integer date : request.getDates()) { MeetingConflictInterface conflict = new MeetingConflictInterface(); if (location == null || location.getEventDepartment() == null || !location.getEventDepartment().isAllowEvents()) conflict.setName(MESSAGES.conflictNotEventRoom(location.getLabel())); else if (request.getEventType() == EventType.Unavailabile) conflict.setName(MESSAGES.conflictCannotMakeUnavailable(location.getLabel())); else conflict.setName(MESSAGES.conflictRoomDenied(location.getLabel())); if (location.getEventDepartment() != null && location.getEventDepartment().isAllowEvents()) { String message = location.getEventMessage(); if (message != null && !message.isEmpty()) { conflict.setName(message); } } conflict.setType(EventInterface.EventType.Unavailabile); conflict.setMeetingDate( CalendarUtils.dateOfYear2date(session.getSessionStartYear(), date)); conflict.setDayOfYear(date); conflict.setStartOffset(0); conflict.setEndOffset(0); conflict.setStartSlot(0); conflict.setEndSlot(288); response.addOverlap(date, location.getPermanentId(), conflict); } } } } } if (request.hasMeetings()) { response.setMeetings(request.getMeetings()); for (MeetingInterface meeting : response.getMeetings()) { if (meeting.hasConflicts()) meeting.getConflicts().clear(); if (meeting.getMeetingDate() == null) { meeting.setMeetingDate( CalendarUtils.dateOfYear2date(session.getSessionStartYear(), meeting.getDayOfYear())); meeting.setDayOfWeek(Constants.getDayOfWeek(meeting.getMeetingDate())); } if (meeting.getApprovalStatus() == ApprovalStatus.Deleted || meeting.getApprovalStatus() == ApprovalStatus.Cancelled || meeting.getApprovalStatus() == ApprovalStatus.Rejected) continue; if (context.isPastOrOutside(meeting.getMeetingDate())) { MeetingConflictInterface conflict = new MeetingConflictInterface(); conflict.setName(MESSAGES.conflictPastOrOutside(session.getLabel())); conflict.setType(meeting.getId() == null ? EventInterface.EventType.Unavailabile : EventInterface.EventType.Message); conflict.setMeetingDate(meeting.getMeetingDate()); conflict.setDayOfYear(meeting.getDayOfYear()); conflict.setStartOffset(0); conflict.setEndOffset(0); conflict.setStartSlot(0); conflict.setEndSlot(288); conflict.setPast(true); meeting.addConflict(conflict); } if (!meeting.hasLocation()) continue; meeting.setCanApprove(context.hasPermission(meeting.getLocation().getId(), "Location", Right.EventLocationApprove)); Location location = LocationDAO.getInstance().get(meeting.getLocation().getId()); boolean available = true; if (location == null || !context.hasPermission(location, Right.EventLocation)) { MeetingConflictInterface conflict = new MeetingConflictInterface(); if (location == null || location.getEventDepartment() == null || !location.getEventDepartment().isAllowEvents()) conflict.setName(MESSAGES.conflictNotEventRoom(meeting.getLocationName())); else conflict.setName(MESSAGES.conflictRoomDenied(meeting.getLocationName())); if (location != null && location.getEventDepartment() != null && location.getEventDepartment().isAllowEvents()) { String message = location.getEventMessage(); if (message != null && !message.isEmpty()) { conflict.setName(message); } } conflict.setType(meeting.getId() == null ? EventInterface.EventType.Unavailabile : EventInterface.EventType.Message); conflict.setMeetingDate(meeting.getMeetingDate()); conflict.setDayOfYear(meeting.getDayOfYear()); conflict.setStartOffset(0); conflict.setEndOffset(0); conflict.setStartSlot(0); conflict.setEndSlot(288); meeting.addConflict(conflict); available = false; } else if (request.getEventType() == EventType.Unavailabile && !context.hasPermission(location, Right.EventLocationUnavailable)) { MeetingConflictInterface conflict = new MeetingConflictInterface(); if (location == null || location.getEventDepartment() == null || !location.getEventDepartment().isAllowEvents()) conflict.setName(MESSAGES.conflictNotEventRoom(meeting.getLocationName())); else conflict.setName(MESSAGES.conflictCannotMakeUnavailable(meeting.getLocationName())); conflict.setType(meeting.getId() == null ? EventInterface.EventType.Unavailabile : EventInterface.EventType.Message); conflict.setMeetingDate(meeting.getMeetingDate()); conflict.setDayOfYear(meeting.getDayOfYear()); conflict.setStartOffset(0); conflict.setEndOffset(0); conflict.setStartSlot(0); conflict.setEndSlot(288); meeting.addConflict(conflict); available = false; } if (!location.isIgnoreRoomCheck()) for (Meeting m : (List<Meeting>) EventDAO.getInstance().getSession() .createQuery("select m from Meeting m, Location l " + "where m.startPeriod < :stopTime and m.stopPeriod > :startTime and m.approvalStatus <= 1 and " + "m.locationPermanentId = l.permanentId and l.uniqueId = :locationdId and m.meetingDate = :meetingDate and m.uniqueId != :meetingId") .setInteger("startTime", meeting.getStartSlot()) .setInteger("stopTime", meeting.getEndSlot()) .setDate("meetingDate", meeting.getMeetingDate()) .setLong("locationdId", meeting.getLocation().getId()) .setLong("meetingId", meeting.getId() == null ? -1 : meeting.getId()).list()) { MeetingConflictInterface conflict = new MeetingConflictInterface(); if (request.hasEventId() && m.getEvent().getUniqueId().equals(request.getEventId())) continue; conflict.setEventId(m.getEvent().getUniqueId()); conflict.setName(m.getEvent().getEventName()); conflict.setType(EventInterface.EventType.values()[m.getEvent().getEventType()]); conflict.setId(m.getUniqueId()); conflict.setMeetingDate(m.getMeetingDate()); conflict.setDayOfYear(meeting.getDayOfYear()); conflict.setStartSlot(m.getStartPeriod()); conflict.setEndSlot(m.getStopPeriod()); conflict.setStartOffset(m.getStartOffset() == null ? 0 : m.getStartOffset()); conflict.setEndOffset(m.getStopOffset() == null ? 0 : m.getStopOffset()); conflict.setApprovalDate(m.getApprovalDate()); conflict.setApprovalStatus(m.getApprovalStatus()); meeting.addConflict(conflict); } if (location != null && location.getEventAvailability() != null && location.getEventAvailability() .length() == Constants.SLOTS_PER_DAY * Constants.DAY_CODES.length) { check: for (int slot = meeting.getStartSlot(); slot < meeting.getEndSlot(); slot++) { if (location.getEventAvailability() .charAt(meeting.getDayOfWeek() * Constants.SLOTS_PER_DAY + slot) == '1') { for (MeetingConflictInterface conflict : generateUnavailabilityMeetings(location, meeting)) meeting.addConflict(conflict); break check; } } } if (available) { if (location.getEventDepartment() == null || !location.getEventDepartment().isAllowEvents()) { // no event department MeetingConflictInterface conflict = new MeetingConflictInterface(); conflict.setName(MESSAGES.conflictNotEventRoom(meeting.getLocationName())); conflict.setType(EventInterface.EventType.Message); conflict.setMeetingDate(meeting.getMeetingDate()); conflict.setDayOfYear(meeting.getDayOfYear()); conflict.setStartOffset(0); conflict.setEndOffset(0); conflict.setStartSlot(0); conflict.setEndSlot(288); meeting.addConflict(conflict); } else { // has a message? String message = location.getEventMessage(); if (message != null && !message.isEmpty()) { MeetingConflictInterface conflict = new MeetingConflictInterface(); conflict.setName(message); conflict.setType(EventInterface.EventType.Message); conflict.setMeetingDate(meeting.getMeetingDate()); conflict.setDayOfYear(meeting.getDayOfYear()); conflict.setStartOffset(0); conflict.setEndOffset(0); conflict.setStartSlot(0); conflict.setEndSlot(288); meeting.addConflict(conflict); } } int tooEarly = ApplicationProperty.EventTooEarlySlot.intValue(); if (tooEarly >= 0 && ((meeting.getStartSlot() > 0 && meeting.getStartSlot() <= tooEarly) || (meeting.getStartSlot() == 0 && meeting.getEndSlot() <= tooEarly))) { MeetingConflictInterface conflict = new MeetingConflictInterface(); conflict.setName(MESSAGES.warnMeetingTooEarly(meeting.getAllocatedTime(CONSTANTS))); conflict.setType(EventInterface.EventType.Message); conflict.setMeetingDate(meeting.getMeetingDate()); conflict.setDayOfYear(meeting.getDayOfYear()); conflict.setStartOffset(0); conflict.setEndOffset(0); conflict.setStartSlot(0); conflict.setEndSlot(288); meeting.addConflict(conflict); } } } } return response; }
From source file:org.unitime.timetable.form.EventRoomAvailabilityForm.java
License:Open Source License
public Hashtable<Long, Hashtable<Date, TreeSet<Meeting>>> getOverlappingMeetings( Hashtable<Long, Location> locations, TreeSet<Date> meetingDates, int startTime, int stopTime) { // get meetings String locIds = ""; for (Long permId : locations.keySet()) { if (locIds.length() > 0) locIds += ","; locIds += permId;/*from w w w . jav a2 s.c om*/ } String dates = ""; for (int idx = 0; idx < meetingDates.size(); idx++) { if (dates.length() > 0) dates += ","; dates += ":md" + idx; } String query = "Select m from Meeting m where " + "m.startPeriod<:stopTime and " + "m.stopPeriod>:startTime and " + "m.locationPermanentId in (" + locIds + ") and " + "m.meetingDate in (" + dates + ")"; Query hibQuery = new MeetingDAO().getSession().createQuery(query); hibQuery.setInteger("startTime", getStartTime()); hibQuery.setInteger("stopTime", getStopTime()); int idx = 0; for (Date md : meetingDates) { hibQuery.setDate("md" + idx, md); idx++; } List<Meeting> meetings = (List<Meeting>) hibQuery.setCacheable(true).list(); // sort meetings by location and date Hashtable<Long, Hashtable<Date, TreeSet<Meeting>>> locationDateMeetings = new Hashtable<Long, Hashtable<Date, TreeSet<Meeting>>>(); for (Meeting meeting : meetings) { Hashtable<Date, TreeSet<Meeting>> dateMeetings = locationDateMeetings .get(meeting.getLocationPermanentId()); if (dateMeetings == null) { dateMeetings = new Hashtable(); locationDateMeetings.put(meeting.getLocationPermanentId(), dateMeetings); } TreeSet<Meeting> myMeetings = dateMeetings.get(new Date(meeting.getMeetingDate().getTime())); if (myMeetings == null) { myMeetings = new TreeSet(); dateMeetings.put(new Date(meeting.getMeetingDate().getTime()), myMeetings); } myMeetings.add(meeting); } return locationDateMeetings; }
From source file:org.unitime.timetable.model.Location.java
License:Open Source License
public static Hashtable<Long, Set<Long>> findClassLocationTable(Long sessionId, int startSlot, int length, Vector<Date> dates) { Hashtable<Long, Set<Long>> table = new Hashtable(); String datesStr = ""; for (int i = 0; i < dates.size(); i++) { if (i > 0) datesStr += ", "; datesStr += ":date" + i; }/*from w w w . j a va 2 s . com*/ Query q = LocationDAO.getInstance().getSession() .createQuery("select distinct r.uniqueId, e.clazz.uniqueId from " + "ClassEvent e inner join e.meetings m, Location r where " + "r.session.uniqueId=:sessionId and r.permanentId=m.locationPermanentId and " + // link Location r with Meeting m "m.stopPeriod>:startSlot and :endSlot>m.startPeriod and " + // meeting time within given time period "m.meetingDate in (" + datesStr + ")") .setLong("sessionId", sessionId).setInteger("startSlot", startSlot) .setInteger("endSlot", startSlot + length); for (int i = 0; i < dates.size(); i++) { q.setDate("date" + i, dates.elementAt(i)); } for (Iterator i = q.setCacheable(true).list().iterator(); i.hasNext();) { Object[] o = (Object[]) i.next(); Set<Long> ids = table.get((Long) o[0]); if (ids == null) { ids = new HashSet<Long>(); table.put((Long) o[0], ids); } ids.add((Long) o[1]); } return table; }
From source file:org.unitime.timetable.model.Location.java
License:Open Source License
public Set<Long> findClassLocationTable(int startSlot, int length, Vector<Date> dates) { String datesStr = ""; for (int i = 0; i < dates.size(); i++) { if (i > 0) datesStr += ", "; datesStr += ":date" + i; }/* ww w.j av a 2 s .com*/ Query q = LocationDAO.getInstance().getSession() .createQuery("select distinct e.clazz.uniqueId from " + "ClassEvent e inner join e.meetings m where " + "m.locationPermanentId=:permanentId and " + "m.stopPeriod>:startSlot and :endSlot>m.startPeriod and " + // meeting time within given time period "m.meetingDate in (" + datesStr + ")") // and date .setLong("permanentId", getPermanentId()).setInteger("startSlot", startSlot) .setInteger("endSlot", startSlot + length); for (int i = 0; i < dates.size(); i++) { q.setDate("date" + i, dates.elementAt(i)); } return new HashSet<Long>(q.setCacheable(true).list()); }