Project

General

Profile

« Previous | Next » 

Revision 531fc7bc

Added by Andreas Müller almost 8 years ago

Remove generics from Reference in cdmlib (except for cdmlib-model) #5830

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcsrdf/TcsRdfTaxonNameImport.java
20 20

  
21 21
import com.hp.hpl.jena.rdf.model.Model;
22 22
import com.hp.hpl.jena.rdf.model.ModelFactory;
23
import com.hp.hpl.jena.rdf.model.Property;
23 24
import com.hp.hpl.jena.rdf.model.RDFNode;
24 25
import com.hp.hpl.jena.rdf.model.ResIterator;
25 26
import com.hp.hpl.jena.rdf.model.Resource;
26 27
import com.hp.hpl.jena.rdf.model.Statement;
27 28
import com.hp.hpl.jena.rdf.model.StmtIterator;
28
import com.hp.hpl.jena.rdf.model.Property;
29

  
30

  
31

  
32 29

  
33 30
import eu.etaxonomy.cdm.common.XmlHelp;
34 31
import eu.etaxonomy.cdm.io.common.ICdmIO;
......
125 122
		Resource elTaxonName = root.getResource(taxonNameNamespace);
126 123

  
127 124
		int i = 0;
128
		
125

  
129 126
		TaxonNameBase name;
130 127
		Property property = root.getProperty(taxonNameNamespace+"authorship");
131
		
128

  
132 129
		ResIterator iterator = root.listSubjectsWithProperty(property, (RDFNode) null);
133 130
		String id ;
134 131
		while (iterator.hasNext()){
135
			
132

  
136 133
			Resource resource = iterator.next();
137
			
134

  
138 135
			name = handleNameResource(resource, config);
139 136
			id = resource.getNameSpace();
140 137
			taxonNameMap.put(id, name);
141 138
		}
142
		
139

  
143 140
		logger.info(i + " names handled");
144 141
		getNameService().save(taxonNameMap.objects());
145 142
//		makeNameSpecificData(nameMap);
......
154 151
    protected boolean isIgnore(TcsRdfImportState state){
155 152
		return ! state.getConfig().isDoTaxonNames();
156 153
	}
157
	
154

  
158 155
	protected TaxonNameBase handleNameModel(Model model, TcsRdfImportConfigurator config, MapWrapper<TaxonNameBase> taxonNameMap, String uri){
159 156
		Resource nameAbout = model.getResource(uri);
160 157
		TaxonNameBase result = handleNameResource(nameAbout, config);
161 158
		taxonNameMap.put(uri, result);
162 159
		return result;
163
		
160

  
164 161
	}
165
	
162

  
166 163
	private TaxonNameBase handleNameResource(Resource nameAbout, TcsRdfImportConfigurator config){
167 164
		String idNamespace = "TaxonName";
168
				
165

  
169 166
		StmtIterator stmts = nameAbout.listProperties();
170 167
		while(stmts.hasNext()){
171 168
			System.out.println(stmts.next().getPredicate().toString());
172 169
		}
173
		
170

  
174 171
		Property prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"nomenclaturalCode");
175 172
		Statement stateNomenclaturalCode = nameAbout.getProperty(prop);
176 173
		String strNomenclaturalCode = stateNomenclaturalCode.getObject().toString();
177 174
		//Rank
178 175
		prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"rankString");
179 176
		String strRank = nameAbout.getProperty(prop).getString();
180
		
181
		
182
		
177

  
178

  
179

  
183 180
		try {
184
			
181

  
185 182
			Rank rank = TcsRdfTransformer.rankString2Rank(strRank);
186 183
			NomenclaturalCode nomCode;
187 184
			if (strNomenclaturalCode != null){
......
189 186
			}else{
190 187
				nomCode = NomenclaturalCode.ICNAFP;
191 188
			}
192
				
189

  
193 190
			TaxonNameBase<?,?> nameBase = nomCode.getNewTaxonNameInstance(rank);
194 191

  
195 192
			Set<String> omitAttributes = null;
196 193
			//makeStandardMapper(nameAbout, nameBase, omitAttributes, standardMappers);
197
			
194

  
198 195
			prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"nameComplete");
199 196
			String strNameComplete = nameAbout.getProperty(prop).getString();
200 197
			nameBase.setTitleCache(strNameComplete, true);
201
			
198

  
202 199
			prop =  nameAbout.getModel().getProperty(config.getCommonNamespaceURIString()+"publishedIn");
203 200
			String strPublishedIn = nameAbout.getProperty(prop).getString();
204 201
			if (strPublishedIn != null && strPublishedIn != ""){
......
221 218
				}catch(NullPointerException e){
222 219
				}
