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
.ArrayList
;
15 import java
.util
.Collection
;
16 import java
.util
.HashMap
;
18 import java
.util
.UUID
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.springframework
.stereotype
.Component
;
23 import eu
.etaxonomy
.cdm
.io
.common
.DbImportBase
;
24 import eu
.etaxonomy
.cdm
.io
.common
.ResultSetPartitioner
;
25 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.name
.IBotanicalName
;
27 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
28 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
40 @SuppressWarnings("serial")
41 public class RedListGefaesspflanzenImportFamily
extends DbImportBase
<RedListGefaesspflanzenImportState
, RedListGefaesspflanzenImportConfigurator
> {
43 private static final Logger logger
= Logger
.getLogger(RedListGefaesspflanzenImportFamily
.class);
45 private static final String tableName
= "Rote Liste Gefäßpflanzen";
47 private static final String pluralString
= "families";
50 public RedListGefaesspflanzenImportFamily() {
51 super(tableName
, pluralString
);
55 protected String
getIdQuery(RedListGefaesspflanzenImportState state
) {
60 protected String
getRecordQuery(RedListGefaesspflanzenImportConfigurator config
) {
65 protected void doInvoke(RedListGefaesspflanzenImportState state
) {
67 Collection
<TaxonBase
> families
= importFamilies(state
);
68 getTaxonService().save(families
);
69 } catch (SQLException e
) {
75 private Collection
<TaxonBase
> importFamilies(RedListGefaesspflanzenImportState state
) throws SQLException
{
76 Map
<String
, UUID
> familyMap
= new HashMap
<>();
77 Collection
<TaxonBase
> families
= new ArrayList
<TaxonBase
>();
79 String query
= "SELECT DISTINCT f.FAMILIE "
80 + " FROM GATTUNG_FAMILIE f";
82 ResultSet rs
= state
.getConfig().getSource().getResultSet(query
);
84 String familieStr
= rs
.getString("FAMILIE");
85 IBotanicalName name
= TaxonNameFactory
.NewBotanicalInstance(Rank
.FAMILY());
86 name
.setGenusOrUninomial(familieStr
);
87 Taxon family
= Taxon
.NewInstance(name
, null);
88 familyMap
.put(familieStr
, family
.getUuid());
91 state
.setFamilyMap(familyMap
);
96 public boolean doPartition(ResultSetPartitioner partitioner
, RedListGefaesspflanzenImportState state
) {
101 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
,
102 RedListGefaesspflanzenImportState state
) {
103 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
108 protected boolean doCheck(RedListGefaesspflanzenImportState state
) {
113 protected boolean isIgnore(RedListGefaesspflanzenImportState state
) {