Project

General

Profile

Download (4.63 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.in;
10

    
11
import java.sql.ResultSet;
12
import java.sql.SQLException;
13
import java.util.HashMap;
14
import java.util.Map;
15
import java.util.UUID;
16

    
17
import org.apache.log4j.Logger;
18
import org.springframework.stereotype.Component;
19

    
20
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
21
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelWebMarkerCategoryImportValidator;
22
import eu.etaxonomy.cdm.io.common.IOValidator;
23
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
24
import eu.etaxonomy.cdm.io.common.Source;
25
import eu.etaxonomy.cdm.model.common.CdmBase;
26
import eu.etaxonomy.cdm.model.common.MarkerType;
27

    
28

    
29
/**
30
 * @author a.mueller
31
 * @created 20.03.2008
32
 * @version 1.0
33
 */
34
@Component
35
public class BerlinModelWebMarkerCategoryImport extends BerlinModelImportBase {
36
	private static final Logger logger = Logger.getLogger(BerlinModelWebMarkerCategoryImport.class);
37

    
38
	private static int modCount = 100;
39
	private static final String dbTableName = "webMarkerCategory";
40
	private static final String pluralString = "markerCategories";
41
	
42
	public BerlinModelWebMarkerCategoryImport(){
43
		super(dbTableName, pluralString);
44
	}
45
	
46
	private static Map<String, MarkerType> generalCategoryMap;
47
	
48
	private static Map<String, MarkerType> getGeneralCategoryMap(){
49
		if (generalCategoryMap == null){
50
			generalCategoryMap = new HashMap<String, MarkerType>();
51
			String tableName = "webMarkerCategory_";
52
			generalCategoryMap.put(tableName + 1, MarkerType.COMPLETE());
53
		}
54
		return generalCategoryMap;
55
	}
56
	
57
	/* (non-Javadoc)
58
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#doInvoke(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState)
59
	 */
60
	protected void doInvoke(BerlinModelImportState state){
61
		boolean success = true ;
62

    
63
		BerlinModelImportConfigurator config = state.getConfig();
64
		Source source = config.getSource();
65

    
66
		logger.info("start make "+pluralString+" ...");
67
		
68
		ResultSet rs = source.getResultSet(getRecordQuery(config)) ;
69
		
70
		int i = 0;
71
		//for each reference
72
		try{
73
			while (rs.next()){
74
				try{
75
					if ((i++ % modCount ) == 0 && i!= 1 ){ logger.info(""+pluralString+" handled: " + (i-1));}
76
					
77
					//
78
					int markerCategoryId = rs.getInt("MarkerCategoryID");
79
					String fullDbId = dbTableName + "_" + markerCategoryId;
80
					MarkerType markerType = getGeneralCategoryMap().get(fullDbId);
81
					if (markerType == null){
82
						String markerDescription = rs.getString("MarkerDescription");
83
						String markerCategory = rs.getString("MarkerCategory");
84
						UUID uuid = BerlinModelTransformer.getWebMarkerUuid(markerCategoryId);
85
						markerType = getMarkerType(state, uuid, markerDescription, markerCategory, null);
86
						getTermService().saveOrUpdate(markerType);
87
					}
88
					state.putDefinedTermToMap(dbTableName, markerCategoryId, markerType);
89
//					state.putMarkerType(markerType);
90

    
91
				}catch(Exception ex){
92
					logger.error(ex.getMessage());
93
					ex.printStackTrace();
94
					success = false;
95
				}
96
			} //while rs.hasNext()
97
		} catch (SQLException e) {
98
			logger.error("SQLException:" +  e);
99
			state.setUnsuccessfull();
100
			return;
101
		}
102

    
103
			
104
		logger.info("save " + i + " "+pluralString + " ...");
105

    
106
		logger.info("end make "+pluralString+" ..." + getSuccessString(success));;
107
		if (!success){
108
			state.setUnsuccessfull();
109
		}
110
		return;
111
		
112
	}
113
	
114

    
115
	/* (non-Javadoc)
116
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getRecordQuery(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator)
117
	 */
118
	@Override
119
	protected String getRecordQuery(BerlinModelImportConfigurator config) {
120
		String strQuery = 
121
			" SELECT *  " +
122
            " FROM "+dbTableName+" " ;
123
		return strQuery;
124
	}
125

    
126
	@Override
127
	public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState state) {
128
		return false; // not needed
129
	}
130

    
131
	@Override
132
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
133
		return null; // not needed
134
	}
135

    
136
	@Override
137
	protected boolean doCheck(BerlinModelImportState state){
138
		IOValidator<BerlinModelImportState> validator = new BerlinModelWebMarkerCategoryImportValidator();
139
		return validator.validate(state);
140
	}
141
	
142
	@Override
143
	protected boolean isIgnore(BerlinModelImportState state){
144
		return ! state.getConfig().isDoMarker();
145
	}
146

    
147
}
(20-20/21)