ref #1444, ref #7976 better logging for unhandled unacceptReason
[cdmlib-apps.git] / cdm-pesi / src / main / java / eu / etaxonomy / cdm / io / pesi / erms / ErmsImportState.java
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 private String unacceptReason;
43
44 @Override
45 public void initialize(ErmsImportConfigurator config) {
46 // super(config);
47 String tableName = "WebMarkerCategory_";
48 //webMarkerCategory
49 dbCdmDefTermMap.put(tableName + 1, MarkerType.COMPLETE());
50 }
51
52 public ErmsImportState(ErmsImportConfigurator config) {
53 super(config);
54 }
55
56 public Map<String, DefinedTermBase> getDbCdmDefinedTermMap(){
57 return this.dbCdmDefTermMap;
58 }
59
60 public void putDefinedTermToMap(String tableName, String id, DefinedTermBase term){
61 this.dbCdmDefTermMap.put(tableName + "_" + id, term);
62 }
63
64 public void putDefinedTermToMap(String tableName, int id, DefinedTermBase term){
65 putDefinedTermToMap(tableName, String.valueOf(id), term);
66 }
67
68 @Override
69 public User getUser(String username){
70 return usernameMap.get(username);
71 }
72
73 @Override
74 public void putUser(String username, User user){
75 usernameMap.put(username, user);
76 }
77
78 public void setRankMap(Map<Integer, Map<Integer,Rank>> rankMap) {
79 this.rankMap = rankMap;
80 }
81
82 /**
83 * Returns the CDM rank depending on the ERMS rankId and the ERMS kingdomId. Returns <code>
84 * null</code> if the rank does not exist.
85 * Throws a RuntimeException if the rank map has not been initialized before.
86 * @param rankId
87 * @param kingdomId
88 * @return
89 * @throws RuntimeException
90 **/
91 public Rank getRank (int rankId, int kingdomId){
92 Rank result = null;
93 if (this.rankMap == null){
94 throw new RuntimeException("rank map not initialized");
95 }
96 if (kingdomId == 147415 && rankId == 10){
97 result = Rank.KINGDOM();
98 }else if (kingdomId ==1 && rankId == 0 ){
99 return Rank.DOMAIN(); //maybe should be Superdomain
100 }else{
101 Map<Integer, Rank> kingdomMap = rankMap.get(rankId);
102 if (kingdomMap != null){
103 result = kingdomMap.get(kingdomId);
104 }
105 }
106 return result;
107 }
108
109 public Set<Integer> getAcceptedTaxaKeys() {
110 return acceptedTaxaKeys;
111 }
112 public void setAcceptedTaxaKeys(Set<Integer> acceptedTaxaKeys) {
113 this.acceptedTaxaKeys = acceptedTaxaKeys;
114 }
115
116 public String getUnhandledUnacceptReason() {
117 return this.unacceptReason;
118 }
119 public void setUnhandledUnacceptReason(String unacceptReason) {
120 this.unacceptReason = unacceptReason;
121 }
122 }