Skip to content

Commit

Permalink
SAK-46178 Move rubrics to spring mvc and in memory calls (sakaiprojec…
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish authored Apr 27, 2022
1 parent a4946c6 commit 3c99296
Show file tree
Hide file tree
Showing 186 changed files with 5,180 additions and 6,776 deletions.
2 changes: 1 addition & 1 deletion assignment/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</dependency>
<dependency>
<groupId>org.sakaiproject.rubrics</groupId>
<artifactId>rubrics-service-api</artifactId>
<artifactId>rubrics-api</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.search</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@
import org.sakaiproject.messaging.api.Message;
import org.sakaiproject.messaging.api.MessageMedium;
import org.sakaiproject.messaging.api.UserMessagingService;
import org.sakaiproject.rubrics.logic.RubricsConstants;
import org.sakaiproject.rubrics.logic.RubricsService;
import org.sakaiproject.rubrics.logic.model.ToolItemRubricAssociation;
import org.sakaiproject.rubrics.api.RubricsConstants;
import org.sakaiproject.rubrics.api.RubricsService;
import org.sakaiproject.rubrics.api.model.ToolItemRubricAssociation;
import org.sakaiproject.search.api.SearchService;
import org.sakaiproject.site.api.Group;
import org.sakaiproject.site.api.Site;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.sakaiproject.hibernate.AssignableUUIDGenerator;
import org.sakaiproject.messaging.api.MessagingService;
import org.sakaiproject.messaging.api.UserMessagingService;
import org.sakaiproject.rubrics.logic.RubricsService;
import org.sakaiproject.rubrics.api.RubricsService;
import org.sakaiproject.search.api.SearchIndexBuilder;
import org.sakaiproject.search.api.SearchService;
import org.sakaiproject.site.api.SiteService;
Expand Down Expand Up @@ -291,7 +291,7 @@ public PreferencesService preferencesService() {
return mock(PreferencesService.class);
}

@Bean(name = "org.sakaiproject.rubrics.logic.RubricsService")
@Bean(name = "org.sakaiproject.rubrics.api.RubricsService")
public RubricsService rubricsService() {
return mock(RubricsService.class);
}
Expand Down
2 changes: 1 addition & 1 deletion assignment/impl/src/webapp/WEB-INF/components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</bean>
</property>
<property name="resourceLoader" ref="org.sakaiproject.util.ResourceLoader.assignment"/>
<property name="rubricsService" ref="org.sakaiproject.rubrics.logic.RubricsService"/>
<property name="rubricsService" ref="org.sakaiproject.rubrics.api.RubricsService"/>
<property name="securityService" ref="org.sakaiproject.authz.api.SecurityService"/>
<property name="sessionManager" ref="org.sakaiproject.tool.api.SessionManager"/>
<property name="serverConfigurationService" ref="org.sakaiproject.component.api.ServerConfigurationService"/>
Expand Down
10 changes: 9 additions & 1 deletion assignment/tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</dependency>
<dependency>
<groupId>org.sakaiproject.rubrics</groupId>
<artifactId>rubrics-service-api</artifactId>
<artifactId>rubrics-api</artifactId>
</dependency>
<!-- ScoringService integration -->
<dependency>
Expand Down Expand Up @@ -141,10 +141,18 @@
<artifactId>json</artifactId>
<version>${sakai.org.json.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.grading.api.GradingService;
import org.sakaiproject.rubrics.logic.RubricsConstants;
import org.sakaiproject.rubrics.api.RubricsConstants;
import org.sakaiproject.site.api.Group;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.SiteService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@
import org.sakaiproject.grading.api.GradingService;
import org.sakaiproject.javax.PagingPosition;
import org.sakaiproject.message.api.MessageHeader;
import org.sakaiproject.rubrics.logic.RubricsConstants;
import org.sakaiproject.rubrics.logic.RubricsService;
import org.sakaiproject.rubrics.api.beans.AssociationTransferBean;
import org.sakaiproject.rubrics.api.RubricsConstants;
import org.sakaiproject.rubrics.api.RubricsService;
import org.sakaiproject.scoringservice.api.ScoringAgent;
import org.sakaiproject.scoringservice.api.ScoringComponent;
import org.sakaiproject.scoringservice.api.ScoringService;
Expand Down Expand Up @@ -1092,7 +1093,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_TOKEN = "rbcs-token";
private static ResourceLoader rb = new ResourceLoader("assignment");
private boolean nextUngraded = false;
private boolean prevUngraded = false;
Expand Down Expand Up @@ -1519,8 +1519,6 @@ public String buildMainPanelContext(VelocityPortlet portlet, Context context, Ru
context.put("assignmentscheck", state.getAttribute(HAS_MULTIPLE_ASSIGNMENTS));
}

context.put(RUBRIC_TOKEN, rubricsService.generateJsonWebToken(RubricsConstants.RBCS_TOOL_ASSIGNMENT));

return template;

} // buildMainPanelContext
Expand Down Expand Up @@ -2748,7 +2746,7 @@ private String build_list_assignments_context(VelocityPortlet portlet, Context c
context.put("assignments", assignments.iterator());

// allow add assignment?
Map<String, List<PeerAssessmentItem>> peerAssessmentItemsMap = new HashMap<String, List<PeerAssessmentItem>>();
Map<String, List<PeerAssessmentItem>> peerAssessmentItemsMap = new HashMap<>();
boolean allowAddAssignment = assignmentService.allowAddAssignment(contextString);
if (!allowAddAssignment) {
//this is the same requirement for displaying the assignment link for students
Expand Down Expand Up @@ -2783,6 +2781,22 @@ private String build_list_assignments_context(VelocityPortlet portlet, Context c

context.put("peerAssessmentItemsMap", peerAssessmentItemsMap);

Map<String, Long> rubricMap = new HashMap<>();
assignments.forEach(a -> {

try {
Optional<AssociationTransferBean> optAssociation
= rubricsService.getAssociationForToolAndItem(RubricsConstants.RBCS_TOOL_ASSIGNMENT, a.getId(), a.getContext());
if (optAssociation.isPresent()) {
rubricMap.put(a.getId(), optAssociation.get().rubricId);
}
} catch (Exception e) {
log.error("Failed to load rubric map", e);
}
});

context.put("rubricMap", rubricMap);

// allow get assignment
context.put("allowGetAssignment", assignmentService.allowGetAssignment(contextString));

Expand Down Expand Up @@ -2916,13 +2930,15 @@ protected String build_instructor_new_edit_assignment_context(VelocityPortlet po
// Anon grading enabled/disabled
context.put("enableAnonGrading", serverConfigurationService.getBoolean(AssignmentConstants.SAK_PROP_ENABLE_ANON_GRADING, false));
boolean forceAnonGrading = false;
String siteId = (String) state.getAttribute(STATE_CONTEXT_STRING);
try {
Site site = siteService.getSite((String) state.getAttribute(STATE_CONTEXT_STRING));
Site site = siteService.getSite(siteId);
forceAnonGrading = site.getProperties().getBooleanProperty(AssignmentConstants.SAK_PROP_FORCE_ANON_GRADING);
} catch (EntityPropertyTypeException | EntityPropertyNotDefinedException | SakaiException se) {
log.debug("Failed to find if anonymous grading is forced.");
}
context.put("forceAnonGrading", forceAnonGrading);
context.put("siteId", siteId);

// is the assignment an new assignment
String assignmentId = (String) state.getAttribute(EDIT_ASSIGNMENT_ID);
Expand All @@ -2931,6 +2947,18 @@ protected String build_instructor_new_edit_assignment_context(VelocityPortlet po
if (a != null) {
context.put("assignmentId", assignmentId);
context.put("assignment", a);
if (state.getAttribute(RUBRIC_ASSOCIATION) == null) {
try {
Optional<AssociationTransferBean> optAssociation
= rubricsService.getAssociationForToolAndItem(RubricsConstants.RBCS_TOOL_ASSIGNMENT, a.getId(), siteId);
if (optAssociation.isPresent()) {
state.setAttribute(RUBRIC_ASSOCIATION, (new ObjectMapper()).writeValueAsString(optAssociation.get()));
}
} catch (Exception e) {
log.warn("Failed to get rubric association for assignment {}", assignmentId);
}
}

rangeAndGroups.buildInstructorNewEditAssignmentContextGroupCheck(context, a);

// controls to disable which groups can be changed
Expand Down Expand Up @@ -4715,6 +4743,16 @@ private String build_instructor_grade_assignment_context(VelocityPortlet portlet
context.put("taggable", Boolean.TRUE);
}

try {
Optional<AssociationTransferBean> optAssociation
= rubricsService.getAssociationForToolAndItem(RubricsConstants.RBCS_TOOL_ASSIGNMENT, assignment.getId(), assignment.getContext());
if (optAssociation.isPresent()) {
context.put("rubricId", optAssociation.get().rubricId);
}
} catch (Exception e) {
log.error("Failed to get association", e);
}

context.put("submissionTypeTable", submissionTypeTable());
context.put("attachments", state.getAttribute(ATTACHMENTS));
context.put("contentTypeImageService", contentTypeImageService);
Expand Down Expand Up @@ -8675,9 +8713,9 @@ private Set<AssignmentSupplementItemAttachment> getAssignmentSupplementItemAttac
* @param params
* @return
*/
private HashMap<String,String> getRubricConfigurationParameters(ParameterParser params, Assignment.GradeType gradeType){
private Map<String,String> getRubricConfigurationParameters(ParameterParser params, Assignment.GradeType gradeType){

HashMap<String,String> parametersHash = new HashMap<>();
Map<String,String> parametersHash = new HashMap<>();
//Get the parameters
Iterator it2 = params.getNames();
while (it2.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@
</div>
<div role="tabpanel" class="tab-pane" id="rubric">
<sakai-rubric-grading
token="$!rbcs-token"
site-id="$!assignment.Context"
tool-id="sakai.assignment"
entity-id="$assignment.Id"
evaluated-item-id="$submission.Id"
Expand Down Expand Up @@ -864,7 +864,6 @@
</div>
<input type="hidden" id="grade-is-released" name="grade-is-released" value="$submission.getGradeReleased()" />
<input type="hidden" name="sakai_csrf_token" value="$sakai_csrf_token"/>
<input type="hidden" name="rbcs-token" value="$!rbcs-token"/>
</form>
</div>
<!-- end: check_assignments_instructor_grading_submission.vm -->
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
current-student-id="$!submitterId"
has-associated-rubric="$!hasAssociatedRubric"
#if ($!hasAssociatedRubric)
token="$!rbcs-token"
tool-id="sakai.assignment"
entity-id="$assignment.Id"
evaluated-item-id="$submission.Id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,17 @@ function printView(url) {
#else
$!service.getGradeForSubmitter($submission, $userSubmission.User.Id)
#end
#if ($rubricId)
<sakai-rubric-student-button
dont-check-association
token="$!rbcs-token"
tool-id="sakai.assignment"
evaluated-item-id="$submission.Id"
entity-id="$assignment.Id"
instructor="true">
rubric-id="$rubricId"
site-id="$assignment.context"
dont-check-association
tool-id="sakai.assignment"
evaluated-item-id="$submission.Id"
entity-id="$assignment.Id"
instructor="true">
</sakai-rubric-student-button>
#end
</td>
#end
#if ($isTimesheet && $assignment.Estimate && !$assignment.Estimate.equals(""))
Expand Down Expand Up @@ -818,31 +821,7 @@ function printView(url) {
}
});


var assignmentId ="$assignment.Id";
var rubricsToken = "$!rbcs-token";

if (assignmentId && rubricsToken) {
const options = {
method: "GET",
headers: {
"Authorization": `Bearer ${rubricsToken}`,
"Accept": "application/json",
"Content-Type": "application/json"
}
};

fetch(`/rubrics-service/rest/rubric-associations/search/by-tool-and-assignment?toolId=sakai.assignment&itemId=${assignmentId}`, options)
.then(r => r.json())
.then(data => {

const association = data._embedded["rubric-associations"][0];

if (association) {
[...document.getElementsByTagName("sakai-rubric-student-button")].forEach(b => b.hidden = false);
}
});
}
ASN.enableLinks();
}); // document.ready
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,6 @@ function showExternalIframe(title, doreload) {
#buttonBar()
</div>
<input type="hidden" name="sakai_csrf_token" value="$sakai_csrf_token" />
<input type="hidden" name="rbcs-token" value="$!rbcs-token"/>
</form>
</div>
<!-- end: chef_assignments_instructor_new_edit_assignment.vm -->
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,11 @@

#assignmentIcons($assignment)

#if ($rubricsService.hasAssociatedRubric("sakai.assignment", $assignment.getId()))
#if ($rubricMap.get($assignment.getId()))
<sakai-rubric-student-button
token="$!rbcs-token"
tool-id="sakai.assignment"
evaluated-item-id="$submission.Id"
entity-id="$assignment.Id"
force-preview
rubric-id="$rubricMap.get($assignment.getId())"
site-id="$assignment.getContext()"
instructor="true">
</sakai-rubric-student-button>
#end
Expand Down Expand Up @@ -313,9 +312,10 @@
#end
$formattedText.escapeHtml($assignment.Title)</a>
#assignmentIcons($assignment)
#if ($rubricsService.hasAssociatedRubric("sakai.assignment", $assignment.getId()))
#if ($rubricMap.get($assignment.getId()))
<sakai-rubric-student-button
token="$!rbcs-token"
site-id="$assignment.getContext()"
rubric-id="$rubricMap.get($assignment.getId())"
tool-id="sakai.assignment"
evaluated-item-id="$submission.Id"
entity-id="$assignment.Id">
Expand All @@ -324,9 +324,10 @@
#else
$formattedText.escapeHtml($assignment.Title)
#assignmentIcons($assignment)
#if ($rubricsService.hasAssociatedRubric("sakai.assignment", $assignment.getId()))
#if ($rubricMap.get($assignment.getId()))
<sakai-rubric-student-button
token="$!rbcs-token"
site-id="$assignment.getContext()"
rubric-id="$rubricMap.get($assignment.getId())"
tool-id="sakai.assignment"
evaluated-item-id="$submission.Id"
entity-id="$assignment.Id">
Expand Down Expand Up @@ -403,7 +404,7 @@
#set($submissionId=$submission.Id)
#end
<sakai-rubric-student-button
token="$!rbcs-token"
site-id="$assignment.getContext()"
tool-id="sakai.assignment"
evaluated-item-id="$submissionId"
entity-id="$assignment.Id">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@

#if ($submission.Graded && ($submission.GradeReleased || $returned))
<sakai-rubric-student
token="$!rbcs-token"
tool-id="sakai.assignment"
entity-id="$assignment.Id"
evaluated-item-id="$submission.Id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,11 @@ $(document).ready(function(){
#supplementItems($!allowViewModelAnswer $!allowReadAssignmentNoteItem $!allowViewAllPurposeItem $!assignmentModelAnswerItem $!assignmentNoteItem $!assignmentAllPurposeItem)

<sakai-rubric-student-preview-button
token="$!rbcs-token"
tool-id="sakai.assignment"
entity-id="$assignment.Id"></sakai-rubric-student-preview-button>

#if ($submission.Graded && ($submission.GradeReleased || $returned))
<sakai-rubric-student
token="$!rbcs-token"
tool-id="sakai.assignment"
entity-id="$assignment.Id"
evaluated-item-id="$submission.Id"
Expand Down
Loading

0 comments on commit 3c99296

Please sign in to comment.