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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/*
|
||||
|
@ -324,7 +325,7 @@ public class FhirContext {
|
|||
Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> existing = new HashMap<>();
|
||||
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.put(theVersion, nameToType);
|
||||
myVersionToNameToResourceType = newVersionToNameToResourceType;
|
||||
|
@ -913,16 +914,25 @@ public class FhirContext {
|
|||
Set<String> resourceNames= new HashSet<>();
|
||||
|
||||
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()) {
|
||||
resourceNames.add(next.getName());
|
||||
}
|
||||
|
||||
// Properties versionProperties = new Properties();
|
||||
// versionProperties.load(myVersion.getFhirVersionPropertiesFile());
|
||||
//
|
||||
return Collections.unmodifiableSet(resourceNames);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
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.IHapiTerminologySvc;
|
||||
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.handler.PerConnectionWebSocketHandler;
|
||||
|
||||
import ca.uhn.fhir.jpa.subscription.SubscriptionWebsocketHandlerDstu2;
|
||||
import ca.uhn.fhir.jpa.subscription.dstu2.SubscriptionWebsocketHandlerDstu2;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSocket()
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||
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;
|
||||
|
||||
@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.dstu3.SearchParamExtractorDstu3;
|
||||
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.term.HapiTerminologySvcDstu3;
|
||||
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.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
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.handler.PerConnectionWebSocketHandler;
|
||||
|
||||
import ca.uhn.fhir.jpa.interceptor.WebSocketSubscriptionDstu3Interceptor;
|
||||
import ca.uhn.fhir.jpa.subscription.SubscriptionWebsocketHandlerDstu3;
|
||||
import ca.uhn.fhir.jpa.subscription.dstu3.WebSocketSubscriptionDstu3Interceptor;
|
||||
import ca.uhn.fhir.jpa.subscription.dstu3.SubscriptionWebsocketHandlerDstu3;
|
||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||
|
||||
@Configuration
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDaoSubscription;
|
||||
import ca.uhn.fhir.jpa.subscription.SubscriptionWebsocketHandlerDstu3;
|
||||
import ca.uhn.fhir.jpa.subscription.dstu3.SubscriptionWebsocketHandlerDstu3;
|
||||
|
||||
@Configuration
|
||||
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.r4.SearchParamExtractorR4;
|
||||
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.term.*;
|
||||
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.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.rest.server.interceptor.IServerInterceptor;
|
||||
|
||||
|
|
|
@ -20,26 +20,15 @@ package ca.uhn.fhir.jpa.dao;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
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.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
import ca.uhn.fhir.context.RuntimeSearchParam;
|
||||
import ca.uhn.fhir.jpa.dao.data.IResourceHistoryTableDao;
|
||||
import ca.uhn.fhir.jpa.dao.data.IResourceLinkDao;
|
||||
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
|
||||
import ca.uhn.fhir.jpa.dao.data.ISearchResultDao;
|
||||
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.util.DeleteConflict;
|
||||
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.model.api.*;
|
||||
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.RequestDetails;
|
||||
import ca.uhn.fhir.rest.param.ParameterUtil;
|
||||
|
@ -56,32 +48,46 @@ import ca.uhn.fhir.rest.server.exceptions.*;
|
|||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
|
||||
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.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)
|
||||
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);
|
||||
|
||||
@Autowired
|
||||
private DaoConfig myDaoConfig;
|
||||
@Autowired
|
||||
protected PlatformTransactionManager myPlatformTransactionManager;
|
||||
@Autowired
|
||||
protected IResourceTableDao myResourceTableDao;
|
||||
@Autowired(required = false)
|
||||
protected IFulltextSearchSvc mySearchDao;
|
||||
@Autowired()
|
||||
protected ISearchResultDao mySearchResultDao;
|
||||
@Autowired
|
||||
private DaoConfig myDaoConfig;
|
||||
@Autowired
|
||||
private IResourceHistoryTableDao myResourceHistoryTableDao;
|
||||
@Autowired
|
||||
private IResourceLinkDao myResourceLinkDao;
|
||||
private String myResourceName;
|
||||
@Autowired
|
||||
protected IResourceTableDao myResourceTableDao;
|
||||
private Class<T> myResourceType;
|
||||
@Autowired(required = false)
|
||||
protected IFulltextSearchSvc mySearchDao;
|
||||
@Autowired()
|
||||
protected ISearchResultDao mySearchResultDao;
|
||||
|
||||
private String mySecondaryPrimaryKeyParamName;
|
||||
|
||||
|
||||
|
@ -94,7 +100,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
}
|
||||
|
||||
//@formatter:off
|
||||
for (BaseTag next : new ArrayList<BaseTag>(entity.getTags())) {
|
||||
for (BaseTag next : new ArrayList<>(entity.getTags())) {
|
||||
if (ObjectUtil.equals(next.getTag().getTagType(), theTagType) &&
|
||||
ObjectUtil.equals(next.getTag().getSystem(), theScheme) &&
|
||||
ObjectUtil.equals(next.getTag().getCode(), theTerm)) {
|
||||
|
@ -199,11 +205,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
if (theRequestDetails != null) {
|
||||
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getContext(), theId.getResourceType(), theId);
|
||||
theRequestDetails.getRequestOperationCallback().resourceDeleted(resourceToDelete);
|
||||
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
||||
if (next instanceof IJpaServerInterceptor) {
|
||||
((IJpaServerInterceptor) next).resourceDeleted(requestDetails, entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
||||
if (next instanceof IServerOperationInterceptor) {
|
||||
|
@ -274,11 +275,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
if (theRequestDetails != null) {
|
||||
theRequestDetails.getRequestOperationCallback().resourceDeleted(resourceToDelete);
|
||||
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()) {
|
||||
if (next instanceof IServerOperationInterceptor) {
|
||||
|
@ -390,11 +386,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
if (theRequestDetails != null) {
|
||||
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequestDetails, getContext(), theResource);
|
||||
theRequestDetails.getRequestOperationCallback().resourceCreated(theResource);
|
||||
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
||||
if (next instanceof IJpaServerInterceptor) {
|
||||
((IJpaServerInterceptor) next).resourceCreated(requestDetails, entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (IServerInterceptor next : getConfig().getInterceptors()) {
|
||||
if (next instanceof IServerOperationInterceptor) {
|
||||
|
@ -420,7 +411,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
for (TagDefinition nextDef : tags) {
|
||||
|
||||
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()) &&
|
||||
ObjectUtil.equals(next.getTag().getSystem(), nextDef.getSystem()) &&
|
||||
ObjectUtil.equals(next.getTag().getCode(), nextDef.getCode())) {
|
||||
|
@ -482,8 +473,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
return tags;
|
||||
}
|
||||
|
||||
protected abstract List<Object> getIncludeValues(FhirTerser theTerser, Include theInclude, IBaseResource theResource, RuntimeResourceDefinition theResourceDef);
|
||||
|
||||
public String getResourceName() {
|
||||
return myResourceName;
|
||||
}
|
||||
|
@ -493,6 +482,12 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
return myResourceType;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Required
|
||||
public void setResourceType(Class<? extends IBaseResource> theTableType) {
|
||||
myResourceType = (Class<T>) theTableType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagList getTags(IIdType theResourceId, RequestDetails theRequestDetails) {
|
||||
// Notify interceptors
|
||||
|
@ -535,14 +530,13 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
}
|
||||
|
||||
private void incrementId(T theResource, ResourceTable theSavedEntity, IIdType theResourceId) {
|
||||
IIdType idType = theResourceId;
|
||||
String newVersion;
|
||||
long newVersionLong;
|
||||
if (idType == null || idType.getVersionIdPart() == null) {
|
||||
if (theResourceId == null || theResourceId.getVersionIdPart() == null) {
|
||||
newVersion = "1";
|
||||
newVersionLong = 1;
|
||||
} else {
|
||||
newVersionLong = idType.getVersionIdPartAsLong() + 1;
|
||||
newVersionLong = theResourceId.getVersionIdPartAsLong() + 1;
|
||||
newVersion = Long.toString(newVersionLong);
|
||||
}
|
||||
|
||||
|
@ -593,7 +587,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <MT extends IBaseMetaType> MT metaDeleteOperation(IIdType theResourceId, MT theMetaDel, RequestDetails theRequestDetails) {
|
||||
// Notify interceptors
|
||||
|
@ -719,8 +712,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
/**
|
||||
* May be overridden by subclasses to validate resources prior to storage
|
||||
*
|
||||
* @param theResource
|
||||
* The resource that is about to be stored
|
||||
* @param theResource The resource that is about to be stored
|
||||
*/
|
||||
protected void preProcessResourceForStorage(T theResource) {
|
||||
String type = getContext().getResourceDefinition(theResource).getName();
|
||||
|
@ -948,12 +940,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
return retVal;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Required
|
||||
public void setResourceType(Class<? extends IBaseResource> theTableType) {
|
||||
myResourceType = (Class<T>) theTableType;
|
||||
}
|
||||
|
||||
/**
|
||||
* If set, the given param will be treated as a secondary primary key, and multiple resources will not be able to share the same value.
|
||||
*/
|
||||
|
@ -1152,11 +1138,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
if (theRequestDetails != null) {
|
||||
theRequestDetails.getRequestOperationCallback().resourceUpdated(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()) {
|
||||
if (next instanceof IServerOperationInterceptor) {
|
||||
|
@ -1191,6 +1172,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
|
||||
/**
|
||||
* Get the resource definition from the criteria which specifies the resource type
|
||||
*
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
|
|
|
@ -56,24 +56,6 @@ public class FhirResourceDaoDstu2<T extends IResource> extends BaseHapiFhirResou
|
|||
@Qualifier("myInstanceValidatorDstu2")
|
||||
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
|
||||
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> {
|
||||
|
||||
@Query("SELECT t FROM SubscriptionTable t WHERE t.myResId = :pid")
|
||||
public SubscriptionTable findOneByResourcePid(@Param("pid") Long theId);
|
||||
SubscriptionTable findOneByResourcePid(@Param("pid") Long theId);
|
||||
|
||||
@Modifying
|
||||
@Query("DELETE FROM SubscriptionTable t WHERE t.myId = :id ")
|
||||
public void deleteAllForSubscription(@Param("id") Long theSubscriptionId);
|
||||
void deleteAllForSubscription(@Param("id") Long theSubscriptionId);
|
||||
|
||||
@Modifying
|
||||
@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)")
|
||||
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")
|
||||
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;
|
||||
}
|
||||
|
||||
@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
|
||||
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;
|
||||
}
|
||||
|
||||
@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
|
||||
public MethodOutcome validate(T theResource, IIdType theId, String theRawResource, EncodingEnum theEncoding, ValidationModeEnum theMode, String theProfile, RequestDetails theRequestDetails) {
|
||||
|
|
|
@ -20,16 +20,7 @@ package ca.uhn.fhir.jpa.entity;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import javax.persistence.Column;
|
||||
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;
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "HFJ_SUBSCRIPTION_FLAG_RES")
|
||||
|
@ -45,13 +36,11 @@ public class SubscriptionFlaggedResource {
|
|||
@JoinColumn(name = "RES_ID", nullable = false, foreignKey = @ForeignKey(name = "FK_SUBSFLAGRES_RES"))
|
||||
private ResourceTable myResource;
|
||||
|
||||
//@formatter:off
|
||||
@ManyToOne()
|
||||
@JoinColumn(name = "SUBSCRIPTION_ID",
|
||||
foreignKey = @ForeignKey(name = "FK_SUBSFLAG_SUBS")
|
||||
)
|
||||
private SubscriptionTable mySubscription;
|
||||
//@formatter:om
|
||||
|
||||
@Column(name = "RES_VERSION", nullable = false)
|
||||
private Long myVersion;
|
||||
|
@ -60,22 +49,22 @@ public class SubscriptionFlaggedResource {
|
|||
return myResource;
|
||||
}
|
||||
|
||||
public SubscriptionTable getSubscription() {
|
||||
return mySubscription;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return myVersion;
|
||||
}
|
||||
|
||||
public void setResource(ResourceTable theResource) {
|
||||
myResource = theResource;
|
||||
}
|
||||
|
||||
public SubscriptionTable getSubscription() {
|
||||
return mySubscription;
|
||||
}
|
||||
|
||||
public void setSubscription(SubscriptionTable theSubscription) {
|
||||
mySubscription = theSubscription;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return myVersion;
|
||||
}
|
||||
|
||||
public void setVersion(Long theVersion) {
|
||||
myVersion = theVersion;
|
||||
}
|
||||
|
|
|
@ -87,13 +87,18 @@ public class SubscriptionTable {
|
|||
@Column(name = "SUBSCRIPTION_STATUS", nullable = false, length = 20)
|
||||
private String myStatus;
|
||||
|
||||
//@formatter:off
|
||||
@OneToOne()
|
||||
@JoinColumn(name = "RES_ID", insertable = true, updatable = false, referencedColumnName = "RES_ID",
|
||||
foreignKey = @ForeignKey(name = "FK_SUBSCRIPTION_RESOURCE_ID")
|
||||
)
|
||||
private ResourceTable mySubscriptionResource;
|
||||
//@formatter:on
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public SubscriptionTable(){
|
||||
super();
|
||||
}
|
||||
|
||||
public long getCheckInterval() {
|
||||
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.GenericMessage;
|
||||
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.PreDestroy;
|
||||
|
@ -40,9 +42,12 @@ public abstract class BaseSubscriptionInterceptor extends ServerOperationInterce
|
|||
private MessageHandler mySubscriptionCheckingSubscriber;
|
||||
private ConcurrentHashMap<String, IBaseResource> myIdToSubscription = new ConcurrentHashMap<>();
|
||||
private Logger ourLog = LoggerFactory.getLogger(BaseSubscriptionInterceptor.class);
|
||||
private SubscriptionDeliveringRestHookSubscriber mySubscriptionDeliverySubscriber;
|
||||
private BlockingQueue<Runnable> myExecutorQueue;
|
||||
|
||||
public ConcurrentHashMap<String, IBaseResource> getIdToSubscription() {
|
||||
return myIdToSubscription;
|
||||
}
|
||||
|
||||
public abstract Subscription.SubscriptionChannelType getChannelType();
|
||||
|
||||
public SubscribableChannel getProcessingChannel() {
|
||||
|
@ -90,7 +95,7 @@ public abstract class BaseSubscriptionInterceptor extends ServerOperationInterce
|
|||
}
|
||||
}
|
||||
|
||||
public BlockingQueue<Runnable> getExecutorQueue() {
|
||||
public BlockingQueue<Runnable> getExecutorQueueForUnitTests() {
|
||||
return myExecutorQueue;
|
||||
}
|
||||
|
||||
|
@ -122,31 +127,33 @@ public abstract class BaseSubscriptionInterceptor extends ServerOperationInterce
|
|||
if (mySubscriptionActivatingSubscriber == null) {
|
||||
mySubscriptionActivatingSubscriber = new SubscriptionActivatingSubscriber(getSubscriptionDao(), myIdToSubscription, getChannelType(), myProcessingChannel);
|
||||
}
|
||||
myProcessingChannel.subscribe(mySubscriptionActivatingSubscriber);
|
||||
getProcessingChannel().subscribe(mySubscriptionActivatingSubscriber);
|
||||
}
|
||||
|
||||
if (mySubscriptionCheckingSubscriber == null) {
|
||||
mySubscriptionCheckingSubscriber = new SubscriptionCheckingSubscriber(getSubscriptionDao(), myIdToSubscription, getChannelType(), myProcessingChannel);
|
||||
}
|
||||
myProcessingChannel.subscribe(mySubscriptionCheckingSubscriber);
|
||||
getProcessingChannel().subscribe(mySubscriptionCheckingSubscriber);
|
||||
|
||||
if (mySubscriptionDeliverySubscriber == null) {
|
||||
mySubscriptionDeliverySubscriber = new SubscriptionDeliveringRestHookSubscriber(getSubscriptionDao(), myIdToSubscription, getChannelType(), myProcessingChannel);
|
||||
}
|
||||
myProcessingChannel.subscribe(mySubscriptionDeliverySubscriber);
|
||||
registerDeliverySubscriber();
|
||||
|
||||
}
|
||||
|
||||
protected abstract void registerDeliverySubscriber();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@PreDestroy
|
||||
public void preDestroy() {
|
||||
if (myAutoActivateSubscriptions) {
|
||||
myProcessingChannel.unsubscribe(mySubscriptionActivatingSubscriber);
|
||||
getProcessingChannel().unsubscribe(mySubscriptionActivatingSubscriber);
|
||||
}
|
||||
myProcessingChannel.unsubscribe(mySubscriptionCheckingSubscriber);
|
||||
myProcessingChannel.unsubscribe(mySubscriptionDeliverySubscriber);
|
||||
getProcessingChannel().unsubscribe(mySubscriptionCheckingSubscriber);
|
||||
|
||||
unregisterDeliverySubscriber();
|
||||
}
|
||||
|
||||
protected abstract void unregisterDeliverySubscriber();
|
||||
|
||||
@Override
|
||||
public void resourceCreated(RequestDetails theRequest, IBaseResource theResource) {
|
||||
ResourceModifiedMessage msg = new ResourceModifiedMessage();
|
||||
|
@ -173,7 +180,15 @@ public abstract class BaseSubscriptionInterceptor extends ServerOperationInterce
|
|||
submitResourceModified(msg);
|
||||
}
|
||||
|
||||
private void submitResourceModified(ResourceModifiedMessage theMsg) {
|
||||
myProcessingChannel.send(new GenericMessage<>(theMsg));
|
||||
private void submitResourceModified(final ResourceModifiedMessage 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.LoggerFactory;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
|
||||
|
@ -41,12 +40,16 @@ public class SubscriptionActivatingSubscriber extends BaseSubscriptionSubscriber
|
|||
IPrimitiveType<?> status = ctx.newTerser().getSingleValueOrNull(subscription, SUBSCRIPTION_STATUS, IPrimitiveType.class);
|
||||
String statusString = status.getValueAsString();
|
||||
|
||||
String oldStatus = Subscription.SubscriptionStatus.REQUESTED.toCode();
|
||||
if (oldStatus.equals(statusString)) {
|
||||
String newStatus = Subscription.SubscriptionStatus.ACTIVE.toCode();
|
||||
status.setValueAsString(newStatus);
|
||||
ourLog.info("Activating subscription {} from status {} to {}", subscription.getIdElement().toUnqualifiedVersionless().getValue(), oldStatus, newStatus);
|
||||
String requestedStatus = Subscription.SubscriptionStatus.REQUESTED.toCode();
|
||||
String activeStatus = Subscription.SubscriptionStatus.ACTIVE.toCode();
|
||||
if (requestedStatus.equals(statusString)) {
|
||||
status.setValueAsString(activeStatus);
|
||||
ourLog.info("Activating subscription {} from status {} to {}", subscription.getIdElement().toUnqualified().getValue(), requestedStatus, activeStatus);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,12 +77,6 @@ public class SubscriptionCheckingSubscriber extends BaseSubscriptionSubscriber {
|
|||
criteria += "&_id=" + resourceType + "/" + resourceId;
|
||||
criteria = massageCriteria(criteria);
|
||||
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException theE) {
|
||||
theE.printStackTrace();
|
||||
}
|
||||
|
||||
IBundleProvider results = performSearch(criteria);
|
||||
if (results.size() == 0) {
|
||||
continue;
|
||||
|
@ -90,11 +84,10 @@ public class SubscriptionCheckingSubscriber extends BaseSubscriptionSubscriber {
|
|||
|
||||
// should just be one resource as it was filtered by the id
|
||||
for (IBaseResource nextBase : results.getResources(0, results.size())) {
|
||||
IBaseResource next = (IBaseResource) nextBase;
|
||||
ourLog.info("Found match: queueing rest-hook notification for resource: {}", next.getIdElement());
|
||||
ourLog.info("Found match: queueing rest-hook notification for resource: {}", nextBase.getIdElement());
|
||||
|
||||
ResourceDeliveryMessage deliveryMsg = new ResourceDeliveryMessage();
|
||||
deliveryMsg.setPayoad(next);
|
||||
deliveryMsg.setPayoad(nextBase);
|
||||
deliveryMsg.setSubscription(nextSubscription);
|
||||
deliveryMsg.setOperationType(msg.getOperationType());
|
||||
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
|
||||
|
@ -21,12 +21,12 @@ package ca.uhn.fhir.jpa.interceptor;
|
|||
*/
|
||||
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
public class RestHookSubscriptionDstu2Interceptor extends BaseSubscriptionInterceptor {
|
||||
public class RestHookSubscriptionDstu2Interceptor extends BaseSubscriptionRestHookInterceptor {
|
||||
@Autowired
|
||||
@Qualifier("mySubscriptionDaoDstu2")
|
||||
private IFhirResourceDao<Subscription> mySubscriptionDao;
|
|
@ -1,4 +1,4 @@
|
|||
package ca.uhn.fhir.jpa.subscription;
|
||||
package ca.uhn.fhir.jpa.subscription.dstu2;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
|
@ -27,6 +27,7 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import ca.uhn.fhir.jpa.subscription.ISubscriptionWebsocketHandler;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.utils.URLEncodedUtils;
|
||||
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.util.List;
|
||||
|
@ -8,6 +8,7 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import ca.uhn.fhir.jpa.subscription.ISubscriptionWebsocketHandler;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.utils.URLEncodedUtils;
|
||||
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.interceptor;
|
||||
package ca.uhn.fhir.jpa.subscription.dstu3;
|
||||
|
||||
/*-
|
||||
* #%L
|
||||
|
@ -22,22 +21,21 @@ package ca.uhn.fhir.jpa.interceptor;
|
|||
*/
|
||||
|
||||
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.springframework.beans.factory.annotation.Autowired;
|
||||
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
|
||||
protected IFhirResourceDao<?> getSubscriptionDao() {
|
||||
return mySubscriptionDao;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mySubscriptionDaoDstu3")
|
||||
private IFhirResourceDao<Subscription> mySubscriptionDao;
|
||||
|
||||
public void setSubscriptionDao(IFhirResourceDao<Subscription> theSubscriptionDao) {
|
||||
mySubscriptionDao = theSubscriptionDao;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package ca.uhn.fhir.jpa.subscription;
|
||||
package ca.uhn.fhir.jpa.subscription.dstu3;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
|
@ -27,6 +27,7 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import ca.uhn.fhir.jpa.subscription.ISubscriptionWebsocketHandler;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.utils.URLEncodedUtils;
|
||||
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.util.List;
|
||||
|
@ -8,6 +8,7 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import ca.uhn.fhir.jpa.subscription.ISubscriptionWebsocketHandler;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.utils.URLEncodedUtils;
|
||||
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
|
||||
|
@ -21,11 +21,11 @@ package ca.uhn.fhir.jpa.interceptor.r4;
|
|||
*/
|
||||
|
||||
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.Qualifier;
|
||||
|
||||
public class RestHookSubscriptionR4Interceptor extends BaseSubscriptionInterceptor {
|
||||
public class RestHookSubscriptionR4Interceptor extends BaseSubscriptionRestHookInterceptor {
|
||||
@Autowired
|
||||
@Qualifier("mySubscriptionDaoR4")
|
||||
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;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
|
||||
import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb;
|
||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||
import ca.uhn.fhir.jpa.dao.DeleteMethodOutcome;
|
||||
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.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.junit.After;
|
||||
|
@ -24,26 +21,15 @@ import org.mockito.ArgumentCaptor;
|
|||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||
import ca.uhn.fhir.jpa.dao.DaoMethodOutcome;
|
||||
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.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;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2InterceptorTest.class);
|
||||
private IJpaServerInterceptor myJpaInterceptor;
|
||||
private JpaServerInterceptorAdapter myJpaInterceptorAdapter = new JpaServerInterceptorAdapter();
|
||||
private IServerOperationInterceptor myJpaInterceptor;
|
||||
private ServerOperationInterceptorAdapter myJpaInterceptorAdapter = new ServerOperationInterceptorAdapter();
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
|
@ -54,7 +40,7 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
|||
|
||||
@Before
|
||||
public void before() {
|
||||
myJpaInterceptor = mock(IJpaServerInterceptor.class);
|
||||
myJpaInterceptor = mock(IServerOperationInterceptor.class);
|
||||
myDaoConfig.getInterceptors().add(myJpaInterceptor);
|
||||
myDaoConfig.getInterceptors().add(myJpaInterceptorAdapter);
|
||||
}
|
||||
|
@ -66,17 +52,17 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
|||
p.addName().addFamily("PATIENT");
|
||||
Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong();
|
||||
|
||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
||||
ArgumentCaptor<ResourceTable> tableCapt;
|
||||
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||
ArgumentCaptor<IBaseResource> tableCapt;
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||
assertNotNull(tableCapt.getValue().getId());
|
||||
assertEquals(id, tableCapt.getValue().getId());
|
||||
assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
|
||||
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
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();
|
||||
assertEquals(id, id2);
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceCreated(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);
|
||||
|
||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
||||
ArgumentCaptor<ResourceTable> tableCapt;
|
||||
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||
ArgumentCaptor<IBaseResource> tableCapt;
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceDeleted(detailsCapt.capture(), tableCapt.capture());
|
||||
assertNotNull(tableCapt.getValue().getId());
|
||||
assertEquals(id, tableCapt.getValue().getId());
|
||||
assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
|
||||
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||
|
||||
}
|
||||
|
||||
|
@ -132,14 +118,14 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
|||
Long id2 = myPatientDao.update(p, mySrd).getId().getIdPartAsLong();
|
||||
assertEquals(id, id2);
|
||||
|
||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
||||
ArgumentCaptor<ResourceTable> tableCapt;
|
||||
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||
ArgumentCaptor<IBaseResource> tableCapt;
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||
assertNotNull(tableCapt.getValue().getId());
|
||||
assertEquals(id, tableCapt.getValue().getId());
|
||||
assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
|
||||
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||
|
||||
/*
|
||||
* Now do a conditional update
|
||||
|
@ -151,11 +137,11 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
|||
id2 = myPatientDao.update(p, "Patient?family=PATIENT1", mySrd).getId().getIdPartAsLong();
|
||||
assertEquals(id, id2);
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceCreated(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)
|
||||
|
@ -166,11 +152,11 @@ public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test {
|
|||
id2 = myPatientDao.update(p, "Patient?family=ZZZ", mySrd).getId().getIdPartAsLong();
|
||||
assertNotEquals(id, id2);
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(2)).resourceUpdated(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")
|
||||
.setMethod(HTTPVerbEnum.DELETE);
|
||||
Bundle resp = mySystemDao.transaction(mySrd, xactBundle);
|
||||
assertNotNull(resp);
|
||||
|
||||
verify(myRequestOperationCallback, times(2)).resourceDeleted(any(IBaseResource.class));
|
||||
verify(myRequestOperationCallback, times(2)).resourceCreated(any(IBaseResource.class));
|
||||
|
|
|
@ -1,35 +1,36 @@
|
|||
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.junit.Assert.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
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 {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3InterceptorTest.class);
|
||||
private IJpaServerInterceptor myJpaInterceptor;
|
||||
private JpaServerInterceptorAdapter myJpaInterceptorAdapter = new JpaServerInterceptorAdapter();
|
||||
private IServerOperationInterceptor myJpaInterceptor;
|
||||
private ServerOperationInterceptorAdapter myJpaInterceptorAdapter = new ServerOperationInterceptorAdapter();
|
||||
private IServerOperationInterceptor myServerOperationInterceptor;
|
||||
|
||||
@After
|
||||
|
@ -41,7 +42,7 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
|||
|
||||
@Before
|
||||
public void before() {
|
||||
myJpaInterceptor = mock(IJpaServerInterceptor.class);
|
||||
myJpaInterceptor = mock(IServerOperationInterceptor.class);
|
||||
|
||||
myServerOperationInterceptor = mock(IServerOperationInterceptor.class, new Answer<Object>() {
|
||||
@Override
|
||||
|
@ -64,17 +65,17 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
|||
p.addName().setFamily("PATIENT");
|
||||
Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong();
|
||||
|
||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
||||
ArgumentCaptor<ResourceTable> tableCapt;
|
||||
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||
ArgumentCaptor<IBaseResource> tableCapt;
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||
assertNotNull(tableCapt.getValue().getId());
|
||||
assertEquals(id, tableCapt.getValue().getId());
|
||||
assertNotNull(tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
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();
|
||||
assertEquals(id, id2);
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceCreated(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);
|
||||
|
||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
||||
ArgumentCaptor<ResourceTable> tableCapt;
|
||||
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||
ArgumentCaptor<IBaseResource> tableCapt;
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceDeleted(detailsCapt.capture(), tableCapt.capture());
|
||||
assertNotNull(tableCapt.getValue().getId());
|
||||
assertEquals(id, tableCapt.getValue().getId());
|
||||
assertNotNull(tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||
|
||||
}
|
||||
|
||||
|
@ -130,14 +131,14 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
|||
Long id2 = myPatientDao.update(p, mySrd).getId().getIdPartAsLong();
|
||||
assertEquals(id, id2);
|
||||
|
||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
||||
ArgumentCaptor<ResourceTable> tableCapt;
|
||||
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||
ArgumentCaptor<IBaseResource> tableCapt;
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||
assertNotNull(tableCapt.getValue().getId());
|
||||
assertEquals(id, tableCapt.getValue().getId());
|
||||
assertNotNull(tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||
|
||||
/*
|
||||
* Now do a conditional update
|
||||
|
@ -149,11 +150,11 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
|||
id2 = myPatientDao.update(p, "Patient?family=PATIENT1", mySrd).getId().getIdPartAsLong();
|
||||
assertEquals(id, id2);
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceCreated(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)
|
||||
|
@ -164,11 +165,11 @@ public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test {
|
|||
id2 = myPatientDao.update(p, "Patient?family=ZZZ", mySrd).getId().getIdPartAsLong();
|
||||
assertNotEquals(id, id2);
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(2)).resourceUpdated(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;
|
||||
|
||||
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.junit.Assert.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
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 {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4InterceptorTest.class);
|
||||
private IJpaServerInterceptor myJpaInterceptor;
|
||||
private JpaServerInterceptorAdapter myJpaInterceptorAdapter = new JpaServerInterceptorAdapter();
|
||||
private IServerOperationInterceptor myJpaInterceptor;
|
||||
private ServerOperationInterceptorAdapter myJpaInterceptorAdapter = new ServerOperationInterceptorAdapter();
|
||||
private IServerOperationInterceptor myServerOperationInterceptor;
|
||||
|
||||
@After
|
||||
|
@ -41,7 +42,7 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
|||
|
||||
@Before
|
||||
public void before() {
|
||||
myJpaInterceptor = mock(IJpaServerInterceptor.class);
|
||||
myJpaInterceptor = mock(IServerOperationInterceptor.class);
|
||||
|
||||
myServerOperationInterceptor = mock(IServerOperationInterceptor.class, new Answer<Object>() {
|
||||
@Override
|
||||
|
@ -64,17 +65,17 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
|||
p.addName().setFamily("PATIENT");
|
||||
Long id = myPatientDao.create(p, mySrd).getId().getIdPartAsLong();
|
||||
|
||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
||||
ArgumentCaptor<ResourceTable> tableCapt;
|
||||
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||
ArgumentCaptor<IBaseResource> tableCapt;
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceCreated(detailsCapt.capture(), tableCapt.capture());
|
||||
assertNotNull(tableCapt.getValue().getId());
|
||||
assertEquals(id, tableCapt.getValue().getId());
|
||||
assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
|
||||
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
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();
|
||||
assertEquals(id, id2);
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceCreated(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);
|
||||
|
||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
||||
ArgumentCaptor<ResourceTable> tableCapt;
|
||||
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||
ArgumentCaptor<IBaseResource> tableCapt;
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceDeleted(detailsCapt.capture(), tableCapt.capture());
|
||||
assertNotNull(tableCapt.getValue().getId());
|
||||
assertEquals(id, tableCapt.getValue().getId());
|
||||
assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
|
||||
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||
|
||||
}
|
||||
|
||||
|
@ -130,14 +131,14 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
|||
Long id2 = myPatientDao.update(p, mySrd).getId().getIdPartAsLong();
|
||||
assertEquals(id, id2);
|
||||
|
||||
ArgumentCaptor<ActionRequestDetails> detailsCapt;
|
||||
ArgumentCaptor<ResourceTable> tableCapt;
|
||||
ArgumentCaptor<RequestDetails> detailsCapt;
|
||||
ArgumentCaptor<IBaseResource> tableCapt;
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceUpdated(detailsCapt.capture(), tableCapt.capture());
|
||||
assertNotNull(tableCapt.getValue().getId());
|
||||
assertEquals(id, tableCapt.getValue().getId());
|
||||
assertNotNull(tableCapt.getValue().getIdElement().getIdPart());
|
||||
assertEquals(id, tableCapt.getValue().getIdElement().getIdPartAsLong());
|
||||
|
||||
/*
|
||||
* Now do a conditional update
|
||||
|
@ -149,11 +150,11 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
|||
id2 = myPatientDao.update(p, "Patient?family=PATIENT1", mySrd).getId().getIdPartAsLong();
|
||||
assertEquals(id, id2);
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(1)).resourceCreated(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)
|
||||
|
@ -164,11 +165,11 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test {
|
|||
id2 = myPatientDao.update(p, "Patient?family=ZZZ", mySrd).getId().getIdPartAsLong();
|
||||
assertNotEquals(id, id2);
|
||||
|
||||
detailsCapt = ArgumentCaptor.forClass(ActionRequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(ResourceTable.class);
|
||||
detailsCapt = ArgumentCaptor.forClass(RequestDetails.class);
|
||||
tableCapt = ArgumentCaptor.forClass(IBaseResource.class);
|
||||
verify(myJpaInterceptor, times(2)).resourceUpdated(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.WebsocketDstu2DispatcherConfig;
|
||||
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.testutil.RandomServerPortProvider;
|
||||
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.dstu3.BaseJpaDstu3Test;
|
||||
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.ISearchCoordinatorSvc;
|
||||
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.r4.BaseJpaR4Test;
|
||||
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.ISearchCoordinatorSvc;
|
||||
import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainR4;
|
||||
|
|
|
@ -50,6 +50,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
|
||||
@After
|
||||
public void afterUnregisterRestHookListener() {
|
||||
ourLog.info("** AFTER **");
|
||||
for (IIdType next : mySubscriptionIds) {
|
||||
ourClient.delete().resourceById(next).execute();
|
||||
}
|
||||
|
@ -279,11 +280,11 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
|||
}
|
||||
|
||||
private void waitForQueueToDrain() throws InterruptedException {
|
||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueue().size());
|
||||
while (ourRestHookSubscriptionInterceptor.getExecutorQueue().size() > 0) {
|
||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||
while (ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size() > 0) {
|
||||
Thread.sleep(250);
|
||||
}
|
||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueue().size());
|
||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||
}
|
||||
|
||||
@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.IIdType;
|
||||
import org.junit.*;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
|
@ -153,11 +151,11 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
|||
}
|
||||
|
||||
private void waitForQueueToDrain() throws InterruptedException {
|
||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueue().size());
|
||||
while (ourRestHookSubscriptionInterceptor.getExecutorQueue().size() > 0) {
|
||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||
while (ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size() > 0) {
|
||||
Thread.sleep(250);
|
||||
}
|
||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueue().size());
|
||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -53,6 +53,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
|
||||
@After
|
||||
public void afterUnregisterRestHookListener() {
|
||||
ourLog.info("** AFTER **");
|
||||
myDaoConfig.setAllowMultipleDelete(true);
|
||||
ourLog.info("Deleting all subscriptions");
|
||||
ourClient.delete().resourceConditionalByUrl("Subscription?status=active").execute();
|
||||
|
@ -73,10 +74,20 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
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.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
||||
subscription.setStatus(SubscriptionStatusEnum.ACTIVE);
|
||||
subscription.setStatus(SubscriptionStatusEnum.REQUESTED);
|
||||
subscription.setCriteria(criteria);
|
||||
|
||||
Channel channel = new Channel();
|
||||
|
@ -88,10 +99,11 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
||||
subscription.setId(methodOutcome.getId().getIdPart());
|
||||
|
||||
waitForQueueToDrain();
|
||||
return subscription;
|
||||
}
|
||||
|
||||
private Observation sendObservation(String code, String system) {
|
||||
private Observation sendObservation(String code, String system) throws InterruptedException {
|
||||
Observation observation = new Observation();
|
||||
CodeableConceptDt codeableConcept = new CodeableConceptDt();
|
||||
observation.setCode(codeableConcept);
|
||||
|
@ -106,6 +118,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
String observationId = methodOutcome.getId().getIdPart();
|
||||
observation.setId(observationId);
|
||||
|
||||
waitForQueueToDrain();
|
||||
return observation;
|
||||
}
|
||||
|
||||
|
@ -123,7 +136,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
Observation observation1 = sendObservation(code, "SNOMED-CT");
|
||||
|
||||
// Should see 1 subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(1, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -137,7 +150,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
||||
|
||||
// Should see two subscription notifications
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(3, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -146,7 +159,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
||||
|
||||
// Should see only one subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(4, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -159,7 +172,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
|
||||
|
||||
// Should see no subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(4, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -173,7 +186,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
|
||||
|
||||
// Should see only one subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(4, ourCreatedObservations.size());
|
||||
assertEquals(1, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -196,7 +209,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
Observation observation1 = sendObservation(code, "SNOMED-CT");
|
||||
|
||||
// Should see 1 subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(1, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -210,7 +223,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
||||
|
||||
// Should see two subscription notifications
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(3, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -219,7 +232,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
||||
|
||||
// Should see only one subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(4, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -232,7 +245,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
|
||||
|
||||
// Should see no subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(4, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -246,7 +259,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B
|
|||
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
|
||||
|
||||
// Should see only one subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(4, ourCreatedObservations.size());
|
||||
assertEquals(1, ourUpdatedObservations.size());
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
|||
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.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
||||
subscription.setStatus(Subscription.SubscriptionStatus.ACTIVE);
|
||||
|
@ -79,10 +79,19 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
|||
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
||||
subscription.setId(methodOutcome.getId().getIdPart());
|
||||
|
||||
waitForQueueToDrain();
|
||||
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();
|
||||
CodeableConcept codeableConcept = new CodeableConcept();
|
||||
observation.setCode(codeableConcept);
|
||||
|
@ -97,6 +106,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
|||
String observationId = methodOutcome.getId().getIdPart();
|
||||
observation.setId(observationId);
|
||||
|
||||
waitForQueueToDrain();
|
||||
return observation;
|
||||
}
|
||||
|
||||
|
@ -187,7 +197,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
|||
Observation observation1 = sendObservation(code, "SNOMED-CT");
|
||||
|
||||
// Should see 1 subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(1, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -201,7 +211,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
|||
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
||||
|
||||
// Should see two subscription notifications
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(3, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -210,7 +220,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
|||
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
||||
|
||||
// Should see only one subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(4, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -223,7 +233,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
|||
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
|
||||
|
||||
// Should see no subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(4, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -237,7 +247,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B
|
|||
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
|
||||
|
||||
// Should see only one subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(4, ourCreatedObservations.size());
|
||||
assertEquals(1, ourUpdatedObservations.size());
|
||||
|
||||
|
|
|
@ -316,11 +316,11 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test {
|
|||
}
|
||||
|
||||
private void waitForQueueToDrain() throws InterruptedException {
|
||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueue().size());
|
||||
while (ourRestHookSubscriptionInterceptor.getExecutorQueue().size() > 0) {
|
||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||
while (ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size() > 0) {
|
||||
Thread.sleep(250);
|
||||
}
|
||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueue().size());
|
||||
ourLog.info("QUEUE HAS {} ITEMS", ourRestHookSubscriptionInterceptor.getExecutorQueueForUnitTests().size());
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
|
|
@ -64,7 +64,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
|||
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.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
||||
subscription.setStatus(Subscription.SubscriptionStatus.ACTIVE);
|
||||
|
@ -79,10 +79,19 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
|||
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
||||
subscription.setId(methodOutcome.getId().getIdPart());
|
||||
|
||||
waitForQueueToDrain();
|
||||
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();
|
||||
CodeableConcept codeableConcept = new CodeableConcept();
|
||||
observation.setCode(codeableConcept);
|
||||
|
@ -97,6 +106,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
|||
String observationId = methodOutcome.getId().getIdPart();
|
||||
observation.setId(observationId);
|
||||
|
||||
waitForQueueToDrain();
|
||||
|
||||
return observation;
|
||||
}
|
||||
|
||||
|
@ -187,7 +198,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
|||
Observation observation1 = sendObservation(code, "SNOMED-CT");
|
||||
|
||||
// Should see 1 subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(1, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -201,7 +212,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
|||
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
||||
|
||||
// Should see two subscription notifications
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(3, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -210,7 +221,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
|||
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
||||
|
||||
// Should see only one subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(4, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -223,7 +234,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
|||
ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute();
|
||||
|
||||
// Should see no subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(4, ourCreatedObservations.size());
|
||||
assertEquals(0, ourUpdatedObservations.size());
|
||||
|
||||
|
@ -237,7 +248,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base
|
|||
ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute();
|
||||
|
||||
// Should see only one subscription notification
|
||||
Thread.sleep(500);
|
||||
waitForQueueToDrain();
|
||||
assertEquals(4, ourCreatedObservations.size());
|
||||
assertEquals(1, ourUpdatedObservations.size());
|
||||
|
||||
|
|
|
@ -1326,7 +1326,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
|
|||
}
|
||||
}
|
||||
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) {
|
||||
assertProviderIsValid(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.utils.GraphQLEngine;
|
||||
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.util.ArrayList;
|
||||
|
@ -106,7 +109,6 @@ public class GraphQLR4ProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testGraphSystemInstance() throws Exception {
|
||||
String query = "{Patient(id:123){id,name{given,family}}}";
|
||||
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("{\n" +
|
||||
" \"Patient\":{\n" +
|
||||
" \"name\":[{\n" +
|
||||
" \"family\":\"FAMILY\",\n" +
|
||||
" \"given\":[\"GIVEN1\",\"GIVEN2\"]\n" +
|
||||
" \"given\":[\"GIVEN1\",\"GIVEN2\"],\n" +
|
||||
" \"family\":\"FAMILY\"\n" +
|
||||
" },{\n" +
|
||||
" \"given\":[\"GivenOnly1\",\"GivenOnly2\"]\n" +
|
||||
" }]\n" +
|
||||
" }\n" +
|
||||
"}", responseContent);
|
||||
assertThat(status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue(), startsWith("application/json"));
|
||||
|
||||
|
@ -133,7 +137,6 @@ public class GraphQLR4ProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testGraphSystemList() throws Exception {
|
||||
String query = "{PatientList(name:\"pet\"){name{family,given}}}";
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/$graphql?query=" + UrlUtil.escape(query));
|
||||
|
@ -144,12 +147,18 @@ public class GraphQLR4ProviderTest {
|
|||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
|
||||
assertEquals("{\n" +
|
||||
" \"PatientList\":[{\n" +
|
||||
" \"name\":[{\n" +
|
||||
" \"family\":\"FAMILY\",\n" +
|
||||
" \"family\":\"pet\",\n" +
|
||||
" \"given\":[\"GIVEN1\",\"GIVEN2\"]\n" +
|
||||
" },{\n" +
|
||||
" \"given\":[\"GivenOnly1\",\"GivenOnly2\"]\n" +
|
||||
" }]\n" +
|
||||
" },{\n" +
|
||||
" \"name\":[{\n" +
|
||||
" \"given\":[\"GivenOnlyB1\",\"GivenOnlyB2\"]\n" +
|
||||
" }]\n" +
|
||||
" }]\n" +
|
||||
"}", responseContent);
|
||||
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 {
|
||||
@Override
|
||||
public ReferenceResolution lookup(Object appInfo, Resource context, Reference reference) throws FHIRException {
|
||||
ourLog.info("lookup from {} to {}", context.getIdElement().getValue(), reference.getReference());
|
||||
public ReferenceResolution lookup(Object theAppInfo, Resource theContext, Reference theReference) throws FHIRException {
|
||||
ourLog.info("lookup from {} to {}", theContext.getIdElement().getValue(), theReference.getReference());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource lookup(Object appInfo, String type, String id) throws FHIRException {
|
||||
ourLog.info("lookup {}/{}", type, id);
|
||||
public Resource lookup(Object theAppInfo, String theType, String theId) throws FHIRException {
|
||||
ourLog.info("lookup {}/{}", theType, theId);
|
||||
|
||||
if (type.equals("Patient") && id.equals("123")) {
|
||||
if (theType.equals("Patient") && theId.equals("123")) {
|
||||
Patient p = new Patient();
|
||||
p
|
||||
.addName()
|
||||
p.addName()
|
||||
.setFamily("FAMILY")
|
||||
.addGiven("GIVEN1")
|
||||
.addGiven("GIVEN2");
|
||||
p
|
||||
.addName()
|
||||
p.addName()
|
||||
.addGiven("GivenOnly1")
|
||||
.addGiven("GivenOnly2");
|
||||
return p;
|
||||
|
@ -236,13 +243,35 @@ public class GraphQLR4ProviderTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void listResources(Object appInfo, String type, List<Argument> searchParams, List<Resource> matches) throws FHIRException {
|
||||
ourLog.info("listResources of {} - {}", type, searchParams);
|
||||
public void listResources(Object theAppInfo, String theType, List<Argument> theSearchParams, List<Resource> theMatches) throws FHIRException {
|
||||
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
|
||||
public Bundle search(Object appInfo, String type, List<Argument> searchParams) throws FHIRException {
|
||||
ourLog.info("search on {} - {}", type, searchParams);
|
||||
public Bundle search(Object theAppInfo, String theType, List<Argument> theSearchParams) throws FHIRException {
|
||||
ourLog.info("search on {} - {}", theType, theSearchParams);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
6
pom.xml
6
pom.xml
|
@ -384,7 +384,7 @@
|
|||
<hibernate_version>5.2.10.Final</hibernate_version>
|
||||
<hibernate_validator_version>5.4.1.Final</hibernate_validator_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>
|
||||
<maven_assembly_plugin_version>2.5.3</maven_assembly_plugin_version>
|
||||
<maven_license_plugin_version>1.8</maven_license_plugin_version>
|
||||
|
@ -451,7 +451,7 @@
|
|||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<version>3.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
|
@ -877,7 +877,7 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jpa</artifactId>
|
||||
<version>1.10.4.RELEASE</version>
|
||||
<version>1.11.6.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
|
|
|
@ -19,8 +19,11 @@
|
|||
<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>Hibernate (JPA): 5.2.9 -> 5.2.10</li>
|
||||
<li>Spring (JPA): 4.3.7.RELEASE -> 4.3.10.RELEASE</li>
|
||||
<li>Thymeleaf (Testpage Overlay): 3.0.2.RELEASE -> 3.0.7.RELEASE</li>
|
||||
<li>Hibernate Search (JPA): 5.7.0 -> 5.7.1</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>
|
||||
]]>
|
||||
</action>
|
||||
|
|
Loading…
Reference in New Issue