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.markup;
|
11
|
|
12
|
import java.net.MalformedURLException;
|
13
|
import java.util.LinkedList;
|
14
|
import java.util.Queue;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import javax.xml.stream.FactoryConfigurationError;
|
18
|
import javax.xml.stream.XMLEventReader;
|
19
|
import javax.xml.stream.XMLStreamException;
|
20
|
import javax.xml.stream.events.XMLEvent;
|
21
|
|
22
|
import org.apache.log4j.Logger;
|
23
|
import org.springframework.beans.factory.annotation.Autowired;
|
24
|
import org.springframework.stereotype.Component;
|
25
|
import org.springframework.transaction.TransactionStatus;
|
26
|
|
27
|
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
|
28
|
import eu.etaxonomy.cdm.io.common.ICdmIO;
|
29
|
import eu.etaxonomy.cdm.io.common.XmlImportBase;
|
30
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
31
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
32
|
import eu.etaxonomy.cdm.model.common.ExtensionType;
|
33
|
import eu.etaxonomy.cdm.model.common.Language;
|
34
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
35
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
36
|
import eu.etaxonomy.cdm.model.description.Feature;
|
37
|
import eu.etaxonomy.cdm.model.description.TextData;
|
38
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
39
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
40
|
import eu.etaxonomy.cdm.model.location.NamedAreaType;
|
41
|
import eu.etaxonomy.cdm.model.media.Media;
|
42
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
43
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
44
|
|
45
|
/**
|
46
|
* @author a.mueller
|
47
|
*
|
48
|
*/
|
49
|
@Component
|
50
|
public class MarkupDocumentImport extends XmlImportBase<MarkupImportConfigurator, MarkupImportState> implements ICdmIO<MarkupImportState> {
|
51
|
@SuppressWarnings("unused")
|
52
|
private static final Logger logger = Logger.getLogger(MarkupDocumentImport.class);
|
53
|
|
54
|
|
55
|
// TODO make part of state, but state is renewed when invoking the import a
|
56
|
// second time
|
57
|
private UnmatchedLeads unmatchedLeads;
|
58
|
|
59
|
|
60
|
@Autowired
|
61
|
private IEditGeoService editGeoService;
|
62
|
|
63
|
public MarkupDocumentImport() {
|
64
|
super();
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
public boolean doCheck(MarkupImportState state) {
|
69
|
state.setCheck(true);
|
70
|
doInvoke(state);
|
71
|
state.setCheck(false);
|
72
|
return state.isSuccess();
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public void doInvoke(MarkupImportState state) {
|
77
|
fireProgressEvent("Start import markup document", "Before start of document");
|
78
|
|
79
|
Queue<CdmBase> outputStream = new LinkedList<CdmBase>();
|
80
|
|
81
|
TransactionStatus tx = startTransaction();
|
82
|
// FIXME reset state
|
83
|
doAllTheOldOtherStuff(state);
|
84
|
|
85
|
// START
|
86
|
try {
|
87
|
// StAX
|
88
|
XMLEventReader reader = getStaxReader(state);
|
89
|
state.setReader(reader);
|
90
|
|
91
|
// start document
|
92
|
if (!validateStartOfDocument(reader)) {
|
93
|
state.setUnsuccessfull();
|
94
|
return;
|
95
|
}
|
96
|
|
97
|
MarkupDocumentImportNoComponent x = new MarkupDocumentImportNoComponent(this);
|
98
|
x.doInvoke(state);
|
99
|
|
100
|
commitTransaction(tx);
|
101
|
|
102
|
// //SAX
|
103
|
// ImportHandlerBase handler= new PublicationHandler(this);
|
104
|
// parseSAX(state, handler);
|
105
|
|
106
|
} catch (FactoryConfigurationError e1) {
|
107
|
fireWarningEvent("Some error occurred while setting up xml factory. Data can't be imported", "Start", 16);
|
108
|
state.setUnsuccessfull();
|
109
|
} catch (XMLStreamException e1) {
|
110
|
fireWarningEvent("An XMLStreamException occurred while parsing. Data can't be imported", "Start", 16);
|
111
|
state.setUnsuccessfull();
|
112
|
}
|
113
|
|
114
|
return;
|
115
|
|
116
|
}
|
117
|
|
118
|
|
119
|
/**
|
120
|
* This comes from the old version, needs to be checked on need
|
121
|
*
|
122
|
* @param state
|
123
|
*/
|
124
|
private void doAllTheOldOtherStuff(MarkupImportState state) {
|
125
|
state.putTree(null, null);
|
126
|
if (unmatchedLeads == null) {
|
127
|
unmatchedLeads = UnmatchedLeads.NewInstance();
|
128
|
}
|
129
|
state.setUnmatchedLeads(unmatchedLeads);
|
130
|
|
131
|
// TransactionStatus tx = startTransaction();
|
132
|
unmatchedLeads.saveToSession(getPolytomousKeyNodeService());
|
133
|
|
134
|
// TODO generally do not store the reference object in the config
|
135
|
Reference<?> sourceReference = state.getConfig().getSourceReference();
|
136
|
getReferenceService().saveOrUpdate(sourceReference);
|
137
|
}
|
138
|
|
139
|
/*
|
140
|
* (non-Javadoc)
|
141
|
*
|
142
|
* @see
|
143
|
* eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common
|
144
|
* .IImportConfigurator)
|
145
|
*/
|
146
|
protected boolean isIgnore(MarkupImportState state) {
|
147
|
return !state.getConfig().isDoTaxa();
|
148
|
}
|
149
|
|
150
|
|
151
|
// ************************* OPEN AFTER REFACTORING ****************************************/
|
152
|
|
153
|
|
154
|
/* (non-Javadoc)
|
155
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#fireWarningEvent(java.lang.String, java.lang.String, java.lang.Integer)
|
156
|
*/
|
157
|
public void fireWarningEvent(String message, String dataLocation, Integer severity) {
|
158
|
super.fireWarningEvent(message, dataLocation, severity, 1);
|
159
|
}
|
160
|
|
161
|
public void fireWarningEvent(String message, String dataLocation, Integer severity, int stackDepth) {
|
162
|
super.fireWarningEvent(message, dataLocation, severity, stackDepth + 1);
|
163
|
}
|
164
|
|
165
|
public void fireSchemaConflictEventExpectedStartTag(String elName, XMLEventReader reader) throws XMLStreamException {
|
166
|
super.fireSchemaConflictEventExpectedStartTag(elName, reader);
|
167
|
}
|
168
|
|
169
|
// ************************* END Events ************************************************************
|
170
|
|
171
|
|
172
|
public boolean isStartingElement(XMLEvent event, String elName) throws XMLStreamException {
|
173
|
return super.isStartingElement(event, elName);
|
174
|
}
|
175
|
|
176
|
public boolean isEndingElement(XMLEvent event, String elName) throws XMLStreamException {
|
177
|
return super.isEndingElement(event, elName);
|
178
|
}
|
179
|
|
180
|
public void fillMissingEpithetsForTaxa(Taxon parentTaxon, Taxon childTaxon) {
|
181
|
super.fillMissingEpithetsForTaxa(parentTaxon, childTaxon);
|
182
|
}
|
183
|
|
184
|
public Feature getFeature(MarkupImportState state, UUID uuid, String label, String text, String labelAbbrev, TermVocabulary<Feature> voc){
|
185
|
return super.getFeature(state, uuid, label, text, labelAbbrev, voc);
|
186
|
}
|
187
|
|
188
|
public ExtensionType getExtensionType(MarkupImportState state, UUID uuid, String label, String text, String labelAbbrev){
|
189
|
return super.getExtensionType(state, uuid, label, text, labelAbbrev);
|
190
|
}
|
191
|
|
192
|
public AnnotationType getAnnotationType(MarkupImportState state, UUID uuid, String label, String text, String labelAbbrev, TermVocabulary<AnnotationType> voc){
|
193
|
return super.getAnnotationType(state, uuid, label, text, labelAbbrev, voc);
|
194
|
}
|
195
|
|
196
|
public TextData getFeaturePlaceholder(MarkupImportState state, DescriptionBase<?> description, Feature feature, boolean createIfNotExists) {
|
197
|
return super.getFeaturePlaceholder(state, description, feature, createIfNotExists);
|
198
|
}
|
199
|
|
200
|
public NamedAreaLevel getNamedAreaLevel(MarkupImportState state, UUID uuid, String label, String text, String labelAbbrev, TermVocabulary<NamedAreaLevel> voc){
|
201
|
return super.getNamedAreaLevel(state, uuid, label, text, labelAbbrev, voc);
|
202
|
}
|
203
|
|
204
|
public NamedArea getNamedArea(MarkupImportState state, UUID uuid, String label, String text, String labelAbbrev, NamedAreaType areaType, NamedAreaLevel level, TermVocabulary voc, TermMatchMode matchMode){
|
205
|
return super.getNamedArea(state, uuid, label, text, labelAbbrev, areaType, level, voc, matchMode);
|
206
|
}
|
207
|
|
208
|
public Language getLanguage(MarkupImportState state, UUID uuid, String label, String text, String labelAbbrev, TermVocabulary voc){
|
209
|
return super.getLanguage(state, uuid, label, text, labelAbbrev, voc);
|
210
|
}
|
211
|
|
212
|
public boolean getReadMediaData(){
|
213
|
return this.READ_MEDIA_DATA;
|
214
|
}
|
215
|
|
216
|
public Media getImageMedia(String uriString, boolean readMediaData, boolean isFigure) throws MalformedURLException {
|
217
|
return super.getImageMedia(uriString, readMediaData, isFigure);
|
218
|
}
|
219
|
|
220
|
public IEditGeoService getEditGeoService() {
|
221
|
return editGeoService;
|
222
|
}
|
223
|
|
224
|
|
225
|
|
226
|
|
227
|
}
|