From e1cfd686a8f50a1b1178c0b9c5a08d3f5cc6608b Mon Sep 17 00:00:00 2001 From: Chris Maurer Date: Mon, 22 Jun 2015 23:26:56 -0400 Subject: [PATCH] Refactor the model a bit to have the comment items as a sub item of the processedGradeItem instead of a separate processedGradeItem. The service won't update a record if the grade is the same but with a changed comment. --- .../business/helpers/ImportGradesHelper.java | 55 ++++++++++--------- .../business/model/ProcessedGradeItem.java | 3 + .../GradeImportConfirmationStep.java | 20 +++++-- .../GradeItemImportSelectionStep.java | 35 +++++++++++- .../helpers/TestImportGradesHelper.java | 22 +++++--- 5 files changed, 96 insertions(+), 39 deletions(-) diff --git a/tool/src/java/org/sakaiproject/gradebookng/business/helpers/ImportGradesHelper.java b/tool/src/java/org/sakaiproject/gradebookng/business/helpers/ImportGradesHelper.java index 5cb2e2703b64..8d7f6c741f69 100644 --- a/tool/src/java/org/sakaiproject/gradebookng/business/helpers/ImportGradesHelper.java +++ b/tool/src/java/org/sakaiproject/gradebookng/business/helpers/ImportGradesHelper.java @@ -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; @@ -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. @@ -254,6 +252,7 @@ public static List processImportedGrades(ImportedGradeWrappe List assignments, List currentGrades) { List processedGradeItems = new ArrayList(); Map assignmentNameMap = new HashMap(); + Map assignmentProcessedGradeItemMap = new HashMap(); Map transformedGradeMap = transformCurrentGrades(currentGrades); @@ -264,31 +263,31 @@ public static List 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()); } @@ -301,13 +300,17 @@ public static List 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; diff --git a/tool/src/java/org/sakaiproject/gradebookng/business/model/ProcessedGradeItem.java b/tool/src/java/org/sakaiproject/gradebookng/business/model/ProcessedGradeItem.java index a4367cc12546..ec810fe0517b 100644 --- a/tool/src/java/org/sakaiproject/gradebookng/business/model/ProcessedGradeItem.java +++ b/tool/src/java/org/sakaiproject/gradebookng/business/model/ProcessedGradeItem.java @@ -17,4 +17,7 @@ public class ProcessedGradeItem implements Serializable { private String itemPointValue; private ProcessedGradeItemStatus status = new ProcessedGradeItemStatus(ProcessedGradeItemStatus.STATUS_UNKNOWN); private List processedGradeItemDetails = new ArrayList(); + + private String commentLabel; + private ProcessedGradeItemStatus commentStatus = new ProcessedGradeItemStatus(ProcessedGradeItemStatus.STATUS_UNKNOWN); } diff --git a/tool/src/java/org/sakaiproject/gradebookng/tool/panels/importExport/GradeImportConfirmationStep.java b/tool/src/java/org/sakaiproject/gradebookng/tool/panels/importExport/GradeImportConfirmationStep.java index d12c0be7a413..4aef0856851e 100644 --- a/tool/src/java/org/sakaiproject/gradebookng/tool/panels/importExport/GradeImportConfirmationStep.java +++ b/tool/src/java/org/sakaiproject/gradebookng/tool/panels/importExport/GradeImportConfirmationStep.java @@ -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; @@ -150,9 +150,21 @@ private ListView makeListView(String componentName, List item) { item.add(new Label("itemTitle", new PropertyModel(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 commentLabelProp = new PropertyModel(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( + "" + commentLabel + "" + ); + } + } + }); } }; } diff --git a/tool/src/java/org/sakaiproject/gradebookng/tool/panels/importExport/GradeItemImportSelectionStep.java b/tool/src/java/org/sakaiproject/gradebookng/tool/panels/importExport/GradeItemImportSelectionStep.java index 9880a5547446..11e3f130a393 100644 --- a/tool/src/java/org/sakaiproject/gradebookng/tool/panels/importExport/GradeItemImportSelectionStep.java +++ b/tool/src/java/org/sakaiproject/gradebookng/tool/panels/importExport/GradeItemImportSelectionStep.java @@ -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; @@ -146,9 +147,41 @@ protected void populateItem(ListItem 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("comment"), " ")); + + PropertyModel commentLabelProp = new PropertyModel(item.getDefaultModel(), "commentLabel"); + final PropertyModel commentStatusProp = new PropertyModel(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( + "" + + "" + + "" + commentLabel + "" + + "" + naString + "" + + "" + statusValue + "" + + "" + + ); + } + } + }); + } }; diff --git a/tool/src/test/java/org/sakaiproject/gradebookng/business/helpers/TestImportGradesHelper.java b/tool/src/test/java/org/sakaiproject/gradebookng/business/helpers/TestImportGradesHelper.java index de5a7007dce8..356a40b5b21e 100644 --- a/tool/src/test/java/org/sakaiproject/gradebookng/business/helpers/TestImportGradesHelper.java +++ b/tool/src/test/java/org/sakaiproject/gradebookng/business/helpers/TestImportGradesHelper.java @@ -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; @@ -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());