View Javadoc
1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   */
18  
19  package org.itracker.services;
20  
21  import org.itracker.core.resources.ITrackerResourcesProvider;
22  import org.itracker.model.*;
23  
24  import java.util.List;
25  import java.util.Locale;
26  import java.util.Map;
27  import java.util.Properties;
28  
29  /**
30   * Manages the applications configuration properties.
31   */
32  public interface ConfigurationService extends ITrackerResourcesProvider {
33  
34      public static final String PNAME_SYSTEM_BASE_URL = "system_base_url";
35  
36      /**
37       * Load a configuration from application properties.
38       *
39       * @param name configuration key
40       * @return the value from the configuration
41       */
42      String getProperty(String name);
43      /**
44       * Load a configuration from application properties.
45       *
46       * @param name configuration key
47       * @param defaultValue returned if the value is null
48       * @return the value from the configuration
49       */
50      String getProperty(String name, String defaultValue);
51  
52      /**
53       * Load a configuration from application properties.
54       *
55       * @param name configuration key
56       * @param defaultValue returned if the value is null
57       * @return the boolean value from the configuration
58       */
59      boolean getBooleanProperty(String name, boolean defaultValue);
60      /**
61       * Load a configuration from application properties.
62       *
63       * @param name configuration key
64       * @param defaultValue returned if the value is null
65       * @return the integer value from the configuration
66       */
67      int getIntegerProperty(String name, int defaultValue);
68      /**
69       * Load a configuration from application properties.
70       *
71       * @param name configuration key
72       * @param defaultValue returned if the value is null
73       * @return the long value from the configuration
74       */
75      long getLongProperty(String name, long defaultValue);
76      /**
77       * Load a configuration from database.
78       *
79       * @param id the row identifier
80       * @return the model from the configuration
81       */
82      Configuration getConfigurationItem(Integer id);
83  
84  
85  
86      /**
87       * The JNDI context where the configuration.properties values can be overridden.
88       * @return
89       */
90      String getJndiPropertiesOverridePrefix();
91  
92      void setJndiPropertiesOverridePrefix(String jndiPropertiesOverridePrefix);
93  
94      /**
95       * The JNDI lookup name for the mail-session.
96       * @return
97       */
98      String getMailSessionLookupName();
99  
100     void setMailSessionLookupName(String mailSessionLookupName);
101 
102     /**
103      * Returns all the configuration items of a particular type.  The name values
104      * for all the items will not be initialized.
105      *
106      * @param type the type of configuration items to retrieve
107      * @return an array of ConfigurationModels
108      * @deprecated use getConfigurationItemsByType(Configuration.Type type)
109      */
110     List<Configuration> getConfigurationItemsByType(int type);
111 
112     /**
113      * Returns all the configuration items of a particular type.  The name values
114      * for all the items will not be initialized.
115      *
116      * @param type the type of configuration items to retrieve
117      * @return an array of ConfigurationModels
118      */
119     List<Configuration> getConfigurationItemsByType(Configuration.Type type);
120 
121     /**
122      * Returns all the configuration items of a particular type.  The name values
123      * for all the items will not be initialized.
124      *
125      * @param type the type of configuration items to retrieve
126      * @param locale the locale to use when setting the configuration items name values
127      * @return an array of ConfigurationModels
128      */
129     List<Configuration> getConfigurationItemsByType(Configuration.Type type, Locale locale);
130     /**
131      * Returns all the configuration items of a particular type.  In addition, all
132      * of the configuration items name values will be initialized to the values
133      * for the supplied locale.
134      *
135      * @param type   the type of configuration items to retrieve
136      * @param locale the locale to use when setting the configuration items name values
137      * @return an array of ConfigurationModels
138      * @deprecated use getConfigurationItemsByType(Configuration.Type type, Locale locale)
139      */
140     List<Configuration> getConfigurationItemsByType(int type, Locale locale);
141 
142     /**
143      * Creates a <code>Configuration</code>.
144      *
145      * @param configuration The <code>Configuration</code> to store
146      * @return the <code>Configuration</code> after saving
147      */
148     Configuration createConfigurationItem(Configuration configuration);
149 
150     /**
151      * This method updates a configuration item in the database.
152      * <p>Version will be fixed to current initialized version.</p>
153      *
154      * @param configuration a Configuration of the item to update
155      * @return a Configuration with the updated item
156      */
157     Configuration updateConfigurationItem(Configuration configuration);
158 
159     /**
160      * Updates the configuration items.
161      * <p>Version will be fixed to current initialized version.</p>
162      *
163      * @param configurations the <code>ConfigurationModels</code> to update
164      * @param type           The type of the <code>ConfigurationItem</code>s to update
165      * @return an array with the saved models
166      */
167     List<Configuration> updateConfigurationItems(List<Configuration> configurations, Configuration.Type type);
168 
169     boolean configurationItemExists(Configuration configuration);
170 
171     boolean isConfigurationItemUpToDate(Configuration configuration);
172 
173     /**
174      * This method will remove the configuration item with the supplied id.
175      *
176      * @param id the id of the configuration information to remove
177      */
178     void removeConfigurationItem(Integer id);
179 
180     /**
181      * This method will remove all configuration items that match the supplied type.  This
182      * will remove all items of that type such as all system status values.
183      *
184      * @param type the type of configuration information to remove
185      * @deprecated use removeConfigurationItems(Configuration.Type type)
186      */
187     void removeConfigurationItems(int type);
188 
189     /**
190      * This method will remove all configuration items that match the supplied type.  This
191      * will remove all items of that type such as all system status values.
192      *
193      * @param type the type of configuration information to remove
194      */
195     void removeConfigurationItems(Configuration.Type type);
196 
197     /**
198      * This method will remove all configuration items that match the supplied models
199      * type and value.  This effectively eliminates all previous versions of the item.
200      * It is normally called prior to a create to remove any older copies of this item.
201      *
202      * @param configuration the model to determine the type and value from
203      */
204     void removeConfigurationItems(Configuration configuration);
205 
206     /**
207      * This method will reset any caches in the system of configuration items for all configuration
208      * item types.
209      */
210     void resetConfigurationCache();
211 
212     /**
213      * This method will reset any caches in the system of configuration items for the specified
214      * configuration item type.
215      *
216      * @param type the type of configuration item to reset in any caches
217      * @deprecated use resetConfigurationCache(Configuration.Type type)
218      */
219     void resetConfigurationCache(int type);
220     /**
221      * This method will reset any caches in the system of configuration items for the specified
222      * configuration item type.
223      *
224      * @param type the type of configuration item to reset in any caches
225      */
226     void resetConfigurationCache(Configuration.Type type);
227 
228     /**
229      * This method will return the requested project script.
230      *
231      * @param id the id of the requested script
232      * @return a ProjectScript with the requested script, or null if not found
233      */
234     ProjectScript getProjectScript(Integer id);
235 
236     /**
237      * This method will return all defined project scripts.
238      *
239      * @return a ProjectScript array with all defined scripts
240      */
241     List<ProjectScript> getProjectScripts();
242 
243     /**
244      * This method will create a new project script for persistance in the database.
245      *
246      * @param projectScript the model to create the script from
247      */
248     ProjectScript createProjectScript(ProjectScript projectScript);
249 
250     /**
251      * This method updates a project script in the database.
252      *
253      * @param projectScript a ProjectScript of the item to update
254      * @return a ProjectScript with the updated item
255      */
256     ProjectScript updateProjectScript(ProjectScript projectScript);
257 
258     /**
259      * This method removes a project script in the database.
260      *
261      * @param id The id of the project script
262      */
263     void removeProjectScript(Integer id);
264 
265     /**
266      * This method will return the requested workflow script.
267      *
268      * @param id the id of the requested script
269      * @return a WorkflowScript with the requested script, or null if not found
270      */
271     WorkflowScript getWorkflowScript(Integer id);
272 
273     /**
274      * This method will return all defined workflow scripts.
275      *
276      * @return a WorkflowScript array with all defined scripts
277      */
278     List<WorkflowScript> getWorkflowScripts();
279 
280     /**
281      * This method will create a new workflow script for persistance in the database.
282      *
283      * @param workflowScript the model to create the script from
284      */
285     WorkflowScript createWorkflowScript(WorkflowScript workflowScript);
286 
287     /**
288      * This method updates a workflow script in the database.
289      *
290      * @param workflowScript a WorkflowScript of the item to update
291      * @return a WorkflowScript with the updated item
292      */
293     WorkflowScript updateWorkflowScript(WorkflowScript workflowScript);
294 
295     /**
296      * This method removes a workflow script in the database.
297      *
298      * @param id The id of the workflow script
299      */
300     void removeWorkflowScript(Integer id);
301 
302     /**
303      * This method will return the requested custom field.
304      *
305      * @param id the id of the requested field
306      * @return a CustomField with the requested field, or null if not found
307      */
308     CustomField getCustomField(Integer id);
309 
310     /**
311      * This method will return all the custom fields defined in the system.
312      *
313      * @return an array of CustomFieldModels
314      */
315     List<CustomField> getCustomFields();
316 
317     /**
318      * This method will create a new CustomField for persistance in the database.  If the
319      * field includes a set of option values, those will be created also.
320      *
321      * @param customField the model to create the field from
322      */
323     CustomField createCustomField(CustomField customField);
324 
325     /**
326      * This method updates a custom field in the database.  It does not include any updates
327      * to language items that would be used to display the localized label for the field.
328      * If any options are included, the list will be used to replace any existing options.
329      *
330      * @param customField a CustomField of the item to update
331      * @return a CustomField with the updated item
332      */
333     CustomField updateCustomField(CustomField customField);
334 
335     /**
336      * Removes a single custom field from the database.
337      *
338      * @param customFieldId the id of the custom field to remove
339      */
340     boolean removeCustomField(Integer customFieldId);
341 
342     /**
343      * This method will return the requested custom field value.
344      *
345      * @param id the id of the requested field value
346      * @return a CustomField with the requested field value, or null if not found
347      */
348     CustomFieldValue getCustomFieldValue(Integer id);
349 
350     /**
351      * This method will create a new CustomFieldValue for persistance in the database.
352      *
353      * @param customFieldValue the model to create the field from
354      */
355     CustomFieldValue createCustomFieldValue(CustomFieldValue customFieldValue);
356 
357     /**
358      * This method updates a custom field value in the database.  It does not include any updates
359      * to language items that would be used to display the localized label for the field value.
360      *
361      * @param customFieldValue a CustomFieldValue of the item to update
362      * @return a CustomFieldValue with the updated item
363      */
364     CustomFieldValue updateCustomFieldValue(CustomFieldValue customFieldValue);
365 
366     /**
367      * This method updates a set of custom field values in the database.  If the array of values
368      * is null or zero length, it will remove all existing values from the custom field.  Otherwise
369      * it will update the value and sort order of all the values.  If the array of models contains
370      * more or less values than the current custom field, it will not remove theose values, or create
371      * new values.
372      *
373      * @param customFieldId the id of the custom field to update
374      * @param customFieldValues        an array of CustomFieldValueModels to update
375      * @return a array of CustomFieldValueModels with the updated items
376      */
377     List<CustomFieldValue> updateCustomFieldValues(Integer customFieldId,
378                                                    List<CustomFieldValue> customFieldValues);
379 
380     /**
381      * Removes a single custom field value from the database.
382      *
383      * @param customFieldValueId the id of the custom field value to remove
384      */
385     boolean removeCustomFieldValue(Integer customFieldValueId);
386 
387     /**
388      * Removes all custom field values from the database for a single custom field.
389      *
390      * @param customFieldId the id of the custom field to remove the values for
391      */
392     boolean removeCustomFieldValues(Integer customFieldId);
393 
394     /**
395      * This method will return the translation for a particular key in a locale.
396      *
397      * @param key    the key to look up
398      * @param locale the localue to translate the key for
399      * @return a Language with the translation
400      */
401     Language getLanguageItemByKey(String key, Locale locale);
402 
403     /**
404      * This method will return all the translations for a particular key.
405      *
406      * @param key the key to look up
407      * @return an array of LanguageModels with the translations for the key
408      */
409     List<Language> getLanguageItemsByKey(String key);
410 
411     /**
412      * Updates a translations for a particular key and locale.
413      *
414      * @param language A Language for the key to update
415      * @return a Language with the updated translation
416      */
417     Language updateLanguageItem(Language language);
418 
419     /**
420      * This method will remove all language items with the supplied key regardless
421      * of locale.
422      *
423      * @param key the key to remove
424      */
425     boolean removeLanguageKey(String key);
426 
427     void removeLanguageItem(Language language);
428 
429     /**
430      * This method will return the current configuration of the system.
431      *
432      * @return a SystemConfiguration with the current configuration of the system
433      */
434     SystemConfiguration getSystemConfiguration(Locale locale);
435 
436     /**
437      * Returns all of the keys currently defined in the base locale sorted and grouped in a
438      * logical manner.
439      */
440     String[] getSortedKeys();
441 
442     Map<String, String> getDefinedKeys(String locale);
443 
444     List<NameValuePair> getDefinedKeysAsArray(String locale);
445 
446     int getNumberDefinedKeys(String locale);
447 
448     Map<String, List<String>> getAvailableLanguages();
449 
450     int getNumberAvailableLanguages();
451 
452 
453     Properties getLanguageProperties(Locale locale);
454 
455     void updateLanguage(Locale locale, List<Language> languages);
456 
457     void updateLanguage(Locale locale, List<Language> languages, Configuration config);
458 
459     /**
460      * This method will load the specified locale.  It will look for the appropriate properties file,
461      * and then load all of the resources into the database.
462      *
463      * @param locale      the locale to load
464      * @param forceReload if true, it will reload the languages from the property file even if it is listed
465      *                    as being up to date
466      */
467     boolean initializeLocale(String locale, boolean forceReload);
468 
469     /**
470      * This method will load the some default system configuration data into the database.  The values
471      * it loads are determined from the base ITracker.properties file so the language initialization
472      * <b>must</b> be performed before this method is called.
473      */
474     void initializeConfiguration();
475 
476     String getSystemBaseURL();
477 
478     String getLanguageValue(String key, Locale locale);
479 
480     /**
481      * This method will attempt to load all of the locales defined in the
482      * ITracker.properties file, and add them to the database if they don't
483      * already exist.
484      *
485      * @param forceReload          if true, it will reload the languages from the property files
486      *                             even if they are listed as being up to date
487      */
488     void initializeAllLanguages(boolean forceReload);
489 }