diff --git a/fhir-persistence/src/main/java/com/ibm/fhir/persistence/index/ParameterValueVisitorAdapter.java b/fhir-persistence/src/main/java/com/ibm/fhir/persistence/index/ParameterValueVisitorAdapter.java index 32a45fc304b..984d03e8d49 100644 --- a/fhir-persistence/src/main/java/com/ibm/fhir/persistence/index/ParameterValueVisitorAdapter.java +++ b/fhir-persistence/src/main/java/com/ibm/fhir/persistence/index/ParameterValueVisitorAdapter.java @@ -16,6 +16,8 @@ public interface ParameterValueVisitorAdapter { /** + * Process a string parameter + * * @param name * @param valueString * @param compositeId @@ -24,6 +26,8 @@ public interface ParameterValueVisitorAdapter { void stringValue(String name, String valueString, Integer compositeId, boolean wholeSystem); /** + * Process a number parameter + * * @param name * @param valueNumber * @param valueNumberLow @@ -33,6 +37,8 @@ public interface ParameterValueVisitorAdapter { void numberValue(String name, BigDecimal valueNumber, BigDecimal valueNumberLow, BigDecimal valueNumberHigh, Integer compositeId); /** + * Process a date parameter + * * @param name * @param valueDateStart * @param valueDateEnd @@ -42,6 +48,8 @@ public interface ParameterValueVisitorAdapter { void dateValue(String name, Instant valueDateStart, Instant valueDateEnd, Integer compositeId, boolean wholeSystem); /** + * Process a token parameter + * * @param name * @param valueSystem * @param valueCode @@ -50,6 +58,8 @@ public interface ParameterValueVisitorAdapter { void tokenValue(String name, String valueSystem, String valueCode, Integer compositeId); /** + * Process a tag parameter + * * @param name * @param valueSystem * @param valueCode @@ -59,6 +69,8 @@ public interface ParameterValueVisitorAdapter { void tagValue(String name, String valueSystem, String valueCode, boolean wholeSystem); /** + * Process a profile parameter + * * @param name * @param url * @param version @@ -68,6 +80,8 @@ public interface ParameterValueVisitorAdapter { void profileValue(String name, String url, String version, String fragment, boolean wholeSystem); /** + * Process a security parameter + * * @param name * @param valueSystem * @param valueCode @@ -76,6 +90,8 @@ public interface ParameterValueVisitorAdapter { void securityValue(String name, String valueSystem, String valueCode, boolean wholeSystem); /** + * Process a quantity parameter + * * @param name * @param valueSystem * @param valueCode @@ -88,6 +104,8 @@ void quantityValue(String name, String valueSystem, String valueCode, BigDecimal Integer compositeId); /** + * Process a location parameter + * * @param name * @param valueLatitude * @param valueLongitude @@ -96,6 +114,8 @@ void quantityValue(String name, String valueSystem, String valueCode, BigDecimal void locationValue(String name, Double valueLatitude, Double valueLongitude, Integer compositeId); /** + * Process a reference parameter + * * @param name * @param refResourceType * @param refLogicalId diff --git a/fhir-persistence/src/main/java/com/ibm/fhir/persistence/index/TokenParameter.java b/fhir-persistence/src/main/java/com/ibm/fhir/persistence/index/TokenParameter.java index 0d12749f5af..5e575784b71 100644 --- a/fhir-persistence/src/main/java/com/ibm/fhir/persistence/index/TokenParameter.java +++ b/fhir-persistence/src/main/java/com/ibm/fhir/persistence/index/TokenParameter.java @@ -73,5 +73,4 @@ public Integer getRefVersionId() { public void setRefVersionId(Integer refVersionId) { this.refVersionId = refVersionId; } - -} +} \ No newline at end of file diff --git a/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/api/IMessageHandler.java b/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/api/IMessageHandler.java index b503b5bcb75..4136b1355ee 100644 --- a/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/api/IMessageHandler.java +++ b/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/api/IMessageHandler.java @@ -16,6 +16,11 @@ */ public interface IMessageHandler { + /** + * Ask the handler to process the list of messages. + * @param messages + * @throws FHIRPersistenceException + */ void process(List messages) throws FHIRPersistenceException; /** diff --git a/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/app/Main.java b/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/app/Main.java index 2ff77dbdd4e..d2f8b9b15d1 100644 --- a/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/app/Main.java +++ b/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/app/Main.java @@ -262,6 +262,7 @@ private void initIdentityCache() throws FHIRPersistenceException { throw new FHIRPersistenceException("cache init failed", x); } } + /** * Create a new consumer * @return @@ -282,6 +283,9 @@ private KafkaConsumer buildConsumer() { return consumer; } + /** + * Set things up to talk to a PostgreSQL database + */ private void configureForPostgres() { this.translator = new PostgresTranslator(); try { diff --git a/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/BaseMessageHandler.java b/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/BaseMessageHandler.java index 6a08a8e53fe..a665c6d6f04 100644 --- a/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/BaseMessageHandler.java +++ b/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/BaseMessageHandler.java @@ -44,6 +44,7 @@ public abstract class BaseMessageHandler implements IMessageHandler { private SecureRandom random = new SecureRandom(); private final long maxReadyWaitMs; + /** * Protected constructor * @param maxReadyWaitMs the max time in ms to wait for the upstream transaction to make the data ready @@ -283,6 +284,8 @@ private void process(RemoteIndexMessage message) throws FHIRPersistenceException } /** + * Process the given LocationParameter p + * * @param tenantId * @param requestShard * @param resourceType @@ -293,6 +296,8 @@ private void process(RemoteIndexMessage message) throws FHIRPersistenceException protected abstract void process(String tenantId, String requestShard, String resourceType, String logicalId, long logicalResourceId, LocationParameter p) throws FHIRPersistenceException; /** + * Process the given TokenParameter p + * * @param tenantId * @param requestShard * @param resourceType @@ -303,6 +308,7 @@ private void process(RemoteIndexMessage message) throws FHIRPersistenceException protected abstract void process(String tenantId, String requestShard, String resourceType, String logicalId, long logicalResourceId, TokenParameter p) throws FHIRPersistenceException; /** + * Process the given TagParameter p * * @param tenantId * @param requestShard @@ -315,6 +321,7 @@ private void process(RemoteIndexMessage message) throws FHIRPersistenceException protected abstract void process(String tenantId, String requestShard, String resourceType, String logicalId, long logicalResourceId, TagParameter p) throws FHIRPersistenceException; /** + * Process the given ProfileParameter p * * @param tenantId * @param requestShard @@ -327,6 +334,7 @@ private void process(RemoteIndexMessage message) throws FHIRPersistenceException protected abstract void process(String tenantId, String requestShard, String resourceType, String logicalId, long logicalResourceId, ProfileParameter p) throws FHIRPersistenceException; /** + * Proces the given SecurityParameter p * * @param tenantId * @param requestShard @@ -339,6 +347,8 @@ private void process(RemoteIndexMessage message) throws FHIRPersistenceException protected abstract void process(String tenantId, String requestShard, String resourceType, String logicalId, long logicalResourceId, SecurityParameter p) throws FHIRPersistenceException; /** + * Process the given QuantityParameter p + * * @param tenantId * @param requestShard * @param resourceType @@ -349,6 +359,8 @@ private void process(RemoteIndexMessage message) throws FHIRPersistenceException protected abstract void process(String tenantId, String requestShard, String resourceType, String logicalId, long logicalResourceId, QuantityParameter p) throws FHIRPersistenceException; /** + * Process the given NumberParameter p + * * @param tenantId * @param requestShard * @param resourceType @@ -359,6 +371,8 @@ private void process(RemoteIndexMessage message) throws FHIRPersistenceException protected abstract void process(String tenantId, String requestShard, String resourceType, String logicalId, long logicalResourceId, NumberParameter p) throws FHIRPersistenceException; /** + * Process the given DateParameter p + * * @param tenantId * @param requestShard * @param resourceType @@ -369,6 +383,7 @@ private void process(RemoteIndexMessage message) throws FHIRPersistenceException protected abstract void process(String tenantId, String requestShard, String resourceType, String logicalId, long logicalResourceId, DateParameter p) throws FHIRPersistenceException; /** + * Process the given ReferenceParameter p * * @param tenantId * @param requestShard @@ -392,7 +407,8 @@ private void process(RemoteIndexMessage message) throws FHIRPersistenceException /** * Tell the persistence layer to commit the current transaction, or perform a rollback - * if setRollbackOnly() has been called + * if setRollbackOnly() has been called. + * * @throws FHIRPersistenceException */ protected abstract void endTransaction() throws FHIRPersistenceException; diff --git a/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/CacheLoader.java b/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/CacheLoader.java index 9e4d08a194c..7d66a6bcae8 100644 --- a/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/CacheLoader.java +++ b/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/CacheLoader.java @@ -30,6 +30,12 @@ public CacheLoader(IdentityCacheImpl cache) { this.cache = cache; } + /** + * Read records from the database using the given connection and apply the + * values to the configured cache object. + * @param connection + * @throws FHIRPersistenceException + */ public void apply(Connection connection) throws FHIRPersistenceException { // load the static list of resource types List resourceTypes = new ArrayList<>(); diff --git a/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/LogicalResourceValue.java b/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/LogicalResourceValue.java index 7491e2f8d79..1c6dc14cc7d 100644 --- a/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/LogicalResourceValue.java +++ b/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/LogicalResourceValue.java @@ -19,6 +19,10 @@ public class LogicalResourceValue { private final int versionId; private final Timestamp lastUpdated; private final String parameterHash; + + /** + * Builder for fluent creation of LogicalResourceValue objects + */ public static class Builder { private short shardKey; private long logicalResourceId; @@ -28,30 +32,71 @@ public static class Builder { private Timestamp lastUpdated; private String parameterHash; + /** + * Set the shardKey + * @param shardKey + * @return + */ public Builder withShardKey(short shardKey) { this.shardKey = shardKey; return this; } + + /** + * Set the logicalResourceId value + * @param logicalResourceId + * @return + */ public Builder withLogicalResourceId(long logicalResourceId) { this.logicalResourceId = logicalResourceId; return this; } + + /** + * Set the resourceType value + * @param resourceType + * @return + */ public Builder withResourceType(String resourceType) { this.resourceType = resourceType; return this; } + + /** + * Set the logicalId value + * @param logicalId + * @return + */ public Builder withLogicalId(String logicalId) { this.logicalId = logicalId; return this; } + + /** + * Set the versionId value + * @param versionId + * @return + */ public Builder withVersionId(int versionId) { this.versionId = versionId; return this; } + + /** + * Set the lastUpdated value + * @param lastUpdated + * @return + */ public Builder withLastUpdated(Timestamp lastUpdated) { this.lastUpdated = lastUpdated; return this; } + + /** + * Set the parameterHash value + * @param parameterHash + * @return + */ public Builder withParameterHash(String parameterHash) { this.parameterHash = parameterHash; return this; @@ -67,7 +112,7 @@ public LogicalResourceValue build() { } /** - * Factor function to create a fresh instance of a {@link Builder} + * Factory function to create a fresh instance of a {@link Builder} * @return */ public static Builder builder() { @@ -75,7 +120,8 @@ public static Builder builder() { } /** - * Public constructor + * Canonical constructor + * * @param shardKey * @param logicalResourceId * @param resourceType diff --git a/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/PlainPostgresMessageHandler.java b/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/PlainPostgresMessageHandler.java index 6749e082ed2..0f6e268f518 100644 --- a/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/PlainPostgresMessageHandler.java +++ b/fhir-remote-index/src/main/java/com/ibm/fhir/remote/index/database/PlainPostgresMessageHandler.java @@ -378,6 +378,14 @@ private CommonTokenValue lookupCommonTokenValue(String codeSystem, String tokenV return result; } + /** + * Get the LogicalReosurceIdentValue we've assigned for the given (resourceType, logicalId) + * tuple. The returned value may not yet have the actual logical_resource_id yet - we fetch + * these values later and create new database records as necessary + * @param resourceType + * @param logicalId + * @return + */ private LogicalResourceIdentValue lookupLogicalResourceIdentValue(String resourceType, String logicalId) { LogicalResourceIdentKey key = new LogicalResourceIdentKey(resourceType, logicalId); LogicalResourceIdentValue result = this.logicalResourceIdentMap.get(key); @@ -393,6 +401,13 @@ private LogicalResourceIdentValue lookupLogicalResourceIdentValue(String resourc return result; } + /** + * Get the CommonCanonicalValue we've assigned for the given url value. + * The returned value may not yet have the actual canonical_id yet - we fetch + * these values later and create new database records as necessary. + * @param url + * @return + */ private CommonCanonicalValue lookupCommonCanonicalValue(String url) { CommonCanonicalValueKey key = new CommonCanonicalValueKey(FIXED_SHARD, url); CommonCanonicalValue result = this.commonCanonicalValueMap.get(key); @@ -500,6 +515,12 @@ protected void addMissingCodeSystems(List missing) throws FHIRP } } + /** + * Fetch all the code_system_id values for the given list of CodeSystemValue objects. + * @param unresolved + * @return + * @throws FHIRPersistenceException + */ private List fetchCodeSystemIds(List unresolved) throws FHIRPersistenceException { // track which values aren't yet in the database List missing = new ArrayList<>(); @@ -624,7 +645,13 @@ private PreparedStatementWrapper buildCommonTokenValueSelectStatement(List fetchCommonTokenValueIds(List unresolved) throws FHIRPersistenceException { // track which values aren't yet in the database List missing = new ArrayList<>(); @@ -738,6 +765,12 @@ private void resolveCommonCanonicalValues() throws FHIRPersistenceException { } } + /** + * Fetch the common_canonical_id values for the given list of CommonCanonicalValue objects. + * @param unresolved + * @return + * @throws FHIRPersistenceException + */ private List fetchCanonicalIds(List unresolved) throws FHIRPersistenceException { // track which values aren't yet in the database List missing = new ArrayList<>(); @@ -893,6 +926,12 @@ private void resolveParameterNames() throws FHIRPersistenceException { } } + /** + * Fetch the parameter_name_id for the given parameterName value + * @param parameterName + * @return + * @throws SQLException + */ private Integer getParameterNameIdFromDatabase(String parameterName) throws SQLException { String SQL = "SELECT parameter_name_id FROM parameter_names WHERE parameter_name = ?"; try (PreparedStatement ps = connection.prepareStatement(SQL)) { @@ -1168,6 +1207,12 @@ protected void addMissingLogicalResourceIdents(List m } } + /** + * Fetch logical_resource_id values for the given list of LogicalResourceIdent objects. + * @param unresolved + * @return + * @throws FHIRPersistenceException + */ private List fetchLogicalResourceIdentIds(List unresolved) throws FHIRPersistenceException { // track which values aren't yet in the database List missing = new ArrayList<>(); @@ -1217,6 +1262,4 @@ private List fetchLogicalResourceIdentIds(List