Skip to content

Commit 01cf3e6

Browse files
committed
SAK-50233: Try catch and I18n issues
1 parent 7fdb126 commit 01cf3e6

File tree

4 files changed

+65
-65
lines changed

4 files changed

+65
-65
lines changed

assignment/api/src/resources/assignment_es.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ settings.access.checkFailure=Comprobaci\u00f3n fallida, no hay respuesta del ser
11671167

11681168
selected.group=Grupo seleccionado
11691169
selected.groups=Grupo(s) seleccionado(s)
1170-
selected.groups.without.gradebook = Has seleccionado grupos sin gradebook existente, por favor revisa la configuraci�n.
1170+
selected.groups.without.gradebook = Has seleccionado grupos sin gradebook existente, por favor revisa la configuraci\u00f3n.
11711171

11721172
submission.inline=Respuesta enviada
11731173
grade.type.unknown=Tipo de nota desconocido

gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,9 @@ else if (!this.businessService.isUserAbleToEditAssessments(siteId)) {
239239

240240
add(new CloseOnESCBehavior(bulkEditItemsWindow));
241241

242-
243-
244242
this.exportRubricWindow = new GbModalWindow("exportRubricWindow");
245243
this.form.add(this.exportRubricWindow);
246244

247-
248245
// first get any settings data from the session
249246
final GradebookUiSettings settings = getUiSettings();
250247

gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/panels/ExportRubricPanel.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.File;
1919
import java.io.FileOutputStream;
20+
import java.io.IOException;
2021
import java.time.Duration;
2122
import java.util.HashMap;
2223
import java.util.List;
@@ -114,37 +115,38 @@ protected File load() {
114115
private File buildFile() {
115116
final String[] userIds = receivedParams.get("userIds").asText().split(",");
116117

117-
File tempFile;
118+
if (rubric == null) {
119+
return null;
120+
}
118121

119122
try {
120-
if (rubric != null) {
121-
Long rubricId = rubric.getId();
122-
tempFile = File.createTempFile("tempZip", ".zip");
123-
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(tempFile));
123+
Long rubricId = rubric.getId();
124+
File tempFile = File.createTempFile("tempZip", ".zip");
125+
126+
try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(tempFile))) {
124127
for (String userId : userIds) {
125-
String evaluatedItemId = rubricsService.getRubricEvaluationObjectId(gradebookAssignmentId, userId, toolId, currentSiteId);
128+
String evaluatedItemId = rubricsService.getRubricEvaluationObjectId(
129+
gradebookAssignmentId, userId, toolId, currentSiteId);
126130
String name = userDirectoryService.getUser(userId).getEid();
127-
128-
Assignment assignment = businessService.getAssignment(currentGradebookUid, currentSiteId, Long.parseLong(gradebookAssignmentId));
129-
131+
Assignment assignment = businessService.getAssignment(
132+
currentGradebookUid, currentSiteId, Long.parseLong(gradebookAssignmentId));
130133
String title = assignment.getName();
131-
byte[] pdf = rubricsService.createPdf(currentSiteId, rubricId, toolId, gradebookAssignmentId, evaluatedItemId);
132-
final ZipEntry zipEntryPdf = new ZipEntry(name + "_" + title + ".pdf");
134+
byte[] pdf = rubricsService.createPdf(
135+
currentSiteId, rubricId, toolId, gradebookAssignmentId, evaluatedItemId);
133136

137+
final ZipEntry zipEntryPdf = new ZipEntry(name + "_" + title + ".pdf");
134138
out.putNextEntry(zipEntryPdf);
135139
out.write(pdf);
136140
out.closeEntry();
137141
}
142+
} // ZipOutputStream is automatically closed here
143+
144+
return tempFile;
138145

139-
out.finish();
140-
out.flush();
141-
out.close();
142-
return tempFile;
143-
}
144146
} catch (final Exception e) {
145-
log.error(e.toString(), e);
147+
log.error("Error occurred while building zip file: " + e.toString(), e);
148+
return null;
146149
}
147-
return null;
148150
}
149151

150152
}

samigo/samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/evaluation/ExportRubrics.java

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323

2424
import java.io.ByteArrayOutputStream;
2525
import java.io.File;
26+
import java.io.IOException;
2627
import java.util.List;
2728
import java.util.Optional;
29+
import java.util.stream.Collectors;
2830
import java.util.zip.ZipEntry;
2931
import java.util.zip.ZipOutputStream;
3032

