Unifiy name and taxon creation
[cdmlib-apps.git] / app-import / src / main / java / eu / etaxonomy / cdm / io / globis / GlobisImportState.java
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.globis;
12
13 import java.util.HashMap;
14 import java.util.HashSet;
15 import java.util.Map;
16 import java.util.Set;
17
18 import org.apache.log4j.Logger;
19
20 import eu.etaxonomy.cdm.io.common.DbImportStateBase;
21 import eu.etaxonomy.cdm.model.agent.AgentBase;
22 import eu.etaxonomy.cdm.model.agent.Person;
23 import eu.etaxonomy.cdm.model.agent.Team;
24 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
25 import eu.etaxonomy.cdm.model.common.MarkerType;
26 import eu.etaxonomy.cdm.model.common.User;
27 import eu.etaxonomy.cdm.model.name.Rank;
28
29 /**
30 * @author a.mueller
31 * @created 11.05.2009
32 * @version 1.0
33 */
34 public class GlobisImportState extends DbImportStateBase<GlobisImportConfigurator, GlobisImportState>{
35 @SuppressWarnings("unused")
36 private static final Logger logger = Logger.getLogger(GlobisImportState.class);
37
38 private Map<String, DefinedTermBase> dbCdmDefTermMap = new HashMap<String, DefinedTermBase>();
39
40 private Map<String, User> usernameMap = new HashMap<String, User>();
41
42 private Map<Integer, Map<Integer,Rank>> rankMap;
43
44 private Map<String, Person> personMap = new HashMap<String, Person>();
45
46 private Map<String, Team> teamMap = new HashMap<String, Team>();
47
48
49
50 @Override
51 public void initialize(GlobisImportConfigurator config) {
52 // super(config);
53 String tableName = "WebMarkerCategory_";
54 //webMarkerCategory
55 dbCdmDefTermMap.put(tableName + 1, MarkerType.COMPLETE());
56 }
57
58 public GlobisImportState(GlobisImportConfigurator config) {
59 super(config);
60 }
61
62 public Map<String, DefinedTermBase> getDbCdmDefinedTermMap(){
63 return this.dbCdmDefTermMap;
64 }
65
66 public void putDefinedTermToMap(String tableName, String id, DefinedTermBase term){
67 this.dbCdmDefTermMap.put(tableName + "_" + id, term);
68 }
69
70 public void putDefinedTermToMap(String tableName, int id, DefinedTermBase term){
71 putDefinedTermToMap(tableName, String.valueOf(id), term);
72 }
73
74 public User getUser(String username){
75 return usernameMap.get(username);
76 }
77
78 public void putUser(String username, User user){
79 usernameMap.put(username, user);
80 }
81
82 /**
83 * @param rankMap the rankMap to set
84 */
85 public void setRankMap(Map<Integer, Map<Integer,Rank>> rankMap) {
86 this.rankMap = rankMap;
87 }
88
89 // /**
90 // * @return the rankMap
91 // */
92 // public Map<Integer, Map<Integer,Rank>> getRankMap() {
93 // return rankMap;
94 // }
95
96
97 /**
98 * Returns the CDM rank depending on the ERMS rankId and the ERMS kingdomId. Returns <code>
99 * null</code> if the rank does not exist.
100 * Throws a RuntimeException if the rank map has not been initialized before.
101 * @param rankId
102 * @param kingdomId
103 * @return
104 * @throws RuntimeException
105 **/
106 public Rank getRank (int rankId, int kingdomId){
107 Rank result = null;
108 if (this.rankMap == null){
109 throw new RuntimeException("rank map not initialized");
110 }
111 Map<Integer, Rank> kingdomMap = rankMap.get(rankId);
112 if (kingdomMap != null){
113 result = kingdomMap.get(kingdomId);
114 }
115 return result;
116 }
117
118 public void putPerson(String str, Person person){
119 personMap.put(str, person);
120 }
121
122
123 public Person getPerson(String str){
124 return personMap.get(str);
125 }
126
127
128 public void putTeam(String str, Team team){
129 teamMap.put(str, team);
130 }
131
132
133 public Team getTeam(String str){
134 return teamMap.get(str);
135 }
136
137 public Set<AgentBase> getAgents(){
138 Set<AgentBase> result = new HashSet<AgentBase>();
139 result.addAll(personMap.values());
140 result.addAll(teamMap.values());
141 return result;
142 }
143
144 }