223 220
				if (config.isPublishReferences()){
224
					((Reference<?>)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
221
					((Reference)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
225 222
				}
226 223
			}
227
			
224

  
228 225
			if (nameBase instanceof NonViralName){
229 226
				NonViralName<?> nonViralName = (NonViralName<?>)nameBase;
230 227
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"genusPart");
......
235 232
					prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"uninomial");
236 233
					strGenusPart = nameAbout.getProperty(prop).getString();
237 234
				}
238
				
235

  
239 236
				nonViralName.setGenusOrUninomial(strGenusPart);
240
				
237

  
241 238
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"infragenericEpithet");
242 239
				try{
243 240
					String strInfragenericEpithet = nameAbout.getProperty(prop).getString();
244 241
					nonViralName.setInfraGenericEpithet(strInfragenericEpithet);
245 242
				}catch(NullPointerException e){
246
					
243

  
247 244
				}
248 245
				try {
249 246
					prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"specificEpithet");
250 247
					String strSpecificEpithet = nameAbout.getProperty(prop).getString();
251 248
					nonViralName.setSpecificEpithet(strSpecificEpithet);
252 249
				}catch(NullPointerException e){
253
					
250

  
254 251
				}
255 252
				try{
256 253
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"infraspecificEpithet");
257 254
				String strInfraspecificEpithet = nameAbout.getProperty(prop).getString();
258 255
				nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
259 256
				}catch(NullPointerException e){
260
					
257

  
261 258
				}
262 259
				//Authorships
263 260
				//TODO
......
268 265
							<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:2691-1"
269 266
								tm:index="1"
270 267
								tm:role="Combination Author"/>
271
							<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:8096-1" 
268
							<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:8096-1"
272 269
								tm:index="1"
273 270
								tm:role="Basionym Author"/>
274 271
						</tm:Team>
......
288 285
					try{
289 286
						stateAutorTeamTeam = stateAuthorTeam.getProperty(prop);
290 287
					}catch(Exception e){
291
						
288

  
292 289
					}
293 290
					try{
294 291
						prop =  stateAuthorTeam.getModel().getProperty(config.getTeamNamespaceURIString()+"name");
295 292
						stateAutorTeamName = stateAuthorTeam.getProperty(prop);
296 293
					}catch(Exception e){
297
						
294

  
298 295
					}
299 296
					try{
300 297
						prop =  nameAbout.getModel().getProperty(config.getTeamNamespaceURIString()+"hasMember");
......
312 309
						System.err.println(e.getMessage());
313 310
					}
314 311
				}
315
				
316
				
317
				
312

  
313

  
314

  
318 315
				nonViralName.setCombinationAuthorship(authorTeam);
319
				
316

  
320 317
				//Annotations:
321 318
				/*
322 319
				 * <tn:hasAnnotation>
......
324 321
                <tn:noteType rdf:resource="http://rs.tdwg.org/ontology/voc/TaxonName#replacementNameFor"/>
325 322
                <tn:objectTaxonName rdf:resource="urn:lsid:ipni.org:names:151538-1"/>
326 323
            </tn:NomenclaturalNote>
327
        </tn:hasAnnotation>   
324
        </tn:hasAnnotation>
328 325
				 */
329 326
				/*
330 327
				String strInfraspecificEpithet = nameAbout.getProperty(prop).getString();
......
368 365
			//ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace);
369 366

  
370 367
			//checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers);
371
			
368

  
372 369
			return nameBase;
373
				
370

  
374 371
			}catch(Exception e){
375 372
			e.printStackTrace();
376 373
			return null;
......
379 376
			//name
380 377
			String strNameComplete = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "nameComplete", rdfNamespace);
381 378
			nameBase.setTitleCache(strNameComplete, true);
382
			
379

  
383 380
			//Reference
384 381
			//TODO
385 382
			String tcsElementName = "publishedIn";
......
405 402
					}
406 403
				}
407 404
				if (config.isPublishReferences()){
408
					((Reference<?>)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
405
					((Reference)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
409 406
				}
410 407
			}
411 408

  
......
437 434
			if (nameBase instanceof NonViralName){
438 435
				NonViralName<?> nonViralName = (NonViralName<?>)nameBase;
439 436
				String strGenusPart =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace);
440
				
437

  
441 438
				//for names of rank genus the uninomial property should be used
442 439
				if (strGenusPart == null){
443 440
					strGenusPart =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "uninomial", rdfNamespace);
444 441
				}
445 442
				nonViralName.setGenusOrUninomial(strGenusPart);
446
				
443

  
447 444
				String strInfragenericEpithet =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace);
448 445
				nonViralName.setGenusOrUninomial(strInfragenericEpithet);
449
				
450
				
451
				
446

  
447

  
448

  
452 449
				String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace);
453 450
				nonViralName.setSpecificEpithet(strSpecificEpithet);
454
				
451

  
455 452
				String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace);
456 453
				nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
457 454
				//AuthorTeams
......
507 504
		}
508 505
		return null;*/
