Skip to content

Commit

Permalink
Issue #2609 - Update after review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Biesterfeld <tbieste@us.ibm.com>
  • Loading branch information
tbieste committed Jul 19, 2021
1 parent 241f06b commit d646fb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2136,8 +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();
phv.setLegacyWholeSystemSearchParamsEnabled(legacyWholeSystemSearchParamsEnabled);
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,28 +47,31 @@ 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);
}
encoder = Base64.getEncoder();
}

/**
* If legacyWholeSystemSearchParamsEnabled is true, then update digest to ensure hash changes
* from when legacyWholeSystemSearchParamsEnabled is false; this can be removed when the
* legacyWholeSystemSearchParamsEnabled config setting is removed.
* @param enabled true or false
*/
public void setLegacyWholeSystemSearchParamsEnabled(boolean enabled) {
if (enabled) {
updateDigestWithString("legacyWholeSystemSearchParamsEnabled");
}
}

@Override
public void visit(StringParmVal param) throws FHIRPersistenceException {
updateDigestWithParmValKey(param);
Expand Down

0 comments on commit d646fb8

Please sign in to comment.