• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openmrs / openmrs-core / 36872660172

01 Oct 2026 01:58PM UTC coverage: 66.293% (+0.2%) from 66.046%
36872660172

push

github

ibacher
TRUNK-6707: Implement full caching for Global Properties (#6598)

219 of 229 new or added lines in 7 files covered. (95.63%)

1 existing line in 1 file now uncovered.

25757 of 38853 relevant lines covered (66.29%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.74
/api/src/main/java/org/openmrs/util/ConfigUtil.java
1
/**
2
 * This Source Code Form is subject to the terms of the Mozilla Public License,
3
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6
 *
7
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8
 * graphic logo is a trademark of OpenMRS Inc.
9
 */
10
package org.openmrs.util;
11

12
import org.apache.commons.lang3.StringUtils;
13
import org.openmrs.api.context.Context;
14

15
/**
16
 * A utility class for working with configuration properties
17
 */
NEW
18
public class ConfigUtil {
×
19
        
20
        /**
21
         * Gets the value of the given OpenMRS global property
22
         */
23
        public static String getGlobalProperty(String propertyName) {
24
                return Context.getAdministrationService().getGlobalProperty(propertyName);
1 ✔
25
        }
26
        
27
        /**
28
         * Returns the value of the given OpenMRS runtime property
29
         */
30
        public static String getRuntimeProperty(String propertyName) {
31
                return Context.getRuntimeProperties().getProperty(propertyName);
1 ✔
32
        }
33
        
34
        /**
35
         * Returns true if a runtime property with the given name has been defined, even if the value is empty
36
         */
37
        public static boolean hasRuntimeProperty(String propertyName) {
38
                return Context.getRuntimeProperties().containsKey(propertyName);
1 ✔
39
        }
40
        
41
        /**
42
         * Returns the value of the given OpenMRS system property
43
         */
44
        public static String getSystemProperty(String propertyName) {
45
                return System.getProperty(propertyName);
1 ✔
46
        }
47
        
48
        /**
49
         * Returns true if a system property with the given name has been defined, even if the value is empty
50
         */
51
        public static boolean hasSystemProperty(String propertyName) {
52
                return System.getProperties().containsKey(propertyName);
1 ✔
53
        }
54
        
55
        /**
56
         * Returns the value of the given configuration property.  This will check the OpenMRS global properties,
57
         * OpenMRS runtime properties, and any defined system properties.  In the event that a property is defined in 
58
         * multiple places, the order of precedence is system properties, then runtime properties, then global properties
59
         */
60
        public static String getProperty(String propertyName) {
61
                if (hasSystemProperty(propertyName)) {
1 ✔
62
                        return getSystemProperty(propertyName);
1 ✔
63
                }
64
                if (hasRuntimeProperty(propertyName)) {
1 ✔
65
                        return getRuntimeProperty(propertyName);
1 ✔
66
                }
67
                return getGlobalProperty(propertyName);
1 ✔
68
        }
69
        
70
        /**
71
         * Returns the value of the given configuration property.  This will check the OpenMRS global properties,
72
         * OpenMRS runtime properties, and any defined system properties.  In the event that a property is defined in 
73
         * multiple places, the order of precedence is system properties, then runtime properties, then global properties
74
         * If the value found is null, empty, or only whitespace, then the default value is returned
75
         */
76
        public static String getProperty(String propertyName, String defaultValue) {
77
                String value = getProperty(propertyName);
1 ✔
78
                if (StringUtils.isBlank(value)) {
1 ✔
79
                        value = defaultValue;
1 ✔
80
                }
81
                return value;
1 ✔
82
        }
83
        
84
        /**
85
         * Operates as above but returns the Boolean value of the property
86
         * 
87
         * @param propertyName
88
         * @param defaultValue
89
         * @return
90
         */
91
        public static boolean getProperty(String propertyName, boolean defaultValue) {
92
                String value = getProperty(propertyName);
1 ✔
93
                if (StringUtils.isBlank(value)) {
1 ✔
94
                        return defaultValue;
1 ✔
95
                }
96
                return Boolean.parseBoolean(value);
1 ✔
97
        }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc