-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Peer Group): Add endpoint for getting Peer Group (#45)
* feat(Peer Group): Add endpoint to get PeerGroup - Ensure there are at least 2 submissions before pairing * feat(Peer Group): Add endpoint to get PeerGroup - Threshold not met now throws an exception instead of returning null. - Throws PeerGroupCreationException when there are other workgroups to wait for. - Fix issue calculating completion percentage by using float instead of int. * feat(Peer Group): Add endpoint to get PeerGroup - Add id equality test to WorkgroupImpl and PersistentGroup - Changed getNumWorkgroupsInPeerGroup() to get PeerGroup for activity component instead of logic component - Return exception key in ResponseBody
- Loading branch information
1 parent
ad1a14b
commit 5317963
Showing
18 changed files
with
833 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...n/java/org/wise/portal/presentation/web/controllers/peergroup/PeerGroupAPIController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* Copyright (c) 2008-2021 Regents of the University of California (Regents). | ||
* Created by WISE, Graduate School of Education, University of California, Berkeley. | ||
* | ||
* This software is distributed under the GNU General Public License, v3, | ||
* or (at your option) any later version. | ||
* | ||
* Permission is hereby granted, without written agreement and without license | ||
* or royalty fees, to use, copy, modify, and distribute this software and its | ||
* documentation for any purpose, provided that the above copyright notice and | ||
* the following two paragraphs appear in all copies of this software. | ||
* | ||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED | ||
* HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE | ||
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | ||
* | ||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | ||
* SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | ||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | ||
* REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package org.wise.portal.presentation.web.controllers.peergroup; | ||
|
||
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.dao.ObjectNotFoundException; | ||
import org.wise.portal.domain.peergroup.PeerGroup; | ||
import org.wise.portal.domain.peergroupactivity.PeerGroupActivity; | ||
import org.wise.portal.domain.run.Run; | ||
import org.wise.portal.domain.user.User; | ||
import org.wise.portal.domain.workgroup.Workgroup; | ||
import org.wise.portal.service.peergroup.PeerGroupActivityThresholdNotSatisfiedException; | ||
import org.wise.portal.service.peergroup.PeerGroupCreationException; | ||
import org.wise.portal.service.peergroup.PeerGroupService; | ||
import org.wise.portal.service.peergroupactivity.PeerGroupActivityNotFoundException; | ||
import org.wise.portal.service.peergroupactivity.PeerGroupActivityService; | ||
import org.wise.portal.service.run.RunService; | ||
import org.wise.portal.service.user.UserService; | ||
import org.wise.portal.service.workgroup.WorkgroupService; | ||
|
||
@RestController | ||
@Secured("ROLE_USER") | ||
@RequestMapping("/api/peer-group") | ||
public class PeerGroupAPIController { | ||
|
||
@Autowired | ||
private RunService runService; | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@Autowired | ||
private WorkgroupService workgroupService; | ||
|
||
@Autowired | ||
private PeerGroupService peerGroupService; | ||
|
||
@Autowired | ||
private PeerGroupActivityService peerGroupActivityService; | ||
|
||
@GetMapping("/run/{runId}/workgroup/{workgroupId}/node-id/{nodeId}/component-id/{componentId}") | ||
PeerGroup getPeerGroup(@PathVariable Long runId, @PathVariable Long workgroupId, | ||
@PathVariable String nodeId, @PathVariable String componentId, Authentication auth) | ||
throws ObjectNotFoundException, PeerGroupActivityNotFoundException, | ||
PeerGroupCreationException, PeerGroupActivityThresholdNotSatisfiedException { | ||
Run run = runService.retrieveById(runId); | ||
Workgroup workgroup = workgroupService.retrieveById(workgroupId); | ||
User user = userService.retrieveUserByUsername(auth.getName()); | ||
if (workgroupService.isUserInWorkgroupForRun(user, run, workgroup)) { | ||
return getPeerGroup(run, nodeId, componentId, workgroup); | ||
} else { | ||
throw new AccessDeniedException("Not permitted"); | ||
} | ||
} | ||
|
||
private PeerGroup getPeerGroup(Run run, String nodeId, String componentId, Workgroup workgroup) | ||
throws PeerGroupActivityNotFoundException, PeerGroupCreationException, | ||
PeerGroupActivityThresholdNotSatisfiedException { | ||
PeerGroupActivity activity = peerGroupActivityService.getByComponent(run, nodeId, componentId); | ||
return peerGroupService.getPeerGroup(workgroup, activity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/org/wise/portal/service/peergroup/PeerGroupThresholdService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) 2008-2021 Regents of the University of California (Regents). | ||
* Created by WISE, Graduate School of Education, University of California, Berkeley. | ||
* | ||
* This software is distributed under the GNU General Public License, v3, | ||
* or (at your option) any later version. | ||
* | ||
* Permission is hereby granted, without written agreement and without license | ||
* or royalty fees, to use, copy, modify, and distribute this software and its | ||
* documentation for any purpose, provided that the above copyright notice and | ||
* the following two paragraphs appear in all copies of this software. | ||
* | ||
* REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED | ||
* HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE | ||
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | ||
* | ||
* IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | ||
* SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | ||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | ||
* REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package org.wise.portal.service.peergroup; | ||
|
||
import org.wise.portal.domain.group.Group; | ||
import org.wise.portal.domain.peergroupactivity.PeerGroupActivity; | ||
|
||
/** | ||
* @author Hiroki Terashima | ||
*/ | ||
public interface PeerGroupThresholdService { | ||
|
||
/** | ||
* Returns true iff the completion threshold has been satisfied to start creating PeerGroup. | ||
* Completion threshold includes minimum workgroups completed count and percentage | ||
* @param activity PeerGroupActivity for which to test for PeerGroup members | ||
* @param period Group subset of workgroups in the run to test for PeerGroup members | ||
* @return boolean | ||
*/ | ||
public boolean isCompletionThresholdSatisfied(PeerGroupActivity activity, Group period); | ||
|
||
/** | ||
* Returns true iff this workgroup is the last workgroup to be in a PeerGroup (last one left), or | ||
* there are at least two workgroups who have completed the logic step but are not in a PeerGroup | ||
* @param activity PeerGroupActivity for which to test for PeerGroup members | ||
* @param period Group subset of workgroups in the run to test for PeerGroup members | ||
* @return boolean | ||
*/ | ||
public boolean canCreatePeerGroup(PeerGroupActivity activity, Group period); | ||
} |
Oops, something went wrong.