1
|
/**
|
2
|
* Copyright (C) 2019 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
|
package eu.etaxonomy.cdm.io.cdm2cdm;
|
10
|
|
11
|
import org.apache.logging.log4j.LogManager;
|
12
|
import org.apache.logging.log4j.Logger;
|
13
|
import org.springframework.stereotype.Component;
|
14
|
import org.springframework.transaction.TransactionStatus;
|
15
|
|
16
|
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
|
17
|
import eu.etaxonomy.cdm.io.common.ITaxonNodeOutStreamPartitioner;
|
18
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
19
|
|
20
|
/**
|
21
|
* @author a.mueller
|
22
|
* @since 17.08.2019
|
23
|
*/
|
24
|
@Component
|
25
|
public class Cdm2CdmTaxonNodeImport
|
26
|
extends Cdm2CdmImportBase {
|
27
|
|
28
|
private static final long serialVersionUID = -2111102574346601573L;
|
29
|
private static final Logger logger = LogManager.getLogger();
|
30
|
|
31
|
|
32
|
@Override
|
33
|
protected void doInvoke(Cdm2CdmImportState state) {
|
34
|
IProgressMonitor monitor = state.getConfig().getProgressMonitor();
|
35
|
|
36
|
Cdm2CdmImportConfigurator config = state.getConfig();
|
37
|
|
38
|
ITaxonNodeOutStreamPartitioner partitioner = getTaxonNodePartitioner(state, monitor, config);
|
39
|
monitor.subTask("Start partitioning");
|
40
|
doData(state, partitioner);
|
41
|
}
|
42
|
|
43
|
private void doData(Cdm2CdmImportState state, ITaxonNodeOutStreamPartitioner partitioner){
|
44
|
TaxonNode node = partitioner.next();
|
45
|
int partitionSize = 100;
|
46
|
int count = 0;
|
47
|
TransactionStatus tx = startTransaction();
|
48
|
while (node != null) {
|
49
|
node = doSingleNode(state, node);
|
50
|
count++;
|
51
|
if (count>=partitionSize){
|
52
|
state.clearSessionCache();
|
53
|
try {
|
54
|
commitTransaction(tx);
|
55
|
} catch (Exception e) {
|
56
|
logger.warn("Exception during commit node " + node.treeIndex());
|
57
|
e.printStackTrace();
|
58
|
}
|
59
|
tx = startTransaction();
|
60
|
count=0;
|
61
|
}
|
62
|
node = partitioner.next();
|
63
|
}
|
64
|
commitTransaction(tx);
|
65
|
partitioner.close();
|
66
|
}
|
67
|
|
68
|
private TaxonNode doSingleNode(Cdm2CdmImportState state, TaxonNode node) {
|
69
|
TaxonNode result = null;
|
70
|
logger.info(node.treeIndex());
|
71
|
try {
|
72
|
result = detache(node, state);
|
73
|
} catch (Exception e) {
|
74
|
logger.warn("Exception during detache node " + node.treeIndex());
|
75
|
e.printStackTrace();
|
76
|
}
|
77
|
try {
|
78
|
if (result != null){
|
79
|
getTaxonNodeService().saveOrUpdate(node);
|
80
|
getCommonService().saveOrUpdate(state.getToSave());
|
81
|
state.clearToSave();
|
82
|
}
|
83
|
} catch (Exception e) {
|
84
|
logger.warn("Exception during save node " + node.treeIndex());
|
85
|
e.printStackTrace();
|
86
|
}
|
87
|
|
88
|
return result;
|
89
|
}
|
90
|
|
91
|
|
92
|
@Override
|
93
|
protected boolean doCheck(Cdm2CdmImportState state) {
|
94
|
return true;
|
95
|
}
|
96
|
|
97
|
@Override
|
98
|
protected boolean isIgnore(Cdm2CdmImportState state) {
|
99
|
return !state.getConfig().isDoTaxa();
|
100
|
}
|
101
|
}
|