1 /* 2 * Copyright 2019 LINE Corporation 3 * 4 * LINE Corporation licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 17 package com.linecorp.centraldogma.server.metadata; 18 19 import static java.util.Objects.requireNonNull; 20 21 import com.fasterxml.jackson.core.JsonProcessingException; 22 import com.fasterxml.jackson.databind.JsonNode; 23 24 import com.linecorp.centraldogma.internal.Jackson; 25 26 /** 27 * Roles of a {@link User} in a project. 28 */ 29 public enum ProjectRole { 30 OWNER, 31 MEMBER, 32 GUEST, 33 ANONYMOUS; 34 35 /** 36 * Returns a {@link ProjectRole} matched with the specified {@code str}. 37 * 38 * @throws IllegalArgumentException if there is no matched {@link ProjectRole}. 39 */ 40 public static ProjectRole of(String str) { 41 requireNonNull(str, "str"); 42 return valueOf(str.toUpperCase()); 43 } 44 45 /** 46 * Returns a {@link ProjectRole} matched with the specified {@link JsonNode}. 47 * 48 * @throws IllegalArgumentException if there is no matched {@link ProjectRole}. 49 */ 50 public static ProjectRole of(JsonNode node) { 51 requireNonNull(node, "node"); 52 try { 53 return Jackson.treeToValue(node, ProjectRole.class); 54 } catch (JsonProcessingException e) { 55 throw new IllegalArgumentException(e); 56 } 57 } 58 }