Project

General

Profile

Download (3.1 KB) Statistics
| Branch: | Tag: | Revision:
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.log4j.Logger;
12
import org.springframework.stereotype.Component;
13
import org.springframework.transaction.TransactionStatus;
14

    
15
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
16
import eu.etaxonomy.cdm.io.common.ITaxonNodeOutStreamPartitioner;
17
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
18

    
19
/**
20
 * @author a.mueller
21
 * @since 17.08.2019
22
 */
23
@Component
24
public class Cdm2CdmTaxonNodeImport
25
        extends Cdm2CdmImportBase {
26

    
27
    private static final long serialVersionUID = -2111102574346601573L;
28
    private static final Logger logger = Logger.getLogger(Cdm2CdmTaxonNodeImport.class);
29

    
30

    
31
    @Override
32
    protected void doInvoke(Cdm2CdmImportState state) {
33
        IProgressMonitor monitor = state.getConfig().getProgressMonitor();
34

    
35
        Cdm2CdmImportConfigurator config = state.getConfig();
36

    
37
        ITaxonNodeOutStreamPartitioner partitioner = getTaxonNodePartitioner(state, monitor, config);
38
        monitor.subTask("Start partitioning");
39
        doData(state, partitioner);
40
    }
41

    
42
    private void doData(Cdm2CdmImportState state, ITaxonNodeOutStreamPartitioner partitioner){
43
        TaxonNode node = partitioner.next();
44
        int partitionSize = 100;
45
        int count = 0;
46
        TransactionStatus tx = startTransaction();
47
        while (node != null) {
48
            node = doSingleNode(state, node);
49
            count++;
50
            if (count>=partitionSize){
51
                state.clearSessionCache();
52
                try {
53
                    commitTransaction(tx);
54
                } catch (Exception e) {
55
                    logger.warn("Exception during commit node " + node.treeIndex());
56
                    e.printStackTrace();
57
                }
58
                tx = startTransaction();
59
                count=0;
60
            }
61
            node = partitioner.next();
62
        }
63
        commitTransaction(tx);
64
        partitioner.close();
65
    }
66

    
67
    private TaxonNode doSingleNode(Cdm2CdmImportState state, TaxonNode node) {
68
        TaxonNode result = null;
69
        logger.info(node.treeIndex());
70
        try {
71
            result = detache(node, state);
72
        } catch (Exception e) {
73
            logger.warn("Exception during detache node " + node.treeIndex());
74
            e.printStackTrace();
75
        }
76
        try {
77
            if (result != null){
78
                getTaxonNodeService().saveOrUpdate(node);
79
                getCommonService().saveOrUpdate(state.getToSave());
80
                state.clearToSave();
81
            }
82
        } catch (Exception e) {
83
            logger.warn("Exception during save node " + node.treeIndex());
84
             e.printStackTrace();
85
        }
86

    
87
        return result;
88
    }
89

    
90

    
91
    @Override
92
    protected boolean doCheck(Cdm2CdmImportState state) {
93
        return true;
94
    }
95

    
96
    @Override
97
    protected boolean isIgnore(Cdm2CdmImportState state) {
98
        return !state.getConfig().isDoTaxa();
99
    }
100
}
(5-5/6)