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
.HashSet
;
15 import java
.util
.SortedSet
;
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
;
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
{
50 public static SortedSet
<SpecimenTypeDesignationStatus
> getSpecimenTypeDesignationStatus() {
51 SortedSet specimenTypeDesignationStatus
= getTermVocabulary(VocabularyEnum
.SpecimenTypeDesignationStatus
).getTermsOrderedByLabels(CdmStore
.getDefaultLanguage());
52 return specimenTypeDesignationStatus
;
59 public static SortedSet
<SpecimenTypeDesignationStatus
> getNameTypeDesignationStatus() {
60 SortedSet nameTypeDesignationStatus
= getTermVocabulary(VocabularyEnum
.NameTypeDesignationStatus
).getTermsOrderedByLabels(CdmStore
.getDefaultLanguage());
61 return nameTypeDesignationStatus
;
68 public static SortedSet
<TaxonRelationshipType
> getTaxonRelationshipTypes(){
69 SortedSet taxonRelationshipTypes
= getOrderedTermVocabulary(VocabularyEnum
.TaxonRelationshipType
).getOrderedTerms();
70 return taxonRelationshipTypes
;
77 * @deprecated handle via preferences
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());
85 return conceptRelationshipTypes
;
92 public static Set
<Language
> getLanguages(){
94 Set languages
= getTermVocabulary(VocabularyEnum
.Language
).getTerms();
96 // SortedSet languages = getDefault().getTermVocabulary(VocabularyEnum.Language).getTermsOrderedByLabels(getDefaultLanguage());
100 public static SortedSet
<?
extends DefinedTermBase
> getTerms(VocabularyEnum vocabularyType
){
102 TermVocabulary
<DefinedTermBase
> terms
= getTermVocabulary(vocabularyType
);
105 return terms
.getTermsOrderedByLabels(CdmStore
.getDefaultLanguage());
113 public static void delete(DefinedTermBase selected
) {
114 CdmStore
.getTermService().delete(selected
);
120 public static SortedSet
<Feature
> getFeatures() {
121 SortedSet features
= getTermVocabulary(VocabularyEnum
.Feature
).getTermsOrderedByLabels(CdmStore
.getDefaultLanguage());
122 features
.remove(Feature
.IMAGE());
131 public static SortedSet
<NameRelationshipType
> getNameRelationshipTypes() {
132 SortedSet nameRelationshipTypes
= getTermVocabulary(VocabularyEnum
.NameRelationshipType
).getTermsOrderedByLabels(CdmStore
.getDefaultLanguage());
133 return nameRelationshipTypes
;
140 public static Set
<NomenclaturalStatusType
> getNomenclaturalStatusTypes(){
142 Set nomenclaturalStatusTypes
= getTermVocabulary(VocabularyEnum
.NomenclaturalStatusType
).getTermsOrderedByLabels(CdmStore
.getDefaultLanguage());
143 return nomenclaturalStatusTypes
;
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
);
159 return nonTechnicalMarkerTypes
;
166 public static Set
<ExtensionType
> getExtensionTypes() {
167 Set extensionTypes
= getTermVocabulary(VocabularyEnum
.ExtensionType
).getTermsOrderedByLabels(CdmStore
.getDefaultLanguage());
168 return extensionTypes
;
174 public static Set
<RightsTerm
> getRightsTypes() {
175 Set rightsTypes
= getTermVocabulary(VocabularyEnum
.RightsTerm
).getTermsOrderedByLabels(CdmStore
.getDefaultLanguage());
181 * Retrieve all ranks from data store.
185 public static SortedSet
<Rank
> getRanks(){
186 SortedSet ranks
= getOrderedTermVocabulary(VocabularyEnum
.Rank
).getOrderedTerms();
192 * Retrieve all presence and absence terms from data store.
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()));
200 return presenceAbsenceTerms
;
204 /*************** save methods ******************************/
206 * Adds a term to a vocabulary
210 public static void saveTerm(DefinedTermBase term
, VocabularyEnum vocabularyType
) {
211 TermVocabulary
<DefinedTermBase
> vocabulary
= getTermVocabulary(vocabularyType
);
212 vocabulary
.addTerm(term
);
214 CdmStore
.getVocabularyService().save(vocabulary
);
218 * Save a vacabulary to data store
222 public static void updateVocabulary(DefinedTermBase term
) {
223 CdmStore
.getTermService().save(term
);
228 /*************** internal methods **************************/
230 private static Language
getDefaultLanguage(){
231 return CdmStore
.getDefaultLanguage();
234 private static OrderedTermVocabulary
<?
extends OrderedTermBase
> getOrderedTermVocabulary(VocabularyEnum vocabularyType
){
235 TermVocabulary
<DefinedTermBase
> vocabulary
= getTermVocabulary(vocabularyType
);
236 return HibernateProxyHelper
.deproxy(vocabulary
, OrderedTermVocabulary
.class);
239 public static TermVocabulary
<DefinedTermBase
> getTermVocabulary(VocabularyEnum vocabularyType
){
240 return CdmStore
.getVocabularyService().getVocabulary(vocabularyType
);