forked from sakaiproject/sakai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 65 additions & 5 deletions
70
tool/src/java/org/sakaiproject/gradebookng/tool/pages/ImportExportPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,86 @@ | ||
package org.sakaiproject.gradebookng.tool.pages; | ||
|
||
|
||
import org.apache.log4j.Logger; | ||
import org.sakaiproject.gradebookng.tool.panels.GradeImportUploadStep; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.wicket.markup.html.link.DownloadLink; | ||
import org.apache.wicket.markup.html.link.ResourceLink; | ||
import org.apache.wicket.model.LoadableDetachableModel; | ||
import org.apache.wicket.request.resource.ByteArrayResource; | ||
import org.apache.wicket.util.time.Duration; | ||
import org.sakaiproject.service.gradebook.shared.Assignment; | ||
import org.sakaiproject.user.api.User; | ||
|
||
import java.io.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Import Export page | ||
* | ||
* | ||
* @author Steve Swinsburg ([email protected]) | ||
* | ||
*/ | ||
public class ImportExportPage extends BasePage { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private static final Logger log = Logger.getLogger(ImportExportPage.class); | ||
|
||
|
||
|
||
public ImportExportPage() { | ||
add(new GradeImportUploadStep("wizard")); | ||
|
||
//get list of assignments. this allows us to build the columns and then fetch the grades for each student for each assignment from the map | ||
final List<Assignment> assignments = this.businessService.getGradebookAssignments(); | ||
final List<User> users = this.businessService.getGradeableUsers(); | ||
|
||
add(new DownloadLink("downloadBlankTemplate", new LoadableDetachableModel<File>() { | ||
|
||
@Override | ||
protected File load() { | ||
File tempFile; | ||
try { | ||
//TODO - add the site name to the file? | ||
tempFile = File.createTempFile("gradebookTemplate", ".csv"); | ||
// FileOutputStream fos = new FileOutputStream(); | ||
FileWriter fw = new FileWriter(tempFile); | ||
//Create csv header | ||
List<String> header = new ArrayList<String>(); | ||
header.add("studentId"); | ||
header.add("studentName"); | ||
|
||
for (Assignment assignment : assignments) { | ||
header.add(assignment.getName()); | ||
} | ||
String headerStr = StringUtils.join(header, ","); | ||
fw.append(headerStr + "\n"); | ||
|
||
List<String> line = new ArrayList<String>(); | ||
|
||
for (User user : users) { | ||
line.add(wrapText(user.getEid())); | ||
line.add(wrapText(user.getSortName())); | ||
String lineStr = StringUtils.join(line, ","); | ||
fw.append(lineStr + "\n"); | ||
} | ||
|
||
|
||
fw.close(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return tempFile; | ||
// return new File(new ByteArrayResource("", null)); | ||
} | ||
}).setCacheDuration(Duration.NONE).setDeleteAfterDownload(true)); | ||
|
||
|
||
|
||
|
||
} | ||
|
||
private String wrapText(String input) { | ||
return "\"" + input + "\""; | ||
} | ||
|
||
|
||
|