Project

General

Profile

Download (3.05 KB) Statistics
| Branch: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.cdm.io.pesi.erms;
11

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

    
16
import org.apache.log4j.Logger;
17

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

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

    
32
	private Map<String, DefinedTermBase> dbCdmDefTermMap = new HashMap<>();
33

    
34
	private Map<String, User> usernameMap = new HashMap<>();
35

    
36
	private Map<Integer, Map<Integer,Rank>> rankMap;
37

    
38
	private Set<Integer> acceptedTaxaKeys;
39

    
40
	@Override
41
	public void initialize(ErmsImportConfigurator config) {
42
//		super(config);
43
		String tableName = "WebMarkerCategory_";
44
		//webMarkerCategory
45
		dbCdmDefTermMap.put(tableName + 1, MarkerType.COMPLETE());
46
	}
47

    
48
	public ErmsImportState(ErmsImportConfigurator config) {
49
		super(config);
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
	@Override
65
    public User getUser(String username){
66
		return usernameMap.get(username);
67
	}
68

    
69
	@Override
70
    public void putUser(String username, User user){
71
		usernameMap.put(username, user);
72
	}
73

    
74
	public void setRankMap(Map<Integer, Map<Integer,Rank>> rankMap) {
75
		this.rankMap = rankMap;
76
	}
77

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

    
103
	public Set<Integer> getAcceptedTaxaKeys() {
104
		return acceptedTaxaKeys;
105
	}
106

    
107
	public void setAcceptedTaxaKeys(Set<Integer> acceptedTaxaKeys) {
108
		this.acceptedTaxaKeys = acceptedTaxaKeys;
109
	}
110

    
111

    
112
}
(7-7/17)