2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
.input
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Arrays
;
13 import java
.util
.HashSet
;
14 import java
.util
.List
;
17 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
18 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
19 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
20 import eu
.etaxonomy
.cdm
.model
.term
.FeatureTree
;
21 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
22 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
23 import eu
.etaxonomy
.cdm
.model
.term
.VocabularyEnum
;
24 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermVocabularyDto
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
26 import eu
.etaxonomy
.taxeditor
.store
.TermStore
;
35 public class TermEditorInput
extends AbstractDefinedTermEditorInput
<DefinedTerm
> {
37 private TermType termType
;
38 private Set
<TermVocabularyDto
> vocabularies
;
40 // FIXME: the default feature should be move to CdmApplicationState
41 // where it is a singleton instance variable
42 private static FeatureTree defaultFeatureTree
= null;
44 private List
<String
> termClasses
= Arrays
.asList(new String
[]{
45 DefinedTerm
.class.getName()
48 public TermEditorInput(TermType termType
) {
49 this.termType
= termType
;
50 vocabularies
= new HashSet
<TermVocabularyDto
>();
51 initialiseVocabularies();
53 public String
getName() {
54 return termType
.getMessage();
58 public List
<String
> getTermClasses() {
62 public TermType
getTermType() {
66 public void initialiseVocabularies() {
67 if(vocabularies
!= null) {
70 List
<TermVocabularyDto
> vocs
= CdmStore
.getService(IVocabularyService
.class).findVocabularyDtoByTermType(termType
);
71 vocabularies
.addAll(vocs
);
74 public Set
<TermVocabularyDto
> getVocabularies() {
78 public void updateDefaultFeatureTree() {
79 for(TermVocabularyDto vocab
: getVocabularies()) {
80 if(vocab
!= null && TermType
.Feature
.equals(vocab
.getTermType())) {
81 defaultFeatureTree
= null;
88 public Set
<TermVocabularyDto
> getRootEntities() {
89 return getVocabularies();
94 List
<TermVocabulary
> vocabularies
= new ArrayList
<>();
95 getRootEntities().forEach(vocDto
->vocabularies
.add(CdmStore
.getService(IVocabularyService
.class).load(vocDto
.getUuid())));
96 CdmStore
.getService(IVocabularyService
.class).merge(vocabularies
, true);
97 updateDefaultFeatureTree();
100 public static FeatureTree
getDefaultFeatureTree() {
101 if(defaultFeatureTree
== null) {
102 List
<Feature
> features
= TermStore
.getTerms(Feature
.class);
103 List
<Feature
> nameFeatures
= CdmStore
.getTermManager().getPreferredTerms(CdmStore
.getService(IVocabularyService
.class).load(VocabularyEnum
.NameFeature
.getUuid()), null);
104 List
<Feature
> copy
= new ArrayList(features
);
105 for (Feature feature
: copy
){
106 if (nameFeatures
.contains(feature
)){
107 features
.remove(feature
);
110 defaultFeatureTree
= FeatureTree
.NewInstance(features
);
112 return defaultFeatureTree
;