Project

General

Profile

Download (4.74 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
		//TODO only dirty quick fix for now
55
		state.setFirstClassificationName(state.getConfig().getClassificationName());
56

    
57
		ResultWrapper<Boolean> success = ResultWrapper.NewInstance(true);
58

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

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

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

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

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

    
84
					TransactionStatus tx = startTransaction();
85

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

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

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

    
121
						}
122

    
123
					}
124

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

    
128

    
129
					if (!success.getValue()){
130
						state.setUnsuccessfull();
131
					}
132
					//FIXME: Only take the first RoteListeData Features
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)