f2511b9e5b23da1b3f903c02ead60410f4871b82
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / VocabularyStore.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.store;
12
13 import java.util.HashSet;
14 import java.util.Set;
15 import java.util.SortedSet;
16
17 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
18 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
19 import eu.etaxonomy.cdm.model.common.ExtensionType;
20 import eu.etaxonomy.cdm.model.common.Language;
21 import eu.etaxonomy.cdm.model.common.MarkerType;
22 import eu.etaxonomy.cdm.model.common.OrderedTermBase;
23 import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
24 import eu.etaxonomy.cdm.model.common.TermVocabulary;
25 import eu.etaxonomy.cdm.model.common.VocabularyEnum;
26 import eu.etaxonomy.cdm.model.description.Feature;
27 import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
28 import eu.etaxonomy.cdm.model.media.RightsTerm;
29 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
30 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
31 import eu.etaxonomy.cdm.model.name.Rank;
32 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
33 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
34
35 /**
36 * All vocabularies may be accessed through this store.
37 * Note: This is for internal use. When using vocabularies in the UI, try to use the preferred terms from
38 * PreferenceUtil
39 *
40 * @author n.hoffmann
41 * @created 25.06.2009
42 * @version 1.0
43 */
44 public class VocabularyStore {
45
46 /**
47 *
48 * @return
49 */
50 public static SortedSet<SpecimenTypeDesignationStatus> getSpecimenTypeDesignationStatus() {
51 SortedSet specimenTypeDesignationStatus = getTermVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus).getTermsOrderedByLabels(CdmStore.getDefaultLanguage());
52 return specimenTypeDesignationStatus;
53 }
54
55 /**
56 *
57 * @return
58 */
59 public static SortedSet<SpecimenTypeDesignationStatus> getNameTypeDesignationStatus() {
60 SortedSet nameTypeDesignationStatus = getTermVocabulary(VocabularyEnum.NameTypeDesignationStatus).getTermsOrderedByLabels(CdmStore.getDefaultLanguage());
61 return nameTypeDesignationStatus;
62 }
63
64 /**
65 *
66 * @return
67 */
68 public static SortedSet<TaxonRelationshipType> getTaxonRelationshipTypes(){
69 SortedSet taxonRelationshipTypes = getOrderedTermVocabulary(VocabularyEnum.TaxonRelationshipType).getOrderedTerms();
70 return taxonRelationshipTypes;
71 }
72
73 /**
74 *
75 * @return
76 *
77 * @deprecated handle via preferences
78 */
79 public static SortedSet<TaxonRelationshipType> getConceptRelationshipTypes() {
80 SortedSet<TaxonRelationshipType> conceptRelationshipTypes = getTaxonRelationshipTypes();
81 // remove these two relations as they are considered standard taxon relations
82 conceptRelationshipTypes.remove(TaxonRelationshipType.MISAPPLIED_NAME_FOR());
83 conceptRelationshipTypes.remove(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN());
84
85 return conceptRelationshipTypes;
86 }
87
88 /**
89 *
90 * @return
91 */
92 public static Set<Language> getLanguages(){
93
94 Set languages = getTermVocabulary(VocabularyEnum.Language).getTerms();
95
96 // SortedSet languages = getDefault().getTermVocabulary(VocabularyEnum.Language).getTermsOrderedByLabels(getDefaultLanguage());
97 return languages;
98 }
99
100 public static SortedSet<? extends DefinedTermBase> getTerms(VocabularyEnum vocabularyType){
101
102 TermVocabulary<DefinedTermBase> terms = getTermVocabulary(vocabularyType);
103
104 if(terms != null) {
105 return terms.getTermsOrderedByLabels(CdmStore.getDefaultLanguage());
106 }
107 return null;
108 }
109
110 /**
111 * @param selected
112 */
113 public static void delete(DefinedTermBase selected) {
114 CdmStore.getTermService().delete(selected);
115 }
116 /**
117 *
118 * @return
119 */
120 public static SortedSet<Feature> getFeatures() {
121 SortedSet features = getTermVocabulary(VocabularyEnum.Feature).getTermsOrderedByLabels(CdmStore.getDefaultLanguage());
122 features.remove(Feature.IMAGE());
123 return features;
124
125 }
126
127 /**
128 *
129 * @return
130 */
131 public static SortedSet<NameRelationshipType> getNameRelationshipTypes() {
132 SortedSet nameRelationshipTypes = getTermVocabulary(VocabularyEnum.NameRelationshipType).getTermsOrderedByLabels(CdmStore.getDefaultLanguage());
133 return nameRelationshipTypes;
134 }
135
136 /**
137 *
138 * @return
139 */
140 public static Set<NomenclaturalStatusType> getNomenclaturalStatusTypes(){
141 // TODO sort types
142 Set nomenclaturalStatusTypes = getTermVocabulary(VocabularyEnum.NomenclaturalStatusType).getTermsOrderedByLabels(CdmStore.getDefaultLanguage());
143 return nomenclaturalStatusTypes;
144 }
145
146
147 /**
148 * @return
149 *
150 */
151 public static Set<MarkerType> getNonTechnicalMarkerTypes() {
152 Set<MarkerType> nonTechnicalMarkerTypes = new HashSet<MarkerType>();
153 for (Object type : getTermVocabulary(VocabularyEnum.MarkerType).getTermsOrderedByLabels(CdmStore.getDefaultLanguage())) {
154 if (((MarkerType) type).isTechnical() == false) {
155 nonTechnicalMarkerTypes.add((MarkerType) type);
156 }
157 }
158
159 return nonTechnicalMarkerTypes;
160 }
161
162
163 /**
164 * @return
165 */
166 public static Set<ExtensionType> getExtensionTypes() {
167 Set extensionTypes = getTermVocabulary(VocabularyEnum.ExtensionType).getTermsOrderedByLabels(CdmStore.getDefaultLanguage());
168 return extensionTypes;
169 }
170
171 /**
172 * @return
173 */
174 public static Set<RightsTerm> getRightsTypes() {
175 Set rightsTypes = getTermVocabulary(VocabularyEnum.RightsTerm).getTermsOrderedByLabels(CdmStore.getDefaultLanguage());
176 return rightsTypes;
177 }
178
179
180 /**
181 * Retrieve all ranks from data store.
182 *
183 * @return
184 */
185 public static SortedSet<Rank> getRanks(){
186 SortedSet ranks = getOrderedTermVocabulary(VocabularyEnum.Rank).getOrderedTerms();
187 return ranks;
188 }
189
190
191 /**
192 * Retrieve all presence and absence terms from data store.
193 *
194 * @return
195 */
196 public static SortedSet<PresenceAbsenceTermBase<PresenceAbsenceTermBase<?>>> getPresenceAbsenceTerms() {
197 SortedSet presenceAbsenceTerms = getTermVocabulary(VocabularyEnum.PresenceTerm).getTermsOrderedByLabels(CdmStore.getDefaultLanguage());
198 presenceAbsenceTerms.addAll(getTermVocabulary(VocabularyEnum.AbsenceTerm).getTermsOrderedByLabels(CdmStore.getDefaultLanguage()));
199
200 return presenceAbsenceTerms;
201 }
202
203
204 /*************** save methods ******************************/
205 /**
206 * Adds a term to a vocabulary
207 *
208 * @param feature
209 */
210 public static void saveTerm(DefinedTermBase term, VocabularyEnum vocabularyType) {
211 TermVocabulary<DefinedTermBase> vocabulary = getTermVocabulary(vocabularyType);
212 vocabulary.addTerm(term);
213
214 CdmStore.getVocabularyService().save(vocabulary);
215 }
216
217 /**
218 * Save a vacabulary to data store
219 *
220 * @param feature
221 */
222 public static void updateVocabulary(DefinedTermBase term) {
223 CdmStore.getTermService().save(term);
224 }
225
226
227
228 /*************** internal methods **************************/
229
230 private static Language getDefaultLanguage(){
231 return CdmStore.getDefaultLanguage();
232 }
233
234 private static OrderedTermVocabulary<? extends OrderedTermBase> getOrderedTermVocabulary(VocabularyEnum vocabularyType){
235 TermVocabulary<DefinedTermBase> vocabulary = getTermVocabulary(vocabularyType);
236 return HibernateProxyHelper.deproxy(vocabulary, OrderedTermVocabulary.class);
237 }
238
239 public static TermVocabulary<DefinedTermBase> getTermVocabulary(VocabularyEnum vocabularyType){
240 return CdmStore.getVocabularyService().getVocabulary(vocabularyType);
241 }
242 }