Skip to content

Commit

Permalink
SAK-46121 - Postem: PostemSakaiService is a singleton and should not …
Browse files Browse the repository at this point in the history
…contain variables (sakaiproject#9691)
  • Loading branch information
Miguel Pellicer authored Sep 1, 2021
1 parent 2e4e7e8 commit 96b758b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@
@Controller
public class ColumnsController {

protected ArrayList students;
protected Gradebook currentGradebook;
protected TreeMap studentMap;

@Autowired
private PostemSakaiService postemSakaiService;

Expand All @@ -83,22 +79,17 @@ public class ColumnsController {
@GetMapping(value = {"/gradebook_view/{gradebookId}"})
public String getViewGradebook(@PathVariable("gradebookId") Long gradebookId, Model model) {
log.debug("getViewGradebook");

currentGradebook = postemSakaiService.getGradebookById2(gradebookId);
students = new ArrayList(currentGradebook.getStudents());

model.addAttribute("visible", Boolean.toString(postemSakaiService.checkAccess()));
Gradebook currentGradebook = postemSakaiService.getGradebookByIdWithHeadingsAndStudents(gradebookId);
model.addAttribute("visible", Boolean.toString(postemSakaiService.canUpdateSite()));
model.addAttribute("currentGradebook", currentGradebook);
model.addAttribute("studentsList", students);
model.addAttribute("studentsList", new ArrayList<>(currentGradebook.getStudents()));
return PostemToolConstants.GRADEBOOK_VIEW;
}

@GetMapping(value = {"/student_grades_view/{gradebookId}"})
public String getStudentGradeView(@PathVariable("gradebookId") Long gradebookId, Model model) {
log.debug("getStudentGradeView");

currentGradebook = postemSakaiService.getGradebookById2(gradebookId);

Gradebook currentGradebook = postemSakaiService.getGradebookByIdWithHeadingsAndStudents(gradebookId);
String userId = sessionManager.getCurrentSessionUserId();
String userEid = null;
if (userId != null) {
Expand All @@ -112,6 +103,7 @@ public String getStudentGradeView(@PathVariable("gradebookId") Long gradebookId,
StudentGrades studentGrades = null;
if (userEid != null) {
studentGrades = postemSakaiService.getStudentByGBAndUsername(currentGradebook, userEid);
postemSakaiService.registerStudentAccess(studentGrades);
}

final Locale locale = StringUtils.isNotBlank(userId) ? preferencesService.getLocale(userId) : Locale.getDefault();
Expand All @@ -121,7 +113,7 @@ public String getStudentGradeView(@PathVariable("gradebookId") Long gradebookId,
model.addAttribute("literalErrorMessage", literalErrorMessage);
}

model.addAttribute("visible", Boolean.toString(postemSakaiService.checkAccess()));
model.addAttribute("visible", Boolean.toString(postemSakaiService.canUpdateSite()));
model.addAttribute("currentGradebook", currentGradebook);
model.addAttribute("student", studentGrades);
return PostemToolConstants.STUDENT_GRADE_VIEW;
Expand All @@ -131,9 +123,8 @@ public String getStudentGradeView(@PathVariable("gradebookId") Long gradebookId,
public String getViewStudent(@PathVariable("gradebookId") Long gradebookId, Model model) {
log.debug("getViewStudent");

studentMap = postemSakaiService.processGradebookView(gradebookId);

model.addAttribute("visible", Boolean.toString(postemSakaiService.checkAccess()));
TreeMap<String, String> studentMap = postemSakaiService.processGradebookView(gradebookId);
model.addAttribute("visible", Boolean.toString(postemSakaiService.canUpdateSite()));
model.addAttribute("studentMap", studentMap);
model.addAttribute("gradebookId", gradebookId);
return PostemToolConstants.STUDENT_VIEW;
Expand All @@ -143,8 +134,8 @@ public String getViewStudent(@PathVariable("gradebookId") Long gradebookId, Mode
public String getViewStudentResult(@PathVariable("gradebookId") Long gradebookId, @PathVariable("student") String selectedStudent, Model model) {
log.debug("getViewStudentResult");

studentMap = postemSakaiService.processGradebookView(gradebookId);
currentGradebook = postemSakaiService.getGradebookById2(gradebookId);
TreeMap<String, String> studentMap = postemSakaiService.processGradebookView(gradebookId);
Gradebook currentGradebook = postemSakaiService.getGradebookByIdWithHeadingsAndStudents(gradebookId);
StudentGrades selStudent = null;
String lastSelected = "";

Expand All @@ -156,7 +147,7 @@ public String getViewStudentResult(@PathVariable("gradebookId") Long gradebookId
}
}

model.addAttribute("visible", Boolean.toString(postemSakaiService.checkAccess()));
model.addAttribute("visible", Boolean.toString(postemSakaiService.canUpdateSite()));
model.addAttribute("lastSelected", lastSelected);
model.addAttribute("selStudent", selStudent);
model.addAttribute("studentMap", studentMap);
Expand All @@ -169,9 +160,9 @@ public String getViewStudentResult(@PathVariable("gradebookId") Long gradebookId
public String getDeleteConfirm(@PathVariable("gradebookId") Long gradebookId, Model model) {
log.debug("getDeleteConfirm");

currentGradebook = postemSakaiService.getGradebookById2(gradebookId);
Gradebook currentGradebook = postemSakaiService.getGradebookByIdWithHeadingsAndStudents(gradebookId);

model.addAttribute("visible", Boolean.toString(postemSakaiService.checkAccess()));
model.addAttribute("visible", Boolean.toString(postemSakaiService.canUpdateSite()));
model.addAttribute("currentGradebook", currentGradebook);
return PostemToolConstants.DELETE_CONFIRM;
}
Expand All @@ -186,7 +177,7 @@ public String processDelete(@PathVariable("gradebookId") Long gradebookId, Model
return PostemToolConstants.PERMISSION_ERROR;
}

model.addAttribute("visible", Boolean.toString(postemSakaiService.checkAccess()));
model.addAttribute("visible", Boolean.toString(postemSakaiService.canUpdateSite()));
return PostemToolConstants.REDIRECT_MAIN_TEMPLATE;
}

Expand All @@ -198,7 +189,7 @@ public ResponseEntity<byte[]> processCsvDownload(@PathVariable("gradebookId") Lo
if (null == csv) {
return ResponseEntity.noContent().build();
}
Gradebook currentGradebook = postemSakaiService.getGradebookById2(gradebookId);
Gradebook currentGradebook = postemSakaiService.getGradebookByIdWithHeadingsAndStudents(gradebookId);
String fileName = "postem_" + currentGradebook.getTitle() + ".csv";
MediaType mediaType = MediaTypeUtils.getMediaTypeForFileName(context, fileName);

Expand All @@ -216,9 +207,9 @@ public ResponseEntity<byte[]> processCsvDownload(@PathVariable("gradebookId") Lo
public String getGradebookUpdate(@PathVariable("gradebookId") Long gradebookId, Model model) {
log.debug("getGradebookUpdate");

currentGradebook = postemSakaiService.getGradebookById2(gradebookId);
Gradebook currentGradebook = postemSakaiService.getGradebookByIdWithHeadingsAndStudents(gradebookId);

model.addAttribute("visible", Boolean.toString(postemSakaiService.checkAccess()));
model.addAttribute("visible", Boolean.toString(postemSakaiService.canUpdateSite()));
String fileReference = currentGradebook.getFileReference();
String partFileReference = "";
if (null != fileReference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String sortByTitle(@PathVariable("ascendingTitle") boolean ascendingTitle
model.addAttribute("ascendingLastMod", PostemToolConstants.POSTEM_FALSE_CONSTANT);
model.addAttribute("ascendingReleased", PostemToolConstants.POSTEM_FALSE_CONSTANT);

String visible = Boolean.toString(postemSakaiService.checkAccess());
String visible = Boolean.toString(postemSakaiService.canUpdateSite());
model.addAttribute("visible", visible);

return PostemToolConstants.INDEX_TEMPLATE;
Expand All @@ -74,7 +74,7 @@ public String sortByCreator(@PathVariable("ascendingCreator") boolean ascendingC
model.addAttribute("ascendingLastMod", PostemToolConstants.POSTEM_FALSE_CONSTANT);
model.addAttribute("ascendingReleased", PostemToolConstants.POSTEM_FALSE_CONSTANT);

String visible = Boolean.toString(postemSakaiService.checkAccess());
String visible = Boolean.toString(postemSakaiService.canUpdateSite());
model.addAttribute("visible", visible);
return PostemToolConstants.INDEX_TEMPLATE;
}
Expand All @@ -94,7 +94,7 @@ public String sortByModifiedBy(@PathVariable("ascendingModifiedBy") boolean asce
model.addAttribute("ascendingLastMod", PostemToolConstants.POSTEM_FALSE_CONSTANT);
model.addAttribute("ascendingReleased", PostemToolConstants.POSTEM_FALSE_CONSTANT);

String visible = Boolean.toString(postemSakaiService.checkAccess());
String visible = Boolean.toString(postemSakaiService.canUpdateSite());
model.addAttribute("visible", visible);
return PostemToolConstants.INDEX_TEMPLATE;
}
Expand All @@ -114,7 +114,7 @@ public String sortByLastModified(@PathVariable("ascendingLastMod") boolean ascen
model.addAttribute("ascendingModifiedBy", PostemToolConstants.POSTEM_FALSE_CONSTANT);
model.addAttribute("ascendingReleased", PostemToolConstants.POSTEM_FALSE_CONSTANT);

String visible = Boolean.toString(postemSakaiService.checkAccess());
String visible = Boolean.toString(postemSakaiService.canUpdateSite());
model.addAttribute("visible", visible);

return PostemToolConstants.INDEX_TEMPLATE;
Expand All @@ -135,7 +135,7 @@ public String sortByReleased(@PathVariable("ascendingReleased") boolean ascendin
model.addAttribute("ascendingModifiedBy", PostemToolConstants.POSTEM_FALSE_CONSTANT);
model.addAttribute("ascendingLastMod", PostemToolConstants.POSTEM_FALSE_CONSTANT);

model.addAttribute("visible", Boolean.toString(postemSakaiService.checkAccess()));
model.addAttribute("visible", Boolean.toString(postemSakaiService.canUpdateSite()));

return PostemToolConstants.INDEX_TEMPLATE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public String showIndex(Model model, HttpServletRequest request, HttpServletResp
model.addAttribute("ascendingModifiedBy", PostemToolConstants.POSTEM_FALSE_CONSTANT);
model.addAttribute("ascendingLastMod", PostemToolConstants.POSTEM_FALSE_CONSTANT);
model.addAttribute("ascendingReleased", PostemToolConstants.POSTEM_FALSE_CONSTANT);
model.addAttribute("visible", Boolean.toString(postemSakaiService.checkAccess()));
model.addAttribute("visible", Boolean.toString(postemSakaiService.canUpdateSite()));

ToolSession toolSession = sessionManager.getCurrentToolSession();
toolSession.setAttribute("currentGradebook", null);
Expand All @@ -100,7 +100,7 @@ public String addItem(@ModelAttribute("gradebookForm") GradebookForm gradebookFo
gradebookForm.setReleased(currentGradebook.getReleased());
}

model.addAttribute("visible", Boolean.toString(postemSakaiService.checkAccess()));
model.addAttribute("visible", Boolean.toString(postemSakaiService.canUpdateSite()));
model.addAttribute("gradebookForm", gradebookForm);
model.addAttribute("fileReference", gradebookForm.getFileReference());
String uploadMax = serverConfigurationService.getString(ContentHostingService.SAK_PROP_MAX_UPLOAD_FILE_SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public String createGradebook(@ModelAttribute("gradebookForm") GradebookForm gra

String userId = sessionManager.getCurrentSessionUserId();
boolean isGradebookUpdate = gradebookForm.isGradebookUpdate();
model.addAttribute("visible", Boolean.toString(postemSakaiService.checkAccess()));
model.addAttribute("visible", Boolean.toString(postemSakaiService.canUpdateSite()));
final Locale locale = preferencesService.getLocale(userId);
ToolSession toolSession = sessionManager.getCurrentToolSession();
Gradebook sessionGradebook = (Gradebook) toolSession.getAttribute("currentGradebook");
Expand Down
Loading

0 comments on commit 96b758b

Please sign in to comment.