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