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 java.util.List;
22  import java.util.Locale;
23  import java.util.Map;
24  import java.util.Properties;
25  
26  import org.itracker.model.Configuration;
27  import org.itracker.model.CustomField;
28  import org.itracker.model.CustomFieldValue;
29  import org.itracker.model.Language;
30  import org.itracker.model.NameValuePair;
31  import org.itracker.model.ProjectScript;
32  import org.itracker.model.SystemConfiguration;
33  import org.itracker.model.WorkflowScript;
34  import org.itracker.services.util.CustomFieldUtilities;
35  
36  /**
37   * Manages the applications configuration properties.
38   */
39  public interface ConfigurationService {
40      
41  	public static final String PNAME_SYSTEM_BASE_URL = "system_base_url";
42  	
43      Properties getProperties();
44  
45      String getProperty(String name);
46      
47      String getProperty(String name, String defaultValue);
48      
49      boolean getBooleanProperty(String name, boolean defaultValue);
50      
51      int getIntegerProperty(String name, int defaultValue);
52      
53      long getLongProperty(String name, long defaultValue);
54  
55      Configuration getConfigurationItem(Integer id);
56      
57      /**
58        * Returns all the configuration items of a particular type.  The name values
59        * for all the items will not be initialized.
60        * @param type the type of configuration items to retrieve
61        * @return an array of ConfigurationModels
62        */
63      List<Configuration> getConfigurationItemsByType(int type);
64      
65      /**
66        * Returns all the configuration items of a particular type.  In addition, all
67        * of the configuration items name values will be initialized to the values
68        * for the supplied locale.
69        * @param type the type of configuration items to retrieve
70        * @param locale the locale to use when setting the configuration items name values
71        * @return an array of ConfigurationModels
72        */   
73      List<Configuration> getConfigurationItemsByType(int type, Locale locale);
74  
75      /**
76        * This method will create a new Configuration for persistance in the database.
77        * @param model the model to create the bean from
78        * @returns and updated model with the information from the newly created bean
79        */
80      Configuration createConfigurationItem(Configuration configuration);
81   
82      /**
83        * This method updates a configuration item in the database.  It does not include any updates
84        * to language items that would be used to display the localized value of the item.
85        * @param model a Configuration of the item to update
86        * @return a Configuration with the updated item
87        */
88      Configuration updateConfigurationItem(Configuration configuration);
89      
90      List<Configuration> updateConfigurationItems(List<Configuration> configurations, int type);
91  
92      boolean configurationItemExists(Configuration configuration);
93      
94      boolean configurationItemUpToDate(Configuration configuration);
95  
96      /**
97        * This method will remove the configuration item with the supplied id.
98        * @param id the id of the configuration information to remove
99        */
100     void removeConfigurationItem(Integer id);
101  
102     /**
103       * This method will remove all configuration items that match the supplied type.  This
104       * will remove all items of that type such as all system status values.
105       * @param type the type of configuration information to remove
106       */
107     void removeConfigurationItems(int type);
108  
109     /**
110       * This method will remove all configuration items that match the supplied models
111       * type and value.  This effectively eliminates all previous versions of the item.
112       * It is normally called prior to a create to remove any older copies of this item.
113       * @param model the model to determine the type and value from
114       */
115     void removeConfigurationItems(Configuration configuration);
116 
117     /**
118       * This method will reset any caches in the system of configuration items for all configuration
119       * item types.
120       */
121     void resetConfigurationCache();
122  
123     /**
124       * This method will reset any caches in the system of configuration items for the specified
125       * configuration item type.
126       * @param type the type of configuration item to reset in any caches
127       */
128     void resetConfigurationCache(int type);
129 
130     /**
131       * This method will return the requested project script.
132       * @param id the id of the requested script
133       * @return a ProjectScript with the requested script, or null if not found
134       */
135     ProjectScript getProjectScript(Integer id);
136     
137     /**
138       * This method will return all defined project scripts.
139       * @return a ProjectScript array with all defined scripts
140       */
141     List<ProjectScript> getProjectScripts();
142     
143     /**
144       * This method will create a new project script for persistance in the database.
145       * @param model the model to create the script from
146       * @returns and updated model with the information from the newly created script
147       */
148     ProjectScript createProjectScript(ProjectScript projectScript);
149     
150     /**
151       * This method updates a project script in the database.
152       * @param model a ProjectScript of the item to update
153       * @return a ProjectScript with the updated item
154       */
155     ProjectScript updateProjectScript(ProjectScript projectScript);
156     
157     /**
158       * This method removes a project script in the database.
159       * @param id  The id of the project script
160       */
161     void removeProjectScript(Integer id);
162 
163     /**
164       * This method will return the requested workflow script.
165       * @param id the id of the requested script
166       * @return a WorkflowScript with the requested script, or null if not found
167       */
168     WorkflowScript getWorkflowScript(Integer id);
169     
170     /**
171       * This method will return all defined workflow scripts.
172       * @return a WorkflowScript array with all defined scripts
173       */
174     List<WorkflowScript> getWorkflowScripts();
175     
176     /**
177       * This method will create a new workflow script for persistance in the database.
178       * @param model the model to create the script from
179       * @returns and updated model with the information from the newly created script
180       */
181     WorkflowScript createWorkflowScript(WorkflowScript workflowScript);
182     
183     /**
184       * This method updates a workflow script in the database.
185       * @param model a WorkflowScript of the item to update
186       * @return a WorkflowScript with the updated item
187       */
188     WorkflowScript updateWorkflowScript(WorkflowScript workflowScript);
189     
190     /**
191       * This method removes a workflow script in the database.
192       * @param id  The id of the workflow script
193       */
194     void removeWorkflowScript(Integer id);
195 
196     /**
197       * This method will return the requested custom field.
198       * @param id the id of the requested field
199       * @return a CustomField with the requested field, or null if not found
200       */
201     CustomField getCustomField(Integer id);
202 
203     /**
204       * This method will return all the custom fields defined in the system.
205       * @return an array of CustomFieldModels
206       */
207     List<CustomField> getCustomFields();
208     
209     /**
210       * This method will return all the custom fields defined in the system.  It will
211       * also initialize all of the field labels using the supplied locale.
212       * @param locale the locale to use to initialize the labels
213       * @return an array of CustomFieldModels
214       * @deprecated use {@link CustomFieldUtilities} to retrieve localization to custom fields
215       */
216     List<CustomField> getCustomFields(Locale locale);
217     
218     /**
219       * This method will create a new CustomField for persistance in the database.  If the
220       * field includes a set of option values, those will be created also.
221       * @param model the model to create the field from
222       * @returns and updated model with the information from the newly created field
223       */
224     CustomField createCustomField(CustomField customField);
225     
226     /**
227       * This method updates a custom field in the database.  It does not include any updates
228       * to language items that would be used to display the localized label for the field.
229       * If any options are included, the list will be used to replace any existing options.
230       * @param model a CustomField of the item to update
231       * @return a CustomField with the updated item
232       */
233     CustomField updateCustomField(CustomField customField);
234     
235     /**
236       * Removes a single custom field from the database.
237       * @param customFieldValueId the id of the custom field to remove
238       */
239     boolean removeCustomField(Integer customFieldId);
240     
241     /**
242       * This method will return the requested custom field value.
243       * @param id the id of the requested field value
244       * @return a CustomField with the requested field value, or null if not found
245       */
246     CustomFieldValue getCustomFieldValue(Integer id);
247     
248     /**
249       * This method will create a new CustomFieldValue for persistance in the database.
250       * @param model the model to create the field from
251       * @returns and updated model with the information from the newly created field
252       */
253     CustomFieldValue createCustomFieldValue(CustomFieldValue customFieldValue);
254     
255     /**
256       * This method updates a custom field value in the database.  It does not include any updates
257       * to language items that would be used to display the localized label for the field value.
258       * @param model a CustomFieldValue of the item to update
259       * @return a CustomFieldValue with the updated item
260       */
261     CustomFieldValue updateCustomFieldValue(CustomFieldValue customFieldValue);
262     
263     /**
264       * This method updates a set of custom field values in the database.  If the array of values
265       * is null or zero length, it will remove all existing values from the custom field.  Otherwise
266       * it will update the value and sort order of all the values.  If the array of models contains
267       * more or less values than the current custom field, it will not remove theose values, or create
268       * new values.
269       * @param customFieldId the id of the custom field to update
270       * @param models an array of CustomFieldValueModels to update
271       * @return a array of CustomFieldValueModels with the updated items
272       */
273     List<CustomFieldValue> updateCustomFieldValues(Integer customFieldId, 
274             List<CustomFieldValue> customFieldValues);
275     
276     /**
277       * Removes a single custom field value from the database.
278       * @param customFieldValueId the id of the custom field value to remove
279       */
280     boolean removeCustomFieldValue(Integer customFieldValueId);
281     
282     /**
283       * Removes all custom field values from the database for a single custom field.
284       * @param customFieldId the id of the custom field to remove the values for
285       */
286     boolean removeCustomFieldValues(Integer customFieldId);
287     
288     /**
289       * This method will return the translation for a particular key in a locale.
290       * @param key the key to look up
291       * @param locale the localue to translate the key for
292       * @return a Language with the translation
293       */
294     Language getLanguageItemByKey(String key, Locale locale);
295     
296     /**
297       * This method will return all the translations for a particular key.
298       * @param key the key to look up
299       * @return an array of LanguageModels with the translations for the key
300       */
301     List<Language> getLanguageItemsByKey(String key);
302     
303     /**
304       * Updates a translations for a particular key and locale.
305       * @param model A Language for the key to update
306       * @return a Language with the updated translation
307       */
308     Language updateLanguageItem(Language language);
309     
310     /**
311       * This method will remove all language items with the supplied key regardless
312       * of locale.
313       * @param key the key to remove
314       */
315     boolean removeLanguageKey(String key);
316     
317     void removeLanguageItem(Language language);
318 
319     /**
320       * This method will return the current configuration of the system.
321       * @return a SystemConfiguration with the current configuration of the system
322       */
323     SystemConfiguration getSystemConfiguration(Locale locale);
324 
325     /**
326       * Returns all of the keys currently defined in the base locale sorted and grouped in a
327       * logical manner.
328       */
329     String[] getSortedKeys();
330 
331     Map<String,String> getDefinedKeys(String locale);
332     
333     List<NameValuePair> getDefinedKeysAsArray(String locale);
334     
335     int getNumberDefinedKeys(String locale);
336     
337     Map<String,List<String>> getAvailableLanguages();
338     
339     int getNumberAvailableLanguages();
340     
341     /**
342      * returns languages for the locale as list of Language-objects
343      * 
344      * @param locale
345      * @return
346      */
347     List<Language> getLanguage(Locale locale);
348     
349     void updateLanguage(Locale locale, List<Language> languages);
350     
351     void updateLanguage(Locale locale, List<Language> languages, Configuration config);
352 
353     /**
354       * This method will load the specified locale.  It will look for the appropriate properties file,
355       * and then load all of the resources into the database.
356       * @param locale the locale to load
357       * @param forceReload if true, it will reload the languages from the property file even if it is listed
358       *                    as being up to date
359       */
360     boolean initializeLocale(String locale, boolean forceReload);
361 
362     /**
363       * This method will load the some default system configuration data into the database.  The values
364       * it loads are determined from the base ITracker.properties file so the language intiialization
365       * <b>must</b> be performed before this method is called.
366       */
367     void initializeConfiguration();
368     
369     String getSystemBaseURL();
370     
371 }