Project

General

Profile

« Previous | Next » 

Revision 2d481abb

Added by Katja Luther almost 10 years ago

changes in Fauna Europeae Import and Index Fungorum Import and PESI Export

View differences:

cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/common/CdmDestinations.java
34 34
	public static ICdmDataSource cdm_test_local_faunaEu_mysql(){
35 35
		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
36 36
		String cdmServer = "127.0.0.1";
37
		String cdmDB = "cdm_test_fauneu"; 
37
		String cdmDB = "cdm_test"; 
38 38
		String cdmUserName = "root";
39 39
		return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
40 40
	}
cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/FaunaEuropaeaActivator.java
37 37
	private static final Logger logger = Logger.getLogger(FaunaEuropaeaActivator.class);
38 38

  
39 39

  
40
	static final Source faunaEuropaeaSource = PesiSources.faunEu_pesi3();
40
	static final Source faunaEuropaeaSource = PesiSources.mfn_faunEu_pesi3();
41 41
	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_faunaEu_mysql();
42 42

  
43 43
	
cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/IndexFungorumActivator.java
41 41

  
42 42
	//database validation status (create, update, validate ...)
43 43
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
44
	static final Source indexFungorumSource = PesiSources.PESI_IF();
44
	static final Source indexFungorumSource = PesiSources.PESI3_IF();
45 45
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_pesi_erms();
46 46
	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_indexFungorum();
47 47
	static final UUID treeUuid = UUID.fromString("4bea48c3-eb10-41d1-b708-b5ee625ed243");
......
51 51

  
52 52
	static final int partitionSize = 2000;
53 53
	
54
	static final boolean doPesiExport = true;
54
	static final boolean doPesiExport = false;
55 55
	
56 56

  
57 57
	//NomeclaturalCode
cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/PesiDestinations.java
61 61
		String strServer = "pesiimport3"; //192.168.1.223
62 62
		String strDB = "CDM_IF2PESI";
63 63
		int port = 1433;
64
		String userName = "pesiexport";
64
		String userName = "pesiExportFaunaEu";
65 65
		return makeSource(dbms, strServer, strDB, port, userName, null);
66 66
	}
67 67
	
cdm-pesi/src/main/java/eu/etaxonomy/cdm/app/pesi/PesiSources.java
37 37
		//	Fauna Europaea auf pesiimport3
38 38
		String dbms = Source.SQL_SERVER_2008;
39 39
        String strServer = "pesiimport3";
40
        String strDB = "MfN_FaunaEuropeae";
40
        String strDB = "MfN_FaunaEuropaea";
41 41
		int port = 1433;
42 42
		String userName = "pesiExportFaunaEu";
43 43
		return  ImportUtils.makeSource(dbms, strServer, strDB, port, userName, null);
......
93 93
		return  makeSource(dbms, strServer, strDB, port, userName, null);
94 94
	}
95 95
	
96
	public static Source PESI3_IF(){
97
		//	BerlinModel - Pesi-ERMS
98
		String dbms = Source.SQL_SERVER_2008;
99
		String strServer = "Pesiimport3";
100
		String strDB = "IF_2014_06";
101
		int port = 1433;
102
		String userName = "pesiExportFaunaEu";
103
		return  makeSource(dbms, strServer, strDB, port, userName, null);
104
	}
105
	
96 106
	public static Source PESI_IF(){
97 107
		//	BerlinModel - Pesi-IF
98 108
		String dbms = Source.SQL_SERVER_2008;
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/faunaEuropaea/FaunaEuropaeaAdditionalTaxonDataImport.java
37 37
public class FaunaEuropaeaAdditionalTaxonDataImport extends FaunaEuropaeaImportBase  {
38 38
	
39 39
	private static final Logger logger = Logger.getLogger(FaunaEuropaeaAdditionalTaxonDataImport.class);
40
	private static final String parentPluralString = "Synonyms";
40
//	private static final String parentPluralString = "Synonyms";
41 41
	private static final String pluralString = "InfraGenericEpithets";
42
	private static final String acceptedTaxonUUID = "A9C24E42-69F5-4681-9399-041E652CF338"; // any accepted taxon uuid, taken from original fauna europaea database
42
	//private static final String acceptedTaxonUUID = "A9C24E42-69F5-4681-9399-041E652CF338"; // any accepted taxon uuid, taken from original fauna europaea database
43 43

  
44 44
	/* (non-Javadoc)
45 45
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/faunaEuropaea/FaunaEuropaeaDistributionImport.java
221 221
					e.printStackTrace();
222 222
				}
223 223
			}
224
			rs = null;
224 225
		} catch (SQLException e) {
225 226
			logger.error("SQLException:" +  e);
226 227
			state.setUnsuccessfull();
227 228
		}
229
		
228 230
		if(logger.isInfoEnabled()) { logger.info("End making distributions..."); }
229 231
		
230 232
		return;
......
238 240
		 List<TaxonBase> taxonList = prepareTaxaAndDistribution(getTaxonService().find(taxonUuids), fauEuTaxonMap, noDataUuid, state);
239 241

  
240 242
		getTaxonService().save(taxonList);
243
		taxonList = null;
244
		taxonUuids = null;
245
		fauEuTaxonMap = null;
241 246
		commitTransaction(txStatus);
242 247
		
243 248
	}
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/faunaEuropaea/FaunaEuropaeaHeterotypicSynonymImport.java
96 96
					NameRelationship nameRelation = null;
97 97
					TaxonNameBase acceptedName = null;
98 98
					
99
					for (Synonym synonym : synonymList) {
99
					for (TaxonBase synonym : synonymList) {
100 100
						synonymName = synonym.getName();
101 101
						if (synonymName.isGroupsBasionym()) {
102 102
							nameRelations = synonymName.getNameRelations();
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/faunaEuropaea/FaunaEuropaeaRefImport.java
208 208
	        	
209 209
				if ((i++ % limit) == 0) {
210 210

  
211
					txStatus = startTransaction();
211
					txStatus = startTransactionForImports();
212 212
					references = new HashMap<Integer,Reference>(limit);
213 213
					authors = new HashMap<String,TeamOrPersonBase>(limit);
214 214
					
......
281 281
	        	
282 282
	        	
283 283
	        }
284
	        rsRefs = null;
284 285
	        if (references != null){
285 286
	        	commitReferences(references, authors, referenceUuids, i, txStatus);
286 287
	        	references= null;
......
290 291
			logger.error("SQLException:" +  e);
291 292
			state.setUnsuccessfull();
292 293
		}
294
		references = null;
295
		authors = null;
293 296
		
294 297
	}
295 298

  
......
453 456
		logger.error("SQLException:" +  e);
454 457
		state.setUnsuccessfull();
455 458
}
459
		taxonUuids = null;
460
		references = null;
461
		taxonList = null;
462
		fauEuTaxonMap = null;
463
		referenceIDs = null;
464
		referenceList = null;
465
		
466
		
456 467
	}
457 468

  
458 469
	private void commitTaxaReferenceRel(Set<UUID> taxonUuids,
......
492 503
				Set<Taxon> acceptedTaxa = syn.getAcceptedTaxa();
493 504
				if (acceptedTaxa.size() > 0) {
494 505
					taxon = syn.getAcceptedTaxa().iterator().next();
506
					logger.warn("Synonym (" + taxonBase.getUuid() + ") has accepted taxon" + taxon.getUuid());
495 507
				} else {
496 508
//								if (logger.isDebugEnabled()) { 
497
						logger.warn("Synonym (" + taxonBase.getUuid() + ") does not have accepted taxa");
509
					logger.warn("Synonym (" + taxonBase.getUuid() + ") does not have accepted taxa");
498 510
//								}
499 511
				}
500 512
			} else {
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/faunaEuropaea/FaunaEuropaeaRelTaxonIncludeImport.java
50 50
	private static final Logger logger = Logger.getLogger(FaunaEuropaeaRelTaxonIncludeImport.class);
51 51
	//private static final String acceptedTaxonUUID = "A9C24E42-69F5-4681-9399-041E652CF338"; // any accepted taxon uuid, taken from original fauna europaea database
52 52
	//private static final String acceptedTaxonUUID = "E23E6295-836A-4332-BF72-7D29949C7C60"; //faunaEu_1_3
53
	private static final String acceptedTaxonUUID = "BB9CDF6C-BBA3-4AC7-A3FD-648A14F518A0"; //for faunEu (2.4)
53
	//private static final String acceptedTaxonUUID = "bab7642e-f733-4a21-848d-a15250d2f4ed"; //for faunEu (2.4)
54
	private static final String acceptedTaxonUUID = "DADA6F44-B7B5-4C0A-9F32-980F54B02C36"; // for MfNFaunaEuropaea
54 55
	
55 56
	private Reference<?> sourceRef;
56 57
	private static String ALL_SYNONYM_FROM_CLAUSE = " FROM Taxon INNER JOIN Taxon AS Parent " +
......
108 109

  
109 110
		Classification tree = getClassificationFor(state, sourceRef);
110 111
		commitTransaction(txStatus);
111
		/*
112
		logger.warn("Before processParentsChildren");
113 112
		
114
		ProfilerController.memorySnapshot();
115
		*/
116
		if (state.getConfig().isDoTaxonomicallyIncluded()) {
113
		logger.warn("Before processParentsChildren" + state.getConfig().isDoTaxonomicallyIncluded());
114
		
115
		//ProfilerController.memorySnapshot();
116
		
117
		if (state.getConfig().isDoTaxonomicallyIncluded())  {
117 118
			processParentsChildren(state);
118 119
		}
119
		/*
120
		logger.warn("Before processMissappliedNames");
121 120
		
122
		ProfilerController.memorySnapshot();
123
		*/
121
		logger.warn("Before processMissappliedNames" + state.getConfig().isDoMisappliedNames());
122
		
123
		//ProfilerController.memorySnapshot();
124
		
124 125
		if (state.getConfig().isDoMisappliedNames()) {
125 126
			processMisappliedNames(state);
126 127
		}
......
138 139
		logger.warn("End RelTaxon doInvoke");
139 140
		ProfilerController.memorySnapshot();
140 141
		*/
141
		logger.info("End making taxa...");
142
		logger.info("End making relationships......");
142 143

  
143 144
		return;
144 145
	}
......
225 226
					}
226 227
				}
227 228
			}
228
	        
229
	        rs = null;
229 230
	        if (childParentMap != null){
230 231
	        	logger.info("processParentsChildren... last commit");
231 232
	        	createAndCommitParentChildRelationships(
......
237 238
			logger.error("SQLException:" +  e);
238 239
			state.setUnsuccessfull();
239 240
		}
241
		childParentMap = null;
240 242
		return;		
241 243
	}
242 244

  
......
395 397
			}
396 398
	        
397 399
	        storeSynonymRelationships(rs, count, state);
398

  
400
	        rs = null;
399 401
		} catch (SQLException e) {
400 402
			logger.error("SQLException:" +  e);
401 403
			state.setUnsuccessfull();
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/faunaEuropaea/FaunaEuropaeaTaxonNameImport.java
416 416
								
417 417
								taxon = Taxon.NewInstance(zooName, auctReference);
418 418
								taxonBase = taxon;
419
								logger.info("Misapplied name created ("+ taxonId + ") " + autName);
419
								//logger.info("Misapplied name created ("+ taxonId + ") " + autName);
420 420
								if (logger.isDebugEnabled()) {
421 421
									logger.debug("Misapplied name created (" + taxonId + ")");
422 422
									}
......
485 485
				}
