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 org
.apache
.log4j
.Logger
;
18 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
19 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
20 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
21 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
22 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
23 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermBase
;
24 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermVocabulary
;
25 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
26 import eu
.etaxonomy
.cdm
.model
.common
.VocabularyEnum
;
27 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
28 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
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
;
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
44 public class VocabularyStore
{
45 private static final Logger logger
= Logger
.getLogger(VocabularyStore
.class);
48 * The singleton instance
50 private static VocabularyStore instance
;
53 * Retrieve the singleton instance
57 private static synchronized VocabularyStore
getDefault(){
59 instance
= new VocabularyStore();
68 public static SortedSet
<SpecimenTypeDesignationStatus
> getSpecimenTypeDesignationStatus() {
69 SortedSet specimenTypeDesignationStatus
= getDefault().getTermVocabulary(VocabularyEnum
.SpecimenTypeDesignationStatus
).getTermsOrderedByLabels(getDefaultLanguage());
70 return specimenTypeDesignationStatus
;
77 public static SortedSet
<TaxonRelationshipType
> getTaxonRelationshipTypes(){
78 SortedSet taxonRelationshipTypes
= getDefault().getOrderedTermVocabulary(VocabularyEnum
.TaxonRelationshipType
).getOrderedTerms();
79 return taxonRelationshipTypes
;
86 public static SortedSet
<TaxonRelationshipType
> getConceptRelationshipTypes() {
87 SortedSet
<TaxonRelationshipType
> conceptRelationshipTypes
= getTaxonRelationshipTypes();
88 // remove these two relations as they are considered standard taxon relations
89 conceptRelationshipTypes
.remove(TaxonRelationshipType
.MISAPPLIED_NAME_FOR());
90 conceptRelationshipTypes
.remove(TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN());
92 return conceptRelationshipTypes
;
99 public static SortedSet
<Language
> getLanguages(){
100 SortedSet languages
= getDefault().getTermVocabulary(VocabularyEnum
.Language
).getTermsOrderedByLabels(getDefaultLanguage());
108 public static SortedSet
<Feature
> getFeatures() {
109 SortedSet features
= getDefault().getTermVocabulary(VocabularyEnum
.Feature
).getTermsOrderedByLabels(getDefaultLanguage());
118 public static SortedSet
<NameRelationshipType
> getNameRelationshipTypes() {
119 SortedSet nameRelationshipTypes
= getDefault().getTermVocabulary(VocabularyEnum
.NameRelationshipType
).getTermsOrderedByLabels(getDefaultLanguage());
120 return nameRelationshipTypes
;
127 public static Set
<NomenclaturalStatusType
> getNomenclaturalStatusTypes(){
129 Set nomenclaturalStatusTypes
= getDefault().getTermVocabulary(VocabularyEnum
.NomenclaturalStatusType
).getTermsOrderedByLabels(getDefaultLanguage());
130 return nomenclaturalStatusTypes
;
134 * Retrieve all ranks from data store.
138 public static SortedSet
<Rank
> getRanks(){
139 SortedSet ranks
= getDefault().getOrderedTermVocabulary(VocabularyEnum
.Rank
).getOrderedTerms();
145 * Retrieve all presence and absence terms from data store.
149 public static SortedSet
<PresenceAbsenceTermBase
<PresenceAbsenceTermBase
<?
>>> getPresenceAbsenceTerms() {
150 SortedSet presenceAbsenceTerms
= getDefault().getTermVocabulary(VocabularyEnum
.PresenceTerm
).getTermsOrderedByLabels(getDefaultLanguage());
151 presenceAbsenceTerms
.addAll(getDefault().getTermVocabulary(VocabularyEnum
.AbsenceTerm
).getTermsOrderedByLabels(getDefaultLanguage()));
153 return presenceAbsenceTerms
;
156 /*************** save methods ******************************/
158 * Adds a term to a vocabulary
162 public static void saveTerm(DefinedTermBase term
, VocabularyEnum vocabularyType
) {
163 TermVocabulary
<DefinedTermBase
> vocabulary
= getDefault().getTermVocabulary(vocabularyType
);
165 vocabulary
.addTerm(term
);
167 getDefault().getTermService().saveTermVocabulary(vocabulary
);
171 * Save a vacabulary to data store
175 public static void updateVocabulary(VocabularyEnum vocabularyType
) {
176 TermVocabulary
<DefinedTermBase
> vocabulary
= getDefault().getTermVocabulary(vocabularyType
);
178 getDefault().getTermService().saveTermVocabulary(vocabulary
);
183 /*************** internal methods **************************/
185 private static Language
getDefaultLanguage(){
186 return CdmStore
.getDefaultLanguage();
189 private OrderedTermVocabulary
<?
extends OrderedTermBase
> getOrderedTermVocabulary(VocabularyEnum vocabularyType
){
190 TermVocabulary
<DefinedTermBase
> vocabulary
= getTermVocabulary(vocabularyType
);
191 return HibernateProxyHelper
.deproxy(vocabulary
, OrderedTermVocabulary
.class);
194 private TermVocabulary
<DefinedTermBase
> getTermVocabulary(VocabularyEnum vocabularyType
){
195 return getTermService().getVocabulary(vocabularyType
);
198 private ITermService
getTermService(){
199 return getApplicationController().getTermService();
202 private CdmApplicationController
getApplicationController(){
203 return CdmStore
.getApplicationController();