1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.editor.definedterm.input;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
16
|
|
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;
|
27
|
|
28
|
|
29
|
|
30
|
/**
|
31
|
* @author n.hoffmann
|
32
|
* @date Jan 24, 2012
|
33
|
*
|
34
|
*/
|
35
|
public class TermEditorInput extends AbstractDefinedTermEditorInput<DefinedTerm> {
|
36
|
|
37
|
private TermType termType;
|
38
|
private Set<TermVocabularyDto> vocabularies;
|
39
|
|
40
|
// FIXME: the default feature should be move to CdmApplicationState
|
41
|
// where it is a singleton instance variable
|
42
|
private static FeatureTree defaultFeatureTree = null;
|
43
|
|
44
|
private List<String> termClasses = Arrays.asList(new String[]{
|
45
|
DefinedTerm.class.getName()
|
46
|
});
|
47
|
|
48
|
public TermEditorInput(TermType termType) {
|
49
|
this.termType = termType;
|
50
|
vocabularies = new HashSet<TermVocabularyDto>();
|
51
|
initialiseVocabularies();
|
52
|
}
|
53
|
public String getName() {
|
54
|
return termType.getMessage();
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public List<String> getTermClasses() {
|
59
|
return termClasses;
|
60
|
}
|
61
|
|
62
|
public TermType getTermType() {
|
63
|
return termType;
|
64
|
}
|
65
|
|
66
|
public void initialiseVocabularies() {
|
67
|
if(vocabularies != null) {
|
68
|
vocabularies.clear();
|
69
|
}
|
70
|
List<TermVocabularyDto> vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(termType);
|
71
|
vocabularies.addAll(vocs);
|
72
|
}
|
73
|
|
74
|
public Set<TermVocabularyDto> getVocabularies() {
|
75
|
return vocabularies;
|
76
|
}
|
77
|
|
78
|
public void updateDefaultFeatureTree() {
|
79
|
for(TermVocabularyDto vocab : getVocabularies()) {
|
80
|
if(vocab != null && TermType.Feature.equals(vocab.getTermType())) {
|
81
|
defaultFeatureTree = null;
|
82
|
return;
|
83
|
}
|
84
|
}
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
public Set<TermVocabularyDto> getRootEntities() {
|
89
|
return getVocabularies();
|
90
|
}
|
91
|
|
92
|
@Override
|
93
|
public void merge() {
|
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();
|
98
|
}
|
99
|
|
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);
|
108
|
}
|
109
|
}
|
110
|
defaultFeatureTree = FeatureTree.NewInstance(features);
|
111
|
}
|
112
|
return defaultFeatureTree;
|
113
|
}
|
114
|
}
|