001/* 002 * Copyright 2018 Anyware Services 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 */ 016package org.ametys.plugins.repository.data.repositorydata; 017 018import java.io.InputStream; 019import java.util.Calendar; 020import java.util.Set; 021 022import org.apache.commons.lang3.StringUtils; 023 024import org.ametys.plugins.repository.data.UnknownDataException; 025 026/** 027 * Interface for data values management in repository 028 */ 029public interface RepositoryData 030{ 031 /** Constant for type string */ 032 public static final String STRING_REPOSITORY_DATA_TYPE = "string"; 033 034 /** Constant for type calendar */ 035 public static final String CALENDAR_REPOSITORY_DATA_TYPE = "calendar"; 036 037 /** Constant for type long */ 038 public static final String LONG_REPOSITORY_DATA_TYPE = "long"; 039 040 /** Constant for type double */ 041 public static final String DOUBLE_REPOSITORY_DATA_TYPE = "double"; 042 043 /** Constant for type boolean */ 044 public static final String BOOLEAN_REPOSITORY_DATA_TYPE = "boolean"; 045 046 /** Constant for type stream */ 047 public static final String STREAM_REPOSITORY_DATA_TYPE = "stream"; 048 049 /** 050 * Retrieves the value of the string data stored in the repository with the given name 051 * @param name name of the data 052 * @return the value of the data 053 */ 054 public default String getString(String name) 055 { 056 return getString(name, getDefaultPrefix()); 057 } 058 059 /** 060 * Retrieves the value of the string data stored in the repository with the given name 061 * @param name name of the data 062 * @param prefix prefix of the data name, to use instead of the default one. 063 * @return the value of the data 064 */ 065 public String getString(String name, String prefix); 066 067 /** 068 * Retrieves the values of the multiple string data stored in the repository with the given name 069 * @param name name of the data 070 * @return the values of the data as a string array 071 */ 072 public default String[] getStrings(String name) 073 { 074 return getStrings(name, getDefaultPrefix()); 075 } 076 077 /** 078 * Retrieves the values of the multiple string data stored in the repository with the given name 079 * @param name name of the data 080 * @param prefix prefix of the data name, to use instead of the default one. 081 * @return the values of the data as a string array 082 */ 083 public String[] getStrings(String name, String prefix); 084 085 /** 086 * Retrieves the value of the date data stored as calendar in the repository with the given name 087 * @param name name of the data 088 * @return the value of the data 089 */ 090 public default Calendar getDate(String name) 091 { 092 return getDate(name, getDefaultPrefix()); 093 } 094 095 /** 096 * Retrieves the value of the date data stored as calendar in the repository with the given name 097 * @param name name of the data 098 * @param prefix prefix of the data name, to use instead of the default one. 099 * @return the value of the data 100 */ 101 public Calendar getDate(String name, String prefix); 102 103 /** 104 * Retrieves the values of the multiple date data as calendar stored in the repository with the given name 105 * @param name name of the data 106 * @return the values of the data as a date array 107 */ 108 public default Calendar[] getDates(String name) 109 { 110 return getDates(name, getDefaultPrefix()); 111 } 112 113 /** 114 * Retrieves the values of the multiple date data as calendar stored in the repository with the given name 115 * @param name name of the data 116 * @param prefix prefix of the data name, to use instead of the default one. 117 * @return the values of the data as a date array 118 */ 119 public Calendar[] getDates(String name, String prefix); 120 121 /** 122 * Retrieves the value of the long data stored in the repository with the given name 123 * @param name name of the data 124 * @return the value of the data 125 */ 126 public default Long getLong(String name) 127 { 128 return getLong(name, getDefaultPrefix()); 129 } 130 131 /** 132 * Retrieves the value of the long data stored in the repository with the given name 133 * @param name name of the data 134 * @param prefix prefix of the data name, to use instead of the default one. 135 * @return the value of the data 136 */ 137 public Long getLong(String name, String prefix); 138 139 /** 140 * Retrieves the values of the multiple long data stored in the repository with the given name 141 * @param name name of the data 142 * @return the values of the data as a long array 143 */ 144 public default Long[] getLongs(String name) 145 { 146 return getLongs(name, getDefaultPrefix()); 147 } 148 149 /** 150 * Retrieves the values of the multiple long data stored in the repository with the given name 151 * @param name name of the data 152 * @param prefix prefix of the data name, to use instead of the default one. 153 * @return the values of the data as a long array 154 */ 155 public Long[] getLongs(String name, String prefix); 156 157 /** 158 * Retrieves the value of the double data stored in the repository with the given name 159 * @param name name of the data 160 * @return the value of the data 161 */ 162 public default Double getDouble(String name) 163 { 164 return getDouble(name, getDefaultPrefix()); 165 } 166 167 /** 168 * Retrieves the value of the double data stored in the repository with the given name 169 * @param name name of the data 170 * @param prefix prefix of the data name, to use instead of the default one. 171 * @return the value of the data 172 */ 173 public Double getDouble(String name, String prefix); 174 175 /** 176 * Retrieves the values of the multiple double data stored in the repository with the given name 177 * @param name name of the data 178 * @return the values of the data as a double array 179 */ 180 public default Double[] getDoubles(String name) 181 { 182 return getDoubles(name, getDefaultPrefix()); 183 } 184 185 /** 186 * Retrieves the values of the multiple double data stored in the repository with the given name 187 * @param name name of the data 188 * @param prefix prefix of the data name, to use instead of the default one. 189 * @return the values of the data as a double array 190 */ 191 public Double[] getDoubles(String name, String prefix); 192 193 /** 194 * Retrieves the value of the boolean data stored in the repository with the given name 195 * @param name name of the data 196 * @return the value of the data 197 */ 198 public default Boolean getBoolean(String name) 199 { 200 return getBoolean(name, getDefaultPrefix()); 201 } 202 203 /** 204 * Retrieves the value of the boolean data stored in the repository with the given name 205 * @param name name of the data 206 * @param prefix prefix of the data name, to use instead of the default one. 207 * @return the value of the data 208 */ 209 public Boolean getBoolean(String name, String prefix); 210 211 /** 212 * Retrieves the values of the multiple boolean data stored in the repository with the given name 213 * @param name name of the data 214 * @return the values of the data as a boolean array 215 */ 216 public default Boolean[] getBooleans(String name) 217 { 218 return getBooleans(name, getDefaultPrefix()); 219 } 220 221 /** 222 * Retrieves the values of the multiple boolean data stored in the repository with the given name 223 * @param name name of the data 224 * @param prefix prefix of the data name, to use instead of the default one. 225 * @return the values of the data as a boolean array 226 */ 227 public Boolean[] getBooleans(String name, String prefix); 228 229 /** 230 * Retrieves the value of the repository data stored in the repository with the given name 231 * @param name name of the data 232 * @return the value of the data 233 */ 234 public default RepositoryData getRepositoryData(String name) 235 { 236 return getRepositoryData(name, getDefaultPrefix()); 237 } 238 239 /** 240 * Retrieves the value of the repository data stored in the repository with the given name 241 * @param name name of the data 242 * @param prefix prefix of the data name, to use instead of the default one. 243 * @return the value of the data 244 */ 245 public RepositoryData getRepositoryData(String name, String prefix); 246 247 /** 248 * Retrieves the values of all the repository data stored in the repository with the given name 249 * @param name name of the data 250 * @return the values of the data 251 */ 252 public default RepositoryData[] getAllRepositoryData(String name) 253 { 254 return getAllRepositoryData(name, getDefaultPrefix()); 255 } 256 257 /** 258 * Retrieves the values of all the repository data stored in the repository with the given name 259 * @param name name of the data 260 * @param prefix prefix of the data name, to use instead of the default one. 261 * @return the values of the data 262 */ 263 public RepositoryData[] getAllRepositoryData(String name, String prefix); 264 265 /** 266 * Retrieves the value of the stream data stored in the repository with the given name 267 * @param name name of the data 268 * @return the value of the data 269 */ 270 public default InputStream getStream(String name) 271 { 272 return getStream(name, getDefaultPrefix()); 273 } 274 275 /** 276 * Retrieves the value of the stream data stored in the repository with the given name 277 * @param name name of the data 278 * @param prefix prefix of the data name, to use instead of the default one. 279 * @return the value of the data 280 */ 281 public InputStream getStream(String name, String prefix); 282 283 /** 284 * Retrieves the length of the value of the stream data stored in the repository with the given name 285 * @param name name of the data 286 * @return the length of the value of the data 287 */ 288 public default Long getStreamLength(String name) 289 { 290 return getStreamLength(name, getDefaultPrefix()); 291 } 292 293 /** 294 * Retrieves the length of the value of the stream data stored in the repository with the given name 295 * @param name name of the data 296 * @param prefix prefix of the data name, to use instead of the default one. 297 * @return the length of the value of the data 298 */ 299 public Long getStreamLength(String name, String prefix); 300 301 /** 302 * Retrieves the values of the multiple stream data stored in the repository with the given name 303 * @param name name of the data 304 * @return the values of the data as an input stream array 305 */ 306 public default InputStream[] getStreams(String name) 307 { 308 return getStreams(name, getDefaultPrefix()); 309 } 310 311 /** 312 * Retrieves the values of the multiple stream data stored in the repository with the given name 313 * @param name name of the data 314 * @param prefix prefix of the data name, to use instead of the default one. 315 * @return the values of the data as an input stream array 316 */ 317 public InputStream[] getStreams(String name, String prefix); 318 319 /** 320 * Retrieves the names of all data in this repository data 321 * @return the names of all data in this repository data 322 */ 323 public default Set<String> getAllDataNames() 324 { 325 return getDataNames(StringUtils.EMPTY); 326 } 327 328 /** 329 * Retrieves the names of data in this repository data with the default prefix 330 * @return the names of data by this repository data 331 */ 332 public default Set<String> getDataNames() 333 { 334 return getDataNames(getDefaultPrefix()); 335 } 336 337 /** 338 * Retrieves the names of data in this repository data with the given prefix 339 * @param prefix prefix of the data names to retrieve. If <code>null</code>, retrieves all the data names of this repository data 340 * @return the names of data by this repository data 341 */ 342 public Set<String> getDataNames(String prefix); 343 344 /** 345 * Retrieves the name of the current repository data, excluding its prefix 346 * @return the name of the current repository data 347 */ 348 public String getName(); 349 350 /** 351 * Checks if there is a value for the data stored in the repository with the given name 352 * @param name name of the data 353 * @return true if there is value for the data, false otherwise 354 */ 355 public default boolean hasValue(String name) 356 { 357 return hasValue(name, getDefaultPrefix()); 358 } 359 360 /** 361 * Checks if there is a value for the data stored in the repository with the given name 362 * @param name name of the data 363 * @param prefix prefix of the data name, to use instead of the default one. 364 * @return true if there is value for the data, false otherwise 365 */ 366 public boolean hasValue(String name, String prefix); 367 368 /** 369 * Retrieves the type of the value for the data stored in the repository with the given name 370 * @param name name of the data 371 * @return the value's type of the data 372 * @throws UnknownDataException if there is no data stored with the given name 373 */ 374 public default String getType(String name) throws UnknownDataException 375 { 376 return getType(name, getDefaultPrefix()); 377 } 378 379 /** 380 * Retrieves the type of the value for the data stored in the repository with the given name 381 * @param name name of the data 382 * @param prefix prefix of the data name, to use instead of the default one. 383 * @return the value's type of the data 384 * @throws UnknownDataException if there is no data stored with the given name 385 */ 386 public String getType(String name, String prefix) throws UnknownDataException; 387 388 /** 389 * Checks if the value for the data stored in the repository with the given name is multiple 390 * @param name name of the data 391 * @return true if the value for the data is multiple, false otherwise 392 * @throws UnknownDataException if there is no data stored with the given name 393 */ 394 public default boolean isMultiple(String name) throws UnknownDataException 395 { 396 return isMultiple(name, getDefaultPrefix()); 397 } 398 399 /** 400 * Checks if the value for the data stored in the repository with the given name is multiple 401 * @param name name of the data 402 * @param prefix prefix of the data name, to use instead of the default one. 403 * @return true if the value for the data is multiple, false otherwise 404 * @throws UnknownDataException if there is no data stored with the given name 405 */ 406 public boolean isMultiple(String name, String prefix) throws UnknownDataException; 407 408 /** 409 * Retrieves the default prefix 410 * @return the default prefix 411 */ 412 public String getDefaultPrefix(); 413}