Project

General

Profile

Download (4.65 KB) Statistics
| Branch: | Tag: | Revision:
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 java.util.ArrayList;
13
import java.util.List;
14

    
15
import org.apache.log4j.Logger;
16
import org.jdom.Element;
17
import org.jdom.Namespace;
18
import org.springframework.stereotype.Component;
19

    
20
import eu.etaxonomy.cdm.api.service.IReferenceService;
21
import eu.etaxonomy.cdm.common.DoubleResult;
22
import eu.etaxonomy.cdm.common.XmlHelp;
23
import eu.etaxonomy.cdm.io.common.ICdmIO;
24
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
25
import eu.etaxonomy.cdm.io.common.ImportHelper;
26
import eu.etaxonomy.cdm.io.common.MapWrapper;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29

    
30
/**
31
 * @author a.mueller
32
 *
33
 */
34
@Component
35
public class TcsXmlPublicationsImport extends TcsXmlImportBase implements ICdmIO<TcsXmlImportState> {
36
	private static final Logger logger = Logger.getLogger(TcsXmlPublicationsImport.class);
37

    
38
	private static int modCount = 1000;
39

    
40

    
41
	public TcsXmlPublicationsImport(){
42
		super();
43

    
44
	}
45

    
46
	@Override
47
	public boolean doCheck(TcsXmlImportState state){
48
		boolean result = true;
49
		result &= checkArticlesWithoutJournal(state.getConfig());
50
		//result &= checkPartOfJournal(config);
51

    
52
		return result;
53
	}
54

    
55
	private static boolean checkArticlesWithoutJournal(IImportConfigurator bmiConfig){
56
		try {
57
			boolean result = true;
58
			//TODO
59
			//				result = firstRow = false;
60
//			}
61
//
62
			return result;
63
		} catch (Exception e) {
64
			e.printStackTrace();
65
			return false;
66
		}
67
	}
68

    
69

    
70

    
71
	@Override
72
	public void doInvoke(TcsXmlImportState state){
73

    
74
		logger.info("start make Publications ...");
75
		boolean success = true;
76
		String childName;
77
		boolean obligatory;
78

    
79
		MapWrapper<Reference> referenceMap = (MapWrapper<Reference>)state.getStore(ICdmIO.REFERENCE_STORE);
80
		IReferenceService referenceService = getReferenceService();
81

    
82
		TcsXmlImportConfigurator config = state.getConfig();
83
		Element elDataSet = getDataSetElement(config);
84
		Namespace tcsNamespace = config.getTcsXmlNamespace();
85

    
86
		DoubleResult<Element, Boolean> doubleResult;
87
		childName = "Publications";
88
		obligatory = false;
89
		doubleResult = XmlHelp.getSingleChildElement(elDataSet, childName, tcsNamespace, obligatory);
90
		success &= doubleResult.getSecondResult();
91
		Element elPublications = doubleResult.getFirstResult();
92

    
93
		String tcsElementName = "Publication";
94
		String idNamespace = "Publication";
95
		List<Element> elPublicationList = elPublications == null ? new ArrayList<Element>() : elPublications.getChildren(tcsElementName, tcsNamespace);
96

    
97
		int i = 0;
98
		//for each taxonName
99
		for (Element elPublication : elPublicationList){
100
			if ((++i % modCount) == 0){ logger.info("publications handled: " + (i-1));}
101

    
102
			//create TaxonName element
103
			String strId = elPublication.getAttributeValue("id");
104

    
105
			childName = "Simple";
106
			obligatory = true;
107
			doubleResult = XmlHelp.getSingleChildElement(elPublication, childName, tcsNamespace, obligatory);
108
			success &= doubleResult.getSecondResult();
109
			Element elSimple = doubleResult.getFirstResult();
110

    
111
			String simple = elSimple.getTextNormalize();
112

    
113
			Reference reference = ReferenceFactory.newGeneric();
114
			reference.setTitleCache(simple, true);
115

    
116
			childName = "PublicationDetailed";
117
			obligatory = false;
118
			doubleResult =  XmlHelp.getSingleChildElement(elPublication, childName, tcsNamespace, obligatory);
119
			success &= doubleResult.getSecondResult();
120
			Element elPublicationDetailed = doubleResult.getFirstResult();
121

    
122
			success &= config.getPlaceholderClass().makePublicationDetailed(config, elPublicationDetailed, reference);
123
			ImportHelper.setOriginalSource(reference, config.getSourceReference(), strId, idNamespace);
124

    
125
			referenceMap.put(strId, reference);
126

    
127

    
128
		}
129
//		//save and store in map
130
//		logger.info("Save nomenclatural references (" + nomRefCount + ")");
131
//		referenceService.saveReferenceAll(nomRefMap.objects());
132
		logger.info("Save bibliographical references (" + i +")");
133
		referenceService.save(referenceMap.objects());
134

    
135
		logger.info("end make publications ...");
136
		if (!success){
137
			state.setUnsuccessfull();
138
		}
139
		return;
140
	}
141

    
142
	/* (non-Javadoc)
143
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
144
	 */
145
	@Override
146
    protected boolean isIgnore(TcsXmlImportState state){
147
		return (state.getConfig().getDoReferences() == IImportConfigurator.DO_REFERENCES.NONE);
148
	}
149

    
150
}
(6-6/11)