Fix test failure in boot

This commit is contained in:
James Agnew 2018-10-03 15:39:19 -04:00
parent 5d5ee78873
commit 6ce9120132
3 changed files with 53 additions and 5 deletions

View File

@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.config;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.i18n.HapiLocalizer;
import ca.uhn.fhir.jpa.dao.DaoRegistry;
import ca.uhn.fhir.jpa.provider.SubscriptionRetriggeringProvider;
import ca.uhn.fhir.jpa.search.*;
import ca.uhn.fhir.jpa.sp.ISearchParamPresenceSvc;
@ -63,6 +64,11 @@ public abstract class BaseConfig implements SchedulingConfigurer {
@Autowired
protected Environment myEnv;
@Bean
public DaoRegistry daoRegistry() {
return new DaoRegistry();
}
@Override
public void configureTasks(@Nonnull ScheduledTaskRegistrar theTaskRegistrar) {
theTaskRegistrar.setTaskScheduler(taskScheduler());

View File

@ -0,0 +1,43 @@
package ca.uhn.fhir.jpa.dao;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import org.apache.commons.lang3.Validate;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
public class DaoRegistry implements ApplicationContextAware {
private ApplicationContext myAppCtx;
@Autowired
private FhirContext myCtx;
private Map<String, IFhirResourceDao<?>> myResourceNameToResourceDao = new HashMap<>();
@Override
public void setApplicationContext(ApplicationContext theApplicationContext) throws BeansException {
myAppCtx = theApplicationContext;
}
@PostConstruct
public void start() {
Map<String, IFhirResourceDao> resourceDaos = myAppCtx.getBeansOfType(IFhirResourceDao.class);
for (IFhirResourceDao nextResourceDao : resourceDaos.values()) {
RuntimeResourceDefinition nextResourceDef = myCtx.getResourceDefinition(nextResourceDao.getResourceType());
myResourceNameToResourceDao.put(nextResourceDef.getName(), nextResourceDao);
}
}
public IFhirResourceDao<?> getResourceDao(String theResourceName) {
IFhirResourceDao<?> retVal = myResourceNameToResourceDao.get(theResourceName);
Validate.notNull(retVal, "No DAO exists for resource type %s", theResourceName);
return retVal;
}
}

View File

@ -89,7 +89,7 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc {
@Autowired
private PlatformTransactionManager myManagedTxManager;
@Autowired
private IFhirSystemDao<?, ?> mySystemDao;
private DaoRegistry myDaoRegistry;
@Autowired
private IPagingProvider myPagingProvider;
@ -170,9 +170,8 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc {
if (newSearch.isPresent()) {
search = newSearch.get();
String resourceType = search.getResourceType();
Class<? extends IBaseResource> type = myContext.getResourceDefinition(resourceType).getImplementingClass();
SearchParameterMap params = search.getSearchParameterMap();
SearchContinuationTask task = new SearchContinuationTask(search, mySystemDao.getDao(type), params, resourceType);
SearchContinuationTask task = new SearchContinuationTask(search, myDaoRegistry.getResourceDao(resourceType), params, resourceType);
myIdToSearchTask.put(search.getUuid(), task);
myExecutor.submit(task);
}