@@ -60,51 +62,50 @@ public class ExportRubrics implements ActionListener {
6062
* Standard process action method.
6163
* @param ae ActionEvent
6264
* @throws AbortProcessingException
63-
*/
65+
*/
6466
public void processAction(ActionEvent ae) throws AbortProcessingException {
65-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
66-
67-
try {
68-
ZipOutputStream out = new ZipOutputStream(baos);
69-
70-
QuestionScoresBean bean = (QuestionScoresBean) ContextUtil.lookupBean("questionScores");
71-
TotalScoresBean tBean = (TotalScoresBean) ContextUtil.lookupBean("totalScores");
72-
String templateFilename = rb.getString("question") + "_" + bean.getItemName();
73-
String toolId = "sakai.samigo";
74-
List<AgentResults> agents = (List<AgentResults>) bean.getAgents();
75-
76-
for (AgentResults ar : agents) {
77-
String itemId = "pub." + bean.getPublishedId() + "." + ContextUtil.lookupParam("itemId");
78-
User user = userDirectoryService.getUserByEid(ar.getAgentEid());
79-
80-
Optional<ToolItemRubricAssociation> optAssociation = associationRepository.findByToolIdAndItemId(toolId, itemId);
81-
long rubricId = optAssociation.isPresent()? optAssociation.get().getRubric().getId() : 0l;
82-
83-
String evaluatedItemId = rubricsService.getRubricEvaluationObjectId(itemId, user.getId(), toolId, AgentFacade.getCurrentSiteId());
84-
byte[] pdf = rubricsService.createPdf(AgentFacade.getCurrentSiteId(), rubricId, toolId, itemId, evaluatedItemId);
85-
final ZipEntry zipEntryPdf = new ZipEntry(user.getEid() + "_" + templateFilename + ".pdf");
86-
87-
out.putNextEntry(zipEntryPdf);
88-
out.write(pdf);
89-
out.closeEntry();
90-
}
91-
92-
out.finish();
93-
out.close();
94-
95-
FacesContext faces = FacesContext.getCurrentInstance();
96-
HttpServletResponse response = (HttpServletResponse)faces.getExternalContext().getResponse();
97-
String fileName = tBean.getAssessmentName().replaceAll(" ", "_") + "_" + templateFilename;
98-
99-
response.reset(); // Eliminate the added-on stuff
100-
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "_" + rb.getString("rubrics") + ".zip\"");
101-
response.setContentType("application/zip");
102-
response.setContentLength(baos.size());
103-
104-
baos.writeTo(response.getOutputStream());
105-
faces.responseComplete();
67+
QuestionScoresBean bean = (QuestionScoresBean) ContextUtil.lookupBean("questionScores");
68+
TotalScoresBean tBean = (TotalScoresBean) ContextUtil.lookupBean("totalScores");
69+
String templateFilename = rb.getString("question") + "_" + bean.getItemName();
70+
String toolId = "sakai.samigo";
71+
72+
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
73+
ZipOutputStream out = new ZipOutputStream(baos)) {
74+
List<AgentResults> agents = (List<AgentResults>) bean.getAgents();
75+
List<User> users = userDirectoryService.getUsersByEids(agents.stream()
76+
.map(AgentResults::getAgentEid)
77+
.collect(Collectors.toList()));
78+
79+
for (User user : users) {
80+
String itemId = "pub." + bean.getPublishedId() + "." + ContextUtil.lookupParam("itemId");
81+
Optional<ToolItemRubricAssociation> optAssociation = associationRepository.findByToolIdAndItemId(toolId, itemId);
82+
long rubricId = optAssociation.isPresent() ? optAssociation.get().getRubric().getId() : 0L;
83+
String evaluatedItemId = rubricsService.getRubricEvaluationObjectId(itemId, user.getId(), toolId, AgentFacade.getCurrentSiteId());
84+
byte[] pdf = rubricsService.createPdf(AgentFacade.getCurrentSiteId(), rubricId, toolId, itemId, evaluatedItemId);
85+
final ZipEntry zipEntryPdf = new ZipEntry(user.getEid() + "_" + templateFilename + ".pdf");
86+
out.putNextEntry(zipEntryPdf);
87+
out.write(pdf);
88+
out.closeEntry();
89+
}
90+
91+
out.finish();
92+
93+
FacesContext faces = FacesContext.getCurrentInstance();
94+
HttpServletResponse response = (HttpServletResponse)faces.getExternalContext().getResponse();
95+
String fileName = tBean.getAssessmentName().replaceAll(" ", "_") + "_" + templateFilename;
96+
97+
response.reset();
98+
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "_" + rb.getString("rubrics") + ".zip\"");
99+
response.setContentType("application/zip");
100+
response.setContentLength(baos.size());
101+
102+
try (var outputStream = response.getOutputStream()) {
103+
baos.writeTo(outputStream);
104+
}
105+
106+
faces.responseComplete();
106107
} catch (Exception e) {
107-
log.error(e.toString(), e);
108+
log.error("Error exporting rubrics", e);
108109
}
109110
}
110111
}

0 commit comments

Comments
 (0)