add configuration setting to disable overriding of resource ids when the

Bundle.entry.fullUrl is specified
This commit is contained in:
michael.i.calderero 2017-04-13 11:32:05 -05:00
parent bf94d78872
commit 7d9883014a
3 changed files with 93 additions and 12 deletions

View File

@ -41,6 +41,7 @@ public class ParserOptions {
private boolean myStripVersionsFromReferences = true;
private Set<String> myDontStripVersionsFromReferencesAtPaths = Collections.emptySet();
private boolean myOverrideResourceIdWithBundleEntryFullUrl = true;
/**
* If supplied value(s), any resource references at the specified paths will have their
@ -144,4 +145,33 @@ public class ParserOptions {
return myDontStripVersionsFromReferencesAtPaths;
}
/**
* If set to <code>true</code> (which is the default), the Bundle.entry.fullUrl will override the Bundle.entry.resource's
* resource id if the fullUrl is defined. This behavior happens when parsing the source data into a Bundle object. Set this
* to <code>false</code> if this is not the desired behavior (e.g. the client code wishes to perform additional
* validation checks between the fullUrl and the resource id).
*
* @return Returns the parser instance's configuration setting for overriding resource ids with Bundle.entry.fullUrl when
* parsing the source data into a Bundle object. Default is <code>true</code>.
*/
public boolean isOverrideResourceIdWithBundleEntryFullUrl() {
return myOverrideResourceIdWithBundleEntryFullUrl;
}
/**
* If set to <code>true</code> (which is the default), the Bundle.entry.fullUrl will override the Bundle.entry.resource's
* resource id if the fullUrl is defined. This behavior happens when parsing the source data into a Bundle object. Set this
* to <code>false</code> if this is not the desired behavior (e.g. the client code wishes to perform additional
* validation checks between the fullUrl and the resource id).
*
* @param theOverrideResourceIdWithBundleEntryFullUrl
* Set this to <code>false</code> to prevent the parser from overriding resource ids with the
* Bundle.entry.fullUrl
*
* @return Returns a reference to <code>this</code> parser so that method calls can be chained together
*/
public ParserOptions setOverrideResourceIdWithBundleEntryFullUrl(boolean theOverrideResourceIdWithBundleEntryFullUrl) {
myOverrideResourceIdWithBundleEntryFullUrl = theOverrideResourceIdWithBundleEntryFullUrl;
return this;
}
}

View File

