Skip to content

Commit

Permalink
SAK-45421 Make rubrics work with csv gb item import (sakaiproject#9214)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish authored Apr 29, 2021
1 parent 66d19cc commit a360bb6
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,6 @@ public class AssignmentAction extends PagedResourceActionII {
private static final String CONTEXT_GO_NEXT_UNGRADED_ENABLED = "goNextUngradedEnabled";
private static final String CONTEXT_GO_PREV_UNGRADED_ENABLED = "goPrevUngradedEnabled";
private static final String PARAMS_VIEW_SUBS_ONLY_CHECKBOX = "chkSubsOnly1";
private static final String RUBRIC_STATE_DETAILS = "rbcs-state-details";
private static final String RUBRIC_TOKEN = "rbcs-token";
private static ResourceLoader rb = new ResourceLoader("assignment");
private boolean nextUngraded = false;
Expand Down Expand Up @@ -11636,9 +11635,6 @@ private void initializeAssignment(SessionState state) {

// SAK-17606
state.removeAttribute(NEW_ASSIGNMENT_CHECK_ANONYMOUS_GRADING);

state.removeAttribute(RUBRIC_STATE_DETAILS);

} // resetNewAssignment

/**
Expand Down Expand Up @@ -11755,8 +11751,6 @@ private void resetAssignment(SessionState state) {

state.removeAttribute(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT);

state.removeAttribute(RUBRIC_STATE_DETAILS);

state.removeAttribute(NEW_ASSIGNMENT_PREVIOUSLY_ASSOCIATED);
} // resetNewAssignment

Expand Down
2 changes: 2 additions & 0 deletions gradebookng/bundle/src/main/bundle/gradebookng.properties
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,10 @@ importExport.confirmation.extraCredit = Extra Credit
importExport.confirmation.dueDate = Due date
importExport.confirmation.releaseToStudents = Release item to students
importExport.confirmation.includeInCourseGrades = Include item in course grade calculations
importExport.confirmation.rubric = Rubric
importExport.confirmation.yes = Yes
importExport.confirmation.no = No
importExport.confirmation.none = None

importExport.confirmation.commentsdisplay = {0} (Comments)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -140,5 +141,5 @@ public int compareTo(final Object o) {

@Getter
@Setter
private Double assignmentPoints;
private Map<String, String> rubricParameters;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
Expand Down Expand Up @@ -117,6 +118,7 @@ protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
// sync up the assignment data so we can present it for confirmation
processedGradeItem.setItemTitle(newAssignment.getName());
processedGradeItem.setItemPointValue(String.valueOf(newAssignment.getPoints()));
processedGradeItem.setRubricParameters(getRubricParameters(""));

// add to model
importWizardModel.getAssignmentsToCreate().put(processedGradeItem, newAssignment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ <h2><wicket:message key="importExport.confirmation.heading" /></h2>
<th><wicket:message key="importExport.confirmation.dueDate" /></th>
<th><wicket:message key="importExport.confirmation.releaseToStudents" /></th>
<th><wicket:message key="importExport.confirmation.includeInCourseGrades" /></th>
<th><wicket:message key="importExport.confirmation.rubric" /></th>
</tr>
</thead>
<tbody>
Expand All @@ -42,6 +43,7 @@ <h2><wicket:message key="importExport.confirmation.heading" /></h2>
<td><span wicket:id="dueDate"></span></td>
<td><span wicket:id="releaseToStudents"></span></td>
<td><span wicket:id="includeInCourseGrades"></span></td>
<td><span wicket:id="rubricId"></span></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -51,6 +52,8 @@
import org.sakaiproject.gradebookng.tool.pages.GradebookPage;
import org.sakaiproject.gradebookng.tool.pages.ImportExportPage;
import org.sakaiproject.gradebookng.tool.panels.BasePanel;
import org.sakaiproject.rubrics.logic.RubricsConstants;
import org.sakaiproject.rubrics.logic.model.Rubric;
import org.sakaiproject.service.gradebook.shared.Assignment;
import org.sakaiproject.service.gradebook.shared.AssignmentHasIllegalPointsException;
import org.sakaiproject.service.gradebook.shared.ConflictingAssignmentNameException;
Expand All @@ -71,6 +74,7 @@ public class GradeImportConfirmationStep extends BasePanel {

private final String yes = MessageHelper.getString("importExport.confirmation.yes");
private final String no = MessageHelper.getString("importExport.confirmation.no");
private final String none = MessageHelper.getString("importExport.confirmation.none");

private boolean errors = false;

Expand Down Expand Up @@ -153,12 +157,13 @@ public void onSubmit(AjaxRequestTarget target, Form<?> form) {

Long assignmentId = null;
try {
ProcessedGradeItem pgi = entry.getKey();
assignmentId = GradeImportConfirmationStep.this.businessService.addAssignment(assignment);
rubricsService.saveRubricAssociation(RubricsConstants.RBCS_TOOL_GRADEBOOKNG, assignmentId.toString(), pgi.getRubricParameters());

success(MessageHelper.getString("notification.addgradeitem.success", assignment.getName()));

// set the processedGradeItem's itemId so we can later save scores from the spreadsheet
ProcessedGradeItem pgi = entry.getKey();
pgi.setItemId(assignmentId);

// since it's new, add this item to the list of items that have grades that need to be written
Expand Down Expand Up @@ -390,6 +395,7 @@ private ListView<Assignment> makeAssignmentsToCreateListView(final String markup
protected void populateItem(final ListItem<Assignment> item) {
final Assignment assignment = item.getModelObject();


String extraCredit = assignment.isExtraCredit() ? yes : no;
String dueDate = FormatHelper.formatDate(assignment.getDueDate(), "");
String releaseToStudents = assignment.isReleased() ? yes : no;
Expand All @@ -401,6 +407,28 @@ protected void populateItem(final ListItem<Assignment> item) {
item.add(new Label("dueDate", dueDate));
item.add(new Label("releaseToStudents", releaseToStudents));
item.add(new Label("includeInCourseGrades", includeInCourseGrades));

ImportWizardModel importWizardModel = GradeImportConfirmationStep.this.model.getObject();

Optional<ProcessedGradeItem> optPgi
= importWizardModel.getAssignmentsToCreate().keySet().stream()
.filter(e -> e.getItemTitle().equals(assignment.getName())).findFirst();

String rubricTitle = none;
if (optPgi.isPresent()) {
String rubricId = optPgi.get().getRubricParameters().get(RubricsConstants.RBCS_LIST);
if (rubricId != null) {
try {
Optional<Rubric> optRubric = rubricsService.getRubric(Long.parseLong(rubricId));
if (optRubric.isPresent()) {
rubricTitle = optRubric.get().getTitle();
}
} catch (Exception e) {
log.error("Failed to get rubric for id {}", rubricId, e);
}
}
}
item.add(new Label("rubricId", rubricTitle));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Optional;

import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.rubrics.logic.model.Rubric;
import org.sakaiproject.rubrics.logic.model.ToolItemRubricAssociation;

/**
Expand All @@ -36,6 +37,8 @@ public interface RubricsService {

public static final String REFERENCE_ROOT = Entity.SEPARATOR + "rubrics";

Optional<Rubric> getRubric(Long rubricId) throws Exception;

boolean hasAssociatedRubric(String toolId, String associatedToolItemId);

boolean hasAssociatedRubric(String toolId, String associatedToolItemId, String siteId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,29 @@ public String generateJsonWebToken(String tool, String siteId) {
return token;
}

public Optional<Rubric> getRubric(Long rubricId) throws Exception {

URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX);
Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON);

Traverson.TraversalBuilder builder = traverson.follow("rubrics");

HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(RubricsConstants.RBCS_TOOL)));
builder.withHeaders(headers);

Map<String, Object> parameters = new HashMap<>();
parameters.put("id", rubricId);

CollectionModel<EntityModel<Rubric>> rubricsModel = builder
.withTemplateParameters(parameters)
.toObject(new TypeReferences.CollectionModelType<EntityModel<Rubric>>() {});

Collection<EntityModel<Rubric>> models = rubricsModel.getContent();

return models.size() == 1 ? Optional.of(models.iterator().next().getContent()) : Optional.empty();
}

public boolean hasAssociatedRubric(String tool, String id) {
return hasAssociatedRubric(tool, id, getCurrentSiteId("hasAssociatedRubric"));
}
Expand Down

0 comments on commit a360bb6

Please sign in to comment.