Refactor to use concrete class instead of parent

This commit is contained in:
Tadgh 2020-09-15 15:27:21 -04:00
parent 5744f7035f
commit ea64bea1b0
9 changed files with 83 additions and 62 deletions

View File

@ -1620,7 +1620,7 @@ public enum Pointcut {
* <p> * <p>
* Hooks may accept the following parameters: * Hooks may accept the following parameters:
* <ul> * <ul>
* <li>ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage- This parameter should not be modified as processing is complete when this hook is invoked.</li> * <li>ca.uhn.fhir.rest.server.messaging.ConcreteResourceModifiedMessage- This parameter should not be modified as processing is complete when this hook is invoked.</li>
* <li>ca.uhn.fhir.empi.model.TransactionLogMessages - This parameter is for informational messages provided by the EMPI module during EMPI procesing. .</li> * <li>ca.uhn.fhir.empi.model.TransactionLogMessages - This parameter is for informational messages provided by the EMPI module during EMPI procesing. .</li>
* </ul> * </ul>
* </p> * </p>
@ -1628,7 +1628,7 @@ public enum Pointcut {
* Hooks should return <code>void</code>. * Hooks should return <code>void</code>.
* </p> * </p>
*/ */
EMPI_AFTER_PERSISTED_RESOURCE_CHECKED(void.class, "ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage", "ca.uhn.fhir.rest.server.TransactionLogMessages"), EMPI_AFTER_PERSISTED_RESOURCE_CHECKED(void.class, "ca.uhn.fhir.rest.server.messaging.ConcreteResourceModifiedMessage", "ca.uhn.fhir.rest.server.TransactionLogMessages"),
/** /**
* <b>Performance Tracing Hook:</b> * <b>Performance Tracing Hook:</b>

View File

@ -33,7 +33,7 @@ import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage;
import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage;
import ca.uhn.fhir.rest.server.TransactionLogMessages; import ca.uhn.fhir.rest.server.TransactionLogMessages;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage; import ca.uhn.fhir.rest.server.messaging.ConcreteResourceModifiedMessage;
import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IAnyResource;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -94,10 +94,14 @@ public class EmpiMessageHandler implements MessageHandler {
}catch (Exception e) { }catch (Exception e) {
log(empiContext, "Failure during EMPI processing: " + e.getMessage()); log(empiContext, "Failure during EMPI processing: " + e.getMessage());
} finally { } finally {
// Interceptor call: EMPI_AFTER_PERSISTED_RESOURCE_CHECKED // Interceptor call: EMPI_AFTER_PERSISTED_RESOURCE_CHECKED
ConcreteResourceModifiedMessage outgoingMsg = new ConcreteResourceModifiedMessage(myFhirContext, theMsg.getPayload(myFhirContext), theMsg.getOperationType());
outgoingMsg.setTransactionId(theMsg.getTransactionId());
HookParams params = new HookParams() HookParams params = new HookParams()
//Janky upcast. //Janky upcast.
.add(BaseResourceModifiedMessage.class, (BaseResourceModifiedMessage) theMsg) .add(ConcreteResourceModifiedMessage.class,outgoingMsg)
.add(TransactionLogMessages.class, empiContext.getTransactionLogMessages()); .add(TransactionLogMessages.class, empiContext.getTransactionLogMessages());
myInterceptorBroadcaster.callHooks(Pointcut.EMPI_AFTER_PERSISTED_RESOURCE_CHECKED, params); myInterceptorBroadcaster.callHooks(Pointcut.EMPI_AFTER_PERSISTED_RESOURCE_CHECKED, params);
} }

View File

@ -5,7 +5,7 @@ import ca.uhn.fhir.empi.log.Logs;
import ca.uhn.fhir.jpa.subscription.channel.api.ChannelConsumerSettings; import ca.uhn.fhir.jpa.subscription.channel.api.ChannelConsumerSettings;
import ca.uhn.fhir.jpa.subscription.channel.api.IChannelFactory; import ca.uhn.fhir.jpa.subscription.channel.api.IChannelFactory;
import ca.uhn.fhir.jpa.subscription.channel.api.IChannelReceiver; import ca.uhn.fhir.jpa.subscription.channel.api.IChannelReceiver;
import ca.uhn.fhir.rest.server.messaging.json.BaseResourceModifiedJsonMessage; import ca.uhn.fhir.rest.server.messaging.json.ConcreteResourceModifiedJsonMessage;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -52,7 +52,7 @@ public class EmpiQueueConsumerLoader {
if (myEmpiChannel == null) { if (myEmpiChannel == null) {
ChannelConsumerSettings config = new ChannelConsumerSettings(); ChannelConsumerSettings config = new ChannelConsumerSettings();
config.setConcurrentConsumers(myEmpiSettings.getConcurrentConsumers()); config.setConcurrentConsumers(myEmpiSettings.getConcurrentConsumers());
myEmpiChannel = myChannelFactory.getOrCreateReceiver(IEmpiSettings.EMPI_CHANNEL_NAME, BaseResourceModifiedJsonMessage.class, config); myEmpiChannel = myChannelFactory.getOrCreateReceiver(IEmpiSettings.EMPI_CHANNEL_NAME, ConcreteResourceModifiedJsonMessage.class, config);
} }
if (myEmpiChannel != null) { if (myEmpiChannel != null) {

View File

@ -63,7 +63,6 @@ public class SubscriptionDeliveringMessageSubscriber extends BaseSubscriptionDel
} }
protected void doDelivery(ResourceDeliveryMessage theMsg, CanonicalSubscription theSubscription, IChannelProducer theChannelProducer, IBaseResource thePayloadResource) { protected void doDelivery(ResourceDeliveryMessage theMsg, CanonicalSubscription theSubscription, IChannelProducer theChannelProducer, IBaseResource thePayloadResource) {
//TODO GGG/KHS Question: is this the point at which we can use a BaseResourceModifiedMessage, since technically we no longer have need of a subscriptionId?
ResourceModifiedMessage payload = new ResourceModifiedMessage(myFhirContext, thePayloadResource, theMsg.getOperationType()); ResourceModifiedMessage payload = new ResourceModifiedMessage(myFhirContext, thePayloadResource, theMsg.getOperationType());
payload.setTransactionId(theMsg.getTransactionId()); payload.setTransactionId(theMsg.getTransactionId());
ResourceModifiedJsonMessage message = new ResourceModifiedJsonMessage(payload); ResourceModifiedJsonMessage message = new ResourceModifiedJsonMessage(payload);

View File

@ -17,7 +17,7 @@ import java.util.List;
import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
public class BaseResourceModifiedMessage extends BaseResourceMessage implements IResourceMessage, IModelJson { public abstract class BaseResourceModifiedMessage extends BaseResourceMessage implements IResourceMessage, IModelJson {
@JsonProperty("resourceId") @JsonProperty("resourceId")
protected String myId; protected String myId;

View File

@ -0,0 +1,18 @@
package ca.uhn.fhir.rest.server.messaging;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import org.hl7.fhir.instance.model.api.IBaseResource;
public class ConcreteResourceModifiedMessage extends BaseResourceModifiedMessage {
public ConcreteResourceModifiedMessage() {
}
public ConcreteResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theResource, OperationTypeEnum theOperationType) {
super(theFhirContext, theResource, theOperationType);
}
public ConcreteResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) {
super(theFhirContext, theNewResource, theOperationType, theRequest);
}
}

View File

@ -1,49 +0,0 @@
package ca.uhn.fhir.rest.server.messaging.json;
import ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.ToStringBuilder;
public class BaseResourceModifiedJsonMessage extends BaseJsonMessage<BaseResourceModifiedMessage> {
@JsonProperty("payload")
private BaseResourceModifiedMessage myPayload;
/**
* Constructor
*/
public BaseResourceModifiedJsonMessage() {
super();
}
/**
* Constructor
*/
public BaseResourceModifiedJsonMessage(BaseResourceModifiedMessage thePayload) {
myPayload = thePayload;
setDefaultRetryHeaders();
}
public BaseResourceModifiedJsonMessage(HapiMessageHeaders theRetryMessageHeaders, BaseResourceModifiedMessage thePayload) {
myPayload = thePayload;
setHeaders(theRetryMessageHeaders);
}
@Override
public BaseResourceModifiedMessage getPayload() {
return myPayload;
}
public void setPayload(BaseResourceModifiedMessage thePayload) {
myPayload = thePayload;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("myPayload", myPayload)
.toString();
}
}

View File

@ -0,0 +1,49 @@
package ca.uhn.fhir.rest.server.messaging.json;
import ca.uhn.fhir.rest.server.messaging.ConcreteResourceModifiedMessage;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.ToStringBuilder;
public class ConcreteResourceModifiedJsonMessage extends BaseJsonMessage<ConcreteResourceModifiedMessage> {
@JsonProperty("payload")
private ConcreteResourceModifiedMessage myPayload;
/**
* Constructor
*/
public ConcreteResourceModifiedJsonMessage() {
super();
}
/**
* Constructor
*/
public ConcreteResourceModifiedJsonMessage(ConcreteResourceModifiedMessage thePayload) {
myPayload = thePayload;
setDefaultRetryHeaders();
}
public ConcreteResourceModifiedJsonMessage(HapiMessageHeaders theRetryMessageHeaders, ConcreteResourceModifiedMessage thePayload) {
myPayload = thePayload;
setHeaders(theRetryMessageHeaders);
}
@Override
public ConcreteResourceModifiedMessage getPayload() {
return myPayload;
}
public void setPayload(ConcreteResourceModifiedMessage thePayload) {
myPayload = thePayload;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("myPayload", myPayload)
.toString();
}
}

View File

@ -1,6 +1,6 @@
package ca.uhn.fhir.rest.server.messaging; package ca.uhn.fhir.rest.server.messaging;
import ca.uhn.fhir.rest.server.messaging.json.BaseResourceModifiedJsonMessage; import ca.uhn.fhir.rest.server.messaging.json.ConcreteResourceModifiedJsonMessage;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -12,15 +12,15 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
class BaseResourceModifiedMessageTest { class ConcreteResourceModifiedMessageTest {
@Test @Test
public void testSerializationAndDeserializationOfResourceModifiedMessage() throws JsonProcessingException { public void testSerializationAndDeserializationOfResourceModifiedMessage() throws JsonProcessingException {
BaseResourceModifiedJsonMessage jsonMessage = new BaseResourceModifiedJsonMessage(); ConcreteResourceModifiedJsonMessage jsonMessage = new ConcreteResourceModifiedJsonMessage();
jsonMessage.setPayload(new BaseResourceModifiedMessage()); jsonMessage.setPayload(new ConcreteResourceModifiedMessage());
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
String serialized = mapper.writeValueAsString(jsonMessage); String serialized = mapper.writeValueAsString(jsonMessage);
jsonMessage = mapper.readValue(serialized, BaseResourceModifiedJsonMessage.class); jsonMessage = mapper.readValue(serialized, ConcreteResourceModifiedJsonMessage.class);
assertThat(jsonMessage.getHapiHeaders().getRetryCount(), is(equalTo(0))); assertThat(jsonMessage.getHapiHeaders().getRetryCount(), is(equalTo(0)));
assertThat(jsonMessage.getHapiHeaders().getFirstFailureDate(), is(equalTo(null))); assertThat(jsonMessage.getHapiHeaders().getFirstFailureDate(), is(equalTo(null)));