Start work on subscription cleanup

This commit is contained in:
jamesagnew 2020-04-02 05:31:12 -04:00
parent 08c1c28f67
commit e1142f4043
17 changed files with 167 additions and 277 deletions

View File

@ -27,12 +27,15 @@ import ca.uhn.fhir.model.dstu2.valueset.ResourceTypeEnum;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;
@Service
@Primary
public class DaoSearchParamProvider implements ISearchParamProvider {
@Autowired
private PlatformTransactionManager myTxManager;
@Autowired

View File

@ -20,8 +20,15 @@ package ca.uhn.fhir.jpa.searchparam.config;
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.searchparam.extractor.ISearchParamExtractor;
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorDstu2;
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorDstu3;
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorR4;
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorR5;
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
import ca.uhn.fhir.jpa.searchparam.registry.SearchParamRegistryImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@ -30,7 +37,29 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@Configuration
@EnableScheduling
@ComponentScan(basePackages = {"ca.uhn.fhir.jpa.searchparam"})
abstract public class BaseSearchParamConfig {
public class SearchParamConfig {
@Autowired
private FhirContext myFhirContext;
@Bean
public ISearchParamExtractor searchParamExtractor() {
switch (myFhirContext.getVersion().getVersion()) {
case DSTU2:
return new SearchParamExtractorDstu2();
case DSTU3:
return new SearchParamExtractorDstu3();
case R4:
return new SearchParamExtractorR4();
case R5:
return new SearchParamExtractorR5();
case DSTU2_HL7ORG:
case DSTU2_1:
default:
throw new IllegalStateException("Can not handle version: " + myFhirContext.getVersion().getVersion());
}
}
@Bean
public ISearchParamRegistry searchParamRegistry() {

View File

@ -1,55 +0,0 @@
package ca.uhn.fhir.jpa.searchparam.config;
/*-
* #%L
* HAPI FHIR Search Parameters
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.ParserOptions;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorDstu2;
import ca.uhn.fhir.context.support.DefaultProfileValidationSupport;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
public class SearchParamDstu2Config extends BaseSearchParamConfig {
@Bean
@Primary
public FhirContext fhirContextDstu2() {
FhirContext retVal = FhirContext.forDstu2();
// Don't strip versions in some places
ParserOptions parserOptions = retVal.getParserOptions();
parserOptions.setDontStripVersionsFromReferencesAtPaths("AuditEvent.entity.reference");
return retVal;
}
@Bean(autowire = Autowire.BY_TYPE)
public SearchParamExtractorDstu2 searchParamExtractor() {
return new SearchParamExtractorDstu2();
}
@Primary
@Bean(autowire = Autowire.BY_NAME, name = "myJpaValidationSupportChain")
public IValidationSupport validationSupportChainDstu2() {
return new DefaultProfileValidationSupport(fhirContextDstu2());
}
}

View File

@ -1,47 +0,0 @@
package ca.uhn.fhir.jpa.searchparam.config;
/*-
* #%L
* HAPI FHIR Search Parameters
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.ParserOptions;
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorDstu3;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
public class SearchParamDstu3Config extends BaseSearchParamConfig {
@Bean
@Primary
public FhirContext fhirContextDstu3() {
FhirContext retVal = FhirContext.forDstu3();
// Don't strip versions in some places
ParserOptions parserOptions = retVal.getParserOptions();
parserOptions.setDontStripVersionsFromReferencesAtPaths("AuditEvent.entity.reference");
return retVal;
}
@Bean(autowire = Autowire.BY_TYPE)
public SearchParamExtractorDstu3 searchParamExtractor() {
return new SearchParamExtractorDstu3();
}
}

View File

@ -1,47 +0,0 @@
package ca.uhn.fhir.jpa.searchparam.config;
/*-
* #%L
* HAPI FHIR Search Parameters
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.ParserOptions;
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorR4;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
public class SearchParamR4Config extends BaseSearchParamConfig {
@Bean
@Primary
public FhirContext fhirContextR4() {
FhirContext retVal = FhirContext.forR4();
// Don't strip versions in some places
ParserOptions parserOptions = retVal.getParserOptions();
parserOptions.setDontStripVersionsFromReferencesAtPaths("AuditEvent.entity.reference");
return retVal;
}
@Bean(autowire = Autowire.BY_TYPE)
public SearchParamExtractorR4 searchParamExtractor() {
return new SearchParamExtractorR4();
}
}

View File

@ -20,31 +20,51 @@ package ca.uhn.fhir.jpa.subscription.module.config;
* #L%
*/
import ca.uhn.fhir.interceptor.executor.InterceptorService;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.jpa.searchparam.config.SearchParamConfig;
import ca.uhn.fhir.jpa.subscription.module.cache.LinkedBlockingQueueSubscribableChannelFactory;
import ca.uhn.fhir.jpa.subscription.module.channel.ISubscribableChannelFactory;
import ca.uhn.fhir.jpa.subscription.module.channel.SubscriptionChannelFactory;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.annotation.EnableScheduling;
@Configuration
@Import({SearchParamConfig.class})
@EnableScheduling
@ComponentScan(basePackages = {"ca.uhn.fhir.jpa.subscription.module"})
public abstract class BaseSubscriptionConfig {
@ComponentScan(
basePackages = {"ca.uhn.fhir.jpa.subscription.module"},
excludeFilters = {
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "ca.uhn.fhir.jpa.subscription.module.standalone.*")
}
)
public class SubscriptionConfig {
@Autowired
private FhirContext myFhirContext;
@Primary
@Bean(autowire = Autowire.BY_NAME, name = "myJpaValidationSupportChain")
public IValidationSupport validationSupportChainR4() {
return myFhirContext.getValidationSupport();
}
@Bean
public ISubscribableChannelFactory subscribableChannelFactory() {
return new LinkedBlockingQueueSubscribableChannelFactory();
}
@Bean
public InterceptorService interceptorRegistry() {
return new InterceptorService("hapi-fhir-jpa-subscription");
}
@Bean
public SubscriptionChannelFactory subscriptionChannelFactory() {
return new SubscriptionChannelFactory();
}
}

View File

@ -1,29 +0,0 @@
package ca.uhn.fhir.jpa.subscription.module.config;
/*-
* #%L
* HAPI FHIR Subscription Server
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import ca.uhn.fhir.jpa.searchparam.config.SearchParamDstu2Config;
import ca.uhn.fhir.jpa.searchparam.config.SearchParamDstu3Config;
import org.springframework.context.annotation.Import;
@Import({SearchParamDstu2Config.class})
public class SubscriptionDstu2Config extends BaseSubscriptionConfig {
}

View File

@ -1,39 +0,0 @@
package ca.uhn.fhir.jpa.subscription.module.config;
/*-
* #%L
* HAPI FHIR Subscription Server
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.jpa.searchparam.config.SearchParamDstu3Config;
import ca.uhn.fhir.context.support.DefaultProfileValidationSupport;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
@Import({SearchParamDstu3Config.class})
public class SubscriptionDstu3Config extends BaseSubscriptionConfig {
@Primary
@Bean(autowire = Autowire.BY_NAME, name = "myJpaValidationSupportChain")
public IValidationSupport validationSupportChainDstu3() {
return new DefaultProfileValidationSupport(FhirContext.forDstu3());
}
}

View File

@ -1,40 +0,0 @@
package ca.uhn.fhir.jpa.subscription.module.config;
/*-
* #%L
* HAPI FHIR Subscription Server
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.jpa.searchparam.config.SearchParamR4Config;
import ca.uhn.fhir.context.support.DefaultProfileValidationSupport;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
@Import({SearchParamR4Config.class})
public class SubscriptionR4Config extends BaseSubscriptionConfig {
@Primary
@Bean(autowire = Autowire.BY_NAME, name = "myJpaValidationSupportChain")
public IValidationSupport validationSupportChainR4() {
return new DefaultProfileValidationSupport(FhirContext.forR4());
}
}

View File

@ -32,7 +32,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class FhirClientResourceRetriever implements IResourceRetriever {
private static final Logger ourLog = LoggerFactory.getLogger(FhirClientResourceRetriever.class);

View File

@ -37,12 +37,14 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class FhirClientSearchParamProvider implements ISearchParamProvider {
private static final Logger ourLog = LoggerFactory.getLogger(FhirClientSearchParamProvider.class);
private IGenericClient myClient;
/**
* Constructor
*/
@Autowired
public FhirClientSearchParamProvider(IGenericClient theClient) {
myClient = theClient;

View File

@ -35,7 +35,6 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class FhirClientSubscriptionProvider implements ISubscriptionProvider {
@Autowired
private FhirContext myFhirContext;

View File

@ -0,0 +1,62 @@
package ca.uhn.fhir.jpa.subscription.module.standalone;
/*-
* #%L
* HAPI FHIR Subscription Server
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import ca.uhn.fhir.rest.client.api.IGenericClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
// FIXME: rename
@Configuration
public class StandaloneSubscriptionConfig {
/**
* Constructor
*/
public StandaloneSubscriptionConfig() {
super();
}
@Autowired
private IGenericClient myClient;
@Bean
public FhirClientResourceRetriever fhirClientResourceRetriever() {
return new FhirClientResourceRetriever();
}
@Bean
public FhirClientSearchParamProvider fhirClientSearchParamProvider() {
return new FhirClientSearchParamProvider(myClient);
}
@Bean
public FhirClientSubscriptionProvider fhirClientSubscriptionProvider() {
return new FhirClientSubscriptionProvider(myClient);
}
@Bean
public StandaloneSubscriptionMessageHandler fhirClientSubscriptionMessageHandler() {
return new StandaloneSubscriptionMessageHandler();
}
}

View File

@ -39,7 +39,6 @@ import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Service;
@Service
public class StandaloneSubscriptionMessageHandler implements MessageHandler {
private static final Logger ourLog = LoggerFactory.getLogger(StandaloneSubscriptionMessageHandler.class);

View File

@ -1,22 +1,23 @@
package ca.uhn.fhir.jpa.subscription.module.config;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.interceptor.executor.InterceptorService;
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.subscription.module.matcher.ISubscriptionMatcher;
import ca.uhn.fhir.jpa.subscription.module.matcher.InMemorySubscriptionMatcher;
import ca.uhn.fhir.jpa.subscription.module.standalone.StandaloneSubscriptionConfig;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.test.utilities.UnregisterScheduledProcessor;
import org.mockito.Mockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.TestPropertySource;
@Configuration
@TestPropertySource(properties = {
"scheduling_disabled=true"
})
public class TestSubscriptionConfig {
@Import(StandaloneSubscriptionConfig.class)
public class TestSubscriptionConfig extends SubscriptionConfig {
@Bean
public ModelConfig modelConfig() {
@ -24,7 +25,7 @@ public class TestSubscriptionConfig {
}
@Bean
public IGenericClient fhirClient(FhirContext theFhirContext) {
public IGenericClient fhirClient() {
return Mockito.mock(IGenericClient.class);
};
@ -33,4 +34,9 @@ public class TestSubscriptionConfig {
return new InMemorySubscriptionMatcher();
}
@Bean
public InterceptorService interceptorRegistry() {
return new InterceptorService("hapi-fhir-jpa-subscription");
}
}

View File

@ -1,8 +1,11 @@
package ca.uhn.fhir.jpa.subscription.module.config;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.api.IDaoRegistry;
import ca.uhn.fhir.jpa.model.sched.ISchedulerService;
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamProvider;
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
import ca.uhn.fhir.jpa.searchparam.registry.SearchParamRegistryImpl;
import ca.uhn.fhir.jpa.subscription.module.cache.ISubscriptionProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -14,8 +17,13 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@Configuration
@Import(TestSubscriptionConfig.class)
public class TestSubscriptionDstu3Config extends SubscriptionDstu3Config {
public class TestSubscriptionDstu3Config extends TestSubscriptionConfig {
@Bean
public FhirContext fhirContext() {
return FhirContext.forDstu3();
}
@Bean
@Primary
public ISearchParamProvider searchParamProvider() {

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.rest.server.interceptor;
/*-
* #%L
* HAPI FHIR - Server Framework
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import ca.uhn.fhir.interceptor.api.Hook;
import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.rest.api.server.RequestDetails;