1
|
/**
|
2
|
* Copyright (C) 2018 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
|
package eu.etaxonomy.taxeditor.preference;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.HashMap;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
|
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;
|
29
|
|
30
|
/**
|
31
|
* @author k.luther
|
32
|
* @since 27.04.2018
|
33
|
*
|
34
|
*/
|
35
|
public class CdmPreferenceCache {
|
36
|
Map<String, CdmPreference> preferenceCache = new HashMap();
|
37
|
|
38
|
private static CdmPreferenceCache instance;
|
39
|
|
40
|
private final static Logger logger = Logger.getLogger(CdmPreferenceCache.class);
|
41
|
|
42
|
public static CdmPreferenceCache instance(){
|
43
|
if(instance == null){
|
44
|
instance = new CdmPreferenceCache();
|
45
|
}
|
46
|
return instance;
|
47
|
}
|
48
|
|
49
|
public CdmPreference get(String key){
|
50
|
return preferenceCache.get(key);
|
51
|
}
|
52
|
|
53
|
public void put(CdmPreference pref){
|
54
|
preferenceCache.put(pref.getPredicate(), pref);
|
55
|
}
|
56
|
|
57
|
public void getAllTaxEditorDBPreferences(){
|
58
|
ICdmRepository controller;
|
59
|
controller = CdmStore.getCurrentApplicationConfiguration();
|
60
|
//ABCD
|
61
|
PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.AbcdImportConfig);
|
62
|
loadAndPutPreference(controller, key);
|
63
|
|
64
|
//ShowIOMenu
|
65
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowImportExportMenu);
|
66
|
loadAndPutPreference(controller, key);
|
67
|
|
68
|
// key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowMediaView);
|
69
|
// loadAndPutPreference(controller, key);
|
70
|
|
71
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowChecklistPerspective);
|
72
|
loadAndPutPreference(controller, key);
|
73
|
|
74
|
|
75
|
//Specimen Details
|
76
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowSpecimen);
|
77
|
loadAndPutPreference(controller, key);
|
78
|
|
79
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowTaxonAssociations);
|
80
|
loadAndPutPreference(controller, key);
|
81
|
|
82
|
|
83
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowCollectingAreasInGeneralSection);
|
84
|
loadAndPutPreference(controller, key);
|
85
|
|
86
|
|
87
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowLifeForm);
|
88
|
loadAndPutPreference(controller, key);
|
89
|
|
90
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.DeterminationOnlyForFieldUnits);
|
91
|
loadAndPutPreference(controller, key);
|
92
|
|
93
|
|
94
|
//Name Details
|
95
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.NameDetailsView);
|
96
|
loadAndPutPreference(controller, key);
|
97
|
|
98
|
|
99
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionStatus);
|
100
|
loadAndPutPreference(controller, key);
|
101
|
|
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){
|
109
|
try {
|
110
|
uuidList.add(UUID.fromString(uuidString));
|
111
|
} catch (Exception e) {
|
112
|
logger.warn("Preference loading failed", e);
|
113
|
}
|
114
|
}
|
115
|
|
116
|
List<DefinedTermBase> definedTermBases = termService.load(uuidList, null);
|
117
|
CdmStore.getTermManager().setPreferredTerms(definedTermBases, TermStore.getTerms(TermType.PresenceAbsenceTerm, null));
|
118
|
}
|
119
|
}
|
120
|
|
121
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AvailableDistributionAreaVocabularies);
|
122
|
loadAndPutPreference(controller, key);
|
123
|
|
124
|
|
125
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.DistributionEditorActivated);
|
126
|
loadAndPutPreference(controller, key);
|
127
|
|
128
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.DisplayOfAreasInDistributionEditor);
|
129
|
loadAndPutPreference(controller, key);
|
130
|
|
131
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.DisplayOfStatus);
|
132
|
loadAndPutPreference(controller, key);
|
133
|
|
134
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowRankInDistributionEditor);
|
135
|
loadAndPutPreference(controller, key);
|
136
|
|
137
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.AreasSortedByIdInVocabulary);
|
138
|
loadAndPutPreference(controller, key);
|
139
|
|
140
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.OwnDescriptionForDistributionEditor);
|
141
|
loadAndPutPreference(controller, key);
|
142
|
|
143
|
//common names
|
144
|
|
145
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.CommonNameAreaVocabularies);
|
146
|
loadAndPutPreference(controller, key);
|
147
|
|
148
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.CommonNameReferencesWithMarker);
|
149
|
loadAndPutPreference(controller, key);
|
150
|
|
151
|
//sources
|
152
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowIdInSource);
|
153
|
loadAndPutPreference(controller, key);
|
154
|
|
155
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowNamespaceInSource);
|
156
|
loadAndPutPreference(controller, key);
|
157
|
|
158
|
//multiple classifications / taxon navigator
|
159
|
|
160
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.DisableMultiClassification);
|
161
|
loadAndPutPreference(controller, key);
|
162
|
|
163
|
|
164
|
key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowTaxonNodeWizard);
|
165
|
loadAndPutPreference(controller, key);
|
166
|
|
167
|
|
168
|
}
|
169
|
|
170
|
private void loadAndPutPreference(ICdmRepository controller, PrefKey key) {
|
171
|
if (controller == null){
|
172
|
return ;
|
173
|
}
|
174
|
CdmPreference preference = controller.getPreferenceService().find(key);
|
175
|
if (preference != null){
|
176
|
put(preference);
|
177
|
}
|
178
|
}
|
179
|
|
180
|
}
|