Skip to content

Commit

Permalink
add instructor support call type (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaroldwong authored Jan 15, 2025
1 parent 24956ba commit 6ecbbd4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface InstructorSupportPreferenceService {
*/
List<Long> updatePriorities(List<Long> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,7 +45,7 @@ public List<Long> updatePriorities(List<Long> 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);
Expand All @@ -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());
}
Expand All @@ -83,37 +85,44 @@ public Long delete(Long instructorSupportPreferenceId) {
}

private void recalculatePriorities(Long sectionGroupId, Long instructorId) {
List<String> appointmentTypes = List.of("teachingAssistant", "reader");

List<InstructorSupportPreference> instructorPreferences = this.instructorSupportPreferenceRepository.findByInstructorIdAndSectionGroupId(instructorId, sectionGroupId);

List<InstructorSupportPreference> processedPreferences = new ArrayList<>();
for (String appointmentType : appointmentTypes) {
List<InstructorSupportPreference> 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<InstructorSupportPreference> 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<InstructorSupportPreference> preferences, long id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `InstructorSupportPreferences` ADD COLUMN `AppointmentType` VARCHAR(20) NULL;

0 comments on commit 6ecbbd4

Please sign in to comment.