Project

General

Profile

Download (2.97 KB) Statistics
| Branch: | Tag: | Revision:
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.common.DefinedTerm;
19
import eu.etaxonomy.cdm.model.common.TermType;
20
import eu.etaxonomy.cdm.model.common.TermVocabulary;
21
import eu.etaxonomy.cdm.model.description.Feature;
22
import eu.etaxonomy.cdm.model.description.FeatureTree;
23
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25
import eu.etaxonomy.taxeditor.store.TermStore;
26

    
27

    
28

    
29
/**
30
 * @author n.hoffmann
31
 * @date Jan 24, 2012
32
 *
33
 */
34
public class TermEditorInput extends AbstractDefinedTermEditorInput<DefinedTerm> {
35

    
36
	private TermType termType;
37
	private Set<TermVocabularyDto> vocabularies;
38

    
39
	// FIXME: the default feature should be move to CdmApplicationState
40
	//        where it is a singleton instance variable
41
	private static FeatureTree defaultFeatureTree = null;
42

    
43
	private List<String> termClasses = Arrays.asList(new String[]{
44
			DefinedTerm.class.getName()
45
	});
46

    
47
	public TermEditorInput(TermType termType) {
48
		this.termType = termType;
49
		vocabularies = new HashSet<TermVocabularyDto>();
50
		initialiseVocabularies();
51
	}
52
	public String getName() {
53
		return termType.getMessage();
54
	}
55

    
56
	@Override
57
	public List<String> getTermClasses() {
58
		return termClasses;
59
	}
60

    
61
	public TermType getTermType() {
62
		return termType;
63
	}
64

    
65
	public void initialiseVocabularies() {
66
		if(vocabularies != null) {
67
			vocabularies.clear();
68
		}
69
		List<TermVocabularyDto> vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(termType);
70
		vocabularies.addAll(vocs);
71
	}
72

    
73
	public Set<TermVocabularyDto> getVocabularies() {
74
		return vocabularies;
75
	}
76

    
77
	public void updateDefaultFeatureTree() {
78
	    for(TermVocabularyDto vocab : getVocabularies()) {
79
	        if(vocab != null && TermType.Feature.equals(vocab.getTermType())) {
80
	            defaultFeatureTree = null;
81
	            return;
82
	        }
83
	    }
84
	}
85

    
86
	@Override
87
    public Set<TermVocabularyDto>  getRootEntities() {
88
        return getVocabularies();
89
    }
90

    
91
	@Override
92
    public void merge() {
93
	    List<TermVocabulary> vocabularies = new ArrayList<>();
94
	    getRootEntities().forEach(vocDto->vocabularies.add(CdmStore.getService(IVocabularyService.class).load(vocDto.getUuid())));
95
        CdmStore.getService(IVocabularyService.class).merge(vocabularies, true);
96
        updateDefaultFeatureTree();
97
    }
98

    
99
    public static FeatureTree getDefaultFeatureTree() {
100
        if(defaultFeatureTree == null) {
101
            defaultFeatureTree = FeatureTree.NewInstance(TermStore.getTerms(Feature.class));
102
        }
103
        return defaultFeatureTree;
104
    }
105
}
(2-2/2)