Skip to content

Commit 77588e7

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

File tree

4 files changed

+65
-54
lines changed

4 files changed

+65
-54
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: 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)