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
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
23
|
|
24
|
/**
|
25
|
* @author a.mueller
|
26
|
* @created 11.05.2009
|
27
|
* @version 1.0
|
28
|
*/
|
29
|
public class IndexFungorumImportState extends DbImportStateBase<IndexFungorumImportConfigurator, IndexFungorumImportState>{
|
30
|
@SuppressWarnings("unused")
|
31
|
private static final Logger logger = Logger.getLogger(IndexFungorumImportState.class);
|
32
|
|
33
|
Map<String, DefinedTermBase> dbCdmDefTermMap = new HashMap<String, DefinedTermBase>();
|
34
|
|
35
|
Map<String, User> usernameMap = new HashMap<String, User>();
|
36
|
|
37
|
private Map<Integer, Map<Integer,Rank>> rankMap;
|
38
|
|
39
|
private Map<String, TaxonBase> speciesMap;
|
40
|
|
41
|
|
42
|
|
43
|
|
44
|
public IndexFungorumImportState(IndexFungorumImportConfigurator config) {
|
45
|
super(config);
|
46
|
}
|
47
|
|
48
|
|
49
|
/* (non-Javadoc)
|
50
|
* @see eu.etaxonomy.cdm.io.common.IoStateBase#initialize(eu.etaxonomy.cdm.io.common.IoConfiguratorBase)
|
51
|
*/
|
52
|
@Override
|
53
|
public void initialize(IndexFungorumImportConfigurator config) {
|
54
|
// super(config);
|
55
|
}
|
56
|
|
57
|
|
58
|
public Map<String, DefinedTermBase> getDbCdmDefinedTermMap(){
|
59
|
return this.dbCdmDefTermMap;
|
60
|
}
|
61
|
|
62
|
public void putDefinedTermToMap(String tableName, String id, DefinedTermBase term){
|
63
|
this.dbCdmDefTermMap.put(tableName + "_" + id, term);
|
64
|
}
|
65
|
|
66
|
public void putDefinedTermToMap(String tableName, int id, DefinedTermBase term){
|
67
|
putDefinedTermToMap(tableName, String.valueOf(id), term);
|
68
|
}
|
69
|
|
70
|
@Override
|
71
|
public User getUser(String username){
|
72
|
return usernameMap.get(username);
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public void putUser(String username, User user){
|
77
|
usernameMap.put(username, user);
|
78
|
}
|
79
|
/**
|
80
|
* @return the speciesMap
|
81
|
*/
|
82
|
public Map<String, TaxonBase> getSpeciesMap() {
|
83
|
return speciesMap;
|
84
|
}
|
85
|
|
86
|
|
87
|
/**
|
88
|
* @param speciesMap the speciesMap to set
|
89
|
*/
|
90
|
public void setSpeciesMap(Map<String, TaxonBase> speciesMap) {
|
91
|
this.speciesMap = speciesMap;
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* @param rankMap the rankMap to set
|
96
|
*/
|
97
|
public void setRankMap(Map<Integer, Map<Integer,Rank>> rankMap) {
|
98
|
this.rankMap = rankMap;
|
99
|
}
|
100
|
|
101
|
// /**
|
102
|
// * @return the rankMap
|
103
|
// */
|
104
|
// public Map<Integer, Map<Integer,Rank>> getRankMap() {
|
105
|
// return rankMap;
|
106
|
// }
|
107
|
|
108
|
|
109
|
/**
|
110
|
* Returns the CDM rank depending on the ERMS rankId and the ERMS kingdomId. Returns <code>
|
111
|
* null</code> if the rank does not exist.
|
112
|
* Throws a RuntimeException if the rank map has not been initialized before.
|
113
|
* @param rankId
|
114
|
* @param kingdomId
|
115
|
* @return
|
116
|
* @throws RuntimeException
|
117
|
**/
|
118
|
public Rank getRank (int rankId, int kingdomId){
|
119
|
Rank result = null;
|
120
|
if (this.rankMap == null){
|
121
|
throw new RuntimeException("rank map not initialized");
|
122
|
}
|
123
|
if (kingdomId == 147415 && rankId == 10){
|
124
|
result = Rank.KINGDOM();
|
125
|
}else{
|
126
|
Map<Integer, Rank> kingdomMap = rankMap.get(rankId);
|
127
|
if (kingdomMap != null){
|
128
|
result = kingdomMap.get(kingdomId);
|
129
|
}
|
130
|
}
|
131
|
return result;
|
132
|
}
|
133
|
|
134
|
|
135
|
}
|