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.regex.Pattern; 021 022import org.ametys.plugins.repository.data.UnknownDataException; 023 024/** 025 * Interface for modifiable data values management in repository 026 */ 027public interface ModifiableRepositoryData extends RepositoryData 028{ 029 /** The data path pattern to test validity */ 030 public static final Pattern DATA_NAME_PATTERN = Pattern.compile("[a-z][a-z0-9-_]*", Pattern.CASE_INSENSITIVE); 031 032 @Override 033 public default ModifiableRepositoryData getRepositoryData(String name) 034 { 035 return getRepositoryData(name, getDefaultPrefix()); 036 } 037 038 @Override 039 public ModifiableRepositoryData getRepositoryData(String name, String prefix); 040 041 /** 042 * Creates a repository data and stores it in the repository with the given name 043 * @param name name of the data 044 * @param dataTypeName data type name to use on creation 045 * @return the value of the data 046 */ 047 public default ModifiableRepositoryData addRepositoryData(String name, String dataTypeName) 048 { 049 return addRepositoryData(name, dataTypeName, getDefaultPrefix()); 050 } 051 052 /** 053 * Creates a repository data and stores it in the repository with the given name 054 * @param name name of the data 055 * @param dataTypeName data type name to use on creation 056 * @param prefix prefix of the data name, to use instead of the default one. 057 * @return the value of the data 058 */ 059 public ModifiableRepositoryData addRepositoryData(String name, String dataTypeName, String prefix); 060 061 /** 062 * Rename the current repository data 063 * @param newName the new name 064 */ 065 public default void rename(String newName) 066 { 067 rename(newName, getDefaultPrefix()); 068 } 069 070 /** 071 * Rename the current repository data 072 * @param newName the new name 073 * @param prefix prefix of the data name, to use instead of the default one. 074 */ 075 public void rename(String newName, String prefix); 076 077 /** 078 * Sets the value of the string data stored in the repository with the given name 079 * @param name name of the data 080 * @param value the value to set 081 */ 082 public default void setValue(String name, String value) 083 { 084 setValue(name, value, getDefaultPrefix()); 085 } 086 087 /** 088 * Sets the value of the string data stored in the repository with the given name 089 * @param name name of the data 090 * @param value the value to set 091 * @param prefix prefix of the data name, to use instead of the default one. 092 */ 093 public void setValue(String name, String value, String prefix); 094 095 /** 096 * Sets the values of the multiple string data stored in the repository with the given name 097 * @param name name of the data 098 * @param values the value to set 099 */ 100 public default void setValues(String name, String[] values) 101 { 102 setValues(name, values, getDefaultPrefix()); 103 } 104 105 /** 106 * Sets the values of the multiple string data stored in the repository with the given name 107 * @param name name of the data 108 * @param values the value to set 109 * @param prefix prefix of the data name, to use instead of the default one. 110 */ 111 public void setValues(String name, String[] values, String prefix); 112 113 /** 114 * Sets the value of the date data stored in the repository with the given name 115 * @param name name of the data 116 * @param value the value to set 117 */ 118 public default void setValue(String name, Calendar value) 119 { 120 setValue(name, value, getDefaultPrefix()); 121 } 122 123 /** 124 * Sets the value of the date data stored in the repository with the given name 125 * @param name name of the data 126 * @param value the value to set 127 * @param prefix prefix of the data name, to use instead of the default one. 128 */ 129 public void setValue(String name, Calendar value, String prefix); 130 131 /** 132 * Sets the values of the multiple date data stored in the repository with the given name 133 * @param name name of the data 134 * @param values the value to set 135 */ 136 public default void setValues(String name, Calendar[] values) 137 { 138 setValues(name, values, getDefaultPrefix()); 139 } 140 141 /** 142 * Sets the values of the multiple date data stored in the repository with the given name 143 * @param name name of the data 144 * @param values the value to set 145 * @param prefix prefix of the data name, to use instead of the default one. 146 */ 147 public void setValues(String name, Calendar[] values, String prefix); 148 149 /** 150 * Sets the value of the long data stored in the repository with the given name 151 * @param name name of the data 152 * @param value the value to set 153 */ 154 public default void setValue(String name, Long value) 155 { 156 setValue(name, value, getDefaultPrefix()); 157 } 158 159 /** 160 * Sets the value of the long data stored in the repository with the given name 161 * @param name name of the data 162 * @param value the value to set 163 * @param prefix prefix of the data name, to use instead of the default one. 164 */ 165 public void setValue(String name, Long value, String prefix); 166 167 /** 168 * Sets the values of the multiple long data stored in the repository with the given name 169 * @param name name of the data 170 * @param values the value to set 171 */ 172 public default void setValues(String name, Long[] values) 173 { 174 setValues(name, values, getDefaultPrefix()); 175 } 176 177 /** 178 * Sets the values of the multiple long data stored in the repository with the given name 179 * @param name name of the data 180 * @param values the value to set 181 * @param prefix prefix of the data name, to use instead of the default one. 182 */ 183 public void setValues(String name, Long[] values, String prefix); 184 185 /** 186 * Sets the value of the double data stored in the repository with the given name 187 * @param name name of the data 188 * @param value the value to set 189 */ 190 public default void setValue(String name, Double value) 191 { 192 setValue(name, value, getDefaultPrefix()); 193 } 194 195 /** 196 * Sets the value of the double data stored in the repository with the given name 197 * @param name name of the data 198 * @param value the value to set 199 * @param prefix prefix of the data name, to use instead of the default one. 200 */ 201 public void setValue(String name, Double value, String prefix); 202 203 /** 204 * Sets the values of the multiple double data stored in the repository with the given name 205 * @param name name of the data 206 * @param values the value to set 207 */ 208 public default void setValues(String name, Double[] values) 209 { 210 setValues(name, values, getDefaultPrefix()); 211 } 212 213 /** 214 * Sets the values of the multiple double data stored in the repository with the given name 215 * @param name name of the data 216 * @param values the value to set 217 * @param prefix prefix of the data name, to use instead of the default one. 218 */ 219 public void setValues(String name, Double[] values, String prefix); 220 221 /** 222 * Sets the value of the boolean data stored in the repository with the given name 223 * @param name name of the data 224 * @param value the value to set 225 */ 226 public default void setValue(String name, Boolean value) 227 { 228 setValue(name, value, getDefaultPrefix()); 229 } 230 231 /** 232 * Sets the value of the boolean data stored in the repository with the given name 233 * @param name name of the data 234 * @param value the value to set 235 * @param prefix prefix of the data name, to use instead of the default one. 236 */ 237 public void setValue(String name, Boolean value, String prefix); 238 239 /** 240 * Sets the values of the multiple boolean data stored in the repository with the given name 241 * @param name name of the data 242 * @param values the value to set 243 */ 244 public default void setValues(String name, Boolean[] values) 245 { 246 setValues(name, values, getDefaultPrefix()); 247 } 248 249 /** 250 * Sets the values of the multiple boolean data stored in the repository with the given name 251 * @param name name of the data 252 * @param values the value to set 253 * @param prefix prefix of the data name, to use instead of the default one. 254 */ 255 public void setValues(String name, Boolean[] values, String prefix); 256 257 /** 258 * Sets the value of the input stream data stored in the repository with the given name 259 * @param name name of the data 260 * @param value the value to set 261 */ 262 public default void setValue(String name, InputStream value) 263 { 264 setValue(name, value, getDefaultPrefix()); 265 } 266 267 /** 268 * Sets the value of the input stream data stored in the repository with the given name 269 * @param name name of the data 270 * @param value the value to set 271 * @param prefix prefix of the data name, to use instead of the default one. 272 */ 273 public void setValue(String name, InputStream value, String prefix); 274 275 /** 276 * Sets the values of the multiple input stream data stored in the repository with the given name 277 * @param name name of the data 278 * @param values the value to set 279 */ 280 public default void setValues(String name, InputStream[] values) 281 { 282 setValues(name, values, getDefaultPrefix()); 283 } 284 285 /** 286 * Sets the values of the multiple input stream data stored in the repository with the given name 287 * @param name name of the data 288 * @param values the value to set 289 * @param prefix prefix of the data name, to use instead of the default one. 290 */ 291 public void setValues(String name, InputStream[] values, String prefix); 292 293 /** 294 * Removes the value of the data stored in the repository with the given name 295 * @param name name of the data 296 * @throws UnknownDataException if there is no data stored with the given name 297 */ 298 public default void removeValue(String name) throws UnknownDataException 299 { 300 removeValue(name, getDefaultPrefix()); 301 } 302 303 /** 304 * Removes the value of the data stored in the repository with the given name 305 * @param name name of the data 306 * @param prefix prefix of the data name, to use instead of the default one. 307 * @throws UnknownDataException if there is no data stored with the given name 308 */ 309 public void removeValue(String name, String prefix) throws UnknownDataException; 310}