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.pesi.euromed;
|
10
|
|
11
|
import java.util.Arrays;
|
12
|
import java.util.List;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.springframework.stereotype.Component;
|
17
|
import org.springframework.transaction.TransactionStatus;
|
18
|
|
19
|
import eu.etaxonomy.cdm.io.common.CdmImportBase;
|
20
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
21
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
22
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
23
|
|
24
|
/**
|
25
|
* @author a.mueller
|
26
|
* @since 08.10.2019
|
27
|
*/
|
28
|
@Component
|
29
|
public class EuroMedSourcesImport
|
30
|
extends CdmImportBase<EuroMedSourcesImportConfigurator, EuroMedSourcesImportState>{
|
31
|
|
32
|
private static final Logger logger = Logger.getLogger(EuroMedSourcesImportConfigurator.class);
|
33
|
private static final long serialVersionUID = -8740059585975302440L;
|
34
|
|
35
|
@Override
|
36
|
protected void doInvoke(EuroMedSourcesImportState state) {
|
37
|
List<String> propPath = Arrays.asList(new String[]{"sources"});
|
38
|
TransactionStatus tx = startTransaction();
|
39
|
Reference sourceRef = getSourceRef(state);
|
40
|
List<Reference> references = getReferenceService().list(null, null, null, null, propPath);
|
41
|
for (Reference reference : references){
|
42
|
reference.addImportSource(String.valueOf(reference.getId()),
|
43
|
Reference.class.getSimpleName(), sourceRef, null);
|
44
|
}
|
45
|
int count = references.size();
|
46
|
references = null;
|
47
|
commitTransaction(tx);
|
48
|
logger.info(count + " references imported");
|
49
|
//taxa
|
50
|
tx = startTransaction();
|
51
|
sourceRef = getSourceRef(state);
|
52
|
List<TaxonBase<?>> taxa = getTaxonService().list(null, null, null, null, propPath);
|
53
|
for (TaxonBase<?> taxon : taxa){
|
54
|
taxon.addImportSource(String.valueOf(taxon.getId()),
|
55
|
TaxonBase.class.getSimpleName(), sourceRef, null);
|
56
|
}
|
57
|
count = taxa.size();
|
58
|
taxa = null;
|
59
|
commitTransaction(tx);
|
60
|
logger.info(count + " taxa imported");
|
61
|
|
62
|
//names
|
63
|
tx = startTransaction();
|
64
|
sourceRef = getSourceRef(state);
|
65
|
List<TaxonName> names = getNameService().list(null, null, null, null, propPath);
|
66
|
for (TaxonName name : names){
|
67
|
name.addImportSource(String.valueOf(name.getId()),
|
68
|
TaxonName.class.getSimpleName(), sourceRef, null);
|
69
|
}
|
70
|
count = names.size();
|
71
|
names = null;
|
72
|
commitTransaction(tx);
|
73
|
logger.info(count + " names imported");
|
74
|
|
75
|
}
|
76
|
|
77
|
private Reference getSourceRef(EuroMedSourcesImportState state) {
|
78
|
UUID uuid = state.getConfig().getSourceRefUuid();
|
79
|
Reference ref = getReferenceService().find(uuid);
|
80
|
if (ref == null){
|
81
|
ref = state.getConfig().getSourceReference();
|
82
|
getReferenceService().save(ref);
|
83
|
}
|
84
|
return ref;
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
protected boolean doCheck(EuroMedSourcesImportState state) {
|
89
|
return true;
|
90
|
}
|
91
|
|
92
|
@Override
|
93
|
protected boolean isIgnore(EuroMedSourcesImportState state) {
|
94
|
return false;
|
95
|
}
|
96
|
}
|