Move partition ID up from ResourceModifiedMessage to BaseResourceModifiedMessage (#4313)

* Move partition ID up from ResourceModifiedMessage to BaseResourceModifiedMessage.

* Add a changelog.  Add a new constructor that contains partition ID to ResourceOperationMessage.   Add partition ID to the toString() for BaseResourceModifiedMessage.  Tweak constructors of all classes to make sure ResourceModifiedMessage always sets default partition IDs, but BaseResourceModifiedMessage and ResourceOperationMessage do not.

* Reverse an accidental whitespace change.

* Small code review fixes including removing comments and updating changelog description.

* Restore whitespace to what it was on master.

* Fix YAML error.
This commit is contained in:
Luke deGruchy 2022-12-05 09:21:30 -05:00 committed by GitHub
parent 08ca687c72
commit 869d9996b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 16 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 4315
title: "Made the partitionId field of ResourceModifiedMessage also available to ResourceOperationMessage. This can be used to manually select a partition for messages of this type"

View File

@ -22,6 +22,7 @@ package ca.uhn.fhir.rest.server.messaging;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.model.api.IModelJson;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.api.EncodingEnum;
@ -45,6 +46,8 @@ public abstract class BaseResourceModifiedMessage extends BaseResourceMessage im
protected String myPayload;
@JsonProperty("payloadId")
protected String myPayloadId;
@JsonProperty(value = "partitionId")
protected RequestPartitionId myPartitionId;
@JsonIgnore
protected transient IBaseResource myPayloadDecoded;
@ -67,6 +70,13 @@ public abstract class BaseResourceModifiedMessage extends BaseResourceMessage im
setTransactionId(theRequest.getTransactionGuid());
}
}
public BaseResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest, RequestPartitionId theRequestPartitionId) {
this(theFhirContext, theNewResource, theOperationType);
if (theRequest != null) {
setTransactionId(theRequest.getTransactionGuid());
}
myPartitionId = theRequestPartitionId;
}
@Override
public String getPayloadId() {
@ -173,10 +183,19 @@ public abstract class BaseResourceModifiedMessage extends BaseResourceMessage im
setPayloadId(payloadIdType);
}
public RequestPartitionId getPartitionId() {
return myPartitionId;
}
public void setPartitionId(RequestPartitionId thePartitionId) {
myPartitionId = thePartitionId;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("operationType", myOperationType)
.append("partitionId", myPartitionId)
.append("payloadId", myPayloadId)
.toString();
}

View File

@ -21,7 +21,9 @@ package ca.uhn.fhir.rest.server.messaging;
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hl7.fhir.instance.model.api.IBaseResource;
public class ResourceOperationMessage extends BaseResourceModifiedMessage {
@ -37,6 +39,10 @@ public class ResourceOperationMessage extends BaseResourceModifiedMessage {
super(theFhirContext, theNewResource, theOperationType, theRequest);
}
public ResourceOperationMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest, RequestPartitionId theRequestPartitionId) {
super(theFhirContext, theNewResource, theOperationType, theRequest, theRequestPartitionId);
}
/**
* If you are using a non-fhir-resource payload, you may set the payload directly here instead of using the constructor.
* @param thePayload the payload of the message.
@ -44,4 +50,13 @@ public class ResourceOperationMessage extends BaseResourceModifiedMessage {
public void setPayload(String thePayload) {
this.myPayload = thePayload;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("operationType", myOperationType)
.append("payloadId", myPayloadId)
.append("partitionId", myPartitionId)
.toString();
}
}

View File

@ -38,12 +38,9 @@ public class ResourceModifiedMessage extends BaseResourceModifiedMessage {
* This will only be set if the resource is being triggered for a specific
* subscription
*/
@JsonProperty(value = "subscriptionId", required = false)
@JsonProperty(value = "subscriptionId")
private String mySubscriptionId;
@JsonProperty(value = "partitionId", required = false)
private RequestPartitionId myPartitionId;
/**
* Constructor
@ -54,17 +51,16 @@ public class ResourceModifiedMessage extends BaseResourceModifiedMessage {
public ResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theResource, OperationTypeEnum theOperationType) {
super(theFhirContext, theResource, theOperationType);
myPartitionId = RequestPartitionId.defaultPartition();
setPartitionId(RequestPartitionId.defaultPartition());
}
public ResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest) {
super(theFhirContext, theNewResource, theOperationType, theRequest);
myPartitionId = RequestPartitionId.defaultPartition();
setPartitionId(RequestPartitionId.defaultPartition());
}
public ResourceModifiedMessage(FhirContext theFhirContext, IBaseResource theNewResource, OperationTypeEnum theOperationType, RequestDetails theRequest, RequestPartitionId theRequestPartitionId) {
super(theFhirContext, theNewResource, theOperationType, theRequest);
myPartitionId = theRequestPartitionId;
super(theFhirContext, theNewResource, theOperationType, theRequest, theRequestPartitionId);
}
@ -76,14 +72,6 @@ public class ResourceModifiedMessage extends BaseResourceModifiedMessage {
mySubscriptionId = theSubscriptionId;
}
public RequestPartitionId getPartitionId() {
return myPartitionId;
}
public void setPartitionId(RequestPartitionId thePartitionId) {
myPartitionId = thePartitionId;
}
@Override
public String toString() {