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