View Javadoc
1   package fr.ifremer.reefdb.config;
2   
3   /*
4    * #%L
5    * Reef DB :: Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import com.google.common.base.Splitter;
27  import com.google.common.collect.Lists;
28  import fr.ifremer.common.synchro.config.SynchroConfigurationOption;
29  import fr.ifremer.quadrige3.core.config.QuadrigeConfigurationOption;
30  import fr.ifremer.quadrige3.core.config.QuadrigeConfigurations;
31  import fr.ifremer.quadrige3.core.config.QuadrigeCoreConfiguration;
32  import fr.ifremer.quadrige3.core.config.QuadrigeCoreConfigurationOption;
33  import fr.ifremer.quadrige3.core.dao.technical.hibernate.DateType;
34  import org.apache.commons.collections4.CollectionUtils;
35  import org.apache.commons.lang3.StringUtils;
36  import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
37  import org.apache.commons.logging.Log;
38  import org.apache.commons.logging.LogFactory;
39  import org.nuiton.config.ApplicationConfig;
40  import org.nuiton.config.ConfigOptionDef;
41  import org.nuiton.version.Version;
42  
43  import javax.swing.KeyStroke;
44  import java.awt.Color;
45  import java.io.File;
46  import java.net.URL;
47  import java.util.*;
48  
49  import static org.nuiton.i18n.I18n.t;
50  
51  /**
52   * ReefDb Configuration
53   *
54   * @author Lionel Touseau <lionel.touseau@e-is.pro>
55   */
56  public final class ReefDbConfiguration extends QuadrigeCoreConfiguration {
57  
58      /**
59       * Logger.
60       */
61      private static final Log LOG = LogFactory.getLog(ReefDbConfiguration.class);
62      /**
63       * Singleton pattern
64       */
65      private static ReefDbConfiguration instance;
66  
67      /**
68       * <p>Constructor for ReefDbConfiguration.</p>
69       *
70       * @param applicationConfig a {@link org.nuiton.config.ApplicationConfig} object.
71       */
72      public ReefDbConfiguration(ApplicationConfig applicationConfig) {
73          super(applicationConfig);
74      }
75  
76      /**
77       * <p>Constructor for ReefDbConfiguration.</p>
78       *
79       * @param file a {@link java.lang.String} object.
80       * @param args a {@link java.lang.String} object.
81       */
82      public ReefDbConfiguration(String file, String... args) {
83          super(file, args);
84  
85          // Verify base directory
86          File reefdbBasedir = getBaseDirectory();
87          if (reefdbBasedir == null) {
88              reefdbBasedir = new File("");
89          }
90          if (!reefdbBasedir.isAbsolute()) {
91              reefdbBasedir = new File(reefdbBasedir.getAbsolutePath());
92          }
93          if ("..".equals(reefdbBasedir.getName())) {
94              reefdbBasedir = reefdbBasedir.getParentFile().getParentFile();
95          }
96          if (".".equals(reefdbBasedir.getName())) {
97              reefdbBasedir = reefdbBasedir.getParentFile();
98          }
99          if (LOG.isInfoEnabled()) {
100             LOG.info("Application basedir: " + reefdbBasedir);
101         }
102         applicationConfig.setOption(
103                 ReefDbConfigurationOption.BASEDIR.getKey(),
104                 reefdbBasedir.getAbsolutePath());
105 
106         // Init timezone (see mantis Allegro-ObsDeb #24623)
107         initTimeZone();
108     }
109 
110     /**
111      * <p>Getter for the field <code>instance</code>.</p>
112      *
113      * @return a {@link fr.ifremer.reefdb.config.ReefDbConfiguration} object.
114      */
115     public static ReefDbConfiguration getInstance() {
116         return instance;
117     }
118 
119     /**
120      * <p>Setter for the field <code>instance</code>.</p>
121      *
122      * @param instance a {@link fr.ifremer.reefdb.config.ReefDbConfiguration} object.
123      */
124     public static void setInstance(ReefDbConfiguration instance) {
125         ReefDbConfiguration.instance = instance;
126         QuadrigeCoreConfiguration.setInstance(instance);
127     }
128 
129     /**
130      * <p>overrideExternalModulesDefaultOptions.</p>
131      */
132     protected void overrideExternalModulesDefaultOptions() {
133         super.overrideExternalModulesDefaultOptions();
134 
135         // Override quadrige3 BASE_DIRECTORY
136         applicationConfig.setDefaultOption(
137                 QuadrigeConfigurationOption.BASEDIR.getKey(),
138                 String.format("${%s}", ReefDbConfigurationOption.BASEDIR.getKey()));
139 
140         // Override Sites
141         applicationConfig.setDefaultOption(
142                 QuadrigeConfigurationOption.SITE_URL.getKey(),
143                 String.format("${%s}", ReefDbConfigurationOption.SITE_URL.getKey()));
144         // Remap :
145         //  - quadrige3.update.XXX to reefdb.update.XXX
146         //  - quadrige3.install.XXX to reefdb.install.XXX
147         //  - quadrige3.authentication.XXX to reefdb.authentication.XXX
148         QuadrigeConfigurations.remapOptionsToPrefix(applicationConfig,
149                 "quadrige3.update",
150                 ReefDbConfigurationOption.values(),
151                 "reefdb.update");
152         QuadrigeConfigurations.remapOptionsToPrefix(applicationConfig,
153                 "quadrige3.install",
154                 ReefDbConfigurationOption.values(),
155                 "reefdb.install");
156         QuadrigeConfigurations.remapOptionsToPrefix(applicationConfig,
157                 "quadrige3.authentication",
158                 ReefDbConfigurationOption.values(),
159                 "reefdb.authentication");
160 
161         // Override Hibernate queries file
162         applicationConfig.setDefaultOption(
163                 QuadrigeConfigurationOption.HIBERNATE_CLIENT_QUERIES_FILE.getKey(),
164                 "reefdb-queries.hbm.xml");
165 
166         // Override enumeration files
167         applicationConfig.setDefaultOption(
168                 QuadrigeConfigurationOption.DB_ENUMERATION_RESOURCE.getKey(),
169                 String.format("${%s}", ReefDbConfigurationOption.DB_ENUMERATION_RESOURCE.getKey()));
170 
171         // Override Db timezone
172         applicationConfig.setDefaultOption(
173                 QuadrigeConfigurationOption.DB_TIMEZONE.getKey(),
174                 String.format("${%s}", ReefDbConfigurationOption.DB_TIMEZONE.getKey()));
175         applicationConfig.setDefaultOption(
176                 SynchroConfigurationOption.DB_TIMEZONE.getKey(),
177                 String.format("${%s}", ReefDbConfigurationOption.DB_TIMEZONE.getKey()));
178 
179         // Override ALL synchronization options
180         QuadrigeConfigurations.remapOptionsToPrefix(applicationConfig,
181                 "synchro",
182                 ReefDbConfigurationOption.values(),
183                 "reefdb.synchro");
184         QuadrigeConfigurations.remapOptionsToPrefix(applicationConfig,
185                 "quadrige3.synchro",
186                 ReefDbConfigurationOption.values(),
187                 "reefdb.synchro");
188 
189         remapOptionsForBackwardCompatibility();
190     }
191 
192     /**
193      * remap (add) property from older reefdb version < 3.0.0
194      */
195     private void remapOptionsForBackwardCompatibility() {
196 
197         // authentication options
198         restoreOldOptions(QuadrigeCoreConfigurationOption.values(), "quadrige3.authentication", "reefdb.authentication");
199         restoreOldOptions(QuadrigeCoreConfigurationOption.values(), "quadrige3.authentication", "quadrige2.authentication");
200 
201         // update options
202         restoreOldOptions(QuadrigeCoreConfigurationOption.values(), "quadrige3.update", "reefdb.update");
203         restoreOldOptions(QuadrigeCoreConfigurationOption.values(), "quadrige3.install", "reefdb.install");
204 
205         // synchronization options
206         restoreOldOptions(QuadrigeConfigurationOption.values(), "quadrige3.synchronization", "reefdb.synchronization");
207         restoreOldOptions(QuadrigeConfigurationOption.values(), "quadrige3.synchro", "quadrige2.synchro");
208 
209         // manage enumeration
210         restoreOldOptions("quadrige3.enumeration", "quadrige2.enumeration");
211     }
212 
213     private void restoreOldOptions(ConfigOptionDef[] optionDefs,
214                                    String newKeyPrefix,
215                                    String oldKeyPrefix) {
216 
217         for (ConfigOptionDef optionDef: optionDefs) {
218             String newProperty = optionDef.getKey();
219 
220             // If prefix match
221             if (newProperty.startsWith(newKeyPrefix)) {
222                 String endPart = newProperty.substring(newKeyPrefix.length());
223                 String oldProperty = oldKeyPrefix + endPart;
224 
225                 // This property could be copy
226                 if (applicationConfig.hasOption(oldProperty)) {
227                     applicationConfig.setOption(newProperty, applicationConfig.getOption(oldProperty));
228                 }
229             }
230         }
231     }
232 
233     private void restoreOldOptions(String newKeyPrefix,
234                                    String oldKeyPrefix) {
235 
236         Properties oldProperties = applicationConfig.getOptionStartsWith(oldKeyPrefix);
237         if (oldProperties != null) {
238             for (String oldKey: oldProperties.stringPropertyNames()) {
239 
240                 String endPart = oldKey.substring(oldKeyPrefix.length());
241                 String newProperty = newKeyPrefix + endPart;
242 
243                 // override this new property if not already exists
244                 if (!applicationConfig.hasOption(newProperty)) {
245                     applicationConfig.setOption(newProperty, oldProperties.getProperty(oldKey));
246                 }
247 
248                 // delete this old property from file
249                 addOptionToNotSave(oldKey);
250             }
251         }
252     }
253 
254     /** {@inheritDoc} */
255     @Override
256     public String getApplicationName() {
257         return t("reefdb.application.name");
258     }
259 
260     /** {@inheritDoc} */
261     @Override
262     public Version getVersion() {
263         return applicationConfig.getOptionAsVersion(ReefDbConfigurationOption.VERSION.getKey());
264     }
265 
266     /** {@inheritDoc} */
267     @Override
268     public KeyStroke getShortcutClosePopup() {
269         return applicationConfig.getOptionAsKeyStroke(ReefDbConfigurationOption.SHORTCUT_CLOSE_POPUP.getKey());
270     }
271 
272     /**
273      * <p>getHelpResourceWithLocale.</p>
274      *
275      * @param value a {@link String} object.
276      * @return a {@link String} object.
277      */
278     public String getHelpResourceWithLocale(String value) {
279         File directory = new File(getHelpDirectory(),
280                 getI18nLocale().getLanguage());
281         File result = new File(directory, value);
282         return result.toString();
283     }
284 
285     /**
286      * Initialization default timezone, from configuration (mantis #24623)
287      */
288     private void initTimeZone() {
289 
290         String timeZone = applicationConfig.getOption(ReefDbConfigurationOption.TIMEZONE.getKey());
291         if (StringUtils.isNotBlank(timeZone)) {
292             if (LOG.isInfoEnabled()) {
293                 LOG.info(String.format("Using timezone [%s]", timeZone));
294             }
295             TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
296             System.setProperty("user.timezone", timeZone);
297         } else if (LOG.isInfoEnabled()) {
298             LOG.info(String.format("Using default timezone [%s]", System.getProperty("user.timezone")));
299         }
300 
301         // Warn only and use user timezone if reefdb.persistence.db.timezone is not set (Mantis #46461)
302         String dbTimeZoneOption = applicationConfig.getOption(ReefDbConfigurationOption.DB_TIMEZONE.getKey());
303         TimeZone dbTimeZone;
304         if (StringUtils.isBlank(dbTimeZoneOption)) {
305             LOG.warn("Timezone for database is not set in configuration, now using user timezone");
306             dbTimeZone = TimeZone.getDefault();
307         } else {
308             dbTimeZone = TimeZone.getTimeZone(dbTimeZoneOption);
309         }
310         if (LOG.isInfoEnabled()) {
311             LOG.info(String.format("Using timezone [%s] for database", dbTimeZone.toZoneId()));
312         }
313         DateType.setTimeZone(dbTimeZone);
314     }
315 
316     /** {@inheritDoc} */
317     @Override
318     public String toString() {
319         return ReflectionToStringBuilder.toString(this);
320     }
321 
322     /**
323      * <p>getLastObservationId.</p>
324      *
325      * @return a {@link Integer} object.
326      */
327     public Integer getLastObservationId() {
328         return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.LAST_OBSERVATION_ID.getKey());
329     }
330 
331     /**
332      * <p>setLastObservationId.</p>
333      *
334      * @param observationId a {@link Integer} object.
335      */
336     public void setLastObservationId(Integer observationId) {
337         String value = "";
338         if (observationId != null) {
339             value = observationId.toString();
340         }
341         applicationConfig.setOption(ReefDbConfigurationOption.LAST_OBSERVATION_ID.getKey(), value);
342     }
343 
344     /**
345      * <p>getLastContextId.</p>
346      *
347      * @return a {@link Integer} object.
348      */
349     public Integer getLastContextId() {
350         int lastContextId = applicationConfig.getOptionAsInt(ReefDbConfigurationOption.LAST_CONTEXT_ID.getKey());
351         return lastContextId == 0 ? null : lastContextId;
352     }
353 
354     /**
355      * <p>setLastContextId.</p>
356      *
357      * @param contextId a {@link Integer} object.
358      */
359     public void setLastContextId(Integer contextId) {
360         String value = "";
361         if (contextId != null) {
362             value = contextId.toString();
363         }
364         applicationConfig.setOption(ReefDbConfigurationOption.LAST_CONTEXT_ID.getKey(), value);
365     }
366 
367     //------------------------------------------------------------------------//
368     //--- DB-related ---------------------------------------------------------//
369     //------------------------------------------------------------------------//
370 
371     /**
372      * <p>getDbBackupExternalDirectory.</p>
373      *
374      * @return a {@link File} object.
375      */
376     public File getDbBackupExternalDirectory() {
377         return applicationConfig.getOptionAsFile(ReefDbConfigurationOption.DB_BACKUP_EXTERNAL_DIRECTORY.getKey());
378     }
379 
380     /**
381      * <p>isDbCheckConstantsEnable.</p>
382      *
383      * @return a boolean.
384      */
385     public boolean isDbCheckConstantsEnable() {
386         return applicationConfig.getOptionAsBoolean(ReefDbConfigurationOption.DB_CHECK_CONSTANTS.getKey());
387     }
388 
389     /**
390      * <p>setDbCheckConstantsEnable.</p>
391      *
392      * @param check a boolean.
393      */
394     public void setDbCheckConstantsEnable(boolean check) {
395         applicationConfig.setOption(ReefDbConfigurationOption.DB_CHECK_CONSTANTS.getKey(), Boolean.toString(check));
396     }
397 
398     /**
399      * <p>getDbDirectory.</p>
400      *
401      * @return a {@link File} object.
402      */
403     public TimeZone getDbTimezone() {
404         String timezone = applicationConfig.getOption(ReefDbConfigurationOption.DB_TIMEZONE.getKey());
405         return StringUtils.isNotBlank(timezone) ? TimeZone.getTimeZone(timezone) : TimeZone.getDefault();
406     }
407 
408     public int getMassiveProcessChunkSize() {
409         return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.DB_VALIDATION_BULK_SIZE.getKey());
410     }
411 
412     /**
413      * <p>isCacheEnabledAtStartup.</p>
414      *
415      * @return a boolean.
416      */
417     public boolean isCacheEnabledAtStartup() {
418         return applicationConfig.getOptionAsBoolean(ReefDbConfigurationOption.CACHE_ENABLED_AT_STARTUP.getKey());
419     }
420 
421     /**
422      * <p>isCleanCacheAtStartup.</p>
423      *
424      * @return a boolean.
425      */
426     public boolean isCleanCacheAtStartup() {
427         return applicationConfig.getOptionAsBoolean(ReefDbConfigurationOption.CACHE_CLEAN_AT_STARTUP.getKey());
428     }
429 
430     /**
431      * <p>getSiteUrl.</p>
432      *
433      * @return {@link fr.ifremer.reefdb.config.ReefDbConfigurationOption#SITE_URL} value
434      */
435     public URL getSiteUrl() {
436         return applicationConfig.getOptionAsURL(ReefDbConfigurationOption.SITE_URL.getKey());
437     }
438 
439     /**
440      * <p>getOrganizationName.</p>
441      *
442      * @return {@link fr.ifremer.reefdb.config.ReefDbConfigurationOption#ORGANIZATION_NAME} value
443      */
444     public String getOrganizationName() {
445         return applicationConfig.getOption(ReefDbConfigurationOption.ORGANIZATION_NAME.getKey());
446     }
447 
448     /**
449      * <p>getInceptionYear.</p>
450      *
451      * @return {@link fr.ifremer.reefdb.config.ReefDbConfigurationOption#INCEPTION_YEAR} value
452      */
453     public int getInceptionYear() {
454         return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.INCEPTION_YEAR.getKey());
455     }
456 
457 
458     //------------------------------------------------------------------------//
459     //--- extraction-related --------------------------------------------------//
460     //------------------------------------------------------------------------//
461 
462     /**
463      * <p>getExtractionFilePrefix.</p>
464      *
465      * @return a {@link String} object.
466      */
467     public String getExtractionFilePrefix() {
468         return applicationConfig.getOption(ReefDbConfigurationOption.EXTRACTION_FILE_PREFIX.getKey());
469     }
470 
471     /**
472      * <p>getExtractionFileExtension.</p>
473      *
474      * @return a {@link String} object.
475      */
476     public String getExtractionFileExtension() {
477         return applicationConfig.getOption(ReefDbConfigurationOption.EXTRACTION_FILE_EXTENSION.getKey());
478     }
479 
480     /**
481      * <p>getExtractionFileTypeCode.</p>
482      *
483      * @return a {@link String} object.
484      */
485     public String getExtractionFileTypeCode() {
486         return applicationConfig.getOption(ReefDbConfigurationOption.EXTRACTION_FILE_TYPE_CODE.getKey());
487     }
488 
489     /**
490      * <p>getExtractionGroupTypePmfmCode.</p>
491      *
492      * @return a {@link String} object.
493      */
494     public String getExtractionGroupTypePmfmCode() {
495         return applicationConfig.getOption(ReefDbConfigurationOption.EXTRACTION_GROUP_TYPE_PMFM_CODE.getKey());
496     }
497 
498     /**
499      * <p>getExtractionTableTypeCode.</p>
500      *
501      * @return a {@link String} object.
502      */
503     public String getExtractionTableTypeCode() {
504         return applicationConfig.getOption(ReefDbConfigurationOption.EXTRACTION_TABLE_TYPE_CODE.getKey());
505     }
506 
507     /**
508      * <p>getExtractionProjectionSystemCode.</p>
509      *
510      * @return a {@link String} object.
511      */
512     public String getExtractionProjectionSystemCode() {
513         return applicationConfig.getOption(ReefDbConfigurationOption.EXTRACTION_PROJECTION_SYSTEM_CODE.getKey());
514     }
515 
516     /**
517      * <p>getExtractionDefaultOrderItemTypeCode.</p>
518      *
519      * @return a {@link String} object.
520      */
521     public String getExtractionDefaultOrderItemTypeCode() {
522         return applicationConfig.getOption(ReefDbConfigurationOption.EXTRACTION_DEFAULT_ORDER_ITEM_TYPE_CODE.getKey());
523     }
524 
525     /**
526      * <p>getExtractionUnitIdsToIgnore.</p>
527      *
528      * @return a {@link List} object.
529      */
530     public List<Integer> getExtractionUnitIdsToIgnore() {
531         List<Integer> ids = Lists.newArrayList();
532         String excludeUnitIds = applicationConfig.getOption(ReefDbConfigurationOption.EXTRACTION_IGNORE_UNIT_IDS.getKey())    ;
533         for (String id : Splitter.on(',').omitEmptyStrings().trimResults().splitToList(excludeUnitIds)) {
534             if (StringUtils.isNumeric(id)) {
535                 ids.add(Integer.valueOf(id));
536             }
537         }
538         return ids;
539     }
540 
541     //------------------------------------------------------------------------//
542     //--- UI-related ---------------------------------------------------------//
543     //------------------------------------------------------------------------//
544 
545     /**
546      * <p>getUIConfigFile.</p>
547      *
548      * @return {@link fr.ifremer.reefdb.config.ReefDbConfigurationOption#UI_CONFIG_FILE} value
549      */
550     public File getUIConfigFile() {
551         return applicationConfig.getOptionAsFile(ReefDbConfigurationOption.UI_CONFIG_FILE.getKey());
552     }
553 
554     /**
555      * <p>getUIRecommendedWidth.</p>
556      *
557      * @return a {@link Integer} object.
558      */
559     public Integer getUIRecommendedWidth() {
560         return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.UI_RECOMMENDED_WIDTH.getKey());
561     }
562 
563     /**
564      * <p>getUIRecommendedHeight.</p>
565      *
566      * @return a {@link Integer} object.
567      */
568     public Integer getUIRecommendedHeight() {
569         return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.UI_RECOMMENDED_HEIGHT.getKey());
570     }
571 
572     /**
573      * <p>isShowTableCheckbox.</p>
574      *
575      * @return {@link fr.ifremer.reefdb.config.ReefDbConfigurationOption#TABLES_CHECKBOX} value
576      */
577     public boolean isShowTableCheckbox() {
578         return applicationConfig.getOptionAsBoolean(ReefDbConfigurationOption.TABLES_CHECKBOX.getKey());
579     }
580 
581     /**
582      * <p>isAutoPopupNumberEditor.</p>
583      *
584      * @return a boolean.
585      */
586     public boolean isAutoPopupNumberEditor() {
587         return applicationConfig.getOptionAsBoolean(ReefDbConfigurationOption.AUTO_POPUP_NUMBER_EDITOR.getKey());
588     }
589 
590     /**
591      * <p>isShowNumberEditorButton.</p>
592      *
593      * @return a boolean.
594      */
595     public boolean isShowNumberEditorButton() {
596         return applicationConfig.getOptionAsBoolean(ReefDbConfigurationOption.SHOW_NUMBER_EDITOR_BUTTON.getKey());
597     }
598 
599     /**
600      * <p>getColorSelectedCell.</p>
601      *
602      * @return a {@link Color} object.
603      */
604     public Color getColorSelectedCell() {
605         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_SELECTED_CELL.getKey());
606     }
607 
608     /**
609      * <p>getColorRowInvalid.</p>
610      *
611      * @return a {@link Color} object.
612      */
613     public Color getColorRowInvalid() {
614         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_ROW_INVALID.getKey());
615     }
616 
617     /**
618      * <p>getColorRowReadOnly.</p>
619      *
620      * @return a {@link Color} object.
621      */
622     public Color getColorRowReadOnly() {
623         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_ROW_READ_ONLY.getKey());
624     }
625 
626     /**
627      * <p>getColorCellWithValue.</p>
628      *
629      * @return a {@link Color} object.
630      */
631     public Color getColorCellWithValue() {
632         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_CELL_WITH_VALUE.getKey());
633     }
634 
635     /**
636      * <p>getColorComputedWeights.</p>
637      *
638      * @return a {@link Color} object.
639      */
640     public Color getColorComputedWeights() {
641         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_COMPUTED_WEIGHTS.getKey());
642     }
643 
644     /**
645      * <p>getColorComputedRow.</p>
646      *
647      * @return a {@link Color} object.
648      */
649     public Color getColorComputedRow() {
650         // same color as COLOR_COMPUTED_WEIGHTS
651         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_COMPUTED_WEIGHTS.getKey());
652     }
653 
654     /**
655      * <p>getColorBlockingLayer.</p>
656      *
657      * @return a {@link Color} object.
658      */
659     public Color getColorBlockingLayer() {
660         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_BLOCKING_LAYER.getKey());
661     }
662 
663     /**
664      * <p>getColorAlternateRow.</p>
665      *
666      * @return a {@link Color} object.
667      */
668     public Color getColorAlternateRow() {
669         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_ALTERNATE_ROW.getKey());
670     }
671 
672     /**
673      * <p>getColorSelectedRow.</p>
674      *
675      * @return a {@link Color} object.
676      */
677     public Color getColorSelectedRow() {
678         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_SELECTED_ROW.getKey());
679     }
680 
681     /**
682      * <p>getColorSelectionPanelBackground.</p>
683      *
684      * @return a {@link Color} object.
685      */
686     public Color getColorSelectionPanelBackground() {
687         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_SELECTION_PANEL_BACKGROUND.getKey());
688     }
689 
690     /**
691      * <p>getColorContextPanelBackground.</p>
692      *
693      * @return a {@link Color} object.
694      */
695     public Color getColorContextPanelBackground() {
696         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_CONTEXT_PANEL_BACKGROUND.getKey());
697     }
698 
699     /**
700      * <p>getColorEditionPanelBackground.</p>
701      *
702      * @return a {@link Color} object.
703      */
704     public Color getColorEditionPanelBackground() {
705         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_EDITION_PANEL_BACKGROUND.getKey());
706     }
707 
708     /**
709      * <p>getColorEditionPanelBorder.</p>
710      *
711      * @return a {@link Color} object.
712      */
713     public Color getColorEditionPanelBorder() {
714         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_EDITION_PANEL_BORDER.getKey());
715     }
716 
717     /**
718      * <p>getColorThematicLabel.</p>
719      *
720      * @return a {@link Color} object.
721      */
722     public Color getColorThematicLabel() {
723         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_THEMATIC_LABEL.getKey());
724     }
725 
726     /**
727      * <p>getColorHighlightButtonBorder.</p>
728      *
729      * @return a {@link Color} object.
730      */
731     public Color getColorHighlightButtonBorder() {
732         return applicationConfig.getOptionAsColor(ReefDbConfigurationOption.COLOR_HIGHLIGHT_BUTTON_BORDER.getKey());
733     }
734 
735     /**
736      * <p>getShortCut.</p>
737      *
738      * @param actionName a {@link String} object.
739      * @return a {@link KeyStroke} object.
740      */
741     public KeyStroke getShortCut(String actionName) {
742         return applicationConfig.getOptionAsKeyStroke("reefdb.ui." + actionName);
743     }
744 
745     /**
746      * <p>getDateFormat.</p>
747      *
748      * @return a {@link String} object.
749      */
750     public String getDateFormat() {
751         return applicationConfig.getOption(ReefDbConfigurationOption.DATE_FORMAT.getKey());
752     }
753 
754     /**
755      * <p>getDateTimeFormat.</p>
756      *
757      * @return a {@link String} object.
758      */
759     public String getDateTimeFormat() {
760         return applicationConfig.getOption(ReefDbConfigurationOption.DATE_TIME_FORMAT.getKey());
761     }
762 
763     /*
764      ----  File and Directory methods ---
765      */
766     /**
767      * <p>getNewTmpDirectory.</p>
768      *
769      * @param name a {@link String} object.
770      * @return a {@link File} object.
771      */
772     public File getNewTmpDirectory(String name) {
773         return new File(getTempDirectory(), name + "_" + System.nanoTime());
774     }
775 
776 
777     /**
778      * <p>getHelpDirectory.</p>
779      *
780      * @return a {@link File} object.
781      */
782     public File getHelpDirectory() {
783         return applicationConfig.getOptionAsFile(
784                 ReefDbConfigurationOption.HELP_DIRECTORY.getKey());
785     }
786 
787     /**
788      * <p>getUnknownRecorderDepartmentId.</p>
789      *
790      * @return a int.
791      */
792     public int getUnknownRecorderDepartmentId() {
793         return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.UNKNOWN_RECORDER_DEPARTMENT.getKey());
794     }
795 
796     // TODO les methodes suivantes sont-elles toujours utiles ?
797     /**
798      * <p>getTemporaryStatusCode.</p>
799      *
800      * @return a {@link String} object.
801      */
802     public String getTemporaryStatusCode() {
803         return "TEMPORARY";
804     }
805 
806     /**
807      * <p>getEnableStatusCode.</p>
808      *
809      * @return a {@link String} object.
810      */
811     public String getEnableStatusCode() {
812         return "ENABLE";
813     }
814 
815     /**
816      * <p>getDisableStatusCode.</p>
817      *
818      * @return a {@link String} object.
819      */
820     public String getDisableStatusCode() {
821         return "DISABLE";
822     }
823 
824     /**
825      * <p>getDeletedStatusCode.</p>
826      *
827      * @return a {@link String} object.
828      */
829     public String getDeletedStatusCode() {
830         return "DELETED";
831     }
832 
833     /**
834      * <p>getDirtySynchronizationStatusCode.</p>
835      *
836      * @return a {@link String} object.
837      */
838     public String getDirtySynchronizationStatusCode() {
839         return "DIRTY";
840     }
841 
842     /**
843      * <p>getReadySynchronizationStatusCode.</p>
844      *
845      * @return a {@link String} object.
846      */
847     public String getReadySynchronizationStatusCode() {
848         return "READY_TO_SYNCHRONIZE";
849     }
850 
851     /**
852      * <p>getSynchronizedSynchronizationStatusCode.</p>
853      *
854      * @return a {@link String} object.
855      */
856     public String getSynchronizedSynchronizationStatusCode() {
857         return "SYNCHRONIZED";
858     }
859 
860     /**
861      * Constants
862      *
863      * @return a int.
864      */
865     public int getDepthValuesPmfmId() {
866         return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.PMFM_ID_DEPTH_VALUES.getKey());
867     }
868 
869     /**
870      * <p>getTransitionLengthPmfmId.</p>
871      *
872      * @return a int.
873      */
874     @Deprecated
875     public int getTransitionLengthPmfmId() {
876 //        return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.PMFM_ID_TRANSITION_LENGTH.getKey());
877         return 0;
878     }
879 
880     /**
881      * <p>getStartPositionPmfmId.</p>
882      *
883      * @return a int.
884      */
885     @Deprecated
886     public int getStartPositionPmfmId() {
887 //        return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.PMFM_ID_START_POSITION.getKey());
888         return 0;
889     }
890 
891     /**
892      * <p>getEndPositionPmfmId.</p>
893      *
894      * @return a int.
895      */
896     @Deprecated
897     public int getEndPositionPmfmId() {
898 //        return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.PMFM_ID_END_POSITION.getKey());
899         return 0;
900     }
901 
902     public List<Integer[]> getCalculatedTransitionLengthPmfmTriplets() {
903 
904         List<Integer[]> result = new ArrayList<>();
905         String configOption = applicationConfig.getOption(ReefDbConfigurationOption.PMFM_IDS_TRANSITION_LENGTH.getKey());
906         if (StringUtils.isBlank(configOption)) return result;
907 
908         List<String> triplets = Splitter.on(";").omitEmptyStrings().splitToList(configOption);
909         for (String triplet : triplets) {
910             List<String> pmfmsIdsStr = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(triplet);
911             if (CollectionUtils.size(pmfmsIdsStr) == 3) {
912                 try {
913                     Integer[] pmfmIds = new Integer[3];
914                     pmfmIds[0] = Integer.parseInt(pmfmsIdsStr.get(0));
915                     pmfmIds[1] = Integer.parseInt(pmfmsIdsStr.get(1));
916                     pmfmIds[2] = Integer.parseInt(pmfmsIdsStr.get(2));
917 
918                     if (pmfmIds[0] < 0 || pmfmIds[1] < 0 || pmfmIds[2] < 0) continue;
919 
920                     result.add(pmfmIds);
921                 } catch (NumberFormatException e) {
922                     LOG.warn(String.format("Problem parsing '%s' option value : %s", ReefDbConfigurationOption.PMFM_IDS_TRANSITION_LENGTH.getKey(), triplet));
923                 }
924             } else {
925                 LOG.warn(String.format("Malformed '%s' option value : %s", ReefDbConfigurationOption.PMFM_IDS_TRANSITION_LENGTH.getKey(), triplet));
926             }
927         }
928 
929         return result;
930     }
931 
932     public int getPitTransitionPmfmId() {
933         return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.PMFM_ID_PIT_TRANSITION.getKey());
934     }
935 
936     public int getPitTransectLengthPmfmId() {
937         return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.PMFM_ID_PIT_TRANSECT_LENGTH.getKey());
938     }
939 
940     public int getPitOriginPmfmId() {
941         return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.PMFM_ID_PIT_ORIGIN.getKey());
942     }
943 
944     public Integer getPitTransectLengthDefaultValue() {
945         return (Integer) applicationConfig.getOption(ReefDbConfigurationOption.PIT_TRANSECT_LENGTH_DEFAULT_VALUE);
946     }
947 
948     public Integer getPitOriginDefaultValue() {
949         return (Integer) applicationConfig.getOption(ReefDbConfigurationOption.PIT_ORIGIN_DEFAULT_VALUE);
950     }
951 
952     /**
953      * <p>getNoUnitId.</p>
954      *
955      * @return a int.
956      */
957     public int getNoUnitId() {
958         return applicationConfig.getOptionAsInt(ReefDbConfigurationOption.UNIT_ID_NO_UNIT.getKey());
959     }
960 
961     /**
962      * <p>getTranscribingItemTypeLbForPmfmNm.</p>
963      *
964      * @return a {@link String} object.
965      */
966     public String getTranscribingItemTypeLbForPmfmNm() {
967         return applicationConfig.getOption(ReefDbConfigurationOption.TRANSCRIBING_ITEM_TYPE_LB_PMFM_NM.getKey());
968     }
969 
970     public String getTranscribingItemTypeLbForPmfmExtraction() {
971         return applicationConfig.getOption(ReefDbConfigurationOption.TRANSCRIBING_ITEM_TYPE_LB_PMFM_EXTRACTION.getKey());
972     }
973 
974     /**
975      * <p>getAlternativeTaxonOriginTaxRef.</p>
976      *
977      * @return a {@link String} object.
978      */
979     public String getAlternativeTaxonOriginTaxRef() {
980         return applicationConfig.getOption(ReefDbConfigurationOption.ALTERNATIVE_TAXON_ORIGIN_TAXREF.getKey());
981     }
982 
983     /**
984      * <p>getAlternativeTaxonOriginWorms.</p>
985      *
986      * @return a {@link String} object.
987      */
988     public String getAlternativeTaxonOriginWorms() {
989         return applicationConfig.getOption(ReefDbConfigurationOption.ALTERNATIVE_TAXON_ORIGIN_WORMS.getKey());
990     }
991 
992     public String getAlternativeTaxonOriginPAMPA() {
993         return applicationConfig.getOption(ReefDbConfigurationOption.ALTERNATIVE_TAXON_ORIGIN_PAMPA.getKey());
994     }
995 
996 }