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

openmrs / openmrs-core / 18842842547

27 Oct 2025 01:35PM UTC coverage: 64.894% (+0.008%) from 64.886%
18842842547

push

github

web-flow
TRUNK-6448: Orders: Allow setting Order Number and Stopping Inactive Orders Based On Global Property (#5418)

17 of 23 new or added lines in 4 files covered. (73.91%)

1 existing line in 1 file now uncovered.

23435 of 36113 relevant lines covered (64.89%)

0.65 hits per line

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

96.55
/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.GlobalProperty;
14
import org.openmrs.api.GlobalPropertyListener;
15
import org.openmrs.api.context.Context;
16

17
import java.util.HashMap;
18
import java.util.Map;
19

20
/**
21
 * A utility class for working with configuration properties
22
 */
23
public class ConfigUtil implements GlobalPropertyListener {
1✔
24

25
        /**
26
         * Cache of global property key/value pairs to enable lookups that do not require accessing the service each time
27
         */
28
        private static final Map<String, String> globalPropertyCache = new HashMap<>();
1✔
29
        
30
        /**
31
         * Gets the value of the given OpenMRS global property
32
         */
33
        public static String getGlobalProperty(String propertyName) {
34
                if (globalPropertyCache.containsKey(propertyName)) {
1✔
35
                        return globalPropertyCache.get(propertyName);
1✔
36
                }
37
                String value = Context.getAdministrationService().getGlobalProperty(propertyName);
1✔
38
                globalPropertyCache.put(propertyName, value);
1✔
39
                return value;
1✔
40
        }
41

42
    /**
43
         * Returns the value of the given OpenMRS runtime property
44
         */
45
        public static String getRuntimeProperty(String propertyName) {
46
                return Context.getRuntimeProperties().getProperty(propertyName);
1✔
47
        }
48

49
        /**
50
         * Returns true if a runtime property with the given name has been defined, even if the value is empty
51
         */
52
        public static boolean hasRuntimeProperty(String propertyName) {
53
                return Context.getRuntimeProperties().containsKey(propertyName);
1✔
54
        }
55

56
        /**
57
         * Returns the value of the given OpenMRS system property
58
         */
59
        public static String getSystemProperty(String propertyName) {
60
                return System.getProperty(propertyName);
1✔
61
        }
62

63
        /**
64
         * Returns true if a system property with the given name has been defined, even if the value is empty
65
         */
66
        public static boolean hasSystemProperty(String propertyName) {
67
                return System.getProperties().containsKey(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
         */
75
        public static String getProperty(String propertyName) {
76
                if (hasSystemProperty(propertyName)) {
1✔
77
                        return getSystemProperty(propertyName);
1✔
78
                }
79
                if (hasRuntimeProperty(propertyName)) {
1✔
80
                        return getRuntimeProperty(propertyName);
1✔
81
                }
82
                return getGlobalProperty(propertyName);
1✔
83
        }
84

85
        /**
86
         * Returns the value of the given configuration property.  This will check the OpenMRS global properties,
87
         * OpenMRS runtime properties, and any defined system properties.  In the event that a property is defined in 
88
         * multiple places, the order of precedence is system properties, then runtime properties, then global properties
89
         * If the value found is null, empty, or only whitespace, then the default value is returned
90
         */
91
        public static String getProperty(String propertyName, String defaultValue) {
92
                String value = getProperty(propertyName);
1✔
93
                if (StringUtils.isBlank(value)) {
1✔
94
                        value = defaultValue;
1✔
95
                }
96
                return value;
1✔
97
        }
98

99
        /**
100
         * Operates as above but returns the Boolean value of the property
101
         * 
102
         * @param propertyName
103
         * @param defaultValue
104
         * @return
105
         */
106
        public static boolean getProperty(String propertyName, boolean defaultValue) {
107
                String value = getProperty(propertyName);
1✔
108
                if (StringUtils.isBlank(value)) {
1✔
NEW
109
                        return defaultValue;
×
110
                }
111
                return Boolean.parseBoolean(value);
1✔
112
        }
113
        
114
        @Override
115
        public void globalPropertyChanged(GlobalProperty newValue) {
116
                globalPropertyCache.put(newValue.getProperty(), newValue.getPropertyValue());
1✔
117
        }
1✔
118
        
119
        @Override
120
        public void globalPropertyDeleted(String propertyName) {
121
                globalPropertyCache.remove(propertyName);
1✔
122
        }
1✔
123
        
124
        @Override
125
        public boolean supportsPropertyName(String propertyName) {
126
                return true;
1✔
127
        }
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc