
001/* 002 * #%L 003 * HAPI FHIR JPA Server 004 * %% 005 * Copyright (C) 2014 - 2025 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.jpa.dao; 021 022import ca.uhn.fhir.context.support.IValidationSupport; 023import ca.uhn.fhir.context.support.ValidationSupportContext; 024import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoStructureDefinition; 025import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome; 026import ca.uhn.fhir.rest.api.server.RequestDetails; 027import ca.uhn.fhir.rest.api.server.storage.TransactionDetails; 028import jakarta.annotation.Nonnull; 029import org.apache.commons.lang3.Validate; 030import org.hl7.fhir.instance.model.api.IBaseResource; 031import org.springframework.beans.factory.annotation.Autowired; 032 033public class JpaResourceDaoStructureDefinition<T extends IBaseResource> extends BaseHapiFhirResourceDao<T> 034 implements IFhirResourceDaoStructureDefinition<T> { 035 036 @Autowired 037 private IValidationSupport myValidationSupport; 038 039 @Override 040 public T generateSnapshot(T theInput, String theUrl, String theWebUrl, String theName) { 041 T output = (T) myValidationSupport.generateSnapshot( 042 new ValidationSupportContext(myValidationSupport), theInput, theUrl, theWebUrl, theName); 043 Validate.notNull(output); 044 return output; 045 } 046 047 @Override 048 public DaoMethodOutcome update( 049 T theResource, 050 String theMatchUrl, 051 boolean thePerformIndexing, 052 boolean theForceUpdateVersion, 053 RequestDetails theRequest, 054 @Nonnull TransactionDetails theTransactionDetails) { 055 DaoMethodOutcome retVal = super.update( 056 theResource, theMatchUrl, thePerformIndexing, theForceUpdateVersion, theRequest, theTransactionDetails); 057 058 if (!retVal.isNop()) { 059 // We store StructureDefinitions in a non-expiring cache/map 060 // In the event that a StructureDefinition changes, we should invalidate the cache 061 // This is particularly helpful with multi-versioned profiles (e.g. multiple StructureDefinition.version) 062 // We generally assume StructureDefinitions don't change over the IValidationSupport lifetime so this 063 // really shouldn't be happening too often. 064 myValidationSupport.invalidateCaches(); 065 } 066 return retVal; 067 } 068}