486 486

  
487 487
			}
488
			rs = null;
488 489
			if (taxonMap != null){
489 490
				commitTaxa(state, txStatus, taxonMap, fauEuTaxonMap,
490 491
						synonymSet);
......
496 497
			logger.error("SQLException:" +  e);
497 498
			state.setUnsuccessfull();
498 499
		}
499

  
500
        taxonMap = null;
501
		synonymSet = null;
502
		fauEuTaxonMap = null;
500 503
		return;
501 504
	}
502 505

  
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/faunaEuropaea/FaunaEuropaeaUsersImport.java
19 19
import java.util.UUID;
20 20

  
21 21
import org.apache.log4j.Logger;
22
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
23
import org.springframework.security.core.userdetails.UserDetails;
22 24
import org.springframework.stereotype.Component;
23 25
import org.springframework.transaction.TransactionStatus;
26
import org.springframework.transaction.support.DefaultTransactionDefinition;
24 27

  
25 28
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
26 29
import eu.etaxonomy.cdm.io.common.ImportHelper;
......
45 48

  
46 49
	/* Interval for progress info message when retrieving taxa */
47 50
	private int modCount = 10000;
51
	
52
	 protected DefaultTransactionDefinition txDefinition = new DefaultTransactionDefinition();
48 53

  
49 54
	/* (non-Javadoc)
50 55
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
......
81 86
		logger.warn("Start User doInvoke");
82 87
		ProfilerController.memorySnapshot();
83 88
		*/
89
		
84 90
		TransactionStatus txStatus = null;
85 91
		Map<String, AgentBase<?>> persons = null;
86
		Map<Integer, User> users= null;
92
		Map<String, User> users= null;
93
		Map<Integer, Reference> references = null;
87 94
		Map<Integer, UUID> userUuids = new HashMap<Integer, UUID>();
88 95
		int limit = state.getConfig().getLimitSave();
89

  
96
		//this.authenticate("admin", "00000");  
97
		
90 98
		FaunaEuropaeaImportConfigurator fauEuConfig = state.getConfig();
91 99
		Source source = fauEuConfig.getSource();
92 100

  
......
117 125
			}
118 126
	        
