Skip to content

Commit

Permalink
Merge pull request #2622 from IBM/tbieste-issue-2609
Browse files Browse the repository at this point in the history
Issue #2609 - Change parameter hash if legacy search params enabled
  • Loading branch information
tbieste authored Jul 19, 2021
2 parents 7013dd4 + d646fb8 commit 3393c29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import static com.ibm.fhir.config.FHIRConfiguration.PROPERTY_JDBC_ENABLE_CODE_SYSTEMS_CACHE;
import static com.ibm.fhir.config.FHIRConfiguration.PROPERTY_JDBC_ENABLE_PARAMETER_NAMES_CACHE;
import static com.ibm.fhir.config.FHIRConfiguration.PROPERTY_JDBC_ENABLE_RESOURCE_TYPES_CACHE;
import static com.ibm.fhir.config.FHIRConfiguration.PROPERTY_SEARCH_ENABLE_OPT_QUERY_BUILDER;
import static com.ibm.fhir.config.FHIRConfiguration.PROPERTY_SEARCH_ENABLE_LEGACY_WHOLE_SYSTEM_SEARCH_PARAMS;
import static com.ibm.fhir.config.FHIRConfiguration.PROPERTY_SEARCH_ENABLE_OPT_QUERY_BUILDER;
import static com.ibm.fhir.config.FHIRConfiguration.PROPERTY_UPDATE_CREATE_ENABLED;
import static com.ibm.fhir.model.type.String.string;
import static com.ibm.fhir.model.util.ModelSupport.getResourceType;
Expand Down Expand Up @@ -266,7 +266,7 @@ public FHIRPersistenceJDBCImpl(FHIRPersistenceJDBCCache cache) throws Exception
this.connectionStrategy = new FHIRDbTenantDatasourceConnectionStrategy(trxSynchRegistry, buildActionChain(), enableReadOnlyReplicas);

this.transactionAdapter = new FHIRUserTransactionAdapter(userTransaction, trxSynchRegistry, cache, TXN_DATA_KEY);

// Use of legacy whole-system search parameters disabled by default
this.legacyWholeSystemSearchParamsEnabled =
fhirConfig.getBooleanProperty(PROPERTY_SEARCH_ENABLE_LEGACY_WHOLE_SYSTEM_SEARCH_PARAMS, false);
Expand Down Expand Up @@ -2136,7 +2136,7 @@ private ExtractedSearchParameters extractSearchParameters(Resource fhirResource,
// Sort extracted parameter values in natural order first, to ensure the hash generated by
// this visitor is deterministic.
sortExtractedParameterValues(allParameters);
ParameterHashVisitor phv = new ParameterHashVisitor();
ParameterHashVisitor phv = new ParameterHashVisitor(legacyWholeSystemSearchParamsEnabled);
for (ExtractedParameterValue p: allParameters) {
p.accept(phv);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,25 @@ public class ParameterHashVisitor implements ExtractedParameterValueVisitor {
* Public constructor.
*/
public ParameterHashVisitor() {
this(false);
}

/**
* Public constructor.
* @param legacyWholeSystemSearchParamsEnabled if true, then update digest to ensure hash changes
* from when it is false; this can be removed when the legacyWholeSystemSearchParamsEnabled config
* setting is removed.
*/
public ParameterHashVisitor(boolean legacyWholeSystemSearchParamsEnabled) {
try {
digest = MessageDigest.getInstance(SHA_256);
// Start digest with latest FHIR schema version (with parameter storage update)
digest.update(FhirSchemaVersion.getLatestParameterStorageUpdate().toString().getBytes(StandardCharsets.UTF_8));
// If legacyWholeSystemSearchParamsEnabled is true, then update digest to ensure hash changes from when
// it is false; this can be removed when the legacyWholeSystemSearchParamsEnabled config setting is removed
if (legacyWholeSystemSearchParamsEnabled) {
updateDigestWithString("legacyWholeSystemSearchParamsEnabled");
}
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("MessageDigest not found: " + SHA_256, e);
}
Expand Down

0 comments on commit 3393c29

Please sign in to comment.