Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.wise.portal.presentation.web.controllers.peergroup;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.wise.portal.domain.peergroup.PeerGroup;
import org.wise.portal.domain.user.User;
import org.wise.portal.service.peergroup.PeerGroupService;
import org.wise.portal.service.peergrouping.PeerGroupingService;
import org.wise.portal.service.run.RunService;
import org.wise.portal.service.user.UserService;

abstract class AbstractPeerGroupAPIController {
@Autowired
protected PeerGroupingService peerGroupingService;

@Autowired
protected PeerGroupService peerGroupService;

@Autowired
protected RunService runService;

@Autowired
protected UserService userService;

protected boolean isUserInPeerGroup(PeerGroup peerGroup, Authentication auth) {
User user = userService.retrieveUserByUsername(auth.getName());
return peerGroup.isMember(user);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.wise.portal.presentation.web.controllers.peergroup;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wise.portal.domain.peergroup.PeerGroup;
import org.wise.portal.domain.peergroup.impl.PeerGroupImpl;
import org.wise.portal.domain.peergrouping.PeerGrouping;
import org.wise.portal.domain.run.Run;
import org.wise.portal.domain.run.impl.RunImpl;
import org.wise.portal.domain.user.User;
import org.wise.portal.domain.workgroup.Workgroup;
import org.wise.portal.domain.workgroup.impl.WorkgroupImpl;
import org.wise.portal.service.peergroup.PeerGroupCreationException;
import org.wise.portal.service.peergrouping.PeerGroupingNotFoundException;
import org.wise.portal.service.vle.wise5.AnnotationService;
import org.wise.portal.service.workgroup.WorkgroupService;
import org.wise.vle.domain.annotation.wise5.Annotation;

@RestController
@Secured("ROLE_USER")
@RequestMapping("/api/peer-group")
public class PeerGroupAnnotationsAPIController extends AbstractPeerGroupAPIController {
@Autowired
private AnnotationService annotationService;

@Autowired
private WorkgroupService workgroupService;

@GetMapping("/{peerGroupId}/{nodeId}/{componentId}/annotations")
List<Annotation> getPeerGroupAnnotations(@PathVariable("peerGroupId") PeerGroupImpl peerGroup,
@PathVariable String nodeId, @PathVariable String componentId, Authentication auth) {
if (isUserInPeerGroup(peerGroup, auth)) {
Set<Workgroup> workgroups = peerGroup.getMembers();
workgroups.addAll(getTeacherWorkgroups(peerGroup.getPeerGrouping().getRun()));
return annotationService.getAnnotationsToWorkgroups(workgroups, nodeId, componentId);
} else {
throw new AccessDeniedException("Not permitted");
}
}

@Secured("ROLE_TEACHER")
@GetMapping("/{runId}/{workgroupId}/{nodeId}/{componentId}/annotations")
List<Annotation> getPeerGroupAnnotations(@PathVariable("runId") RunImpl run,
@PathVariable("workgroupId") WorkgroupImpl workgroup, @PathVariable String nodeId,
@PathVariable String componentId, Authentication auth)
throws JSONException, PeerGroupingNotFoundException, PeerGroupCreationException {
User user = userService.retrieveUserByUsername(auth.getName());
if (runService.isAllowedToViewStudentWork(run, user)) {
PeerGrouping peerGrouping = peerGroupingService.getByComponent(run, nodeId, componentId);
PeerGroup peerGroup = peerGroupService.getPeerGroup(workgroup, peerGrouping);
Set<Workgroup> workgroups = peerGroup.getMembers();
workgroups.addAll(getTeacherWorkgroups(run));
return annotationService.getAnnotationsToWorkgroups(workgroups, nodeId, componentId);
} else {
throw new AccessDeniedException("Not permitted");
}
}

List<Workgroup> getTeacherWorkgroups(Run run) {
List<Workgroup> teacherWorkgroups = new ArrayList<Workgroup>();
User runOwner = run.getOwner();
List<Workgroup> workgroupsForRunOwner = workgroupService.getWorkgroupListByRunAndUser(run,
runOwner);
teacherWorkgroups.addAll(workgroupsForRunOwner);
for (User sharedOwner : run.getSharedowners()) {
List<Workgroup> sharedTeacherWorkgroups = workgroupService.getWorkgroupListByRunAndUser(run,
sharedOwner);
teacherWorkgroups.addAll(sharedTeacherWorkgroups);
}
return teacherWorkgroups;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.List;

import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.Authentication;
Expand All @@ -18,29 +17,13 @@
import org.wise.portal.domain.user.User;
import org.wise.portal.domain.workgroup.impl.WorkgroupImpl;
import org.wise.portal.service.peergroup.PeerGroupCreationException;
import org.wise.portal.service.peergroup.PeerGroupService;
import org.wise.portal.service.peergrouping.PeerGroupingNotFoundException;
import org.wise.portal.service.peergrouping.PeerGroupingService;
import org.wise.portal.service.run.RunService;
import org.wise.portal.service.user.UserService;
import org.wise.vle.domain.work.StudentWork;

@RestController
@Secured("ROLE_USER")
@RequestMapping("/api/peer-group")
public class PeerGroupWorkAPIController {

@Autowired
private PeerGroupingService peerGroupingService;

@Autowired
private PeerGroupService peerGroupService;

@Autowired
private RunService runService;

@Autowired
private UserService userService;
public class PeerGroupWorkAPIController extends AbstractPeerGroupAPIController {

@GetMapping("/{peerGroupId}/{nodeId}/{componentId}/student-work")
List<StudentWork> getPeerGroupWork(@PathVariable("peerGroupId") PeerGroupImpl peerGroup,
Expand All @@ -52,21 +35,15 @@ List<StudentWork> getPeerGroupWork(@PathVariable("peerGroupId") PeerGroupImpl pe
}
}

private boolean isUserInPeerGroup(PeerGroup peerGroup, Authentication auth) {
User user = userService.retrieveUserByUsername(auth.getName());
return peerGroup.isMember(user);
}

@Secured("ROLE_TEACHER")
@GetMapping("/{runId}/{workgroupId}/{nodeId}/{componentId}/student-work")
List<StudentWork> getPeerGroupWork(@PathVariable("runId") RunImpl run,
@PathVariable("workgroupId") WorkgroupImpl workgroup,
@PathVariable String nodeId, @PathVariable String componentId, Authentication auth)
@PathVariable("workgroupId") WorkgroupImpl workgroup, @PathVariable String nodeId,
@PathVariable String componentId, Authentication auth)
throws JSONException, PeerGroupingNotFoundException, PeerGroupCreationException {
User user = userService.retrieveUserByUsername(auth.getName());
if (runService.isAllowedToViewStudentWork(run, user)) {
PeerGrouping peerGrouping = peerGroupingService.getByComponent(run, nodeId,
componentId);
PeerGrouping peerGrouping = peerGroupingService.getByComponent(run, nodeId, componentId);
PeerGroup peerGroup = peerGroupService.getPeerGroup(workgroup, peerGrouping);
return peerGroupService.getStudentWork(peerGroup, nodeId, componentId);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,38 @@

public interface PeerGroupService {

/**
* Gets the PeerGroup with the specified id
* @param id Long PeerGroup's id
* @return matched PeerGroup
* @throws ObjectNotFoundException when PeerGroup with the given id is not found
*/
public PeerGroup getById(Long id) throws ObjectNotFoundException;
/**
* Gets the PeerGroup with the specified id
* @param id Long PeerGroup's id
* @return matched PeerGroup
* @throws ObjectNotFoundException when PeerGroup with the given id is not found
*/
public PeerGroup getById(Long id) throws ObjectNotFoundException;

/**
* Gets a PeerGroup for the specified workgroup and PeerGrouping if a PeerGroup
* does not exist, create one.
*
* @param workgroup Workgroup to get/create the PeerGroup for
* @param peerGrouping PeerGrouping to get/create the PeerGroup for
* @return PeerGroup for the specified workgroup and PeerGrouping
* @throws PeerGroupCreationException the PeerGroup cannot be created for other reasons
* like an error occurred while grouping members
*/
PeerGroup getPeerGroup(Workgroup workgroup, PeerGrouping peerGrouping)
throws PeerGroupCreationException;
/**
* Gets a PeerGroup for the specified workgroup and PeerGrouping if a PeerGroup
* does not exist, create one.
*
* @param workgroup Workgroup to get/create the PeerGroup for
* @param peerGrouping PeerGrouping to get/create the PeerGroup for
* @return PeerGroup for the specified workgroup and PeerGrouping
* @throws PeerGroupCreationException the PeerGroup cannot be created for other reasons
* like an error occurred while grouping members
*/
PeerGroup getPeerGroup(Workgroup workgroup, PeerGrouping peerGrouping)
throws PeerGroupCreationException;

/**
* Gets all the PeerGroups for the specified PeerGrouping
* @param peerGrouping PeerGrouping the PeerGroups works on
* @return PeerGroups that work on the specified PeerGrouping
*/
List<PeerGroup> getPeerGroups(PeerGrouping peerGrouping);
/**
* Gets all the PeerGroups for the specified PeerGrouping
* @param peerGrouping PeerGrouping the PeerGroups works on
* @return PeerGroups that work on the specified PeerGrouping
*/
List<PeerGroup> getPeerGroups(PeerGrouping peerGrouping);

/**
* Gets StudentWork for the component from all the members in the PeerGroup
* @param peerGroup group of workgroups in the PeerGroup
* @return List of StudentWork by members in the PeerGroup for the component
*/
public List<StudentWork> getStudentWork(PeerGroup peerGroup, String nodeId, String componentId);
/**
* Gets StudentWork for the component from all the members in the PeerGroup
* @param peerGroup group of workgroups in the PeerGroup
* @return List of StudentWork by members in the PeerGroup for the component
*/
public List<StudentWork> getStudentWork(PeerGroup peerGroup, String nodeId, String componentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ public interface AnnotationService {
*/
List<Annotation> getLatest(Set<Workgroup> workgroups, String nodeId, String componentId,
String type);

List<Annotation> getAnnotationsToWorkgroups(Set<Workgroup> workgroups, String nodeId,
String componentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ public List<Annotation> getLatest(Set<Workgroup> workgroups, String nodeId, Stri
}
return new ArrayList<Annotation>(workgroupToAnnotation.values());
}

public List<Annotation> getAnnotationsToWorkgroups(Set<Workgroup> workgroups, String nodeId,
String componentId) {
return annotationDao.getAnnotationsToWorkgroups(workgroups, nodeId, componentId);
}
}