Project

General

Profile

Download (3.03 KB) Statistics
| Branch: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
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.
9
*/
10

    
11
package eu.etaxonomy.cdm.io.pesi.indexFungorum;
12

    
13
import java.util.HashMap;
14
import java.util.Map;
15

    
16
import org.apache.log4j.Logger;
17

    
18
import eu.etaxonomy.cdm.io.common.DbImportStateBase;
19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20
import eu.etaxonomy.cdm.model.common.User;
21
import eu.etaxonomy.cdm.model.name.Rank;
22

    
23
/**
24
 * @author a.mueller
25
 * @created 11.05.2009
26
 * @version 1.0
27
 */
28
public class IndexFungorumImportState extends DbImportStateBase<IndexFungorumImportConfigurator, IndexFungorumImportState>{
29
	@SuppressWarnings("unused")
30
	private static final Logger logger = Logger.getLogger(IndexFungorumImportState.class);
31

    
32
	Map<String, DefinedTermBase> dbCdmDefTermMap = new HashMap<String, DefinedTermBase>();
33
	
34
	Map<String, User> usernameMap = new HashMap<String, User>();
35
	
36
	private Map<Integer, Map<Integer,Rank>> rankMap;
37

    
38
	public IndexFungorumImportState(IndexFungorumImportConfigurator config) {
39
		super(config);
40
	}
41

    
42
	
43
	/* (non-Javadoc)
44
	 * @see eu.etaxonomy.cdm.io.common.IoStateBase#initialize(eu.etaxonomy.cdm.io.common.IoConfiguratorBase)
45
	 */
46
	@Override
47
	public void initialize(IndexFungorumImportConfigurator config) {
48
//		super(config);
49
	}
50

    
51
	
52
	public Map<String, DefinedTermBase> getDbCdmDefinedTermMap(){
53
		return this.dbCdmDefTermMap;
54
	}
55
	
56
	public void putDefinedTermToMap(String tableName, String id, DefinedTermBase term){
57
		 this.dbCdmDefTermMap.put(tableName + "_" + id, term);
58
	}
59
	
60
	public void putDefinedTermToMap(String tableName, int id, DefinedTermBase term){
61
		putDefinedTermToMap(tableName, String.valueOf(id), term);
62
	}
63
	
64
	public User getUser(String username){
65
		return usernameMap.get(username);
66
	}
67

    
68
	public void putUser(String username, User user){
69
		usernameMap.put(username, user);
70
	}
71

    
72
	/**
73
	 * @param rankMap the rankMap to set
74
	 */
75
	public void setRankMap(Map<Integer, Map<Integer,Rank>> rankMap) {
76
		this.rankMap = rankMap;
77
	}
78

    
79
//	/**
80
//	 * @return the rankMap
81
//	 */
82
//	public Map<Integer, Map<Integer,Rank>> getRankMap() {
83
//		return rankMap;
84
//	}
85
	
86
 
87
	/**
88
	 * Returns the CDM rank depending on the ERMS rankId and the ERMS kingdomId. Returns <code>
89
	 * null</code> if the rank does not exist.
90
	 * Throws a RuntimeException if the rank map has not been initialized before.
91
	 * @param rankId
92
	 * @param kingdomId
93
	 * @return
94
	 * @throws RuntimeException
95
	 **/
96
	public Rank getRank (int rankId, int  kingdomId){
97
		Rank result = null;
98
		if (this.rankMap == null){
99
			throw new RuntimeException("rank map not initialized");
100
		}
101
		if (kingdomId == 147415 && rankId == 10){
102
			result = Rank.KINGDOM();
103
		}else{
104
			Map<Integer, Rank> kingdomMap = rankMap.get(rankId);
105
			if (kingdomMap != null){
106
				result = kingdomMap.get(kingdomId);
107
			}
108
		}
109
		return result;
110
	}
111

    
112
    
113
}
(6-6/9)