119 127
	        while (rsUser.next()){
120
	        	int userId = rsUser.getInt("usr_id");
128
	        	int refId = rsUser.getInt("usr_id");
121 129
				String userTitle = rsUser.getString("usr_title");
122 130
				String userFirstname = rsUser.getString("usr_firstname");
123 131
				String userLastname = rsUser.getString("usr_lastname");
......
136 144
				if ((userTitle != null || userFirstname != null) && userLastname != null) {
137 145
					userPerson += " " + userLastname;
138 146
				}
139

  
147
				this.authenticate("admin", "00000");
140 148
				// build year
141 149
				String year = null;
142 150
				if (createdDate != null) {
......
147 155

  
148 156
					txStatus = startTransaction();
149 157
					persons= new HashMap<String,AgentBase<?>>(limit);
150
					users = new HashMap<Integer,User>(limit);
158
					users = new HashMap<String,User>(limit);
159
					references = new HashMap<Integer, Reference>(limit);
151 160
					
152 161
					if(logger.isInfoEnabled()) {
153 162
						logger.info("i = " + i + " - User import transaction started"); 
......
156 165
				
157 166
				AgentBase<?> person = null;
158 167
				User user = null;
159
				person= Person.NewTitledInstance(userTitle);
168
				Reference reference = null;
169
				person= Person.NewTitledInstance(userPerson);
160 170
				user = User.NewInstance(userPerson, userPwd);
161
				//reference.setTitle("" + refId); // This unique key is needed to get a hand on this Reference in PesiTaxonExport
162
				//reference.setDatePublished(ImportHelper.getDatePublished(year));
171
				reference = ReferenceFactory.newGeneric();
172
				reference.setTitle("" + refId); // This unique key is needed to get a hand on this Reference in PesiTaxonExport
173
				reference.setDatePublished(ImportHelper.getDatePublished(year));
174
				
163 175
				
164 176
				if (!persons.containsKey(userPerson)) {
165 177
					if (userPerson == null) {
......
175 187
				} else {
176 188
					person = persons.get(userPerson);
177 189
					if (logger.isDebugEnabled()) { 
178
						logger.debug("Not imported user with duplicated user_id (" + userId + 
190
						logger.debug("Not imported user with duplicated ref_id (" + refId + 
179 191
							") " + userPerson);
180 192
					}
181 193
				}
182 194
				
183 195
				// set protected titleCache
184
				/*StringBuilder referenceTitleCache = new StringBuilder(user.getTitleCache() + ".");
196
				StringBuilder referenceTitleCache = new StringBuilder(person.getTitleCache() + ".");
185 197
				if (year != null) {
186 198
					referenceTitleCache.append(" " + year);
187 199
				}
188 200
				reference.setTitleCache(referenceTitleCache.toString(), true);
189 201
				
190
				reference.setAuthorTeam(author);*/
202
				reference.setAuthorTeam((TeamOrPersonBase)person);
191 203
				
192 204
				//ImportHelper.setOriginalSource(user, fauEuConfig.getSourceReference(), userId, namespace);
193
				ImportHelper.setOriginalSource(person, fauEuConfig.getSourceReference(), userId, namespace);
205
				ImportHelper.setOriginalSource(person, fauEuConfig.getSourceReference(), refId, namespace);
194 206

  
195 207
				
196 208
				// Store persons
197
				if (!users.containsKey(userId)) {
209
				if (!users.containsKey(userPerson)) {
198 210

  
199 211
					if (user == null) {
200 212
						logger.warn("User is null");
201 213
					}
202
					users.put(userId, user);
214
					users.put(userPerson, user);
203 215
					if (logger.isTraceEnabled()) { 
204
						logger.trace("Stored user (" + userTitle + ")"); 
216
						logger.trace("Stored user (" + userPerson + ")"); 
205 217
					}
206 218
				} else {
207 219
					if (logger.isDebugEnabled()) { 
208
						logger.debug("Duplicated user(" + userId + ", " + userTitle+ ")");
220
						logger.debug("Duplicated user(" + userPerson +")");
209 221
					}
210 222
					//continue;
211 223
				}
212 224
				
213 225
				if (((i % limit) == 0 && i > 1 ) || i == count ) { 
214 226
					
215
					commitUsers(txStatus, persons, users,
227
					commitUsers(txStatus, persons, users, references,
216 228
							userUuids, i);
217 229
					
218 230
					users = null;					
......
221 233
	        	
222 234
	        }
223 235
	        if (users != null){
224
	        	commitUsers(txStatus, persons, users, userUuids, i);
236
	        	commitUsers(txStatus, persons, users, references, userUuids, i);
225 237
	        	users = null;					
226 238
				persons= null;
227 239
	        }
......
240 252

  
241 253
	private void commitUsers(TransactionStatus txStatus,
242 254
			Map<String, AgentBase<?>> persons,
243
			Map<Integer, User> users,
255
			Map<String, User> users,
256
			Map<Integer, Reference> references,
244 257
			Map<Integer, UUID> userUuids, int i) {
258
		
245 259
		Map<UUID, AgentBase> userMap =getAgentService().save((Collection)persons.values());
246
		logger.info("i = " + i + " - users saved"); 
247

  
260
		logger.info("i = " + i + " - persons saved"); 
261
		
262
	    
263
	       
248 264
		Iterator<Entry<UUID, AgentBase>> it = userMap.entrySet().iterator();
249 265
		while (it.hasNext()){
250 266
			AgentBase person = it.next().getValue();
......
254 270
		}
255 271
		
256 272
		getUserService().save((Collection)users.values());
273
		logger.info("i = " + users.size() + " - users saved"); 
274
		//getReferenceService().save(references.values());
275
		//logger.info("i = " +references.size() + " - references saved"); 
257 276
		commitTransaction(txStatus);
258 277
	}
259 278

  
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumDistributionImport.java
97 97
				Integer id = rs.getInt("PreferredNameIFnumber");
98 98
				Taxon taxon = state.getRelatedObject(NAMESPACE_SPECIES, String.valueOf(id), Taxon.class);
99 99
				Reference<?> ref = null;
100
				TaxonDescription description = getTaxonDescription(taxon, ref, false, true);
100
				if (taxon == null){
101
					logger.debug("taxon is null for id " + id);
102
				} else{
103
					TaxonDescription description = getTaxonDescription(taxon, ref, false, true);
101 104
				
102
				//handle single distributions
103
				int count = rs.getMetaData().getColumnCount();
104
				for (int i=1; i <= count; i++ ){
105
					String colName = rs.getMetaData().getColumnName(i);
106
					//exclude non distribution columns
107
					if (! excludedColumns.contains(colName)){
108
						String distributionValue = rs.getString(i);
109
						if (StringUtils.isNotBlank(distributionValue)){
110
							//create distribution for existing occurrences
111
							if (! distributionValue.equals("X")){
112
								logger.warn("Unexpected distribution value '" + distributionValue + "' for area " + colName);
105
					//handle single distributions
106
					int count = rs.getMetaData().getColumnCount();
107
					for (int i=1; i <= count; i++ ){
108
						String colName = rs.getMetaData().getColumnName(i);
109
						//exclude non distribution columns
110
						if (! excludedColumns.contains(colName)){
111
							String distributionValue = rs.getString(i);
112
							if (StringUtils.isNotBlank(distributionValue)){
113
								//create distribution for existing occurrences
114
								if (! distributionValue.equals("X")){
115
									logger.warn("Unexpected distribution value '" + distributionValue + "' for area " + colName);
116
								}
117
								NamedArea area = state.getTransformer().getNamedAreaByKey(colName);
118
								Distribution distribution = Distribution.NewInstance(area, status);
119
								description.addElement(distribution);
120
								//no last action
121
								distribution.addMarker(Marker.NewInstance(noLastActionMarkerType, true));
113 122
							}
114
							NamedArea area = state.getTransformer().getNamedAreaByKey(colName);
115
							Distribution distribution = Distribution.NewInstance(area, status);
116
							description.addElement(distribution);
117
							//no last action
118
							distribution.addMarker(Marker.NewInstance(noLastActionMarkerType, true));
123
							
119 124
						}
120
						
121 125
					}
126
					getTaxonService().saveOrUpdate(taxon);
122 127
				}
123 128
				
124 129
				//save
125
				getTaxonService().saveOrUpdate(taxon);
130
				
126 131
			}
127 132

  
128 133
			
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumGeneraImport.java
53 53
	
54 54
	@Override
55 55
	protected String getIdQuery() {
56
		String result = " SELECT RECORD_NUMBER FROM " + getTableName() +
57
				" ORDER BY PreferredName ";
56
		String result = " SELECT [RECORD NUMBER] FROM " + getTableName() +
57
				" ORDER BY [NAME OF FUNGUS] ";
58 58
		return result;
59 59
	}
60 60

  
......
64 64
	@Override
65 65
	protected String getRecordQuery(IndexFungorumImportConfigurator config) {
66 66
		String strRecordQuery = 
67
				" SELECT DISTINCT c.FamilyName, c.OrderName, c.SubclassName, c.ClassName, c.SubphylumName, c.PhylumName, c.KingdomName, g.* " +
68
                " FROM tblGenera AS g LEFT OUTER JOIN  dbo.[tblPESIfungi-Classification] AS c ON g.RECORD_NUMBER = c.PreferredNameFDCnumber " +
69
			" WHERE ( g.RECORD_NUMBER IN (" + ID_LIST_TOKEN + ") )" + 
67
				" SELECT DISTINCT c.[Family name], c.[Order name], c.[Subclass name], c.[Class name], c.[Subphylum name], c.[Phylum name], c.[Kingdom name], g.* " +
68
                " FROM tblGenera AS g LEFT OUTER JOIN  dbo.[tblPESIfungi-Classification] AS c ON g.[RECORD NUMBER] = c.PreferredNameFDCnumber " +
69
			" WHERE ( g.[RECORD NUMBER] IN (" + ID_LIST_TOKEN + ") )" + 
70 70
			"";
71 71
		return strRecordQuery;
72 72
	}
......
86 86
				//TODO
87 87
				//DisplayName, NomRefCache
88 88

  
89
				Integer id = (Integer)rs.getObject("RECORD_NUMBER");
89
				Double id = (Double)rs.getObject("RECORD NUMBER");
90 90
				
91 91
				
92
				String preferredName = rs.getString("PreferredName");
92
				String preferredName = rs.getString("NAME OF FUNGUS");
93 93
				if (StringUtils.isBlank(preferredName)){
94
					logger.warn("Preferred name is blank. This case is not yet handled by IF import. RECORD_NUMBER" + CdmUtils.Nz(id));
94
					logger.warn("Preferred name is blank. This case is not yet handled by IF import. RECORD NUMBER" + id);
95 95
				}
96 96
				
97 97
				Rank rank = Rank.GENUS();
......
105 105
				//author + publication
106 106
				makeAuthorAndPublication(state, rs, name);
107 107
				//source
108
				makeSource(state, taxon, id, NAMESPACE_GENERA );
109
				
108
				//makeSource(state, taxon, id, NAMESPACE_GENERA );
109
				if (id != null){
110
					makeSource(state, taxon, id.intValue(), NAMESPACE_GENERA );
111
				} else{
112
					makeSource(state, taxon, null,NAMESPACE_GENERA);
113
				}
110 114
				getTaxonService().saveOrUpdate(taxon);
111 115
			}
112 116

  
......
123 127
	
124 128
	private Taxon getParentTaxon(IndexFungorumImportState state, ResultSet rs) throws SQLException {
125 129
		String parentName = getParentNameString(rs);
126
		
130
		if (parentName == null){
131
			logger.warn("Parent name not found for: " + rs.getString("NAME OF FUNGUS"));
132
		}
127 133
		Taxon taxon = state.getRelatedObject(NAMESPACE_SUPRAGENERIC_NAMES, parentName, Taxon.class);
128 134
		if (taxon == null){
129
			logger.warn("Taxon not found for " + parentName);
135
			logger.warn("Taxon not found for " + parentName + " name of fungus: " +rs.getString("NAME OF FUNGUS") );
130 136
		}
131 137
		return taxon;
132 138
	}
133 139

  
134 140

  
135 141
	private String getParentNameString(ResultSet rs) throws SQLException {
136
		String parentName = rs.getString("FamilyName");
142
		String parentName = rs.getString("Family name");
143
		if (parentName == null){
144
			logger.warn(rs.getObject("NAME OF FUNGUS") + " has no family name. ");
145
			return null;
146
		}
137 147
		if (parentName.equalsIgnoreCase(INCERTAE_SEDIS)){
138
			parentName = rs.getString("OrderName");
148
			parentName = rs.getString("Order name");
139 149
			if (parentName.equalsIgnoreCase(INCERTAE_SEDIS)){
140
				parentName = rs.getString("SubclassName");
150
				parentName = rs.getString("Subclass name");
141 151
				if (parentName.equalsIgnoreCase(INCERTAE_SEDIS)){
142
					parentName = rs.getString("ClassName");
152
					parentName = rs.getString("Class name");
143 153
					if (parentName.equalsIgnoreCase(INCERTAE_SEDIS)){
144
						parentName = rs.getString("SubphylumName");
154
						parentName = rs.getString("Subphylum name");
145 155
						if (parentName.equalsIgnoreCase(INCERTAE_SEDIS)){
146
							parentName = rs.getString("PhylumName");
156
							parentName = rs.getString("Phylum name");
147 157
							if (parentName.equalsIgnoreCase(INCERTAE_SEDIS) || parentName.equalsIgnoreCase(FOSSIL_FUNGI) ){
148
								parentName = rs.getString("KingdomName");
158
								parentName = rs.getString("Kingdom name");
149 159
							}
150 160
						}
151 161
					}
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumHigherClassificationImport.java
21 21
import org.springframework.stereotype.Component;
22 22
import org.springframework.transaction.TransactionStatus;
23 23

  
24
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
24 25
import eu.etaxonomy.cdm.io.pesi.out.PesiTransformer;
25 26
import eu.etaxonomy.cdm.model.common.CdmBase;
26 27
import eu.etaxonomy.cdm.model.common.Marker;
......
31 32
import eu.etaxonomy.cdm.model.taxon.Classification;
32 33
import eu.etaxonomy.cdm.model.taxon.Taxon;
33 34
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
35
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
34 36

  
35 37

  
36 38
/**
......
52 54
	@Override
53 55
	protected String getRecordQuery(IndexFungorumImportConfigurator config) {
54 56
		String strRecordQuery = 
55
			" SELECT DISTINCT KingdomName, PhylumName, SubphylumName, ClassName, SubclassName, OrderName, FamilyName, g.PreferredName as GenusName, c.PreferredName as SpeciesName " + 
57
			" SELECT DISTINCT [Kingdom name], [Phylum name], [Subphylum name], [Class name], [Subclass name], [Order name], [Family name], g.[NAME OF FUNGUS] as GenusName, c.PreferredName as SpeciesName " + 
56 58
			" FROM [tblPESIfungi-Classification] c  LEFT OUTER JOIN " +
57
                      " tblGenera g ON c.PreferredNameFDCnumber = g.RECORD_NUMBER" +
59
                      " tblGenera g ON c.PreferredNameFDCnumber = g.[RECORD NUMBER]" +
58 60
//			" WHERE ( dr.id IN (" + ID_LIST_TOKEN + ") )";
59
			" ORDER BY KingdomName, PhylumName, SubphylumName, ClassName, SubclassName, OrderName, FamilyName, GenusName, SpeciesName ";
61
			" ORDER BY [Kingdom name], [Phylum name], [Subphylum name], [Class name], [Subclass name], [Order name],  [Family name], GenusName, SpeciesName ";
60 62
		return strRecordQuery;
61 63
	}
62 64

  
......
102 104
		
103 105
		try {
104 106
			while (rs.next()){
105
				String kingdom = rs.getString("KingdomName");
106
				String phylum = rs.getString("PhylumName");
107
				String subphylum = rs.getString("SubphylumName");
108
				String classname = rs.getString("ClassName");
109
				String subclass = rs.getString("SubclassName");
110
				String order = rs.getString("OrderName");
111
				String family = rs.getString("FamilyName");
107
				String kingdom = rs.getString("Kingdom name");
108
				String phylum = rs.getString("Phylum name");
109
				String subphylum = rs.getString("Subphylum name");
110
				String classname = rs.getString("Class name");
111
				String subclass = rs.getString("Subclass name");
112
				String order = rs.getString("Order name");
113
				String family = rs.getString("Family name");
112 114
//				String genus = rs.getString("GenusName");
113 115
//				String species = rs.getString("SpeciesName");
114 116
				
......
132 134
										Rank newRank = (lastKingdom.equals("Fungi") ? null : Rank.PHYLUM());
133 135
										taxonPhylum = makeTaxon(state, phylum, newRank);
134 136
										if (taxonPhylum != null){
135
											classification.addParentChild(higherTaxon, taxonPhylum, null, null);
137
											classification.addParentChild(higherTaxon, taxonPhylum, null, null, true);
136 138
										}
137 139
										higherTaxon = isIncertisSedis(phylum) ? higherTaxon : taxonPhylum;
138 140
										lastPhylum = phylum;
......
143 145
									Rank newRank = (lastKingdom.equals("Fungi") ? null : Rank.SUBPHYLUM());
144 146
									taxonSubphylum = makeTaxon(state, subphylum, newRank);
145 147
									if (taxonSubphylum != null){
146
										getClassification(state).addParentChild(higherTaxon,taxonSubphylum, null, null);
148
										getClassification(state).addParentChild(higherTaxon,taxonSubphylum, null, null,true);
147 149
									}
148 150
									higherTaxon = isIncertisSedis(subphylum) ? higherTaxon : taxonSubphylum;
149 151
									lastSubphylum = subphylum;
......
152 154
								}
153 155
								taxonClass = makeTaxon(state, classname, Rank.CLASS());
154 156
								if (taxonClass != null){
155
									getClassification(state).addParentChild(higherTaxon, taxonClass, null, null);
157
									getClassification(state).addParentChild(higherTaxon, taxonClass, null, null, true);
156 158
								}
157 159
								higherTaxon = isIncertisSedis(classname) ? higherTaxon : taxonClass;
158 160
								lastClassname = classname;
......
161 163
							}
162 164
							taxonSubclass = makeTaxon(state, subclass, Rank.SUBCLASS());
163 165
							if (taxonSubclass != null){
164
								getClassification(state).addParentChild(higherTaxon, taxonSubclass,null, null);
166
								getClassification(state).addParentChild(higherTaxon, taxonSubclass,null, null, true);
165 167
							}
166 168
							higherTaxon = isIncertisSedis(subclass) ? higherTaxon : taxonSubclass;
167 169
							lastSubclass = subclass;
......
170 172
						}
171 173
						taxonOrder = makeTaxon(state, order, Rank.ORDER());
172 174
						if (taxonOrder != null){
173
							getClassification(state).addParentChild(higherTaxon, taxonOrder, null, null);
175
							getClassification(state).addParentChild(higherTaxon, taxonOrder, null, null, true);
174 176
						}
175 177
						higherTaxon = isIncertisSedis(order) ? higherTaxon : taxonOrder;
176 178
						lastOrder = order;
......
179 181
					}
180 182
					taxonFamily = makeTaxon(state, family, Rank.FAMILY());
181 183
					if (taxonFamily != null){
182
						getClassification(state).addParentChild(higherTaxon, taxonFamily, null, null);
184
						try{
185
							getClassification(state).addParentChild(higherTaxon, taxonFamily, null, null, true);
186
						}catch(IllegalStateException e){
187
							if (e.getMessage().startsWith("The child taxon is already part of the tree")){
188
								//TaxonNode node = getClassification(state).getNode(taxonFamily);
189
								logger.warn(e.getMessage() + taxonFamily.getTitleCache() + " " + higherTaxon.getTitleCache());
190
								
191
									
192
									
193
								}
194
							
195
						}
183 196
					}
184 197
					higherTaxon = isIncertisSedis(family) ? higherTaxon : taxonFamily;
185 198
					lastFamily = family;
......
240 253
		Taxon taxon = state.getRelatedObject(IndexFungorumSupraGeneraImport.NAMESPACE_SUPRAGENERIC_NAMES, uninomial, Taxon.class);
241 254
		if (taxon == null){
242 255
			if (! newRank.equals(Rank.KINGDOM())){
243
				logger.warn("Taxon not found for " + uninomial);
256
				logger.warn("Taxon not found for uninomial " + uninomial);
244 257
			}
245 258
			NonViralName<?> name = BotanicalName.NewInstance(newRank);
246 259
			name.setGenusOrUninomial(uninomial);
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumImportBase.java
283 283
		boolean hasInReference = false;
284 284
		//publishing authors
285 285
		Team pubAuthor = null;
286
		String pubAuthorStr = rs.getString("PUBLISHING_AUTHORS");
286
		String pubAuthorStr = rs.getString("PUBLISHING AUTHORS");
287 287
		if (StringUtils.isNotBlank(pubAuthorStr)){
288 288
			if (StringUtils.isNotBlank(authorStr)){
289 289
				if (! pubAuthorStr.equals(authorStr)){
......
345 345
		ref.setVolume(volume);
346 346
		
347 347
		//year
348
		String yearOfPubl = rs.getString("YEAR_OF_PUBLICATION");
349
		String yearOnPubl = rs.getString("YEAR_ON_PUBLICATION");
348
		String yearOfPubl = rs.getString("YEAR OF PUBLICATION");
349
		String yearOnPubl = rs.getString("YEAR ON PUBLICATION");
350 350
		String year = null;
351 351
		if (StringUtils.isNotBlank(yearOfPubl)){
352 352
			year = yearOfPubl.trim();
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumSpeciesImport.java
58 58
	
59 59
	@Override
60 60
	protected String getIdQuery() {
61
		String result = " SELECT RECORD_NUMBER FROM " + getTableName() +
61
		String result = " SELECT PreferredNameIFnumber FROM " + getTableName() +
62 62
				" ORDER BY PreferredName ";
63 63
		return result;
64 64
	}
......
72 72
	@Override
73 73
	protected String getRecordQuery(IndexFungorumImportConfigurator config) {
74 74
		String strRecordQuery = 
75
				" SELECT DISTINCT distribution.PreferredNameFDCnumber, species.* , cl.PhylumName" +
76
				" FROM tblPESIfungi AS distribution RIGHT OUTER JOIN  dbo.[tblPESIfungi-IFdata] AS species ON distribution.PreferredNameIFnumber = species.RECORD_NUMBER " +
75
				" SELECT DISTINCT distribution.PreferredNameFDCnumber, species.* , cl.[Phylum name]" +
76
				" FROM tblPESIfungi AS distribution RIGHT OUTER JOIN  dbo.[tblPESIfungi-IFdata] AS species ON distribution.PreferredNameIFnumber = species.PreferredNameIFnumber " +
77 77
					" LEFT OUTER JOIN [tblPESIfungi-Classification] cl ON species.PreferredName   = cl.PreferredName " +
78
				" WHERE ( species.RECORD_NUMBER IN (" + ID_LIST_TOKEN + ") )" +
78
				" WHERE ( species.PreferredNameIFnumber IN (" + ID_LIST_TOKEN + ") )" +
79 79
			"";
80 80
		return strRecordQuery;
81 81
	}
......
93 93

  
94 94
				//DisplayName, NomRefCache -> don't use, created by Marc
95 95

  
96
				Integer id = (Integer)rs.getObject("RECORD_NUMBER");
97
				String phylumName = rs.getString("PhylumName");
96
				Integer id = (Integer)rs.getObject("PreferredNameIFnumber");
97
				String phylumName = rs.getString("Phylum name");
98 98
				
99 99
				String preferredName = rs.getString("PreferredName");
100 100
				if (StringUtils.isBlank(preferredName)){
101
					logger.warn("Preferred name is blank. This case is not yet handled by IF import. RECORD_NUMBER" + CdmUtils.Nz(id));
101
					logger.warn("Preferred name is blank. This case is not yet handled by IF import. RECORD UMBER" + CdmUtils.Nz(id));
102 102
				}
103 103
				
104 104
				Rank rank = Rank.SPECIES();
......
108 108
				
109 109
				Taxon taxon = Taxon.NewInstance(name, sourceReference);
110 110
				Taxon parent = getParentTaxon(state, rs);
111
				if (parent == null){
112
					logger.warn("parent not found for name:" +preferredName);
113
				}
111 114
				classification.addParentChild(parent, taxon, null, null);
112 115
				
113 116
				//author + publication
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumSupraGeneraImport.java
77 77
				//TODO
78 78
				//DisplayName, NomRefCache
79 79

  
80
				Integer id = (Integer)rs.getObject("RECORD_NUMBER");
80
				Double id = (Double)rs.getObject("RECORD NUMBER");
81 81
				
82
				String supragenericNames = rs.getString("SupragenericNames");
83
				String preferredName = rs.getString("PreferredName");
82
				String supragenericNames = rs.getString("Suprageneric names");
83
				//String preferredName = rs.getString("PreferredName");
84 84
				Integer rankFk = rs.getInt("PESI_RankFk");
85 85
				
86 86
				//name
87 87
				Rank rank = state.getTransformer().getRankByKey(String.valueOf(rankFk));
88 88
				NonViralName<?> name = BotanicalName.NewInstance(rank);
89 89
				name.setGenusOrUninomial(supragenericNames);
90
				if (preferredName != null && !preferredName.equals(supragenericNames)){
91
					logger.warn("Suprageneric names and preferredName is not equal. This case is not yet handled by IF import. I take SupragenericNames for import. RECORD_NUMBER" + CdmUtils.Nz(id));
92
				}
90
				/*if (preferredName != null && !preferredName.equals(supragenericNames)){
91
					logger.warn("Suprageneric names and preferredName is not equal. This case is not yet handled by IF import. I take SupragenericNames for import. RECORD NUMBER" +id);
92
				}*/
93 93
				
94 94
				//taxon
95 95
				Taxon taxon = Taxon.NewInstance(name, sourceReference);
96 96
				//author + nom.ref.
97 97
				makeAuthorAndPublication(state, rs, name);
98 98
				//source
99
				makeSource(state, taxon, id, NAMESPACE_SUPRAGENERIC_NAMES );
100
				
99
				if (id != null){
100
					makeSource(state, taxon, id.intValue(), NAMESPACE_SUPRAGENERIC_NAMES );
101
				} else{
102
					makeSource(state, taxon, null,NAMESPACE_SUPRAGENERIC_NAMES);
103
				}
101 104
				getTaxonService().saveOrUpdate(taxon);
102 105
			}
103 106

  
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiDescriptionExport.java
341 341
						addSourceSourceMapping, additionalSourceMapping, isImageGallery, element);
342 342
			}
343 343
		}
344
		descriptions = null;
344 345
		return success;
345 346
	}
346 347

  
......
834 835
	private PesiExportMapping getNotesMapping() {
835 836
		PesiExportMapping mapping = new PesiExportMapping(dbNoteTableName);
836 837
		
837
		mapping.addMapper(IdMapper.NewInstance("NoteId"));
838
		//mapping.addMapper(IdMapper.NewInstance("NoteId"));
838 839
		mapping.addMapper(DbTextDataMapper.NewInstance(Language.ENGLISH(), "Note_1"));
839 840
		//TODO
840 841
		mapping.addMapper(MethodMapper.NewInstance("Note_2", this, DescriptionElementBase.class));
......
871 872
	private PesiExportMapping getOccurrenceMapping() {
872 873
		PesiExportMapping mapping = new PesiExportMapping(dbOccurrenceTableName);
873 874
		
874
		mapping.addMapper(IdMapper.NewInstance("OccurrenceId"));
875
		//mapping.addMapper(IdMapper.NewInstance("OccurrenceId"));
875 876
		mapping.addMapper(DbDescriptionElementTaxonMapper.NewInstance("taxonFk"));
876 877
		mapping.addMapper(DbDescriptionElementTaxonMapper.NewInstance("TaxonFullNameCache", true, true, null)); 
877 878
		
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiSourceExport.java
422 422
		PesiExportMapping mapping = new PesiExportMapping(dbTableName);
423 423
		ExtensionType extensionType = null;
424 424
		
425
		mapping.addMapper(IdMapper.NewInstance("SourceId"));
425
	//	mapping.addMapper(IdMapper.NewInstance("SourceId"));
426 426
		
427 427
		// IMIS_Id
428 428
		extensionType = (ExtensionType)getTermService().find(ErmsTransformer.IMIS_UUID);
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiTaxonExport.java
777 777
			// Increment pageNumber
778 778
			pageNumber++;
779 779
		}
780
		
780
		taxonList = null;
781 781
		while ((taxonList  = getTaxonService().listTaxaByName(Taxon.class, "*", "*", "*", "*", Rank.SUBSPECIES(), pageSize, pageNumber)).size() > 0) {
782 782
			HashMap<Integer, TaxonNameBase<?,?>> inferredSynonymsDataToBeSaved = new HashMap<Integer, TaxonNameBase<?,?>>();
783 783

  
......
866 866
						// Classification could not be determined directly from this TaxonNode
867 867
						// The stored classification from another TaxonNode is used. It's a simple, but not a failsafe fallback solution.
868 868
						if (taxonNodes.size() == 0) {
869
							logger.error("Classification could not be determined directly from this Taxon: " + acceptedTaxon.getUuid() + " is misapplication? "+acceptedTaxon.isMisapplication()+ "). The classification of the last taxon is used");
869
							//logger.error("Classification could not be determined directly from this Taxon: " + acceptedTaxon.getUuid() + " is misapplication? "+acceptedTaxon.isMisapplication()+ "). The classification of the last taxon is used");
870 870
						
871 871
						}
872 872
					}
......
940 940
				logger.error("This TaxonBase is not a Taxon even though it should be: " + taxonBase.getUuid() + " (" + taxonBase.getTitleCache() + ")");
941 941
			}
942 942
		}
943
		taxonList = null;
943 944
		return inferredSynonymsDataToBeSaved;
944 945
	}
945 946
	
......
2524 2525
	private PesiExportMapping getMapping() {
2525 2526
		PesiExportMapping mapping = new PesiExportMapping(dbTableName);
2526 2527
		
2527
		mapping.addMapper(IdMapper.NewInstance("TaxonId"));
2528
		//mapping.addMapper(IdMapper.NewInstance("TaxonId"));
2528 2529
		mapping.addMapper(DbObjectMapper.NewInstance("sec", "sourceFk")); //OLD:mapping.addMapper(MethodMapper.NewInstance("SourceFK", this.getClass(), "getSourceFk", standardMethodParameter, PesiExportState.class));
2529 2530
		mapping.addMapper(MethodMapper.NewInstance("TaxonStatusFk", this.getClass(), "getTaxonStatusFk", standardMethodParameter, PesiExportState.class));
2530 2531
		mapping.addMapper(MethodMapper.NewInstance("TaxonStatusCache", this.getClass(), "getTaxonStatusCache", standardMethodParameter, PesiExportState.class));

Also available in: Unified diff