Project

General

Profile

Download (3.16 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
29
        extends DbImportStateBase<ErmsImportConfigurator, ErmsImportState>{
30

    
31
    @SuppressWarnings("unused")
32
	private static final Logger logger = Logger.getLogger(ErmsImportState.class);
33

    
34
	private Map<String, DefinedTermBase> dbCdmDefTermMap = new HashMap<>();
35

    
36
	private Map<String, User> usernameMap = new HashMap<>();
37

    
38
	private Map<Integer, Map<Integer,Rank>> rankMap;
39

    
40
	private Set<Integer> acceptedTaxaKeys;
41

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

    
50
	public ErmsImportState(ErmsImportConfigurator config) {
51
		super(config);
52
	}
53

    
54
	public Map<String, DefinedTermBase> getDbCdmDefinedTermMap(){
55
		return this.dbCdmDefTermMap;
56
	}
57

    
58
	public void putDefinedTermToMap(String tableName, String id, DefinedTermBase term){
59
		 this.dbCdmDefTermMap.put(tableName + "_" + id, term);
60
	}
61

    
62
	public void putDefinedTermToMap(String tableName, int id, DefinedTermBase term){
63
		putDefinedTermToMap(tableName, String.valueOf(id), term);
64
	}
65

    
66
	@Override
67
    public User getUser(String username){
68
		return usernameMap.get(username);
69
	}
70

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

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

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

    
107
	public Set<Integer> getAcceptedTaxaKeys() {
108
		return acceptedTaxaKeys;
109
	}
110
	public void setAcceptedTaxaKeys(Set<Integer> acceptedTaxaKeys) {
111
		this.acceptedTaxaKeys = acceptedTaxaKeys;
112
	}
113
}
(7-7/17)