Project

General

Profile

Download (6.53 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
package eu.etaxonomy.cdm.io.berlinModel.out;
10

    
11
import java.sql.SQLException;
12
import java.util.List;
13

    
14
import org.apache.log4j.Logger;
15
import org.springframework.stereotype.Component;
16
import org.springframework.transaction.TransactionStatus;
17

    
18
import eu.etaxonomy.cdm.io.common.Source;
19
import eu.etaxonomy.cdm.io.common.mapping.out.CdmDbExportMapping;
20
import eu.etaxonomy.cdm.io.common.mapping.out.CreatedAndNotesMapper;
21
import eu.etaxonomy.cdm.io.common.mapping.out.DbExtensionMapper;
22
import eu.etaxonomy.cdm.io.common.mapping.out.DbStringMapper;
23
import eu.etaxonomy.cdm.io.common.mapping.out.DbTimePeriodMapper;
24
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
25
import eu.etaxonomy.cdm.io.common.mapping.out.IdMapper;
26
import eu.etaxonomy.cdm.model.agent.AgentBase;
27
import eu.etaxonomy.cdm.model.agent.Person;
28
import eu.etaxonomy.cdm.model.common.CdmBase;
29
import eu.etaxonomy.cdm.model.common.ExtensionType;
30

    
31

    
32
/**
33
 * @author a.mueller
34
 * @since 20.03.2008
35
 * @version 1.0
36
 */
37
@Component
38
public class BerlinModelAuthorExport extends BerlinModelExportBase<Person> {
39
	private static final Logger logger = Logger.getLogger(BerlinModelAuthorExport.class);
40

    
41
	private static int modCount = 5000;
42
	private static final String dbTableName = "Author";
43
	private static final String pluralString = "Authors";
44
	private static final Class<? extends CdmBase> standardMethodParameter = Person.class;
45
	public BerlinModelAuthorExport(){
46
		super();
47
	}
48

    
49

    
50
	@Override
51
	protected boolean doCheck(BerlinModelExportState state){
52
		boolean result = true;
53
		logger.warn("Checking for "+pluralString+" not yet implemented");
54
		//result &= checkArticlesWithoutJournal(bmiConfig);
55
		//result &= checkPartOfJournal(bmiConfig);
56

    
57
		return result;
58
	}
59

    
60
	private CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> getMapping(){
61
		String tableName = dbTableName;
62
		CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping = new CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer>(tableName);
63
		mapping.addMapper(IdMapper.NewInstance("AuthorId"));
64
		mapping.addMapper(DbStringMapper.NewInstance("nomenclaturalTitle", "Abbrev"));
65
		mapping.addMapper(DbStringMapper.NewInstance("givenname", "FirstName"));
66
		mapping.addMapper(DbStringMapper.NewInstance("familyname", "LastName"));
67
		mapping.addMapper(DbTimePeriodMapper.NewInstance("lifespan", "Dates"));
68
		mapping.addMapper(DbExtensionMapper.NewInstance(ExtensionType.NOMENCLATURAL_STANDARD(), "NomStandard"));
69
		mapping.addMapper(DbExtensionMapper.NewInstance(ExtensionType.AREA_OF_INTREREST(), "AreaOfInterest"));
70
		mapping.addMapper(DbExtensionMapper.NewInstance(ExtensionType.ABBREVIATION(), "Initials"));
71
//		mapping.addMapper(DbExtensionMapper.NewInstance(ExtensionType.ABBREVIATION(),Kürzel")); //Initials used instead
72
//		mapping.addMapper(DbExtensionMapper.NewInstance(ExtensionType.ABBREVIATION(), "DraftKürz")); //Initials used instead
73
		mapping.addMapper(CreatedAndNotesMapper.NewInstance());
74

    
75
		return mapping;
76
	}
77

    
78
	@Override
79
	protected void doInvoke(BerlinModelExportState state) {
80
		try{
81
			boolean success = true;
82
			BerlinModelExportConfigurator bmeConfig = state.getConfig();
83

    
84
			logger.info("start make "+pluralString+" ...");
85
			doDelete(bmeConfig);
86

    
87
			TransactionStatus txStatus = startTransaction(true);
88
			Class<Person> clazz = Person.class;
89
			List<Person> persons = getAgentService().list(clazz, 100000000, 0, null, null);
90

    
91
			CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping = getMapping();
92
			mapping.initialize(state);
93

    
94
			logger.info("save "+pluralString+" ...");
95
			int count = 0;
96
			for (AgentBase<?> agent : persons){
97
				doCount(count++, modCount, pluralString);
98
				if (agent instanceof Person){
99
					success &= mapping.invoke(agent);
100
				}
101
			}
102

    
103
			commitTransaction(txStatus);
104
			logger.info("end make "+pluralString+"  ..." + getSuccessString(success));
105
			if (!success){
106
                String message = "An undefined error occurred during Author export";
107
                state.getResult().addError(message);
108
			}
109
			return;
110
		}catch(SQLException e){
111
			e.printStackTrace();
112
			logger.error(e.getMessage());
113
			state.getResult().addException(e);
114
			return;
115
		}
116
	}
117

    
118
	protected boolean doDelete(BerlinModelExportConfigurator config){
119

    
120
		//TODO make more generic for all BerlinModelExport classes
121
		String sql;
122
		Source destination =  config.getDestination();
123
		//RelPTaxon
124
		sql = "DELETE FROM RelPTaxon";
125
		destination.setQuery(sql);
126
		destination.update(sql);
127
		//Fact
128
		sql = "DELETE FROM Fact";
129
		destination.setQuery(sql);
130
		destination.update(sql);
131
		//PTaxon
132
		sql = "DELETE FROM PTaxon";
133
		destination.setQuery(sql);
134
		destination.update(sql);
135

    
136
		//NameHistory
137
		sql = "DELETE FROM NameHistory";
138
		destination.setQuery(sql);
139
		destination.update(sql);
140
		//RelName
141
		sql = "DELETE FROM RelName";
142
		destination.setQuery(sql);
143
		destination.update(sql);
144
		//NomStatusRel
145
		sql = "DELETE FROM NomStatusRel";
146
		destination.setQuery(sql);
147
		destination.update(sql);
148
		//Name
149
		sql = "DELETE FROM Name";
150
		destination.setQuery(sql);
151
		destination.update(sql);
152
		//RefDetail
153
		sql = "DELETE FROM RefDetail";
154
		destination.setQuery(sql);
155
		destination.update(sql);
156
		//Reference
157
		sql = "DELETE FROM Reference";
158
		destination.setQuery(sql);
159
		destination.update(sql);
160
		//AuthorTeamSequence
161
		sql = "DELETE FROM AuthorTeamSequence";
162
		destination.setQuery(sql);
163
		destination.update(sql);
164
		//AuthorTeam
165
		sql = "DELETE FROM AuthorTeam";
166
		destination.setQuery(sql);
167
		destination.update(sql);
168
		//Author
169
		sql = "DELETE FROM Author";
170
		destination.setQuery(sql);
171
		destination.update(sql);
172
		return true;
173
	}
174

    
175

    
176
	/* (non-Javadoc)
177
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IIoConfigurator)
178
	 */
179
	@Override
180
	protected boolean isIgnore(BerlinModelExportState state) {
181
		return ! state.getConfig().isDoAuthors();
182
	}
183

    
184
	/* (non-Javadoc)
185
	 * @see eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportBase#getStandardMethodParameter()
186
	 */
187
	@Override
188
	public Class<? extends CdmBase> getStandardMethodParameter() {
189
		return standardMethodParameter;
190
	}
191

    
192

    
193

    
194
}
(1-1/12)