Skip to content

Commit d29895a

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

File tree

4 files changed

+66
-33
lines changed

4 files changed

+66
-33
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 & 7 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,13 +115,14 @@ protected File load() {
114115
private File buildFile() {
115116
final String[] userIds = receivedParams.get("userIds").asText().split(",");
116117

117-
File tempFile;
118+
File tempFile = null;
119+
ZipOutputStream out = null;
118120

119121
try {
120122
if (rubric != null) {
121123
Long rubricId = rubric.getId();
122124
tempFile = File.createTempFile("tempZip", ".zip");
123-
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(tempFile));
125+
out = new ZipOutputStream(new FileOutputStream(tempFile));
124126
for (String userId : userIds) {
125127
String evaluatedItemId = rubricsService.getRubricEvaluationObjectId(gradebookAssignmentId, userId, toolId, currentSiteId);
126128
String name = userDirectoryService.getUser(userId).getEid();
@@ -135,14 +137,25 @@ private File buildFile() {
135137
out.write(pdf);
136138
out.closeEntry();
137139
}
138-
139-
out.finish();
140-
out.flush();
141-
out.close();
142-
return tempFile;
143140
}
144141
} catch (final Exception e) {
145142
log.error(e.toString(), e);
143+
} finally {
144+
if (out != null) {
145+
try {
146+
out.finish();
147+
out.flush();
148+
} catch (IOException e) {
149+
log.error("Error ocurred while finish ZipOutputStream: " + e.toString(), e);
150+
}
151+
try {
152+
out.close();
153+
} catch (IOException e) {
154+
log.error("Error ocurred while closing ZipOutputStream: " + e.toString(), e);
155+
}
156+
157+
return tempFile;
158+
}
146159
}
147160
return null;
148161
}

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

Lines changed: 45 additions & 22 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

@@ -64,18 +66,23 @@ public class ExportRubrics implements ActionListener {
6466
public void processAction(ActionEvent ae) throws AbortProcessingException {
6567
ByteArrayOutputStream baos = new ByteArrayOutputStream();
6668

69+
QuestionScoresBean bean = (QuestionScoresBean) ContextUtil.lookupBean("questionScores");
70+
TotalScoresBean tBean = (TotalScoresBean) ContextUtil.lookupBean("totalScores");
71+
String templateFilename = rb.getString("question") + "_" + bean.getItemName();
72+
String toolId = "sakai.samigo";
73+
74+
ZipOutputStream out = null;
75+
6776
try {
68-
ZipOutputStream out = new ZipOutputStream(baos);
77+
out = new ZipOutputStream(baos);
6978

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";
7479
List<AgentResults> agents = (List<AgentResults>) bean.getAgents();
80+
List<User> users = userDirectoryService.getUsersByEids(agents.stream()
81+
.map(AgentResults::getAgentEid)
82+
.collect(Collectors.toList()));
7583

76-
for (AgentResults ar : agents) {
84+
for (User user : users) {
7785
String itemId = "pub." + bean.getPublishedId() + "." + ContextUtil.lookupParam("itemId");
78-
User user = userDirectoryService.getUserByEid(ar.getAgentEid());
7986

8087
Optional<ToolItemRubricAssociation> optAssociation = associationRepository.findByToolIdAndItemId(toolId, itemId);
8188
long rubricId = optAssociation.isPresent()? optAssociation.get().getRubric().getId() : 0l;
@@ -88,23 +95,39 @@ public void processAction(ActionEvent ae) throws AbortProcessingException {
8895
out.write(pdf);
8996
out.closeEntry();
9097
}
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();
10698
} catch (Exception e) {
10799
log.error(e.toString(), e);
100+
} finally {
101+
if (out != null) {
102+
try {
103+
out.finish();
104+
out.flush();
105+
} catch (IOException e) {
106+
log.error("Error ocurred while finish ZipOutputStream: " + e.toString(), e);
107+
}
108+
try {
109+
out.close();
110+
} catch (IOException e) {
111+
log.error("Error ocurred while closing ZipOutputStream: " + e.toString(), e);
112+
}
113+
114+
FacesContext faces = FacesContext.getCurrentInstance();
115+
HttpServletResponse response = (HttpServletResponse)faces.getExternalContext().getResponse();
116+
String fileName = tBean.getAssessmentName().replaceAll(" ", "_") + "_" + templateFilename;
117+
118+
response.reset(); // Eliminate the added-on stuff
119+
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "_" + rb.getString("rubrics") + ".zip\"");
120+
response.setContentType("application/zip");
121+
response.setContentLength(baos.size());
122+
123+
try {
124+
baos.writeTo(response.getOutputStream());
125+
} catch (IOException e) {
126+
log.error("Error ocurred while writing ByteArrayOutputStream: " + e.toString(), e);
127+
}
128+
129+
faces.responseComplete();
130+
}
108131
}
109132
}
110133
}

0 commit comments

Comments
 (0)