
001package ca.uhn.fhir.rest.api; 002 003/* 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2022 Smile CDR, Inc. 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import ca.uhn.fhir.i18n.Msg; 024import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; 025import ca.uhn.fhir.util.UrlUtil; 026 027import java.util.HashMap; 028import java.util.Map; 029 030public enum SearchContainedModeEnum { 031 032 /** 033 * default, search on the non-contained (normal) resources 034 */ 035 FALSE("false"), 036 037 /** 038 * search on the contained resources only 039 */ 040 TRUE("true"), 041 042 /** 043 * Search on the normal resources and contained resources. 044 * This option is not supported yet. 045 */ 046 BOTH("both"); 047 048 private static volatile Map<String, SearchContainedModeEnum> ourCodeToEnum; 049 private final String myCode; 050 051 SearchContainedModeEnum(String theCode) { 052 myCode = theCode; 053 } 054 055 public String getCode() { 056 return myCode; 057 } 058 059 public static SearchContainedModeEnum fromCode(String theCode) { 060 Map<String, SearchContainedModeEnum> codeToEnum = ourCodeToEnum; 061 if (codeToEnum == null) { 062 codeToEnum = new HashMap<>(); 063 for (SearchContainedModeEnum next : values()) { 064 codeToEnum.put(next.getCode(), next); 065 } 066 ourCodeToEnum = codeToEnum; 067 } 068 069 SearchContainedModeEnum retVal = codeToEnum.get(theCode); 070 if (retVal == null) { 071 throw new InvalidRequestException(Msg.code(1963) + "Invalid contained mode: " + UrlUtil.sanitizeUrlPart(theCode)); 072 } 073 074 return retVal; 075 } 076 077}