Search in sources :

Example 1 with Group

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());
}
Also used : Group(com.instructure.canvasapi.model.Group) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 2 with Group

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());
}
Also used : Group(com.instructure.canvasapi.model.Group) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 3 with Group

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;
}
Also used : Group(com.instructure.canvasapi.model.Group) LongSparseArray(android.support.v4.util.LongSparseArray) User(com.instructure.canvasapi.model.User) Submission(com.instructure.canvasapi.model.Submission) ArrayList(java.util.ArrayList)

Aggregations

Group (com.instructure.canvasapi.model.Group)3 Gson (com.google.gson.Gson)2 Test (org.junit.Test)2 LongSparseArray (android.support.v4.util.LongSparseArray)1 Submission (com.instructure.canvasapi.model.Submission)1 User (com.instructure.canvasapi.model.User)1 ArrayList (java.util.ArrayList)1