2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.preference
;
11 import java
.util
.ArrayList
;
12 import java
.util
.HashMap
;
13 import java
.util
.List
;
15 import java
.util
.UUID
;
17 import org
.apache
.log4j
.Logger
;
19 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
20 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
21 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
22 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
;
24 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmPreference
.PrefKey
;
25 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
26 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferenceSubject
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
28 import eu
.etaxonomy
.taxeditor
.store
.TermStore
;
35 public class CdmPreferenceCache
{
36 Map
<String
, CdmPreference
> preferenceCache
= new HashMap();
38 private static CdmPreferenceCache instance
;
40 private final static Logger logger
= Logger
.getLogger(CdmPreferenceCache
.class);
42 public static CdmPreferenceCache
instance(){
44 instance
= new CdmPreferenceCache();
49 public CdmPreference
get(String key
){
50 return preferenceCache
.get(key
);
53 public void put(CdmPreference pref
){
54 preferenceCache
.put(pref
.getPredicate(), pref
);
57 public void getAllTaxEditorDBPreferences(){
58 ICdmRepository controller
;
59 controller
= CdmStore
.getCurrentApplicationConfiguration();
61 PrefKey key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.AbcdImportConfig
);
62 loadAndPutPreference(controller
, key
);
65 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowImportExportMenu
);
66 loadAndPutPreference(controller
, key
);
68 // key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowMediaView);
69 // loadAndPutPreference(controller, key);
71 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowChecklistPerspective
);
72 loadAndPutPreference(controller
, key
);
76 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowSpecimen
);
77 loadAndPutPreference(controller
, key
);
79 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowTaxonAssociations
);
80 loadAndPutPreference(controller
, key
);
83 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowCollectingAreasInGeneralSection
);
84 loadAndPutPreference(controller
, key
);
87 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowLifeForm
);
88 loadAndPutPreference(controller
, key
);
90 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.DeterminationOnlyForFieldUnits
);
91 loadAndPutPreference(controller
, key
);
95 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.NameDetailsView
);
96 loadAndPutPreference(controller
, key
);
99 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.AvailableDistributionStatus
);
100 loadAndPutPreference(controller
, key
);
102 if (preferenceCache
.get(key
) != null){
103 if (!PreferencesUtil
.getBooleanValue(PreferencesUtil
.prefOverrideKey(PreferencePredicate
.AvailableDistributionStatus
.getKey())) || !preferenceCache
.get(key
).isAllowOverride()){
104 //get terms for the uuids... and add them to the termManager as preferred terms
105 ITermService termService
= CdmStore
.getService(ITermService
.class);
106 String
[] uuidArray
= preferenceCache
.get(key
).getValue().split(";");
107 List
<UUID
> uuidList
= new ArrayList();
108 for (String uuidString
:uuidArray
){
110 uuidList
.add(UUID
.fromString(uuidString
));
111 } catch (Exception e
) {
112 logger
.warn("Preference loading failed", e
);
116 List
<DefinedTermBase
> definedTermBases
= termService
.load(uuidList
, null);
117 CdmStore
.getTermManager().setPreferredTerms(definedTermBases
, TermStore
.getTerms(TermType
.PresenceAbsenceTerm
, null));
121 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.AvailableDistributionAreaVocabularies
);
122 loadAndPutPreference(controller
, key
);
125 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.DistributionEditorActivated
);
126 loadAndPutPreference(controller
, key
);
128 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.DisplayOfAreasInDistributionEditor
);
129 loadAndPutPreference(controller
, key
);
131 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.DisplayOfStatus
);
132 loadAndPutPreference(controller
, key
);
134 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowRankInDistributionEditor
);
135 loadAndPutPreference(controller
, key
);
137 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.AreasSortedInDistributionEditor
);
138 loadAndPutPreference(controller
, key
);
140 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.OwnDescriptionForDistributionEditor
);
141 loadAndPutPreference(controller
, key
);
145 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.CommonNameAreaVocabularies
);
146 loadAndPutPreference(controller
, key
);
148 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.CommonNameReferencesWithMarker
);
149 loadAndPutPreference(controller
, key
);
152 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowIdInSource
);
153 loadAndPutPreference(controller
, key
);
155 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowNamespaceInSource
);
156 loadAndPutPreference(controller
, key
);
158 //multiple classifications / taxon navigator
160 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.DisableMultiClassification
);
161 loadAndPutPreference(controller
, key
);
164 key
= CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowTaxonNodeWizard
);
165 loadAndPutPreference(controller
, key
);
170 private void loadAndPutPreference(ICdmRepository controller
, PrefKey key
) {
171 if (controller
== null){
174 CdmPreference preference
= controller
.getPreferenceService().find(key
);
175 if (preference
!= null){