Skip to content

Commit

Permalink
added maxRetriex extension to canonical subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
fil512 committed Jan 21, 2019
1 parent 17f03ac commit a6d1cc5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
Expand Up @@ -295,6 +295,8 @@ public static class RestHookDetails {
private boolean myStripVersionId;
@JsonProperty("deliverLatestVersion")
private boolean myDeliverLatestVersion;
@JsonProperty("maxRetries")
private int myMaxRetries;

/**
* Constructor
Expand All @@ -311,6 +313,23 @@ public void setDeliverLatestVersion(boolean theDeliverLatestVersion) {
myDeliverLatestVersion = theDeliverLatestVersion;
}


public boolean isStripVersionId() {
return myStripVersionId;
}

public void setStripVersionId(boolean theStripVersionId) {
myStripVersionId = theStripVersionId;
}

public int getMaxRetries() {
return myMaxRetries;
}

public void setMaxRetries(int theMaxRetries) {
myMaxRetries = theMaxRetries;
}

@Override
public boolean equals(Object theO) {
if (this == theO) return true;
Expand All @@ -322,6 +341,7 @@ public boolean equals(Object theO) {
return new EqualsBuilder()
.append(myStripVersionId, that.myStripVersionId)
.append(myDeliverLatestVersion, that.myDeliverLatestVersion)
.append(myMaxRetries, that.myMaxRetries)
.isEquals();
}

Expand All @@ -330,17 +350,10 @@ public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(myStripVersionId)
.append(myDeliverLatestVersion)
.append(myMaxRetries)
.toHashCode();
}

public boolean isStripVersionId() {
return myStripVersionId;
}

public void setStripVersionId(boolean theStripVersionId) {
myStripVersionId = theStripVersionId;
}

}

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down
Expand Up @@ -28,6 +28,7 @@
import ca.uhn.fhir.model.api.IPrimitiveDatatype;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import org.hl7.fhir.dstu3.model.Subscription;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.IBaseReference;
import org.hl7.fhir.instance.model.api.IBaseResource;
Expand Down Expand Up @@ -96,10 +97,10 @@ protected CanonicalSubscription canonicalizeDstu3(IBaseResource theSubscription)
retVal.setIdElement(subscription.getIdElement());
retVal.setPayloadString(subscription.getChannel().getPayload());

if (retVal.getChannelType() == CanonicalSubscriptionChannelType.EMAIL) {
if (retVal.getChannelType() == CanonicalSubscriptionChannelType.EMAIL) {
String from;
String subjectTemplate;
String bodyTemplate;

try {
from = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_EMAIL_FROM);
subjectTemplate = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE);
Expand All @@ -111,16 +112,22 @@ protected CanonicalSubscription canonicalizeDstu3(IBaseResource theSubscription)
}

if (retVal.getChannelType() == CanonicalSubscriptionChannelType.RESTHOOK) {

String stripVersionIds;
String deliverLatestVersion;
String maxRetries;
try {
stripVersionIds = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_RESTHOOK_STRIP_VERSION_IDS);
deliverLatestVersion = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_RESTHOOK_DELIVER_LATEST_VERSION);
maxRetries = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_MAX_RETRIES);
} catch (FHIRException theE) {
throw new ConfigurationException("Failed to extract subscription extension(s): " + theE.getMessage(), theE);
}
retVal.getRestHookDetails().setStripVersionId(Boolean.parseBoolean(stripVersionIds));
retVal.getRestHookDetails().setDeliverLatestVersion(Boolean.parseBoolean(deliverLatestVersion));
if (isNotBlank(maxRetries)) {
retVal.getRestHookDetails().setMaxRetries(Integer.parseInt(maxRetries));
}
}

} catch (FHIRException theE) {
Expand Down Expand Up @@ -239,14 +246,20 @@ protected CanonicalSubscription canonicalizeR4(IBaseResource theSubscription) {
if (retVal.getChannelType() == CanonicalSubscriptionChannelType.RESTHOOK) {
String stripVersionIds;
String deliverLatestVersion;
String maxRetries;
try {
stripVersionIds = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_RESTHOOK_STRIP_VERSION_IDS);
deliverLatestVersion = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_RESTHOOK_DELIVER_LATEST_VERSION);
maxRetries = subscription.getChannel().getExtensionString(SubscriptionConstants.EXT_SUBSCRIPTION_MAX_RETRIES);

} catch (FHIRException theE) {
throw new ConfigurationException("Failed to extract subscription extension(s): " + theE.getMessage(), theE);
}
retVal.getRestHookDetails().setStripVersionId(Boolean.parseBoolean(stripVersionIds));
retVal.getRestHookDetails().setDeliverLatestVersion(Boolean.parseBoolean(deliverLatestVersion));
if (isNotBlank(maxRetries)) {
retVal.getRestHookDetails().setMaxRetries(Integer.parseInt(maxRetries));
}
}

List<Extension> topicExts = subscription.getExtensionsByUrl("http://hl7.org/fhir/subscription/topics");
Expand Down
Expand Up @@ -67,6 +67,12 @@ public class SubscriptionConstants {
*/
public static final String EXT_SUBSCRIPTION_RESTHOOK_DELIVER_LATEST_VERSION = "http://hapifhir.io/fhir/StructureDefinition/subscription-resthook-deliver-latest-version";

/**
* This extension URL indicates the maximum number of delivery retries that will be attempted before the subscription delivery is considered to have failed.
*/

public static final String EXT_SUBSCRIPTION_MAX_RETRIES = "http://hapifhir.io/fhir/StructureDefinition/subscription-max-retries";

/**
* The number of threads used in subscription channel processing
*/
Expand Down
Expand Up @@ -101,8 +101,7 @@ protected void doDelivery(ResourceDeliveryMessage theMsg, CanonicalSubscription
try {
operation.execute();
} catch (ResourceNotFoundException e) {
ourLog.error("Cannot reach " + theMsg.getSubscription().getEndpointUrl());
e.printStackTrace();
ourLog.error("Cannot reach " + theMsg.getSubscription().getEndpointUrl(), e);
throw e;
}
}
Expand Down

0 comments on commit a6d1cc5

Please sign in to comment.