From 6ecbbd4c11ee2c016fb1dbf9e2e1352d2e2dd5b7 Mon Sep 17 00:00:00 2001 From: Jarold Wong Date: Tue, 14 Jan 2025 21:13:24 -0800 Subject: [PATCH] add instructor support call type (#392) --- ...ionalSupportInstructorFormsController.java | 6 +- .../entities/InstructorSupportPreference.java | 9 +++ .../InstructorSupportPreferenceService.java | 2 +- ...JpaInstructorSupportPreferenceService.java | 55 +++++++++++-------- ...ntType_To_InstructorSupportPreferences.sql | 1 + 5 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 src/main/resources/db/migration/V256__Add_AppointmentType_To_InstructorSupportPreferences.sql diff --git a/src/main/java/edu/ucdavis/dss/ipa/api/components/instructionalSupport/InstructionalSupportInstructorFormsController.java b/src/main/java/edu/ucdavis/dss/ipa/api/components/instructionalSupport/InstructionalSupportInstructorFormsController.java index d8e4db50a..db359d442 100644 --- a/src/main/java/edu/ucdavis/dss/ipa/api/components/instructionalSupport/InstructionalSupportInstructorFormsController.java +++ b/src/main/java/edu/ucdavis/dss/ipa/api/components/instructionalSupport/InstructionalSupportInstructorFormsController.java @@ -32,16 +32,16 @@ public InstructionalSupportCallInstructorFormView getInstructionalSupportCallIns return instructionalSupportViewFactory.createInstructorFormView(workgroupId, year, shortTermCode, instructor.getId()); } - @RequestMapping(value = "/api/instructionalSupportInstructorFormView/sectionGroups/{sectionGroupId}/supportStaff/{supportStaffId}", method = RequestMethod.POST, produces = "application/json") + @RequestMapping(value = "/api/instructionalSupportInstructorFormView/sectionGroups/{sectionGroupId}/supportStaff/{supportStaffId}/type/{appointmentType}", method = RequestMethod.POST, produces = "application/json") @ResponseBody - public InstructorSupportPreference addPreference(@PathVariable long sectionGroupId, @PathVariable long supportStaffId) { + public InstructorSupportPreference addPreference(@PathVariable long sectionGroupId, @PathVariable long supportStaffId, @PathVariable String appointmentType) { Long workgroupId = sectionGroupService.getOneById(sectionGroupId).getCourse().getSchedule().getWorkgroup().getId(); authorizer.hasWorkgroupRoles(workgroupId, "academicPlanner", "reviewer", "instructor", "studentPhd", "studentMasters", "instructionalSupport"); User currentUser = userService.getOneByLoginId(authorization.getLoginId()); Instructor instructor = instructorService.getOneByLoginId(currentUser.getLoginId()); - return instructorSupportPreferenceService.create(supportStaffId, instructor.getId(), sectionGroupId); + return instructorSupportPreferenceService.create(supportStaffId, instructor.getId(), sectionGroupId, appointmentType); } @RequestMapping(value = "/api/instructionalSupportInstructorFormView/instructorSupportCallResponses/{instructorSupportCallResponseId}", method = RequestMethod.PUT, produces = "application/json") diff --git a/src/main/java/edu/ucdavis/dss/ipa/entities/InstructorSupportPreference.java b/src/main/java/edu/ucdavis/dss/ipa/entities/InstructorSupportPreference.java index 1a6881638..0e54dad1b 100644 --- a/src/main/java/edu/ucdavis/dss/ipa/entities/InstructorSupportPreference.java +++ b/src/main/java/edu/ucdavis/dss/ipa/entities/InstructorSupportPreference.java @@ -23,6 +23,7 @@ public class InstructorSupportPreference implements Serializable { private SupportStaff supportStaff; private Instructor instructor; private long priority; + private String appointmentType; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -109,4 +110,12 @@ public long getPriority() { public void setPriority(long priority) { this.priority = priority; } + + public String getAppointmentType() { + return appointmentType; + } + + public void setAppointmentType(String appointmentType) { + this.appointmentType = appointmentType; + } } \ No newline at end of file diff --git a/src/main/java/edu/ucdavis/dss/ipa/services/InstructorSupportPreferenceService.java b/src/main/java/edu/ucdavis/dss/ipa/services/InstructorSupportPreferenceService.java index 72cbcdfb8..567de9cb6 100644 --- a/src/main/java/edu/ucdavis/dss/ipa/services/InstructorSupportPreferenceService.java +++ b/src/main/java/edu/ucdavis/dss/ipa/services/InstructorSupportPreferenceService.java @@ -14,7 +14,7 @@ public interface InstructorSupportPreferenceService { */ List updatePriorities(List instructorInstructionalSupportPreferenceIds, long sectionGroupId); - InstructorSupportPreference create (long instructionalSupportStaffId, long instructorId, long sectionGroupId); + InstructorSupportPreference create (long instructionalSupportStaffId, long instructorId, long sectionGroupId, String appointmentType); Long delete(Long studentInstructionalSupportPreferenceId); diff --git a/src/main/java/edu/ucdavis/dss/ipa/services/jpa/JpaInstructorSupportPreferenceService.java b/src/main/java/edu/ucdavis/dss/ipa/services/jpa/JpaInstructorSupportPreferenceService.java index 265a220d5..0d76a0347 100644 --- a/src/main/java/edu/ucdavis/dss/ipa/services/jpa/JpaInstructorSupportPreferenceService.java +++ b/src/main/java/edu/ucdavis/dss/ipa/services/jpa/JpaInstructorSupportPreferenceService.java @@ -3,6 +3,7 @@ import edu.ucdavis.dss.ipa.entities.*; import edu.ucdavis.dss.ipa.repositories.InstructorSupportPreferenceRepository; import edu.ucdavis.dss.ipa.services.*; + import java.util.stream.Collectors; import org.springframework.stereotype.Service; import jakarta.inject.Inject; @@ -44,7 +45,7 @@ public List updatePriorities(List preferenceIds, long sectionGroupId } @Override - public InstructorSupportPreference create(long instructionalSupportStaffId, long instructorId, long sectionGroupId) { + public InstructorSupportPreference create(long instructionalSupportStaffId, long instructorId, long sectionGroupId, String appointmentType) { SupportStaff supportStaff = supportStaffService.findOneById(instructionalSupportStaffId); Instructor instructor = instructorService.getOneById(instructorId); SectionGroup sectionGroup = sectionGroupService.getOneById(sectionGroupId); @@ -53,13 +54,14 @@ public InstructorSupportPreference create(long instructionalSupportStaffId, long instructorSupportPreference.setSectionGroup(sectionGroup); instructorSupportPreference.setSupportStaff(supportStaff); instructorSupportPreference.setInstructor(instructor); + instructorSupportPreference.setAppointmentType(appointmentType); // Set priority arbitrarily to a ceiling, to ensure recalculation places it at the end. instructorSupportPreference.setPriority(999L); instructorSupportPreference = this.save(instructorSupportPreference); - this.recalculatePriorities(sectionGroup.getId(), instructor.getId()); + this.recalculatePriorities(sectionGroupId, instructorId); return this.findById(instructorSupportPreference.getId()); } @@ -83,37 +85,44 @@ public Long delete(Long instructorSupportPreferenceId) { } private void recalculatePriorities(Long sectionGroupId, Long instructorId) { + List appointmentTypes = List.of("teachingAssistant", "reader"); + List instructorPreferences = this.instructorSupportPreferenceRepository.findByInstructorIdAndSectionGroupId(instructorId, sectionGroupId); - List processedPreferences = new ArrayList<>(); + for (String appointmentType : appointmentTypes) { + List filteredPreferences = instructorPreferences.stream() + .filter(p -> p.getAppointmentType() == null || appointmentType.equals(p.getAppointmentType())) + .toList(); - // Assign each preference value - for (int priority = 1; priority <= instructorPreferences.size(); priority++) { + List processedPreferences = new ArrayList<>(); - // Find the preference with the lowest priority (that hasn't already been processed) - InstructorSupportPreference lowestPriorityPreference = null; + // Assign each preference value + for (int priority = 1; priority <= filteredPreferences.size(); priority++) { - for (InstructorSupportPreference preference : instructorPreferences) { - if (this.isInArray(processedPreferences, preference.getId())) { - continue; - } + // Find the preference with the lowest priority (that hasn't already been processed) + InstructorSupportPreference lowestPriorityPreference = null; - if (lowestPriorityPreference == null) { - lowestPriorityPreference = preference; - continue; - } + for (InstructorSupportPreference preference : filteredPreferences) { + if (this.isInArray(processedPreferences, preference.getId())) { + continue; + } - if (preference.getPriority() < lowestPriorityPreference.getPriority()) { - lowestPriorityPreference = preference; + if (lowestPriorityPreference == null) { + lowestPriorityPreference = preference; + continue; + } + + if (preference.getPriority() < lowestPriorityPreference.getPriority()) { + lowestPriorityPreference = preference; + } } - } - // Save the preference its new priority add it to the list of processed preferences - lowestPriorityPreference.setPriority(priority); - this.save(lowestPriorityPreference); - processedPreferences.add(lowestPriorityPreference); + // Save the preference its new priority add it to the list of processed preferences + lowestPriorityPreference.setPriority(priority); + this.save(lowestPriorityPreference); + processedPreferences.add(lowestPriorityPreference); + } } - } private boolean isInArray(List preferences, long id) { diff --git a/src/main/resources/db/migration/V256__Add_AppointmentType_To_InstructorSupportPreferences.sql b/src/main/resources/db/migration/V256__Add_AppointmentType_To_InstructorSupportPreferences.sql new file mode 100644 index 000000000..8cccea53b --- /dev/null +++ b/src/main/resources/db/migration/V256__Add_AppointmentType_To_InstructorSupportPreferences.sql @@ -0,0 +1 @@ +ALTER TABLE `InstructorSupportPreferences` ADD COLUMN `AppointmentType` VARCHAR(20) NULL;