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 org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
13
|
import org.jdom.Element;
|
14
|
import org.jdom.Namespace;
|
15
|
import org.springframework.stereotype.Component;
|
16
|
|
17
|
import eu.etaxonomy.cdm.common.DoubleResult;
|
18
|
import eu.etaxonomy.cdm.common.XmlHelp;
|
19
|
import eu.etaxonomy.cdm.io.common.ICdmIO;
|
20
|
|
21
|
/**
|
22
|
* @author a.mueller
|
23
|
*
|
24
|
*/
|
25
|
@Component
|
26
|
public class TcsXmlMetaDataImport extends TcsXmlImportBase implements ICdmIO<TcsXmlImportState> {
|
27
|
private static final Logger logger = LogManager.getLogger(TcsXmlMetaDataImport.class);
|
28
|
|
29
|
private static int modCount = 1000;
|
30
|
|
31
|
public TcsXmlMetaDataImport(){
|
32
|
super();
|
33
|
}
|
34
|
|
35
|
@Override
|
36
|
public boolean doCheck(TcsXmlImportState state){
|
37
|
boolean result = true;
|
38
|
//result &= checkArticlesWithoutJournal(config);
|
39
|
//result &= checkPartOfJournal(config);
|
40
|
|
41
|
return result;
|
42
|
}
|
43
|
|
44
|
|
45
|
|
46
|
@Override
|
47
|
public void doInvoke(TcsXmlImportState state){
|
48
|
logger.info("start make MetaData ...");
|
49
|
boolean success = true;
|
50
|
String childName;
|
51
|
boolean obligatory;
|
52
|
|
53
|
// MapWrapper<Reference> referenceMap = (MapWrapper<Reference>)stores.get(ICdmIO.REFERENCE_STORE);
|
54
|
|
55
|
TcsXmlImportConfigurator config = state.getConfig();
|
56
|
Element elDataSet = getDataSetElement(config);
|
57
|
Namespace tcsNamespace = config.getTcsXmlNamespace();
|
58
|
|
59
|
DoubleResult<Element, Boolean> doubleResult;
|
60
|
childName = "MetaData";
|
61
|
obligatory = false;
|
62
|
doubleResult = XmlHelp.getSingleChildElement(elDataSet, childName, tcsNamespace, obligatory);
|
63
|
success &= doubleResult.getSecondResult();
|
64
|
Element elMetaData = doubleResult.getFirstResult();
|
65
|
|
66
|
childName = "Simple";
|
67
|
obligatory = true;
|
68
|
doubleResult = XmlHelp.getSingleChildElement(elMetaData, childName, tcsNamespace, obligatory);
|
69
|
success &= doubleResult.getSecondResult();
|
70
|
Element elSimple = doubleResult.getFirstResult();
|
71
|
//TODO do simple MetaData
|
72
|
if (elSimple != null && (elSimple.getChildren().size() > 0 || elSimple.getAttributes().size() > 0 )){
|
73
|
logger.warn("Simple Metadata not handled yet");
|
74
|
}
|
75
|
|
76
|
childName = "MetaDataDetailed";
|
77
|
obligatory = false;
|
78
|
doubleResult = XmlHelp.getSingleChildElement(elMetaData, childName, tcsNamespace, obligatory);
|
79
|
success &= doubleResult.getSecondResult();
|
80
|
Element elMetaDataDetailed = doubleResult.getFirstResult();
|
81
|
|
82
|
success &= config.getPlaceholderClass().makeMetaDataDetailed(config, elMetaDataDetailed);
|
83
|
// try {
|
84
|
// List<Object> args = Arrays.asList(tcsConfig, elMetaDataDetailed);
|
85
|
// tcsConfig.getFunctionMetaDataDetailed().invoke(this, args);
|
86
|
// } catch (IllegalArgumentException e) {
|
87
|
// e.printStackTrace();
|
88
|
// success = false;
|
89
|
// } catch (IllegalAccessException e) {
|
90
|
// e.printStackTrace();
|
91
|
// success = false;
|
92
|
// } catch (InvocationTargetException e) {
|
93
|
// e.printStackTrace();
|
94
|
// success = false;
|
95
|
// }
|
96
|
|
97
|
logger.info("end make MetaData ...");
|
98
|
if (!success){
|
99
|
state.setUnsuccessfull();
|
100
|
}
|
101
|
return;
|
102
|
}
|
103
|
|
104
|
|
105
|
/* (non-Javadoc)
|
106
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
107
|
*/
|
108
|
protected boolean isIgnore(TcsXmlImportState state){
|
109
|
TcsXmlImportConfigurator tcsConfig = state.getConfig();
|
110
|
return (! tcsConfig.isDoMetaData());
|
111
|
}
|
112
|
|
113
|
}
|