Skip to content

Commit

Permalink
Actually need to add the student grade info data to the list...duh!
Browse files Browse the repository at this point in the history
Need to convert the user's eid from the import file to a uuid that the service can actually use.
  • Loading branch information
maurercw committed Jun 18, 2015
1 parent c47f985 commit 3dbf9e7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ImportGradesHelper extends BaseImportHelper {
* @param is InputStream of the data to parse
* @return
*/
public static ImportedGradeWrapper parseCsv(InputStream is) {
public static ImportedGradeWrapper parseCsv(InputStream is, Map<String, String> userMap) {

//manually parse method so we can support arbitrary columns
CSVReader reader = new CSVReader(new InputStreamReader(is));
Expand All @@ -68,7 +68,7 @@ public static ImportedGradeWrapper parseCsv(InputStream is) {
mapping = mapHeaderRow(nextLine);
} else {
//map the fields into the object
list.add(mapLine(nextLine, mapping));
list.add(mapLine(nextLine, mapping, userMap));
}
lineCount++;
}
Expand Down Expand Up @@ -97,7 +97,7 @@ public static ImportedGradeWrapper parseCsv(InputStream is) {
* @param is InputStream of the data to parse
* @return
*/
public static ImportedGradeWrapper parseXls(InputStream is) {
public static ImportedGradeWrapper parseXls(InputStream is, Map<String, String> userMap) {

int lineCount = 0;
List<ImportedGrade> list = new ArrayList<ImportedGrade>();
Expand All @@ -115,7 +115,7 @@ public static ImportedGradeWrapper parseXls(InputStream is) {
mapping = mapHeaderRow(r);
} else {
//map the fields into the object
list.add(mapLine(r, mapping));
list.add(mapLine(r, mapping, userMap));
}
lineCount++;
}
Expand Down Expand Up @@ -193,7 +193,7 @@ private static boolean isGradeColumn(String headerValue) {
* @param mapping
* @return
*/
private static ImportedGrade mapLine(String[] line, Map<Integer,ImportColumn> mapping){
private static ImportedGrade mapLine(String[] line, Map<Integer,ImportColumn> mapping, Map<String, String> userMap){

ImportedGrade grade = new ImportedGrade();
ResourceProperties p = new BaseResourcePropertiesEdit();
Expand All @@ -212,7 +212,8 @@ private static ImportedGrade mapLine(String[] line, Map<Integer,ImportColumn> ma

//now check each of the main properties in turn to determine which one to set, otherwise set into props
if(StringUtils.equals(importColumn.getColumnTitle(), IMPORT_USER_ID)) {
grade.setStudentId(lineVal);
grade.setStudentEid(lineVal);
grade.setStudentUuid(userMap.get(lineVal));
} else if(StringUtils.equals(importColumn.getColumnTitle(), IMPORT_USER_NAME)) {
grade.setStudentName(lineVal);
} else if(ImportColumn.TYPE_ITEM_WITH_POINTS==importColumn.getType()) {
Expand Down Expand Up @@ -295,8 +296,10 @@ public static List<ProcessedGradeItem> processImportedGrades(ImportedGradeWrappe
ImportedGradeItem importedGradeItem = importedGrade.getGradeItemMap().get(assignmentName);
if (importedGradeItem != null) {
ProcessedGradeItemDetail processedGradeItemDetail = new ProcessedGradeItemDetail();
processedGradeItemDetail.setStudentId(importedGrade.getStudentId());
processedGradeItemDetail.setStudentEid(importedGrade.getStudentEid());
processedGradeItemDetail.setStudentUuid(importedGrade.getStudentUuid());
processedGradeItemDetail.setGrade(importedGradeItem.getGradeItemScore());
processedGradeItemDetails.add(processedGradeItemDetail);
}

}
Expand Down Expand Up @@ -325,7 +328,7 @@ private static ProcessedGradeItemStatus determineStatus(ImportColumn column, Ass
String actualComment = null;

if (assignmentStudentGradeInfo != null) {
GradeInfo actualGradeInfo = assignmentStudentGradeInfo.getStudentGrades().get(importedGrade.getStudentId());
GradeInfo actualGradeInfo = assignmentStudentGradeInfo.getStudentGrades().get(importedGrade.getStudentEid());

if (actualGradeInfo != null) {
actualScore = actualGradeInfo.getGrade();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
@Data
public class ImportedGrade implements Serializable {

private String studentId;
private String studentEid;
private String studentUuid;
private String studentName;

private Map<String, ImportedGradeItem> gradeItemMap = new HashMap<String, ImportedGradeItem>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
@Data
public class ProcessedGradeItemDetail implements Serializable {

private String studentId;
private String studentEid;
private String studentUuid;
private String grade;
private String comment;
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ protected void onSubmit()
//TODO this loops through grades and comments separately...need to figure out a better way
for (ProcessedGradeItemDetail processedGradeItemDetail : processedGradeItem.getProcessedGradeItemDetails()) {
LOG.debug("Looping through detail items to save");
GradeSaveResponse saved = businessService.saveGrade(processedGradeItem.getItemId(), processedGradeItemDetail.getStudentId(),
GradeSaveResponse saved = businessService.saveGrade(processedGradeItem.getItemId(), processedGradeItemDetail.getStudentUuid(),
processedGradeItemDetail.getGrade(), processedGradeItemDetail.getComment());
if (saved != GradeSaveResponse.OK) {
//Anything other than OK and NO_CHANGE is bad
if (!(saved == GradeSaveResponse.OK || saved == GradeSaveResponse.NO_CHANGE)) {
errors = true;
}
LOG.info("Saving grade: " + saved + ", " + processedGradeItem.getItemId() + ", " + processedGradeItemDetail.getStudentId() + ", " +
LOG.info("Saving grade: " + saved + ", " + processedGradeItem.getItemId() + ", " + processedGradeItemDetail.getStudentEid() + ", " +
processedGradeItemDetail.getGrade() + ", " + processedGradeItemDetail.getComment());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by chmaurer on 1/22/15.
Expand Down Expand Up @@ -163,8 +165,11 @@ public void onSubmit() {

try {
log.debug("file upload success");
//get all users
Map<String, String> userMap = makeUserMap(grades);

//turn file into list
ImportedGradeWrapper importedGradeWrapper = parseImportedGradeFile(upload.getInputStream(), upload.getContentType());
ImportedGradeWrapper importedGradeWrapper = parseImportedGradeFile(upload.getInputStream(), upload.getContentType(), userMap);

List<ProcessedGradeItem> processedGradeItems = ImportGradesHelper.processImportedGrades(importedGradeWrapper, assignments, grades);

Expand Down Expand Up @@ -194,14 +199,27 @@ public void onSubmit() {
}
}

/**
* Create a map so that we can use the user's eid (from the imported file) to lookup their uuid (used to store the grade by the backend service)
* @param grades
* @return Map where the user's eid is the key and the uuid is the value
*/
private Map<String, String> makeUserMap(List<StudentGradeInfo> grades) {
Map<String, String> userMap = new HashMap<String, String>();

for (StudentGradeInfo studentGradeInfo : grades) {
userMap.put(studentGradeInfo.getStudentEid(), studentGradeInfo.getStudentUuid());
}
return userMap;
}

public ImportedGradeWrapper parseImportedGradeFile(InputStream is, String mimetype){
public ImportedGradeWrapper parseImportedGradeFile(InputStream is, String mimetype, Map<String, String> userMap){

//determine file type and delegate
if(ArrayUtils.contains(CSV_MIME_TYPES, mimetype)) {
return ImportGradesHelper.parseCsv(is);
return ImportGradesHelper.parseCsv(is, userMap);
} else if (ArrayUtils.contains(XLS_MIME_TYPES, mimetype)) {
return ImportGradesHelper.parseXls(is);
return ImportGradesHelper.parseXls(is, userMap);
} else {
log.error("Invalid file type for grade import: " + mimetype);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@
*/
public class TestImportGradesHelper {

private Map<String, String> userMap() {
Map<String, String> userMap = new HashMap<String, String>();
userMap.put("student1", "student1");
userMap.put("student2", "student2");
return userMap;
}

@Test
public void testCsvImport() throws Exception {
InputStream is = this.getClass().getClassLoader().getResourceAsStream("grades_import.csv");
ImportedGradeWrapper importedGradeWrapper = ImportGradesHelper.parseCsv(is);
ImportedGradeWrapper importedGradeWrapper = ImportGradesHelper.parseCsv(is, userMap());
is.close();

testImport(importedGradeWrapper);
Expand All @@ -40,7 +47,7 @@ public void testCsvImport() throws Exception {
@Test
public void testXlsImport() throws Exception {
InputStream is = this.getClass().getClassLoader().getResourceAsStream("grades_import.xls");
ImportedGradeWrapper importedGradeWrapper = ImportGradesHelper.parseXls(is);
ImportedGradeWrapper importedGradeWrapper = ImportGradesHelper.parseXls(is, userMap());
is.close();

testImport(importedGradeWrapper);
Expand Down Expand Up @@ -222,7 +229,8 @@ private ImportedGradeWrapper mockImportedGrades() {

List<ImportedGrade> importedGrades = new ArrayList<ImportedGrade>();
ImportedGrade importedGrade1 = new ImportedGrade();
importedGrade1.setStudentId("user1");
importedGrade1.setStudentUuid("user1");
importedGrade1.setStudentEid("user1");
importedGrade1.setStudentName("User 1");
Map<String, ImportedGradeItem> gradeMap1 = new HashMap<>();

Expand All @@ -232,7 +240,8 @@ private ImportedGradeWrapper mockImportedGrades() {
importedGrades.add(importedGrade1);

ImportedGrade importedGrade2 = new ImportedGrade();
importedGrade2.setStudentId("user2");
importedGrade2.setStudentEid("user2");
importedGrade2.setStudentUuid("user2");
importedGrade2.setStudentName("User 2");
Map<String, ImportedGradeItem> gradeMap2 = new HashMap<>();

Expand All @@ -242,7 +251,8 @@ private ImportedGradeWrapper mockImportedGrades() {
importedGrades.add(importedGrade2);

ImportedGrade importedGrade3 = new ImportedGrade();
importedGrade3.setStudentId("user3");
importedGrade3.setStudentEid("user3");
importedGrade3.setStudentUuid("user3");
importedGrade3.setStudentName("User 3");
Map<String, ImportedGradeItem> gradeMap3 = new HashMap<>();

Expand Down

0 comments on commit 3dbf9e7

Please sign in to comment.