final commit of Taraxacum import on behalf of anahit
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / common / ImportStateBase.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.common;
12
13 import java.util.HashMap;
14 import java.util.Map;
15 import java.util.UUID;
16
17 import org.apache.log4j.Logger;
18
19 import eu.etaxonomy.cdm.api.service.IService;
20 import eu.etaxonomy.cdm.model.agent.Person;
21 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
22 import eu.etaxonomy.cdm.model.common.CdmBase;
23 import eu.etaxonomy.cdm.model.common.User;
24 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
25 import eu.etaxonomy.cdm.model.occurrence.Specimen;
26 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
27 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
28 import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;
29
30 /**
31 * @author a.mueller
32 * @created 11.05.2009
33 * @version 1.0
34 */
35 public abstract class ImportStateBase<CONFIG extends ImportConfiguratorBase> extends IoStateBase<CONFIG> {
36 @SuppressWarnings("unused")
37 private static final Logger logger = Logger.getLogger(ImportStateBase.class);
38
39 private Map<Object,TaxonomicTree> treeMap = new HashMap<Object,TaxonomicTree>();
40
41 private Map<ReferenceBase,UUID> treeUuidMap = new HashMap<ReferenceBase,UUID>();
42
43
44 protected ImportStateBase(CONFIG config){
45 this.config = config;
46 stores.put(ICdmIO.USER_STORE, new MapWrapper<User>(service));
47 stores.put(ICdmIO.PERSON_STORE, new MapWrapper<Person>(service));
48 stores.put(ICdmIO.TEAM_STORE, new MapWrapper<TeamOrPersonBase<?>>(service));
49 stores.put(ICdmIO.REFERENCE_STORE, new MapWrapper<ReferenceBase>(service));
50 stores.put(ICdmIO.NOMREF_STORE, new MapWrapper<ReferenceBase>(service));
51 stores.put(ICdmIO.NOMREF_DETAIL_STORE, new MapWrapper<ReferenceBase>(service));
52 stores.put(ICdmIO.REF_DETAIL_STORE, new MapWrapper<ReferenceBase>(service));
53 stores.put(ICdmIO.TAXONNAME_STORE, new MapWrapper<TaxonNameBase<?,?>>(service));
54 stores.put(ICdmIO.TAXON_STORE, new MapWrapper<TaxonBase>(service));
55 stores.put(ICdmIO.SPECIMEN_STORE, new MapWrapper<Specimen>(service));
56 }
57
58 //different type of stores that are used by the known imports
59 protected Map<String, MapWrapper<? extends CdmBase>> stores = new HashMap<String, MapWrapper<? extends CdmBase>>();
60
61 protected IService<CdmBase> service = null;
62
63 /**
64 * @return the stores
65 */
66 public Map<String, MapWrapper<? extends CdmBase>> getStores() {
67 return stores;
68 }
69
70 /**
71 * @param stores the stores to set
72 */
73 public void setStores(Map<String, MapWrapper<? extends CdmBase>> stores) {
74 this.stores = stores;
75 }
76
77
78 public MapWrapper<? extends CdmBase> getStore(String storeLabel){
79 return (MapWrapper<? extends CdmBase>) stores.get(storeLabel);
80 }
81
82
83 /**
84 * @return the treeMap
85 */
86 public TaxonomicTree getTree(Object ref) {
87 return treeMap.get(ref);
88 }
89
90 /**
91 * @param treeMap the treeMap to set
92 */
93 public void putTree(Object ref, TaxonomicTree tree) {
94 if (tree != null){
95 this.treeMap.put(ref, tree);
96 }
97 }
98
99 public int countTrees(){
100 return treeUuidMap.size();
101 }
102
103 /**
104 * @return the treeUuid
105 */
106 public UUID getTreeUuid(ReferenceBase ref) {
107 return treeUuidMap.get(ref);
108 }
109
110 public void putTreeUuid(ReferenceBase ref, TaxonomicTree tree) {
111 if (tree != null && tree.getUuid() != null){
112 this.treeUuidMap.put(ref, tree.getUuid());
113 }
114 }
115
116 public int countTreeUuids(){
117 return treeUuidMap.size();
118 }
119 }