Skip to content

Commit

Permalink
Refactor the model a bit to have the comment items as a sub item of t…
Browse files Browse the repository at this point in the history
…he processedGradeItem instead of a separate processedGradeItem.

The service won't update a record if the grade is the same but with a changed comment.
  • Loading branch information
maurercw committed Jun 23, 2015
1 parent ca0cc1b commit e1cfd68
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
package org.sakaiproject.gradebookng.business.helpers;


import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.MessageFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import au.com.bytecode.opencsv.CSVReader;
import lombok.extern.apachecommons.CommonsLog;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
Expand All @@ -32,7 +22,15 @@
import org.sakaiproject.service.gradebook.shared.Assignment;
import org.sakaiproject.util.BaseResourcePropertiesEdit;

import au.com.bytecode.opencsv.CSVReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.MessageFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by chmaurer on 1/21/15.
Expand Down Expand Up @@ -254,6 +252,7 @@ public static List<ProcessedGradeItem> processImportedGrades(ImportedGradeWrappe
List<Assignment> assignments, List<GbStudentGradeInfo> currentGrades) {
List<ProcessedGradeItem> processedGradeItems = new ArrayList<ProcessedGradeItem>();
Map<String, Assignment> assignmentNameMap = new HashMap<String, Assignment>();
Map<String, ProcessedGradeItem> assignmentProcessedGradeItemMap = new HashMap<String, ProcessedGradeItem>();

Map<Long, AssignmentStudentGradeInfo> transformedGradeMap = transformCurrentGrades(currentGrades);

Expand All @@ -264,31 +263,31 @@ public static List<ProcessedGradeItem> processImportedGrades(ImportedGradeWrappe


for (ImportColumn column : importedGradeWrapper.getColumns()) {
ProcessedGradeItem processedGradeItem = new ProcessedGradeItem();

boolean needsAdded = false;
String assignmentName = column.getColumnTitle();

ProcessedGradeItem processedGradeItem = assignmentProcessedGradeItemMap.get(assignmentName);
if (processedGradeItem == null) {
processedGradeItem = new ProcessedGradeItem();
needsAdded = true;
}

Assignment assignment = assignmentNameMap.get(assignmentName);
ProcessedGradeItemStatus status = determineStatus(column, assignment, importedGradeWrapper, transformedGradeMap);

if (column.getType() == ImportColumn.TYPE_ITEM_WITH_POINTS) {
processedGradeItem.setItemTitle(assignmentName);
processedGradeItem.setItemPointValue(column.getPoints());



processedGradeItem.setStatus(status);
} else if (column.getType() == ImportColumn.TYPE_ITEM_WITH_COMMENTS) {
processedGradeItem.setItemTitle(assignmentName + " Comments");
processedGradeItem.setItemPointValue("N/A");

processedGradeItem.setCommentLabel(assignmentName + " Comments");
processedGradeItem.setCommentStatus(status);
} else {
//Just get out
log.warn("Bad column type - " + column.getType() + ". Skipping.");
continue;
}

Assignment assignment = assignmentNameMap.get(assignmentName);

ProcessedGradeItemStatus status = determineStatus(column, assignment, importedGradeWrapper, transformedGradeMap);
processedGradeItem.setStatus(status);

if (assignment != null) {
processedGradeItem.setItemId(assignment.getId());
}
Expand All @@ -301,13 +300,17 @@ public static List<ProcessedGradeItem> processImportedGrades(ImportedGradeWrappe
processedGradeItemDetail.setStudentEid(importedGrade.getStudentEid());
processedGradeItemDetail.setStudentUuid(importedGrade.getStudentUuid());
processedGradeItemDetail.setGrade(importedGradeItem.getGradeItemScore());
processedGradeItemDetail.setComment(importedGradeItem.getGradeItemComment());
processedGradeItemDetails.add(processedGradeItemDetail);
}

}
processedGradeItem.setProcessedGradeItemDetails(processedGradeItemDetails);

processedGradeItems.add(processedGradeItem);
if (needsAdded) {
processedGradeItems.add(processedGradeItem);
assignmentProcessedGradeItemMap.put(assignmentName, processedGradeItem);
}
}

return processedGradeItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public class ProcessedGradeItem implements Serializable {
private String itemPointValue;
private ProcessedGradeItemStatus status = new ProcessedGradeItemStatus(ProcessedGradeItemStatus.STATUS_UNKNOWN);
private List<ProcessedGradeItemDetail> processedGradeItemDetails = new ArrayList<ProcessedGradeItemDetail>();

private String commentLabel;
private ProcessedGradeItemStatus commentStatus = new ProcessedGradeItemStatus(ProcessedGradeItemStatus.STATUS_UNKNOWN);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.sakaiproject.gradebookng.tool.panels.importExport;

import org.apache.log4j.Logger;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
Expand Down Expand Up @@ -150,9 +150,21 @@ private ListView<ProcessedGradeItem> makeListView(String componentName, List<Pro
@Override
protected void populateItem(ListItem<ProcessedGradeItem> item) {
item.add(new Label("itemTitle", new PropertyModel<String>(item.getDefaultModel(), "itemTitle")));
String naString = getString("importExport.selection.pointValue.na", new Model(), "N/A");
if (naString.equals(item.getModelObject().getItemPointValue()))
item.add(new AttributeModifier("class", "comment"));

PropertyModel<String> commentLabelProp = new PropertyModel<String>(item.getDefaultModel(), "commentLabel");
final String commentLabel = commentLabelProp.getObject();

item.add(new Behavior() {
@Override
public void afterRender(Component component) {
super.afterRender(component);
if(commentLabel != null){
component.getResponse().write(
"<tr class=\"comment\"><td class=\"item_title\"><span>" + commentLabel + "</span></td></tr>"
);
}
}
});
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Check;
Expand Down Expand Up @@ -146,9 +147,41 @@ protected void populateItem(ListItem<ProcessedGradeItem> item)
item.add(new Label("status", getString("importExport.status." + status.getStatusCode())));
}

String naString = getString("importExport.selection.pointValue.na", new Model(), "N/A");
final String naString = getString("importExport.selection.pointValue.na", new Model(), "N/A");
if (naString.equals(item.getModelObject().getItemPointValue()))
item.add(new AttributeAppender("class", new Model<String>("comment"), " "));

PropertyModel<String> commentLabelProp = new PropertyModel<String>(item.getDefaultModel(), "commentLabel");
final PropertyModel<ProcessedGradeItemStatus> commentStatusProp = new PropertyModel<ProcessedGradeItemStatus>(item.getDefaultModel(), "commentStatus");
final String commentLabel = commentLabelProp.getObject();
final ProcessedGradeItemStatus commentStatus = commentStatusProp.getObject();

item.add(new Behavior() {
@Override
public void afterRender(Component component) {
super.afterRender(component);
if(commentLabel != null){
String rowClass = "comment";
String statusValue = getString("importExport.status." + commentStatus.getStatusCode());
if (commentStatus.getStatusCode() == ProcessedGradeItemStatus.STATUS_EXTERNAL) {
rowClass += " external";
statusValue = new StringResourceModel("importExport.status." + commentStatus.getStatusCode(),
commentStatusProp, null, commentStatus.getStatusValue()).getString();
}

component.getResponse().write(
"<tr class=\"" + rowClass + "\">" +
"<td></td>" +
"<td class=\"item_title\"><span>" + commentLabel + "</span></td>" +
"<td><span>" + naString + "</span></td>" +
"<td class=\"item_status\"><span>" + statusValue + "</span></td>" +
"</tr>"

);
}
}
});

}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import org.junit.Test;
import org.mockito.Mockito;
import org.sakaiproject.gradebookng.business.model.GbGradeInfo;
import org.sakaiproject.gradebookng.business.model.GbStudentGradeInfo;
import org.sakaiproject.gradebookng.business.model.ImportColumn;
import org.sakaiproject.gradebookng.business.model.ImportedGrade;
import org.sakaiproject.gradebookng.business.model.ImportedGradeItem;
import org.sakaiproject.gradebookng.business.model.ImportedGradeWrapper;
import org.sakaiproject.gradebookng.business.model.ProcessedGradeItem;
import org.sakaiproject.gradebookng.business.model.ProcessedGradeItemStatus;
import org.sakaiproject.gradebookng.business.model.GbStudentGradeInfo;
import org.sakaiproject.service.gradebook.shared.Assignment;
import org.sakaiproject.service.gradebook.shared.GradeDefinition;
import org.sakaiproject.user.api.User;
Expand Down Expand Up @@ -123,16 +123,22 @@ public void testProcessImportedGrades() throws Exception {

Assert.assertNotNull(processedGradeItems);

Assert.assertEquals("wrong number of results", 7, processedGradeItems.size());
Assert.assertEquals("wrong number of results", 4, processedGradeItems.size());

//assignment 1
Assert.assertEquals("wrong status", ProcessedGradeItemStatus.STATUS_NA, processedGradeItems.get(0).getStatus().getStatusCode());
Assert.assertEquals("wrong status", ProcessedGradeItemStatus.STATUS_NA, processedGradeItems.get(1).getStatus().getStatusCode());
Assert.assertEquals("wrong status", ProcessedGradeItemStatus.STATUS_UPDATE, processedGradeItems.get(2).getStatus().getStatusCode());
Assert.assertEquals("wrong status", ProcessedGradeItemStatus.STATUS_UPDATE, processedGradeItems.get(3).getStatus().getStatusCode());
Assert.assertEquals("wrong status", ProcessedGradeItemStatus.STATUS_NEW, processedGradeItems.get(4).getStatus().getStatusCode());
Assert.assertEquals("wrong status", ProcessedGradeItemStatus.STATUS_NEW, processedGradeItems.get(5).getStatus().getStatusCode());
Assert.assertEquals("wrong status", ProcessedGradeItemStatus.STATUS_NA, processedGradeItems.get(0).getCommentStatus().getStatusCode());

//assignment 2
Assert.assertEquals("wrong status", ProcessedGradeItemStatus.STATUS_UPDATE, processedGradeItems.get(1).getStatus().getStatusCode());
Assert.assertEquals("wrong status", ProcessedGradeItemStatus.STATUS_UPDATE, processedGradeItems.get(1).getCommentStatus().getStatusCode());

//assignment 3
Assert.assertEquals("wrong status", ProcessedGradeItemStatus.STATUS_NEW, processedGradeItems.get(2).getStatus().getStatusCode());
Assert.assertEquals("wrong status", ProcessedGradeItemStatus.STATUS_NEW, processedGradeItems.get(2).getCommentStatus().getStatusCode());

ProcessedGradeItemStatus extStatus = processedGradeItems.get(6).getStatus();
//assignment ext
ProcessedGradeItemStatus extStatus = processedGradeItems.get(3).getStatus();
Assert.assertEquals("wrong status", ProcessedGradeItemStatus.STATUS_EXTERNAL, extStatus.getStatusCode());
Assert.assertEquals("wrong status name", "From a test", extStatus.getStatusValue());

Expand Down

0 comments on commit e1cfd68

Please sign in to comment.