Project

General

Profile

« Previous | Next » 

Revision 6921aa7e

Added by Andreas Müller over 15 years ago

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelTaxonRelationIO.java
181 181
						}
182 182
					}else if (relQualifierFk == TAX_REL_IS_MISAPPLIED_NAME_OF){
183 183
						((Taxon)taxon2).addMisappliedName((Taxon)taxon1, citation, microcitation);
184
//					}else if (relQualifierFk == TAX_REL_){
185
//						((Taxon)taxon2).addMisappliedName((Taxon)taxon1, citation, microcitation);
184 186
					}else {
185 187
						//TODO
186 188
						logger.warn("TaxonRelationShipType " + relQualifierFk + " not yet implemented");
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcs/TcsReferenceIO.java
3 3
 */
4 4
package eu.etaxonomy.cdm.io.tcs;
5 5

  
6
import java.util.Calendar;
7
import java.util.List;
6 8
import java.util.Map;
7 9

  
8 10
import org.apache.log4j.Logger;
11
import org.jdom.Attribute;
9 12
import org.jdom.Element;
13
import org.jdom.Namespace;
10 14

  
11 15
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
16
import eu.etaxonomy.cdm.api.service.INameService;
17
import eu.etaxonomy.cdm.api.service.IReferenceService;
18
import eu.etaxonomy.cdm.common.XmlHelp;
12 19
import eu.etaxonomy.cdm.io.common.CdmIoBase;
13 20
import eu.etaxonomy.cdm.io.common.ICdmIO;
14 21
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
22
import eu.etaxonomy.cdm.io.common.ImportHelper;
15 23
import eu.etaxonomy.cdm.io.common.MapWrapper;
24
import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
25
import eu.etaxonomy.cdm.model.agent.Team;
16 26
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
17 27
import eu.etaxonomy.cdm.model.common.CdmBase;
28
import eu.etaxonomy.cdm.model.common.TimePeriod;
29
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
30
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
31
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
32
import eu.etaxonomy.cdm.model.name.NonViralName;
33
import eu.etaxonomy.cdm.model.name.Rank;
34
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
35
import eu.etaxonomy.cdm.model.reference.Generic;
18 36
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
37
import eu.etaxonomy.cdm.model.reference.StrictReferenceBase;
38
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
19 39

  
20 40
/**
21 41
 * @author a.mueller
......
129 149
		
130 150
		TcsImportConfigurator tcsConfig = (TcsImportConfigurator)config;
131 151
		Element source = tcsConfig.getSourceRoot();
152
		Element root = tcsConfig.getSourceRoot();
153
		logger.info("start makeReferences ...");
132 154
		
133
		String dbAttrName;
155
		String tcsElementName;
156
		Namespace tcsNamespace;
134 157
		String cdmAttrName;
158
		String value;
135 159
		boolean success = true;
160
		IReferenceService referenceService = cdmApp.getReferenceService();
161
		
162
		
136 163
		MapWrapper<ReferenceBase> referenceStore= new MapWrapper<ReferenceBase>(null);
137 164
		//Map<Integer, ReferenceBase> referenceCollectionMap = new HashMap<Integer, ReferenceBase>();
138 165
		
166
		Namespace rdfNamespace = root.getNamespace();
167
		String prefix = "tn";
168
		Namespace taxonNameNamespace = root.getNamespace(prefix);
169
		prefix = "tc";
170
		Namespace taxonConceptNamespace = root.getNamespace(prefix);
171
		prefix = "tcom";
172
		Namespace commonNamespace = root.getNamespace(prefix);
173
		prefix = "tpub";
174
		Namespace publicationNamespace = root.getNamespace(prefix);
175

  
139 176
		
140
//		logger.info("start makeReferences ...");
141
//		IReferenceService referenceService = cdmApp.getReferenceService();
142
//		try {
143
//			
144
//			
145
//			
146
//			//get data from database
147
//			String strQueryBase = 
148
//					" SELECT Reference.* , InReference.RefId as InRefId, InReference.RefCategoryFk as InRefCategoryFk,  " +
149
//						" InInReference.RefId as InInRefId, InInReference.RefCategoryFk as InInRefCategoryFk, " +
150
//						" InReference.InRefFk AS InRefInRefFk, InInReference.InRefFk AS InInRefInRefFk " +
151
//                    " FROM Reference AS InInReference " +
152
//                    	" RIGHT OUTER JOIN Reference AS InReference ON InInReference.RefId = InReference.InRefFk " + 
153
//                    	" RIGHT OUTER JOIN Reference ON InReference.RefId = dbo.Reference.InRefFk " + 
154
//					" WHERE (1=1) "; 
155
//			//strQueryBase += " AND Reference.refId = 7000000 " ;
156
//			String strQueryNoInRef = strQueryBase + 
157
//				" AND (Reference.InRefFk is NULL) ";
158
//			
159
//			String strQuery1InRef = strQueryBase + 
160
//				" AND (Reference.InRefFk is NOT NULL) AND (InReference.InRefFk is NULL) ";
161
//
162
//			String strQuery2InRef = strQueryBase + 
163
//				" AND (Reference.InRefFk is NOT NULL) AND (InReference.InRefFk is NOT NULL) AND (InInReference.InRefFk is NULL) ";
164
//
165
//			String strQueryTesMaxRecursion = strQueryBase + 
166
//				" AND (Reference.InRefFk is NOT NULL) AND (InReference.InRefFk is NOT NULL) AND (InInReference.InRefFk is NOT NULL) ";
167
//
168
//			ResultSet testMaxRecursionResultSet = source.getResultSet(strQueryTesMaxRecursion);
169
//			if (testMaxRecursionResultSet.next() == true){
170
//				logger.error("Maximum allowed InReference recursions exceeded in Berlin Model. Maximum recursion level is 2.");
171
//				return false;
172
//			}
173
//
174
//			if (bmiConfig.getDoReferences() == CONCEPT_REFERENCES){
175
//				strQueryNoInRef += " AND ( Reference.refId IN ( SELECT ptRefFk FROM PTaxon) ) ";
176
//			}
177
//			
178
//			List<ResultSet> resultSetList = new ArrayList<ResultSet>();
179
//			resultSetList.add(source.getResultSet(strQueryNoInRef));
180
//			if (bmiConfig.getDoReferences() == ALL || bmiConfig.getDoReferences() == NOMENCLATURAL){
181
//				resultSetList.add(source.getResultSet(strQuery1InRef));
182
//				resultSetList.add(source.getResultSet(strQuery2InRef));
183
//			}
184
//			
185
//			
186
//			int i = 0;
187
//			//for each reference
188
//			Iterator<ResultSet> resultSetListIterator =  resultSetList.listIterator();
189
//			while (resultSetListIterator.hasNext()){
190
//				i = 0;
191
//				ResultSet rs = resultSetListIterator.next();
192
//				while (rs.next()){
193
//					
194
//					if ((i++ % modCount) == 0){ logger.info("References handled: " + (i-1));}
195
//					
196
//					//create TaxonName element
197
//					int refId = rs.getInt("refId");
198
//					int categoryFk = rs.getInt("refCategoryFk");
199
//					Object inRefFk = rs.getObject("inRefFk");
200
//					int inRefCategoryFk = rs.getInt("InRefCategoryFk");
201
//					
202
//					StrictReferenceBase referenceBase;
203
//					try {
204
//						logger.debug("RefCategoryFk: " + categoryFk);
205
//						
206
//						if (categoryFk == REF_JOURNAL){
207
//							referenceBase = new Journal();
208
//						}else if(categoryFk == REF_BOOK){
209
//							referenceBase = new Book();
210
//						}else if(categoryFk == REF_ARTICLE){
211
//							referenceBase = new Article();
212
//							if (inRefFk != null){
213
//								if (inRefCategoryFk == REF_JOURNAL){
214
//									int inRefFkInt = (Integer)inRefFk;
215
//									if (referenceStore.containsId(inRefFkInt)){
216
//										ReferenceBase inJournal = referenceStore.get(inRefFkInt);
217
//										if (Journal.class.isAssignableFrom(inJournal.getClass())){
218
//											((Article)referenceBase).setInJournal((Journal)inJournal);
219
//										}else{
220
//											logger.warn("InJournal is not of type journal but of type " + inJournal.getClass().getSimpleName() +
221
//												" Inreference relation could not be set");
222
//										}
223
//									}else{
224
//										logger.error("Journal for Article (refID = " + refId +") could not be found. Inconsistency error. ");
225
//										return false;
226
//									}
227
//								}else{
228
//									logger.warn("Wrong inrefCategory for Article (refID = " + refId +"). Type must be 'Journal' but was not (RefCategoryFk=" + inRefCategoryFk + "))." +
229
//										" InReference was not added to Article! ");
230
//								}
231
//							}
232
//						}else if(categoryFk == REF_DATABASE){
233
//							referenceBase = new Database();
234
//						}else if(categoryFk == REF_PART_OF_OTHER_TITLE){
235
//							if (inRefCategoryFk == REF_BOOK){
236
//								referenceBase = new BookSection();
237
//								if (inRefFk != null){
238
//									int inRefFkInt = (Integer)inRefFk;
239
//									if (referenceStore.containsId(inRefFkInt)){
240
//										ReferenceBase inBook = referenceStore.get(inRefFkInt);
241
//										if (Book.class.isAssignableFrom(inBook.getClass())){
242
//											((BookSection)referenceBase).setInBook((Book)inBook);
243
//										}else{
244
//											logger.warn("InBook is not of type book but of type " + inBook.getClass().getSimpleName() +
245
//													" Inreference relation could not be set");
246
//										}
247
//									}else{
248
//										logger.error("Book (refId = " + inRefFkInt + " for part_of_other_title (refID = " + refId +") could not be found in Hashmap. Inconsistency error. ");
249
//										return false;
250
//									}
251
//								}
252
//							}else if (inRefCategoryFk == REF_ARTICLE){
253
//								//TODO 
254
//								logger.warn("Reference (refId = " + refId + ") of type 'part_of_other_title' is part of 'article'." +
255
//										" This type is not implemented yet. Generic reference created instead") ;
256
//								referenceBase = new Generic();
257
//							}else if (inRefCategoryFk == REF_JOURNAL){
258
//								//TODO 
259
//								logger.warn("Reference (refId = " + refId + ") of type 'part_of_other_title' has inReference of type 'journal'." +
260
//										" This is not allowed! Generic reference created instead") ;
261
//								referenceBase = new Generic();
262
//								referenceBase.addMarker(Marker.NewInstance(MarkerType.TO_BE_CHECKED(), true));
263
//							}else{
264
//								logger.warn("InReference type (catFk = " + inRefCategoryFk + ") of part-of-reference not recognized for refId " + refId + "." +
265
//									" Create 'Generic' reference instead");
266
//								referenceBase = new Generic();
267
//							}
268
//						}else if(categoryFk == REF_INFORMAL){
269
//							if (logger.isDebugEnabled()){logger.debug("RefType 'Informal'");}
270
//							referenceBase = new Generic();
271
//						}else if(categoryFk == REF_WEBSITE){
272
//							if (logger.isDebugEnabled()){logger.debug("RefType 'Website'");}
273
//							referenceBase = new Generic();
274
//						}else if(categoryFk == REF_UNKNOWN){
275
//							if (logger.isDebugEnabled()){logger.debug("RefType 'Unknown'");}
276
//							referenceBase = new Generic();
277
//						}else{
278
//							logger.warn("Unknown categoryFk (" + categoryFk + "). Create 'Generic instead'");
279
//							referenceBase = new Generic();	
280
//						}
281
//						
282
//						dbAttrName = "refCache";
283
//						cdmAttrName = "titleCache";
284
//						//TODO wohin kommt der refCache
285
//						//INomenclaturalReference hat nur getNomenclaturalCitation , m?sste es nicht so was wie setAbbrevTitle geben? 
286
//						success &= ImportHelper.addStringValue(rs, referenceBase, dbAttrName, cdmAttrName);
287
//						
288
//						dbAttrName = "nomRefCache";
289
//						cdmAttrName = "titleCache";
290
//						success &= ImportHelper.addStringValue(rs, referenceBase, dbAttrName, cdmAttrName, ImportHelper.NO_OVERWRITE);
291
//						
292
//						//refId
293
//						ImportHelper.setOriginalSource(referenceBase, bmiConfig.getSourceReference(), refId);
294
//						
295
//						//	dbAttrName = "BinomHybFlag";
296
//						//	cdmAttrName = "isBinomHybrid";
297
//						//	ImportHelper.addBooleanValue(rs, ref, dbAttrName, cdmAttrName);
298
//						
299
//						//TODO
300
//						// all attributes
301
//						
302
//						if (! referenceStore.containsId(refId)){
303
//							referenceStore.put(refId, referenceBase);
304
//							referenceMap.put(refId, referenceBase);
305
//						}else{
306
//							logger.warn("Duplicate refId in Berlin Model database. Second reference was not imported !!");
307
//						}
308
//					} catch (Exception e) {
309
//						logger.warn("Reference with id " + refId +  " threw Exception and could not be saved");
310
//						e.printStackTrace();
311
//						success = false;
312
//						return success;
313
//					}
314
//					
315
//				} // end resultSet
316
//				//save and store in map
317
//				referenceService.saveReferenceAll(referenceStore.objects());
318
//			}//end resultSetList	
319
//
320
//			logger.info("end makeReferences ...");
321
//			return success;
322
//		} catch (SQLException e) {
323
//			logger.error("SQLException:" +  e);
324
//			return false;
325
//		}
326
		return false;
177
		
178
		tcsElementName = "PublicationCitation";
179
		tcsNamespace = publicationNamespace;
180
		List<Element> elPublicationCitations = root.getChildren(tcsElementName, tcsNamespace);
181

  
182
		
183
		int i = 0;
184
		//for each taxonName
185
		for (Element elPublicationCitation : elPublicationCitations){
186
			
187
			if ((++i % modCount) == 0){ logger.info("Names handled: " + (i-1));}
188
			
189
			Attribute about = elPublicationCitation.getAttribute("about", rdfNamespace);
190

  
191
			//create TaxonName element
192
			String strAbout = elPublicationCitation.getAttributeValue("about", rdfNamespace);
193
			
194
			String pages = 
195
			tcsElementName = "publicationType";
196
			tcsNamespace = publicationNamespace;
197
			String strPubType = XmlHelp.getChildAttributeValue(elPublicationCitation, tcsElementName, tcsNamespace, "resource", rdfNamespace);
198
			
199
			try {
200
				ReferenceBase refBase = TcsTransformer.pubTypeStr2PubType(strPubType);
201
				
202
				//attributes
203
				tcsElementName = "publisher";
204
				tcsNamespace = publicationNamespace;
205
				cdmAttrName = "genusOrUninomial";
206
				success &= ImportHelper.addXmlStringValue(elPublicationCitation, refBase, tcsElementName, tcsNamespace, cdmAttrName);
207

  
208
				tcsElementName = "shortTitle";
209
				tcsNamespace = publicationNamespace;
210
				cdmAttrName = "title";
211
				success &= ImportHelper.addXmlStringValue(elPublicationCitation, refBase, tcsElementName, tcsNamespace, cdmAttrName);
212

  
213
				tcsElementName = "title";
214
				tcsNamespace = publicationNamespace;
215
				cdmAttrName = "title";
216
				success &= ImportHelper.addXmlStringValue(elPublicationCitation, refBase, tcsElementName, tcsNamespace, cdmAttrName);
217

  
218
				tcsElementName = "year";
219
				tcsNamespace = publicationNamespace;
220
				cdmAttrName = "year";
221
				success &= ImportHelper.addXmlStringValue(elPublicationCitation, refBase, tcsElementName, tcsNamespace, cdmAttrName);
222

  
223
				//TODO
224
				tcsElementName = "year";
225
				tcsNamespace = publicationNamespace;
226
				Integer year = null;
227
				try {
228
					value = (String)ImportHelper.getXmlInputValue(elPublicationCitation, tcsElementName, tcsNamespace);
229
					year = Integer.valueOf(value);
230
					Calendar cal = Calendar.getInstance();
231
					//FIXME
232
					cal.set(year, 1, 1);
233
					if (refBase instanceof StrictReferenceBase){
234
						StrictReferenceBase ref = (StrictReferenceBase)refBase;
235
						ref.setDatePublished(TimePeriod.NewInstance(cal));
236
					}else{
237
						logger.warn("year not implemented for ReferenceBase type " +  ((refBase == null) ? "(null)" : refBase.getClass().getSimpleName()));
238
					}
239
				} catch (RuntimeException e) {
240
					logger.warn("year could not be parsed");
241
				}
242
			
243

  
244
				
245
				
246
				tcsElementName = "pages";
247
				tcsNamespace = publicationNamespace;
248
				cdmAttrName = "pages";
249
				success &= ImportHelper.addXmlStringValue(elPublicationCitation, refBase, tcsElementName, tcsNamespace, cdmAttrName);
250

  
251
				tcsElementName = "volume";
252
				tcsNamespace = publicationNamespace;
253
				cdmAttrName = "volume";
254
				success &= ImportHelper.addXmlStringValue(elPublicationCitation, refBase, tcsElementName, tcsNamespace, cdmAttrName);
255
				
256
				
257
				//Reference
258
				//TODO
259
				tcsElementName = "parentPublication";
260
				tcsNamespace = publicationNamespace;
261
				String strParent = XmlHelp.getChildAttributeValue(elPublicationCitation, tcsElementName, tcsNamespace, "resource", rdfNamespace);
262
				ReferenceBase parent = referenceMap.get(strParent);
263
				if (parent != null){
264
					logger.warn("parent not yet implemented");
265
					//TODO refBase.setParent(parent);
266
				}
267
				
268
				//ImportHelper.setOriginalSource(nameBase, tcsConfig.getSourceReference(), nameId);
269
				referenceMap.put(strAbout, refBase);
270
				
271
			} catch (UnknownCdmTypeException e) {
272
				//FIXME
273
				logger.warn("Name with id " + strAbout + " has unknown type " + strPubType + " and could not be saved.");
274
				success = false; 
275
			}
276
		}
277
		logger.info(i + " names handled");
278
		referenceService.saveReferenceAll(referenceMap.objects());
279
		logger.info("end makeReferences ...");
280
		return success;
327 281
	}
328 282
	
329 283
	/* (non-Javadoc)
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcs/TcsTaxonNameIO.java
89 89
		//for each taxonName
90 90
		for (Element elTaxonName : elTaxonNames){
91 91
			
92
			if ((i++ % modCount) == 0){ logger.info("Names handled: " + (i-1));}
92
			if ((++i % modCount) == 0){ logger.info("Names handled: " + (i-1));}
93 93
			
94 94
			Attribute about = elTaxonName.getAttribute("about", rdfNamespace);
95 95

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcs/TcsTaxonNameRelationsIO.java
1 1
package eu.etaxonomy.cdm.io.tcs;
2 2

  
3 3
import java.util.HashSet;
4
import java.util.List;
4 5
import java.util.Map;
5 6
import java.util.Set;
6 7

  
7 8
import org.apache.log4j.Logger;
9
import org.jdom.Attribute;
8 10
import org.jdom.Element;
11
import org.jdom.Namespace;
9 12

  
10 13
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
11 14
import eu.etaxonomy.cdm.api.service.INameService;
......
43 46
		MapWrapper<TaxonNameBase> taxonNameMap = (MapWrapper<TaxonNameBase>)stores.get(ICdmIO.TAXONNAME_STORE);
44 47
		MapWrapper<ReferenceBase> referenceMap = (MapWrapper<ReferenceBase>)stores.get(ICdmIO.REFERENCE_STORE);
45 48
		
49
		String tcsElementName;
50
		Namespace tcsNamespace;
51
		String cdmAttrName;
52
		String value;
53

  
46 54
		Set<TaxonNameBase> nameStore = new HashSet<TaxonNameBase>();
47 55
		TcsImportConfigurator tcsConfig = (TcsImportConfigurator)config;
48 56
		Element source = tcsConfig.getSourceRoot();
49
		String dbAttrName;
50
		String cdmAttrName;
51 57
		
52 58
		logger.info("start makeNameRelationships ...");
53
		logger.warn("start makeNameRelationships not yet implemented !!!");
54 59
		INameService nameService = cdmApp.getNameService();
55 60

  
56
//		try {
57
//			//get data from database
58
//			String strQuery = 
59
//					" SELECT RelName.*, FromName.nameId as name1Id, ToName.nameId as name2Id, RefDetail.Details " + 
60
//					" FROM Name as FromName INNER JOIN " +
61
//                      	" RelName ON FromName.NameId = RelName.NameFk1 INNER JOIN " +
62
//                      	" Name AS ToName ON RelName.NameFk2 = ToName.NameId LEFT OUTER JOIN "+
63
//                      	" RefDetail ON RelName.RefDetailFK = RefDetail.RefDetailId " + 
64
//                    " WHERE (1=1)";
65
//			ResultSet rs = source.getResultSet(strQuery) ;
66
//			
67
//			int i = 0;
68
//			//for each reference
69
//			while (rs.next()){
70
//				
71
//				if ((i++ % modCount) == 0){ logger.info("RelName handled: " + (i-1));}
72
//				
73
//				int relNameId = rs.getInt("RelNameId");
74
//				int name1Id = rs.getInt("name1Id");
75
//				int name2Id = rs.getInt("name2Id");
76
//				int relRefFk = rs.getInt("refFk");
77
//				String details = rs.getString("details");
78
//				int relQualifierFk = rs.getInt("relNameQualifierFk");
79
//				
80
//				TaxonNameBase nameFrom = nameMap.get(name1Id);
81
//				TaxonNameBase nameTo = nameMap.get(name2Id);
82
//				
83
//				ReferenceBase citation = referenceMap.get(relRefFk);
84
//				//TODO (preliminaryFlag = true testen
85
//				String microcitation = details;
86
//
87
//				if (nameFrom != null && nameTo != null){
88
//					if (relQualifierFk == NAME_REL_IS_BASIONYM_FOR){
89
//						//TODO references, mikroref, etc
90
//						nameTo.setBasionym(nameFrom);
91
//					}else if (relQualifierFk == NAME_REL_IS_LATER_HOMONYM_OF){
92
//						String rule = null;  //TODO
93
//						nameFrom.addRelationshipToName(nameTo, NameRelationshipType.LATER_HOMONYM(), rule) ;
94
//						//TODO reference
95
//					}else if (relQualifierFk == NAME_REL_IS_REPLACED_SYNONYM_FOR){
96
//						String rule = null;  //TODO
97
//						nameFrom.addRelationshipToName(nameTo, NameRelationshipType.REPLACED_SYNONYM(), rule) ;
98
//						//TODO reference
99
//					}else if (relQualifierFk == NAME_REL_IS_TYPE_OF || relQualifierFk == NAME_REL_IS_REJECTED_TYPE_OF ||  relQualifierFk == NAME_REL_IS_CONSERVED_TYPE_OF ){
100
//						//TODO
101
//						String originalNameString = null;
102
//						boolean isRejectedType = (relQualifierFk == NAME_REL_IS_REJECTED_TYPE_OF);
103
//						boolean isConservedType = (relQualifierFk == NAME_REL_IS_CONSERVED_TYPE_OF);
104
//						//TODO nameTo.addNameTypeDesignation(nameFrom, citation, microcitation, originalNameString, isRejectedType, isConservedType);
105
//					}else if (relQualifierFk == NAME_REL_IS_ORTHOGRAPHIC_VARIANT_OF){
106
//						String rule = null;  //TODO
107
//						nameFrom.addRelationshipToName(nameTo, NameRelationshipType.ORTHOGRAPHIC_VARIANT(), rule) ;
108
//						//TODO reference
109
//					}else {
110
//						//TODO
111
//						logger.warn("NameRelationShipType " + relQualifierFk + " not yet implemented");
112
//					}
113
//					nameStore.add(nameFrom);
114
//					
115
//					//TODO
116
//					//ID
117
//					//etc.
118
//				}else{
119
//					//TODO
120
//					if (nameFrom == null){
121
//						 logger.warn("from TaxonName for RelName (" + relNameId + ") does not exist in store");
122
//					}
123
//					if (nameTo == null){
124
//						logger.warn("to TaxonNames for RelName (" + relNameId + ") does not exist in store");
125
//					}
126
//				}
127
//			}
128
//			logger.info("TaxonName to save: " + nameStore.size());
129
//			nameService.saveTaxonNameAll(nameStore);
130
//			
131
//			logger.info("end makeRelName ...");
132
//			return true;
133
//		} catch (SQLException e) {
134
//			logger.error("SQLException:" +  e);
135
//			return false;
136
//		}
137
		return true;
61
//		<tn:hasBasionym rdf:resource="palm_tn_14530"/>
62
		
63
		Element root = tcsConfig.getSourceRoot();
64
		boolean success =true;
65
		
66
		Namespace rdfNamespace = root.getNamespace();
67
		String prefix = "tn";
68
		Namespace taxonNameNamespace = root.getNamespace(prefix);
69
		prefix = "tc";
70
		Namespace taxonConceptNamespace = root.getNamespace(prefix);
71
		prefix = "tcom";
72
		Namespace commonNamespace = root.getNamespace(prefix);
73
		//String strTnNamespace = "http://rs.tdwg.org/ontology/voc/TaxonName#";
74
		//Namespace taxonNameNamespace = Namespace.getNamespace("tn", strTnNamespace);
75
		
76
		List<Element> elTaxonNames = root.getChildren("TaxonName", taxonNameNamespace);
77

  
78
		
79
		int i = 0;
80
		int nameRelCount = 0;
81
		//for each taxonName
82
		for (Element elTaxonName : elTaxonNames){
83
			
84
			TaxonNameBase fromName = null;
85
			if ((++i % modCount) == 0){ logger.info("Names handled: " + (i-1));}
86
			
87
			//Basionyms
88
			tcsElementName = "hasBasionym";
89
			tcsNamespace = taxonNameNamespace;
90
			List<Element> elBasionymList = elTaxonName.getChildren(tcsElementName, tcsNamespace);
91
			
92
			for (Element elBasionym: elBasionymList){
93
				nameRelCount++;
94
				logger.info("BASIONYM "+  nameRelCount);
95
				tcsElementName = "resource";
96
				tcsNamespace = rdfNamespace;
97
				Attribute attrResource = elBasionym.getAttribute(tcsElementName, tcsNamespace);
98
				if (attrResource == null){
99
					logger.warn("Basionym rdf:resource is missing ! Basionym not set!");
100
					continue;
101
				}
102
				String basionymId = attrResource.getValue();
103
				TaxonNameBase basionym = taxonNameMap.get(basionymId);
104
				if (basionym == null){
105
					logger.warn("Basionym name ("+basionymId+") not found in Map! Basionym not set!");
106
					continue;
107
				}
108
				if (fromName == null){
109
					Attribute about = elTaxonName.getAttribute("about", rdfNamespace);
110
					if (about != null){
111
						fromName = taxonNameMap.get(about.getValue() );
112
					}
113
					if (fromName == null){
114
						logger.warn("From name ("+about+") not found in Map! Basionym not set!");
115
						continue;
116
					}
117
				}
118
				String ruleConcidered = null; //TODO
119
				fromName.addBasionym(basionym, ruleConcidered);
120
				nameStore.add(fromName);
121

  
122
			}
123
		}// end Basionyms
124
		
125
		//Other Relations
126
		//TODO
127
		
128
		logger.info(nameRelCount + " nameRelations handled");
129
		nameService.saveTaxonNameAll(nameStore);
130
		logger.info("end makeNameRelationships ...");
131
		return success;
138 132
	}
139 133
	
140 134
	/* (non-Javadoc)
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcs/TcsTaxonRelationsIO.java
21 21
import eu.etaxonomy.cdm.io.common.MapWrapper;
22 22
import eu.etaxonomy.cdm.model.common.CdmBase;
23 23
import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
24
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
24 25
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
25 26
import eu.etaxonomy.cdm.model.taxon.Synonym;
26 27
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
......
145 146
										logger.warn("TaxonBase fromTaxon is not of Type 'Synonym'. Relationship is not added.");
146 147
									}else{
147 148
										Synonym synonym = (Synonym)fromTaxon;
149
										TaxonNameBase synName = synonym.getName();
150
										TaxonNameBase accName = taxonTo.getName();
151
										if (synName != null && accName != null && synName.isHomotypic(accName)
152
													&& ( synRelType.equals(SynonymRelationshipType.SYNONYM_OF()))){
153
											synRelType = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF(); 
154
										}
148 155
										taxonTo.addSynonym(synonym, synRelType,  citation, microReference);
149 156
									}
150 157
								}else if (relType instanceof TaxonRelationshipType){
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcs/TcsTransformer.java
9 9
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
10 10
import eu.etaxonomy.cdm.model.name.Rank;
11 11
import eu.etaxonomy.cdm.model.name.TypeDesignationStatus;
12
import eu.etaxonomy.cdm.model.reference.Book;
13
import eu.etaxonomy.cdm.model.reference.Journal;
14
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
15
import eu.etaxonomy.cdm.model.reference.WebPage;
12 16
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
13 17
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
14 18
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
......
105 109
		return false;
106 110
	}
107 111
	
112
	/** Creates an cdm-Rank by the tcs rank
113
	 */
114
	public static ReferenceBase pubTypeStr2PubType (String strPubType) throws UnknownCdmTypeException{
115
		String tcsRoot = "http://rs.tdwg.org/ontology/voc/PublicationCitation#";
116
		String tcsBook = tcsRoot + "Book";
117
		String tcsJournal = tcsRoot + "Journal";
118
		String tcsWebPage = tcsRoot + "WebPage";
119
		String tcsCommunication = tcsRoot + "Communication";
120
		String tcsBookSeries = tcsRoot + "BookSeries";
121
		
122
		
123
		if (strPubType == null){return null;
124
		}else if (tcsBook.equals(strPubType)){return Book.NewInstance();
125
		}else if (tcsJournal.equals(strPubType)){return Journal.NewInstance();
126
		}else if (tcsWebPage.equals(strPubType)){return WebPage.NewInstance();
127
		}	
128
		else {
129
			throw new UnknownCdmTypeException("Unknown publication type " + strPubType);
130
		}
131
	}
132
	
108 133
	/** Creates an cdm-RelationshipTermBase by the tcsRelationshipCategory
109 134
	 */
110 135
	public static RelationshipTermBase tcsRelationshipCategory2Relationship (String tcsRelationshipCategory) throws UnknownCdmTypeException{

Also available in: Unified diff