Revision af09506a
Added by Patrick Plitzner about 8 years ago
app-import/src/main/java/eu/etaxonomy/cdm/app/common/CdmDestinations.java | ||
---|---|---|
519 | 519 |
String cdmUserName = "edit"; |
520 | 520 |
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null); |
521 | 521 |
} |
522 |
|
|
522 |
|
|
523 |
public static ICdmDataSource cdm_production_redlist_gefaesspflanzen(){ |
|
524 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
|
525 |
String cdmServer = "160.45.63.171"; |
|
526 |
String cdmDB = "cdm_production_rl_plantae"; |
|
527 |
String cdmUserName = "edit"; |
|
528 |
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null); |
|
529 |
} |
|
523 | 530 |
|
524 | 531 |
public static ICdmDataSource cdm_production_edaphobase(){ |
525 | 532 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
app-import/src/main/java/eu/etaxonomy/cdm/app/common/CdmImportSources.java | ||
---|---|---|
26 | 26 |
public class CdmImportSources extends SourceBase{ |
27 | 27 |
@SuppressWarnings("unused") |
28 | 28 |
private static final Logger logger = Logger.getLogger(CdmImportSources.class); |
29 |
|
|
29 |
|
|
30 |
public static Source ROTE_LISTE_GEFAESSPFLANZEN_DB(){ |
|
31 |
String dbms = Source.ACCESS; |
|
32 |
String strServer = null; |
|
33 |
String strDB = "/home/pplitzner/Rote Listen 2020/Gefaesspflanzen/tax_atlas_d20_export.accdb"; |
|
34 |
int port = -1; |
|
35 |
String userName = ""; |
|
36 |
return makeSource(dbms, strServer, strDB, port, userName, null); |
|
37 |
} |
|
38 |
|
|
30 | 39 |
public static Source ROTE_LISTE_DB(){ |
31 | 40 |
String dbms = Source.ORACLE; |
32 | 41 |
String strServer = "xxx"; |
app-import/src/main/java/eu/etaxonomy/cdm/app/redlist/RedListGefaesspflanzenActivator.java | ||
---|---|---|
1 |
package eu.etaxonomy.cdm.app.redlist; |
|
2 |
|
|
3 |
import java.util.UUID; |
|
4 |
|
|
5 |
import org.apache.log4j.Logger; |
|
6 |
|
|
7 |
import eu.etaxonomy.cdm.app.common.CdmDestinations; |
|
8 |
import eu.etaxonomy.cdm.app.common.CdmImportSources; |
|
9 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
|
10 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
11 |
import eu.etaxonomy.cdm.io.common.CdmDefaultImport; |
|
12 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK; |
|
13 |
import eu.etaxonomy.cdm.io.common.Source; |
|
14 |
import eu.etaxonomy.cdm.io.redlist.gefaesspflanzen.RedListGefaesspflanzenImportConfigurator; |
|
15 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
16 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
17 |
|
|
18 |
public class RedListGefaesspflanzenActivator { |
|
19 |
@SuppressWarnings("unused") |
|
20 |
private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenActivator.class); |
|
21 |
|
|
22 |
//database validation status (create, update, validate ...) |
|
23 |
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE; |
|
24 |
static final Source mySource = CdmImportSources.ROTE_LISTE_GEFAESSPFLANZEN_DB(); |
|
25 |
|
|
26 |
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2(); |
|
27 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_redlist_gefaesspflanzen(); |
|
28 |
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql(); |
|
29 |
|
|
30 |
//feature tree uuid |
|
31 |
public static final UUID featureTreeUuid = UUID.fromString("75a0e0fc-838a-4c12-8fbb-90d42ba98a34"); |
|
32 |
|
|
33 |
public static final String sourceReference = "Rote Listen - Gefäßpflanzen"; |
|
34 |
|
|
35 |
|
|
36 |
//classification |
|
37 |
public static final UUID classificationUuid = UUID.fromString("c4053649-1994-4b79-b409-f3986227a4af"); |
|
38 |
|
|
39 |
//check - import |
|
40 |
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK; |
|
41 |
|
|
42 |
//taxa |
|
43 |
static final boolean doTaxa = true; |
|
44 |
|
|
45 |
private void doImport(ICdmDataSource cdmDestination){ |
|
46 |
|
|
47 |
//make Source |
|
48 |
Source source = mySource; |
|
49 |
|
|
50 |
RedListGefaesspflanzenImportConfigurator config= RedListGefaesspflanzenImportConfigurator.NewInstance(source, cdmDestination); |
|
51 |
config.setClassificationUuid(classificationUuid); |
|
52 |
// config.setDoTaxa(doTaxa); |
|
53 |
config.setCheck(check); |
|
54 |
config.setDbSchemaValidation(hbm2dll); |
|
55 |
|
|
56 |
CdmDefaultImport<RedListGefaesspflanzenImportConfigurator> myImport = new CdmDefaultImport<RedListGefaesspflanzenImportConfigurator>(); |
|
57 |
|
|
58 |
System.out.println("Start import from ("+ source.toString() + ") ..."); |
|
59 |
config.setSourceReference(getSourceReference(sourceReference)); |
|
60 |
myImport.invoke(config); |
|
61 |
System.out.println("End import from ("+ source.toString() + ")..."); |
|
62 |
} |
|
63 |
|
|
64 |
private Reference<?> getSourceReference(String string) { |
|
65 |
Reference<?> result = ReferenceFactory.newGeneric(); |
|
66 |
result.setTitleCache(string, true); |
|
67 |
return result; |
|
68 |
} |
|
69 |
|
|
70 |
|
|
71 |
public static void main(String[] args) { |
|
72 |
RedListGefaesspflanzenActivator me = new RedListGefaesspflanzenActivator(); |
|
73 |
me.doImport(cdmDestination); |
|
74 |
} |
|
75 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportConfigurator.java | ||
---|---|---|
1 |
package eu.etaxonomy.cdm.io.redlist.gefaesspflanzen; |
|
2 |
|
|
3 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
4 |
import eu.etaxonomy.cdm.io.common.DbImportConfiguratorBase; |
|
5 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator; |
|
6 |
import eu.etaxonomy.cdm.io.common.Source; |
|
7 |
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer; |
|
8 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
9 |
|
|
10 |
@SuppressWarnings("serial") |
|
11 |
public class RedListGefaesspflanzenImportConfigurator extends |
|
12 |
DbImportConfiguratorBase<RedListGefaesspflanzenImportState> implements |
|
13 |
IImportConfigurator { |
|
14 |
|
|
15 |
public static RedListGefaesspflanzenImportConfigurator NewInstance(Source source, ICdmDataSource cdmDestination) { |
|
16 |
return new RedListGefaesspflanzenImportConfigurator(source, cdmDestination, new RedListGefaesspflanzenTransformer()); |
|
17 |
} |
|
18 |
|
|
19 |
|
|
20 |
protected RedListGefaesspflanzenImportConfigurator(Source source, |
|
21 |
ICdmDataSource destination, IInputTransformer defaultTransformer) { |
|
22 |
super(source, destination, NomenclaturalCode.ICNAFP, defaultTransformer); |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public RedListGefaesspflanzenImportState getNewState() { |
|
27 |
return new RedListGefaesspflanzenImportState(this); |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
protected void makeIoClassList() { |
|
32 |
ioClassList = new Class[]{ |
|
33 |
RedListGefaesspflanzenImportTaxa.class, |
|
34 |
}; |
|
35 |
} |
|
36 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportState.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.redlist.gefaesspflanzen; |
|
12 |
|
|
13 |
import org.apache.log4j.Logger; |
|
14 |
|
|
15 |
import eu.etaxonomy.cdm.io.common.DbImportStateBase; |
|
16 |
|
|
17 |
/** |
|
18 |
* @author a.mueller |
|
19 |
* @created 11.05.2009 |
|
20 |
*/ |
|
21 |
public class RedListGefaesspflanzenImportState extends DbImportStateBase<RedListGefaesspflanzenImportConfigurator, RedListGefaesspflanzenImportState>{ |
|
22 |
@SuppressWarnings("unused") |
|
23 |
private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportState.class); |
|
24 |
|
|
25 |
protected RedListGefaesspflanzenImportState(RedListGefaesspflanzenImportConfigurator config) { |
|
26 |
super(config); |
|
27 |
} |
|
28 |
|
|
29 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportTaxa.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.redlist.gefaesspflanzen; |
|
11 |
|
|
12 |
import java.sql.ResultSet; |
|
13 |
import java.sql.SQLException; |
|
14 |
import java.util.HashMap; |
|
15 |
import java.util.HashSet; |
|
16 |
import java.util.Map; |
|
17 |
import java.util.Set; |
|
18 |
|
|
19 |
import org.apache.log4j.Logger; |
|
20 |
import org.springframework.stereotype.Component; |
|
21 |
|
|
22 |
import eu.etaxonomy.cdm.io.common.DbImportBase; |
|
23 |
import eu.etaxonomy.cdm.io.common.IPartitionedIO; |
|
24 |
import eu.etaxonomy.cdm.io.common.ImportHelper; |
|
25 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
|
26 |
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException; |
|
27 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
28 |
import eu.etaxonomy.cdm.model.name.NonViralName; |
|
29 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
30 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
31 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
32 |
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl; |
|
33 |
|
|
34 |
/** |
|
35 |
* @author a.mueller |
|
36 |
* @created 05.01.2016 |
|
37 |
*/ |
|
38 |
|
|
39 |
@Component |
|
40 |
@SuppressWarnings("serial") |
|
41 |
public class RedListGefaesspflanzenImportTaxa extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> { |
|
42 |
private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportTaxa.class); |
|
43 |
|
|
44 |
private static final String tableName = "Rote Liste Gefäßpflanzen"; |
|
45 |
|
|
46 |
private static final String pluralString = "taxa"; |
|
47 |
|
|
48 |
private static final String TAXON_NAMESPACE = "taxon"; |
|
49 |
|
|
50 |
public RedListGefaesspflanzenImportTaxa() { |
|
51 |
super(tableName, pluralString); |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
protected String getIdQuery(RedListGefaesspflanzenImportState state) { |
|
56 |
return "SELECT NAMNR FROM V_TAXATLAS_D20_EXPORT t " |
|
57 |
// + " ORDER BY NAMNR" |
|
58 |
; |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) { |
|
63 |
String result = " SELECT * " |
|
64 |
+ " FROM V_TAXATLAS_D20_EXPORT t " |
|
65 |
+ " WHERE t.NAMNR IN (@IDSET)"; |
|
66 |
result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN); |
|
67 |
return result; |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
protected void doInvoke(RedListGefaesspflanzenImportState state) { |
|
72 |
super.doInvoke(state); |
|
73 |
} |
|
74 |
|
|
75 |
|
|
76 |
@Override |
|
77 |
public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) { |
|
78 |
ResultSet rs = partitioner.getResultSet(); |
|
79 |
Set<TaxonBase> taxaToSave = new HashSet<>(); |
|
80 |
try { |
|
81 |
while (rs.next()){ |
|
82 |
taxaToSave = makeSingleTaxon(state, rs); |
|
83 |
|
|
84 |
} |
|
85 |
} catch (SQLException e) { |
|
86 |
e.printStackTrace(); |
|
87 |
} |
|
88 |
|
|
89 |
getTaxonService().saveOrUpdate(taxaToSave); |
|
90 |
return true; |
|
91 |
} |
|
92 |
|
|
93 |
private Set<TaxonBase> makeSingleTaxon(RedListGefaesspflanzenImportState state, ResultSet rs) |
|
94 |
throws SQLException { |
|
95 |
Set<TaxonBase> taxaToSave = new HashSet<>(); |
|
96 |
long id = rs.getLong("NAMNR"); |
|
97 |
String taxonNameString = rs.getString("TAXNAME"); |
|
98 |
|
|
99 |
NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance(); |
|
100 |
NonViralName<?> name = parser.parseFullName(taxonNameString); |
|
101 |
TaxonBase taxon = Taxon.NewInstance(name, null); |
|
102 |
|
|
103 |
taxaToSave.add(taxon); |
|
104 |
|
|
105 |
//id |
|
106 |
ImportHelper.setOriginalSource(taxon, state.getTransactionalSourceReference(), id, TAXON_NAMESPACE); |
|
107 |
ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, TAXON_NAMESPACE); |
|
108 |
|
|
109 |
return taxaToSave; |
|
110 |
} |
|
111 |
|
|
112 |
private Rank makeRank(RedListGefaesspflanzenImportState state, String rankStr) { |
|
113 |
Rank rank = null; |
|
114 |
try { |
|
115 |
rank = state.getTransformer().getRankByKey(rankStr); |
|
116 |
} catch (UndefinedTransformerMethodException e) { |
|
117 |
e.printStackTrace(); |
|
118 |
} |
|
119 |
return rank; |
|
120 |
} |
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
@Override |
|
125 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, |
|
126 |
RedListGefaesspflanzenImportState state) { |
|
127 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>(); |
|
128 |
// Map<String, TeamOrPersonBase<?>> authorMap = new HashMap<>(); |
|
129 |
// Set<String> authorSet = new HashSet<>(); |
|
130 |
// Set<String> referenceIdSet = new HashSet<String>(); |
|
131 |
// |
|
132 |
// try { |
|
133 |
// while (rs.next()){ |
|
134 |
// String authorStr = rs.getString("tax_author_name"); |
|
135 |
// authorSet.add(authorStr); |
|
136 |
// handleForeignKey(rs, referenceIdSet, "tax_document"); |
|
137 |
// } |
|
138 |
// } catch (SQLException e) { |
|
139 |
// e.printStackTrace(); |
|
140 |
// } |
|
141 |
// |
|
142 |
// //Authors |
|
143 |
// Set<UUID> uuidSet = new HashSet<>(); |
|
144 |
// for (String authorStr : authorSet){ |
|
145 |
// UUID uuid = state.getAuthorUuid(authorStr); |
|
146 |
// uuidSet.add(uuid); |
|
147 |
// } |
|
148 |
// List<TeamOrPersonBase<?>> authors = (List)getAgentService().find(uuidSet); |
|
149 |
// Map<UUID, TeamOrPersonBase<?>> authorUuidMap = new HashMap<>(); |
|
150 |
// for (TeamOrPersonBase<?> author : authors){ |
|
151 |
// authorUuidMap.put(author.getUuid(), author); |
|
152 |
// } |
|
153 |
// |
|
154 |
// for (String authorStr : authorSet){ |
|
155 |
// UUID uuid = state.getAuthorUuid(authorStr); |
|
156 |
// TeamOrPersonBase<?> author = authorUuidMap.get(uuid); |
|
157 |
// authorMap.put(authorStr, author); |
|
158 |
// } |
|
159 |
// result.put(AUTHOR_NAMESPACE, authorMap); |
|
160 |
// |
|
161 |
// //reference map |
|
162 |
// String nameSpace = REFERENCE_NAMESPACE; |
|
163 |
// Class<?> cdmClass = Reference.class; |
|
164 |
// Set<String> idSet = referenceIdSet; |
|
165 |
// Map<String, Reference<?>> referenceMap = (Map<String, Reference<?>>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
166 |
// result.put(nameSpace, referenceMap); |
|
167 |
// |
|
168 |
// //secundum |
|
169 |
// UUID secUuid = state.getConfig().getSecUuid(); |
|
170 |
// Reference<?> secRef = getReferenceService().find(secUuid); |
|
171 |
// referenceMap.put(secUuid.toString(), secRef); |
|
172 |
|
|
173 |
return result; |
|
174 |
} |
|
175 |
|
|
176 |
@Override |
|
177 |
protected boolean doCheck(RedListGefaesspflanzenImportState state) { |
|
178 |
return false; |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
protected boolean isIgnore(RedListGefaesspflanzenImportState state) { |
|
183 |
return false; |
|
184 |
} |
|
185 |
|
|
186 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenTransformer.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.redlist.gefaesspflanzen; |
|
12 |
|
|
13 |
import org.apache.log4j.Logger; |
|
14 |
|
|
15 |
import eu.etaxonomy.cdm.io.common.mapping.InputTransformerBase; |
|
16 |
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException; |
|
17 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
18 |
|
|
19 |
/** |
|
20 |
* @author a.mueller |
|
21 |
* @created 01.03.2010 |
|
22 |
*/ |
|
23 |
@SuppressWarnings("serial") |
|
24 |
public final class RedListGefaesspflanzenTransformer extends InputTransformerBase { |
|
25 |
|
|
26 |
@SuppressWarnings("unused") |
|
27 |
private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenTransformer.class); |
|
28 |
|
|
29 |
@Override |
|
30 |
public Rank getRankByKey(String key) throws UndefinedTransformerMethodException { |
|
31 |
if (key == null){return null;} |
|
32 |
if (key.equals("GAT")){return Rank.GENUS();} |
|
33 |
else if (key.equals("SPE")){return Rank.SPECIES();} |
|
34 |
return null; |
|
35 |
} |
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
} |
Also available in: Unified diff
Add importer classes for RedListGefaesspflanzen