@@ -185,16 +185,19 @@ public boolean hasConflicts(Long offeringId) {
185185 }
186186 }
187187
188+ Date [] bounds = DatePattern .getBounds (offering .getSessionId ());
189+ boolean changePast = ApplicationProperty .ClassAssignmentChangePastMeetings .isTrue ();
190+ boolean ignorePast = ApplicationProperty .ClassAssignmentIgnorePastMeetings .isTrue ();
191+ Calendar cal = Calendar .getInstance (Locale .US );
192+ cal .setTime (new Date ());
193+ cal .set (Calendar .HOUR_OF_DAY , 0 );
194+ cal .set (Calendar .MINUTE , 0 );
195+ cal .set (Calendar .SECOND , 0 );
196+ cal .set (Calendar .MILLISECOND , 0 );
197+ Date today = cal .getTime ();
198+
188199 if (RoomAvailability .getInstance () != null && RoomAvailability .getInstance () instanceof DefaultRoomAvailabilityService ) {
189- boolean changePast = ApplicationProperty .ClassAssignmentChangePastMeetings .isTrue ();
190- boolean ignorePast = ApplicationProperty .ClassAssignmentIgnorePastMeetings .isTrue ();
191200 if (!changePast || ignorePast ) {
192- Calendar cal = Calendar .getInstance (Localization .getJavaLocale ());
193- cal .set (Calendar .HOUR_OF_DAY , 0 );
194- cal .set (Calendar .MINUTE , 0 );
195- cal .set (Calendar .SECOND , 0 );
196- cal .set (Calendar .MILLISECOND , 0 );
197- Date today = cal .getTime ();
198201 return MeetingDAO .getInstance ().getSession ().createQuery (
199202 "select count(mx) from ClassEvent e inner join e.meetings m, Meeting mx inner join mx.event ex " +
200203 "where e.clazz.schedulingSubpart.instrOfferingConfig.instructionalOffering.uniqueId = :offeringId and type(ex) != ClassEvent and m.approvalStatus = 1 and mx.approvalStatus = 1 and " +
@@ -210,16 +213,6 @@ public boolean hasConflicts(Long offeringId) {
210213 ).setParameter ("offeringId" , offeringId ).setCacheable (true ).uniqueResult ().intValue () > 0 ;
211214 }
212215 } else if (RoomAvailability .getInstance () != null ) {
213- Date [] bounds = DatePattern .getBounds (offering .getSessionId ());
214- boolean changePast = ApplicationProperty .ClassAssignmentChangePastMeetings .isTrue ();
215- boolean ignorePast = ApplicationProperty .ClassAssignmentIgnorePastMeetings .isTrue ();
216- Calendar cal = Calendar .getInstance (Locale .US );
217- cal .setTime (new Date ());
218- cal .set (Calendar .HOUR_OF_DAY , 0 );
219- cal .set (Calendar .MINUTE , 0 );
220- cal .set (Calendar .SECOND , 0 );
221- cal .set (Calendar .MILLISECOND , 0 );
222- Date today = cal .getTime ();
223216 for (InstrOfferingConfig config : offering .getInstrOfferingConfigs ())
224217 for (SchedulingSubpart subpart : config .getSchedulingSubparts ())
225218 for (Class_ clazz : subpart .getClasses ()) {
@@ -252,6 +245,54 @@ public boolean hasConflicts(Long offeringId) {
252245 }
253246 }
254247
248+ for (InstrOfferingConfig config : offering .getInstrOfferingConfigs ())
249+ for (SchedulingSubpart subpart : config .getSchedulingSubparts ())
250+ for (Class_ clazz : subpart .getClasses ()) {
251+ if (clazz .isCancelled () || !clazz .hasLeadInstructor ()) continue ;
252+ if (!clazz .hasLeadInstructorWithUnavailabilities () && !ApplicationProperty .RoomAvailabilityIncludeInstructors .isTrue ()) continue ;
253+ Assignment assignment = getAssignment (clazz );
254+ if (assignment == null ) continue ;
255+ ClassTimeInfo period = new ClassTimeInfo (assignment );
256+ for (ClassInstructor ci : clazz .getClassInstructors ()) {
257+ if (!ci .getLead ()) continue ;
258+ if (RoomAvailability .getInstance () != null ) {
259+ Collection <TimeBlock > times = RoomAvailability .getInstance ().getInstructorAvailability (
260+ ci .getInstructor ().getUniqueId (),
261+ bounds [0 ], bounds [1 ],
262+ RoomAvailabilityInterface .sClassType );
263+ if (times != null && !times .isEmpty ()) {
264+ Collection <TimeBlock > timesToCheck = null ;
265+ if (!changePast || ignorePast ) {
266+ timesToCheck = new Vector ();
267+ for (TimeBlock time : times ) {
268+ if (!time .getEndTime ().before (today ))
269+ timesToCheck .add (time );
270+ }
271+ } else {
272+ timesToCheck = times ;
273+ }
274+ if (period .overlaps (timesToCheck ) != null ) return true ;
275+ }
276+ }
277+ if (ci .getInstructor ().hasUnavailabilities ()) {
278+ Collection <TimeBlock > times = ci .getInstructor ().listUnavailableDays ();
279+ if (times != null && !times .isEmpty ()) {
280+ Collection <TimeBlock > timesToCheck = null ;
281+ if (!changePast || ignorePast ) {
282+ timesToCheck = new Vector ();
283+ for (TimeBlock time : times ) {
284+ if (!time .getEndTime ().before (today ))
285+ timesToCheck .add (time );
286+ }
287+ } else {
288+ timesToCheck = times ;
289+ }
290+ if (period .overlaps (timesToCheck ) != null ) return true ;
291+ }
292+ }
293+ }
294+ }
295+
255296 return false ;
256297 }
257298
@@ -348,6 +389,7 @@ public Set<TimeBlock> getConflictingTimeBlocks(Long classId) {
348389 Class_ clazz = Class_DAO .getInstance ().get (classId );
349390 if (clazz == null || clazz .isCancelled ()) return null ;
350391 Set <TimeBlock > conflicts = new TreeSet <TimeBlock >(new TimeBlockComparator ());
392+ boolean defaultRoomAvailability = (RoomAvailability .getInstance () != null && RoomAvailability .getInstance () instanceof DefaultRoomAvailabilityService );
351393
352394 Assignment assignment = getAssignment (clazz );
353395 Set <Long > ignorePermIds = new HashSet <Long >();
@@ -367,6 +409,7 @@ public Set<TimeBlock> getConflictingTimeBlocks(Long classId) {
367409 for (Location room : assignment .getRooms ()) {
368410 if (room .isIgnoreRoomCheck ()) {
369411 ignorePermIds .add (room .getPermanentId ());
412+ } else if (defaultRoomAvailability ) {
370413 } else {
371414 Collection <TimeBlock > times = RoomAvailability .getInstance ().getRoomAvailability (
372415 room .getUniqueId (),
@@ -391,7 +434,64 @@ public Set<TimeBlock> getConflictingTimeBlocks(Long classId) {
391434 }
392435 }
393436
394- if (RoomAvailability .getInstance () != null && RoomAvailability .getInstance () instanceof DefaultRoomAvailabilityService ) {
437+ if (assignment != null && clazz .hasLeadInstructor () &&
438+ (clazz .hasLeadInstructorWithUnavailabilities () || ApplicationProperty .RoomAvailabilityIncludeInstructors .isTrue ())) {
439+ Date [] bounds = DatePattern .getBounds (clazz .getSessionId ());
440+ boolean changePast = ApplicationProperty .ClassAssignmentChangePastMeetings .isTrue ();
441+ boolean ignorePast = ApplicationProperty .ClassAssignmentIgnorePastMeetings .isTrue ();
442+ Calendar cal = Calendar .getInstance (Locale .US );
443+ cal .setTime (new Date ());
444+ cal .set (Calendar .HOUR_OF_DAY , 0 );
445+ cal .set (Calendar .MINUTE , 0 );
446+ cal .set (Calendar .SECOND , 0 );
447+ cal .set (Calendar .MILLISECOND , 0 );
448+ Date today = cal .getTime ();
449+ ClassTimeInfo period = new ClassTimeInfo (assignment );
450+ for (ClassInstructor ci : clazz .getClassInstructors ()) {
451+ if (!ci .getLead ()) continue ;
452+ if (RoomAvailability .getInstance () != null ) {
453+ Collection <TimeBlock > times = RoomAvailability .getInstance ().getInstructorAvailability (
454+ ci .getInstructor ().getUniqueId (),
455+ bounds [0 ], bounds [1 ],
456+ RoomAvailabilityInterface .sClassType );
457+ if (times != null && !times .isEmpty ()) {
458+ Collection <TimeBlock > timesToCheck = null ;
459+ if (!changePast || ignorePast ) {
460+ timesToCheck = new Vector ();
461+ for (TimeBlock time : times ) {
462+ if (!time .getEndTime ().before (today ))
463+ timesToCheck .add (time );
464+ }
465+ } else {
466+ timesToCheck = times ;
467+ }
468+ List <TimeBlock > overlaps = period .allOverlaps (timesToCheck );
469+ if (overlaps != null )
470+ conflicts .addAll (overlaps );
471+ }
472+ }
473+ if (ci .getInstructor ().hasUnavailabilities ()) {
474+ Collection <TimeBlock > times = ci .getInstructor ().listUnavailableDays ();
475+ if (times != null && !times .isEmpty ()) {
476+ Collection <TimeBlock > timesToCheck = null ;
477+ if (!changePast || ignorePast ) {
478+ timesToCheck = new Vector ();
479+ for (TimeBlock time : times ) {
480+ if (!time .getEndTime ().before (today ))
481+ timesToCheck .add (time );
482+ }
483+ } else {
484+ timesToCheck = times ;
485+ }
486+ List <TimeBlock > overlaps = period .allOverlaps (timesToCheck );
487+ if (overlaps != null )
488+ conflicts .addAll (overlaps );
489+ }
490+ }
491+ }
492+ }
493+
494+ if (defaultRoomAvailability ) {
395495 EventDateMapping .Class2EventDateMap class2eventDateMap = EventDateMapping .getMapping (clazz .getManagingDept ().getSessionId ());
396496 boolean changePast = ApplicationProperty .ClassAssignmentChangePastMeetings .isTrue ();
397497 boolean ignorePast = ApplicationProperty .ClassAssignmentIgnorePastMeetings .isTrue ();
0 commit comments