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
;
14 import java
.util
.SortedSet
;
16 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
17 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
18 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
19 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
20 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
21 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermBase
;
22 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermVocabulary
;
23 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
24 import eu
.etaxonomy
.cdm
.model
.common
.VocabularyEnum
;
25 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
26 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
27 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
28 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
29 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
30 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
34 * All vocabularies may be accessed through this store.
35 * Note: This is for internal use. When using vocabularies in the UI, try to use the preferred terms from
42 public class VocabularyStore
{
45 * The singleton instance
47 private static VocabularyStore instance
;
50 * Retrieve the singleton instance
54 private static synchronized VocabularyStore
getDefault(){
56 instance
= new VocabularyStore();
65 public static SortedSet
<SpecimenTypeDesignationStatus
> getSpecimenTypeDesignationStatus() {
66 SortedSet specimenTypeDesignationStatus
= getDefault().getTermVocabulary(VocabularyEnum
.SpecimenTypeDesignationStatus
).getTermsOrderedByLabels(getDefaultLanguage());
67 return specimenTypeDesignationStatus
;
74 public static SortedSet
<TaxonRelationshipType
> getTaxonRelationshipTypes(){
75 SortedSet taxonRelationshipTypes
= getDefault().getOrderedTermVocabulary(VocabularyEnum
.TaxonRelationshipType
).getOrderedTerms();
76 return taxonRelationshipTypes
;
83 * @deprecated handle via preferences
85 public static SortedSet
<TaxonRelationshipType
> getConceptRelationshipTypes() {
86 SortedSet
<TaxonRelationshipType
> conceptRelationshipTypes
= getTaxonRelationshipTypes();
87 // remove these two relations as they are considered standard taxon relations
88 conceptRelationshipTypes
.remove(TaxonRelationshipType
.MISAPPLIED_NAME_FOR());
89 conceptRelationshipTypes
.remove(TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN());
91 return conceptRelationshipTypes
;
98 public static SortedSet
<Language
> getLanguages(){
99 SortedSet languages
= getDefault().getTermVocabulary(VocabularyEnum
.Language
).getTermsOrderedByLabels(getDefaultLanguage());
107 public static SortedSet
<Feature
> getFeatures() {
108 SortedSet features
= getDefault().getTermVocabulary(VocabularyEnum
.Feature
).getTermsOrderedByLabels(getDefaultLanguage());
117 public static SortedSet
<NameRelationshipType
> getNameRelationshipTypes() {
118 SortedSet nameRelationshipTypes
= getDefault().getTermVocabulary(VocabularyEnum
.NameRelationshipType
).getTermsOrderedByLabels(getDefaultLanguage());
119 return nameRelationshipTypes
;
126 public static Set
<NomenclaturalStatusType
> getNomenclaturalStatusTypes(){
128 Set nomenclaturalStatusTypes
= getDefault().getTermVocabulary(VocabularyEnum
.NomenclaturalStatusType
).getTermsOrderedByLabels(getDefaultLanguage());
129 return nomenclaturalStatusTypes
;
133 * Retrieve all ranks from data store.
137 public static SortedSet
<Rank
> getRanks(){
138 SortedSet ranks
= getDefault().getOrderedTermVocabulary(VocabularyEnum
.Rank
).getOrderedTerms();
144 * Retrieve all presence and absence terms from data store.
148 public static SortedSet
<PresenceAbsenceTermBase
<PresenceAbsenceTermBase
<?
>>> getPresenceAbsenceTerms() {
149 SortedSet presenceAbsenceTerms
= getDefault().getTermVocabulary(VocabularyEnum
.PresenceTerm
).getTermsOrderedByLabels(getDefaultLanguage());
150 presenceAbsenceTerms
.addAll(getDefault().getTermVocabulary(VocabularyEnum
.AbsenceTerm
).getTermsOrderedByLabels(getDefaultLanguage()));
152 return presenceAbsenceTerms
;
155 /*************** save methods ******************************/
157 * Adds a term to a vocabulary
161 public static void saveTerm(DefinedTermBase term
, VocabularyEnum vocabularyType
) {
162 TermVocabulary
<DefinedTermBase
> vocabulary
= getDefault().getTermVocabulary(vocabularyType
);
164 vocabulary
.addTerm(term
);
166 getDefault().getTermService().saveTermVocabulary(vocabulary
);
170 * Save a vacabulary to data store
174 public static void updateVocabulary(VocabularyEnum vocabularyType
) {
175 TermVocabulary
<DefinedTermBase
> vocabulary
= getDefault().getTermVocabulary(vocabularyType
);
177 getDefault().getTermService().saveTermVocabulary(vocabulary
);
182 /*************** internal methods **************************/
184 private static Language
getDefaultLanguage(){
185 return CdmStore
.getDefaultLanguage();
188 private OrderedTermVocabulary
<?
extends OrderedTermBase
> getOrderedTermVocabulary(VocabularyEnum vocabularyType
){
189 TermVocabulary
<DefinedTermBase
> vocabulary
= getTermVocabulary(vocabularyType
);
190 return HibernateProxyHelper
.deproxy(vocabulary
, OrderedTermVocabulary
.class);
193 private TermVocabulary
<DefinedTermBase
> getTermVocabulary(VocabularyEnum vocabularyType
){
194 return getTermService().getVocabulary(vocabularyType
);
197 private ITermService
getTermService(){
198 return getApplicationController().getTermService();
201 private CdmApplicationController
getApplicationController(){
202 return CdmStore
.getApplicationController();