Project

General

Profile

« Previous | Next » 

Revision 8bc5f53a

Added by Andreas Müller over 16 years ago

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/init/DefaultVocabularyStore.java
11 11
import org.apache.log4j.Logger;
12 12

  
13 13
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
14
import eu.etaxonomy.cdm.model.common.ILoadableTerm;
14 15
import eu.etaxonomy.cdm.model.common.Language;
15 16
import eu.etaxonomy.cdm.model.common.TermVocabulary;
16 17

  
18
/**
19
 * @author AM
20
 *
21
 */
17 22
/**
18 23
 * @author AM
19 24
 *
......
28 33
	}
29 34
	
30 35
	
31
	static protected Map<UUID, DefinedTermBase> definedTermsMap = null;
36
	static protected Map<UUID, ILoadableTerm> definedTermsMap = null;
32 37
	static protected Map<UUID, TermVocabulary<DefinedTermBase>> termVocabularyMap = null;
33 38

  
34 39

  
35 40
	/* (non-Javadoc)
36 41
	 * @see eu.etaxonomy.cdm.model.common.init.IVocabularyStore#getTermByUuid(java.util.UUID)
37 42
	 */
38
	public DefinedTermBase getTermByUuid(UUID uuid) {
43
	public DefinedTermBase<DefinedTermBase> getTermByUuid(UUID uuid) {
39 44
		if (!isInitialized  &&  ! loadBasicTerms()){ return null;}
40
		return definedTermsMap.get(uuid);
45
		return (DefinedTermBase<DefinedTermBase>)definedTermsMap.get(uuid);
41 46
	}
42 47

  
43 48
	/* (non-Javadoc)
......
53 58
	 * @see eu.etaxonomy.cdm.model.common.init.IVocabularyStore#saveOrUpdate(eu.etaxonomy.cdm.model.common.TermVocabulary)
54 59
	 */
55 60
	public void saveOrUpdate(TermVocabulary<DefinedTermBase> vocabulary) {
61
		logger.info("dddd");
56 62
		loadBasicTerms();
57 63
		Iterator<DefinedTermBase> termIterator = vocabulary.iterator();
58

  
59 64
		while (termIterator.hasNext()){
60 65
			DefinedTermBase<DefinedTermBase> term = termIterator.next();
61 66
			if (definedTermsMap.get(term.getUuid()) != null){
......
66 71
		termVocabularyMap.put(vocabulary.getUuid(), vocabulary);
67 72
	}
68 73
	
74
	/* (non-Javadoc)
75
	 * @see eu.etaxonomy.cdm.model.common.init.IVocabularyStore#saveOrUpdate(eu.etaxonomy.cdm.model.common.TermVocabulary)
76
	 */
77
	public void saveOrUpdate(ILoadableTerm term) {
78
		loadBasicTerms();
79
		if (definedTermsMap.get(term.getUuid()) != null){
80
			term.setId(definedTermsMap.get(term.getUuid()).getId()); // to avoid duplicates in the default Language
81
		}
82
		definedTermsMap.put(term.getUuid(), term);
83
		termVocabularyMap.put(term.getVocabulary().getUuid(), term.getVocabulary());
84
	}
85
	
69 86
	
70 87
	public boolean loadBasicTerms() {
71 88
		if (definedTermsMap == null){
72 89
			logger.info("initTermsMap start ...");
73
			definedTermsMap = new HashMap<UUID, DefinedTermBase>();
90
			definedTermsMap = new HashMap<UUID, ILoadableTerm>();
74 91
			try {
75 92
				definedTermsMap.put(DEFAULT_LANGUAGE().getUuid(), DEFAULT_LANGUAGE());
76 93
				TermLoader termLoader = new TermLoader(this);

Also available in: Unified diff