Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Peer Group): Add ability to get manually assigned peer group #77

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
Expand Up @@ -40,6 +40,8 @@ public interface PeerGroupActivity {

String getLogicComponentId() throws JSONException;

String getLogicName() throws JSONException;

String getLogicNodeId() throws JSONException;

int getLogicThresholdCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
*/
@Entity
@Table(name = "peer_group_activities", indexes = {
@Index(columnList = "runId", name = "peer_group_activities_run_id_index")
})
@Index(columnList = "runId", name = "peer_group_activities_run_id_index") })
@Getter
@Setter
public class PeerGroupActivityImpl implements PeerGroupActivity {
Expand All @@ -63,8 +62,8 @@ public class PeerGroupActivityImpl implements PeerGroupActivity {
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id = null;

@ManyToOne(targetEntity = RunImpl.class, cascade = { CascadeType.PERSIST },
fetch = FetchType.LAZY)
@ManyToOne(targetEntity = RunImpl.class, cascade = {
CascadeType.PERSIST }, fetch = FetchType.LAZY)
@JoinColumn(name = "runId", nullable = false)
@JsonIgnore
private Run run;
Expand Down Expand Up @@ -112,4 +111,9 @@ public String getLogicComponentId() throws JSONException {
private JSONObject getFirstLogicJSON() throws JSONException {
return new JSONArray(this.logic).getJSONObject(0);
}

public String getLogicName() throws JSONException {
JSONObject logic = getFirstLogicJSON();
return logic.getString("name");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.wise.portal.presentation.web.controllers.peergroup;

import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.annotation.Secured;
Expand Down Expand Up @@ -69,7 +70,7 @@ public class PeerGroupAPIController {
@GetMapping("/{runId}/{workgroupId}/{nodeId}/{componentId}")
PeerGroup getPeerGroup(@PathVariable Long runId, @PathVariable Long workgroupId,
@PathVariable String nodeId, @PathVariable String componentId, Authentication auth)
throws ObjectNotFoundException, PeerGroupActivityNotFoundException,
throws JSONException, ObjectNotFoundException, PeerGroupActivityNotFoundException,
PeerGroupCreationException, PeerGroupActivityThresholdNotSatisfiedException {
Run run = runService.retrieveById(runId);
Workgroup workgroup = workgroupService.retrieveById(workgroupId);
Expand All @@ -82,7 +83,7 @@ PeerGroup getPeerGroup(@PathVariable Long runId, @PathVariable Long workgroupId,
}

private PeerGroup getPeerGroup(Run run, String nodeId, String componentId, Workgroup workgroup)
throws PeerGroupActivityNotFoundException, PeerGroupCreationException,
throws JSONException, PeerGroupActivityNotFoundException, PeerGroupCreationException,
PeerGroupActivityThresholdNotSatisfiedException {
PeerGroupActivity activity = peerGroupActivityService.getByComponent(run, nodeId, componentId);
return peerGroupService.getPeerGroup(workgroup, activity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand Down Expand Up @@ -66,7 +67,7 @@ private boolean isUserInPeerGroup(PeerGroup peerGroup, Authentication auth) {
@GetMapping("/{runId}/{workgroupId}/{nodeId}/{componentId}/student-work")
List<StudentWork> getPeerGroupWork(@PathVariable Long runId, @PathVariable Long workgroupId,
@PathVariable String nodeId, @PathVariable String componentId, Authentication auth)
throws ObjectNotFoundException, PeerGroupActivityNotFoundException,
throws JSONException, ObjectNotFoundException, PeerGroupActivityNotFoundException,
PeerGroupActivityThresholdNotSatisfiedException, PeerGroupCreationException {
Run run = runService.retrieveById(runId);
User user = userService.retrieveUserByUsername(auth.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.List;

import org.json.JSONException;
import org.wise.portal.dao.ObjectNotFoundException;
import org.wise.portal.domain.peergroup.PeerGroup;
import org.wise.portal.domain.peergroupactivity.PeerGroupActivity;
Expand Down Expand Up @@ -56,8 +57,8 @@ public interface PeerGroupService {
* @throws PeerGroupCreationException the PeerGroup cannot be created for other reasons
* like an error occurred while grouping members
*/
PeerGroup getPeerGroup(Workgroup workgroup, PeerGroupActivity activity)
throws PeerGroupActivityThresholdNotSatisfiedException, PeerGroupCreationException;
PeerGroup getPeerGroup(Workgroup workgroup, PeerGroupActivity activity) throws JSONException,
PeerGroupActivityThresholdNotSatisfiedException, PeerGroupCreationException;

/**
* Gets all the PeerGroups for the specified PeerGroupActivity
Expand All @@ -75,5 +76,6 @@ PeerGroup getPeerGroup(Workgroup workgroup, PeerGroupActivity activity)

public List<StudentWork> getStudentWork(PeerGroup peerGroup, String nodeId, String componentId);

public List<StudentWork> getLatestStudentWork(PeerGroup peerGroup, String nodeId, String componentId);
public List<StudentWork> getLatestStudentWork(PeerGroup peerGroup, String nodeId,
String componentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ public PeerGroup getById(Long id) throws ObjectNotFoundException {

@Override
public PeerGroup getPeerGroup(Workgroup workgroup, PeerGroupActivity activity)
throws PeerGroupActivityThresholdNotSatisfiedException, PeerGroupCreationException {
throws JSONException, PeerGroupActivityThresholdNotSatisfiedException,
PeerGroupCreationException {
PeerGroup peerGroup = peerGroupDao.getByWorkgroupAndActivity(workgroup, activity);
return peerGroup != null ? peerGroup : this.createPeerGroup(workgroup, activity);
if (activity.getLogicName().equals("manual")) {
return peerGroup;
} else {
return peerGroup != null ? peerGroup : this.createPeerGroup(workgroup, activity);
}
}

private PeerGroup createPeerGroup(Workgroup workgroup, PeerGroupActivity activity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.easymock.EasyMock.*;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -80,7 +81,7 @@ public class PeerGroupServiceImplTest extends WISEServiceTest {
@Mock
private StudentWorkDao<StudentWork> studentWorkDao;

PeerGroupActivity activity;
PeerGroupActivity activity, manualActivity;

PeerGroup peerGroup;

Expand All @@ -91,6 +92,7 @@ public void setUp() throws Exception {
super.setUp();
PeerGroupServiceTestHelper testHelper = new PeerGroupServiceTestHelper(run1, run1Component2);
activity = testHelper.activity;
manualActivity = testHelper.manualActivity;
peerGroup = testHelper.peerGroup1;
peerGroups = testHelper.peerGroups;
}
Expand Down Expand Up @@ -175,6 +177,24 @@ public void getPeerGroup_AllThresholdsSatisfiedMoreThan3WorkgroupsLeft_Create2Wo
verifyAll();
}

@Test
public void getPeerGroup_ManualLogicPeerGroupNotExist_ReturnNull() throws Exception {
expectPeerGroupFromDB(null, manualActivity);
replayAll();
assertNull(service.getPeerGroup(run1Workgroup1, manualActivity));
verifyAll();
}

@Test
public void getPeerGroup_ManualLogicPeerGroupExists_ReturnPeerGroup() throws Exception {
PeerGroup peerGroup = new PeerGroupImpl(manualActivity, run1Period1,
new HashSet<Workgroup>(Arrays.asList(run1Workgroup1, run1Workgroup2)));
expectPeerGroupFromDB(peerGroup, manualActivity);
replayAll();
assertEquals(peerGroup, service.getPeerGroup(run1Workgroup1, manualActivity));
verifyAll();
}

@Test
public void getStudentWork_PeerGroupExist_ReturnStudentWorkList() {
expectGetWorkForComponentByWorkgroups();
Expand Down Expand Up @@ -267,6 +287,10 @@ private void expectWorkForLogicComponent(List<StudentWork> workForLogicComponent
}

private void expectPeerGroupFromDB(PeerGroup peerGroup) {
expectPeerGroupFromDB(peerGroup, activity);
}

private void expectPeerGroupFromDB(PeerGroup peerGroup, PeerGroupActivity activity) {
expect(peerGroupDao.getByWorkgroupAndActivity(run1Workgroup1, activity)).andReturn(peerGroup);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
package org.wise.portal.service.peergroup.impl;

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

import org.json.JSONException;
import org.json.JSONObject;
import org.wise.portal.dao.Component;
import org.wise.portal.domain.peergroup.PeerGroup;
Expand All @@ -41,40 +42,68 @@

/**
* @author Hiroki Terashima
* @author Geoffrey Kwan
*/
public class PeerGroupServiceTestHelper extends WISEServiceTest {

String logic = "[{\"name\": \"maximizeDifferentIdeas\"," +
"\"nodeId\": \"" + run1Node1Id + "\", \"componentId\": \"" + run1Component1Id + "\"}]";

int logicThresholdCount = 3;

int logicThresholdPercent = 50;

int maxMembershipCount = 2;

String peerGroupActivityComponentString =
"{\"id\":\"" + run1Component2Id + "\"," +
"\"logic\":" + logic + "," +
"\"logicThresholdCount\":" + logicThresholdCount + "," +
"\"logicThresholdPercent\":" + logicThresholdPercent + "," +
"\"maxMembershipCount\":" + maxMembershipCount + "}";

PeerGroupActivity activity;
PeerGroupActivity activity, manualActivity;

PeerGroup peerGroup1, peerGroup2, peerGroup3;

List<PeerGroup> peerGroups = new ArrayList<PeerGroup>();

public PeerGroupServiceTestHelper(Run run, Component component) throws Exception {
super.setUp();
activity = new PeerGroupActivityImpl(run, component.nodeId,
new ProjectComponent(new JSONObject(peerGroupActivityComponentString)));
Set<Workgroup> members = new HashSet<Workgroup>();
members.add(run1Workgroup1);
members.add(run1Workgroup2);
peerGroup1 = new PeerGroupImpl(activity, run1Period1, members);
activity = createPeerGroupActivity(run, component, run1Component2Id, "maximizeDifferentIdeas",
run1Node1Id, run1Component1Id, 3, 50, 2);
peerGroup1 = new PeerGroupImpl(activity, run1Period1,
new HashSet<Workgroup>(Arrays.asList(run1Workgroup1, run1Workgroup2)));
peerGroups.add(peerGroup1);
peerGroup2 = new PeerGroupImpl(activity, run1Period1, new HashSet<Workgroup>());
manualActivity = createPeerGroupActivity(run, component, run1Component2Id, "manual",
run1Node1Id, run1Component1Id, 2, 50, 2);
}

private PeerGroupActivity createPeerGroupActivity(Run run, Component component, String componentId,
String logicName, String logicNodeId, String logicComponentId, Integer logicThresholdCount,
Integer logicThresholdPercent, Integer maxMembershipCount) throws JSONException {
String peerGroupActivityComponentString = createPeerGroupActivityComponentString(componentId,
logicName, logicNodeId, logicComponentId, logicThresholdCount, logicThresholdPercent,
maxMembershipCount);
return new PeerGroupActivityImpl(run, component.nodeId,
new ProjectComponent(new JSONObject(peerGroupActivityComponentString)));
}

private String createPeerGroupActivityComponentString(String componentId, String logicName,
String logicNodeId, String logicComponentId, Integer logicThresholdCount,
Integer logicThresholdPercent, Integer maxMembershipCount) {
String logic = createLogicString(logicName, logicNodeId, logicComponentId);
return createPeerGroupActivityComponentString(componentId, logic, logicThresholdCount,
logicThresholdPercent, maxMembershipCount);
}

private String createPeerGroupActivityComponentString(String componentId, String logic,
Integer logicThresholdCount, Integer logicThresholdPercent, Integer maxMembershipCount) {
return new StringBuilder()
.append("{")
.append(" \"id\": \"" + componentId + "\",")
.append(" \"logic\": " + logic + ",")
.append(" \"logicThresholdCount\": \"" + logicThresholdCount + "\",")
.append(" \"logicThresholdPercent\": \"" + logicThresholdPercent + "\",")
.append(" \"maxMembershipCount\": \"" + maxMembershipCount + "\"")
.append("}")
.toString();
}

private String createLogicString(String name, String nodeId, String componentId) {
return new StringBuilder()
.append("[")
.append(" {")
.append(" \"name\": \"" + name + "\",")
.append(" \"nodeId\": \"" + nodeId + "\",")
.append(" \"componentId\": \"" + componentId + "\"")
.append(" }")
.append("]")
.toString();
}
}