001/*- 002 * #%L 003 * HAPI FHIR - Core Library 004 * %% 005 * Copyright (C) 2014 - 2025 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.system; 021 022import java.util.concurrent.TimeUnit; 023 024public final class HapiSystemProperties { 025 static final String SUPPRESS_HAPI_FHIR_VERSION_LOG = "suppress_hapi_fhir_version_log"; 026 static final String DISABLE_STATUS_BASED_REINDEX = "disable_status_based_reindex"; 027 /** 028 * This is provided for testing only! Use with caution as this property may change. 029 */ 030 static final String VALIDATION_RESOURCE_CACHE_TIMEOUT_MILLIS = "VALIDATION_RESOURCE_CACHE_EXPIRY_MS"; 031 032 static final String UNIT_TEST_CAPTURE_STACK = "unit_test_capture_stack"; 033 static final String STACKFILTER_PATTERN_PROP = "log.stackfilter.pattern"; 034 static final String HAPI_CLIENT_KEEPRESPONSES = "hapi.client.keepresponses"; 035 static final String TEST_MODE = "test"; 036 static final String UNIT_TEST_MODE = "unit_test_mode"; 037 static final long DEFAULT_VALIDATION_RESOURCE_CACHE_TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(10); 038 static final String PREVENT_INVALIDATING_CONDITIONAL_MATCH_CRITERIA = 039 "hapi.storage.prevent_invalidating_conditional_match_criteria"; 040 041 private HapiSystemProperties() {} 042 043 /** 044 * This property is used by unit tests - do not rely on it in production code 045 * as it may change at any time. If you want to capture responses in a reliable 046 * way in your own code, just use client interceptors 047 */ 048 public static void enableHapiClientKeepResponses() { 049 System.setProperty(HAPI_CLIENT_KEEPRESPONSES, Boolean.TRUE.toString()); 050 } 051 052 public static void disableHapiClientKeepResponses() { 053 System.clearProperty(HAPI_CLIENT_KEEPRESPONSES); 054 } 055 056 /** 057 * This property is used by unit tests - do not rely on it in production code 058 * as it may change at any time. If you want to capture responses in a reliable 059 * way in your own code, just use client interceptors 060 */ 061 public static boolean isHapiClientKeepResponsesEnabled() { 062 return (Boolean.parseBoolean(System.getProperty(HAPI_CLIENT_KEEPRESPONSES))); 063 } 064 065 /** 066 * This property gets used in the logback.xml file. 067 * It causes logged stack traces to skip a number of packages that are 068 * just noise. 069 */ 070 public static void setStackFilterPattern(String thePattern) { 071 System.setProperty(STACKFILTER_PATTERN_PROP, thePattern); 072 } 073 074 /** 075 * Set the validation resource cache expireAfterWrite timeout in milliseconds 076 * 077 * @param theMillis the timeout value to set (in milliseconds) 078 */ 079 public static void setValidationResourceCacheTimeoutMillis(long theMillis) { 080 System.setProperty(VALIDATION_RESOURCE_CACHE_TIMEOUT_MILLIS, "" + theMillis); 081 } 082 083 /** 084 * Get the validation resource cache expireAfterWrite timeout in milliseconds. If it has not been set, the default 085 * value is 10 seconds. 086 */ 087 public static long getValidationResourceCacheTimeoutMillis() { 088 String property = System.getProperty(VALIDATION_RESOURCE_CACHE_TIMEOUT_MILLIS); 089 if (property == null) { 090 return DEFAULT_VALIDATION_RESOURCE_CACHE_TIMEOUT_MILLIS; 091 } 092 return Long.parseLong(property); 093 } 094 095 /** 096 * When this property is primarily used to control application shutdown behavior 097 */ 098 public static void enableTestMode() { 099 System.setProperty(TEST_MODE, Boolean.TRUE.toString()); 100 } 101 102 public static boolean isTestModeEnabled() { 103 return Boolean.parseBoolean(System.getProperty(TEST_MODE)); 104 } 105 106 /** 107 * This property is used to ensure unit test behaviour is deterministic. 108 */ 109 public static void enableUnitTestMode() { 110 System.setProperty(UNIT_TEST_MODE, Boolean.TRUE.toString()); 111 } 112 113 public static void disableUnitTestMode() { 114 System.setProperty(UNIT_TEST_MODE, Boolean.FALSE.toString()); 115 } 116 117 public static boolean isUnitTestModeEnabled() { 118 return Boolean.parseBoolean(System.getProperty(UNIT_TEST_MODE)); 119 } 120 121 /** 122 * This property prevents stack traces from getting truncated and includes the full stack trace in failed search responses. 123 */ 124 public static void enableUnitTestCaptureStack() { 125 System.setProperty(UNIT_TEST_CAPTURE_STACK, Boolean.TRUE.toString()); 126 } 127 128 public static void disableUnitTestCaptureStack() { 129 System.clearProperty(HapiSystemProperties.UNIT_TEST_CAPTURE_STACK); 130 } 131 132 public static boolean isUnitTestCaptureStackEnabled() { 133 return Boolean.parseBoolean(System.getProperty(HapiSystemProperties.UNIT_TEST_CAPTURE_STACK)); 134 } 135 136 public static boolean isDisableStatusBasedReindex() { 137 return Boolean.parseBoolean(System.getProperty(DISABLE_STATUS_BASED_REINDEX)); 138 } 139 140 public static void disableStatusBasedReindex() { 141 System.setProperty(DISABLE_STATUS_BASED_REINDEX, Boolean.TRUE.toString()); 142 } 143 144 /** 145 * This property sets {@link JpaStorageSettings#setStatusBasedReindexingDisabled(Boolean)} to true when the system starts up. 146 */ 147 public static void enableStatusBasedReindex() { 148 System.clearProperty(DISABLE_STATUS_BASED_REINDEX); 149 } 150 151 /** 152 * This property is used to suppress the logging of the HAPI FHIR version on startup. 153 */ 154 // TODO KHS use this in cdr 155 public static void enableSuppressHapiFhirVersionLog() { 156 System.setProperty(SUPPRESS_HAPI_FHIR_VERSION_LOG, Boolean.TRUE.toString()); 157 } 158 159 public static boolean isSuppressHapiFhirVersionLogEnabled() { 160 return Boolean.parseBoolean(System.getProperty(SUPPRESS_HAPI_FHIR_VERSION_LOG)); 161 } 162 163 public static boolean isPreventInvalidatingConditionalMatchCriteria() { 164 return Boolean.parseBoolean(System.getProperty( 165 HapiSystemProperties.PREVENT_INVALIDATING_CONDITIONAL_MATCH_CRITERIA, Boolean.FALSE.toString())); 166 } 167}