509 506
	}
510
	
507

  
511 508
	protected TaxonNameBase handleNameElement(Element elTaxonName, Namespace rdfNamespace, Namespace taxonNameNamespace, TcsRdfImportConfigurator config, MapWrapper<TaxonNameBase> taxonNameMap){
512 509
		String idNamespace = "TaxonName";
513 510
		Attribute about = elTaxonName.getAttribute("about", rdfNamespace);
514
		
511

  
515 512
		//create TaxonName element
516
		
517
	
513

  
514

  
518 515
		String nameAbout = elTaxonName.getAttributeValue("about", rdfNamespace);
519 516
		if (nameAbout == null){
520 517
			nameAbout = XmlHelp.getChildAttributeValue(elTaxonName, "TaxonName", taxonNameNamespace, "about", rdfNamespace);
521 518
		}
522
		
523
		
519

  
520

  
524 521
		String strRank = XmlHelp.getChildAttributeValue(elTaxonName, "rankString", taxonNameNamespace, "rankString", rdfNamespace);
525 522
		if (strRank == null){
526 523
			strRank = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "rankString", rdfNamespace);
527
			
524

  
528 525
		}
529
		
526

  
530 527
		if (strRank == null){
531 528
			strRank = XmlHelp.getChildAttributeValue(elTaxonName, "rank", taxonNameNamespace, "resource", rdfNamespace);
532
			
529

  
533 530
		}
534
		
531

  
535 532
		String strNomenclaturalCode = XmlHelp.getChildContentAttributeValue(elTaxonName, "TaxonName", taxonNameNamespace, "nomenclaturalCode", rdfNamespace);
536 533
		if (strNomenclaturalCode == null){
537 534
			strNomenclaturalCode = XmlHelp.getChildAttributeValue(elTaxonName, "nomenclaturalCode", taxonNameNamespace, "resource", rdfNamespace);
538
			
535

  
539 536
		}
540 537
		try {
541
			
538

  
542 539
			Rank rank = TcsRdfTransformer.rankString2Rank(strRank);
543 540
			NomenclaturalCode nomCode;
544 541
			if (strNomenclaturalCode != null){
......
546 543
			}else{
547 544
				nomCode = NomenclaturalCode.ICNAFP;
548 545
			}
549
				
546

  
550 547
			TaxonNameBase<?,?> nameBase = nomCode.getNewTaxonNameInstance(rank);
551 548

  
552 549
			Set<String> omitAttributes = null;
553 550
			//makeStandardMapper(elTaxonName, nameBase, omitAttributes, standardMappers);
554
			
551

  
555 552
			//name
556 553
			String strNameComplete = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "nameComplete", rdfNamespace);
557 554
			nameBase.setTitleCache(strNameComplete, true);
558
			
555

  
559 556
			//Reference
560 557
			//TODO
561 558
			String tcsElementName = "publishedIn";
......
581 578
					}
582 579
				}
583 580
				if (config.isPublishReferences()){
584
					((Reference<?>)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
581
					((Reference)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
585 582
				}
586 583
			}
587 584

  
......
613 610
			if (nameBase instanceof NonViralName){
614 611
				NonViralName<?> nonViralName = (NonViralName<?>)nameBase;
615 612
				String strGenusPart =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace);
616
				
613

  
617 614
				//for names of rank genus the uninomial property should be used
618 615
				if (strGenusPart == null){
619 616
					strGenusPart =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "uninomial", rdfNamespace);
620 617
				}
621 618
				nonViralName.setGenusOrUninomial(strGenusPart);
622
				
619

  
623 620
				String strInfragenericEpithet =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace);
624 621
				nonViralName.setGenusOrUninomial(strInfragenericEpithet);
625
				
626
				
627
				
622

  
623

  
624

  
628 625
				String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace);
629 626
				nonViralName.setSpecificEpithet(strSpecificEpithet);
630
				
627

  
631 628
				String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace);
632 629
				nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
633 630
				//AuthorTeams
......
688 685
	Model model = ModelFactory.createDefaultModel();
689 686
		try{
690 687
			model.read(is, null);
691
			
688

  
692 689
			config.makeNamespaces(model);
693
			
690

  
694 691
			String rdfNamespace = config.getRdfNamespaceURIString();
695 692
			String taxonNameNamespace = config.getTnNamespaceURIString();
696 693
			return handleNameModel(model, config, taxonNameMap, uri);
697
			
698
			
694

  
695

  
699 696
		}catch(Exception e){
700 697
			logger.debug("The file was no valid rdf file");
701 698
		}
702
		
703
		
704
		
699

  
700

  
701

  
705 702
		return null;
706 703
	}
707
	
704

  
708 705
}

Also available in: Unified diff