fix searchparam not found failure at startup (#2408)

* reproduced and fixed issue reported by Adi

* undoing rearrange
This commit is contained in:
Ken Stevens 2021-02-22 15:09:59 -05:00 committed by GitHub
parent 65c9f5fbf8
commit 0e314a9382
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 7 deletions

View File

@ -34,6 +34,7 @@ import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.searchparam.JpaRuntimeSearchParam;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.util.SearchParameterUtil;
import ca.uhn.fhir.util.StopWatch;
import com.google.common.annotations.VisibleForTesting;
@ -47,19 +48,19 @@ import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static org.apache.commons.lang3.StringUtils.isBlank;
public class SearchParamRegistryImpl implements ISearchParamRegistry, IResourceChangeListener {
private static final Logger ourLog = LoggerFactory.getLogger(SearchParamRegistryImpl.class);
private static final int MAX_MANAGED_PARAM_COUNT = 10000;
private static long REFRESH_INTERVAL = DateUtils.MILLIS_PER_HOUR;
private static final long REFRESH_INTERVAL = DateUtils.MILLIS_PER_HOUR;
@Autowired
private ModelConfig myModelConfig;
@ -74,7 +75,7 @@ public class SearchParamRegistryImpl implements ISearchParamRegistry, IResourceC
private volatile ReadOnlySearchParamCache myBuiltInSearchParams;
private volatile IPhoneticEncoder myPhoneticEncoder;
private volatile JpaSearchParamCache myJpaSearchParamCache = new JpaSearchParamCache();
private final JpaSearchParamCache myJpaSearchParamCache = new JpaSearchParamCache();
private volatile RuntimeSearchParamCache myActiveSearchParams;
@Autowired
@ -282,7 +283,15 @@ public class SearchParamRegistryImpl implements ISearchParamRegistry, IResourceC
@Override
public void handleInit(Collection<IIdType> theResourceIds) {
List<IBaseResource> searchParams = theResourceIds.stream().map(id -> mySearchParamProvider.read(id)).collect(Collectors.toList());
List<IBaseResource> searchParams = new ArrayList<>();
for (IIdType id : theResourceIds) {
try {
IBaseResource searchParam = mySearchParamProvider.read(id);
searchParams.add(searchParam);
} catch (ResourceNotFoundException e) {
ourLog.warn("SearchParameter {} not found. Excluding from list of active search params.", id);
}
}
initializeActiveSearchParams(searchParams);
}

View File

@ -17,8 +17,11 @@ import ca.uhn.fhir.jpa.searchparam.MatchUrlService;
import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryMatchResult;
import ca.uhn.fhir.jpa.searchparam.matcher.InMemoryResourceMatcher;
import ca.uhn.fhir.jpa.searchparam.matcher.SearchParamMatcher;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.SimpleBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.hl7.fhir.r4.model.Enumerations;
import org.hl7.fhir.r4.model.SearchParameter;
@ -62,10 +65,10 @@ public class SearchParamRegistryImplTest {
private static final ReadOnlySearchParamCache ourBuiltInSearchParams = ReadOnlySearchParamCache.fromFhirContext(ourFhirContext);
public static final int TEST_SEARCH_PARAMS = 3;
private static List<ResourceTable> ourEntities;
private static ResourceVersionMap ourResourceVersionMap;
private static final List<ResourceTable> ourEntities;
private static final ResourceVersionMap ourResourceVersionMap;
private static int ourLastId;
private static int ourBuiltinPatientSearchParamCount;
private static final int ourBuiltinPatientSearchParamCount;
static {
ourEntities = new ArrayList<>();
@ -172,6 +175,24 @@ public class SearchParamRegistryImplTest {
mySearchParamRegistry.resetForUnitTest();
}
@Test
void handleInit() {
assertEquals(25, mySearchParamRegistry.getActiveSearchParams("Patient").size());
IdDt idBad = new IdDt("SearchParameter/bad");
when(mySearchParamProvider.read(idBad)).thenThrow(new ResourceNotFoundException("id bad"));
IdDt idGood = new IdDt("SearchParameter/good");
SearchParameter goodSearchParam = buildSearchParameter(Enumerations.PublicationStatus.ACTIVE);
when(mySearchParamProvider.read(idGood)).thenReturn(goodSearchParam);
List<IIdType> idList = new ArrayList<>();
idList.add(idBad);
idList.add(idGood);
mySearchParamRegistry.handleInit(idList);
assertEquals(26, mySearchParamRegistry.getActiveSearchParams("Patient").size());
}
@Test
public void testRefreshAfterExpiry() {
mySearchParamRegistry.requestRefresh();