| 1 | package edu.ucsb.cs156.frontiers.enums; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.annotation.JsonCreator; | |
| 4 | import com.fasterxml.jackson.annotation.JsonFormat; | |
| 5 | import com.fasterxml.jackson.databind.JsonNode; | |
| 6 | import java.util.List; | |
| 7 | import lombok.Getter; | |
| 8 | ||
| 9 | @Getter | |
| 10 | @JsonFormat(shape = JsonFormat.Shape.OBJECT) | |
| 11 | public enum School { | |
| 12 | CHICO_STATE( | |
| 13 | "Chico State", | |
| 14 | List.of("Chico State University", "Chico State", "CSUCS"), | |
| 15 | "https://canvas.csuchico.edu/api/graphql"), | |
| 16 | OREGON_STATE( | |
| 17 | "Oregon State University", | |
| 18 | List.of("Oregon State University", "Oregon State", "OSU"), | |
| 19 | "https://canvas.oregonstate.edu/api/graphql"), | |
| 20 | UCSB( | |
| 21 | "UCSB", | |
| 22 | List.of("UC Santa Barbara", "University of California, Santa Barbara", "SB"), | |
| 23 | "https://ucsb.instructure.com/api/graphql"); | |
| 24 | ||
| 25 | private School(String displayName, List<String> alternateNames, String canvasImplementation) { | |
| 26 | this.displayName = displayName; | |
| 27 | this.alternateNames = alternateNames; | |
| 28 | this.canvasImplementation = canvasImplementation; | |
| 29 | } | |
| 30 | ||
| 31 | private final List<String> alternateNames; | |
| 32 | private final String canvasImplementation; | |
| 33 | private final String displayName; | |
| 34 | private final String key = this.name(); | |
| 35 | ||
| 36 | /* | |
| 37 | * This is mostly to allow tests to serialize back in objects with school properties. | |
| 38 | */ | |
| 39 | @JsonCreator | |
| 40 | public static School fromKey(JsonNode node) { | |
| 41 |
1
1. fromKey : negated conditional → KILLED |
if (node == null) { |
| 42 | return null; | |
| 43 | } | |
| 44 |
1
1. fromKey : negated conditional → KILLED |
if (node.isTextual()) { |
| 45 |
1
1. fromKey : replaced return value with null for edu/ucsb/cs156/frontiers/enums/School::fromKey → KILLED |
return School.valueOf(node.asText().toUpperCase()); |
| 46 | } | |
| 47 |
1
1. fromKey : negated conditional → KILLED |
if (node.has("key")) { |
| 48 |
1
1. fromKey : replaced return value with null for edu/ucsb/cs156/frontiers/enums/School::fromKey → KILLED |
return School.valueOf(node.get("key").asText().toUpperCase()); |
| 49 | } | |
| 50 | ||
| 51 | throw new IllegalArgumentException("Invalid JSON node for School enum"); | |
| 52 | } | |
| 53 | } | |
Mutations | ||
| 41 |
1.1 |
|
| 44 |
1.1 |
|
| 45 |
1.1 |
|
| 47 |
1.1 |
|
| 48 |
1.1 |