1
|
/**
|
2
|
* Copyright (C) 2009 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.tcsxml.in;
|
11
|
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.jdom.Element;
|
16
|
import org.jdom.Namespace;
|
17
|
import org.springframework.stereotype.Component;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
20
|
import eu.etaxonomy.cdm.common.DoubleResult;
|
21
|
import eu.etaxonomy.cdm.common.XmlHelp;
|
22
|
import eu.etaxonomy.cdm.io.common.ICdmIO;
|
23
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
24
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
25
|
import eu.etaxonomy.cdm.io.common.MapWrapper;
|
26
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
27
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
28
|
|
29
|
/**
|
30
|
* @author a.mueller
|
31
|
*
|
32
|
*/
|
33
|
@Component
|
34
|
public class TcsXmlPublicationsImport extends TcsXmlImportBase implements ICdmIO<TcsXmlImportState> {
|
35
|
private static final Logger logger = Logger.getLogger(TcsXmlPublicationsImport.class);
|
36
|
|
37
|
private static int modCount = 1000;
|
38
|
|
39
|
public TcsXmlPublicationsImport(){
|
40
|
super();
|
41
|
}
|
42
|
|
43
|
@Override
|
44
|
public boolean doCheck(TcsXmlImportState state){
|
45
|
boolean result = true;
|
46
|
result &= checkArticlesWithoutJournal(state.getConfig());
|
47
|
//result &= checkPartOfJournal(config);
|
48
|
|
49
|
return result;
|
50
|
}
|
51
|
|
52
|
private static boolean checkArticlesWithoutJournal(IImportConfigurator bmiConfig){
|
53
|
try {
|
54
|
boolean result = true;
|
55
|
//TODO
|
56
|
// result = firstRow = false;
|
57
|
// }
|
58
|
//
|
59
|
return result;
|
60
|
} catch (Exception e) {
|
61
|
e.printStackTrace();
|
62
|
return false;
|
63
|
}
|
64
|
}
|
65
|
|
66
|
|
67
|
|
68
|
@Override
|
69
|
public void doInvoke(TcsXmlImportState state){
|
70
|
|
71
|
logger.info("start make Publications ...");
|
72
|
boolean success = true;
|
73
|
String childName;
|
74
|
boolean obligatory;
|
75
|
|
76
|
MapWrapper<Reference> referenceMap = (MapWrapper<Reference>)state.getStore(ICdmIO.REFERENCE_STORE);
|
77
|
IReferenceService referenceService = getReferenceService();
|
78
|
|
79
|
TcsXmlImportConfigurator config = state.getConfig();
|
80
|
Element elDataSet = getDataSetElement(config);
|
81
|
Namespace tcsNamespace = config.getTcsXmlNamespace();
|
82
|
|
83
|
DoubleResult<Element, Boolean> doubleResult;
|
84
|
childName = "Publications";
|
85
|
obligatory = false;
|
86
|
doubleResult = XmlHelp.getSingleChildElement(elDataSet, childName, tcsNamespace, obligatory);
|
87
|
success &= doubleResult.getSecondResult();
|
88
|
Element elPublications = doubleResult.getFirstResult();
|
89
|
|
90
|
String tcsElementName = "Publication";
|
91
|
String idNamespace = "Publication";
|
92
|
List<Element> elPublicationList = elPublications.getChildren(tcsElementName, tcsNamespace);
|
93
|
|
94
|
int i = 0;
|
95
|
//for each taxonName
|
96
|
ReferenceFactory refFactory = ReferenceFactory.newInstance();
|
97
|
for (Element elPublication : elPublicationList){
|
98
|
if ((++i % modCount) == 0){ logger.info("publications handled: " + (i-1));}
|
99
|
|
100
|
//create TaxonName element
|
101
|
String strId = elPublication.getAttributeValue("id");
|
102
|
|
103
|
childName = "Simple";
|
104
|
obligatory = true;
|
105
|
doubleResult = XmlHelp.getSingleChildElement(elPublication, childName, tcsNamespace, obligatory);
|
106
|
success &= doubleResult.getSecondResult();
|
107
|
Element elSimple = doubleResult.getFirstResult();
|
108
|
|
109
|
String simple = elSimple.getTextNormalize();
|
110
|
|
111
|
Reference reference = refFactory.newGeneric();
|
112
|
reference.setTitleCache(simple, true);
|
113
|
|
114
|
childName = "PublicationDetailed";
|
115
|
obligatory = false;
|
116
|
doubleResult = XmlHelp.getSingleChildElement(elPublication, childName, tcsNamespace, obligatory);
|
117
|
success &= doubleResult.getSecondResult();
|
118
|
Element elPublicationDetailed = doubleResult.getFirstResult();
|
119
|
|
120
|
success &= config.getPlaceholderClass().makePublicationDetailed(config, elPublicationDetailed, reference);
|
121
|
ImportHelper.setOriginalSource(reference, config.getSourceReference(), strId, idNamespace);
|
122
|
|
123
|
referenceMap.put(strId, reference);
|
124
|
|
125
|
|
126
|
}
|
127
|
// //save and store in map
|
128
|
// logger.info("Save nomenclatural references (" + nomRefCount + ")");
|
129
|
// referenceService.saveReferenceAll(nomRefMap.objects());
|
130
|
logger.info("Save bibliographical references (" + i +")");
|
131
|
referenceService.save(referenceMap.objects());
|
132
|
|
133
|
logger.info("end make publications ...");
|
134
|
if (!success){
|
135
|
state.setUnsuccessfull();
|
136
|
}
|
137
|
return;
|
138
|
}
|
139
|
|
140
|
/* (non-Javadoc)
|
141
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
142
|
*/
|
143
|
protected boolean isIgnore(TcsXmlImportState state){
|
144
|
return (state.getConfig().getDoReferences() == IImportConfigurator.DO_REFERENCES.NONE);
|
145
|
}
|
146
|
|
147
|
}
|