2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.redlist
.gefaesspflanzen
;
12 import java
.sql
.ResultSet
;
13 import java
.sql
.SQLException
;
14 import java
.util
.HashMap
;
15 import java
.util
.HashSet
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.springframework
.stereotype
.Component
;
22 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
23 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
24 import eu
.etaxonomy
.cdm
.io
.common
.DbImportBase
;
25 import eu
.etaxonomy
.cdm
.io
.common
.IPartitionedIO
;
26 import eu
.etaxonomy
.cdm
.io
.common
.ImportHelper
;
27 import eu
.etaxonomy
.cdm
.io
.common
.ResultSetPartitioner
;
28 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.UndefinedTransformerMethodException
;
29 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
30 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
31 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
32 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
33 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
43 @SuppressWarnings("serial")
44 public class RedListGefaesspflanzenImportNames
extends DbImportBase
<RedListGefaesspflanzenImportState
, RedListGefaesspflanzenImportConfigurator
> {
45 private static final Logger logger
= Logger
.getLogger(RedListGefaesspflanzenImportNames
.class);
47 private static final String tableName
= "Rote Liste Gefäßpflanzen";
49 private static final String pluralString
= "names";
51 private static final String NAME_NAMESPACE
= "name";
53 public RedListGefaesspflanzenImportNames() {
54 super(tableName
, pluralString
);
58 protected String
getIdQuery(RedListGefaesspflanzenImportState state
) {
59 return "SELECT NAMNR "
60 + "FROM V_TAXATLAS_D20_EXPORT t "
65 protected String
getRecordQuery(RedListGefaesspflanzenImportConfigurator config
) {
66 String result
= " SELECT * "
67 + " FROM V_TAXATLAS_D20_EXPORT t "
68 + " WHERE t.NAMNR IN (@IDSET)";
69 result
= result
.replace("@IDSET", IPartitionedIO
.ID_LIST_TOKEN
);
74 protected void doInvoke(RedListGefaesspflanzenImportState state
) {
75 super.doInvoke(state
);
80 public boolean doPartition(ResultSetPartitioner partitioner
, RedListGefaesspflanzenImportState state
) {
81 ResultSet rs
= partitioner
.getResultSet();
82 Set
<TaxonNameBase
> namesToSave
= new HashSet
<TaxonNameBase
>();
85 makeSingleName(state
, rs
, namesToSave
);
88 } catch (SQLException e
) {
92 getNameService().saveOrUpdate(namesToSave
);
96 private void makeSingleName(RedListGefaesspflanzenImportState state
, ResultSet rs
, Set
<TaxonNameBase
> namesToSave
)
98 long id
= rs
.getLong("NAMNR");
99 String taxNameString
= rs
.getString("TAXNAME");
100 String rangString
= rs
.getString("RANG");
101 String ep1String
= rs
.getString("EPI1");
102 String ep2String
= rs
.getString("EPI2");
103 String ep3String
= rs
.getString("EPI3");
104 String nomZusatzString
= rs
.getString("NOM_ZUSATZ");
105 String zusatzString
= rs
.getString("ZUSATZ");
106 String authorKombString
= rs
.getString("AUTOR_KOMB");
107 String authorBasiString
= rs
.getString("AUTOR_BASI");
109 if(CdmUtils
.isBlank(taxNameString
) && CdmUtils
.isBlank(ep1String
)){
110 logger
.error("NAMNR: "+id
+" No name found!");
114 Rank rank
= makeRank(state
, rangString
);
115 BotanicalName name
= BotanicalName
.NewInstance(rank
);
117 //ep1 should always be present
118 name
.setGenusOrUninomial(ep1String
);
119 if(rank
==Rank
.SPECIES()){
120 name
.setGenusOrUninomial(ep1String
);
124 TeamOrPersonBase authorKomb
= HibernateProxyHelper
.deproxy(getAgentService().load(state
.getAuthorMap().get(authorKombString
)), TeamOrPersonBase
.class);
125 name
.setCombinationAuthorship(authorKomb
);
128 ImportHelper
.setOriginalSource(name
, state
.getTransactionalSourceReference(), id
, NAME_NAMESPACE
);
130 namesToSave
.add(name
);
133 private Rank
makeRank(RedListGefaesspflanzenImportState state
, String rankStr
) {
136 rank
= state
.getTransformer().getRankByKey(rankStr
);
137 } catch (UndefinedTransformerMethodException e
) {
141 logger
.error(rankStr
+" could not be associated to a known rank.");
149 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
,
150 RedListGefaesspflanzenImportState state
) {
151 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
152 // Map<Long, AgentBase<?>> authorKombMap = new HashMap<>();
153 // Map<Long, AgentBase<?>> authorBasiMap = new HashMap<>();
156 // for(Entry<Long, UUID> entry:state.getAuthorKombMap().entrySet()){
157 // authorKombMap.put(entry.getKey(), getAgentService().load(entry.getValue()));
159 // for(Entry<Long, UUID> entry:state.getAuthorBasiMap().entrySet()){
160 // authorBasiMap.put(entry.getKey(), getAgentService().load(entry.getValue()));
163 // while (rs.next()){
164 // long id = rs.getLong("NAMNR");
166 // } catch (SQLException e) {
167 // e.printStackTrace();
171 // Set<UUID> uuidSet = new HashSet<>();
172 // for (String authorStr : authorKombSet){
173 // UUID uuid = state.getAuthorUuid(authorStr);
174 // uuidSet.add(uuid);
176 // List<TeamOrPersonBase<?>> authors = (List)getAgentService().find(uuidSet);
177 // Map<UUID, TeamOrPersonBase<?>> authorUuidMap = new HashMap<>();
178 // for (TeamOrPersonBase<?> author : authors){
179 // authorUuidMap.put(author.getUuid(), author);
182 // for (String authorStr : authorKombSet){
183 // UUID uuid = state.getAuthorUuid(authorStr);
184 // TeamOrPersonBase<?> author = authorUuidMap.get(uuid);
185 // authorMap.put(authorStr, author);
187 // result.put(AUTHOR_NAMESPACE, authorMap);
190 // String nameSpace = REFERENCE_NAMESPACE;
191 // Class<?> cdmClass = Reference.class;
192 // Set<String> idSet = referenceIdSet;
193 // Map<String, Reference<?>> referenceMap = (Map<String, Reference<?>>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
194 // result.put(nameSpace, referenceMap);
197 // UUID secUuid = state.getConfig().getSecUuid();
198 // Reference<?> secRef = getReferenceService().find(secUuid);
199 // referenceMap.put(secUuid.toString(), secRef);
205 protected boolean doCheck(RedListGefaesspflanzenImportState state
) {
210 protected boolean isIgnore(RedListGefaesspflanzenImportState state
) {