@ -97,6 +97,7 @@ public abstract class BaseParser implements IParser {
private List<Class<? extends IBaseResource>> myPreferTypes;
private String myServerBaseUrl;
private Boolean myStripVersionsFromReferences;
private Boolean myOverrideResourceIdWithBundleEntryFullUrl;
private boolean mySummaryMode;
private boolean mySuppressNarratives;
private Set<String> myDontStripVersionsFromReferencesAtPaths;
@ -346,6 +347,15 @@ public abstract class BaseParser implements IParser {
return true;
}
private boolean isOverrideResourceIdWithBundleEntryFullUrl() {
Boolean overrideResourceIdWithBundleEntryFullUrl = myOverrideResourceIdWithBundleEntryFullUrl;
if (overrideResourceIdWithBundleEntryFullUrl != null) {
return overrideResourceIdWithBundleEntryFullUrl;
}
return myContext.getParserOptions().isOverrideResourceIdWithBundleEntryFullUrl();
}
protected abstract void doEncodeBundleToWriter(Bundle theBundle, Writer theWriter) throws IOException, DataFormatException;
@ -596,6 +606,11 @@ public abstract class BaseParser implements IParser {
public Boolean getStripVersionsFromReferences() {
return myStripVersionsFromReferences;
}
@Override
public Boolean getOverrideResourceIdWithBundleEntryFullUrl() {
return myOverrideResourceIdWithBundleEntryFullUrl;
}
@Override
public boolean isSummaryMode() {
@ -658,22 +673,23 @@ public abstract class BaseParser implements IParser {
if (fullUrlChild == null) {
continue; // TODO: remove this once the data model in tinder plugin catches up to 1.2
}
List<IBase> fullUrl = fullUrlChild.getAccessor().getValues(nextEntry);
if (fullUrl != null && !fullUrl.isEmpty()) {
IPrimitiveType<?> value = (IPrimitiveType<?>) fullUrl.get(0);
if (value.isEmpty() == false) {
List<IBase> entryResources = entryDef.getChildByName("resource").getAccessor().getValues(nextEntry);
if (entryResources != null && entryResources.size() > 0) {
IBaseResource res = (IBaseResource) entryResources.get(0);
String versionId = res.getIdElement().getVersionIdPart();
res.setId(value.getValueAsString());
if (isNotBlank(versionId) && res.getIdElement().hasVersionIdPart() == false) {
res.setId(res.getIdElement().withVersion(versionId));
if (isOverrideResourceIdWithBundleEntryFullUrl()) {
List<IBase> fullUrl = fullUrlChild.getAccessor().getValues(nextEntry);
if (fullUrl != null && !fullUrl.isEmpty()) {
IPrimitiveType<?> value = (IPrimitiveType<?>) fullUrl.get(0);
if (value.isEmpty() == false) {
List<IBase> entryResources = entryDef.getChildByName("resource").getAccessor().getValues(nextEntry);
if (entryResources != null && entryResources.size() > 0) {
IBaseResource res = (IBaseResource) entryResources.get(0);
String versionId = res.getIdElement().getVersionIdPart();
res.setId(value.getValueAsString());
if (isNotBlank(versionId) && res.getIdElement().hasVersionIdPart() == false) {
res.setId(res.getIdElement().withVersion(versionId));
}
}
}
}
}
}
}
@ -876,6 +892,12 @@ public abstract class BaseParser implements IParser {
myStripVersionsFromReferences = theStripVersionsFromReferences;
return this;
}
@Override
public IParser setOverrideResourceIdWithBundleEntryFullUrl(Boolean theOverrideResourceIdWithBundleEntryFullUrl) {
myOverrideResourceIdWithBundleEntryFullUrl = theOverrideResourceIdWithBundleEntryFullUrl;
return this;
}
@Override
public IParser setDontStripVersionsFromReferencesAtPaths(String... thePaths) {

View File

@ -128,6 +128,19 @@ public interface IParser {
* @see ParserOptions
*/
Boolean getStripVersionsFromReferences();
/**
* If set to <code>true</code> (which is the default), the Bundle.entry.fullUrl will override the Bundle.entry.resource's
* resource id if the fullUrl is defined. This behavior happens when parsing the source data into a Bundle object. Set this
* to <code>false</code> if this is not the desired behavior (e.g. the client code wishes to perform additional
* validation checks between the fullUrl and the resource id).
*
* @return Returns the parser instance's configuration setting for overriding resource ids with Bundle.entry.fullUrl when
* parsing the source data into a Bundle object. This method will return <code>null</code> if no value is set, in
* which case the value from the {@link ParserOptions} will be used (default is <code>true</code>)
* @see ParserOptions
*/
Boolean getOverrideResourceIdWithBundleEntryFullUrl();
/**
* Is the parser in "summary mode"? See {@link #setSummaryMode(boolean)} for information
@ -361,6 +374,22 @@ public interface IParser {
* @return Returns a reference to <code>this</code> parser so that method calls can be chained together
*/
IParser setStripVersionsFromReferences(Boolean theStripVersionsFromReferences);
/**
* If set to <code>true</code> (which is the default), the Bundle.entry.fullUrl will override the Bundle.entry.resource's
* resource id if the fullUrl is defined. This behavior happens when parsing the source data into a Bundle object. Set this
* to <code>false</code> if this is not the desired behavior (e.g. the client code wishes to perform additional
* validation checks between the fullUrl and the resource id).
*
* @param theOverrideResourceIdWithBundleEntryFullUrl
* Set this to <code>false</code> to prevent the parser from overriding resource ids with the
* Bundle.entry.fullUrl (or <code>null</code> to apply the default setting from the {@link ParserOptions})
*
* @see ParserOptions
*
* @return Returns a reference to <code>this</code> parser so that method calls can be chained together
*/
IParser setOverrideResourceIdWithBundleEntryFullUrl(Boolean theOverrideResourceIdWithBundleEntryFullUrl);
/**
* If set to <code>true</code> (default is <code>false</code>) only elements marked by the FHIR specification as