use of com.instructure.canvasapi.model.Group in project instructure-android by instructure.
the class GroupUnitTest method myGroupsTest.
@Test
public void myGroupsTest() {
Gson gson = CanvasRestAdapter.getGSONParser();
Group[] groupList = gson.fromJson(myGroupListJSON, Group[].class);
assertNotNull(groupList);
Group group = groupList[0];
assertNotNull(group);
assertNull(group.getDescription());
assertTrue(group.getId() == 91885);
assertTrue(group.getGroupCategoryId() == 22277);
assertFalse(group.isPublic());
assertTrue(group.getMembersCount() == 2);
assertTrue(group.getCourseId() == 969287);
assertNull(group.getAvatarUrl());
// assertNull(group.getRole());
}
use of com.instructure.canvasapi.model.Group in project instructure-android by instructure.
the class GroupUnitTest method courseGroupsTest.
@Test
public void courseGroupsTest() {
Gson gson = CanvasRestAdapter.getGSONParser();
Group[] groupList = gson.fromJson(courseGroupsJSON, Group[].class);
assertNotNull(groupList);
Group group = groupList[0];
assertNotNull(group);
assertNull(group.getDescription());
assertTrue(group.getGroupCategoryId() == 41559);
assertTrue(group.getId() == 175540);
assertFalse(group.isPublic());
assertTrue(group.getMembersCount() == 1);
assertTrue(group.getCourseId() == 1272783);
assertNull(group.getAvatarUrl());
assertNotNull(group.getRole());
}
use of com.instructure.canvasapi.model.Group in project instructure-android by instructure.
the class DocumentActivity method groupSubmissionsByGroupId.
public List<Submission> groupSubmissionsByGroupId(Submission[] submissions, User[] courseStudents) {
LongSparseArray<Group> groupMap = new LongSparseArray<>();
LongSparseArray<Group> studentGroupMap = new LongSparseArray<>();
// Map students to groups
for (Group group : mGroups) {
groupMap.put(group.getId(), group);
for (User user : group.getUsers()) {
studentGroupMap.put(user.getId(), group);
}
}
// Get list of unassigned students
LongSparseArray<User> unassignedStudents = new LongSparseArray<>();
for (User student : courseStudents) {
if (studentGroupMap.indexOfKey(student.getId()) < 0) {
unassignedStudents.put(student.getId(), student);
}
}
LongSparseArray<Submission> groupSubmissionMap = new LongSparseArray<>();
for (Group group : mGroups) groupSubmissionMap.put(group.getId(), null);
List<Submission> individualSubmissions = new ArrayList<>();
List<Submission> emptyGroupSubmissions = new ArrayList<>();
List<Submission> emptyIndividualSubmissions = new ArrayList<>();
for (Submission submission : submissions) {
// Group submissions by group ID
long groupId = submission.getGroup().getId();
// Check for and fix missing group info
if (groupId == 0) {
long userId = submission.getUser_id();
if (studentGroupMap.get(userId) != null) {
Group group = studentGroupMap.get(userId);
submission.setGroup(group);
groupId = group.getId();
}
}
if (groupSubmissionMap.get(groupId) == null) {
// check if we need to increment the graded count
if (UserSubmissionsListAdapter.isGraded(submission)) {
gradedCount++;
}
if (groupId != 0) {
groupSubmissionMap.put(groupId, submission);
} else {
// It's possible the submission belongs to a user who doesn't belong to a group
// in that case, we still want to add that submission to our results and display the username
individualSubmissions.add(submission);
unassignedStudents.remove(submission.getUser_id());
}
} else if (!UserSubmissionsListAdapter.isGraded(groupSubmissionMap.get(groupId)) && UserSubmissionsListAdapter.isGraded(submission)) {
groupSubmissionMap.put(groupId, submission);
}
}
List<Submission> result = new ArrayList<>();
// Add group submissions to result, create empty submissions as necessary
for (int i = 0; i < groupSubmissionMap.size(); i++) {
if (groupSubmissionMap.valueAt(i) != null) {
result.add(groupSubmissionMap.valueAt(i));
} else {
Group group = groupMap.get(groupSubmissionMap.keyAt(i));
emptyGroupSubmissions.add(createEmptySubmissionForGroup(group));
}
}
// Create empty submissions for students not assigned to a group
for (int i = 0; i < unassignedStudents.size(); i++) {
emptyIndividualSubmissions.add(createEmptySubmissionForUser(unassignedStudents.valueAt(i)));
}
result.addAll(individualSubmissions);
result.addAll(emptyGroupSubmissions);
result.addAll(emptyIndividualSubmissions);
return result;
}
Aggregations