001package ca.uhn.fhir.rest.server.interceptor; 002 003/*- 004 * #%L 005 * HAPI FHIR - Server Framework 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.context.FhirContext; 024import ca.uhn.fhir.context.support.IValidationSupport; 025import ca.uhn.fhir.rest.api.server.RequestDetails; 026import ca.uhn.fhir.util.BundleUtil; 027import org.apache.commons.lang3.Validate; 028import org.hl7.fhir.instance.model.api.IBaseBundle; 029import org.hl7.fhir.instance.model.api.IBaseResource; 030 031import javax.annotation.Nonnull; 032import java.util.Collections; 033import java.util.List; 034 035public class BaseResponseTerminologyInterceptor { 036 protected final IValidationSupport myValidationSupport; 037 protected final FhirContext myContext; 038 039 /** 040 * Constructor 041 * 042 * @param theValidationSupport The validation support module 043 */ 044 public BaseResponseTerminologyInterceptor(@Nonnull IValidationSupport theValidationSupport) { 045 myValidationSupport = theValidationSupport; 046 Validate.notNull(theValidationSupport, "The validation support must not be null"); 047 048 myContext = theValidationSupport.getFhirContext(); 049 Validate.notNull(myContext, "The validation support must not return a null context"); 050 } 051 052 053 @Nonnull 054 protected List<IBaseResource> toListForProcessing(RequestDetails theRequestDetails, IBaseResource theResource) { 055 056 switch (theRequestDetails.getRestOperationType()) { 057 // Don't apply to these operations 058 case ADD_TAGS: 059 case DELETE_TAGS: 060 case GET_TAGS: 061 case GET_PAGE: 062 case GRAPHQL_REQUEST: 063 case EXTENDED_OPERATION_SERVER: 064 case EXTENDED_OPERATION_TYPE: 065 case EXTENDED_OPERATION_INSTANCE: 066 case CREATE: 067 case DELETE: 068 case TRANSACTION: 069 case UPDATE: 070 case VALIDATE: 071 case METADATA: 072 case META_ADD: 073 case META: 074 case META_DELETE: 075 case PATCH: 076 default: 077 return Collections.emptyList(); 078 079 // Do apply to these operations 080 case HISTORY_INSTANCE: 081 case HISTORY_SYSTEM: 082 case HISTORY_TYPE: 083 case SEARCH_SYSTEM: 084 case SEARCH_TYPE: 085 case READ: 086 case VREAD: 087 break; 088 } 089 090 List<IBaseResource> resources; 091 if (theResource instanceof IBaseBundle) { 092 resources = BundleUtil.toListOfResources(myContext, (IBaseBundle) theResource); 093 } else { 094 resources = Collections.singletonList(theResource); 095 } 096 return resources; 097 } 098 099}