3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.store
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Collections
;
15 import java
.util
.Comparator
;
16 import java
.util
.List
;
18 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
19 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
20 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
21 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
22 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
23 import eu
.etaxonomy
.cdm
.model
.common
.ExtensionType
;
24 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
25 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
26 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermVocabulary
;
28 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
29 import eu
.etaxonomy
.cdm
.model
.common
.VocabularyEnum
;
30 import eu
.etaxonomy
.cdm
.model
.description
.AbsenceTerm
;
31 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
32 import eu
.etaxonomy
.cdm
.model
.description
.MeasurementUnit
;
33 import eu
.etaxonomy
.cdm
.model
.description
.Modifier
;
34 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
35 import eu
.etaxonomy
.cdm
.model
.description
.PresenceTerm
;
36 import eu
.etaxonomy
.cdm
.model
.description
.Scope
;
37 import eu
.etaxonomy
.cdm
.model
.description
.Stage
;
38 import eu
.etaxonomy
.cdm
.model
.description
.State
;
39 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
40 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaType
;
41 import eu
.etaxonomy
.cdm
.model
.location
.ReferenceSystem
;
42 import eu
.etaxonomy
.cdm
.model
.media
.RightsTerm
;
43 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
44 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignationStatus
;
45 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
46 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
47 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
48 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationModifier
;
49 import eu
.etaxonomy
.cdm
.model
.occurrence
.PreservationMethod
;
50 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
51 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
54 * All terms may be accessed through this store.
55 * Note: This is for internal use. When using vocabularies in the UI, try to use the preferred terms from
62 public class TermStore
{
65 * <p>getSpecimenTypeDesignationStatus</p>
67 * @return a {@link java.util.List} object.
69 public static List
<SpecimenTypeDesignationStatus
> getSpecimenTypeDesignationStatus() {
70 return getTerms(SpecimenTypeDesignationStatus
.class);
75 * <p>getNameTypeDesignationStatus</p>
77 * @return a {@link java.util.List} object.
79 public static List
<NameTypeDesignationStatus
> getNameTypeDesignationStatus() {
80 return getTerms(NameTypeDesignationStatus
.class);
84 * <p>getNamedAreaTypes</p>
86 * @return a {@link java.util.List} object.
88 public static List
<NamedAreaType
> getNamedAreaTypes(){
89 return getTerms(NamedAreaType
.class);
93 * <p>getAnnotationTypes</p>
95 * @return a {@link java.util.List} object.
97 public static List
<AnnotationType
> getAnnotationTypes(){
98 return getTerms(AnnotationType
.class);
102 * <p>getTaxonRelationshipTypes</p>
104 * @return a {@link java.util.List} object.
106 public static List
<TaxonRelationshipType
> getTaxonRelationshipTypes(){
107 return getTerms(TaxonRelationshipType
.class);
112 * <p>getLanguages</p>
114 * @return a {@link java.util.List} object.
116 public static List
<Language
> getLanguages(){
117 return getTerms(Language
.class);
123 * @return a {@link java.util.List} object.
125 public static List
<Feature
> getFeatures() {
126 List
<Feature
> features
= getTerms(Feature
.class);
127 features
.remove(Feature
.IMAGE());
133 * <p>getNameRelationshipTypes</p>
135 * @return a {@link java.util.List} object.
137 public static List
<NameRelationshipType
> getNameRelationshipTypes() {
138 return getTerms(NameRelationshipType
.class);
142 * <p>getNomenclaturalStatusTypes</p>
144 * @return a {@link java.util.List} object.
146 public static List
<NomenclaturalStatusType
> getNomenclaturalStatusTypes(){
147 return getTerms(NomenclaturalStatusType
.class);
152 * <p>getNonTechnicalMarkerTypes</p>
154 * @return a {@link java.util.List} object.
156 public static List
<MarkerType
> getNonTechnicalMarkerTypes() {
157 List
<MarkerType
> nonTechnicalMarkerTypes
= new ArrayList
<MarkerType
>();
158 List
<MarkerType
> markerTypes
= getTerms(MarkerType
.class);
160 for (Object type
: markerTypes
) {
161 if (((MarkerType
) type
).isTechnical() == false) {
162 nonTechnicalMarkerTypes
.add((MarkerType
) type
);
166 return nonTechnicalMarkerTypes
;
171 * <p>getExtensionTypes</p>
173 * @return a {@link java.util.List} object.
175 public static List
<ExtensionType
> getExtensionTypes() {
176 return getTerms(ExtensionType
.class);
180 * <p>getRightsTypes</p>
182 * @return a {@link java.util.List} object.
184 public static List
<RightsTerm
> getRightsTypes() {
185 return getTerms(RightsTerm
.class);
190 * Retrieve all ranks from data store.
192 * @return a {@link java.util.List} object.
194 public static List
<Rank
> getRanks(){
195 if(PreferencesUtil
.getSortRanksHierarchichally()){
196 return getTerms(Rank
.class, new Comparator
<Rank
>(){
199 public int compare(Rank o1
, Rank o2
) {
200 return o1
.compareTo(o2
);
205 return getTerms(Rank
.class);
211 * Retrieve all presence and absence terms from data store.
213 * @return a {@link java.util.List} object.
215 public static List
<PresenceAbsenceTermBase
> getPresenceAbsenceTerms() {
216 List presenceAbsenceTerms
= getTerms(PresenceTerm
.class);
217 presenceAbsenceTerms
.addAll(getTerms(AbsenceTerm
.class));
219 return presenceAbsenceTerms
;
223 * Retrieve all stages from data store.
225 * @return a {@link java.util.List} object.
227 public static List
<Stage
> getStages(){
228 return getTerms(Stage
.class);
232 * Retrieve all states from data store.
234 * @return a {@link java.util.List} object.
236 public static List
<State
> getStates() {
237 return getTerms(State
.class);
241 * Retrieve all preservation methods from data store.
243 * @return a {@link java.util.List} object.
245 public static List
<PreservationMethod
> getPreservationMethods(){
246 return getTerms(PreservationMethod
.class);
252 * <p>getMeasurementUnits</p>
254 * @return a {@link java.util.List} object.
256 public static List
<MeasurementUnit
> getMeasurementUnits() {
257 return getTerms(MeasurementUnit
.class);
262 * <p>getModifiers</p>
264 * @return a {@link java.util.List} object.
266 public static List
<Modifier
> getModifiers() {
267 return getTerms(Modifier
.class);
272 * <p>getStatisticalMeasures</p>
274 * @return a {@link java.util.List} object.
276 public static List
<StatisticalMeasure
> getStatisticalMeasures() {
277 return getTerms(StatisticalMeasure
.class);
283 * @return a {@link java.util.List} object.
285 public static List
<Scope
> getScopes() {
286 return getTerms(Scope
.class);
290 * <p>getDeterminationModifiers</p>
292 * @return a {@link java.util.List} object.
294 public static List
<DeterminationModifier
> getDeterminationModifiers() {
295 return getTerms(DeterminationModifier
.class);
299 * <p>getReferenceSystems</p>
301 * @return a {@link java.util.List} object.
303 public static List
<ReferenceSystem
> getReferenceSystems() {
304 return getTerms(ReferenceSystem
.class);
308 ************* save methods *****************************
310 * @param term a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase} object.
312 public static void saveTerm(DefinedTermBase term
){
313 getTermService().saveOrUpdate(term
);
319 * @param selected a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase} object.
321 public static void delete(DefinedTermBase selected
) {
322 getTermService().delete(selected
);
326 * Save a vacabulary to data store
328 * @param term a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase} object.
330 public static void updateVocabulary(DefinedTermBase term
) {
331 getTermService().saveOrUpdate(term
);
336 /*************** internal methods **************************/
338 private static Language
getDefaultLanguage(){
339 return CdmStore
.getDefaultLanguage();
342 private static OrderedTermVocabulary
<?
extends OrderedTermBase
> getOrderedTermVocabulary(VocabularyEnum vocabularyType
){
343 TermVocabulary
<DefinedTermBase
> vocabulary
= getTermVocabulary(vocabularyType
);
344 return HibernateProxyHelper
.deproxy(vocabulary
, OrderedTermVocabulary
.class);
348 * <p>getTermVocabulary</p>
350 * @param vocabularyType a {@link eu.etaxonomy.cdm.model.common.VocabularyEnum} object.
351 * @return a {@link eu.etaxonomy.cdm.model.common.TermVocabulary} object.
353 public static TermVocabulary
<DefinedTermBase
> getTermVocabulary(VocabularyEnum vocabularyType
){
355 return CdmStore
.getService(IVocabularyService
.class).getVocabulary(vocabularyType
);
358 private static <TERM
extends DefinedTermBase
> List
<TERM
> getTerms(Class
<TERM
> clazz
){
359 Comparator
<TERM
> comparator
= new Comparator
<TERM
>() {
361 public int compare(TERM o1
, TERM o2
) {
362 String label1
= o1
.getLabel(getDefaultLanguage()) != null ? o1
.getLabel(getDefaultLanguage()) : o1
.getTitleCache();
363 String label2
= o2
.getLabel(getDefaultLanguage()) != null ? o2
.getLabel(getDefaultLanguage()) : o2
.getTitleCache();
364 return label1
.compareTo(label2
);
368 return getTerms(clazz
, comparator
);
372 private static <TERM
extends DefinedTermBase
> List
<TERM
> getTerms(Class
<TERM
> clazz
, Comparator
<TERM
> comparator
){
375 List
<TERM
> terms
= new ArrayList
<TERM
>();
376 if(getTermService() != null){
377 terms
= getTermService().listByTermClass(clazz
, null, null, null, null);
379 Collections
.sort(terms
, comparator
);
386 private static ITermService
getTermService(){
387 return CdmStore
.getService(ITermService
.class);