Project

General

Profile

Download (4.77 KB) Statistics
| Branch: | Revision:
1
/**
2
* Copyright (C) 2007 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.redlist.bfnXml;
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
import org.springframework.transaction.TransactionStatus;
19

    
20
import eu.etaxonomy.cdm.common.ResultWrapper;
21
import eu.etaxonomy.cdm.io.common.ICdmIO;
22
import eu.etaxonomy.cdm.model.common.TimePeriod;
23
import eu.etaxonomy.cdm.model.reference.Reference;
24
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
25
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
26
/**
27
 *
28
 * @author a.oppermann
29
 * @date 04.07.2013
30
 *
31
 */
32
@Component
33
public class BfnXmlImportMetaData extends BfnXmlImportBase implements ICdmIO<BfnXmlImportState> {
34
	private static final Logger logger = Logger.getLogger(BfnXmlImportMetaData.class);
35
	private String sourceFileName;
36
	private String debVersion;
37
	private String timeStamp;
38

    
39
	public BfnXmlImportMetaData(){
40
		super();
41
	}
42

    
43
	@Override
44
	public boolean doCheck(BfnXmlImportState state){
45
		boolean result = true;
46
		//TODO needs to be implemented
47
		return result;
48
	}
49

    
50
	@Override
51
	public void doInvoke(BfnXmlImportState state){
52
		logger.warn("start import MetaData...");
53

    
54

    
55
		ResultWrapper<Boolean> success = ResultWrapper.NewInstance(true);
56

    
57
		BfnXmlImportConfigurator config = state.getConfig();
58
		Element elDataSet = getDataSetElement(config);
59
		Namespace bfnNamespace = config.getBfnXmlNamespace();
60
		//create complete source object
61
		if(elDataSet.getName().equalsIgnoreCase("DEBExport")){
62
			sourceFileName = elDataSet.getAttributeValue("source");
63
			debVersion = elDataSet.getAttributeValue("debversion");
64
			timeStamp = elDataSet.getAttributeValue("timestamp");
65

    
66
			Reference<?> sourceReference = ReferenceFactory.newGeneric();
67
			sourceReference.setTitle(sourceFileName);
68
			TimePeriod parsedTimePeriod = TimePeriodParser.parseString(timeStamp);
69
			sourceReference.setDatePublished(parsedTimePeriod);
70
			state.setCompleteSourceRef(sourceReference);
71
		}
72

    
73
		List<?> contentXML = elDataSet.getContent();
74
		Element currentElement = null;
75
		for(Object object:contentXML){
76

    
77

    
78
			if(object instanceof Element){
79
				currentElement = (Element)object;
80

    
81
				if(currentElement.getName().equalsIgnoreCase("METADATEN")){
82

    
83
					TransactionStatus tx = startTransaction();
84

    
85
					String bfnElementName = "METADATEN";
86
					@SuppressWarnings("unchecked")
87
                    List<Element> elMetaDataList  = currentElement.getChildren();
88
					//for each taxonName
89
					for (Element elMetaData : elMetaDataList){
90
						if( elMetaData.getAttributeValue("standardname").equalsIgnoreCase("KurzLit_A")){
91
							@SuppressWarnings("unchecked")
92
                            List<Element> children = elMetaData.getChildren();
93
							String kurzlitA = children.get(0).getTextNormalize();
94
							Reference<?> sourceReference = ReferenceFactory.newGeneric();
95
							sourceReference.setTitle(kurzlitA);
96
							state.setFirstListSecRef(sourceReference);
97

    
98
						}
99
						else if( elMetaData.getAttributeValue("standardname").equalsIgnoreCase("Klassifikation_A")){
100
							@SuppressWarnings("unchecked")
101
                            List<Element> children = elMetaData.getChildren();
102
							String klassifikation_A = children.get(0).getTextNormalize();
103
							state.setFirstClassificationName(klassifikation_A);
104

    
105
						}
106
						else if( elMetaData.getAttributeValue("standardname").equalsIgnoreCase("KurzLit_B")){
107
							@SuppressWarnings("unchecked")
108
                            List<Element> children = elMetaData.getChildren();
109
							String kurzlitB = children.get(0).getTextNormalize();
110
							Reference<?> sourceReference = ReferenceFactory.newGeneric();
111
							sourceReference.setTitle(kurzlitB);
112
							state.setSecondListSecRef(sourceReference);
113
						}
114
						else if( elMetaData.getAttributeValue("standardname").equalsIgnoreCase("Klassifikation_B")){
115
							@SuppressWarnings("unchecked")
116
                            List<Element> children = elMetaData.getChildren();
117
							String klassifikation_B = children.get(0).getTextNormalize();
118
							state.setSecondClassificationName(klassifikation_B);
119

    
120
						}
121

    
122
					}
123

    
124
					logger.warn("end import MetaData ...");
125
					commitTransaction(tx);
126

    
127

    
128
					if (!success.getValue()){
129
						state.setUnsuccessfull();
130
					}
131
					//FIXME: Only take the first RoteListeData Features
132

    
133

    
134
					return;
135
				}
136
			}
137
		}
138
		return;
139

    
140
	}
141

    
142
	@Override
143
	protected boolean isIgnore(BfnXmlImportState state) {
144
		return ! state.getConfig().isDoMetaData();
145
	}
146

    
147
}
(5-5/8)