Skip to content

Commit

Permalink
feat(PeerGroupWork): Return StudentWorkAnnotation for MC Reference Co…
Browse files Browse the repository at this point in the history
…mponent (WISE-Community#235)
  • Loading branch information
hirokiterashima authored Sep 15, 2023
1 parent 97f82f2 commit 4b8dd6d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ public class ProjectComponent {
@Getter
ProjectNode node;

@Getter
String type;

public ProjectComponent(ProjectNode node, JSONObject componentJSON) throws JSONException {
this.node = node;
this.componentJSON = componentJSON;
this.id = componentJSON.getString("id");
this.type = componentJSON.getString("type");
}

public String getString(String key) throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.wise.portal.presentation.web.controllers.peergroup;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -21,6 +22,7 @@
import org.wise.portal.presentation.web.controllers.student.AbstractPeerGroupWorkController;
import org.wise.portal.service.vle.wise5.AnnotationService;
import org.wise.vle.domain.annotation.wise5.Annotation;
import org.wise.vle.domain.work.StudentWork;
import org.wise.vle.domain.work.StudentWorkAnnotation;

import lombok.Getter;
Expand All @@ -37,32 +39,56 @@ public class PeerGroupStudentWorkAnnotationController extends AbstractPeerGroupW
List<StudentWorkAnnotation> getStudentDataForDynamicPrompt(
@PathVariable("peerGroupId") PeerGroupImpl peerGroup, @PathVariable String nodeId,
@PathVariable String componentId, Authentication auth) throws Exception {
return getStudentDataForReferenceComponent(peerGroup, nodeId, componentId, auth,
"dynamicPrompt");
checkPermissions(auth, peerGroup);
return getStudentDataForReferenceComponent(peerGroup, nodeId, componentId, "dynamicPrompt");
}

@GetMapping("/question-bank")
List<StudentWorkAnnotation> getStudentDataForQuestionBank(
@PathVariable("peerGroupId") PeerGroupImpl peerGroup, @PathVariable String nodeId,
@PathVariable String componentId, Authentication auth) throws Exception {
return getStudentDataForReferenceComponent(peerGroup, nodeId, componentId, auth,
"questionBank");
checkPermissions(auth, peerGroup);
return getStudentDataForReferenceComponent(peerGroup, nodeId, componentId, "questionBank");
}

private void checkPermissions(Authentication auth, PeerGroupImpl peerGroup)
throws ObjectNotFoundException {
if (!isUserInPeerGroup(auth, peerGroup)) {
throw new AccessDeniedException("Not permitted");
}
}

private List<StudentWorkAnnotation> getStudentDataForReferenceComponent(PeerGroupImpl peerGroup,
String nodeId, String componentId, Authentication auth, String fieldName) throws Exception {
if (isUserInPeerGroup(auth, peerGroup)) {
ReferenceComponent component = getReferenceComponent(peerGroup.getPeerGrouping().getRun(),
nodeId, componentId, fieldName);
List<Annotation> annotations = annotationService.getLatest(peerGroup.getMembers(),
component.getNodeId(), component.getComponentId(), "autoScore");
return annotations.stream().map(annotation -> new StudentWorkAnnotation(annotation))
.collect(Collectors.toList());
String nodeId, String componentId, String fieldName) throws Exception {
Run run = peerGroup.getPeerGrouping().getRun();
ReferenceComponent component = getReferenceComponent(run, nodeId, componentId, fieldName);
String referenceComponentType = getProjectComponent(run, component.nodeId,
component.componentId).getType();
if (referenceComponentType.equals("MultipleChoice")) {
return getStudentDataForMultipleChoice(peerGroup, component);
} else if (referenceComponentType.equals("OpenResponse")) {
return getStudentDataForOpenResponse(peerGroup, component);
} else {
throw new AccessDeniedException("Not permitted");
return new ArrayList<StudentWorkAnnotation>();
}
}

private List<StudentWorkAnnotation> getStudentDataForMultipleChoice(PeerGroupImpl peerGroup,
ReferenceComponent component) {
List<StudentWork> studentWorkList = studentWorkService.getStudentWork(peerGroup.getMembers(),
component.getNodeId(), component.getComponentId());
return studentWorkList.stream().map(studentWork -> new StudentWorkAnnotation(studentWork))
.collect(Collectors.toList());
}

private List<StudentWorkAnnotation> getStudentDataForOpenResponse(PeerGroupImpl peerGroup,
ReferenceComponent component) {
List<Annotation> annotations = annotationService.getLatest(peerGroup.getMembers(),
component.getNodeId(), component.getComponentId(), "autoScore");
return annotations.stream().map(annotation -> new StudentWorkAnnotation(annotation))
.collect(Collectors.toList());
}

private ReferenceComponent getReferenceComponent(Run run, String nodeId, String componentId,
String fieldName) throws IOException, JSONException, ObjectNotFoundException {
ProjectComponent projectComponent = getProjectComponent(run, nodeId, componentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public StudentWorkAnnotation(Annotation annotation) {
this.studentWork = annotation.getStudentWork();
this.workgroup = annotation.getToWorkgroup();
}

public StudentWorkAnnotation(StudentWork studentWork) {
this.studentWork = studentWork;
this.workgroup = studentWork.getWorkgroup();
}
}

0 comments on commit 4b8dd6d

Please sign in to comment.