001/* 002 * (C) Copyright 2015-2019 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Andre Justo 018 * Anahide Tchertchian 019 */ 020package org.nuxeo.runtime.services.config; 021 022import java.io.IOException; 023import java.io.Serializable; 024import java.time.Duration; 025import java.util.Map; 026import java.util.Optional; 027 028/** 029 * Service holding runtime configuration properties. 030 * 031 * @since 7.4 032 */ 033public interface ConfigurationService { 034 035 String LIST_SEPARATOR = ","; 036 037 /** 038 * Returns the given property value if any. 039 * 040 * @param key the property key 041 * @since 11.1 042 */ 043 Optional<String> getString(String key); 044 045 /** 046 * Returns the given property value if any, otherwise returns the given default value. 047 * 048 * @param key the property key 049 * @param defaultValue the default value for this key 050 * @since 11.1 051 */ 052 String getString(String key, String defaultValue); 053 054 /** 055 * Returns the given property value if any. 056 * 057 * @param key the property key 058 * @since 11.1 059 */ 060 Optional<Integer> getInteger(String key); 061 062 /** 063 * Returns the given property value if any, otherwise returns the given default value. 064 * 065 * @param key the property key 066 * @param defaultValue the default value for this key 067 * @since 11.1 068 */ 069 int getInteger(String key, int defaultValue); 070 071 /** 072 * Returns the given property value if any. 073 * 074 * @param key the property key 075 * @since 11.1 076 */ 077 Optional<Long> getLong(String key); 078 079 /** 080 * Returns the given property value if any, otherwise returns the given default value. 081 * 082 * @param key the property key 083 * @param defaultValue the default value for this key 084 * @since 11.1 085 */ 086 long getLong(String key, long defaultValue); 087 088 /** 089 * Returns the given property value if any. 090 * 091 * @param key the property key 092 * @since 11.1 093 */ 094 Optional<Boolean> getBoolean(String key); 095 096 /** 097 * Returns true if given property exists and is true when compared to a boolean value. 098 * 099 * <pre> 100 * prop=true | isBooleanTrue("prop") = true 101 * prop=trUe | isBooleanTrue("prop") = true 102 * prop=false | isBooleanTrue("prop") = false 103 * prop=any | isBooleanTrue("prop") = false 104 * prop= | isBooleanTrue("prop") = false 105 * </pre> 106 * 107 * @since 11.1 108 */ 109 boolean isBooleanTrue(String key); 110 111 /** 112 * Returns true if given property exists and is false when compared to a boolean value. 113 * 114 * <pre> 115 * prop=false | isBooleanFalse("prop") = true 116 * prop=fAlse | isBooleanFalse("prop") = true 117 * prop=true | isBooleanFalse("prop") = false 118 * prop=any | isBooleanFalse("prop") = false 119 * prop= | isBooleanFalse("prop") = false 120 * </pre> 121 * 122 * @since 11.1 123 */ 124 boolean isBooleanFalse(String key); 125 126 /** 127 * Returns the given property value if any. 128 * 129 * @param key the property key 130 * @since 11.1 131 */ 132 Optional<Duration> getDuration(String key); 133 134 /** 135 * Returns the given property value if any, otherwise returns the given default value. 136 * 137 * @param key the property key 138 * @param defaultValue the default value for this key 139 * @since 11.1 140 */ 141 Duration getDuration(String key, Duration defaultValue); 142 143 /** 144 * Returns the given property value if any, otherwise null. 145 * 146 * @param key the property key 147 * @deprecated since 11.1, use {@link #getString(String)} instead 148 */ 149 @Deprecated 150 String getProperty(String key); 151 152 /** 153 * Returns the given property value if any, otherwise returns the given default value. 154 * 155 * @param key the property key 156 * @param defaultValue the default value for this key 157 * @deprecated since 11.1, use {@link #getString(String, String)} instead 158 */ 159 @Deprecated 160 String getProperty(String key, String defaultValue); 161 162 /** 163 * Returns the properties with key starting with the given namespace. 164 * 165 * @param namespace the namespace 166 * @return a map of properties with trimmed keys (namespace removed) 167 * @since 10.3 168 */ 169 Map<String, Serializable> getProperties(String namespace); 170 171 /** 172 * Returns true if given property is true when compared to a boolean value. 173 * 174 * @deprecated since 11.1, use {@link #isBooleanTrue(String)} instead 175 */ 176 @Deprecated 177 boolean isBooleanPropertyTrue(String key); 178 179 /** 180 * Returns true if given property is false when compared to a boolean value. 181 * <p> 182 * Returns also true if property is not blank and is not equals to true. 183 * 184 * @deprecated since 11.1, use {@link #isBooleanFalse(String)} instead 185 */ 186 @Deprecated 187 boolean isBooleanPropertyFalse(String key); 188 189 /** 190 * Returns the json string representing the properties with key starting with the given namespace. 191 * 192 * @param namespace the namespace of the properties 193 * @since 10.3 194 */ 195 String getPropertiesAsJson(String namespace) throws IOException; 196 197}