adapt preferenceCache for same predicate but different subject
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / PreferencesUtil.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.preference;
11
12 import java.io.File;
13 import java.io.FileInputStream;
14 import java.io.FileOutputStream;
15 import java.io.IOException;
16 import java.net.URI;
17 import java.net.URISyntaxException;
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Properties;
25 import java.util.StringTokenizer;
26 import java.util.UUID;
27
28 import org.apache.commons.lang.StringUtils;
29 import org.apache.log4j.Logger;
30 import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
31 import org.eclipse.jface.preference.IPreferenceStore;
32 import org.eclipse.jface.window.Window;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Control;
35 import org.eclipse.swt.widgets.Shell;
36 import org.eclipse.ui.PlatformUI;
37
38 import eu.etaxonomy.cdm.api.application.ICdmRepository;
39 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator;
40 import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
41 import eu.etaxonomy.cdm.api.service.ITermService;
42 import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
43 import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
44 import eu.etaxonomy.cdm.common.CdmUtils;
45 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
46 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
47 import eu.etaxonomy.cdm.model.common.ICdmBase;
48 import eu.etaxonomy.cdm.model.common.Language;
49 import eu.etaxonomy.cdm.model.common.MarkerType;
50 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
51 import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
52 import eu.etaxonomy.cdm.model.metadata.IPreferencePredicate;
53 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
54 import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
55 import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum;
56 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
57 import eu.etaxonomy.cdm.model.term.FeatureTree;
58 import eu.etaxonomy.cdm.model.term.IDefinedTerm;
59 import eu.etaxonomy.cdm.model.term.ISimpleTerm;
60 import eu.etaxonomy.cdm.model.term.TermBase;
61 import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
62 import eu.etaxonomy.cdm.strategy.match.FieldMatcher;
63 import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
64 import eu.etaxonomy.cdm.strategy.match.MatchException;
65 import eu.etaxonomy.cdm.strategy.match.MatchMode;
66 import eu.etaxonomy.taxeditor.model.AbstractUtility;
67 import eu.etaxonomy.taxeditor.model.MessagingUtils;
68 import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
69 import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
70 import eu.etaxonomy.taxeditor.store.CdmStore;
71 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
72 import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog;
73
74 /**
75 * <p>
76 * PreferencesUtil class.
77 * </p>
78 *
79 * @author p.ciardelli
80 * @author n.hoffmann
81 * @created 05.12.2008
82 */
83 public class PreferencesUtil implements IPreferenceKeys {
84
85 /**
86 *
87 */
88 public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
89
90 public static final String P2_REPOSITORIES_DELIM = ",";
91 public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
92
93 private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
94
95
96
97
98
99 /**
100 * <p>
101 * getPreferenceStore
102 * </p>
103 *
104 * @return a {@link org.eclipse.jface.preference.IPreferenceStore} object.
105 */
106 public static IPreferenceStore getPreferenceStore() {
107 return TaxeditorStorePlugin.getDefault().getPreferenceStore();
108 }
109
110 static String prefKey(String name) {
111 return name + "_"+ ((CdmRemoteSource)CdmStore.getActiveCdmSource()).toString();
112 }
113
114 public static String prefOverrideKey(String name) {
115 return name + "_OVERRIDE_";
116 }
117
118 /**
119 * <p>
120 * setStringValue
121 * </p>
122 *
123 *
124 **/
125 public static void setStringValue(String name, String value) {
126 if (value != null){
127 getPreferenceStore().setValue(prefKey(name), value);
128 }else{
129 getPreferenceStore().setToDefault(name);
130 }
131 }
132
133 /**
134 * <p>
135 * setIntValue
136 * </p>
137 *
138 *
139 **/
140 public static void setIntValue(String name, int value) {
141 getPreferenceStore().setValue(prefKey(name), value);
142 }
143
144 /**
145 * <p>
146 * setBooleanValue
147 * </p>
148 *
149 *
150 **/
151 public static void setBooleanValue(String name, boolean value) {
152 getPreferenceStore().setValue(prefKey(name), value);
153 }
154
155 /**
156 * <p>
157 * setBooleanValue
158 * </p>
159 *
160 *
161 **/
162 public static void setDoubleValue(String name, double value) {
163 getPreferenceStore().setValue(prefKey(name), value);
164 }
165
166 /**
167 * <p>
168 * setFloatValue
169 * </p>
170 *
171 *
172 **/
173 public static void setFloatValue(String name, float value) {
174 getPreferenceStore().setValue(prefKey(name), value);
175 }
176
177 /**
178 * <p>
179 * setFloatValue
180 * </p>
181 *
182 *
183 **/
184 public static void setLongValue(String name, long value) {
185 getPreferenceStore().setValue(prefKey(name), value);
186 }
187
188 /**
189 * <p>
190 * getStringValue
191 * </p>
192 *
193 *
194 **/
195 public static String getStringValue(String name, boolean local) {
196
197 CdmPreference pref = getDBPreferenceValue(name);
198 String prefValue = null;
199 String overrideKey = createPreferenceString(createOverridePreferenceString(name));
200 boolean override = true;
201 if (getPreferenceStore().contains(overrideKey)){
202 override = getPreferenceStore().getBoolean(overrideKey);
203 }
204 if (local || pref == null || (pref != null && pref.isAllowOverride() && override)){
205 String dbSpecific = prefKey(name);
206 if (getPreferenceStore().contains(dbSpecific)){
207 prefValue = getPreferenceStore().getString(dbSpecific);
208 }else{
209 prefValue = getPreferenceStore().
210 getString(name);
211 }
212 }else if (pref != null){
213 prefValue = pref.getValue();
214 }
215 return prefValue;
216
217 }
218
219 public static String getStringValue(String name){
220 return getStringValue(name, false);
221 }
222
223 private static CdmPreference getDBPreferenceValue(String name) {
224 CdmPreferenceCache cache = CdmPreferenceCache.instance();
225 CdmPreference result = null;
226 List<CdmPreference> prefs = null;
227 //
228 prefs = cache.get(name);
229 if (prefs == null ){
230 //get default value for Predicate
231 IPreferencePredicate pred = PreferencePredicate.getByKey(name);
232 if (pred != null){
233 if (pred.getDefaultValue() != null){
234 result = CdmPreference.NewTaxEditorInstance(pred, pred.getDefaultValue().toString());
235 }else{
236 result = CdmPreference.NewTaxEditorInstance(pred, null);
237 }
238 result.setAllowOverride(true);
239 }
240 }else{
241 if (prefs.size() == 1){
242 result = prefs.get(0);
243 }else{
244 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.getByKey(name));
245 result = cache.findBestMatching(key);
246
247 }
248 }
249 return result;
250 }
251
252 /**
253 * <p>
254 * setIntValue
255 * </p>
256 *
257 *
258 **/
259 public static int getIntValue(String name) {
260 CdmPreference pref= getDBPreferenceValue(name);
261 String prefValue = null;
262 if (pref != null){
263 prefValue = pref.getValue();
264 }
265 Integer result = null;
266 try{
267 result = Integer.parseInt(prefValue);
268 }catch(NumberFormatException e){
269 logger.debug("Preference value of " + name + " is not a number");
270 }
271 if (result == null){
272 String dbSpecific = prefKey(name);
273 if (getPreferenceStore().contains(dbSpecific)){
274 result = getPreferenceStore().getInt(dbSpecific);
275 }else{
276 result = getPreferenceStore().
277 getInt(name);
278 }
279 }
280 return result;
281
282
283 }
284
285 public static boolean getBooleanValue(String name) {
286 return getBooleanValue(name, false);
287 }
288
289 /**
290 * <p>
291 * getBooleanValue
292 * </p>
293 *
294 *
295 **/
296 public static boolean getBooleanValue(String name, boolean local) {
297 if (CdmStore.isActive()){
298 CdmPreference pref = getDBPreferenceValue(name);
299 String prefValue = null;
300 if (pref == null || local){
301 String dbSpecific = prefKey(name);
302 if (getPreferenceStore().contains(dbSpecific)){
303 return getPreferenceStore().getBoolean(dbSpecific);
304 }else{
305 return getPreferenceStore().
306 getBoolean(name);
307 }
308 }else{
309 return Boolean.valueOf(pref.getValue());
310 }
311
312 }else{
313 return getPreferenceStore().getBoolean(name);
314 }
315
316 }
317
318 /**
319 * <p>
320 * setBooleanValue
321 * </p>
322 *
323 *
324 **/
325 public static double getDoubleValue(String name) {
326 CdmPreference pref = getDBPreferenceValue(name);
327 String prefValue = null;
328 if (pref != null){
329 prefValue = pref.getValue();
330 }
331 Double result = null;
332 try{
333 result = Double.parseDouble(prefValue);
334 }catch(NumberFormatException e){
335 logger.debug("Preference value of " + name + " is not a number");
336 }
337 if (result == null){
338 String dbSpecific = prefKey(name);
339 if (getPreferenceStore().contains(dbSpecific)){
340 result = getPreferenceStore().getDouble(dbSpecific);
341 }else{
342 result = getPreferenceStore().
343 getDouble(name);
344 }
345 }
346 return result;
347
348 }
349
350 /**
351 * <p>
352 * getFloatValue
353 * </p>
354 *
355 *
356 **/
357 public static float getFloatValue(String name) {
358 CdmPreference pref = getDBPreferenceValue(name);
359 String prefValue = null;
360 if (pref != null){
361 prefValue = pref.getValue();
362 }
363 Float result = null;
364 try{
365 result = Float.parseFloat(prefValue);
366 }catch(NumberFormatException e){
367 logger.debug("Preference value of " + name + " is not a number");
368 }
369 if (result == null){
370 String dbSpecific = prefKey(name);
371 if (getPreferenceStore().contains(dbSpecific)){
372 result = getPreferenceStore().getFloat(dbSpecific);
373 }else{
374 result = getPreferenceStore().
375 getFloat(name);
376 }
377 }
378 return result;
379
380 }
381
382 /**
383 * <p>
384 * getLongValue
385 * </p>
386 *
387 *
388 **/
389 public static long getLongValue(String name) {
390 CdmPreference pref = getDBPreferenceValue(name);
391 String prefValue = null;
392 if (pref != null){
393 prefValue = pref.getValue();
394 }
395 Long result = null;
396 try{
397 result = Long.parseLong(prefValue);
398 }catch(NumberFormatException e){
399 logger.debug("Preference value of " + name + " is not a number");
400 }
401 if (result == null){
402 String dbSpecific = prefKey(name);
403 if (getPreferenceStore().contains(dbSpecific)){
404 result = getPreferenceStore().getLong(dbSpecific);
405 }else{
406 result = getPreferenceStore().
407 getLong(name);
408 }
409 }
410 return result;
411 }
412
413
414 /**
415 * <p>
416 * setPreferredNomenclaturalCode
417 * </p>
418 *
419 * @param preferredCode
420 * a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
421 * object.
422 */
423 public static CdmPreference setPreferredNomenclaturalCode(
424 String preferenceValue, boolean local) {
425 if (local){
426 setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
427 preferenceValue);
428 }
429 else{
430 ICdmRepository controller;
431 controller = CdmStore.getCurrentApplicationConfiguration();
432 if (controller == null){
433 return null;
434 }
435 PrefKey key = null;
436 try{
437 key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
438 }catch (Exception e){
439 System.out.println(e.getStackTrace());
440 }
441 CdmPreference preference = null;
442
443 if (preferenceValue == null){
444 preference = controller.getPreferenceService().find(key);
445 if (preference == null){
446 return null;
447 } else{
448 setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
449 preference.getValue());
450
451 return preference;
452 }
453 } else{
454 preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferenceValue);
455 controller.getPreferenceService().set(preference);
456
457 }
458 }
459 return null;
460
461
462
463 }
464
465 /**
466 * <p>
467 * setPreferredNomenclaturalCode
468 * </p>
469 *
470 * @param preferredCode
471 * a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
472 * object.
473 */
474 public static void setPreferredNomenclaturalCode(
475 CdmPreference preference) {
476
477 ICdmRepository controller;
478 controller = CdmStore.getCurrentApplicationConfiguration();
479 if (controller == null){
480 return;
481 }
482 PrefKey key = null;
483 try{
484 key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
485 }catch (Exception e){
486 System.out.println(e.getStackTrace());
487 }
488
489 controller.getPreferenceService().set(preference);
490
491 }
492
493
494
495
496 /**
497 * <p>
498 * getPreferredNomenclaturalCode
499 * </p>
500 *
501 * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
502 */
503 public static NomenclaturalCode getPreferredNomenclaturalCode() {
504
505 CdmPreference pref = getPreferenceFromDB(PreferencePredicate.NomenclaturalCode);
506
507
508 String preferredCode;
509 if(pref == null || (pref.isAllowOverride() && getBooleanValue(prefOverrideKey(PreferencePredicate.NomenclaturalCode.getKey())))){
510 preferredCode = getStringValue(
511 PreferencePredicate.NomenclaturalCode.getKey(), true);
512
513 }else{
514 preferredCode = pref.getValue();
515 }
516 if (StringUtils.isBlank(preferredCode)){
517 preferredCode = getPreferenceKey((NomenclaturalCode)PreferencePredicate.NomenclaturalCode.getDefaultValue());
518 }
519
520 return getPreferredNomenclaturalCode(preferredCode);
521
522 }
523
524 /**
525 * <p>
526 * getPreferredNomenclaturalCode
527 * </p>
528 *
529 * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
530 */
531 public static NomenclaturalCode getPreferredNomenclaturalCode(String preferenceKeyNomenclaturalCode) {
532
533 for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
534 if (getPreferenceKey(code).equals(preferenceKeyNomenclaturalCode)) {
535 return code;
536 }
537 }
538 return null;
539 }
540
541 public static boolean isShowTaxonAssociations(){
542 boolean result = getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey());
543 return result;
544 }
545
546 public static boolean isShowLifeForm(){
547 boolean result = getBooleanValue(PreferencePredicate.ShowLifeForm.getKey());
548 return result;
549 }
550
551 public static boolean isDeterminationOnlyForFieldUnits(){
552 boolean result = getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
553 return result;
554 }
555
556 public static boolean isCollectingAreaInGeneralSection(){
557 boolean result = getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey());
558 return result;
559 }
560
561 public static CdmPreference getPreferenceFromDB(IPreferencePredicate predicate){
562 ICdmRepository controller;
563 CdmPreference pref = null;
564
565 try{
566 if(CdmStore.isActive()){
567 controller = CdmStore.getCurrentApplicationConfiguration();
568 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
569 pref = controller.getPreferenceService().find(key);
570 }
571 }catch(Exception e){
572 e.printStackTrace();
573 }
574
575 return pref;
576
577 }
578
579 public static List<CdmPreference> getPreferencesFromDB(IPreferencePredicate predicate){
580 ICdmRepository controller;
581 List<CdmPreference> prefs = null;
582
583 try{
584 if(CdmStore.isActive()){
585 controller = CdmStore.getCurrentApplicationConfiguration();
586 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), predicate);
587 prefs = controller.getPreferenceService().list(predicate);
588 }
589 }catch(Exception e){
590 e.printStackTrace();
591 }
592
593 return prefs;
594
595 }
596
597 public static CdmPreference getPreferenceFromDB(PrefKey key){
598 ICdmRepository controller;
599 CdmPreference pref = null;
600
601 try{
602 if(CdmStore.isActive()){
603 controller = CdmStore.getCurrentApplicationConfiguration();
604 pref = controller.getPreferenceService().find(key);
605 }
606 }catch(Exception e){
607 e.printStackTrace();
608 }
609
610 return pref;
611
612 }
613
614
615
616 public static void setPreferenceToDB(CdmPreference preference){
617 ICdmRepository controller;
618 try{
619 if(CdmStore.isActive()){
620 controller = CdmStore.getCurrentApplicationConfiguration();
621 controller.getPreferenceService().set(preference);
622 CdmPreferenceCache.instance().put(preference);
623 }
624 }catch(Exception e){
625 e.printStackTrace();
626 }
627
628 }
629
630
631
632 public static String getPreferredDefaultLangugae(){
633 String preferredLanguage = getStringValue(DEFAULT_LANGUAGE_EDITOR);
634 if(StringUtils.isNotEmpty(preferredLanguage) && StringUtils.isNotBlank(preferredLanguage)){
635 return preferredLanguage;
636 }
637 return null;
638 }
639
640 public static boolean isShowMediaPreview(){
641 boolean isShowMediaPreview = getBooleanValue(SHOW_MEDIA_PREVIEW);
642 return isShowMediaPreview;
643 }
644
645 /**
646 * Get the match strategy for the given class that was stored in preferences
647 * or the default strategy if it was not stored in preferences
648 *
649 * @param clazz
650 * a {@link java.lang.Class} object.
651 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
652 */
653 public static IMatchStrategy getMatchStrategy(Class<?> clazz) {
654 String className = clazz.getName();
655 if (getBooleanValue(MATCH_STRATEGY_PREFIX + className)) {
656 IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz);
657
658 //TODO CacheMatchers (or multiple field matchers in future) are missing here
659 for (FieldMatcher fieldMatcher : matchStrategy.getMatching().getFieldMatchers(false)) {
660 String fieldName = fieldMatcher.getPropertyName();
661 String matchModeName = getStringValue(
662 getMatchStrategyFieldName(className, fieldName));
663 MatchMode matchMode = MatchMode.valueOf(matchModeName);
664 try {
665 matchStrategy.setMatchMode(fieldName, matchMode);
666 } catch (MatchException e) {
667 MessagingUtils.error(PreferencesUtil.class, e);
668 throw new RuntimeException(e);
669 }
670 }
671
672 return matchStrategy;
673 }
674 return getDefaultMatchStrategy(clazz);
675 }
676
677 /**
678 * Stores a matchStrategy into the preference store.
679 *
680 * @param matchStrategy
681 * a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy}
682 * object.
683 */
684 public static void setMatchStrategy(IMatchStrategy matchStrategy) {
685 String className = "ANY class"; //FIXME was: matchStrategy.getMatchClass().getName(); seems currently not in use
686 setBooleanValue(MATCH_STRATEGY_PREFIX + className, true);
687
688 List<FieldMatcher> fieldMatchers = matchStrategy.getMatching().getFieldMatchers(false);
689
690 for (FieldMatcher fieldMatcher : fieldMatchers) {
691 String fieldName = fieldMatcher.getPropertyName();
692 setStringValue(
693 getMatchStrategyFieldName(className, fieldName),
694 fieldMatcher.getMatchMode().name());
695 }
696 }
697
698 /**
699 * Helper method to create the preference property for a match field.
700 *
701 * @param className
702 * @param fieldName
703 * @return
704 */
705 private static String getMatchStrategyFieldName(String className,
706 String fieldName) {
707 return MATCH_STRATEGY_PREFIX + className + "." + fieldName;
708 }
709
710 /**
711 * Returns the default match strategy for a given class.
712 *
713 * @param clazz
714 * a {@link java.lang.Class} object.
715 * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object.
716 */
717 public static IMatchStrategy getDefaultMatchStrategy(Class clazz) {
718 return DefaultMatchStrategy.NewInstance(clazz);
719 }
720
721 /**
722 * <p>
723 * getDateFormatPattern
724 * </p>
725 *
726 * @return a {@link java.lang.String} object.
727 */
728 public static String getDateFormatPattern() {
729 // TODO make this configurable in properties
730 String pattern = "Y-M-d H:m";
731 return pattern;
732 }
733
734 /**
735 * <p>
736 * addTermToPreferredTerms
737 * </p>
738 *
739 * @param term
740 * a T object.
741 * @param <T>
742 * a T object.
743 */
744 public static <T extends TermBase> void addTermToPreferredTerms(T term) {
745
746 // VocabularyEnum vocabulary =
747 // VocabularyEnum.getVocabularyEnum(term.getClass());
748 //
749 // getPreferenceStore().setValue(getPreferenceKey(term),
750 // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term));
751 //
752 // firePreferencesChanged(term.getClass());
753 }
754
755 /**
756 * Construct a unique key using the CdmBase object's uuid
757 *
758 * @param cdmBase
759 * @return
760 */
761 private static String getPreferenceKey(ICdmBase cdmBase) {
762 cdmBase = HibernateProxyHelper.deproxy(cdmBase);
763
764 String key = cdmBase.getClass().getName().concat(".")
765 .concat(cdmBase.getUuid().toString());
766 if (key.contains("javassist")) {
767 MessagingUtils.info("proxy");
768 }
769 return key;
770 }
771
772 /**
773 * Construct a unique key using the CdmBase object's uuid
774 *
775 * @param cdmBase
776 * @return
777 */
778 public static String getPreferenceKey(ISimpleTerm simpleTerm) {
779 simpleTerm = HibernateProxyHelper.deproxy(simpleTerm);
780 String key = simpleTerm.getClass().getName().concat(".")
781 .concat(simpleTerm.getUuid().toString());
782 if (key.contains("javassist")) {
783 MessagingUtils.warn(PreferencesUtil.class,
784 "Trying to persist a preference based on a proxy class.");
785 }
786 return key;
787 }
788
789
790
791 /**
792 * Construct a unique key using the CdmBase object's uuid
793 *
794 * @param cdmBase
795 * @return
796 */
797 public static String getPreferenceKey(IDefinedTerm definedTerm) {
798 definedTerm = HibernateProxyHelper.deproxy(definedTerm);
799 String key = definedTerm.getClass().getName().concat(".")
800 .concat(definedTerm.getUuid().toString());
801 if (key.contains("javassist")) {
802 MessagingUtils.warn(PreferencesUtil.class,
803 "Trying to persist a preference based on a proxy class.");
804 }
805 return key;
806 }
807
808 /**
809 * Retrieves search preferences from the preference store
810 *
811 * @return an {@link ITaxonServiceConfigurator} to pass to search methods
812 */
813 public static IFindTaxaAndNamesConfigurator getSearchConfigurator() {
814 IFindTaxaAndNamesConfigurator configurator = initializeSearchConfigurator();
815
816 configurator.setDoTaxa(getBooleanValue(
817 TAXON_SERVICE_CONFIGURATOR_TAXA));
818 configurator.setDoSynonyms(getBooleanValue(
819 TAXON_SERVICE_CONFIGURATOR_SYNONYMS));
820 configurator.setDoNamesWithoutTaxa(getBooleanValue(
821 TAXON_SERVICE_CONFIGURATOR_NAMES));
822 configurator.setDoTaxaByCommonNames(getBooleanValue(
823 TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES));
824 //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getStringValue(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
825
826 return configurator;
827 }
828
829 /**
830 * create new preferences, setting all search options to true
831 *
832 * @return a
833 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
834 * object.
835 */
836 public static IFindTaxaAndNamesConfigurator initializeSearchConfigurator() {
837 IFindTaxaAndNamesConfigurator configurator = FindTaxaAndNamesConfiguratorImpl.NewInstance();
838
839 configurator.setDoTaxa(true);
840 configurator.setDoSynonyms(true);
841 configurator.setDoNamesWithoutTaxa(true);
842 configurator.setDoTaxaByCommonNames(true);
843
844 configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache",
845 "name", "name.$", "relationsFromThisTaxon.$"));
846
847 configurator.setSynonymPropertyPath(Arrays.asList("$", "titleCache",
848 "name", "name.$", "synonyms.relatedTo.*"));
849
850 // DEFAULT VALUES
851 // match mode is a simple like, actually all other match modes are kind
852 // of bogus
853 configurator
854 .setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.ANYWHERE);
855 // we set page number and size here as this should always be unlimited
856 configurator.setPageNumber(0);
857 // TODO currently limit results to 10000
858 configurator.setPageSize(10000);
859 setSearchConfigurator(configurator) ;
860 return configurator;
861 }
862
863 /**
864 * Store search preferences
865 *
866 * @param configurator
867 * a
868 * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator}
869 * object.
870 */
871 public static void setSearchConfigurator(
872 IFindTaxaAndNamesConfigurator configurator) {
873 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA,
874 configurator.isDoTaxa());
875 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
876 configurator.isDoSynonyms());
877 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES,
878 configurator.isDoNamesWithoutTaxa());
879 getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES,
880 configurator.isDoTaxaByCommonNames());
881 }
882
883 /**
884 * <p>
885 * firePreferencesChanged
886 * </p>
887 *
888 * @param clazz
889 * a {@link java.lang.Class} object.
890 */
891 public static void firePreferencesChanged(Class clazz) {
892 getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE,
893 null, clazz);
894 }
895
896 public static String createPreferenceString(String property){
897 return prefKey(property);
898
899 }
900 public static String createOverridePreferenceString(String property){
901 return prefOverrideKey(property);
902
903 }
904
905 /**
906 * Set default values for preferences
907 */
908 public static void setDefaults() {
909 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true);
910 getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS,
911 true);
912 getPreferenceStore().setDefault(createPreferenceString(EDIT_MAP_SERVICE_ACCES_POINT),
913 "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php");
914 //FIXME : changed default for SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
915 getPreferenceStore().setDefault(createPreferenceString(SHOULD_CONNECT_AT_STARTUP), false);
916 getPreferenceStore().setDefault(createPreferenceString(OPENURL_ACCESS_POINT),
917 "http://www.biodiversitylibrary.org/openurl");
918 getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_WIDTH), "1000");
919 getPreferenceStore().setDefault(createPreferenceString(OPENURL_IMAGE_MAX_HEIGHT), "1000");
920 //Distribution Editor:
921 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DistributionEditorActivated.getKey()), Boolean.valueOf(PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString()));
922 // getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString());
923 // getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisplayOfStatus.getKey()), PreferencePredicate.DisplayOfStatus.getDefaultValue().toString());
924
925
926 //Name Details
927 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.NameDetailsView.getKey()), new NameDetailsConfigurator(false).toString());
928
929 //Navigator preferences
930 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.TaxonNodeOrder.getKey()), NavigatorOrderEnum.RankAndNameOrder.getKey());
931
932 getPreferenceStore().setDefault(createPreferenceString(SORT_TAXA_BY_RANK_AND_NAME), true);
933
934 getPreferenceStore().setDefault(createPreferenceString(SHOW_ADVANCED_MEDIA_SECTION), false);
935
936 getPreferenceStore().setDefault(createPreferenceString(SHOW_MEDIA_PREVIEW), false);
937 //override db preferences
938 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey())), false);
939 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey())), true);
940 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.NameDetailsView.getKey())), false);
941 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey())), true);
942 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionStatus.getKey())), true);
943 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaTerms.getKey())), true);
944 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey())), true);
945 getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.CommonNameAreaVocabularies.getKey())), false);
946 getPreferenceStore().setDefault(createPreferenceString(FILTER_COMMON_NAME_REFERENCES), false);
947 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowTaxonNodeWizard.getKey()), Boolean.valueOf(PreferencePredicate.ShowTaxonNodeWizard.getDefaultValue().toString()));
948 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowNamespaceInSource.getKey()), Boolean.valueOf(PreferencePredicate.ShowNamespaceInSource.getDefaultValue().toString()));
949 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowIdInSource.getKey()), Boolean.valueOf(PreferencePredicate.ShowIdInSource.getDefaultValue().toString()));
950 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.DisableMultiClassification.getKey()), Boolean.valueOf(PreferencePredicate.DisableMultiClassification.getDefaultValue().toString()));
951 getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.ShowImportExportMenu.getKey()), Boolean.valueOf(PreferencePredicate.ShowImportExportMenu.getDefaultValue().toString()));
952
953 }
954
955 /**
956 * <p>
957 * checkNomenclaturalCode
958 * </p>
959 */
960 public static void checkNomenclaturalCode() {
961 // First time Editor is opened, no nomenclatural code has been set
962 if (PreferencesUtil.getPreferredNomenclaturalCode() == null) {
963 PreferencesUtil.setPreferredNomenclaturalCode(getPreferenceKey(NomenclaturalCode.ICNAFP), true);
964 }
965
966
967
968 }
969 public static void setNomenclaturalCodePreferences(){
970 ICdmRepository controller;
971 controller = CdmStore.getCurrentApplicationConfiguration();
972 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
973 CdmPreference preference = null;
974 if (controller == null){
975 return ;
976 }
977 preference = controller.getPreferenceService().find(key);
978 if (preference == null){
979 return;
980 }
981 // setBooleanValue(ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY, preference.isAllowOverride());
982
983 int index = StringUtils.lastIndexOf(preference.getValue(), ".");
984 UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
985 NomenclaturalCode preferredCode = NomenclaturalCode.getByUuid(uuid);
986
987 setStringValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
988 getPreferenceKey(preferredCode));
989
990 }
991
992 public static void checkDefaultLanguage(){
993 if(PreferencesUtil.getPreferredDefaultLangugae() == null){
994 Shell shell = AbstractUtility.getShell();
995 int open = new DefaultLanguageDialog(shell).open();
996 if(open == Window.OK){
997 PlatformUI.getWorkbench().restart();
998 }
999 }else{
1000 //TODO:In case of a reinstall, the config.ini will be overwritten
1001 // here you create config.ini with the stored key from preferences
1002 }
1003 }
1004
1005 /**
1006 * <p>
1007 * getMapServiceAccessPoint
1008 * </p>
1009 *
1010 * @return a {@link java.lang.String} object.
1011 */
1012 public static String getMapServiceAccessPoint() {
1013 return getStringValue(EDIT_MAP_SERVICE_ACCES_POINT);
1014 }
1015
1016 /**
1017 * <p>
1018 * shouldConnectAtStartUp
1019 * </p>
1020 *
1021 * @return a boolean.
1022 */
1023 public static boolean shouldConnectAtStartUp() {
1024 //FIXME : force SHOULD_CONNECT_AT_STARTUP to false (ticket 3828) until resolution
1025 //return getBooleanValue(SHOULD_CONNECT_AT_STARTUP);
1026 return false;
1027 }
1028
1029 /**
1030 * <p>
1031 * getDefaultFeatureTreeForTextualDescription
1032 * </p>
1033 *
1034 * @return a {@link eu.etaxonomy.cdm.model.term.FeatureTree} object.
1035 */
1036 public static FeatureTree getDefaultFeatureTreeForTextualDescription() {
1037 String uuidString = getStringValue(
1038 FEATURE_TREE_DEFAULT_TEXT);
1039 if (StringUtils.isBlank(uuidString)) {
1040 return null;
1041 }
1042 FeatureTree tree = CdmStore.getService(
1043 IFeatureTreeService.class).load(UUID.fromString(uuidString));
1044 if (tree.getId() == 0) {
1045 return null;
1046 }
1047 return tree;
1048 }
1049
1050 /**
1051 * <p>
1052 * getDefaultFeatureTreeForStructuredDescription
1053 * </p>
1054 *
1055 * @return a {@link eu.etaxonomy.cdm.model.term.FeatureTree} object.
1056 */
1057 public static FeatureTree getDefaultFeatureTreeForStructuredDescription() {
1058 String uuidString = getStringValue(
1059 FEATURE_TREE_DEFAULT_STRUCTURE);
1060 return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(
1061 IFeatureTreeService.class).load(UUID.fromString(uuidString));
1062 }
1063
1064 /**
1065 * <p>
1066 * setSortRanksHierarchichally
1067 * </p>
1068 *
1069 * @param selection
1070 * a boolean.
1071 */
1072 public static void setSortRanksHierarchichally(boolean selection) {
1073 setBooleanValue(SORT_RANKS_HIERARCHICHALLY, selection);
1074 }
1075
1076 /**
1077 * <p>
1078 * getSortRanksHierarchichally
1079 * </p>
1080 *
1081 * @return a boolean.
1082 */
1083 public static boolean getSortRanksHierarchichally() {
1084 return getBooleanValue(SORT_RANKS_HIERARCHICHALLY);
1085 }
1086
1087 public static boolean isMultilanguageTextEditingCapability() {
1088 return getBooleanValue(
1089 MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
1090 }
1091
1092 public static Language getGlobalLanguage() {
1093
1094
1095 String languageUuidString = getStringValue(
1096 GLOBAL_LANGUAGE_UUID);
1097
1098 if(!CdmStore.isActive()) {
1099 MessagingUtils.noDataSourceWarningDialog(languageUuidString);
1100 return null;
1101 }
1102
1103 if (CdmUtils.isBlank(languageUuidString)) {
1104 return Language.getDefaultLanguage();
1105 }
1106
1107 UUID languageUuid = UUID.fromString(languageUuidString);
1108 return (Language) CdmStore.getService(ITermService.class).load(
1109 languageUuid);
1110 }
1111
1112 public static void setGlobalLanguage(Language language) {
1113 if(language != null) {
1114 setStringValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
1115 CdmStore.setDefaultLanguage(language);
1116 }
1117
1118 }
1119
1120 /**
1121 * @return
1122 */
1123 public static Map<MarkerType, Boolean> getEditMarkerTypePreferences() {
1124 List<MarkerType> markerTypes = CdmStore.getTermManager()
1125 .getPreferredTerms(MarkerType.class);
1126
1127 Map<MarkerType, Boolean> result = new HashMap<MarkerType, Boolean>();
1128
1129 for (MarkerType markerType : markerTypes) {
1130 String name = getMarkerTypeEditingPreferenceKey(markerType);
1131 Boolean value = getBooleanValue(name);
1132
1133 result.put(markerType, value);
1134 }
1135
1136 return result;
1137 }
1138
1139 /**
1140 * @param markerTypeEditingMap
1141 */
1142 public static void setEditMarkerTypePreferences(
1143 Map<MarkerType, Boolean> markerTypeEditingMap) {
1144 for (MarkerType markerType : markerTypeEditingMap.keySet()) {
1145 String name = getMarkerTypeEditingPreferenceKey(markerType);
1146 setBooleanValue(name,
1147 markerTypeEditingMap.get(markerType));
1148 }
1149
1150 }
1151
1152 private static String getMarkerTypeEditingPreferenceKey(
1153 MarkerType markerType) {
1154 markerType = HibernateProxyHelper.deproxy(markerType);
1155 return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX;
1156 }
1157
1158 /**
1159 * <p>
1160 * setEditMarkerTypePreference
1161 * </p>
1162 *
1163 * @param input
1164 * a {@link org.eclipse.ui.IEditorInput} object.
1165 * @param markerType
1166 * a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
1167 * @param edit
1168 * a boolean.
1169 */
1170 public static void setEditMarkerTypePreference(MarkerType markerType,
1171 boolean edit) {
1172 setBooleanValue(
1173 getMarkerTypeEditingPreferenceKey(markerType), edit);
1174 }
1175
1176 /**
1177 * @return
1178 */
1179 public static DerivedUnitFacadeConfigurator getDerivedUnitConfigurator() {
1180 DerivedUnitFacadeConfigurator configurator = DerivedUnitFacadeConfigurator
1181 .NewInstance();
1182 configurator.setMoveDerivedUnitMediaToGallery(true);
1183 configurator.setMoveFieldObjectMediaToGallery(true);
1184 return configurator;
1185 }
1186
1187 /**
1188 * This method will write language properties to the config.ini located in the configuration folder
1189 * of the Taxonomic Ediitor. <b>This method is only used to set the default language for Taxonomic Editor.</b>
1190 *
1191 * @param setLanguage 0 is for german and 1 for english.
1192 * @throws IOException
1193 */
1194 public void writePropertyToConfigFile(int setLanguage) throws IOException {
1195 File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile();
1196 //give warning to user if the directory has no write access
1197 if(file == null){
1198 throw new IOException();
1199 }
1200 Properties properties = load(file.getAbsolutePath()+"/config.ini");
1201 switch(setLanguage){
1202 case 0:
1203 properties.setProperty("osgi.nl", "de");
1204 setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "de");
1205 break;
1206 case 1:
1207 properties.setProperty("osgi.nl", "en");
1208 setStringValue(IPreferenceKeys.DEFAULT_LANGUAGE_EDITOR, "en");
1209 break;
1210 default:
1211 break;
1212 }
1213 save(file+"/config.ini", properties);
1214 }
1215
1216 /**
1217 * This method loads a property from a given file and returns it.
1218 *
1219 * @param filename
1220 * @return
1221 * @throws IOException
1222 */
1223 private Properties load(String filename) throws IOException {
1224 FileInputStream in = new FileInputStream(filename);
1225 Properties prop = new Properties();
1226 prop.load(in);
1227 in.close();
1228 return prop;
1229 }
1230
1231 /**
1232 * This method saves a property to the specified file.
1233 *
1234 * @param filename
1235 * @param properties
1236 * @throws IOException
1237 */
1238 private void save(String filename, Properties properties) throws IOException{
1239 FileOutputStream fos = new FileOutputStream(filename);
1240 properties.store(fos, "");
1241 fos.close();
1242 }
1243
1244 /**
1245 * Saves a list of P2 Metadata Repositories as string with specified delimiters
1246 *
1247 * @param p2Repos
1248 */
1249 public static void setP2Repositories(List<MetadataRepositoryElement> p2Repos) {
1250 StringBuilder sb = new StringBuilder();
1251 for(MetadataRepositoryElement p2Repo : p2Repos) {
1252 sb.append(P2_REPOSITORIES_DELIM);
1253 if(p2Repo.getName() == null || p2Repo.getName().isEmpty()) {
1254 sb.append("-");
1255 } else {
1256 sb.append(p2Repo.getName());
1257 }
1258 sb.append(P2_REPOSITORY_FIELDS_DELIM);
1259 sb.append(p2Repo.getLocation().toString());
1260 sb.append(P2_REPOSITORY_FIELDS_DELIM);
1261 sb.append(String.valueOf(p2Repo.isEnabled()));
1262 }
1263 getPreferenceStore().setValue(P2_REPOSITORY_LIST, sb.toString());
1264 }
1265
1266
1267 /**
1268 * Retrieves a list of previously saved P2 repositories
1269 *
1270 * @return
1271 */
1272 public static List<MetadataRepositoryElement> getP2Repositories() {
1273 List<MetadataRepositoryElement> p2Repos = new ArrayList<MetadataRepositoryElement>();
1274 String p2ReposPref = getStringValue(P2_REPOSITORY_LIST);
1275 if(p2ReposPref != null && !p2ReposPref.isEmpty()) {
1276 StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM);
1277
1278 while(p2ReposPrefST.hasMoreTokens()) {
1279 String p2RepoStr = p2ReposPrefST.nextToken();
1280 StringTokenizer p2ReposStrST = new StringTokenizer(p2RepoStr,P2_REPOSITORY_FIELDS_DELIM);
1281 if(p2ReposStrST.countTokens()==3) {
1282 String nickname = p2ReposStrST.nextToken();
1283 URI uri = null;
1284 try {
1285 uri = new URI(p2ReposStrST.nextToken());
1286 } catch (URISyntaxException e) {
1287 continue;
1288 }
1289 boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
1290 MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
1291 mre.setNickname(nickname);
1292 mre.setEnabled(enabled);
1293 p2Repos.add(mre);
1294 }
1295 }
1296 }
1297
1298 return p2Repos;
1299 }
1300
1301 /**
1302 * enables/disables nested composite. <br>
1303 *
1304 * @param ctrl - Composite to be en-/disabeld
1305 * @param enabled - boolean
1306 */
1307 public static void recursiveSetEnabled(Control ctrl, boolean enabled) {
1308 if (ctrl instanceof Composite) {
1309 Composite comp = (Composite) ctrl;
1310 for (Control c : comp.getChildren()) {
1311 recursiveSetEnabled(c, enabled);
1312 }
1313 } else {
1314 ctrl.setEnabled(enabled);
1315 }
1316 }
1317
1318
1319
1320
1321 /**
1322 * @param orderActivated
1323 */
1324 public static void setSortNodes(NavigatorOrderEnum nodesOrder) {
1325 setStringValue(PreferencePredicate.TaxonNodeOrder.getKey(), nodesOrder.key);
1326
1327 }
1328
1329 /**
1330 * @param orderActivated
1331 */
1332 public static NavigatorOrderEnum getSortNodes() {
1333 return NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
1334
1335 }
1336
1337 /**
1338 * @param orderActivated
1339 */
1340 public static boolean isNodesSortedNaturally() {
1341 NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
1342 return value.equals(NavigatorOrderEnum.NaturalOrder);
1343
1344 }
1345
1346 /**
1347 * @param orderActivated
1348 */
1349 public static boolean isNodesSortedByName() {
1350 NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
1351 return value.equals(NavigatorOrderEnum.AlphabeticalOrder);
1352
1353 }
1354
1355 /**
1356 * @param orderActivated
1357 */
1358 public static boolean isNodesSortedByNameAndRank() {
1359 NavigatorOrderEnum value = NavigatorOrderEnum.valueOf(getStringValue(PreferencePredicate.TaxonNodeOrder.getKey()));
1360 return value.equals(NavigatorOrderEnum.RankAndNameOrder);
1361
1362 }
1363 /**
1364 * <p>
1365 * setStoreNavigatorState
1366 * </p>
1367 *
1368 * @param selection
1369 * a boolean.
1370 */
1371 public static boolean isStoreNavigatorState() {
1372 return getBooleanValue(RESTORE_NAVIGATOR_STATE);
1373
1374 }
1375
1376 /**
1377 * <p>
1378 * setStoreNavigatorState
1379 * </p>
1380 *
1381 * @param selection
1382 * a boolean.
1383 */
1384 public static void setStoreNavigatorState(boolean selection) {
1385 setBooleanValue(RESTORE_NAVIGATOR_STATE, selection);
1386
1387 }
1388
1389 /**
1390 * @return
1391 */
1392 public static boolean isShowUpWidgetIsDisposedMessages() {
1393 return getBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED);
1394 }
1395 public static void setShowUpWidgetIsDisposedMessages(boolean selection) {
1396 setBooleanValue(IS_SHOW_UP_WIDGET_IS_DISPOSED, selection);
1397 }
1398
1399 /**
1400 * @return
1401 */
1402 public static boolean isShowIdInVocabularyInChecklistEditor() {
1403 String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1404 if (area_display.equals(TermDisplayEnum.IdInVocabulary.getKey())) {
1405 return true;
1406 }else{
1407 return false;
1408 }
1409 }
1410 public static boolean isShowSymbol1InChecklistEditor() {
1411 String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1412 if (area_display.equals(TermDisplayEnum.Symbol1.getKey())) {
1413 return true;
1414 }else{
1415 return false;
1416 }
1417 }
1418 public static boolean isShowSymbol2InChecklistEditor() {
1419 String area_display = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1420 if (area_display.equals(TermDisplayEnum.Symbol2.getKey())) {
1421 return true;
1422 }else{
1423 return false;
1424 }
1425 }
1426 public static void setAreaDisplayInChecklistEditor(String selection) {
1427 setStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey(), selection);
1428 }
1429
1430 public static void setOwnDescriptionForChecklistEditor(boolean selection) {
1431 setBooleanValue(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey(), selection);
1432 }
1433
1434 public static boolean isOwnDescriptionForChecklistEditor() {
1435 return getBooleanValue(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey());
1436 }
1437
1438 /**
1439 * @return
1440 */
1441 public static String displayAreaInChecklistEditor() {
1442 String result = getStringValue(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey());
1443 if (StringUtils.isBlank(result)){
1444 return ((TermDisplayEnum) PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue()).getKey();
1445 }
1446 return result;
1447 }
1448
1449 /**
1450 * @return
1451 */
1452 public static String displayStatusInChecklistEditor() {
1453 String result = getStringValue(PreferencePredicate.DisplayOfStatus.getKey());
1454 if (StringUtils.isBlank(result)){
1455 return((TermDisplayEnum) PreferencePredicate.DisplayOfStatus.getDefaultValue()).getKey();
1456 }
1457 return result;
1458 }
1459 public static void setDisplayStatusInChecklistEditor(String selection) {
1460 setStringValue(PreferencePredicate.DisplayOfStatus.getKey(), selection);
1461
1462 }
1463
1464 /**
1465 * @return
1466 */
1467 public static boolean isShowRankInChecklistEditor() {
1468 return getBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey());
1469 }
1470 public static void setShowRankInChecklistEditor(boolean selection) {
1471 setBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey(), selection);
1472 }
1473
1474 /**
1475 * @param object
1476 * @param b
1477 * @return
1478 */
1479 public static NameDetailsConfigurator getPreferredNameDetailsConfiguration( boolean local) {
1480 NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1481 CdmPreferenceCache cache = CdmPreferenceCache.instance();
1482 CdmPreference preference = null;
1483 String value;
1484 if (!local) {
1485 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.NameDetailsView);
1486 preference = cache.findBestMatching(key);
1487 if (preference == null){
1488 return null;
1489 }
1490
1491 // setBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS, preference.isAllowOverride());
1492 value = preference.getValue();
1493 config.setAllowOverride(preference.isAllowOverride());
1494 //the preference value is build like this:
1495 //<section1>:true;<section2>:false....
1496 }else{
1497 value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), local);
1498 }
1499 String [] sections = value.split(";");
1500 Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
1501 String[] sectionValues;
1502 for (String sectionValue: sections){
1503 sectionValues = sectionValue.split(":");
1504 sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
1505 }
1506
1507 config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
1508
1509 config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
1510
1511 config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails"));
1512 config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled"));
1513
1514 config.setLSIDActivated(getValue(sectionMap, "lsid"));
1515
1516 config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
1517
1518 config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
1519
1520 config.setRankActivated(getValue(sectionMap, "rank"));
1521
1522 config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
1523
1524 config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
1525
1526 config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
1527
1528 config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
1529
1530 config.setProtologueActivated(getValue(sectionMap,"protologue"));
1531
1532 config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
1533
1534 config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
1535
1536 config.setHybridActivated(getValue(sectionMap,"hybrid"));
1537
1538 return config;
1539 }
1540
1541 public static NameDetailsConfigurator getPreferredNameDetailsConfiguration() {
1542 NameDetailsConfigurator config = new NameDetailsConfigurator(true);
1543
1544 String value;
1545
1546 value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), false);
1547
1548 String [] sections = value.split(";");
1549 Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
1550 String[] sectionValues;
1551 for (String sectionValue: sections){
1552 sectionValues = sectionValue.split(":");
1553 sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
1554 }
1555
1556 config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
1557
1558 config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
1559
1560 config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails"));
1561 config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled"));
1562
1563 config.setLSIDActivated(getValue(sectionMap, "lsid"));
1564
1565 config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
1566
1567 config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
1568
1569 config.setRankActivated(getValue(sectionMap, "rank"));
1570
1571 config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
1572
1573 config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
1574
1575 config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
1576
1577 config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
1578
1579 config.setProtologueActivated(getValue(sectionMap,"protologue"));
1580
1581 config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
1582
1583 config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
1584
1585 config.setHybridActivated(getValue(sectionMap,"hybrid"));
1586
1587 return config;
1588 }
1589
1590
1591 /**
1592 * @param object
1593 * @param b
1594 * @return
1595 */
1596 public static void setPreferredNameDetailsConfiguration(NameDetailsConfigurator config, boolean local) {
1597 CdmPreference preference = null;
1598
1599 if (!local) {
1600 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.NameDetailsView, config.toString());
1601
1602 setPreferenceToDB(preference);
1603 }
1604 else{
1605 setStringValue(PreferencePredicate.NameDetailsView.getKey(), config.toString());
1606 }
1607
1608
1609 }
1610
1611 private static Boolean getValue(Map<String, Boolean> sectionMap, String string) {
1612 if (sectionMap.containsKey(string)){
1613 return sectionMap.get(string);
1614 }else{
1615 return true;
1616 }
1617
1618 }
1619
1620
1621
1622 /**
1623 * <p>
1624 * setAbcdConfigurator
1625 * </p>
1626 *
1627 * @param preferredConfiguration
1628 * a {@link eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator}
1629 * object.
1630 */
1631 public static Abcd206ImportConfigurator getDBAbcdImportConfigurationPreference() {
1632
1633 Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1634 ICdmRepository controller;
1635 controller = CdmStore.getCurrentApplicationConfiguration();
1636 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AbcdImportConfig);
1637 CdmPreference preference = null;
1638 if (controller == null){
1639 return null;
1640 }
1641 preference = controller.getPreferenceService().find(key);
1642 if (preference == null){
1643 return config;
1644 } else{
1645 String configString = preference.getValue();
1646 String[] configArray = configString.split(";");
1647
1648 for (String configItem: configArray){
1649 String[] keyValue = configItem.split(":");
1650 String keyString = keyValue[0];
1651 String valueString = null;
1652 if (keyValue.length>1){
1653 valueString = keyValue[1];
1654 }
1655 if (keyString.equals("ignoreImportOfExistingSpecimen")){
1656 config.setIgnoreImportOfExistingSpecimen(Boolean.valueOf(valueString));
1657 }else if (keyString.equals("addIndividualsAssociationsSuchAsSpecimenAndObservations")){
1658 config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(Boolean.valueOf(valueString));
1659 }else if (keyString.equals("reuseExistingTaxaWhenPossible")){
1660 config.setReuseExistingTaxaWhenPossible(Boolean.valueOf(valueString));
1661 }else if (keyString.equals("ignoreAuthorship")){
1662 config.setIgnoreAuthorship(Boolean.valueOf(valueString));
1663 }else if (keyString.equals("addMediaAsMediaSpecimen")){
1664 config.setAddMediaAsMediaSpecimen(Boolean.valueOf(valueString));
1665 }else if (keyString.equals("reuseExistingMetaData")){
1666 config.setReuseExistingMetaData(Boolean.valueOf(valueString));
1667 }else if (keyString.equals("reuseExistingDescriptiveGroups")){
1668 config.setReuseExistingDescriptiveGroups(Boolean.valueOf(valueString));
1669 }else if (keyString.equals("allowReuseOtherClassifications")){
1670 config.setAllowReuseOtherClassifications(Boolean.valueOf(valueString));
1671 }else if (keyString.equals("deduplicateReferences")){
1672 config.setDeduplicateReferences(Boolean.valueOf(valueString));
1673 }else if (keyString.equals("deduplicateClassifications")){
1674 config.setDeduplicateClassifications(Boolean.valueOf(valueString));
1675 }else if (keyString.equals("moveNewTaxaToDefaultClassification")){
1676 config.setMoveNewTaxaToDefaultClassification(Boolean.valueOf(valueString));
1677 }else if (keyString.equals("mapUnitIdToCatalogNumber")){
1678 config.setMapUnitIdToCatalogNumber(Boolean.valueOf(valueString));
1679 }else if (keyString.equals("mapUnitIdToAccessionNumber")){
1680 config.setMapUnitIdToAccessionNumber(Boolean.valueOf(valueString));
1681 }else if (keyString.equals("mapUnitIdToBarcode")){
1682 config.setMapUnitIdToBarcode(Boolean.valueOf(valueString));
1683 }else if (keyString.equals("overwriteExistingSpecimens")){
1684 config.setOverwriteExistingSpecimens(Boolean.valueOf(valueString));
1685 }else if (keyString.equals("nomenclaturalCode")){
1686 config.setNomenclaturalCode(NomenclaturalCode.fromString(valueString));
1687 }else{
1688 logger.debug("This key of the abcd configurator needs to be added to the transformer: " + keyString);
1689 }
1690
1691 }
1692 }
1693 return config;
1694 }
1695
1696 public static Abcd206ImportConfigurator getLocalAbcdImportConfigurator(){
1697 Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
1698
1699 config.setAddIndividualsAssociationsSuchAsSpecimenAndObservations(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS));
1700
1701 config.setAddMediaAsMediaSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN));
1702
1703 config.setAllowReuseOtherClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS));
1704 config.setDeduplicateClassifications(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS));
1705 config.setDeduplicateReferences(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES));
1706 config.setRemoveCountryFromLocalityText(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REMOVE_COUNTRY_FROM_LOCALITY_TEXT));
1707 config.setGetSiblings(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS));
1708 config.setIgnoreAuthorship(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP));
1709 config.setIgnoreImportOfExistingSpecimen(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN));
1710 config.setMapUnitIdToAccessionNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER));
1711 config.setMapUnitIdToBarcode(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE));
1712 config.setMapUnitIdToCatalogNumber(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER));
1713 config.setMoveNewTaxaToDefaultClassification(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION));
1714 config.setOverwriteExistingSpecimens(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN));
1715 config.setReuseExistingDescriptiveGroups(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS));
1716 config.setReuseExistingMetaData(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA));
1717 config.setReuseExistingTaxaWhenPossible(getBooleanValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE));
1718 config.setNomenclaturalCode(NomenclaturalCode.getByKey(getStringValue(IPreferenceKeys.ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE)));
1719
1720 return config;
1721
1722 }
1723
1724
1725 public static void updateAbcdImportConfigurationPreference() {
1726 CdmPreferenceCache cache = CdmPreferenceCache.instance();
1727
1728 CdmPreference pref = cache.findBestMatching(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AbcdImportConfig));
1729
1730 if (!getBooleanValue(prefOverrideKey(PreferencePredicate.AbcdImportConfig.getKey())) || !pref.isAllowOverride()){
1731 resetToDBPreferenceAbcdCOnfigurator();
1732
1733 }
1734 }
1735
1736 public static void resetToDBPreferenceAbcdCOnfigurator(){
1737 Abcd206ImportConfigurator config = getDBAbcdImportConfigurationPreference();
1738 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_INDIVIDUALS_ASSOCIATIONS_SUCH_AS_SPECIMEN_AND_OBSERVATIONS, config.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
1739 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ADD_MEDIA_AS_MEDIASPECIMEN, config.isAddMediaAsMediaSpecimen());
1740
1741 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_ALLOW_REUSE_OTHER_CLASSIFICATIONS, config.isAllowReuseOtherClassifications());
1742 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_CLASSIFICATIONS, config.isDeduplicateClassifications());
1743 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DEDUPLICATE_REFERENCES, config.isDeduplicateReferences());
1744
1745 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_DO_SIBLINGS, config.isGetSiblings());
1746 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_AUTHORSHIP, config.isIgnoreAuthorship());
1747 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_IGNORE_IMPORT_OF_EXISTING_SPECIMEN, config.isIgnoreImportOfExistingSpecimen());
1748 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_ACCESSION_NUMBER, config.isMapUnitIdToAccessionNumber());
1749 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TO_BARCODE, config.isMapUnitIdToBarcode());
1750 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MAP_UNIT_ID_TOCATALOG_NUMBER, config.isMapUnitIdToCatalogNumber());
1751 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_MOVE_NEW_TAXA_TO_DEFAULT_CLASSIFICATION, config.isMoveNewTaxaToDefaultClassification());
1752 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_OVERWRITE_EXISTING_SPECIMEN, config.isOverwriteExistingSpecimens());
1753 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_DESCRIPTIVE_GROUPS, config.isReuseExistingDescriptiveGroups());
1754 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_META_DATA, config.isReuseExistingMetaData());
1755 setBooleanValue(ABCD_IMPORT_CONFIGURATOR_REUSE_EXISTING_TAXA_WHEN_POSSIBLE, config.isReuseExistingTaxaWhenPossible());
1756 if (config.getNomenclaturalCode() != null){
1757 setStringValue(ABCD_IMPORT_CONFIGURATOR_NOMENCLATURAL_CODE, config.getNomenclaturalCode().getKey());
1758 }
1759 }
1760
1761
1762
1763
1764
1765
1766
1767 /**
1768 * @return
1769 */
1770 public static boolean isSortTaxaByRankAndName() {
1771
1772 return getBooleanValue(IPreferenceKeys.SORT_TAXA_BY_RANK_AND_NAME);
1773 }
1774
1775 /**
1776 * @return
1777 */
1778 public static String getSortNamedAreasInDistributionEditor() {
1779
1780 return getStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey());
1781 }
1782
1783 public static void setSortNamedAreasInDistributionEditor(String isSortByVocabularyOrder) {
1784 setStringValue(PreferencePredicate.AreasSortedInDistributionEditor.getKey(), isSortByVocabularyOrder);
1785
1786 }
1787
1788 /**
1789 * <p>
1790 * setPreferredNamedAreasForDistributionEditor
1791 * </p>
1792 *
1793 * @param saveCheckedElements
1794 * @param saveGrayedElements
1795 */
1796 public static void setLastSelectedReference(
1797 List<String> lastSelectedReferences) {
1798
1799 setStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
1800 }
1801
1802 /**
1803 * <p>
1804 * setPreferredNamedAreasForDistributionEditor
1805 * </p>
1806 *
1807 * @param saveCheckedElements
1808 * @param saveGrayedElements
1809 */
1810 public static List<String> getLastSelectedReferences() {
1811
1812 //IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1813 String lastSelected = getStringValue(PreferencesUtil.LAST_SELECTED_REFERENCES);
1814 List<String> result = new ArrayList<>();
1815 if (!StringUtils.isBlank(lastSelected)){
1816 Collections.addAll(result, lastSelected.substring(1,lastSelected.length()-1).split(", "));
1817 }
1818 return result;
1819 }
1820
1821
1822 /**
1823 * <p>
1824 * setPreferredNamedAreasForDistributionEditor
1825 * </p>
1826 *
1827 * @param saveCheckedElements
1828 * @param saveGrayedElements
1829 */
1830 public static void setPreferredNamedAreasForDistributionEditor(
1831 String saveCheckedElements, String saveGrayedElements, boolean local) {
1832 if (local){
1833 setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements);
1834
1835 }
1836 else{
1837 CdmPreference preference = null;
1838
1839 if (saveCheckedElements == null){
1840 preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaTerms);
1841
1842 if (preference == null){
1843 return ;
1844 } else{
1845 setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(),
1846 saveCheckedElements);
1847 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1848 setPreferenceToDB(preference);
1849
1850 }
1851 } else{
1852 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaTerms, saveCheckedElements);
1853 setPreferenceToDB(preference);
1854 setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(),
1855 saveCheckedElements);
1856
1857 }
1858 }
1859
1860 }
1861
1862 /**
1863 * @param saveCheckedElements
1864 * @param saveCheckedElements2
1865 * @param b
1866 */
1867 public static void setPreferredVocabulariesForDistributionEditor(String saveCheckedElements,
1868 boolean local, boolean isOverride) {
1869 if (local){
1870 setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), saveCheckedElements);
1871 setBooleanValue(prefOverrideKey(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()), isOverride);
1872 }
1873 else{
1874 ICdmRepository controller;
1875 CdmPreference preference = null;
1876
1877 if (saveCheckedElements == null){
1878 preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1879
1880 if (preference == null){
1881 return ;
1882 } else{
1883 setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
1884 saveCheckedElements);
1885 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1886 preference.setAllowOverride(isOverride);
1887 setPreferenceToDB(preference);
1888 }
1889 } else{
1890 preference = CdmPreference.NewInstance(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies, saveCheckedElements);
1891 preference.setAllowOverride(isOverride);
1892 setPreferenceToDB(preference);
1893 setStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(),
1894 saveCheckedElements);
1895
1896 }
1897 }
1898 }
1899
1900
1901 /**
1902 * @param saveCheckedElements
1903 * @param saveCheckedElements2
1904 * @param b
1905 */
1906 public static String getPreferredVocabulariesForDistributionEditor(boolean local) {
1907 if (local){
1908
1909 String pref = getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey(), local);
1910 return pref;
1911 }
1912 else{
1913 CdmPreference preference = null;
1914 preference = getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
1915 if (preference == null){
1916 return null;
1917 } else{
1918 return preference.getValue();
1919 }
1920
1921 }
1922 }
1923
1924 public static List<UUID> createUUIDListFromStringPref(String prefKey) {
1925 String prefValue = PreferencesUtil.getStringValue(prefKey);
1926 String[] stringArray = prefValue.split(";");
1927 List<UUID> uuidList = new ArrayList();
1928 for (String uuid: stringArray){
1929 if (!StringUtils.isBlank(uuid)){
1930 uuidList.add(UUID.fromString(uuid));
1931 }
1932 }
1933 return uuidList;
1934 }
1935
1936 public static boolean getFilterCommonNameReferences(){
1937 return getBooleanValue(PreferencesUtil.FILTER_COMMON_NAME_REFERENCES);
1938 }
1939
1940 /**
1941 *
1942 */
1943 public static void updateDBPreferences() {
1944 CdmPreference preference = null;
1945 CdmPreferenceCache cache = CdmPreferenceCache.instance();
1946 cache.getAllTaxEditorDBPreferences();
1947
1948 //ABCD Configurator
1949
1950 updateAbcdImportConfigurationPreference();
1951
1952 //Name Details
1953 NameDetailsConfigurator config = getPreferredNameDetailsConfiguration(false);
1954 // if (config != null ){
1955 // if (!getBooleanValue(OVERRIDE_NAME_DETAILS) || !getBooleanValue(ALLOW_OVERRIDE_NAME_DETAILS)){
1956 // setPreferredNameDetailsConfiguration(config, false);
1957 // }
1958 // }
1959
1960
1961
1962
1963
1964
1965
1966
1967 }
1968
1969 /**
1970 * @param string
1971 * @param saveCheckedElements
1972 */
1973 public static void setPreferencesToDB(List<CdmPreference> preferences) {
1974
1975 ICdmRepository controller;
1976 try{
1977 if(CdmStore.isActive()){
1978 controller = CdmStore.getCurrentApplicationConfiguration();
1979 for (CdmPreference preference: preferences){
1980
1981 controller.getPreferenceService().set(preference);
1982
1983 CdmPreferenceCache.instance().put(preference);
1984 }
1985 }
1986 }catch(Exception e){
1987 e.printStackTrace();
1988 }
1989 }
1990
1991
1992
1993
1994
1995
1996
1997
1998 }