Upgrade subscriptions to use interceptors across the board
This commit is contained in:
parent
de5c01c00d
commit
1c88fd154d
|
@ -1,5 +1,6 @@
|
||||||
package ca.uhn.fhir.context;
|
package ca.uhn.fhir.context;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -324,7 +325,7 @@ public class FhirContext {
|
||||||
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> existing = new HashMap<>();
|
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> existing = new HashMap<>();
|
||||||
ModelScanner.scanVersionPropertyFile(null, nameToType, theVersion, existing);
|
ModelScanner.scanVersionPropertyFile(null, nameToType, theVersion, existing);
|
||||||
|
|
||||||
Map<FhirVersionEnum, Map<String, Class<? extends IBaseResource>>> newVersionToNameToResourceType = new HashMap<FhirVersionEnum, Map<String, Class<? extends IBaseResource>>>();
|
Map<FhirVersionEnum, Map<String, Class<? extends IBaseResource>>> newVersionToNameToResourceType = new HashMap<>();
|
||||||
newVersionToNameToResourceType.putAll(myVersionToNameToResourceType);
|
newVersionToNameToResourceType.putAll(myVersionToNameToResourceType);
|
||||||
newVersionToNameToResourceType.put(theVersion, nameToType);
|
newVersionToNameToResourceType.put(theVersion, nameToType);
|
||||||
myVersionToNameToResourceType = newVersionToNameToResourceType;
|
myVersionToNameToResourceType = newVersionToNameToResourceType;
|
||||||
|
@ -913,16 +914,25 @@ public class FhirContext {
|
||||||
Set<String> resourceNames= new HashSet<>();
|
Set<String> resourceNames= new HashSet<>();
|
||||||
|
|
||||||
if (myNameToResourceDefinition.isEmpty()) {
|
if (myNameToResourceDefinition.isEmpty()) {
|
||||||
|
Properties props = new Properties();
|
||||||
|
try {
|
||||||
|
props.load(myVersion.getFhirVersionPropertiesFile());
|
||||||
|
} catch (IOException theE) {
|
||||||
|
throw new ConfigurationException("Failed to load version properties file");
|
||||||
|
}
|
||||||
|
Enumeration<?> propNames = props.propertyNames();
|
||||||
|
while (propNames.hasMoreElements()){
|
||||||
|
String next = (String) propNames.nextElement();
|
||||||
|
if (next.startsWith("resource.")) {
|
||||||
|
resourceNames.add(next.substring("resource.".length()).trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (RuntimeResourceDefinition next : myNameToResourceDefinition.values()) {
|
for (RuntimeResourceDefinition next : myNameToResourceDefinition.values()) {
|
||||||
resourceNames.add(next.getName());
|
resourceNames.add(next.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Properties versionProperties = new Properties();
|
|
||||||
// versionProperties.load(myVersion.getFhirVersionPropertiesFile());
|
|
||||||
//
|
|
||||||
return Collections.unmodifiableSet(resourceNames);
|
return Collections.unmodifiableSet(resourceNames);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.jpa.dao.*;
|
import ca.uhn.fhir.jpa.dao.*;
|
||||||
import ca.uhn.fhir.jpa.interceptor.RestHookSubscriptionDstu2Interceptor;
|
import ca.uhn.fhir.jpa.subscription.dstu2.RestHookSubscriptionDstu2Interceptor;
|
||||||
import ca.uhn.fhir.jpa.term.HapiTerminologySvcDstu2;
|
import ca.uhn.fhir.jpa.term.HapiTerminologySvcDstu2;
|
||||||
import ca.uhn.fhir.jpa.term.IHapiTerminologySvc;
|
import ca.uhn.fhir.jpa.term.IHapiTerminologySvc;
|
||||||
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
|
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||||
import org.springframework.web.socket.handler.PerConnectionWebSocketHandler;
|
import org.springframework.web.socket.handler.PerConnectionWebSocketHandler;
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.subscription.SubscriptionWebsocketHandlerDstu2;
|
import ca.uhn.fhir.jpa.subscription.dstu2.SubscriptionWebsocketHandlerDstu2;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSocket()
|
@EnableWebSocket()
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoSubscription;
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoSubscription;
|
||||||
import ca.uhn.fhir.jpa.subscription.SubscriptionWebsocketHandlerDstu2;
|
import ca.uhn.fhir.jpa.subscription.dstu2.SubscriptionWebsocketHandlerDstu2;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Subscription;
|
import ca.uhn.fhir.model.dstu2.resource.Subscription;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|
|
@ -40,7 +40,7 @@ import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc;
|
||||||
import ca.uhn.fhir.jpa.dao.ISearchParamRegistry;
|
import ca.uhn.fhir.jpa.dao.ISearchParamRegistry;
|
||||||
import ca.uhn.fhir.jpa.dao.dstu3.SearchParamExtractorDstu3;
|
import ca.uhn.fhir.jpa.dao.dstu3.SearchParamExtractorDstu3;
|
||||||
import ca.uhn.fhir.jpa.dao.dstu3.SearchParamRegistryDstu3;
|
import ca.uhn.fhir.jpa.dao.dstu3.SearchParamRegistryDstu3;
|
||||||
import ca.uhn.fhir.jpa.interceptor.RestHookSubscriptionDstu3Interceptor;
|
import ca.uhn.fhir.jpa.subscription.dstu3.RestHookSubscriptionDstu3Interceptor;
|
||||||
import ca.uhn.fhir.jpa.provider.dstu3.TerminologyUploaderProviderDstu3;
|
import ca.uhn.fhir.jpa.provider.dstu3.TerminologyUploaderProviderDstu3;
|
||||||
import ca.uhn.fhir.jpa.term.HapiTerminologySvcDstu3;
|
import ca.uhn.fhir.jpa.term.HapiTerminologySvcDstu3;
|
||||||
import ca.uhn.fhir.jpa.term.IHapiTerminologyLoaderSvc;
|
import ca.uhn.fhir.jpa.term.IHapiTerminologyLoaderSvc;
|
||||||
|
|
|
@ -23,7 +23,6 @@ package ca.uhn.fhir.jpa.config.dstu3;
|
||||||
import org.springframework.beans.factory.annotation.Autowire;
|
import org.springframework.beans.factory.annotation.Autowire;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
import org.springframework.scheduling.TaskScheduler;
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
@ -33,8 +32,8 @@ import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||||
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||||
import org.springframework.web.socket.handler.PerConnectionWebSocketHandler;
|
import org.springframework.web.socket.handler.PerConnectionWebSocketHandler;
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.interceptor.WebSocketSubscriptionDstu3Interceptor;
|
import ca.uhn.fhir.jpa.subscription.dstu3.WebSocketSubscriptionDstu3Interceptor;
|
||||||
import ca.uhn.fhir.jpa.subscription.SubscriptionWebsocketHandlerDstu3;
|
import ca.uhn.fhir.jpa.subscription.dstu3.SubscriptionWebsocketHandlerDstu3;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoSubscription;
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoSubscription;
|
||||||
import ca.uhn.fhir.jpa.subscription.SubscriptionWebsocketHandlerDstu3;
|
import ca.uhn.fhir.jpa.subscription.dstu3.SubscriptionWebsocketHandlerDstu3;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class WebsocketDstu3DispatcherConfig {
|
public class WebsocketDstu3DispatcherConfig {
|
||||||
|
|
|
@ -34,7 +34,7 @@ import ca.uhn.fhir.jpa.config.BaseConfig;
|
||||||
import ca.uhn.fhir.jpa.dao.*;
|
import ca.uhn.fhir.jpa.dao.*;
|
||||||
import ca.uhn.fhir.jpa.dao.r4.SearchParamExtractorR4;
|
import ca.uhn.fhir.jpa.dao.r4.SearchParamExtractorR4;
|
||||||
import ca.uhn.fhir.jpa.dao.r4.SearchParamRegistryR4;
|
import ca.uhn.fhir.jpa.dao.r4.SearchParamRegistryR4;
|
||||||
import ca.uhn.fhir.jpa.interceptor.r4.RestHookSubscriptionR4Interceptor;
|
import ca.uhn.fhir.jpa.subscription.r4.RestHookSubscriptionR4Interceptor;
|
||||||
import ca.uhn.fhir.jpa.provider.r4.TerminologyUploaderProviderR4;
|
import ca.uhn.fhir.jpa.provider.r4.TerminologyUploaderProviderR4;
|
||||||
import ca.uhn.fhir.jpa.term.*;
|
import ca.uhn.fhir.jpa.term.*;
|
||||||
import ca.uhn.fhir.jpa.term.HapiTerminologySvcR4;
|
import ca.uhn.fhir.jpa.term.HapiTerminologySvcR4;
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.springframework.web.socket.WebSocketHandler;
|
||||||
import org.springframework.web.socket.config.annotation.*;
|
import org.springframework.web.socket.config.annotation.*;
|
||||||
import org.springframework.web.socket.handler.PerConnectionWebSocketHandler;
|
import org.springframework.web.socket.handler.PerConnectionWebSocketHandler;
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.interceptor.r4.WebSocketSubscriptionR4Interceptor;
|
import ca.uhn.fhir.jpa.subscription.r4.WebSocketSubscriptionR4Interceptor;
|
||||||
import ca.uhn.fhir.jpa.subscription.r4.SubscriptionWebsocketHandlerR4;
|
import ca.uhn.fhir.jpa.subscription.r4.SubscriptionWebsocketHandlerR4;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||||
|
|
||||||
|
|
|
@ -20,26 +20,15 @@ package ca.uhn.fhir.jpa.dao;
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
import ca.uhn.fhir.context.ConfigurationException;
|
||||||
|
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||||
import java.util.*;
|
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||||
|
import ca.uhn.fhir.context.RuntimeSearchParam;
|
||||||
import javax.annotation.PostConstruct;
|
import ca.uhn.fhir.jpa.dao.data.IResourceHistoryTableDao;
|
||||||
import javax.persistence.NoResultException;
|
import ca.uhn.fhir.jpa.dao.data.IResourceLinkDao;
|
||||||
import javax.persistence.TypedQuery;
|
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
|
||||||
|
import ca.uhn.fhir.jpa.dao.data.ISearchResultDao;
|
||||||
import org.apache.commons.lang3.Validate;
|
|
||||||
import org.hl7.fhir.instance.model.api.*;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Required;
|
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import ca.uhn.fhir.context.*;
|
|
||||||
import ca.uhn.fhir.jpa.dao.data.*;
|
|
||||||
import ca.uhn.fhir.jpa.entity.*;
|
import ca.uhn.fhir.jpa.entity.*;
|
||||||
import ca.uhn.fhir.jpa.interceptor.IJpaServerInterceptor;
|
|
||||||
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
||||||
import ca.uhn.fhir.jpa.util.DeleteConflict;
|
import ca.uhn.fhir.jpa.util.DeleteConflict;
|
||||||
import ca.uhn.fhir.jpa.util.StopWatch;
|
import ca.uhn.fhir.jpa.util.StopWatch;
|
||||||
|
@ -47,7 +36,10 @@ import ca.uhn.fhir.jpa.util.jsonpatch.JsonPatchUtils;
|
||||||
import ca.uhn.fhir.jpa.util.xmlpatch.XmlPatchUtils;
|
import ca.uhn.fhir.jpa.util.xmlpatch.XmlPatchUtils;
|
||||||
import ca.uhn.fhir.model.api.*;
|
import ca.uhn.fhir.model.api.*;
|
||||||
import ca.uhn.fhir.model.primitive.IdDt;
|
import ca.uhn.fhir.model.primitive.IdDt;
|
||||||
import ca.uhn.fhir.rest.api.*;
|
import ca.uhn.fhir.rest.api.PatchTypeEnum;
|
||||||
|
import ca.uhn.fhir.rest.api.QualifiedParamList;
|
||||||
|
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||||
|
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
|
||||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
import ca.uhn.fhir.rest.param.ParameterUtil;
|
import ca.uhn.fhir.rest.param.ParameterUtil;
|
||||||
|
@ -56,35 +48,49 @@ import ca.uhn.fhir.rest.server.exceptions.*;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor;
|
import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor;
|
||||||
import ca.uhn.fhir.rest.server.method.MethodUtil;
|
|
||||||
import ca.uhn.fhir.rest.server.method.SearchMethodBinding;
|
import ca.uhn.fhir.rest.server.method.SearchMethodBinding;
|
||||||
import ca.uhn.fhir.util.*;
|
import ca.uhn.fhir.util.FhirTerser;
|
||||||
|
import ca.uhn.fhir.util.ObjectUtil;
|
||||||
|
import ca.uhn.fhir.util.OperationOutcomeUtil;
|
||||||
|
import ca.uhn.fhir.util.ResourceReferenceInfo;
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
import org.hl7.fhir.instance.model.api.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Required;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||||
|
|
||||||
@Transactional(propagation = Propagation.REQUIRED)
|
@Transactional(propagation = Propagation.REQUIRED)
|
||||||
public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends BaseHapiFhirDao<T> implements IFhirResourceDao<T> {
|
public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends BaseHapiFhirDao<T> implements IFhirResourceDao<T> {
|
||||||
|
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseHapiFhirResourceDao.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseHapiFhirResourceDao.class);
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private DaoConfig myDaoConfig;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected PlatformTransactionManager myPlatformTransactionManager;
|
protected PlatformTransactionManager myPlatformTransactionManager;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
protected IResourceTableDao myResourceTableDao;
|
||||||
|
@Autowired(required = false)
|
||||||
|
protected IFulltextSearchSvc mySearchDao;
|
||||||
|
@Autowired()
|
||||||
|
protected ISearchResultDao mySearchResultDao;
|
||||||
|
@Autowired
|
||||||
|
private DaoConfig myDaoConfig;
|
||||||
|
@Autowired
|
||||||
private IResourceHistoryTableDao myResourceHistoryTableDao;
|
private IResourceHistoryTableDao myResourceHistoryTableDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IResourceLinkDao myResourceLinkDao;
|
private IResourceLinkDao myResourceLinkDao;
|
||||||
private String myResourceName;
|
private String myResourceName;
|
||||||
@Autowired
|
|
||||||
protected IResourceTableDao myResourceTableDao;
|
|
||||||
private Class<T> myResourceType;
|
private Class<T> myResourceType;
|
||||||
@Autowired(required = false)
|
|
||||||
protected IFulltextSearchSvc mySearchDao;
|
|
||||||
@Autowired()
|
|
||||||
protected ISearchResultDao mySearchResultDao;
|
|
||||||
|
|
||||||
private String mySecondaryPrimaryKeyParamName;
|
private String mySecondaryPrimaryKeyParamName;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm, String theLabel) {
|
public void addTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm, String theLabel) {
|
||||||
StopWatch w = new StopWatch();
|
StopWatch w = new StopWatch();
|
||||||
|
@ -94,10 +100,10 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
}
|
}
|
||||||
|
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
for (BaseTag next : new ArrayList<BaseTag>(entity.getTags())) {
|
for (BaseTag next : new ArrayList<>(entity.getTags())) {
|
||||||
if (ObjectUtil.equals(next.getTag().getTagType(), theTagType) &&
|
if (ObjectUtil.equals(next.getTag().getTagType(), theTagType) &&
|
||||||
ObjectUtil.equals(next.getTag().getSystem(), theScheme) &&
|
ObjectUtil.equals(next.getTag().getSystem(), theScheme) &&
|
||||||
ObjectUtil.equals(next.getTag().getCode(), theTerm)) {
|
ObjectUtil.equals(next.getTag().getCode(), theTerm)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,10 +119,10 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
myEntityManager.merge(entity);
|
myEntityManager.merge(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ourLog.info("Processed addTag {}/{} on {} in {}ms", new Object[] { theScheme, theTerm, theId, w.getMillisAndRestart() });
|
ourLog.info("Processed addTag {}/{} on {} in {}ms", new Object[]{theScheme, theTerm, theId, w.getMillisAndRestart()});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DaoMethodOutcome create(final T theResource) {
|
public DaoMethodOutcome create(final T theResource) {
|
||||||
return create(theResource, null, true, null);
|
return create(theResource, null, true, null);
|
||||||
|
@ -182,9 +188,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
T resourceToDelete = toResource(myResourceType, entity, false);
|
T resourceToDelete = toResource(myResourceType, entity, false);
|
||||||
|
|
||||||
validateOkToDelete(theDeleteConflicts, entity);
|
validateOkToDelete(theDeleteConflicts, entity);
|
||||||
|
|
||||||
preDelete(resourceToDelete, entity);
|
preDelete(resourceToDelete, entity);
|
||||||
|
|
||||||
// Notify interceptors
|
// Notify interceptors
|
||||||
if (theRequestDetails != null) {
|
if (theRequestDetails != null) {
|
||||||
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getContext(), theId.getResourceType(), theId);
|
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getContext(), theId.getResourceType(), theId);
|
||||||
|
@ -199,11 +205,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
if (theRequestDetails != null) {
|
if (theRequestDetails != null) {
|
||||||
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getContext(), theId.getResourceType(), theId);
|
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getContext(), theId.getResourceType(), theId);
|
||||||
theRequestDetails.getRequestOperationCallback().resourceDeleted(resourceToDelete);
|
theRequestDetails.getRequestOperationCallback().resourceDeleted(resourceToDelete);
|
||||||
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
|
||||||
if (next instanceof IJpaServerInterceptor) {
|
|
||||||
((IJpaServerInterceptor) next).resourceDeleted(requestDetails, entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
||||||
if (next instanceof IServerOperationInterceptor) {
|
if (next instanceof IServerOperationInterceptor) {
|
||||||
|
@ -238,7 +239,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method gets called by {@link #deleteByUrl(String, List, RequestDetails)} as well as by
|
* This method gets called by {@link #deleteByUrl(String, List, RequestDetails)} as well as by
|
||||||
* transaction processors
|
* transaction processors
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public DeleteMethodOutcome deleteByUrl(String theUrl, List<DeleteConflict> deleteConflicts, RequestDetails theRequestDetails) {
|
public DeleteMethodOutcome deleteByUrl(String theUrl, List<DeleteConflict> deleteConflicts, RequestDetails theRequestDetails) {
|
||||||
|
@ -264,7 +265,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, idToDelete.getResourceType(), idToDelete);
|
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, idToDelete.getResourceType(), idToDelete);
|
||||||
notifyInterceptors(RestOperationTypeEnum.DELETE, requestDetails);
|
notifyInterceptors(RestOperationTypeEnum.DELETE, requestDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform delete
|
// Perform delete
|
||||||
Date updateTime = new Date();
|
Date updateTime = new Date();
|
||||||
updateEntity(null, entity, updateTime, updateTime);
|
updateEntity(null, entity, updateTime, updateTime);
|
||||||
|
@ -274,11 +275,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
if (theRequestDetails != null) {
|
if (theRequestDetails != null) {
|
||||||
theRequestDetails.getRequestOperationCallback().resourceDeleted(resourceToDelete);
|
theRequestDetails.getRequestOperationCallback().resourceDeleted(resourceToDelete);
|
||||||
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, idToDelete.getResourceType(), idToDelete);
|
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, idToDelete.getResourceType(), idToDelete);
|
||||||
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
|
||||||
if (next instanceof IJpaServerInterceptor) {
|
|
||||||
((IJpaServerInterceptor) next).resourceDeleted(requestDetails, entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
||||||
if (next instanceof IServerOperationInterceptor) {
|
if (next instanceof IServerOperationInterceptor) {
|
||||||
|
@ -302,14 +298,14 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
OperationOutcomeUtil.addIssue(getContext(), oo, severity, message, null, code);
|
OperationOutcomeUtil.addIssue(getContext(), oo, severity, message, null, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
ourLog.info("Processed delete on {} (matched {} resource(s)) in {}ms", new Object[] { theUrl, deletedResources.size(), w.getMillis() });
|
ourLog.info("Processed delete on {} (matched {} resource(s)) in {}ms", new Object[]{theUrl, deletedResources.size(), w.getMillis()});
|
||||||
|
|
||||||
DeleteMethodOutcome retVal = new DeleteMethodOutcome();
|
DeleteMethodOutcome retVal = new DeleteMethodOutcome();
|
||||||
retVal.setDeletedEntities(deletedResources);
|
retVal.setDeletedEntities(deletedResources);
|
||||||
retVal.setOperationOutcome(oo);
|
retVal.setOperationOutcome(oo);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DeleteMethodOutcome deleteByUrl(String theUrl, RequestDetails theRequestDetails) {
|
public DeleteMethodOutcome deleteByUrl(String theUrl, RequestDetails theRequestDetails) {
|
||||||
List<DeleteConflict> deleteConflicts = new ArrayList<DeleteConflict>();
|
List<DeleteConflict> deleteConflicts = new ArrayList<DeleteConflict>();
|
||||||
|
@ -317,7 +313,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
DeleteMethodOutcome outcome = deleteByUrl(theUrl, deleteConflicts, theRequestDetails);
|
DeleteMethodOutcome outcome = deleteByUrl(theUrl, deleteConflicts, theRequestDetails);
|
||||||
|
|
||||||
validateDeleteConflictsEmptyOrThrowException(deleteConflicts);
|
validateDeleteConflictsEmptyOrThrowException(deleteConflicts);
|
||||||
|
|
||||||
return outcome;
|
return outcome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +347,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
if (isNotBlank(theResource.getIdElement().getIdPart())) {
|
if (isNotBlank(theResource.getIdElement().getIdPart())) {
|
||||||
if (isValidPid(theResource.getIdElement())) {
|
if (isValidPid(theResource.getIdElement())) {
|
||||||
throw new UnprocessableEntityException(
|
throw new UnprocessableEntityException(
|
||||||
"This server cannot create an entity with a user-specified numeric ID - Client should not specify an ID when creating a new resource, or should include at least one letter in the ID to force a client-defined ID");
|
"This server cannot create an entity with a user-specified numeric ID - Client should not specify an ID when creating a new resource, or should include at least one letter in the ID to force a client-defined ID");
|
||||||
}
|
}
|
||||||
createForcedIdIfNeeded(entity, theResource.getIdElement());
|
createForcedIdIfNeeded(entity, theResource.getIdElement());
|
||||||
|
|
||||||
|
@ -385,16 +381,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
if (!thePerformIndexing) {
|
if (!thePerformIndexing) {
|
||||||
incrementId(theResource, entity, theResource.getIdElement());
|
incrementId(theResource, entity, theResource.getIdElement());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify JPA interceptors
|
// Notify JPA interceptors
|
||||||
if (theRequestDetails != null) {
|
if (theRequestDetails != null) {
|
||||||
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getContext(), theResource);
|
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getContext(), theResource);
|
||||||
theRequestDetails.getRequestOperationCallback().resourceCreated(theResource);
|
theRequestDetails.getRequestOperationCallback().resourceCreated(theResource);
|
||||||
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
|
||||||
if (next instanceof IJpaServerInterceptor) {
|
|
||||||
((IJpaServerInterceptor) next).resourceCreated(requestDetails, entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
||||||
if (next instanceof IServerOperationInterceptor) {
|
if (next instanceof IServerOperationInterceptor) {
|
||||||
|
@ -418,12 +409,12 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
List<TagDefinition> tags = toTagList(theMetaAdd);
|
List<TagDefinition> tags = toTagList(theMetaAdd);
|
||||||
|
|
||||||
for (TagDefinition nextDef : tags) {
|
for (TagDefinition nextDef : tags) {
|
||||||
|
|
||||||
boolean hasTag = false;
|
boolean hasTag = false;
|
||||||
for (BaseTag next : new ArrayList<BaseTag>(entity.getTags())) {
|
for (BaseTag next : new ArrayList<>(entity.getTags())) {
|
||||||
if (ObjectUtil.equals(next.getTag().getTagType(), nextDef.getTagType()) &&
|
if (ObjectUtil.equals(next.getTag().getTagType(), nextDef.getTagType()) &&
|
||||||
ObjectUtil.equals(next.getTag().getSystem(), nextDef.getSystem()) &&
|
ObjectUtil.equals(next.getTag().getSystem(), nextDef.getSystem()) &&
|
||||||
ObjectUtil.equals(next.getTag().getCode(), nextDef.getCode())) {
|
ObjectUtil.equals(next.getTag().getCode(), nextDef.getCode())) {
|
||||||
hasTag = true;
|
hasTag = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -431,7 +422,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
|
|
||||||
if (!hasTag) {
|
if (!hasTag) {
|
||||||
entity.setHasTags(true);
|
entity.setHasTags(true);
|
||||||
|
|
||||||
TagDefinition def = getTagOrNull(nextDef.getTagType(), nextDef.getSystem(), nextDef.getCode(), nextDef.getDisplay());
|
TagDefinition def = getTagOrNull(nextDef.getTagType(), nextDef.getSystem(), nextDef.getCode(), nextDef.getDisplay());
|
||||||
if (def != null) {
|
if (def != null) {
|
||||||
BaseTag newEntity = entity.addTag(def);
|
BaseTag newEntity = entity.addTag(def);
|
||||||
|
@ -443,7 +434,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
}
|
}
|
||||||
|
|
||||||
validateMetaCount(entity.getTags().size());
|
validateMetaCount(entity.getTags().size());
|
||||||
|
|
||||||
myEntityManager.merge(entity);
|
myEntityManager.merge(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,9 +444,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
for (TagDefinition nextDef : tags) {
|
for (TagDefinition nextDef : tags) {
|
||||||
for (BaseTag next : new ArrayList<BaseTag>(entity.getTags())) {
|
for (BaseTag next : new ArrayList<BaseTag>(entity.getTags())) {
|
||||||
if (ObjectUtil.equals(next.getTag().getTagType(), nextDef.getTagType()) &&
|
if (ObjectUtil.equals(next.getTag().getTagType(), nextDef.getTagType()) &&
|
||||||
ObjectUtil.equals(next.getTag().getSystem(), nextDef.getSystem()) &&
|
ObjectUtil.equals(next.getTag().getSystem(), nextDef.getSystem()) &&
|
||||||
ObjectUtil.equals(next.getTag().getCode(), nextDef.getCode())) {
|
ObjectUtil.equals(next.getTag().getCode(), nextDef.getCode())) {
|
||||||
myEntityManager.remove(next);
|
myEntityManager.remove(next);
|
||||||
entity.getTags().remove(next);
|
entity.getTags().remove(next);
|
||||||
}
|
}
|
||||||
|
@ -482,8 +473,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract List<Object> getIncludeValues(FhirTerser theTerser, Include theInclude, IBaseResource theResource, RuntimeResourceDefinition theResourceDef);
|
|
||||||
|
|
||||||
public String getResourceName() {
|
public String getResourceName() {
|
||||||
return myResourceName;
|
return myResourceName;
|
||||||
}
|
}
|
||||||
|
@ -493,6 +482,12 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
return myResourceType;
|
return myResourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Required
|
||||||
|
public void setResourceType(Class<? extends IBaseResource> theTableType) {
|
||||||
|
myResourceType = (Class<T>) theTableType;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TagList getTags(IIdType theResourceId, RequestDetails theRequestDetails) {
|
public TagList getTags(IIdType theResourceId, RequestDetails theRequestDetails) {
|
||||||
// Notify interceptors
|
// Notify interceptors
|
||||||
|
@ -535,17 +530,16 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
}
|
}
|
||||||
|
|
||||||
private void incrementId(T theResource, ResourceTable theSavedEntity, IIdType theResourceId) {
|
private void incrementId(T theResource, ResourceTable theSavedEntity, IIdType theResourceId) {
|
||||||
IIdType idType = theResourceId;
|
|
||||||
String newVersion;
|
String newVersion;
|
||||||
long newVersionLong;
|
long newVersionLong;
|
||||||
if (idType == null || idType.getVersionIdPart() == null) {
|
if (theResourceId == null || theResourceId.getVersionIdPart() == null) {
|
||||||
newVersion = "1";
|
newVersion = "1";
|
||||||
newVersionLong = 1;
|
newVersionLong = 1;
|
||||||
} else {
|
} else {
|
||||||
newVersionLong = idType.getVersionIdPartAsLong() + 1;
|
newVersionLong = theResourceId.getVersionIdPartAsLong() + 1;
|
||||||
newVersion = Long.toString(newVersionLong);
|
newVersion = Long.toString(newVersionLong);
|
||||||
}
|
}
|
||||||
|
|
||||||
IIdType newId = theResourceId.withVersion(newVersion);
|
IIdType newId = theResourceId.withVersion(newVersion);
|
||||||
theResource.getIdElement().setValue(newId.getValue());
|
theResource.getIdElement().setValue(newId.getValue());
|
||||||
theSavedEntity.setVersion(newVersionLong);
|
theSavedEntity.setVersion(newVersionLong);
|
||||||
|
@ -568,7 +562,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theResourceId);
|
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theResourceId);
|
||||||
notifyInterceptors(RestOperationTypeEnum.META_ADD, requestDetails);
|
notifyInterceptors(RestOperationTypeEnum.META_ADD, requestDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
StopWatch w = new StopWatch();
|
StopWatch w = new StopWatch();
|
||||||
BaseHasResource entity = readEntity(theResourceId);
|
BaseHasResource entity = readEntity(theResourceId);
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
|
@ -586,14 +580,13 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
doMetaAdd(theMetaAdd, history);
|
doMetaAdd(theMetaAdd, history);
|
||||||
}
|
}
|
||||||
|
|
||||||
ourLog.info("Processed metaAddOperation on {} in {}ms", new Object[] { theResourceId, w.getMillisAndRestart() });
|
ourLog.info("Processed metaAddOperation on {} in {}ms", new Object[]{theResourceId, w.getMillisAndRestart()});
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
MT retVal = (MT) metaGetOperation(theMetaAdd.getClass(), theResourceId, theRequestDetails);
|
MT retVal = (MT) metaGetOperation(theMetaAdd.getClass(), theResourceId, theRequestDetails);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <MT extends IBaseMetaType> MT metaDeleteOperation(IIdType theResourceId, MT theMetaDel, RequestDetails theRequestDetails) {
|
public <MT extends IBaseMetaType> MT metaDeleteOperation(IIdType theResourceId, MT theMetaDel, RequestDetails theRequestDetails) {
|
||||||
// Notify interceptors
|
// Notify interceptors
|
||||||
|
@ -601,7 +594,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theResourceId);
|
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theResourceId);
|
||||||
notifyInterceptors(RestOperationTypeEnum.META_DELETE, requestDetails);
|
notifyInterceptors(RestOperationTypeEnum.META_DELETE, requestDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
StopWatch w = new StopWatch();
|
StopWatch w = new StopWatch();
|
||||||
BaseHasResource entity = readEntity(theResourceId);
|
BaseHasResource entity = readEntity(theResourceId);
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
|
@ -621,7 +614,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
|
|
||||||
myEntityManager.flush();
|
myEntityManager.flush();
|
||||||
|
|
||||||
ourLog.info("Processed metaDeleteOperation on {} in {}ms", new Object[] { theResourceId.getValue(), w.getMillisAndRestart() });
|
ourLog.info("Processed metaDeleteOperation on {} in {}ms", new Object[]{theResourceId.getValue(), w.getMillisAndRestart()});
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
MT retVal = (MT) metaGetOperation(theMetaDel.getClass(), theResourceId, theRequestDetails);
|
MT retVal = (MT) metaGetOperation(theMetaDel.getClass(), theResourceId, theRequestDetails);
|
||||||
|
@ -635,7 +628,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theId);
|
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theId);
|
||||||
notifyInterceptors(RestOperationTypeEnum.META, requestDetails);
|
notifyInterceptors(RestOperationTypeEnum.META, requestDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<TagDefinition> tagDefs = new HashSet<TagDefinition>();
|
Set<TagDefinition> tagDefs = new HashSet<TagDefinition>();
|
||||||
BaseHasResource entity = readEntity(theId);
|
BaseHasResource entity = readEntity(theId);
|
||||||
for (BaseTag next : entity.getTags()) {
|
for (BaseTag next : entity.getTags()) {
|
||||||
|
@ -656,7 +649,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), null);
|
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), null);
|
||||||
notifyInterceptors(RestOperationTypeEnum.META, requestDetails);
|
notifyInterceptors(RestOperationTypeEnum.META, requestDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t WHERE t.myResourceType = :res_type)";
|
String sql = "SELECT d FROM TagDefinition d WHERE d.myId IN (SELECT DISTINCT t.myTagId FROM ResourceTag t WHERE t.myResourceType = :res_type)";
|
||||||
TypedQuery<TagDefinition> q = myEntityManager.createQuery(sql, TagDefinition.class);
|
TypedQuery<TagDefinition> q = myEntityManager.createQuery(sql, TagDefinition.class);
|
||||||
q.setParameter("res_type", myResourceName);
|
q.setParameter("res_type", myResourceName);
|
||||||
|
@ -675,9 +668,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
throw new ResourceVersionConflictException("Version " + theId.getVersionIdPart() + " is not the most recent version of this resource, unable to apply patch");
|
throw new ResourceVersionConflictException("Version " + theId.getVersionIdPart() + " is not the most recent version of this resource, unable to apply patch");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validateResourceType(entityToUpdate);
|
validateResourceType(entityToUpdate);
|
||||||
|
|
||||||
IBaseResource resourceToUpdate = toResource(entityToUpdate, false);
|
IBaseResource resourceToUpdate = toResource(entityToUpdate, false);
|
||||||
IBaseResource destination;
|
IBaseResource destination;
|
||||||
if (thePatchType == PatchTypeEnum.JSON_PATCH) {
|
if (thePatchType == PatchTypeEnum.JSON_PATCH) {
|
||||||
|
@ -685,7 +678,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
} else {
|
} else {
|
||||||
destination = XmlPatchUtils.apply(getContext(), resourceToUpdate, thePatchBody);
|
destination = XmlPatchUtils.apply(getContext(), resourceToUpdate, thePatchBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
T destinationCasted = (T) destination;
|
T destinationCasted = (T) destination;
|
||||||
return update(destinationCasted, null, true, theRequestDetails);
|
return update(destinationCasted, null, true, theRequestDetails);
|
||||||
|
@ -710,7 +703,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subclasses may override to provide behaviour. Invoked within a delete
|
* Subclasses may override to provide behaviour. Invoked within a delete
|
||||||
* transaction with the resource that is about to be deleted.
|
* transaction with the resource that is about to be deleted.
|
||||||
*/
|
*/
|
||||||
protected void preDelete(T theResourceToDelete, ResourceTable theEntityToDelete) {
|
protected void preDelete(T theResourceToDelete, ResourceTable theEntityToDelete) {
|
||||||
// nothing by default
|
// nothing by default
|
||||||
|
@ -718,9 +711,8 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* May be overridden by subclasses to validate resources prior to storage
|
* May be overridden by subclasses to validate resources prior to storage
|
||||||
*
|
*
|
||||||
* @param theResource
|
* @param theResource The resource that is about to be stored
|
||||||
* The resource that is about to be stored
|
|
||||||
*/
|
*/
|
||||||
protected void preProcessResourceForStorage(T theResource) {
|
protected void preProcessResourceForStorage(T theResource) {
|
||||||
String type = getContext().getResourceDefinition(theResource).getName();
|
String type = getContext().getResourceDefinition(theResource).getName();
|
||||||
|
@ -825,7 +817,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
if (theId.hasVersionIdPart()) {
|
if (theId.hasVersionIdPart()) {
|
||||||
TypedQuery<ResourceHistoryTable> q = myEntityManager
|
TypedQuery<ResourceHistoryTable> q = myEntityManager
|
||||||
.createQuery("SELECT t from ResourceHistoryTable t WHERE t.myResourceId = :RID AND t.myResourceType = :RTYP AND t.myResourceVersion = :RVER", ResourceHistoryTable.class);
|
.createQuery("SELECT t from ResourceHistoryTable t WHERE t.myResourceId = :RID AND t.myResourceType = :RTYP AND t.myResourceVersion = :RVER", ResourceHistoryTable.class);
|
||||||
q.setParameter("RID", pid);
|
q.setParameter("RID", pid);
|
||||||
q.setParameter("RTYP", myResourceName);
|
q.setParameter("RTYP", myResourceName);
|
||||||
q.setParameter("RVER", theId.getVersionIdPartAsLong());
|
q.setParameter("RVER", theId.getVersionIdPartAsLong());
|
||||||
|
@ -859,7 +851,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
ourLog.debug("Indexing resource {} - PID {}", theResource.getIdElement().getValue(), theEntity.getId());
|
ourLog.debug("Indexing resource {} - PID {}", theResource.getIdElement().getValue(), theEntity.getId());
|
||||||
updateEntity(theResource, theEntity, null, true, false, theEntity.getUpdatedDate(), true, false);
|
updateEntity(theResource, theEntity, null, true, false, theEntity.getUpdatedDate(), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm) {
|
public void removeTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm) {
|
||||||
removeTag(theId, theTagType, theScheme, theTerm, null);
|
removeTag(theId, theTagType, theScheme, theTerm, null);
|
||||||
|
@ -872,7 +864,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theId);
|
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getResourceName(), theId);
|
||||||
notifyInterceptors(RestOperationTypeEnum.DELETE_TAGS, requestDetails);
|
notifyInterceptors(RestOperationTypeEnum.DELETE_TAGS, requestDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
StopWatch w = new StopWatch();
|
StopWatch w = new StopWatch();
|
||||||
BaseHasResource entity = readEntity(theId);
|
BaseHasResource entity = readEntity(theId);
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
|
@ -881,9 +873,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
|
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
for (BaseTag next : new ArrayList<BaseTag>(entity.getTags())) {
|
for (BaseTag next : new ArrayList<BaseTag>(entity.getTags())) {
|
||||||
if (ObjectUtil.equals(next.getTag().getTagType(), theTagType) &&
|
if (ObjectUtil.equals(next.getTag().getTagType(), theTagType) &&
|
||||||
ObjectUtil.equals(next.getTag().getSystem(), theScheme) &&
|
ObjectUtil.equals(next.getTag().getSystem(), theScheme) &&
|
||||||
ObjectUtil.equals(next.getTag().getCode(), theTerm)) {
|
ObjectUtil.equals(next.getTag().getCode(), theTerm)) {
|
||||||
myEntityManager.remove(next);
|
myEntityManager.remove(next);
|
||||||
entity.getTags().remove(next);
|
entity.getTags().remove(next);
|
||||||
}
|
}
|
||||||
|
@ -896,25 +888,25 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
|
|
||||||
myEntityManager.merge(entity);
|
myEntityManager.merge(entity);
|
||||||
|
|
||||||
ourLog.info("Processed remove tag {}/{} on {} in {}ms", new Object[] { theScheme, theTerm, theId.getValue(), w.getMillisAndRestart() });
|
ourLog.info("Processed remove tag {}/{} on {} in {}ms", new Object[]{theScheme, theTerm, theId.getValue(), w.getMillisAndRestart()});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(propagation=Propagation.SUPPORTS)
|
@Transactional(propagation = Propagation.SUPPORTS)
|
||||||
@Override
|
@Override
|
||||||
public IBundleProvider search(final SearchParameterMap theParams) {
|
public IBundleProvider search(final SearchParameterMap theParams) {
|
||||||
return search(theParams, null);
|
return search(theParams, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(propagation=Propagation.SUPPORTS)
|
@Transactional(propagation = Propagation.SUPPORTS)
|
||||||
@Override
|
@Override
|
||||||
public IBundleProvider search(final SearchParameterMap theParams, RequestDetails theRequestDetails) {
|
public IBundleProvider search(final SearchParameterMap theParams, RequestDetails theRequestDetails) {
|
||||||
// Notify interceptors
|
// Notify interceptors
|
||||||
if (theRequestDetails != null) {
|
if (theRequestDetails != null) {
|
||||||
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getContext(), getResourceName(), null);
|
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getContext(), getResourceName(), null);
|
||||||
notifyInterceptors(RestOperationTypeEnum.SEARCH_TYPE, requestDetails);
|
notifyInterceptors(RestOperationTypeEnum.SEARCH_TYPE, requestDetails);
|
||||||
|
|
||||||
if (theRequestDetails.isSubRequest()) {
|
if (theRequestDetails.isSubRequest()) {
|
||||||
Integer max = myDaoConfig.getMaximumSearchResultCountInTransaction();
|
Integer max = myDaoConfig.getMaximumSearchResultCountInTransaction();
|
||||||
if (max != null) {
|
if (max != null) {
|
||||||
Validate.inclusiveBetween(1, Integer.MAX_VALUE, max.intValue(), "Maximum search result count in transaction ust be a positive integer");
|
Validate.inclusiveBetween(1, Integer.MAX_VALUE, max.intValue(), "Maximum search result count in transaction ust be a positive integer");
|
||||||
theParams.setLoadSynchronousUpTo(myDaoConfig.getMaximumSearchResultCountInTransaction());
|
theParams.setLoadSynchronousUpTo(myDaoConfig.getMaximumSearchResultCountInTransaction());
|
||||||
|
@ -925,7 +917,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
theParams.setLoadSynchronous(true);
|
theParams.setLoadSynchronous(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mySearchCoordinatorSvc.registerSearch(this, theParams, getResourceName());
|
return mySearchCoordinatorSvc.registerSearch(this, theParams, getResourceName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -936,22 +928,16 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
builder.setType(getResourceType(), getResourceName());
|
builder.setType(getResourceType(), getResourceName());
|
||||||
|
|
||||||
// FIXME: fail if too many results
|
// FIXME: fail if too many results
|
||||||
|
|
||||||
HashSet<Long> retVal = new HashSet<Long>();
|
HashSet<Long> retVal = new HashSet<Long>();
|
||||||
|
|
||||||
String uuid = UUID.randomUUID().toString();
|
String uuid = UUID.randomUUID().toString();
|
||||||
Iterator<Long> iter = builder.createQuery(theParams, uuid);
|
Iterator<Long> iter = builder.createQuery(theParams, uuid);
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
retVal.add(iter.next());
|
retVal.add(iter.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
return retVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
return retVal;
|
||||||
@Required
|
|
||||||
public void setResourceType(Class<? extends IBaseResource> theTableType) {
|
|
||||||
myResourceType = (Class<T>) theTableType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -970,15 +956,15 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
}
|
}
|
||||||
for (TagDefinition next : tagDefinitions) {
|
for (TagDefinition next : tagDefinitions) {
|
||||||
switch (next.getTagType()) {
|
switch (next.getTagType()) {
|
||||||
case PROFILE:
|
case PROFILE:
|
||||||
retVal.addProfile(next.getCode());
|
retVal.addProfile(next.getCode());
|
||||||
break;
|
break;
|
||||||
case SECURITY_LABEL:
|
case SECURITY_LABEL:
|
||||||
retVal.addSecurity().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay());
|
retVal.addSecurity().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay());
|
||||||
break;
|
break;
|
||||||
case TAG:
|
case TAG:
|
||||||
retVal.addTag().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay());
|
retVal.addTag().setSystem(next.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
|
@ -1028,15 +1014,15 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(propagation=Propagation.SUPPORTS)
|
@Transactional(propagation = Propagation.SUPPORTS)
|
||||||
@Override
|
@Override
|
||||||
public void translateRawParameters(Map<String, List<String>> theSource, SearchParameterMap theTarget) {
|
public void translateRawParameters(Map<String, List<String>> theSource, SearchParameterMap theTarget) {
|
||||||
if (theSource == null || theSource.isEmpty()) {
|
if (theSource == null || theSource.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, RuntimeSearchParam> searchParams = mySerarchParamRegistry.getActiveSearchParams(getResourceName());
|
Map<String, RuntimeSearchParam> searchParams = mySerarchParamRegistry.getActiveSearchParams(getResourceName());
|
||||||
|
|
||||||
Set<String> paramNames = theSource.keySet();
|
Set<String> paramNames = theSource.keySet();
|
||||||
for (String nextParamName : paramNames) {
|
for (String nextParamName : paramNames) {
|
||||||
QualifierDetails qualifiedParamName = SearchMethodBinding.extractQualifiersFromParameterName(nextParamName);
|
QualifierDetails qualifiedParamName = SearchMethodBinding.extractQualifiersFromParameterName(nextParamName);
|
||||||
|
@ -1058,7 +1044,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
theTarget.add(qualifiedParamName.getParamName(), parsedParam);
|
theTarget.add(qualifiedParamName.getParamName(), parsedParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1109,7 +1095,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
} catch (ResourceNotFoundException e) {
|
} catch (ResourceNotFoundException e) {
|
||||||
if (resourceId.isIdPartValidLong()) {
|
if (resourceId.isIdPartValidLong()) {
|
||||||
throw new InvalidRequestException(
|
throw new InvalidRequestException(
|
||||||
getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getIdElement().getIdPart()));
|
getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getIdElement().getIdPart()));
|
||||||
}
|
}
|
||||||
return doCreate(theResource, null, thePerformIndexing, new Date(), theRequestDetails);
|
return doCreate(theResource, null, thePerformIndexing, new Date(), theRequestDetails);
|
||||||
}
|
}
|
||||||
|
@ -1121,7 +1107,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
|
|
||||||
if (resourceId.hasResourceType() && !resourceId.getResourceType().equals(getResourceName())) {
|
if (resourceId.hasResourceType() && !resourceId.getResourceType().equals(getResourceName())) {
|
||||||
throw new UnprocessableEntityException(
|
throw new UnprocessableEntityException(
|
||||||
"Invalid resource ID[" + entity.getIdDt().toUnqualifiedVersionless() + "] of type[" + entity.getResourceType() + "] - Does not match expected [" + getResourceName() + "]");
|
"Invalid resource ID[" + entity.getIdDt().toUnqualifiedVersionless() + "] of type[" + entity.getResourceType() + "] - Does not match expected [" + getResourceName() + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify interceptors
|
// Notify interceptors
|
||||||
|
@ -1132,7 +1118,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
}
|
}
|
||||||
|
|
||||||
IBaseResource oldResource = toResource(entity, false);
|
IBaseResource oldResource = toResource(entity, false);
|
||||||
|
|
||||||
// Perform update
|
// Perform update
|
||||||
ResourceTable savedEntity = updateEntity(theResource, entity, null, thePerformIndexing, thePerformIndexing, new Date(), theForceUpdateVersion, thePerformIndexing);
|
ResourceTable savedEntity = updateEntity(theResource, entity, null, thePerformIndexing, thePerformIndexing, new Date(), theForceUpdateVersion, thePerformIndexing);
|
||||||
|
|
||||||
|
@ -1152,11 +1138,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
if (theRequestDetails != null) {
|
if (theRequestDetails != null) {
|
||||||
theRequestDetails.getRequestOperationCallback().resourceUpdated(theResource);
|
theRequestDetails.getRequestOperationCallback().resourceUpdated(theResource);
|
||||||
theRequestDetails.getRequestOperationCallback().resourceUpdated(oldResource, theResource);
|
theRequestDetails.getRequestOperationCallback().resourceUpdated(oldResource, theResource);
|
||||||
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
|
||||||
if (next instanceof IJpaServerInterceptor) {
|
|
||||||
((IJpaServerInterceptor) next).resourceUpdated(requestDetails, entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
||||||
if (next instanceof IServerOperationInterceptor) {
|
if (next instanceof IServerOperationInterceptor) {
|
||||||
|
@ -1164,21 +1145,21 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
((IServerOperationInterceptor) next).resourceUpdated(theRequestDetails, oldResource, theResource);
|
((IServerOperationInterceptor) next).resourceUpdated(theRequestDetails, oldResource, theResource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DaoMethodOutcome outcome = toMethodOutcome(savedEntity, theResource).setCreated(false);
|
DaoMethodOutcome outcome = toMethodOutcome(savedEntity, theResource).setCreated(false);
|
||||||
|
|
||||||
if (!thePerformIndexing) {
|
if (!thePerformIndexing) {
|
||||||
outcome.setId(theResource.getIdElement());
|
outcome.setId(theResource.getIdElement());
|
||||||
}
|
}
|
||||||
|
|
||||||
String msg = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "successfulCreate", outcome.getId(), w.getMillisAndRestart());
|
String msg = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "successfulCreate", outcome.getId(), w.getMillisAndRestart());
|
||||||
outcome.setOperationOutcome(createInfoOperationOutcome(msg));
|
outcome.setOperationOutcome(createInfoOperationOutcome(msg));
|
||||||
|
|
||||||
ourLog.info(msg);
|
ourLog.info(msg);
|
||||||
return outcome;
|
return outcome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DaoMethodOutcome update(T theResource, String theMatchUrl, boolean thePerformIndexing, RequestDetails theRequestDetails) {
|
public DaoMethodOutcome update(T theResource, String theMatchUrl, boolean thePerformIndexing, RequestDetails theRequestDetails) {
|
||||||
return update(theResource, theMatchUrl, thePerformIndexing, false, theRequestDetails);
|
return update(theResource, theMatchUrl, thePerformIndexing, false, theRequestDetails);
|
||||||
|
@ -1191,18 +1172,19 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the resource definition from the criteria which specifies the resource type
|
* Get the resource definition from the criteria which specifies the resource type
|
||||||
|
*
|
||||||
* @param criteria
|
* @param criteria
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public RuntimeResourceDefinition validateCriteriaAndReturnResourceDefinition(String criteria) {
|
public RuntimeResourceDefinition validateCriteriaAndReturnResourceDefinition(String criteria) {
|
||||||
String resourceName;
|
String resourceName;
|
||||||
if(criteria == null || criteria.trim().isEmpty()){
|
if (criteria == null || criteria.trim().isEmpty()) {
|
||||||
throw new IllegalArgumentException("Criteria cannot be empty");
|
throw new IllegalArgumentException("Criteria cannot be empty");
|
||||||
}
|
}
|
||||||
if(criteria.contains("?")){
|
if (criteria.contains("?")) {
|
||||||
resourceName = criteria.substring(0, criteria.indexOf("?"));
|
resourceName = criteria.substring(0, criteria.indexOf("?"));
|
||||||
}else{
|
} else {
|
||||||
resourceName = criteria;
|
resourceName = criteria;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1220,7 +1202,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void validateOkToDelete(List<DeleteConflict> theDeleteConflicts, ResourceTable theEntity) {
|
protected void validateOkToDelete(List<DeleteConflict> theDeleteConflicts, ResourceTable theEntity) {
|
||||||
TypedQuery<ResourceLink> query = myEntityManager.createQuery("SELECT l FROM ResourceLink l WHERE l.myTargetResourcePid = :target_pid", ResourceLink.class);
|
TypedQuery<ResourceLink> query = myEntityManager.createQuery("SELECT l FROM ResourceLink l WHERE l.myTargetResourcePid = :target_pid", ResourceLink.class);
|
||||||
query.setParameter("target_pid", theEntity.getId());
|
query.setParameter("target_pid", theEntity.getId());
|
||||||
|
@ -1235,7 +1217,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
||||||
myResourceLinkDao.delete(resultList);
|
myResourceLinkDao.delete(resultList);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceLink link = resultList.get(0);
|
ResourceLink link = resultList.get(0);
|
||||||
IdDt targetId = theEntity.getIdDt();
|
IdDt targetId = theEntity.getIdDt();
|
||||||
IdDt sourceId = link.getSourceResource().getIdDt();
|
IdDt sourceId = link.getSourceResource().getIdDt();
|
||||||
|
|
|
@ -56,24 +56,6 @@ public class FhirResourceDaoDstu2<T extends IResource> extends BaseHapiFhirResou
|
||||||
@Qualifier("myInstanceValidatorDstu2")
|
@Qualifier("myInstanceValidatorDstu2")
|
||||||
private IValidatorModule myInstanceValidator;
|
private IValidatorModule myInstanceValidator;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<Object> getIncludeValues(FhirTerser theTerser, Include theInclude, IBaseResource theResource, RuntimeResourceDefinition theResourceDef) {
|
|
||||||
List<Object> values;
|
|
||||||
if ("*".equals(theInclude.getValue())) {
|
|
||||||
values = new ArrayList<Object>();
|
|
||||||
values.addAll(theTerser.getAllPopulatedChildElementsOfType(theResource, BaseResourceReferenceDt.class));
|
|
||||||
} else if (theInclude.getValue().startsWith(theResourceDef.getName() + ":")) {
|
|
||||||
values = new ArrayList<Object>();
|
|
||||||
String paramName = theInclude.getValue().substring(theInclude.getValue().indexOf(':') + 1);
|
|
||||||
RuntimeSearchParam sp = getSearchParamByName(theResourceDef, paramName);
|
|
||||||
for (String nextPath : sp.getPathsSplit()) {
|
|
||||||
values.addAll(theTerser.getValues(theResource, nextPath));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
values = Collections.emptyList();
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage, String theCode) {
|
protected IBaseOperationOutcome createOperationOutcome(String theSeverity, String theMessage, String theCode) {
|
||||||
|
|
|
@ -33,19 +33,19 @@ import ca.uhn.fhir.jpa.entity.SubscriptionTable;
|
||||||
public interface ISubscriptionTableDao extends JpaRepository<SubscriptionTable, Long> {
|
public interface ISubscriptionTableDao extends JpaRepository<SubscriptionTable, Long> {
|
||||||
|
|
||||||
@Query("SELECT t FROM SubscriptionTable t WHERE t.myResId = :pid")
|
@Query("SELECT t FROM SubscriptionTable t WHERE t.myResId = :pid")
|
||||||
public SubscriptionTable findOneByResourcePid(@Param("pid") Long theId);
|
SubscriptionTable findOneByResourcePid(@Param("pid") Long theId);
|
||||||
|
|
||||||
@Modifying
|
@Modifying
|
||||||
@Query("DELETE FROM SubscriptionTable t WHERE t.myId = :id ")
|
@Query("DELETE FROM SubscriptionTable t WHERE t.myId = :id ")
|
||||||
public void deleteAllForSubscription(@Param("id") Long theSubscriptionId);
|
void deleteAllForSubscription(@Param("id") Long theSubscriptionId);
|
||||||
|
|
||||||
@Modifying
|
@Modifying
|
||||||
@Query("UPDATE SubscriptionTable t SET t.myLastClientPoll = :last_client_poll")
|
@Query("UPDATE SubscriptionTable t SET t.myLastClientPoll = :last_client_poll")
|
||||||
public int updateLastClientPoll(@Param("last_client_poll") Date theLastClientPoll);
|
int updateLastClientPoll(@Param("last_client_poll") Date theLastClientPoll);
|
||||||
|
|
||||||
@Query("SELECT t FROM SubscriptionTable t WHERE t.myLastClientPoll < :cutoff OR (t.myLastClientPoll IS NULL AND t.myCreated < :cutoff)")
|
@Query("SELECT t FROM SubscriptionTable t WHERE t.myLastClientPoll < :cutoff OR (t.myLastClientPoll IS NULL AND t.myCreated < :cutoff)")
|
||||||
public Collection<SubscriptionTable> findInactiveBeforeCutoff(@Param("cutoff") Date theCutoff);
|
Collection<SubscriptionTable> findInactiveBeforeCutoff(@Param("cutoff") Date theCutoff);
|
||||||
|
|
||||||
@Query("SELECT t.myId FROM SubscriptionTable t WHERE t.myStatus = :status AND t.myNextCheck <= :next_check")
|
@Query("SELECT t.myId FROM SubscriptionTable t WHERE t.myStatus = :status AND t.myNextCheck <= :next_check")
|
||||||
public Collection<Long> findSubscriptionsWhichNeedToBeChecked(@Param("status") String theStatus, @Param("next_check") Date theNextCheck);
|
Collection<Long> findSubscriptionsWhichNeedToBeChecked(@Param("status") String theStatus, @Param("next_check") Date theNextCheck);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,24 +70,6 @@ public class FhirResourceDaoDstu3<T extends IAnyResource> extends BaseHapiFhirRe
|
||||||
return oo;
|
return oo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<Object> getIncludeValues(FhirTerser theTerser, Include theInclude, IBaseResource theResource, RuntimeResourceDefinition theResourceDef) {
|
|
||||||
List<Object> values;
|
|
||||||
if ("*".equals(theInclude.getValue())) {
|
|
||||||
values = new ArrayList<Object>();
|
|
||||||
values.addAll(theTerser.getAllPopulatedChildElementsOfType(theResource, BaseResourceReferenceDt.class));
|
|
||||||
} else if (theInclude.getValue().startsWith(theResourceDef.getName() + ":")) {
|
|
||||||
values = new ArrayList<Object>();
|
|
||||||
String paramName = theInclude.getValue().substring(theInclude.getValue().indexOf(':') + 1);
|
|
||||||
RuntimeSearchParam sp = getSearchParamByName(theResourceDef, paramName);
|
|
||||||
for (String nextPath : sp.getPathsSplit()) {
|
|
||||||
values.addAll(theTerser.getValues(theResource, nextPath));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
values = Collections.emptyList();
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) {
|
public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) {
|
||||||
|
|
|
@ -70,24 +70,6 @@ public class FhirResourceDaoR4<T extends IAnyResource> extends BaseHapiFhirResou
|
||||||
return oo;
|
return oo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<Object> getIncludeValues(FhirTerser theTerser, Include theInclude, IBaseResource theResource, RuntimeResourceDefinition theResourceDef) {
|
|
||||||
List<Object> values;
|
|
||||||
if ("*".equals(theInclude.getValue())) {
|
|
||||||
values = new ArrayList<Object>();
|
|
||||||
values.addAll(theTerser.getAllPopulatedChildElementsOfType(theResource, BaseResourceReferenceDt.class));
|
|
||||||
} else if (theInclude.getValue().startsWith(theResourceDef.getName() + ":")) {
|
|
||||||
values = new ArrayList<Object>();
|
|
||||||
String paramName = theInclude.getValue().substring(theInclude.getValue().indexOf(':') + 1);
|
|
||||||
RuntimeSearchParam sp = getSearchParamByName(theResourceDef, paramName);
|
|
||||||
for (String nextPath : sp.getPathsSplit()) {
|
|
||||||
values.addAll(theTerser.getValues(theResource, nextPath));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
values = Collections.emptyList();
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) {
|
public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) {
|
||||||
|
|
|
@ -20,64 +20,53 @@ package ca.uhn.fhir.jpa.entity;
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.ForeignKey;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.persistence.SequenceGenerator;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "HFJ_SUBSCRIPTION_FLAG_RES")
|
@Table(name = "HFJ_SUBSCRIPTION_FLAG_RES")
|
||||||
public class SubscriptionFlaggedResource {
|
public class SubscriptionFlaggedResource {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO, generator="SEQ_SUBSCRIPTION_FLAG_ID")
|
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_SUBSCRIPTION_FLAG_ID")
|
||||||
@SequenceGenerator(name = "SEQ_SUBSCRIPTION_FLAG_ID", sequenceName = "SEQ_SUBSCRIPTION_FLAG_ID")
|
@SequenceGenerator(name = "SEQ_SUBSCRIPTION_FLAG_ID", sequenceName = "SEQ_SUBSCRIPTION_FLAG_ID")
|
||||||
@Column(name = "PID", insertable = false, updatable = false)
|
@Column(name = "PID", insertable = false, updatable = false)
|
||||||
private Long myId;
|
private Long myId;
|
||||||
|
|
||||||
@ManyToOne()
|
@ManyToOne()
|
||||||
@JoinColumn(name="RES_ID", nullable=false, foreignKey=@ForeignKey(name="FK_SUBSFLAGRES_RES"))
|
@JoinColumn(name = "RES_ID", nullable = false, foreignKey = @ForeignKey(name = "FK_SUBSFLAGRES_RES"))
|
||||||
private ResourceTable myResource;
|
private ResourceTable myResource;
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
@ManyToOne()
|
@ManyToOne()
|
||||||
@JoinColumn(name="SUBSCRIPTION_ID",
|
@JoinColumn(name = "SUBSCRIPTION_ID",
|
||||||
foreignKey=@ForeignKey(name="FK_SUBSFLAG_SUBS")
|
foreignKey = @ForeignKey(name = "FK_SUBSFLAG_SUBS")
|
||||||
)
|
)
|
||||||
private SubscriptionTable mySubscription;
|
private SubscriptionTable mySubscription;
|
||||||
//@formatter:om
|
|
||||||
|
@Column(name = "RES_VERSION", nullable = false)
|
||||||
@Column(name="RES_VERSION", nullable=false)
|
|
||||||
private Long myVersion;
|
private Long myVersion;
|
||||||
|
|
||||||
public ResourceTable getResource() {
|
public ResourceTable getResource() {
|
||||||
return myResource;
|
return myResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubscriptionTable getSubscription() {
|
|
||||||
return mySubscription;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getVersion() {
|
|
||||||
return myVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResource(ResourceTable theResource) {
|
public void setResource(ResourceTable theResource) {
|
||||||
myResource = theResource;
|
myResource = theResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SubscriptionTable getSubscription() {
|
||||||
|
return mySubscription;
|
||||||
|
}
|
||||||
|
|
||||||
public void setSubscription(SubscriptionTable theSubscription) {
|
public void setSubscription(SubscriptionTable theSubscription) {
|
||||||
mySubscription = theSubscription;
|
mySubscription = theSubscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getVersion() {
|
||||||
|
return myVersion;
|
||||||
|
}
|
||||||
|
|
||||||
public void setVersion(Long theVersion) {
|
public void setVersion(Long theVersion) {
|
||||||
myVersion = theVersion;
|
myVersion = theVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,13 +87,18 @@ public class SubscriptionTable {
|
||||||
@Column(name = "SUBSCRIPTION_STATUS", nullable = false, length = 20)
|
@Column(name = "SUBSCRIPTION_STATUS", nullable = false, length = 20)
|
||||||
private String myStatus;
|
private String myStatus;
|
||||||
|
|
||||||
//@formatter:off
|
|
||||||
@OneToOne()
|
@OneToOne()
|
||||||
@JoinColumn(name = "RES_ID", insertable = true, updatable = false, referencedColumnName = "RES_ID",
|
@JoinColumn(name = "RES_ID", insertable = true, updatable = false, referencedColumnName = "RES_ID",
|
||||||
foreignKey = @ForeignKey(name = "FK_SUBSCRIPTION_RESOURCE_ID")
|
foreignKey = @ForeignKey(name = "FK_SUBSCRIPTION_RESOURCE_ID")
|
||||||
)
|
)
|
||||||
private ResourceTable mySubscriptionResource;
|
private ResourceTable mySubscriptionResource;
|
||||||
//@formatter:on
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public SubscriptionTable(){
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
public long getCheckInterval() {
|
public long getCheckInterval() {
|
||||||
return myCheckInterval;
|
return myCheckInterval;
|
||||||
|
|
|
@ -1,89 +0,0 @@
|
||||||
package ca.uhn.fhir.jpa.interceptor;
|
|
||||||
|
|
||||||
/*-
|
|
||||||
* #%L
|
|
||||||
* HAPI FHIR JPA Server
|
|
||||||
* %%
|
|
||||||
* Copyright (C) 2014 - 2017 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 org.hl7.fhir.instance.model.api.IBaseResource;
|
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
|
||||||
|
|
||||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
|
||||||
import ca.uhn.fhir.jpa.dao.*;
|
|
||||||
import ca.uhn.fhir.jpa.provider.ServletSubRequestDetails;
|
|
||||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter;
|
|
||||||
|
|
||||||
public abstract class BaseRestHookSubscriptionInterceptor extends ServerOperationInterceptorAdapter {
|
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseRestHookSubscriptionInterceptor.class);
|
|
||||||
|
|
||||||
protected static final Integer MAX_SUBSCRIPTION_RESULTS = 10000;
|
|
||||||
|
|
||||||
protected abstract IFhirResourceDao<?> getSubscriptionDao();
|
|
||||||
|
|
||||||
protected void checkSubscriptionCriterias(String theCriteria) {
|
|
||||||
try {
|
|
||||||
IBundleProvider results = executeSubscriptionCriteria(theCriteria, null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
ourLog.warn("Invalid criteria when creating subscription", e);
|
|
||||||
throw new InvalidRequestException("Invalid criteria: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private IBundleProvider executeSubscriptionCriteria(String theCriteria, IIdType idType) {
|
|
||||||
String criteria = theCriteria;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Run the subscriptions query and look for matches, add the id as part of the criteria
|
|
||||||
* to avoid getting matches of previous resources rather than the recent resource
|
|
||||||
*/
|
|
||||||
if (idType != null) {
|
|
||||||
criteria += "&_id=" + idType.getResourceType() + "/" + idType.getIdPart();
|
|
||||||
}
|
|
||||||
|
|
||||||
IBundleProvider results = getBundleProvider(criteria, true);
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Search based on a query criteria
|
|
||||||
*
|
|
||||||
* @param theCheckOnly Is this just a test that the search works
|
|
||||||
*/
|
|
||||||
protected IBundleProvider getBundleProvider(String theCriteria, boolean theCheckOnly) {
|
|
||||||
RuntimeResourceDefinition responseResourceDef = getSubscriptionDao().validateCriteriaAndReturnResourceDefinition(theCriteria);
|
|
||||||
SearchParameterMap responseCriteriaUrl = BaseHapiFhirDao.translateMatchUrl(getSubscriptionDao(), getSubscriptionDao().getContext(), theCriteria, responseResourceDef);
|
|
||||||
|
|
||||||
RequestDetails req = new ServletSubRequestDetails();
|
|
||||||
req.setSubRequest(true);
|
|
||||||
|
|
||||||
IFhirResourceDao<? extends IBaseResource> responseDao = getSubscriptionDao().getDao(responseResourceDef.getImplementingClass());
|
|
||||||
|
|
||||||
if (theCheckOnly) {
|
|
||||||
responseCriteriaUrl.setLoadSynchronousUpTo(1);
|
|
||||||
} else {
|
|
||||||
responseCriteriaUrl.setLoadSynchronousUpTo(MAX_SUBSCRIPTION_RESULTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
IBundleProvider responseResults = responseDao.search(responseCriteriaUrl, req);
|
|
||||||
return responseResults;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,88 +0,0 @@
|
||||||
package ca.uhn.fhir.jpa.interceptor;
|
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
|
||||||
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #%L
|
|
||||||
* HAPI FHIR JPA Server
|
|
||||||
* %%
|
|
||||||
* Copyright (C) 2014 - 2017 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%
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Server interceptor for JPA DAOs which adds methods that will be called at certain points
|
|
||||||
* in the operation lifecycle for JPA operations.
|
|
||||||
*
|
|
||||||
* @deprecated Use {@link IServerOperationInterceptor instead}. Deprecated since HAPI FHIR 2.3
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public interface IJpaServerInterceptor extends IServerInterceptor {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is invoked by the JPA DAOs when a resource has been newly created in the database.
|
|
||||||
* It will be invoked within the current transaction scope.
|
|
||||||
* <p>
|
|
||||||
* This method is called within the server database transaction, after the
|
|
||||||
* entity has been persisted and flushed to the database. It may not be a good
|
|
||||||
* candidate for security decisions depending on how your database is set up.
|
|
||||||
* Any exceptions thrown by this method will result in the transaction being
|
|
||||||
* rolled back. Thrown exceptions should be of a type which
|
|
||||||
* subclasses {@link BaseServerResponseException}.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param theDetails The request details
|
|
||||||
* @param theResourceTable The actual created entity
|
|
||||||
*/
|
|
||||||
void resourceCreated(ActionRequestDetails theDetails, ResourceTable theResourceTable);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is invoked by the JPA DAOs when a resource has been updated in the database.
|
|
||||||
* It will be invoked within the current transaction scope.
|
|
||||||
* <p>
|
|
||||||
* This method is called within the server database transaction, after the
|
|
||||||
* entity has been persisted and flushed to the database. It may not be a good
|
|
||||||
* candidate for security decisions depending on how your database is set up.
|
|
||||||
* Any exceptions thrown by this method will result in the transaction being
|
|
||||||
* rolled back. Thrown exceptions should be of a type which
|
|
||||||
* subclasses {@link BaseServerResponseException}.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param theDetails The request details
|
|
||||||
* @param theResourceTable The actual updated entity
|
|
||||||
*/
|
|
||||||
void resourceUpdated(ActionRequestDetails theDetails, ResourceTable theResourceTable);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is invoked by the JPA DAOs when a resource has been updated in the database.
|
|
||||||
* It will be invoked within the current transaction scope.
|
|
||||||
* <p>
|
|
||||||
* This method is called within the server database transaction, after the
|
|
||||||
* entity has been persisted and flushed to the database. It may not be a good
|
|
||||||
* candidate for security decisions depending on how your database is set up.
|
|
||||||
* Any exceptions thrown by this method will result in the transaction being
|
|
||||||
* rolled back. Thrown exceptions should be of a type which
|
|
||||||
* subclasses {@link BaseServerResponseException}.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param theDetails The request details
|
|
||||||
* @param theResourceTable The actual updated entity
|
|
||||||
*/
|
|
||||||
void resourceDeleted(ActionRequestDetails theDetails, ResourceTable theResourceTable);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
package ca.uhn.fhir.jpa.interceptor;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* #%L
|
|
||||||
* HAPI FHIR JPA Server
|
|
||||||
* %%
|
|
||||||
* Copyright (C) 2014 - 2017 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.entity.ResourceTable;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
|
|
||||||
|
|
||||||
public class JpaServerInterceptorAdapter extends InterceptorAdapter implements IJpaServerInterceptor {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resourceCreated(ActionRequestDetails theDetails, ResourceTable theResourceTable) {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resourceUpdated(ActionRequestDetails theDetails, ResourceTable theResourceTable) {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resourceDeleted(ActionRequestDetails theDetails, ResourceTable theResourceTable) {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,93 +0,0 @@
|
||||||
|
|
||||||
package ca.uhn.fhir.jpa.interceptor;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
|
|
||||||
/*-
|
|
||||||
* #%L
|
|
||||||
* HAPI FHIR JPA Server
|
|
||||||
* %%
|
|
||||||
* Copyright (C) 2014 - 2017 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.dao.IFhirResourceDao;
|
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoSubscription;
|
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Subscription;
|
|
||||||
import ca.uhn.fhir.rest.api.RequestTypeEnum;
|
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
|
|
||||||
|
|
||||||
public class WebSocketSubscriptionDstu2Interceptor extends InterceptorAdapter implements IJpaServerInterceptor {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(WebSocketSubscriptionDstu2Interceptor.class);
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
@Qualifier("mySubscriptionDaoDstu2")
|
|
||||||
private IFhirResourceDao<Subscription> reference;
|
|
||||||
|
|
||||||
private IFhirResourceDaoSubscription<Subscription> casted;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void postConstruct(){
|
|
||||||
casted = (IFhirResourceDaoSubscription) reference;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resourceCreated(ActionRequestDetails theDetails, ResourceTable theResourceTable) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resourceUpdated(ActionRequestDetails theDetails, ResourceTable theResourceTable) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resourceDeleted(ActionRequestDetails theDetails, ResourceTable theResourceTable) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks for websocket subscriptions
|
|
||||||
* @param theRequestDetails
|
|
||||||
* A bean containing details about the request that is about to be processed, including details such as the
|
|
||||||
* resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been
|
|
||||||
* pulled out of the {@link HttpServletRequest servlet request}.
|
|
||||||
* @param theResponseObject
|
|
||||||
* The actual object which is being streamed to the client as a response
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject) {
|
|
||||||
if (theRequestDetails.getResourceName() == null ||
|
|
||||||
theRequestDetails.getResourceName().isEmpty() ||
|
|
||||||
theRequestDetails.getResourceName().equals("Subscription")) {
|
|
||||||
return super.outgoingResponse(theRequestDetails, theResponseObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (theRequestDetails.getRequestType().equals(RequestTypeEnum.POST) || theRequestDetails.getRequestType().equals(RequestTypeEnum.PUT)) {
|
|
||||||
logger.info("Found POST or PUT for a non-subscription resource");
|
|
||||||
casted.pollForNewUndeliveredResources(theRequestDetails.getResourceName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.outgoingResponse(theRequestDetails, theResponseObject);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,107 +0,0 @@
|
||||||
|
|
||||||
package ca.uhn.fhir.jpa.interceptor;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import org.hl7.fhir.dstu3.model.Subscription;
|
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
|
|
||||||
/*-
|
|
||||||
* #%L
|
|
||||||
* HAPI FHIR JPA Server
|
|
||||||
* %%
|
|
||||||
* Copyright (C) 2014 - 2017 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.dao.IFhirResourceDao;
|
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoSubscription;
|
|
||||||
import ca.uhn.fhir.rest.api.RequestTypeEnum;
|
|
||||||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
|
||||||
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter;
|
|
||||||
|
|
||||||
public class WebSocketSubscriptionDstu3Interceptor extends ServerOperationInterceptorAdapter {
|
|
||||||
|
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(WebSocketSubscriptionDstu3Interceptor.class);
|
|
||||||
|
|
||||||
private IFhirResourceDaoSubscription<Subscription> mySubscriptionDaoCasted;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
@Qualifier("mySubscriptionDaoDstu3")
|
|
||||||
private IFhirResourceDao<Subscription> mySubscriptionDao;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
|
|
||||||
if (theRequestDetails.getRestOperationType().equals(RestOperationTypeEnum.DELETE)) {
|
|
||||||
mySubscriptionDaoCasted.pollForNewUndeliveredResources(theRequestDetails.getResourceName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.incomingRequestPostProcessed(theRequestDetails, theRequest, theResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks for websocket subscriptions
|
|
||||||
*
|
|
||||||
* @param theRequestDetails
|
|
||||||
* A bean containing details about the request that is about to be processed, including details such as the
|
|
||||||
* resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been
|
|
||||||
* pulled out of the {@link HttpServletRequest servlet request}.
|
|
||||||
* @param theResponseObject
|
|
||||||
* The actual object which is being streamed to the client as a response
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject) {
|
|
||||||
if (theRequestDetails.getResourceName() == null ||
|
|
||||||
theRequestDetails.getResourceName().isEmpty() ||
|
|
||||||
theRequestDetails.getResourceName().equals("Subscription")) {
|
|
||||||
return super.outgoingResponse(theRequestDetails, theResponseObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (theRequestDetails.getRequestType().equals(RequestTypeEnum.POST) || theRequestDetails.getRequestType().equals(RequestTypeEnum.PUT)) {
|
|
||||||
ourLog.info("Found POST or PUT for a non-subscription resource");
|
|
||||||
mySubscriptionDaoCasted.pollForNewUndeliveredResources(theRequestDetails.getResourceName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.outgoingResponse(theRequestDetails, theResponseObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
||||||
@PostConstruct
|
|
||||||
public void postConstruct() {
|
|
||||||
mySubscriptionDaoCasted = (IFhirResourceDaoSubscription) mySubscriptionDao;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resourceCreated(RequestDetails theRequest, IBaseResource theResource) {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resourceDeleted(RequestDetails theRequest, IBaseResource theResource) {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resourceUpdated(RequestDetails theRequest, IBaseResource theOldResource, IBaseResource theNewResource) {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,107 +0,0 @@
|
||||||
|
|
||||||
package ca.uhn.fhir.jpa.interceptor.r4;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import org.hl7.fhir.r4.model.Subscription;
|
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
|
|
||||||
/*-
|
|
||||||
* #%L
|
|
||||||
* HAPI FHIR JPA Server
|
|
||||||
* %%
|
|
||||||
* Copyright (C) 2014 - 2017 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.dao.IFhirResourceDao;
|
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoSubscription;
|
|
||||||
import ca.uhn.fhir.rest.api.RequestTypeEnum;
|
|
||||||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
|
||||||
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter;
|
|
||||||
|
|
||||||
public class WebSocketSubscriptionR4Interceptor extends ServerOperationInterceptorAdapter {
|
|
||||||
|
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(WebSocketSubscriptionR4Interceptor.class);
|
|
||||||
|
|
||||||
private IFhirResourceDaoSubscription<Subscription> mySubscriptionDaoCasted;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
@Qualifier("mySubscriptionDaoR4")
|
|
||||||
private IFhirResourceDao<Subscription> mySubscriptionDao;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
|
|
||||||
if (theRequestDetails.getRestOperationType().equals(RestOperationTypeEnum.DELETE)) {
|
|
||||||
mySubscriptionDaoCasted.pollForNewUndeliveredResources(theRequestDetails.getResourceName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.incomingRequestPostProcessed(theRequestDetails, theRequest, theResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks for websocket subscriptions
|
|
||||||
*
|
|
||||||
* @param theRequestDetails
|
|
||||||
* A bean containing details about the request that is about to be processed, including details such as the
|
|
||||||
* resource type and logical ID (if any) and other FHIR-specific aspects of the request which have been
|
|
||||||
* pulled out of the {@link HttpServletRequest servlet request}.
|
|
||||||
* @param theResponseObject
|
|
||||||
* The actual object which is being streamed to the client as a response
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject) {
|
|
||||||
if (theRequestDetails.getResourceName() == null ||
|
|
||||||
theRequestDetails.getResourceName().isEmpty() ||
|
|
||||||
theRequestDetails.getResourceName().equals("Subscription")) {
|
|
||||||
return super.outgoingResponse(theRequestDetails, theResponseObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (theRequestDetails.getRequestType().equals(RequestTypeEnum.POST) || theRequestDetails.getRequestType().equals(RequestTypeEnum.PUT)) {
|
|
||||||
ourLog.info("Found POST or PUT for a non-subscription resource");
|
|
||||||
mySubscriptionDaoCasted.pollForNewUndeliveredResources(theRequestDetails.getResourceName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.outgoingResponse(theRequestDetails, theResponseObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
||||||
@PostConstruct
|
|
||||||
public void postConstruct() {
|
|
||||||
mySubscriptionDaoCasted = (IFhirResourceDaoSubscription) mySubscriptionDao;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resourceCreated(RequestDetails theRequest, IBaseResource theResource) {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resourceDeleted(RequestDetails theRequest, IBaseResource theResource) {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resourceUpdated(RequestDetails theRequest, IBaseResource theOldResource, IBaseResource theNewResource) {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,6 +18,8 @@ import org.springframework.messaging.SubscribableChannel;
|
||||||
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
||||||
import org.springframework.messaging.support.GenericMessage;
|
import org.springframework.messaging.support.GenericMessage;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
||||||
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
|
@ -40,9 +42,12 @@ public abstract class BaseSubscriptionInterceptor extends ServerOperationInterce
|
||||||
private MessageHandler mySubscriptionCheckingSubscriber;
|
private MessageHandler mySubscriptionCheckingSubscriber;
|
||||||
private ConcurrentHashMap<String, IBaseResource> myIdToSubscription = new ConcurrentHashMap<>();
|
private ConcurrentHashMap<String, IBaseResource> myIdToSubscription = new ConcurrentHashMap<>();
|
||||||
private Logger ourLog = LoggerFactory.getLogger(BaseSubscriptionInterceptor.class);
|
private Logger ourLog = LoggerFactory.getLogger(BaseSubscriptionInterceptor.class);
|
||||||
private SubscriptionDeliveringRestHookSubscriber mySubscriptionDeliverySubscriber;
|
|
||||||
private BlockingQueue<Runnable> myExecutorQueue;
|
private BlockingQueue<Runnable> myExecutorQueue;
|
||||||
|
|
||||||
|
public ConcurrentHashMap<String, IBaseResource> getIdToSubscription() {
|
||||||
|
return myIdToSubscription;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract Subscription.SubscriptionChannelType getChannelType();
|
public abstract Subscription.SubscriptionChannelType getChannelType();
|
||||||
|
|
||||||
public SubscribableChannel getProcessingChannel() {
|
public SubscribableChannel getProcessingChannel() {
|
||||||
|
@ -90,7 +95,7 @@ public abstract class BaseSubscriptionInterceptor extends ServerOperationInterce
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockingQueue<Runnable> getExecutorQueue() {
|
public BlockingQueue<Runnable> getExecutorQueueForUnitTests() {
|
||||||
return myExecutorQueue;
|
return myExecutorQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,31 +127,33 @@ public abstract class BaseSubscriptionInterceptor extends ServerOperationInterce
|
||||||
if (mySubscriptionActivatingSubscriber == null) {
|
if (mySubscriptionActivatingSubscriber == null) {
|
||||||
mySubscriptionActivatingSubscriber = new SubscriptionActivatingSubscriber(getSubscriptionDao(), myIdToSubscription, getChannelType(), myProcessingChannel);
|
mySubscriptionActivatingSubscriber = new SubscriptionActivatingSubscriber(getSubscriptionDao(), myIdToSubscription, getChannelType(), myProcessingChannel);
|
||||||
}
|
}
|
||||||
myProcessingChannel.subscribe(mySubscriptionActivatingSubscriber);
|
getProcessingChannel().subscribe(mySubscriptionActivatingSubscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mySubscriptionCheckingSubscriber == null) {
|
if (mySubscriptionCheckingSubscriber == null) {
|
||||||
mySubscriptionCheckingSubscriber = new SubscriptionCheckingSubscriber(getSubscriptionDao(), myIdToSubscription, getChannelType(), myProcessingChannel);
|
mySubscriptionCheckingSubscriber = new SubscriptionCheckingSubscriber(getSubscriptionDao(), myIdToSubscription, getChannelType(), myProcessingChannel);
|
||||||
}
|
}
|
||||||
myProcessingChannel.subscribe(mySubscriptionCheckingSubscriber);
|
getProcessingChannel().subscribe(mySubscriptionCheckingSubscriber);
|
||||||
|
|
||||||
if (mySubscriptionDeliverySubscriber == null) {
|
registerDeliverySubscriber();
|
||||||
mySubscriptionDeliverySubscriber = new SubscriptionDeliveringRestHookSubscriber(getSubscriptionDao(), myIdToSubscription, getChannelType(), myProcessingChannel);
|
|
||||||
}
|
|
||||||
myProcessingChannel.subscribe(mySubscriptionDeliverySubscriber);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void registerDeliverySubscriber();
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void preDestroy() {
|
public void preDestroy() {
|
||||||
if (myAutoActivateSubscriptions) {
|
if (myAutoActivateSubscriptions) {
|
||||||
myProcessingChannel.unsubscribe(mySubscriptionActivatingSubscriber);
|
getProcessingChannel().unsubscribe(mySubscriptionActivatingSubscriber);
|
||||||
}
|
}
|
||||||
myProcessingChannel.unsubscribe(mySubscriptionCheckingSubscriber);
|
getProcessingChannel().unsubscribe(mySubscriptionCheckingSubscriber);
|
||||||
myProcessingChannel.unsubscribe(mySubscriptionDeliverySubscriber);
|
|
||||||
|
unregisterDeliverySubscriber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void unregisterDeliverySubscriber();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resourceCreated(RequestDetails theRequest, IBaseResource theResource) {
|
public void resourceCreated(RequestDetails theRequest, IBaseResource theResource) {
|
||||||
ResourceModifiedMessage msg = new ResourceModifiedMessage();
|
ResourceModifiedMessage msg = new ResourceModifiedMessage();
|
||||||
|
@ -173,7 +180,15 @@ public abstract class BaseSubscriptionInterceptor extends ServerOperationInterce
|
||||||
submitResourceModified(msg);
|
submitResourceModified(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void submitResourceModified(ResourceModifiedMessage theMsg) {
|
private void submitResourceModified(final ResourceModifiedMessage theMsg) {
|
||||||
myProcessingChannel.send(new GenericMessage<>(theMsg));
|
/*
|
||||||
|
* We only actually submit this item work working after the
|
||||||
|
*/
|
||||||
|
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
|
||||||
|
@Override
|
||||||
|
public void afterCommit() {
|
||||||
|
getProcessingChannel().send(new GenericMessage<>(theMsg));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package ca.uhn.fhir.jpa.subscription;
|
||||||
|
|
||||||
|
public abstract class BaseSubscriptionRestHookInterceptor extends BaseSubscriptionInterceptor {
|
||||||
|
private SubscriptionDeliveringRestHookSubscriber mySubscriptionDeliverySubscriber;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void registerDeliverySubscriber() {
|
||||||
|
if (mySubscriptionDeliverySubscriber == null) {
|
||||||
|
mySubscriptionDeliverySubscriber = new SubscriptionDeliveringRestHookSubscriber(getSubscriptionDao(), getIdToSubscription(), getChannelType(), getProcessingChannel());
|
||||||
|
}
|
||||||
|
getProcessingChannel().subscribe(mySubscriptionDeliverySubscriber);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void unregisterDeliverySubscriber() {
|
||||||
|
getProcessingChannel().unsubscribe(mySubscriptionDeliverySubscriber);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package ca.uhn.fhir.jpa.subscription;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
|
||||||
|
import ca.uhn.fhir.jpa.dao.data.ISubscriptionFlaggedResourceDataDao;
|
||||||
|
import ca.uhn.fhir.jpa.dao.data.ISubscriptionTableDao;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
|
||||||
|
public abstract class BaseSubscriptionWebsocketInterceptor extends BaseSubscriptionInterceptor {
|
||||||
|
private SubscriptionDeliveringWebsocketSubscriber mySubscriptionDeliverySubscriber;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISubscriptionFlaggedResourceDataDao mySubscriptionFlaggedResourceDataDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISubscriptionTableDao mySubscriptionTableDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PlatformTransactionManager myTxManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IResourceTableDao myResourceTableDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void registerDeliverySubscriber() {
|
||||||
|
if (mySubscriptionDeliverySubscriber == null) {
|
||||||
|
mySubscriptionDeliverySubscriber = new SubscriptionDeliveringWebsocketSubscriber(getSubscriptionDao(), getIdToSubscription(), getChannelType(), getProcessingChannel(), myTxManager, mySubscriptionFlaggedResourceDataDao, mySubscriptionTableDao, myResourceTableDao);
|
||||||
|
}
|
||||||
|
getProcessingChannel().subscribe(mySubscriptionDeliverySubscriber);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void unregisterDeliverySubscriber() {
|
||||||
|
getProcessingChannel().unsubscribe(mySubscriptionDeliverySubscriber);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,6 @@ import org.hl7.fhir.r4.model.Subscription;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.MessageHandler;
|
|
||||||
import org.springframework.messaging.MessagingException;
|
import org.springframework.messaging.MessagingException;
|
||||||
import org.springframework.messaging.SubscribableChannel;
|
import org.springframework.messaging.SubscribableChannel;
|
||||||
|
|
||||||
|
@ -41,12 +40,16 @@ public class SubscriptionActivatingSubscriber extends BaseSubscriptionSubscriber
|
||||||
IPrimitiveType<?> status = ctx.newTerser().getSingleValueOrNull(subscription, SUBSCRIPTION_STATUS, IPrimitiveType.class);
|
IPrimitiveType<?> status = ctx.newTerser().getSingleValueOrNull(subscription, SUBSCRIPTION_STATUS, IPrimitiveType.class);
|
||||||
String statusString = status.getValueAsString();
|
String statusString = status.getValueAsString();
|
||||||
|
|
||||||
String oldStatus = Subscription.SubscriptionStatus.REQUESTED.toCode();
|
String requestedStatus = Subscription.SubscriptionStatus.REQUESTED.toCode();
|
||||||
if (oldStatus.equals(statusString)) {
|
String activeStatus = Subscription.SubscriptionStatus.ACTIVE.toCode();
|
||||||
String newStatus = Subscription.SubscriptionStatus.ACTIVE.toCode();
|
if (requestedStatus.equals(statusString)) {
|
||||||
status.setValueAsString(newStatus);
|
status.setValueAsString(activeStatus);
|
||||||
ourLog.info("Activating subscription {} from status {} to {}", subscription.getIdElement().toUnqualifiedVersionless().getValue(), oldStatus, newStatus);
|
ourLog.info("Activating subscription {} from status {} to {}", subscription.getIdElement().toUnqualified().getValue(), requestedStatus, activeStatus);
|
||||||
getSubscriptionDao().update(subscription);
|
getSubscriptionDao().update(subscription);
|
||||||
|
getIdToSubscription().put(subscription.getIdElement().getIdPart(), subscription);
|
||||||
|
} else if (activeStatus.equals(statusString)) {
|
||||||
|
ourLog.info("Newly created active subscription {}", subscription.getIdElement().toUnqualified().getValue());
|
||||||
|
|
||||||
getIdToSubscription().put(subscription.getIdElement().getIdPart(), subscription);
|
getIdToSubscription().put(subscription.getIdElement().getIdPart(), subscription);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,12 +77,6 @@ public class SubscriptionCheckingSubscriber extends BaseSubscriptionSubscriber {
|
||||||
criteria += "&_id=" + resourceType + "/" + resourceId;
|
criteria += "&_id=" + resourceType + "/" + resourceId;
|
||||||
criteria = massageCriteria(criteria);
|
criteria = massageCriteria(criteria);
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(500);
|
|
||||||
} catch (InterruptedException theE) {
|
|
||||||
theE.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
IBundleProvider results = performSearch(criteria);
|
IBundleProvider results = performSearch(criteria);
|
||||||
if (results.size() == 0) {
|
if (results.size() == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -90,11 +84,10 @@ public class SubscriptionCheckingSubscriber extends BaseSubscriptionSubscriber {
|
||||||
|
|
||||||
// should just be one resource as it was filtered by the id
|
// should just be one resource as it was filtered by the id
|
||||||
for (IBaseResource nextBase : results.getResources(0, results.size())) {
|
for (IBaseResource nextBase : results.getResources(0, results.size())) {
|
||||||
IBaseResource next = (IBaseResource) nextBase;
|
ourLog.info("Found match: queueing rest-hook notification for resource: {}", nextBase.getIdElement());
|
||||||
ourLog.info("Found match: queueing rest-hook notification for resource: {}", next.getIdElement());
|
|
||||||
|
|
||||||
ResourceDeliveryMessage deliveryMsg = new ResourceDeliveryMessage();
|
ResourceDeliveryMessage deliveryMsg = new ResourceDeliveryMessage();
|
||||||
deliveryMsg.setPayoad(next);
|
deliveryMsg.setPayoad(nextBase);
|
||||||
deliveryMsg.setSubscription(nextSubscription);
|
deliveryMsg.setSubscription(nextSubscription);
|
||||||
deliveryMsg.setOperationType(msg.getOperationType());
|
deliveryMsg.setOperationType(msg.getOperationType());
|
||||||
deliveryMsg.setPayloadId(msg.getId());
|
deliveryMsg.setPayloadId(msg.getId());
|
||||||
|
|
|
@ -0,0 +1,142 @@
|
||||||
|
package ca.uhn.fhir.jpa.subscription;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.dao.IDao;
|
||||||
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||||
|
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
|
||||||
|
import ca.uhn.fhir.jpa.dao.data.ISubscriptionFlaggedResourceDataDao;
|
||||||
|
import ca.uhn.fhir.jpa.dao.data.ISubscriptionTableDao;
|
||||||
|
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||||
|
import ca.uhn.fhir.jpa.entity.SubscriptionFlaggedResource;
|
||||||
|
import ca.uhn.fhir.jpa.entity.SubscriptionTable;
|
||||||
|
import ca.uhn.fhir.model.api.IResource;
|
||||||
|
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||||
|
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||||
|
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||||
|
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||||
|
import ca.uhn.fhir.rest.gclient.IClientExecutable;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||||
|
import org.hl7.fhir.r4.model.Subscription;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
import org.springframework.messaging.MessagingException;
|
||||||
|
import org.springframework.messaging.SubscribableChannel;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.TransactionStatus;
|
||||||
|
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
|
||||||
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class SubscriptionDeliveringWebsocketSubscriber extends BaseSubscriptionSubscriber {
|
||||||
|
private final PlatformTransactionManager myTxManager;
|
||||||
|
private final ISubscriptionFlaggedResourceDataDao mySubscriptionFlaggedResourceDao;
|
||||||
|
private final ISubscriptionTableDao mySubscriptionTableDao;
|
||||||
|
private final IResourceTableDao myResourceTableDao;
|
||||||
|
private Logger ourLog = LoggerFactory.getLogger(SubscriptionDeliveringWebsocketSubscriber.class);
|
||||||
|
|
||||||
|
public SubscriptionDeliveringWebsocketSubscriber(IFhirResourceDao theSubscriptionDao, ConcurrentHashMap<String, IBaseResource> theIdToSubscription, Subscription.SubscriptionChannelType theChannelType, SubscribableChannel theProcessingChannel, PlatformTransactionManager theTxManager, ISubscriptionFlaggedResourceDataDao theSubscriptionFlaggedResourceDataDao, ISubscriptionTableDao theSubscriptionTableDao, IResourceTableDao theResourceTableDao) {
|
||||||
|
super(theSubscriptionDao, theIdToSubscription, theChannelType, theProcessingChannel);
|
||||||
|
|
||||||
|
myTxManager = theTxManager;
|
||||||
|
mySubscriptionFlaggedResourceDao = theSubscriptionFlaggedResourceDataDao;
|
||||||
|
mySubscriptionTableDao = theSubscriptionTableDao;
|
||||||
|
myResourceTableDao = theResourceTableDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMessage(final Message<?> theMessage) throws MessagingException {
|
||||||
|
if (!(theMessage.getPayload() instanceof ResourceDeliveryMessage)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ResourceDeliveryMessage msg = (ResourceDeliveryMessage) theMessage.getPayload();
|
||||||
|
|
||||||
|
if (!subscriptionTypeApplies(getContext(), msg.getSubscription())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TransactionTemplate txTemplate = new TransactionTemplate(myTxManager);
|
||||||
|
txTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRED);
|
||||||
|
txTemplate.execute(new TransactionCallbackWithoutResult() {
|
||||||
|
@Override
|
||||||
|
protected void doInTransactionWithoutResult(TransactionStatus status) {
|
||||||
|
IBaseResource payload = msg.getPayoad();
|
||||||
|
Long payloadPid = extractResourcePid(payload);
|
||||||
|
ResourceTable payloadTable = myResourceTableDao.findOne(payloadPid);
|
||||||
|
|
||||||
|
IBaseResource subscription = msg.getSubscription();
|
||||||
|
Long subscriptionPid = extractResourcePid(subscription);
|
||||||
|
SubscriptionTable subscriptionTable = mySubscriptionTableDao.findOneByResourcePid(subscriptionPid);
|
||||||
|
|
||||||
|
ourLog.info("Adding new resource {} for subscription: {}", payload.getIdElement().toUnqualified().getValue(), subscription.getIdElement().toUnqualifiedVersionless().getValue());
|
||||||
|
|
||||||
|
SubscriptionFlaggedResource candidate = new SubscriptionFlaggedResource();
|
||||||
|
candidate.setResource(payloadTable);
|
||||||
|
candidate.setSubscription(subscriptionTable);
|
||||||
|
candidate.setVersion(payload.getIdElement().getVersionIdPartAsLong());
|
||||||
|
|
||||||
|
mySubscriptionFlaggedResourceDao.save(candidate);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
RestOperationTypeEnum operationType = msg.getOperationType();
|
||||||
|
IBaseResource subscription = msg.getSubscription();
|
||||||
|
|
||||||
|
// Grab the endpoint from the subscription
|
||||||
|
IPrimitiveType<?> endpoint = getContext().newTerser().getSingleValueOrNull(subscription, BaseSubscriptionInterceptor.SUBSCRIPTION_ENDPOINT, IPrimitiveType.class);
|
||||||
|
String endpointUrl = endpoint.getValueAsString();
|
||||||
|
|
||||||
|
// Grab the payload type (encoding mimetype ) from the subscription
|
||||||
|
IPrimitiveType<?> payload = getContext().newTerser().getSingleValueOrNull(subscription, BaseSubscriptionInterceptor.SUBSCRIPTION_PAYLOAD, IPrimitiveType.class);
|
||||||
|
String payloadString = payload.getValueAsString();
|
||||||
|
if (payloadString.contains(";")) {
|
||||||
|
payloadString = payloadString.substring(0, payloadString.indexOf(';'));
|
||||||
|
}
|
||||||
|
payloadString = payloadString.trim();
|
||||||
|
EncodingEnum payloadType = EncodingEnum.forContentType(payloadString);
|
||||||
|
payloadType = ObjectUtils.defaultIfNull(payloadType, EncodingEnum.XML);
|
||||||
|
|
||||||
|
getContext().getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||||
|
IGenericClient client = getContext().newRestfulGenericClient(endpointUrl);
|
||||||
|
|
||||||
|
IBaseResource payloadResource = msg.getPayoad();
|
||||||
|
|
||||||
|
IClientExecutable<?, ?> operation;
|
||||||
|
switch (operationType) {
|
||||||
|
case CREATE:
|
||||||
|
operation = client.create().resource(payloadResource);
|
||||||
|
break;
|
||||||
|
case UPDATE:
|
||||||
|
operation = client.update().resource(payloadResource);
|
||||||
|
break;
|
||||||
|
case DELETE:
|
||||||
|
operation = client.delete().resourceById(msg.getPayloadId());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ourLog.warn("Ignoring delivery message of type: {}", msg.getOperationType());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
operation.encoded(payloadType);
|
||||||
|
|
||||||
|
ourLog.info("Delivering {} rest-hook payload {} for {}", operationType, payloadResource.getIdElement().toUnqualified().getValue(), subscription.getIdElement().toUnqualifiedVersionless().getValue());
|
||||||
|
|
||||||
|
operation.execute();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long extractResourcePid(IBaseResource thePayoad) {
|
||||||
|
Long pid;
|
||||||
|
if (thePayoad instanceof IResource) {
|
||||||
|
pid = IDao.RESOURCE_PID.get((IResource) thePayoad);
|
||||||
|
} else {
|
||||||
|
pid = IDao.RESOURCE_PID.get((IAnyResource) thePayoad);
|
||||||
|
}
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package ca.uhn.fhir.jpa.interceptor;
|
package ca.uhn.fhir.jpa.subscription.dstu2;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
|
@ -21,12 +21,12 @@ package ca.uhn.fhir.jpa.interceptor;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||||
import ca.uhn.fhir.jpa.subscription.BaseSubscriptionInterceptor;
|
import ca.uhn.fhir.jpa.subscription.BaseSubscriptionRestHookInterceptor;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Subscription;
|
import ca.uhn.fhir.model.dstu2.resource.Subscription;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|
||||||
public class RestHookSubscriptionDstu2Interceptor extends BaseSubscriptionInterceptor {
|
public class RestHookSubscriptionDstu2Interceptor extends BaseSubscriptionRestHookInterceptor {
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("mySubscriptionDaoDstu2")
|
@Qualifier("mySubscriptionDaoDstu2")
|
||||||
private IFhirResourceDao<Subscription> mySubscriptionDao;
|
private IFhirResourceDao<Subscription> mySubscriptionDao;
|
|
@ -1,4 +1,4 @@
|
||||||
package ca.uhn.fhir.jpa.subscription;
|
package ca.uhn.fhir.jpa.subscription.dstu2;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
|
@ -27,6 +27,7 @@ import java.util.concurrent.ScheduledFuture;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.subscription.ISubscriptionWebsocketHandler;
|
||||||
import org.apache.http.NameValuePair;
|
import org.apache.http.NameValuePair;
|
||||||
import org.apache.http.client.utils.URLEncodedUtils;
|
import org.apache.http.client.utils.URLEncodedUtils;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
package ca.uhn.fhir.jpa.subscription;
|
package ca.uhn.fhir.jpa.subscription.dstu2;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -8,6 +8,7 @@ import java.util.concurrent.ScheduledFuture;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.subscription.ISubscriptionWebsocketHandler;
|
||||||
import org.apache.http.NameValuePair;
|
import org.apache.http.NameValuePair;
|
||||||
import org.apache.http.client.utils.URLEncodedUtils;
|
import org.apache.http.client.utils.URLEncodedUtils;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
|
@ -0,0 +1,45 @@
|
||||||
|
|
||||||
|
package ca.uhn.fhir.jpa.subscription.dstu2;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||||
|
import ca.uhn.fhir.jpa.subscription.BaseSubscriptionWebsocketInterceptor;
|
||||||
|
import ca.uhn.fhir.model.dstu2.resource.Subscription;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* HAPI FHIR JPA Server
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2014 - 2017 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%
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class WebSocketSubscriptionDstu2Interceptor extends BaseSubscriptionWebsocketInterceptor {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("mySubscriptionDaoDstu2")
|
||||||
|
private IFhirResourceDao<Subscription> mySubscriptionDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType getChannelType() {
|
||||||
|
return org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType.WEBSOCKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IFhirResourceDao<?> getSubscriptionDao() {
|
||||||
|
return mySubscriptionDao;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
|
package ca.uhn.fhir.jpa.subscription.dstu3;
|
||||||
package ca.uhn.fhir.jpa.interceptor;
|
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
|
@ -22,22 +21,21 @@ package ca.uhn.fhir.jpa.interceptor;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||||
import ca.uhn.fhir.jpa.subscription.BaseSubscriptionInterceptor;
|
import ca.uhn.fhir.jpa.subscription.BaseSubscriptionRestHookInterceptor;
|
||||||
import org.hl7.fhir.dstu3.model.Subscription;
|
import org.hl7.fhir.dstu3.model.Subscription;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|
||||||
public class RestHookSubscriptionDstu3Interceptor extends BaseSubscriptionInterceptor
|
public class RestHookSubscriptionDstu3Interceptor extends BaseSubscriptionRestHookInterceptor {
|
||||||
{
|
@Autowired
|
||||||
|
@Qualifier("mySubscriptionDaoDstu3")
|
||||||
|
private IFhirResourceDao<Subscription> mySubscriptionDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IFhirResourceDao<?> getSubscriptionDao() {
|
protected IFhirResourceDao<?> getSubscriptionDao() {
|
||||||
return mySubscriptionDao;
|
return mySubscriptionDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
|
||||||
@Qualifier("mySubscriptionDaoDstu3")
|
|
||||||
private IFhirResourceDao<Subscription> mySubscriptionDao;
|
|
||||||
|
|
||||||
public void setSubscriptionDao(IFhirResourceDao<Subscription> theSubscriptionDao) {
|
public void setSubscriptionDao(IFhirResourceDao<Subscription> theSubscriptionDao) {
|
||||||
mySubscriptionDao = theSubscriptionDao;
|
mySubscriptionDao = theSubscriptionDao;
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package ca.uhn.fhir.jpa.subscription;
|
package ca.uhn.fhir.jpa.subscription.dstu3;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
|
@ -27,6 +27,7 @@ import java.util.concurrent.ScheduledFuture;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.subscription.ISubscriptionWebsocketHandler;
|
||||||
import org.apache.http.NameValuePair;
|
import org.apache.http.NameValuePair;
|
||||||
import org.apache.http.client.utils.URLEncodedUtils;
|
import org.apache.http.client.utils.URLEncodedUtils;
|
||||||
import org.hl7.fhir.dstu3.model.IdType;
|
import org.hl7.fhir.dstu3.model.IdType;
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
package ca.uhn.fhir.jpa.subscription;
|
package ca.uhn.fhir.jpa.subscription.dstu3;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -8,6 +8,7 @@ import java.util.concurrent.ScheduledFuture;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.subscription.ISubscriptionWebsocketHandler;
|
||||||
import org.apache.http.NameValuePair;
|
import org.apache.http.NameValuePair;
|
||||||
import org.apache.http.client.utils.URLEncodedUtils;
|
import org.apache.http.client.utils.URLEncodedUtils;
|
||||||
import org.hl7.fhir.dstu3.model.IdType;
|
import org.hl7.fhir.dstu3.model.IdType;
|
|
@ -0,0 +1,57 @@
|
||||||
|
|
||||||
|
package ca.uhn.fhir.jpa.subscription.dstu3;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.subscription.BaseSubscriptionWebsocketInterceptor;
|
||||||
|
import org.hl7.fhir.dstu3.model.Subscription;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* HAPI FHIR JPA Server
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2014 - 2017 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.dao.IFhirResourceDao;
|
||||||
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoSubscription;
|
||||||
|
import ca.uhn.fhir.rest.api.RequestTypeEnum;
|
||||||
|
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||||
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
|
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
||||||
|
import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter;
|
||||||
|
|
||||||
|
public class WebSocketSubscriptionDstu3Interceptor extends BaseSubscriptionWebsocketInterceptor {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("mySubscriptionDaoDstu3")
|
||||||
|
private IFhirResourceDao<org.hl7.fhir.dstu3.model.Subscription> mySubscriptionDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType getChannelType() {
|
||||||
|
return org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType.WEBSOCKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IFhirResourceDao<?> getSubscriptionDao() {
|
||||||
|
return mySubscriptionDao;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package ca.uhn.fhir.jpa.interceptor.r4;
|
package ca.uhn.fhir.jpa.subscription.r4;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
|
@ -21,11 +21,11 @@ package ca.uhn.fhir.jpa.interceptor.r4;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||||
import ca.uhn.fhir.jpa.subscription.BaseSubscriptionInterceptor;
|
import ca.uhn.fhir.jpa.subscription.BaseSubscriptionRestHookInterceptor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|
||||||
public class RestHookSubscriptionR4Interceptor extends BaseSubscriptionInterceptor {
|
public class RestHookSubscriptionR4Interceptor extends BaseSubscriptionRestHookInterceptor {
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("mySubscriptionDaoR4")
|
@Qualifier("mySubscriptionDaoR4")
|
||||||
private IFhirResourceDao<org.hl7.fhir.r4.model.Subscription> mySubscriptionDao;
|
private IFhirResourceDao<org.hl7.fhir.r4.model.Subscription> mySubscriptionDao;
|
|
@ -0,0 +1,44 @@
|
||||||
|
package ca.uhn.fhir.jpa.subscription.r4;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||||
|
import ca.uhn.fhir.jpa.subscription.BaseSubscriptionWebsocketInterceptor;
|
||||||
|
import org.hl7.fhir.r4.model.Subscription;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* HAPI FHIR JPA Server
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2014 - 2017 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%
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class WebSocketSubscriptionR4Interceptor extends BaseSubscriptionWebsocketInterceptor {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("mySubscriptionDaoR4")
|
||||||
|
private IFhirResourceDao<org.hl7.fhir.r4.model.Subscription> mySubscriptionDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Subscription.SubscriptionChannelType getChannelType() {
|
||||||
|
return Subscription.SubscriptionChannelType.WEBSOCKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IFhirResourceDao<?> getSubscriptionDao() {
|
||||||
|
return mySubscriptionDao;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,19 +1,16 @@
|
||||||
package ca.uhn.fhir.jpa.dao.dstu2;
|
package ca.uhn.fhir.jpa.dao.dstu2;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||||
import static org.junit.Assert.assertEquals;
|
import ca.uhn.fhir.jpa.dao.DeleteMethodOutcome;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||||
import static org.junit.Assert.assertThat;
|
import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum;
|
||||||
import static org.mockito.Matchers.any;
|
import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import ca.uhn.fhir.model.primitive.IdDt;
|
||||||
import static org.mockito.Mockito.mock;
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
import static org.mockito.Mockito.times;
|
import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor;
|
||||||
import static org.mockito.Mockito.verify;
|
import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
|
|
||||||
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
|
|
||||||
import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb;
|
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
@ -24,26 +21,15 @@ import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import ca.uhn.fhir.jpa.dao.DaoMethodOutcome;
|
import static org.junit.Assert.*;
|
||||||
import ca.uhn.fhir.jpa.dao.DeleteMethodOutcome;
|
import static org.mockito.Matchers.any;
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
import static org.mockito.Mockito.*;
|
||||||
import ca.uhn.fhir.jpa.interceptor.IJpaServerInterceptor;
|
|
||||||
import ca.uhn.fhir.jpa.interceptor.JpaServerInterceptorAdapter;
|
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum;
|
|
||||||
import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum;
|
|
||||||
import ca.uhn.fhir.model.primitive.IdDt;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
|
||||||
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
|
||||||
|
|
||||||
public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2InterceptorTest.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2InterceptorTest.class);
|
||||||
private IJpaServerInterceptor myJpaInterceptor;
|
private IServerOperationInterceptor myJpaInterceptor;
|
||||||
private JpaServerInterceptorAdapter myJpaInterceptorAdapter = new JpaServerInterceptorAdapter();
|
private ServerOperationInterceptorAdapter myJpaInterceptorAdapter = new ServerOperationInterceptorAdapter();
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void after() {
|
public void after() {
|
||||||
|
@ -54,7 +40,7 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
myJpaInterceptor = mock(IJpaServerInterceptor.class);
|
myJpaInterceptor = mock(IServerOperationInterceptor.class);
|
||||||
myDaoConfig.getInterceptors().add(myJpaInterceptor);
|
myDaoConfig.getInterceptors().add(myJpaInterceptor);
|
||||||
myDaoConfig.getInterceptors().add(myJpaInterceptorAdapter);
|
myDaoConfig.getInterceptors().add(myJpaInterceptorAdapter);
|
||||||
}
|
}
|
||||||
|
@ -66,17 +52,17 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
||||||
p.addName().addFamily("PATIENT");
|
p.addName().addFamily("PATIENT");
|
||||||
Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong();
|
Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong();
|
||||||
|
|
||||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||||
ArgumentCaptor<ResourceTable> tableCapt;
|
ArgumentCaptor<IBaseResource> tableCapt;
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertNotNull(tableCapt.getValue().getId());
|
assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
|
||||||
assertEquals(id, tableCapt.getValue().getId());
|
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -87,8 +73,8 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
||||||
Long id2 = myPatientDao.create(p, "Patient?family=PATIENT", mySrd).getId().getIdPartAsLong();
|
Long id2 = myPatientDao.create(p, "Patient?family=PATIENT", mySrd).getId().getIdPartAsLong();
|
||||||
assertEquals(id, id2);
|
assertEquals(id, id2);
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||||
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
|
|
||||||
|
@ -102,14 +88,14 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
||||||
|
|
||||||
myPatientDao.delete(new IdDt("Patient", id), mySrd);
|
myPatientDao.delete(new IdDt("Patient", id), mySrd);
|
||||||
|
|
||||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||||
ArgumentCaptor<ResourceTable> tableCapt;
|
ArgumentCaptor<IBaseResource> tableCapt;
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceDeleted(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceDeleted(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertNotNull(tableCapt.getValue().getId());
|
assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
|
||||||
assertEquals(id, tableCapt.getValue().getId());
|
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,14 +118,14 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
||||||
Long id2 = myPatientDao.update(p, mySrd).getId().getIdPartAsLong();
|
Long id2 = myPatientDao.update(p, mySrd).getId().getIdPartAsLong();
|
||||||
assertEquals(id, id2);
|
assertEquals(id, id2);
|
||||||
|
|
||||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||||
ArgumentCaptor<ResourceTable> tableCapt;
|
ArgumentCaptor<IBaseResource> tableCapt;
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertNotNull(tableCapt.getValue().getId());
|
assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
|
||||||
assertEquals(id, tableCapt.getValue().getId());
|
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now do a conditional update
|
* Now do a conditional update
|
||||||
|
@ -151,11 +137,11 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
||||||
id2 = myPatientDao.update(p, "Patient?family=PATIENT1", mySrd).getId().getIdPartAsLong();
|
id2 = myPatientDao.update(p, "Patient?family=PATIENT1", mySrd).getId().getIdPartAsLong();
|
||||||
assertEquals(id, id2);
|
assertEquals(id, id2);
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||||
verify(myJpaInterceptor, times(2)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(2)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertEquals(id, tableCapt.getAllValues().get(2).getId());
|
assertEquals(id, tableCapt.getAllValues().get(2).getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now do a conditional update where none will match (so this is actually a create)
|
* Now do a conditional update where none will match (so this is actually a create)
|
||||||
|
@ -166,11 +152,11 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
||||||
id2 = myPatientDao.update(p, "Patient?family=ZZZ", mySrd).getId().getIdPartAsLong();
|
id2 = myPatientDao.update(p, "Patient?family=ZZZ", mySrd).getId().getIdPartAsLong();
|
||||||
assertNotEquals(id, id2);
|
assertNotEquals(id, id2);
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(2)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(2)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
verify(myJpaInterceptor, times(2)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(2)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertEquals(id2, tableCapt.getAllValues().get(3).getId());
|
assertEquals(id2, tableCapt.getAllValues().get(3).getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -347,6 +333,7 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
||||||
.setUrl("Patient?name=PATIENT")
|
.setUrl("Patient?name=PATIENT")
|
||||||
.setMethod(HTTPVerbEnum.DELETE);
|
.setMethod(HTTPVerbEnum.DELETE);
|
||||||
Bundle resp = mySystemDao.transaction(mySrd, xactBundle);
|
Bundle resp = mySystemDao.transaction(mySrd, xactBundle);
|
||||||
|
assertNotNull(resp);
|
||||||
|
|
||||||
verify(myRequestOperationCallback, times(2)).resourceDeleted(any(IBaseResource.class));
|
verify(myRequestOperationCallback, times(2)).resourceDeleted(any(IBaseResource.class));
|
||||||
verify(myRequestOperationCallback, times(2)).resourceCreated(any(IBaseResource.class));
|
verify(myRequestOperationCallback, times(2)).resourceCreated(any(IBaseResource.class));
|
||||||
|
|
|
@ -1,35 +1,36 @@
|
||||||
package ca.uhn.fhir.jpa.dao.dstu3;
|
package ca.uhn.fhir.jpa.dao.dstu3;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||||
|
import ca.uhn.fhir.jpa.dao.DeleteMethodOutcome;
|
||||||
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
|
import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor;
|
||||||
|
import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter;
|
||||||
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
|
import org.hl7.fhir.dstu3.model.Bundle;
|
||||||
|
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
|
||||||
|
import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb;
|
||||||
|
import org.hl7.fhir.dstu3.model.IdType;
|
||||||
|
import org.hl7.fhir.dstu3.model.Patient;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import org.hl7.fhir.dstu3.model.*;
|
|
||||||
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
|
|
||||||
import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb;
|
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
|
||||||
import org.junit.*;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
|
||||||
import org.mockito.stubbing.Answer;
|
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
|
||||||
import ca.uhn.fhir.jpa.dao.DeleteMethodOutcome;
|
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
|
||||||
import ca.uhn.fhir.jpa.interceptor.IJpaServerInterceptor;
|
|
||||||
import ca.uhn.fhir.jpa.interceptor.JpaServerInterceptorAdapter;
|
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor;
|
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
|
||||||
|
|
||||||
public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3InterceptorTest.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3InterceptorTest.class);
|
||||||
private IJpaServerInterceptor myJpaInterceptor;
|
private IServerOperationInterceptor myJpaInterceptor;
|
||||||
private JpaServerInterceptorAdapter myJpaInterceptorAdapter = new JpaServerInterceptorAdapter();
|
private ServerOperationInterceptorAdapter myJpaInterceptorAdapter = new ServerOperationInterceptorAdapter();
|
||||||
private IServerOperationInterceptor myServerOperationInterceptor;
|
private IServerOperationInterceptor myServerOperationInterceptor;
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -41,7 +42,7 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
myJpaInterceptor = mock(IJpaServerInterceptor.class);
|
myJpaInterceptor = mock(IServerOperationInterceptor.class);
|
||||||
|
|
||||||
myServerOperationInterceptor = mock(IServerOperationInterceptor.class, new Answer<Object>() {
|
myServerOperationInterceptor = mock(IServerOperationInterceptor.class, new Answer<Object>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,17 +65,17 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
||||||
p.addName().setFamily("PATIENT");
|
p.addName().setFamily("PATIENT");
|
||||||
Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong();
|
Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong();
|
||||||
|
|
||||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||||
ArgumentCaptor<ResourceTable> tableCapt;
|
ArgumentCaptor<IBaseResource> tableCapt;
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertNotNull(tableCapt.getValue().getId());
|
assertNotNull(tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||||
assertEquals(id, tableCapt.getValue().getId());
|
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -85,8 +86,8 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
||||||
Long id2 = myPatientDao.create(p, "Patient?family=PATIENT", mySrd).getId().getIdPartAsLong();
|
Long id2 = myPatientDao.create(p, "Patient?family=PATIENT", mySrd).getId().getIdPartAsLong();
|
||||||
assertEquals(id, id2);
|
assertEquals(id, id2);
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||||
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
|
|
||||||
|
@ -107,14 +108,14 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
||||||
|
|
||||||
myPatientDao.delete(new IdType("Patient", id), mySrd);
|
myPatientDao.delete(new IdType("Patient", id), mySrd);
|
||||||
|
|
||||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||||
ArgumentCaptor<ResourceTable> tableCapt;
|
ArgumentCaptor<IBaseResource> tableCapt;
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceDeleted(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceDeleted(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertNotNull(tableCapt.getValue().getId());
|
assertNotNull(tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||||
assertEquals(id, tableCapt.getValue().getId());
|
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,14 +131,14 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
||||||
Long id2 = myPatientDao.update(p, mySrd).getId().getIdPartAsLong();
|
Long id2 = myPatientDao.update(p, mySrd).getId().getIdPartAsLong();
|
||||||
assertEquals(id, id2);
|
assertEquals(id, id2);
|
||||||
|
|
||||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||||
ArgumentCaptor<ResourceTable> tableCapt;
|
ArgumentCaptor<IBaseResource> tableCapt;
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertNotNull(tableCapt.getValue().getId());
|
assertNotNull(tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||||
assertEquals(id, tableCapt.getValue().getId());
|
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now do a conditional update
|
* Now do a conditional update
|
||||||
|
@ -149,11 +150,11 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
||||||
id2 = myPatientDao.update(p, "Patient?family=PATIENT1", mySrd).getId().getIdPartAsLong();
|
id2 = myPatientDao.update(p, "Patient?family=PATIENT1", mySrd).getId().getIdPartAsLong();
|
||||||
assertEquals(id, id2);
|
assertEquals(id, id2);
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||||
verify(myJpaInterceptor, times(2)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(2)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertEquals(id, tableCapt.getAllValues().get(2).getId());
|
assertEquals(id, tableCapt.getAllValues().get(2).getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now do a conditional update where none will match (so this is actually a create)
|
* Now do a conditional update where none will match (so this is actually a create)
|
||||||
|
@ -164,11 +165,11 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
||||||
id2 = myPatientDao.update(p, "Patient?family=ZZZ", mySrd).getId().getIdPartAsLong();
|
id2 = myPatientDao.update(p, "Patient?family=ZZZ", mySrd).getId().getIdPartAsLong();
|
||||||
assertNotEquals(id, id2);
|
assertNotEquals(id, id2);
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(2)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(2)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
verify(myJpaInterceptor, times(2)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(2)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertEquals(id2, tableCapt.getAllValues().get(3).getId());
|
assertEquals(id2, tableCapt.getAllValues().get(3).getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,35 +1,36 @@
|
||||||
package ca.uhn.fhir.jpa.dao.r4;
|
package ca.uhn.fhir.jpa.dao.r4;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||||
|
import ca.uhn.fhir.jpa.dao.DeleteMethodOutcome;
|
||||||
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
|
import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor;
|
||||||
|
import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter;
|
||||||
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
|
import org.hl7.fhir.r4.model.Bundle;
|
||||||
|
import org.hl7.fhir.r4.model.Bundle.BundleType;
|
||||||
|
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
|
||||||
|
import org.hl7.fhir.r4.model.IdType;
|
||||||
|
import org.hl7.fhir.r4.model.Patient;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import org.hl7.fhir.r4.model.*;
|
|
||||||
import org.hl7.fhir.r4.model.Bundle.BundleType;
|
|
||||||
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
|
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
|
||||||
import org.junit.*;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
|
||||||
import org.mockito.stubbing.Answer;
|
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
|
||||||
import ca.uhn.fhir.jpa.dao.DeleteMethodOutcome;
|
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
|
||||||
import ca.uhn.fhir.jpa.interceptor.IJpaServerInterceptor;
|
|
||||||
import ca.uhn.fhir.jpa.interceptor.JpaServerInterceptorAdapter;
|
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor;
|
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
|
||||||
|
|
||||||
public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4InterceptorTest.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4InterceptorTest.class);
|
||||||
private IJpaServerInterceptor myJpaInterceptor;
|
private IServerOperationInterceptor myJpaInterceptor;
|
||||||
private JpaServerInterceptorAdapter myJpaInterceptorAdapter = new JpaServerInterceptorAdapter();
|
private ServerOperationInterceptorAdapter myJpaInterceptorAdapter = new ServerOperationInterceptorAdapter();
|
||||||
private IServerOperationInterceptor myServerOperationInterceptor;
|
private IServerOperationInterceptor myServerOperationInterceptor;
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -41,7 +42,7 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
myJpaInterceptor = mock(IJpaServerInterceptor.class);
|
myJpaInterceptor = mock(IServerOperationInterceptor.class);
|
||||||
|
|
||||||
myServerOperationInterceptor = mock(IServerOperationInterceptor.class, new Answer<Object>() {
|
myServerOperationInterceptor = mock(IServerOperationInterceptor.class, new Answer<Object>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,17 +65,17 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
||||||
p.addName().setFamily("PATIENT");
|
p.addName().setFamily("PATIENT");
|
||||||
Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong();
|
Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong();
|
||||||
|
|
||||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||||
ArgumentCaptor<ResourceTable> tableCapt;
|
ArgumentCaptor<IBaseResource> tableCapt;
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertNotNull(tableCapt.getValue().getId());
|
assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
|
||||||
assertEquals(id, tableCapt.getValue().getId());
|
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -85,8 +86,8 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
||||||
Long id2 = myPatientDao.create(p, "Patient?family=PATIENT", mySrd).getId().getIdPartAsLong();
|
Long id2 = myPatientDao.create(p, "Patient?family=PATIENT", mySrd).getId().getIdPartAsLong();
|
||||||
assertEquals(id, id2);
|
assertEquals(id, id2);
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||||
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(0)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
|
|
||||||
|
@ -107,14 +108,14 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
||||||
|
|
||||||
myPatientDao.delete(new IdType("Patient", id), mySrd);
|
myPatientDao.delete(new IdType("Patient", id), mySrd);
|
||||||
|
|
||||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||||
ArgumentCaptor<ResourceTable> tableCapt;
|
ArgumentCaptor<IBaseResource> tableCapt;
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceDeleted(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceDeleted(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertNotNull(tableCapt.getValue().getId());
|
assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
|
||||||
assertEquals(id, tableCapt.getValue().getId());
|
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,14 +131,14 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
||||||
Long id2 = myPatientDao.update(p, mySrd).getId().getIdPartAsLong();
|
Long id2 = myPatientDao.update(p, mySrd).getId().getIdPartAsLong();
|
||||||
assertEquals(id, id2);
|
assertEquals(id, id2);
|
||||||
|
|
||||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||||
ArgumentCaptor<ResourceTable> tableCapt;
|
ArgumentCaptor<IBaseResource> tableCapt;
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertNotNull(tableCapt.getValue().getId());
|
assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
|
||||||
assertEquals(id, tableCapt.getValue().getId());
|
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now do a conditional update
|
* Now do a conditional update
|
||||||
|
@ -149,11 +150,11 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
||||||
id2 = myPatientDao.update(p, "Patient?family=PATIENT1", mySrd).getId().getIdPartAsLong();
|
id2 = myPatientDao.update(p, "Patient?family=PATIENT1", mySrd).getId().getIdPartAsLong();
|
||||||
assertEquals(id, id2);
|
assertEquals(id, id2);
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||||
verify(myJpaInterceptor, times(2)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(2)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertEquals(id, tableCapt.getAllValues().get(2).getId());
|
assertEquals(id, tableCapt.getAllValues().get(2).getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now do a conditional update where none will match (so this is actually a create)
|
* Now do a conditional update where none will match (so this is actually a create)
|
||||||
|
@ -164,11 +165,11 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
||||||
id2 = myPatientDao.update(p, "Patient?family=ZZZ", mySrd).getId().getIdPartAsLong();
|
id2 = myPatientDao.update(p, "Patient?family=ZZZ", mySrd).getId().getIdPartAsLong();
|
||||||
assertNotEquals(id, id2);
|
assertNotEquals(id, id2);
|
||||||
|
|
||||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||||
verify(myJpaInterceptor, times(2)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(2)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||||
verify(myJpaInterceptor, times(2)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
verify(myJpaInterceptor, times(2)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||||
assertEquals(id2, tableCapt.getAllValues().get(3).getId());
|
assertEquals(id2, tableCapt.getAllValues().get(3).getIdElement().getIdPartAsLong());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||||
import ca.uhn.fhir.jpa.config.WebsocketDstu2Config;
|
import ca.uhn.fhir.jpa.config.WebsocketDstu2Config;
|
||||||
import ca.uhn.fhir.jpa.config.WebsocketDstu2DispatcherConfig;
|
import ca.uhn.fhir.jpa.config.WebsocketDstu2DispatcherConfig;
|
||||||
import ca.uhn.fhir.jpa.dao.dstu2.BaseJpaDstu2Test;
|
import ca.uhn.fhir.jpa.dao.dstu2.BaseJpaDstu2Test;
|
||||||
import ca.uhn.fhir.jpa.interceptor.RestHookSubscriptionDstu2Interceptor;
|
import ca.uhn.fhir.jpa.subscription.dstu2.RestHookSubscriptionDstu2Interceptor;
|
||||||
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
||||||
import ca.uhn.fhir.jpa.testutil.RandomServerPortProvider;
|
import ca.uhn.fhir.jpa.testutil.RandomServerPortProvider;
|
||||||
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||||
|
|
|
@ -26,7 +26,7 @@ import ca.uhn.fhir.jpa.config.dstu3.WebsocketDstu3DispatcherConfig;
|
||||||
import ca.uhn.fhir.jpa.dao.data.ISearchDao;
|
import ca.uhn.fhir.jpa.dao.data.ISearchDao;
|
||||||
import ca.uhn.fhir.jpa.dao.dstu3.BaseJpaDstu3Test;
|
import ca.uhn.fhir.jpa.dao.dstu3.BaseJpaDstu3Test;
|
||||||
import ca.uhn.fhir.jpa.dao.dstu3.SearchParamRegistryDstu3;
|
import ca.uhn.fhir.jpa.dao.dstu3.SearchParamRegistryDstu3;
|
||||||
import ca.uhn.fhir.jpa.interceptor.RestHookSubscriptionDstu3Interceptor;
|
import ca.uhn.fhir.jpa.subscription.dstu3.RestHookSubscriptionDstu3Interceptor;
|
||||||
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
||||||
import ca.uhn.fhir.jpa.search.ISearchCoordinatorSvc;
|
import ca.uhn.fhir.jpa.search.ISearchCoordinatorSvc;
|
||||||
import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainDstu3;
|
import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainDstu3;
|
||||||
|
|
|
@ -26,7 +26,7 @@ import ca.uhn.fhir.jpa.config.r4.WebsocketR4DispatcherConfig;
|
||||||
import ca.uhn.fhir.jpa.dao.data.ISearchDao;
|
import ca.uhn.fhir.jpa.dao.data.ISearchDao;
|
||||||
import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test;
|
import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test;
|
||||||
import ca.uhn.fhir.jpa.dao.r4.SearchParamRegistryR4;
|
import ca.uhn.fhir.jpa.dao.r4.SearchParamRegistryR4;
|
||||||
import ca.uhn.fhir.jpa.interceptor.r4.RestHookSubscriptionR4Interceptor;
|
import ca.uhn.fhir.jpa.subscription.r4.RestHookSubscriptionR4Interceptor;
|
||||||
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
||||||
import ca.uhn.fhir.jpa.search.ISearchCoordinatorSvc;
|
import ca.uhn.fhir.jpa.search.ISearchCoordinatorSvc;
|
||||||
import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainR4;
|
import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainR4;
|
||||||
|
|
|
@ -50,6 +50,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void afterUnregisterRestHookListener() {
|
public void afterUnregisterRestHookListener() {
|
||||||
|
ourLog.info("** AFTER **");
|
||||||
for (IIdType next : mySubscriptionIds) {
|
for (IIdType next : mySubscriptionIds) {
|
||||||
ourClient.delete().resourceById(next).execute();
|
ourClient.delete().resourceById(next).execute();
|
||||||
}
|
}
|
||||||
|
@ -279,11 +280,11 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void waitForQueueToDrain() throws InterruptedException {
|
private void waitForQueueToDrain() throws InterruptedException {
|
||||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueue().size());
|
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||||
while (ourRestHookSubscriptionInterceptor.getExecutorQueue().size() > 0) {
|
while (ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size() > 0) {
|
||||||
Thread.sleep(250);
|
Thread.sleep(250);
|
||||||
}
|
}
|
||||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueue().size());
|
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
|
|
@ -21,8 +21,6 @@ import org.hl7.fhir.dstu3.model.*;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
import org.springframework.messaging.support.ChannelInterceptor;
|
|
||||||
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -153,11 +151,11 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void waitForQueueToDrain() throws InterruptedException {
|
private void waitForQueueToDrain() throws InterruptedException {
|
||||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueue().size());
|
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||||
while (ourRestHookSubscriptionInterceptor.getExecutorQueue().size() > 0) {
|
while (ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size() > 0) {
|
||||||
Thread.sleep(250);
|
Thread.sleep(250);
|
||||||
}
|
}
|
||||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueue().size());
|
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -53,6 +53,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void afterUnregisterRestHookListener() {
|
public void afterUnregisterRestHookListener() {
|
||||||
|
ourLog.info("** AFTER **");
|
||||||
myDaoConfig.setAllowMultipleDelete(true);
|
myDaoConfig.setAllowMultipleDelete(true);
|
||||||
ourLog.info("Deleting all subscriptions");
|
ourLog.info("Deleting all subscriptions");
|
||||||
ourClient.delete().resourceConditionalByUrl("Subscription?status=active").execute();
|
ourClient.delete().resourceConditionalByUrl("Subscription?status=active").execute();
|
||||||
|
@ -73,10 +74,20 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
ourUpdatedObservations.clear();
|
ourUpdatedObservations.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Subscription createSubscription(String criteria, String payload, String endpoint) {
|
private void waitForQueueToDrain() throws InterruptedException {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||||
|
while (ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size() > 0) {
|
||||||
|
Thread.sleep(250);
|
||||||
|
}
|
||||||
|
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Subscription createSubscription(String criteria, String payload, String endpoint) throws InterruptedException {
|
||||||
Subscription subscription = new Subscription();
|
Subscription subscription = new Subscription();
|
||||||
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
||||||
subscription.setStatus(SubscriptionStatusEnum.ACTIVE);
|
subscription.setStatus(SubscriptionStatusEnum.REQUESTED);
|
||||||
subscription.setCriteria(criteria);
|
subscription.setCriteria(criteria);
|
||||||
|
|
||||||
Channel channel = new Channel();
|
Channel channel = new Channel();
|
||||||
|
@ -88,10 +99,11 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
||||||
subscription.setId(methodOutcome.getId().getIdPart());
|
subscription.setId(methodOutcome.getId().getIdPart());
|
||||||
|
|
||||||
|
waitForQueueToDrain();
|
||||||
return subscription;
|
return subscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Observation sendObservation(String code, String system) {
|
private Observation sendObservation(String code, String system) throws InterruptedException {
|
||||||
Observation observation = new Observation();
|
Observation observation = new Observation();
|
||||||
CodeableConceptDt codeableConcept = new CodeableConceptDt();
|
CodeableConceptDt codeableConcept = new CodeableConceptDt();
|
||||||
observation.setCode(codeableConcept);
|
observation.setCode(codeableConcept);
|
||||||
|
@ -106,6 +118,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
String observationId = methodOutcome.getId().getIdPart();
|
String observationId = methodOutcome.getId().getIdPart();
|
||||||
observation.setId(observationId);
|
observation.setId(observationId);
|
||||||
|
|
||||||
|
waitForQueueToDrain();
|
||||||
return observation;
|
return observation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +136,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
Observation observation1 = sendObservation(code, "SNOMED-CT");
|
Observation observation1 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see 1 subscription notification
|
// Should see 1 subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(1, ourCreatedObservations.size());
|
assertEquals(1, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -137,7 +150,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see two subscription notifications
|
// Should see two subscription notifications
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(3, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -146,7 +159,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(4, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -159,7 +172,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
|
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
|
||||||
|
|
||||||
// Should see no subscription notification
|
// Should see no subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(4, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -173,7 +186,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
|
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(4, ourCreatedObservations.size());
|
||||||
assertEquals(1, ourUpdatedObservations.size());
|
assertEquals(1, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -196,7 +209,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
Observation observation1 = sendObservation(code, "SNOMED-CT");
|
Observation observation1 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see 1 subscription notification
|
// Should see 1 subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(1, ourCreatedObservations.size());
|
assertEquals(1, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -210,7 +223,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see two subscription notifications
|
// Should see two subscription notifications
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(3, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -219,7 +232,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(4, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -232,7 +245,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
|
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
|
||||||
|
|
||||||
// Should see no subscription notification
|
// Should see no subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(4, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -246,7 +259,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
||||||
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
|
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(4, ourCreatedObservations.size());
|
||||||
assertEquals(1, ourUpdatedObservations.size());
|
assertEquals(1, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
||||||
ourUpdatedObservations.clear();
|
ourUpdatedObservations.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Subscription createSubscription(String criteria, String payload, String endpoint) {
|
private Subscription createSubscription(String criteria, String payload, String endpoint) throws InterruptedException {
|
||||||
Subscription subscription = new Subscription();
|
Subscription subscription = new Subscription();
|
||||||
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
||||||
subscription.setStatus(Subscription.SubscriptionStatus.ACTIVE);
|
subscription.setStatus(Subscription.SubscriptionStatus.ACTIVE);
|
||||||
|
@ -79,10 +79,19 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
||||||
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
||||||
subscription.setId(methodOutcome.getId().getIdPart());
|
subscription.setId(methodOutcome.getId().getIdPart());
|
||||||
|
|
||||||
|
waitForQueueToDrain();
|
||||||
return subscription;
|
return subscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Observation sendObservation(String code, String system) {
|
private void waitForQueueToDrain() throws InterruptedException {
|
||||||
|
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||||
|
while (ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size() > 0) {
|
||||||
|
Thread.sleep(250);
|
||||||
|
}
|
||||||
|
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Observation sendObservation(String code, String system) throws InterruptedException {
|
||||||
Observation observation = new Observation();
|
Observation observation = new Observation();
|
||||||
CodeableConcept codeableConcept = new CodeableConcept();
|
CodeableConcept codeableConcept = new CodeableConcept();
|
||||||
observation.setCode(codeableConcept);
|
observation.setCode(codeableConcept);
|
||||||
|
@ -97,6 +106,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
||||||
String observationId = methodOutcome.getId().getIdPart();
|
String observationId = methodOutcome.getId().getIdPart();
|
||||||
observation.setId(observationId);
|
observation.setId(observationId);
|
||||||
|
|
||||||
|
waitForQueueToDrain();
|
||||||
return observation;
|
return observation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +197,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
||||||
Observation observation1 = sendObservation(code, "SNOMED-CT");
|
Observation observation1 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see 1 subscription notification
|
// Should see 1 subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(1, ourCreatedObservations.size());
|
assertEquals(1, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -201,7 +211,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
||||||
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see two subscription notifications
|
// Should see two subscription notifications
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(3, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -210,7 +220,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
||||||
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(4, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -223,7 +233,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
||||||
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
|
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
|
||||||
|
|
||||||
// Should see no subscription notification
|
// Should see no subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(4, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -237,7 +247,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
||||||
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
|
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(4, ourCreatedObservations.size());
|
||||||
assertEquals(1, ourUpdatedObservations.size());
|
assertEquals(1, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
|
|
@ -316,11 +316,11 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void waitForQueueToDrain() throws InterruptedException {
|
private void waitForQueueToDrain() throws InterruptedException {
|
||||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueue().size());
|
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||||
while (ourRestHookSubscriptionInterceptor.getExecutorQueue().size() > 0) {
|
while (ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size() > 0) {
|
||||||
Thread.sleep(250);
|
Thread.sleep(250);
|
||||||
}
|
}
|
||||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueue().size());
|
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
||||||
ourUpdatedObservations.clear();
|
ourUpdatedObservations.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Subscription createSubscription(String criteria, String payload, String endpoint) {
|
private Subscription createSubscription(String criteria, String payload, String endpoint) throws InterruptedException {
|
||||||
Subscription subscription = new Subscription();
|
Subscription subscription = new Subscription();
|
||||||
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
||||||
subscription.setStatus(Subscription.SubscriptionStatus.ACTIVE);
|
subscription.setStatus(Subscription.SubscriptionStatus.ACTIVE);
|
||||||
|
@ -79,10 +79,19 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
||||||
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
||||||
subscription.setId(methodOutcome.getId().getIdPart());
|
subscription.setId(methodOutcome.getId().getIdPart());
|
||||||
|
|
||||||
|
waitForQueueToDrain();
|
||||||
return subscription;
|
return subscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Observation sendObservation(String code, String system) {
|
private void waitForQueueToDrain() throws InterruptedException {
|
||||||
|
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||||
|
while (ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size() > 0) {
|
||||||
|
Thread.sleep(250);
|
||||||
|
}
|
||||||
|
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Observation sendObservation(String code, String system) throws InterruptedException {
|
||||||
Observation observation = new Observation();
|
Observation observation = new Observation();
|
||||||
CodeableConcept codeableConcept = new CodeableConcept();
|
CodeableConcept codeableConcept = new CodeableConcept();
|
||||||
observation.setCode(codeableConcept);
|
observation.setCode(codeableConcept);
|
||||||
|
@ -97,6 +106,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
||||||
String observationId = methodOutcome.getId().getIdPart();
|
String observationId = methodOutcome.getId().getIdPart();
|
||||||
observation.setId(observationId);
|
observation.setId(observationId);
|
||||||
|
|
||||||
|
waitForQueueToDrain();
|
||||||
|
|
||||||
return observation;
|
return observation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +128,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(1, ourCreatedObservations.size());
|
assertEquals(1, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId());
|
Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId());
|
||||||
Assert.assertNotNull(subscriptionTemp);
|
Assert.assertNotNull(subscriptionTemp);
|
||||||
|
|
||||||
|
@ -131,7 +142,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(3, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
ourClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute();
|
ourClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute();
|
||||||
|
|
||||||
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
||||||
|
@ -187,10 +198,10 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
||||||
Observation observation1 = sendObservation(code, "SNOMED-CT");
|
Observation observation1 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see 1 subscription notification
|
// Should see 1 subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(1, ourCreatedObservations.size());
|
assertEquals(1, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId());
|
Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId());
|
||||||
Assert.assertNotNull(subscriptionTemp);
|
Assert.assertNotNull(subscriptionTemp);
|
||||||
|
|
||||||
|
@ -201,16 +212,16 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
||||||
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see two subscription notifications
|
// Should see two subscription notifications
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(3, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
ourClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute();
|
ourClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute();
|
||||||
|
|
||||||
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(4, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -223,7 +234,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
||||||
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
|
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
|
||||||
|
|
||||||
// Should see no subscription notification
|
// Should see no subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(4, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
@ -237,7 +248,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
||||||
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
|
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
waitForQueueToDrain();
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(4, ourCreatedObservations.size());
|
||||||
assertEquals(1, ourUpdatedObservations.size());
|
assertEquals(1, ourUpdatedObservations.size());
|
||||||
|
|
||||||
|
|
|
@ -1326,7 +1326,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!newPlainProviders.isEmpty()) {
|
if (!newPlainProviders.isEmpty()) {
|
||||||
ourLog.info("Added {} plain provider(s). Total {}", newPlainProviders.size());
|
ourLog.info("Added {} plain provider(s). Total {}", newPlainProviders.size(), myPlainProviders.size());
|
||||||
for (Object provider : newPlainProviders) {
|
for (Object provider : newPlainProviders) {
|
||||||
assertProviderIsValid(provider);
|
assertProviderIsValid(provider);
|
||||||
findResourceMethods(provider);
|
findResourceMethods(provider);
|
||||||
|
|
|
@ -24,7 +24,10 @@ import org.hl7.fhir.r4.hapi.rest.server.GraphQLProvider;
|
||||||
import org.hl7.fhir.r4.model.*;
|
import org.hl7.fhir.r4.model.*;
|
||||||
import org.hl7.fhir.r4.utils.GraphQLEngine;
|
import org.hl7.fhir.r4.utils.GraphQLEngine;
|
||||||
import org.hl7.fhir.utilities.graphql.Argument;
|
import org.hl7.fhir.utilities.graphql.Argument;
|
||||||
import org.junit.*;
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -106,7 +109,6 @@ public class GraphQLR4ProviderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void testGraphSystemInstance() throws Exception {
|
public void testGraphSystemInstance() throws Exception {
|
||||||
String query = "{Patient(id:123){id,name{given,family}}}";
|
String query = "{Patient(id:123){id,name{given,family}}}";
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/$graphql?query=" + UrlUtil.escape(query));
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/$graphql?query=" + UrlUtil.escape(query));
|
||||||
|
@ -117,12 +119,14 @@ public class GraphQLR4ProviderTest {
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
assertEquals("{\n" +
|
assertEquals("{\n" +
|
||||||
" \"name\":[{\n" +
|
" \"Patient\":{\n" +
|
||||||
" \"family\":\"FAMILY\",\n" +
|
" \"name\":[{\n" +
|
||||||
" \"given\":[\"GIVEN1\",\"GIVEN2\"]\n" +
|
" \"given\":[\"GIVEN1\",\"GIVEN2\"],\n" +
|
||||||
" },{\n" +
|
" \"family\":\"FAMILY\"\n" +
|
||||||
" \"given\":[\"GivenOnly1\",\"GivenOnly2\"]\n" +
|
" },{\n" +
|
||||||
" }]\n" +
|
" \"given\":[\"GivenOnly1\",\"GivenOnly2\"]\n" +
|
||||||
|
" }]\n" +
|
||||||
|
" }\n" +
|
||||||
"}", responseContent);
|
"}", responseContent);
|
||||||
assertThat(status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue(), startsWith("application/json"));
|
assertThat(status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue(), startsWith("application/json"));
|
||||||
|
|
||||||
|
@ -133,7 +137,6 @@ public class GraphQLR4ProviderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void testGraphSystemList() throws Exception {
|
public void testGraphSystemList() throws Exception {
|
||||||
String query = "{PatientList(name:\"pet\"){name{family,given}}}";
|
String query = "{PatientList(name:\"pet\"){name{family,given}}}";
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/$graphql?query=" + UrlUtil.escape(query));
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/$graphql?query=" + UrlUtil.escape(query));
|
||||||
|
@ -144,11 +147,17 @@ public class GraphQLR4ProviderTest {
|
||||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
assertEquals("{\n" +
|
assertEquals("{\n" +
|
||||||
" \"name\":[{\n" +
|
" \"PatientList\":[{\n" +
|
||||||
" \"family\":\"FAMILY\",\n" +
|
" \"name\":[{\n" +
|
||||||
" \"given\":[\"GIVEN1\",\"GIVEN2\"]\n" +
|
" \"family\":\"pet\",\n" +
|
||||||
|
" \"given\":[\"GIVEN1\",\"GIVEN2\"]\n" +
|
||||||
|
" },{\n" +
|
||||||
|
" \"given\":[\"GivenOnly1\",\"GivenOnly2\"]\n" +
|
||||||
|
" }]\n" +
|
||||||
" },{\n" +
|
" },{\n" +
|
||||||
" \"given\":[\"GivenOnly1\",\"GivenOnly2\"]\n" +
|
" \"name\":[{\n" +
|
||||||
|
" \"given\":[\"GivenOnlyB1\",\"GivenOnlyB2\"]\n" +
|
||||||
|
" }]\n" +
|
||||||
" }]\n" +
|
" }]\n" +
|
||||||
"}", responseContent);
|
"}", responseContent);
|
||||||
assertThat(status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue(), startsWith("application/json"));
|
assertThat(status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue(), startsWith("application/json"));
|
||||||
|
@ -209,24 +218,22 @@ public class GraphQLR4ProviderTest {
|
||||||
|
|
||||||
private static class MyStorageServices implements GraphQLEngine.IGraphQLStorageServices {
|
private static class MyStorageServices implements GraphQLEngine.IGraphQLStorageServices {
|
||||||
@Override
|
@Override
|
||||||
public ReferenceResolution lookup(Object appInfo, Resource context, Reference reference) throws FHIRException {
|
public ReferenceResolution lookup(Object theAppInfo, Resource theContext, Reference theReference) throws FHIRException {
|
||||||
ourLog.info("lookup from {} to {}", context.getIdElement().getValue(), reference.getReference());
|
ourLog.info("lookup from {} to {}", theContext.getIdElement().getValue(), theReference.getReference());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resource lookup(Object appInfo, String type, String id) throws FHIRException {
|
public Resource lookup(Object theAppInfo, String theType, String theId) throws FHIRException {
|
||||||
ourLog.info("lookup {}/{}", type, id);
|
ourLog.info("lookup {}/{}", theType, theId);
|
||||||
|
|
||||||
if (type.equals("Patient") && id.equals("123")) {
|
if (theType.equals("Patient") && theId.equals("123")) {
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
p
|
p.addName()
|
||||||
.addName()
|
|
||||||
.setFamily("FAMILY")
|
.setFamily("FAMILY")
|
||||||
.addGiven("GIVEN1")
|
.addGiven("GIVEN1")
|
||||||
.addGiven("GIVEN2");
|
.addGiven("GIVEN2");
|
||||||
p
|
p.addName()
|
||||||
.addName()
|
|
||||||
.addGiven("GivenOnly1")
|
.addGiven("GivenOnly1")
|
||||||
.addGiven("GivenOnly2");
|
.addGiven("GivenOnly2");
|
||||||
return p;
|
return p;
|
||||||
|
@ -236,13 +243,35 @@ public class GraphQLR4ProviderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void listResources(Object appInfo, String type, List<Argument> searchParams, List<Resource> matches) throws FHIRException {
|
public void listResources(Object theAppInfo, String theType, List<Argument> theSearchParams, List<Resource> theMatches) throws FHIRException {
|
||||||
ourLog.info("listResources of {} - {}", type, searchParams);
|
ourLog.info("listResources of {} - {}", theType, theSearchParams);
|
||||||
|
|
||||||
|
if (theSearchParams.size() == 1) {
|
||||||
|
String name = theSearchParams.get(0).getName();
|
||||||
|
if ("name".equals(name)) {
|
||||||
|
Patient p = new Patient();
|
||||||
|
p.addName()
|
||||||
|
.setFamily(theSearchParams.get(0).getValues().get(0).toString())
|
||||||
|
.addGiven("GIVEN1")
|
||||||
|
.addGiven("GIVEN2");
|
||||||
|
p.addName()
|
||||||
|
.addGiven("GivenOnly1")
|
||||||
|
.addGiven("GivenOnly2");
|
||||||
|
theMatches.add(p);
|
||||||
|
|
||||||
|
p = new Patient();
|
||||||
|
p.addName()
|
||||||
|
.addGiven("GivenOnlyB1")
|
||||||
|
.addGiven("GivenOnlyB2");
|
||||||
|
theMatches.add(p);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Bundle search(Object appInfo, String type, List<Argument> searchParams) throws FHIRException {
|
public Bundle search(Object theAppInfo, String theType, List<Argument> theSearchParams) throws FHIRException {
|
||||||
ourLog.info("search on {} - {}", type, searchParams);
|
ourLog.info("search on {} - {}", theType, theSearchParams);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -384,7 +384,7 @@
|
||||||
<hibernate_version>5.2.10.Final</hibernate_version>
|
<hibernate_version>5.2.10.Final</hibernate_version>
|
||||||
<hibernate_validator_version>5.4.1.Final</hibernate_validator_version>
|
<hibernate_validator_version>5.4.1.Final</hibernate_validator_version>
|
||||||
<!-- Update lucene version when you update hibernate-search version -->
|
<!-- Update lucene version when you update hibernate-search version -->
|
||||||
<hibernate_search_version>5.7.0.Final</hibernate_search_version>
|
<hibernate_search_version>5.7.1.Final</hibernate_search_version>
|
||||||
<lucene_version>5.5.4</lucene_version>
|
<lucene_version>5.5.4</lucene_version>
|
||||||
<maven_assembly_plugin_version>2.5.3</maven_assembly_plugin_version>
|
<maven_assembly_plugin_version>2.5.3</maven_assembly_plugin_version>
|
||||||
<maven_license_plugin_version>1.8</maven_license_plugin_version>
|
<maven_license_plugin_version>1.8</maven_license_plugin_version>
|
||||||
|
@ -451,7 +451,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
<artifactId>okhttp</artifactId>
|
<artifactId>okhttp</artifactId>
|
||||||
<version>3.4.1</version>
|
<version>3.8.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-cli</groupId>
|
<groupId>commons-cli</groupId>
|
||||||
|
@ -877,7 +877,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-jpa</artifactId>
|
<artifactId>spring-data-jpa</artifactId>
|
||||||
<version>1.10.4.RELEASE</version>
|
<version>1.11.6.RELEASE</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
|
|
|
@ -19,8 +19,11 @@
|
||||||
<li>Apache HttpCore (FHIR Client): 4.4.5 -> 4.4.6</li>
|
<li>Apache HttpCore (FHIR Client): 4.4.5 -> 4.4.6</li>
|
||||||
<li>Phloc Commons (Schematron Validator): 4.4.6 -> 4.4.11</li>
|
<li>Phloc Commons (Schematron Validator): 4.4.6 -> 4.4.11</li>
|
||||||
<li>Hibernate (JPA): 5.2.9 -> 5.2.10</li>
|
<li>Hibernate (JPA): 5.2.9 -> 5.2.10</li>
|
||||||
<li>Spring (JPA): 4.3.7.RELEASE -> 4.3.10.RELEASE</li>
|
<li>Hibernate Search (JPA): 5.7.0 -> 5.7.1</li>
|
||||||
<li>Thymeleaf (Testpage Overlay): 3.0.2.RELEASE -> 3.0.7.RELEASE</li>
|
<li>Spring (JPA): 4.3.7 -> 4.3.10</li>
|
||||||
|
<li>Spring Data JPA (JPA): 1.10.4 -> 1.11.6</li>
|
||||||
|
<li>Thymeleaf (Testpage Overlay): 3.0.2 -> 3.0.7</li>
|
||||||
|
<li>OkHttp (Android): 3.4.1 -> 3.8.1</li>
|
||||||
</ul>
|
</ul>
|
||||||
]]>
|
]]>
|
||||||
</action>
|
</action>
|
||||||
|
|
Loading…
Reference in New Issue