| 1 | package edu.ucsb.cs156.frontiers.services; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.databind.DeserializationFeature; | |
| 4 | import com.fasterxml.jackson.databind.JsonNode; | |
| 5 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 6 | import edu.ucsb.cs156.frontiers.entities.Course; | |
| 7 | import edu.ucsb.cs156.frontiers.entities.RosterStudent; | |
| 8 | import edu.ucsb.cs156.frontiers.models.CanvasGroup; | |
| 9 | import edu.ucsb.cs156.frontiers.models.CanvasGroupDetail; | |
| 10 | import edu.ucsb.cs156.frontiers.models.CanvasGroupSet; | |
| 11 | import edu.ucsb.cs156.frontiers.models.CanvasGroupSetDetail; | |
| 12 | import edu.ucsb.cs156.frontiers.models.CanvasStudent; | |
| 13 | import edu.ucsb.cs156.frontiers.utilities.CanonicalFormConverter; | |
| 14 | import edu.ucsb.cs156.frontiers.validators.HasLinkedCanvasCourse; | |
| 15 | import java.util.ArrayList; | |
| 16 | import java.util.LinkedHashMap; | |
| 17 | import java.util.List; | |
| 18 | import java.util.Map; | |
| 19 | import org.springframework.graphql.client.ClientGraphQlResponse; | |
| 20 | import org.springframework.graphql.client.GraphQlClient; | |
| 21 | import org.springframework.graphql.client.HttpSyncGraphQlClient; | |
| 22 | import org.springframework.http.MediaType; | |
| 23 | import org.springframework.stereotype.Service; | |
| 24 | import org.springframework.validation.annotation.Validated; | |
| 25 | import org.springframework.web.client.RestClient; | |
| 26 | ||
| 27 | /** | |
| 28 | * Service for interacting with the Canvas API. | |
| 29 | * | |
| 30 | * <p>Note that the Canvas API uses a GraphQL endpoint, which allows for more flexible queries | |
| 31 | * compared to traditional REST APIs. | |
| 32 | * | |
| 33 | * <p>For more information on the Canvas API, visit the official documentation at <a | |
| 34 | * href="https://canvas.instructure.com/doc/api/">...</a>. | |
| 35 | * | |
| 36 | * <p>You can typically interact with Canvas API GraphQL endpoints interactively by appending | |
| 37 | * /graphiql to the URL of the Canvas instance. | |
| 38 | * | |
| 39 | * <p>For example, for UCSB Canvas, use: <a href="https://ucsb.instructure.com/graphiql">...</a> | |
| 40 | * | |
| 41 | * <p>Every Canvas GraphQL connection is paginated: without a {@code first} argument Canvas returns | |
| 42 | * only the first page (20 items by default), and it never returns more than {@link #PAGE_SIZE} per | |
| 43 | * request. Every connection read here therefore asks for {@link #PAGE_SIZE} items and follows | |
| 44 | * {@code pageInfo.endCursor} until {@code hasNextPage} is false. | |
| 45 | */ | |
| 46 | @Service | |
| 47 | @Validated | |
| 48 | public class CanvasService { | |
| 49 | ||
| 50 | /** The largest page Canvas allows (its default_max_page_size). */ | |
| 51 | static final int PAGE_SIZE = 100; | |
| 52 | ||
| 53 | private HttpSyncGraphQlClient graphQlClient; | |
| 54 | private RestClient restClient; | |
| 55 | private ObjectMapper mapper; | |
| 56 | private CanvasApiTokenSecurityService canvasApiTokenSecurityService; | |
| 57 | ||
| 58 | public CanvasService( | |
| 59 | ObjectMapper mapper, | |
| 60 | RestClient.Builder builder, | |
| 61 | CanvasApiTokenSecurityService canvasApiTokenSecurityService) { | |
| 62 | this.graphQlClient = HttpSyncGraphQlClient.builder(builder.build()).build(); | |
| 63 | this.restClient = builder.build(); | |
| 64 | this.mapper = mapper; | |
| 65 | this.mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | |
| 66 | this.canvasApiTokenSecurityService = canvasApiTokenSecurityService; | |
| 67 | } | |
| 68 | ||
| 69 | public List<CanvasGroupSet> getCanvasGroupSets(@HasLinkedCanvasCourse Course course) { | |
| 70 | // language=GraphQL | |
| 71 | String query = | |
| 72 | """ | |
| 73 | query GetGroupSets($courseId: ID!) { | |
| 74 | course(id: $courseId) { | |
| 75 | groupSets { | |
| 76 | _id | |
| 77 | name | |
| 78 | id | |
| 79 | } | |
| 80 | } | |
| 81 | } | |
| 82 | """; | |
| 83 | ||
| 84 | HttpSyncGraphQlClient authedClient = authedClient(course); | |
| 85 | ||
| 86 | List<CanvasGroupSet> groupSets = | |
| 87 | authedClient | |
| 88 | .document(query) | |
| 89 | .variable("courseId", course.getCanvasCourseId()) | |
| 90 | .retrieveSync("course.groupSets") | |
| 91 | .toEntityList(CanvasGroupSet.class); | |
| 92 |
1
1. getCanvasGroupSets : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/services/CanvasService::getCanvasGroupSets → KILLED |
return groupSets; |
| 93 | } | |
| 94 | ||
| 95 | /** | |
| 96 | * Fetches the roster of students from Canvas for the given course, following pagination so that | |
| 97 | * every enrolled student is returned. | |
| 98 | * | |
| 99 | * @param course the Course entity containing canvasApiToken and canvasCourseId | |
| 100 | * @return list of RosterStudent objects from Canvas | |
| 101 | */ | |
| 102 | public List<RosterStudent> getCanvasRoster(@HasLinkedCanvasCourse Course course) { | |
| 103 | String nodeFields = | |
| 104 | """ | |
| 105 | firstName | |
| 106 | lastName | |
| 107 | sisId | |
| 108 | email | |
| 109 | integrationId | |
| 110 | enrollments(courseId: $courseId) { | |
| 111 | section { | |
| 112 | name | |
| 113 | } | |
| 114 | } | |
| 115 | """; | |
| 116 | ||
| 117 | List<CanvasStudent> students = | |
| 118 | studentEdges(course, nodeFields).stream() | |
| 119 |
1
1. lambda$getCanvasRoster$0 : replaced return value with null for edu/ucsb/cs156/frontiers/services/CanvasService::lambda$getCanvasRoster$0 → KILLED |
.map(edge -> toCanvasStudent(edge.get("node"))) |
| 120 | .toList(); | |
| 121 | ||
| 122 |
1
1. getCanvasRoster : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/services/CanvasService::getCanvasRoster → KILLED |
return students.stream() |
| 123 | .map( | |
| 124 | student -> | |
| 125 |
1
1. lambda$getCanvasRoster$1 : replaced return value with null for edu/ucsb/cs156/frontiers/services/CanvasService::lambda$getCanvasRoster$1 → KILLED |
RosterStudent.builder() |
| 126 | .firstName(student.getFirstName()) | |
| 127 | .lastName(student.getLastName()) | |
| 128 | .studentId(student.getStudentId()) | |
| 129 | .email(student.getEmail()) | |
| 130 |
1
1. lambda$getCanvasRoster$1 : negated conditional → KILLED |
.section(student.getSection() != null ? student.getSection() : "") |
| 131 | .build()) | |
| 132 | .toList(); | |
| 133 | } | |
| 134 | ||
| 135 | private CanvasStudent toCanvasStudent(JsonNode userNode) { | |
| 136 | CanvasStudent canvasStudent = mapper.convertValue(userNode, CanvasStudent.class); | |
| 137 | JsonNode enrollments = userNode.path("enrollments"); | |
| 138 |
2
1. toCanvasStudent : negated conditional → KILLED 2. toCanvasStudent : negated conditional → KILLED |
if (enrollments.isArray() && !enrollments.isEmpty()) { |
| 139 | JsonNode sectionName = enrollments.get(0).path("section").path("name"); | |
| 140 |
1
1. toCanvasStudent : negated conditional → KILLED |
if (sectionName.isTextual()) { |
| 141 | String name = sectionName.asText(); | |
| 142 |
1
1. toCanvasStudent : removed call to edu/ucsb/cs156/frontiers/models/CanvasStudent::setSection → KILLED |
canvasStudent.setSection(name.substring(0, Math.min(5, name.length()))); |
| 143 | } | |
| 144 | } | |
| 145 |
1
1. toCanvasStudent : replaced return value with null for edu/ucsb/cs156/frontiers/services/CanvasService::toCanvasStudent → KILLED |
return canvasStudent; |
| 146 | } | |
| 147 | ||
| 148 | /** | |
| 149 | * Fetches the groups in a Canvas group set with their members' emails, as used by the pull-teams | |
| 150 | * job. This is a view of {@link #getCanvasGroupSetDetail}. | |
| 151 | * | |
| 152 | * @param course the course, which must be linked to Canvas | |
| 153 | * @param groupSetId the group set's GraphQL relay id or numeric Canvas id | |
| 154 | * @return the groups, each with its members' canonical emails | |
| 155 | */ | |
| 156 | public List<CanvasGroup> getCanvasGroups( | |
| 157 | @HasLinkedCanvasCourse Course course, String groupSetId) { | |
| 158 | List<CanvasGroup> groups = new ArrayList<>(); | |
| 159 | for (CanvasGroupDetail group : getCanvasGroupSetDetail(course, groupSetId).getGroups()) { | |
| 160 | groups.add( | |
| 161 | CanvasGroup.builder() | |
| 162 | .name(group.getName()) | |
| 163 | .id(group.getId()) | |
| 164 | .members(new ArrayList<>(group.getMemberUserIdsByEmail().keySet())) | |
| 165 | .build()); | |
| 166 | } | |
| 167 |
1
1. getCanvasGroups : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/services/CanvasService::getCanvasGroups → KILLED |
return groups; |
| 168 | } | |
| 169 | ||
| 170 | /** | |
| 171 | * Fetches a Canvas group set with everything the push-to-Canvas job needs: the numeric ids of the | |
| 172 | * group set and its groups, and each group's members as canonical email to numeric Canvas user | |
| 173 | * id. Group membership is paginated, so groups with more than {@link #PAGE_SIZE} members are | |
| 174 | * completed with follow-up queries. | |
| 175 | * | |
| 176 | * @param course the course, which must be linked to Canvas | |
| 177 | * @param groupSetId the group set's GraphQL relay id (as returned by getCanvasGroupSets) or its | |
| 178 | * numeric Canvas id (as shown in Canvas URLs) | |
| 179 | * @return the group set detail | |
| 180 | */ | |
| 181 | public CanvasGroupSetDetail getCanvasGroupSetDetail( | |
| 182 | @HasLinkedCanvasCourse Course course, String groupSetId) { | |
| 183 | String query = | |
| 184 | "query GetGroupSetDetail($groupId: ID!, $first: Int!) { groupSet: " | |
| 185 | + groupSetSelector(groupSetId) | |
| 186 | + """ | |
| 187 | { | |
| 188 | ... on GroupSet { | |
| 189 | _id | |
| 190 | name | |
| 191 | groups { | |
| 192 | _id | |
| 193 | name | |
| 194 | membersConnection(first: $first) { | |
| 195 | edges { | |
| 196 | node { | |
| 197 | user { | |
| 198 | _id | |
| 199 | email | |
| 200 | } | |
| 201 | } | |
| 202 | } | |
| 203 | pageInfo { | |
| 204 | hasNextPage | |
| 205 | endCursor | |
| 206 | } | |
| 207 | } | |
| 208 | } | |
| 209 | } | |
| 210 | } | |
| 211 | } | |
| 212 | """; | |
| 213 | ||
| 214 | HttpSyncGraphQlClient client = authedClient(course); | |
| 215 | JsonNode node = | |
| 216 | client | |
| 217 | .document(query) | |
| 218 | .variable("groupId", groupSetId) | |
| 219 | .variable("first", PAGE_SIZE) | |
| 220 | .retrieveSync("groupSet") | |
| 221 | .toEntity(JsonNode.class); | |
| 222 | ||
| 223 | List<CanvasGroupDetail> groups = new ArrayList<>(); | |
| 224 | for (JsonNode group : node.path("groups")) { | |
| 225 | Integer groupId = group.path("_id").asInt(); | |
| 226 | List<JsonNode> edges = new ArrayList<>(); | |
| 227 |
1
1. getCanvasGroupSetDetail : removed call to com/fasterxml/jackson/databind/JsonNode::forEach → KILLED |
group.path("membersConnection").path("edges").forEach(edges::add); |
| 228 | JsonNode pageInfo = group.path("membersConnection").path("pageInfo"); | |
| 229 |
1
1. getCanvasGroupSetDetail : negated conditional → KILLED |
if (pageInfo.path("hasNextPage").asBoolean()) { |
| 230 | edges.addAll( | |
| 231 | remainingGroupMemberEdges(client, groupId, pageInfo.path("endCursor").asText())); | |
| 232 | } | |
| 233 | Map<String, Integer> members = new LinkedHashMap<>(); | |
| 234 | for (JsonNode edge : edges) { | |
| 235 | JsonNode user = edge.path("node").path("user"); | |
| 236 | members.put( | |
| 237 | CanonicalFormConverter.convertToValidEmail(user.path("email").asText()), | |
| 238 | user.path("_id").asInt()); | |
| 239 | } | |
| 240 | groups.add( | |
| 241 | CanvasGroupDetail.builder() | |
| 242 | .id(groupId) | |
| 243 | .name(group.path("name").asText()) | |
| 244 | .memberUserIdsByEmail(members) | |
| 245 | .build()); | |
| 246 | } | |
| 247 |
1
1. getCanvasGroupSetDetail : replaced return value with null for edu/ucsb/cs156/frontiers/services/CanvasService::getCanvasGroupSetDetail → KILLED |
return CanvasGroupSetDetail.builder() |
| 248 | .id(node.path("_id").asInt()) | |
| 249 | .name(node.path("name").asText()) | |
| 250 | .groups(groups) | |
| 251 | .build(); | |
| 252 | } | |
| 253 | ||
| 254 | /** | |
| 255 | * Fetches the numeric Canvas user id of every student enrolled in the Canvas course, keyed by | |
| 256 | * canonical email, following pagination so that every enrolled student is included. | |
| 257 | * | |
| 258 | * @param course the course, which must be linked to Canvas | |
| 259 | * @return map from canonical email to Canvas user id | |
| 260 | */ | |
| 261 | public Map<String, Integer> getCanvasUserIdsByEmail(@HasLinkedCanvasCourse Course course) { | |
| 262 | Map<String, Integer> userIds = new LinkedHashMap<>(); | |
| 263 | for (JsonNode edge : studentEdges(course, "_id\nemail\n")) { | |
| 264 | JsonNode user = edge.path("node"); | |
| 265 | userIds.put( | |
| 266 | CanonicalFormConverter.convertToValidEmail(user.path("email").asText()), | |
| 267 | user.path("_id").asInt()); | |
| 268 | } | |
| 269 |
1
1. getCanvasUserIdsByEmail : replaced return value with Collections.emptyMap for edu/ucsb/cs156/frontiers/services/CanvasService::getCanvasUserIdsByEmail → KILLED |
return userIds; |
| 270 | } | |
| 271 | ||
| 272 | /** | |
| 273 | * Creates a group in a Canvas group set. | |
| 274 | * | |
| 275 | * @param course the course, which must be linked to Canvas | |
| 276 | * @param groupSetId the numeric Canvas id of the group set | |
| 277 | * @param name the name of the new group | |
| 278 | * @return the numeric Canvas id of the new group | |
| 279 | * @throws RuntimeException if Canvas reports a validation error | |
| 280 | */ | |
| 281 | public Integer createCanvasGroup( | |
| 282 | @HasLinkedCanvasCourse Course course, Integer groupSetId, String name) { | |
| 283 | // language=GraphQL | |
| 284 | String mutation = | |
| 285 | """ | |
| 286 | mutation CreateGroup($groupSetId: ID!, $name: String!) { | |
| 287 | createGroupInSet(input: {groupSetId: $groupSetId, name: $name}) { | |
| 288 | group { | |
| 289 | _id | |
| 290 | } | |
| 291 | errors { | |
| 292 | message | |
| 293 | } | |
| 294 | } | |
| 295 | } | |
| 296 | """; | |
| 297 | ||
| 298 | ClientGraphQlResponse response = | |
| 299 | authedClient(course) | |
| 300 | .document(mutation) | |
| 301 | .variable("groupSetId", groupSetId.toString()) | |
| 302 | .variable("name", name) | |
| 303 | .executeSync(); | |
| 304 | JsonNode payload = response.field("createGroupInSet").toEntity(JsonNode.class); | |
| 305 | JsonNode errors = payload.path("errors"); | |
| 306 |
2
1. createCanvasGroup : negated conditional → KILLED 2. createCanvasGroup : negated conditional → KILLED |
if (errors.isArray() && !errors.isEmpty()) { |
| 307 | throw new RuntimeException( | |
| 308 | "Canvas refused to create group " + name + ": " + errors.get(0).path("message").asText()); | |
| 309 | } | |
| 310 |
1
1. createCanvasGroup : replaced Integer return value with 0 for edu/ucsb/cs156/frontiers/services/CanvasService::createCanvasGroup → KILLED |
return payload.path("group").path("_id").asInt(); |
| 311 | } | |
| 312 | ||
| 313 | /** | |
| 314 | * Deletes a Canvas group. | |
| 315 | * | |
| 316 | * @param course the course, which must be linked to Canvas | |
| 317 | * @param groupId the numeric Canvas id of the group | |
| 318 | */ | |
| 319 | public void deleteCanvasGroup(@HasLinkedCanvasCourse Course course, Integer groupId) { | |
| 320 | restClient | |
| 321 | .delete() | |
| 322 | .uri(restBaseUrl(course) + "/groups/" + groupId) | |
| 323 | .header("Authorization", bearer(course)) | |
| 324 | .retrieve() | |
| 325 | .toBodilessEntity(); | |
| 326 | } | |
| 327 | ||
| 328 | /** | |
| 329 | * Adds a user to a Canvas group. | |
| 330 | * | |
| 331 | * @param course the course, which must be linked to Canvas | |
| 332 | * @param groupId the numeric Canvas id of the group | |
| 333 | * @param userId the numeric Canvas id of the user | |
| 334 | */ | |
| 335 | public void addCanvasGroupMember( | |
| 336 | @HasLinkedCanvasCourse Course course, Integer groupId, Integer userId) { | |
| 337 | restClient | |
| 338 | .post() | |
| 339 | .uri(restBaseUrl(course) + "/groups/" + groupId + "/memberships") | |
| 340 | .header("Authorization", bearer(course)) | |
| 341 | .contentType(MediaType.APPLICATION_JSON) | |
| 342 | .body(Map.of("user_id", userId)) | |
| 343 | .retrieve() | |
| 344 | .toBodilessEntity(); | |
| 345 | } | |
| 346 | ||
| 347 | /** | |
| 348 | * Removes a user from a Canvas group. | |
| 349 | * | |
| 350 | * @param course the course, which must be linked to Canvas | |
| 351 | * @param groupId the numeric Canvas id of the group | |
| 352 | * @param userId the numeric Canvas id of the user | |
| 353 | */ | |
| 354 | public void removeCanvasGroupMember( | |
| 355 | @HasLinkedCanvasCourse Course course, Integer groupId, Integer userId) { | |
| 356 | restClient | |
| 357 | .delete() | |
| 358 | .uri(restBaseUrl(course) + "/groups/" + groupId + "/users/" + userId) | |
| 359 | .header("Authorization", bearer(course)) | |
| 360 | .retrieve() | |
| 361 | .toBodilessEntity(); | |
| 362 | } | |
| 363 | ||
| 364 | /** | |
| 365 | * Fetches every edge of the course's student enrollment connection, following pagination. | |
| 366 | * | |
| 367 | * @param course the course | |
| 368 | * @param nodeFields the GraphQL fields to select on each user node | |
| 369 | * @return all edges, in Canvas order | |
| 370 | */ | |
| 371 | private List<JsonNode> studentEdges(Course course, String nodeFields) { | |
| 372 | String query = | |
| 373 | "query GetStudents($courseId: ID!, $first: Int!, $after: String) {" | |
| 374 | + " course(id: $courseId) {" | |
| 375 | + " usersConnection(filter: {enrollmentTypes: StudentEnrollment}, first: $first," | |
| 376 | + " after: $after) { edges { node { " | |
| 377 | + nodeFields | |
| 378 | + " } } pageInfo { hasNextPage endCursor } } } }"; | |
| 379 |
1
1. studentEdges : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/services/CanvasService::studentEdges → KILLED |
return allEdges( |
| 380 | authedClient(course), | |
| 381 | query, | |
| 382 | Map.of("courseId", course.getCanvasCourseId()), | |
| 383 | "course.usersConnection", | |
| 384 | null); | |
| 385 | } | |
| 386 | ||
| 387 | /** | |
| 388 | * Fetches the members of one group that did not fit in the first page of the group set query. | |
| 389 | * | |
| 390 | * @param client the authenticated client | |
| 391 | * @param groupId the numeric Canvas id of the group | |
| 392 | * @param after the end cursor of the page already read | |
| 393 | * @return the remaining edges | |
| 394 | */ | |
| 395 | private List<JsonNode> remainingGroupMemberEdges( | |
| 396 | HttpSyncGraphQlClient client, Integer groupId, String after) { | |
| 397 | // language=GraphQL | |
| 398 | String query = | |
| 399 | """ | |
| 400 | query GetGroupMembers($groupId: ID!, $first: Int!, $after: String) { | |
| 401 | legacyNode(_id: $groupId, type: Group) { | |
| 402 | ... on Group { | |
| 403 | membersConnection(first: $first, after: $after) { | |
| 404 | edges { | |
| 405 | node { | |
| 406 | user { | |
| 407 | _id | |
| 408 | email | |
| 409 | } | |
| 410 | } | |
| 411 | } | |
| 412 | pageInfo { | |
| 413 | hasNextPage | |
| 414 | endCursor | |
| 415 | } | |
| 416 | } | |
| 417 | } | |
| 418 | } | |
| 419 | } | |
| 420 | """; | |
| 421 |
1
1. remainingGroupMemberEdges : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/services/CanvasService::remainingGroupMemberEdges → KILLED |
return allEdges( |
| 422 | client, | |
| 423 | query, | |
| 424 | Map.of("groupId", groupId.toString()), | |
| 425 | "legacyNode.membersConnection", | |
| 426 | after); | |
| 427 | } | |
| 428 | ||
| 429 | /** | |
| 430 | * Reads a paginated connection to the end. The query must declare {@code $first: Int!} and {@code | |
| 431 | * $after: String}, pass them to the connection, and select {@code pageInfo { hasNextPage | |
| 432 | * endCursor }} on it. | |
| 433 | * | |
| 434 | * @param client the authenticated client | |
| 435 | * @param query the query | |
| 436 | * @param variables the query's other variables | |
| 437 | * @param connectionPath the path of the connection in the response | |
| 438 | * @param after the cursor to start after, or null to start at the beginning | |
| 439 | * @return every edge from {@code after} to the end, in order | |
| 440 | */ | |
| 441 | private static List<JsonNode> allEdges( | |
| 442 | HttpSyncGraphQlClient client, | |
| 443 | String query, | |
| 444 | Map<String, Object> variables, | |
| 445 | String connectionPath, | |
| 446 | String after) { | |
| 447 | List<JsonNode> edges = new ArrayList<>(); | |
| 448 | while (true) { | |
| 449 | GraphQlClient.RequestSpec request = | |
| 450 | client.document(query).variables(variables).variable("first", PAGE_SIZE); | |
| 451 |
1
1. allEdges : negated conditional → KILLED |
if (after != null) { |
| 452 | request = request.variable("after", after); | |
| 453 | } | |
| 454 | JsonNode connection = request.retrieveSync(connectionPath).toEntity(JsonNode.class); | |
| 455 |
1
1. allEdges : removed call to com/fasterxml/jackson/databind/JsonNode::forEach → KILLED |
connection.path("edges").forEach(edges::add); |
| 456 | JsonNode pageInfo = connection.path("pageInfo"); | |
| 457 |
1
1. allEdges : negated conditional → KILLED |
if (!pageInfo.path("hasNextPage").asBoolean()) { |
| 458 |
1
1. allEdges : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/services/CanvasService::allEdges → KILLED |
return edges; |
| 459 | } | |
| 460 | after = pageInfo.path("endCursor").asText(); | |
| 461 | } | |
| 462 | } | |
| 463 | ||
| 464 | /** | |
| 465 | * The GraphQL field that looks up a group set by the given id. Canvas's {@code node(id:)} takes | |
| 466 | * only the GraphQL relay id (e.g. "R3JvdXBTZXQtMTAx"); a plain numeric id, as shown in Canvas | |
| 467 | * URLs and by the Canvas REST API, must go through {@code legacyNode}. Both forms are accepted so | |
| 468 | * that instructors can paste either. | |
| 469 | * | |
| 470 | * @param groupSetId a relay id or a numeric id | |
| 471 | * @return the field selector, without its selection set | |
| 472 | */ | |
| 473 | static String groupSetSelector(String groupSetId) { | |
| 474 |
1
1. groupSetSelector : negated conditional → KILLED |
if (groupSetId.matches("\\d+")) { |
| 475 |
1
1. groupSetSelector : replaced return value with "" for edu/ucsb/cs156/frontiers/services/CanvasService::groupSetSelector → KILLED |
return "legacyNode(_id: $groupId, type: GroupSet)"; |
| 476 | } | |
| 477 |
1
1. groupSetSelector : replaced return value with "" for edu/ucsb/cs156/frontiers/services/CanvasService::groupSetSelector → KILLED |
return "node(id: $groupId)"; |
| 478 | } | |
| 479 | ||
| 480 | private HttpSyncGraphQlClient authedClient(Course course) { | |
| 481 |
1
1. authedClient : replaced return value with null for edu/ucsb/cs156/frontiers/services/CanvasService::authedClient → KILLED |
return graphQlClient |
| 482 | .mutate() | |
| 483 | .header("Authorization", bearer(course)) | |
| 484 | .url(course.getSchool().getCanvasImplementation()) | |
| 485 | .build(); | |
| 486 | } | |
| 487 | ||
| 488 | private String bearer(Course course) { | |
| 489 |
1
1. bearer : replaced return value with "" for edu/ucsb/cs156/frontiers/services/CanvasService::bearer → KILLED |
return "Bearer " + canvasApiTokenSecurityService.decrypt(course.getCanvasApiToken()); |
| 490 | } | |
| 491 | ||
| 492 | /** | |
| 493 | * The Canvas REST API base for the course's school, derived from the GraphQL endpoint: e.g. | |
| 494 | * https://ucsb.instructure.com/api/graphql becomes https://ucsb.instructure.com/api/v1. | |
| 495 | */ | |
| 496 | private static String restBaseUrl(Course course) { | |
| 497 |
1
1. restBaseUrl : replaced return value with "" for edu/ucsb/cs156/frontiers/services/CanvasService::restBaseUrl → KILLED |
return course.getSchool().getCanvasImplementation().replace("/api/graphql", "/api/v1"); |
| 498 | } | |
| 499 | } | |
Mutations | ||
| 92 |
1.1 |
|
| 119 |
1.1 |
|
| 122 |
1.1 |
|
| 125 |
1.1 |
|
| 130 |
1.1 |
|
| 138 |
1.1 2.2 |
|
| 140 |
1.1 |
|
| 142 |
1.1 |
|
| 145 |
1.1 |
|
| 167 |
1.1 |
|
| 227 |
1.1 |
|
| 229 |
1.1 |
|
| 247 |
1.1 |
|
| 269 |
1.1 |
|
| 306 |
1.1 2.2 |
|
| 310 |
1.1 |
|
| 379 |
1.1 |
|
| 421 |
1.1 |
|
| 451 |
1.1 |
|
| 455 |
1.1 |
|
| 457 |
1.1 |
|
| 458 |
1.1 |
|
| 474 |
1.1 |
|
| 475 |
1.1 |
|
| 477 |
1.1 |
|
| 481 |
1.1 |
|
| 489 |
1.1 |
|
| 497 |
1.1 |