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-ext/src/main/java/eu/etaxonomy/cdm/ext/ipni/IpniService.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
55 55
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
56 56

  
57 57
/**
58
* @author a.mueller
59
* @created Aug 16, 2010
60
* @version 1.0
58
 * @author a.mueller
59
 * @created Aug 16, 2010
61 60
 *
62 61
 * TODO the whole ipni service should be refactored to use UriUtils. I did this for the queryService method only because we ran into timeout
63 62
 * problems in tests. UriUtils handles these problems already.
......
98 97
	private static final String TYPE_REMARKS = "Type remarks";
99 98

  
100 99
	private static final Logger logger = Logger.getLogger(IpniService.class);
101
	
100

  
102 101
	// GENERAL
103 102
	public static String ID = "Id";
104 103
	public static String VERSION = "Version";
105 104
	public static final String REMARKS = "Remarks";
106
	
107
	//NAMES 
105

  
106
	//NAMES
108 107
	public static final String FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS = "Full name without family and authors";
109 108
	public static final String AUTHORS = "Authors";
110 109
	public static final String FAMILY = "Family";
......
121 120
	public static final String BASIONYM = "Basionym";
122 121
	public static final String REPLACED_SYNONYM = "Replaced synonym";
123 122

  
124
	
123

  
125 124
	//AUTHORS
126
	
125

  
127 126
	public static final String STANDARD_FORM = "Standard Form";
128
	
127

  
129 128
	public static final String DEFAULT_AUTHOR_FORENAME = "Default author forename";
130 129
	public static final String DEFAULT_AUTHOR_SURNAME = "Default author surname";
131 130
	public static final String TAXON_GROUPS = "Taxon groups";
132 131
	public static final String DATES = "Dates";
133 132
	public static final String ALTERNATIVE_NAMES = "Alternative names";
134
	
133

  
135 134
	public static final String DEFAULT_AUTHOR_NAME = "Default author name";
136
	
135

  
137 136
	public static final String NAME_NOTES = "Name notes";
138 137
	public static final String NAME_SOURCE = "Name source";
139 138
	public static final String DATE_TYPE_CODE = "Date type code";
140 139
	public static final String DATE_TYPE_STRING = "Date type string";
141
	
140

  
142 141
	public static final String ALTERNATIVE_ABBREVIATIONS = "Alternative abbreviations";
143 142
	public static final String EXAMPLE_OF_NAME_PUBLISHED = "Example of name published";
144
	
145
	
143

  
144

  
146 145
	//PUBLICATIONS
147
	
146

  
148 147
	public static final String ABBREVIATION = "Abbreviation";
149 148
	public static final String TITLE = "Title";
150 149
	public static final String BPH_NUMBER = "BPH number";
......
161 160
	public static final String TL2_AUTHOR = "TL2 author";
162 161
	public static final String TL2_NUMBER = "TL2 number";
163 162
	public static final String TDWG_ABBREVIATION = "TDWG abbreviation";
164
	
163

  
165 164
	private enum ServiceType{
166 165
		 AUTHOR,
167 166
		 NAME,
168 167
		 PUBLICATION,
169 168
		 ID
170 169
	}
171
	
170

  
172 171
	public enum IpniRank{
173 172
		ALL ("All"),
174 173
		FAMILIAL ("Familial"),
......
177 176
		INFRA_GENERIC("Infrageneric"),
178 177
		SPECIFIC ("Specific"),
179 178
		INFRA_SPECIFIC("InfraSpecific");
180
		
179

  
181 180
		String strRank;
182 181
		IpniRank(String strRank){
183 182
			this.strRank = strRank;
184 183
		}
185
		
184

  
186 185
		public static IpniRank valueOf(Rank rank){
187 186
			if (rank == null){
188 187
				return ALL;
......
204 203
			}
205 204
		}
206 205
	}
207
		
208
	 
206

  
207

  
209 208
//	private URL serviceUrl;
210
	 
209

  
211 210
// ******************************** CONSTRUCTOR **************************************
212 211

  
213
// ****************************** METHODS ****************************************************/	
214
	
212
// ****************************** METHODS ****************************************************/
213

  
215 214

  
216 215
	/* (non-Javadoc)
217 216
	 * @see eu.etaxonomy.cdm.ext.ipni.IIpniService#getAuthors(java.lang.String, java.lang.String, java.lang.String, java.lang.String, eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration, eu.etaxonomy.cdm.ext.ipni.IpniServiceAuthorConfigurator)
218 217
	 */
219
	public List<Person> getAuthors(String abbreviation, String surname, String forename, String isoCountry, ICdmApplicationConfiguration services, IpniServiceAuthorConfigurator config){
218
	@Override
219
    public List<Person> getAuthors(String abbreviation, String surname, String forename, String isoCountry, ICdmApplicationConfiguration services, IpniServiceAuthorConfigurator config){
220 220
		//config
221 221
		if (config == null){
222 222
			config = new IpniServiceAuthorConfigurator();
223 223
		}
224
		
225
		
224

  
225

  
226 226
		abbreviation = normalizeParameter(abbreviation);
227 227
		surname = normalizeParameter(surname);
228 228
		isoCountry = normalizeParameter(isoCountry);
229 229
		forename = normalizeParameter(forename);
230
		
230

  
231 231
		DelimitedFormat format = config.getFormat();
232
			
233
		String request = "find_abbreviation=" + abbreviation + 
234
						"&find_surname=" + surname + 
235
						"&find_isoCountry=" + isoCountry + 
232

  
233
		String request = "find_abbreviation=" + abbreviation +
234
						"&find_surname=" + surname +
235
						"&find_isoCountry=" + isoCountry +
236 236
						"&find_forename=" + forename +
237 237
						"&output_format=" + format.parameter;
238
		
238

  
239 239
		return (List)queryService(request, services, getServiceUrl(IIpniService.AUTHOR_SERVICE_URL), config, ServiceType.AUTHOR);
240 240
	}
241
	       
241

  
242 242

  
243 243
	/**
244 244
	 *	FIXME rewrote this method to rely on {@link UriUtils}. The whole class should be adjusted to reflect this change.
......
252 252
			throw new NullPointerException("Ipni service configurator should not be null");
253 253
		}
254 254
		try {
255
			
255

  
256 256
            // create the request url
257 257
            URL newUrl = new URL(serviceUrl.getProtocol(),
258 258
                                                     serviceUrl.getHost(),
259 259
                                                     serviceUrl.getPort(),
260
                                                     serviceUrl.getPath() 
260
                                                     serviceUrl.getPath()
261 261
                                                     + "?" + request);
262
            
263
            
262

  
263

  
264 264
            URI newUri = newUrl.toURI();
265
                       
265

  
266 266
            logger.info("Firing request for URI: " + newUri);
267
                
267

  
268 268
            HttpResponse response = UriUtils.getResponse(newUri, null);
269
            
269

  
270 270
            int responseCode = response.getStatusLine().getStatusCode();
271
            
271

  
272 272
            // get the content at the resource
273 273
            InputStream content = response.getEntity().getContent();
274 274
            // build the result
......
283 283
            if(responseCode == HttpURLConnection.HTTP_OK){
284 284
                    return result;
285 285
            }else{
286
                //TODO error handling    
286
                //TODO error handling
287 287
            	logger.error("No Http_OK");
288 288
            }
289
               
289

  
290 290
        } catch (IOException e) {
291 291
            logger.error("No content for request: " + request);
292 292
        } catch (URISyntaxException e) {
293 293
			logger.error("Given URL could not be transformed into URI", e);
294 294
		}
295
       
295

  
296 296
        // error
297 297
        return null;
298 298
    }
299
	
299

  
300 300
	public InputStream queryServiceForID (String request, URL serviceUrl){
301
		
301

  
302 302
		try {
303
			
303

  
304 304
            // create the request url
305 305
            URL newUrl = new URL(serviceUrl.getProtocol(),
306 306
                                                     serviceUrl.getHost(),
307 307
                                                     serviceUrl.getPort(),
308
                                                     serviceUrl.getPath() 
308
                                                     serviceUrl.getPath()
309 309
                                                     + "?" + request);
310
            
311
            
310

  
311

  
312 312
            URI newUri = newUrl.toURI();
313
                       
313

  
314 314
            logger.info("Firing request for URI: " + newUri);
315
                
315

  
316 316
            HttpResponse response = UriUtils.getResponse(newUri, null);
317
            
317

  
318 318
            int responseCode = response.getStatusLine().getStatusCode();
319
            
319

  
320 320
            // get the content at the resource
321 321
            InputStream content = response.getEntity().getContent();
322 322
            return content;
323
           
323

  
324 324
		   } catch (IOException e) {
325 325
	            logger.error("No content for request: " + request);
326 326
	        } catch (URISyntaxException e) {
327 327
				logger.error("Given URL could not be transformed into URI", e);
328 328
			}
329
         
329

  
330 330
		return null;
331
	
331

  
332 332
	}
333 333

  
334
	
334

  
335 335

  
336 336

  
337 337
	private List<Reference> buildPublicationList( InputStream content, ICdmApplicationConfiguration services, IIpniServiceConfigurator iConfig) throws IOException {
338 338
		IpniServicePublicationConfigurator config = (IpniServicePublicationConfigurator)iConfig;
339
		
340
		List<Reference> result = new ArrayList<Reference>(); 
339

  
340
		List<Reference> result = new ArrayList<Reference>();
341 341
		BufferedReader reader = new BufferedReader (new InputStreamReader(content));
342
		
342

  
343 343
		String headerLine = reader.readLine();
344 344
		Map<Integer, String> parameterMap = getParameterMap(headerLine);
345
		
345

  
346 346
		String line = reader.readLine();
347 347
		while (StringUtils.isNotBlank(line)){
348 348
			Reference reference = getPublicationFromLine(line, parameterMap, services, config);
......
364 364
	private Reference getPublicationFromLine(String line, Map<Integer, String> parameterMap, ICdmApplicationConfiguration appConfig, IpniServicePublicationConfigurator config) {
365 365
		//fill value map
366 366
		String[] splits = line.split("%");
367
		
367

  
368 368
		Map<String, String> valueMap = new HashMap<String, String>();
369 369
		for (int i = 0; i < splits.length; i++){
370 370
			valueMap.put(parameterMap.get(i), splits[i]);
371 371
		}
372
		
372

  
373 373
		//create reference object
374 374
		Reference ref = ReferenceFactory.newGeneric();
375
		
375

  
376 376
		//reference
377 377
		if (config.isUseAbbreviationAsTitle() == true){
378 378
			ref.setTitle(valueMap.get(ABBREVIATION));
......
391 391
			Team team = Team.NewTitledInstance(author, author);
392 392
			ref.setAuthorship(team);
393 393
		}
394
		
394

  
395 395
		//remarks
396 396
		String remarks = valueMap.get(REMARKS);
397 397
		Annotation annotation = Annotation.NewInstance(remarks, AnnotationType.EDITORIAL(), Language.ENGLISH());
......
403 403
			Team tl2Author = Team.NewTitledInstance(tl2AuthorString, null);
404 404
			ref.setAuthorship(tl2Author);
405 405
		}else{
406
			//TODO parse name, 
406
			//TODO parse name,
407 407
			ref.getAuthorship().setTitleCache(tl2AuthorString, true);
408 408
			ref.addAnnotation(Annotation.NewInstance(tl2AuthorString, AnnotationType.EDITORIAL(), Language.ENGLISH()));
409 409
		}
410 410

  
411
		
411

  
412 412
		//dates
413 413
		TimePeriod date = TimePeriodParser.parseString(valueMap.get(DATE));
414 414
		ref.setDatePublished(date);
......
418 418
		Reference citation = getIpniCitation(appConfig);
419 419
		ref.addSource(OriginalSourceType.Lineage, valueMap.get(ID), "Publication", citation, valueMap.get(VERSION));
420 420

  
421
		
422
		
421

  
422

  
423 423
/*		TODO
424 424
		BPH number
425 425
		Authors role
......
429 429
		TL2 number
430 430
		TDWG abbreviation
431 431
	*/
432
		
432

  
433 433
		return ref;
434 434
	}
435 435

  
436 436

  
437 437
	private List<BotanicalName> buildNameList( InputStream content, ICdmApplicationConfiguration appConfig, IIpniServiceConfigurator iConfig) throws IOException {
438 438
		IpniServiceNamesConfigurator config = (IpniServiceNamesConfigurator)iConfig;
439
		List<BotanicalName> result = new ArrayList<BotanicalName>(); 
439
		List<BotanicalName> result = new ArrayList<BotanicalName>();
440 440
		BufferedReader reader = new BufferedReader (new InputStreamReader(content));
441
		
441

  
442 442
		String headerLine = reader.readLine();
443 443
		Map<Integer, String> parameterMap = getParameterMap(headerLine);
444
		
444

  
445 445
		String line = reader.readLine();
446 446
		while (StringUtils.isNotBlank(line)){
447
			
447

  
448 448
			BotanicalName name = getNameFromLine(line,parameterMap, appConfig);
449 449
			result.add(name);
450 450
			line = reader.readLine();
451
			
451

  
452 452
		}
453 453

  
454
		
454

  
455 455
		return result;
456 456
	}
457 457

  
......
460 460
		//Id%Version%Standard form%Default author forename%Default author surname%Taxon groups%Dates%Alternative names
461 461
		String[] splits = line.split("%");
462 462
		Map<String, String> valueMap = new HashMap<String, String>();
463
		
463

  
464 464
		for (int i = 0; i < splits.length; i++){
465 465
			valueMap.put(parameterMap.get(i), splits[i]);
466 466
		}
467
		
467

  
468 468
		BotanicalName name = BotanicalName.NewInstance(null);
469
		
469

  
470 470
		//caches
471 471
		name.setNameCache(valueMap.get(FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS), true);
472 472
		name.setAuthorshipCache(valueMap.get(AUTHORS), true);
473
		
473

  
474 474
		//epithets
475 475
		name.setGenusOrUninomial(valueMap.get(GENUS));
476 476
		name.setInfraGenericEpithet(valueMap.get(INFRA_GENUS));
477 477
		name.setSpecificEpithet(valueMap.get(SPECIES));
478 478
		name.setInfraSpecificEpithet(valueMap.get(INFRA_SPECIFIC));
479
		
479

  
480 480
		//rank
481 481
		try {
482 482
			String rankStr = nomalizeRank(valueMap.get(RANK));
......
484 484
		} catch (UnknownCdmTypeException e) {
485 485
			logger.warn("Rank was unknown");
486 486
		}
487
		
487

  
488 488
		//authors
489 489
		name.setBasionymAuthorship(Team.NewTitledInstance(valueMap.get(BASIONYM_AUTHOR), valueMap.get(BASIONYM_AUTHOR)));
490 490
		name.setCombinationAuthorship(Team.NewTitledInstance(valueMap.get(PUBLISHING_AUTHOR), valueMap.get(PUBLISHING_AUTHOR)));
491
		
491

  
492 492
		//publication
493
		Reference<?> ref = ReferenceFactory.newGeneric();
493
		Reference ref = ReferenceFactory.newGeneric();
494 494
		ref.setTitleCache(valueMap.get(PUBLICATION), true);
495 495
		TimePeriod datePublished = TimePeriodParser.parseString(valueMap.get(PUBLICATION_YEAR_FULL));
496 496
		name.setNomenclaturalReference(ref);
497
		
497

  
498 498
		//name status
499 499
		NomenclaturalStatusType statusType = null;
500 500
		String statusString = valueMap.get(NAME_STATUS);
......
507 507
				logger.warn("Name status not recognized: " + statusString);
508 508
			}
509 509
		}
510
		
510

  
511 511
		//remarks
512 512
		String remarks = valueMap.get(REMARKS);
513 513
		Annotation annotation = Annotation.NewInstance(remarks, AnnotationType.EDITORIAL(), Language.ENGLISH());
514 514
		name.addAnnotation(annotation);
515
		
515

  
516 516
		//basionym
517 517
		BotanicalName basionym = BotanicalName.NewInstance(null);
518 518
		basionym.setTitleCache(valueMap.get(BASIONYM), true);
519 519
		name.addBasionym(basionym);
520
		
520

  
521 521
		//replaced synonym
522 522
		BotanicalName replacedSynoynm = BotanicalName.NewInstance(null);
523 523
		replacedSynoynm.setTitleCache(valueMap.get(REPLACED_SYNONYM), true);
......
525 525

  
526 526
		//type information
527 527
		DerivedUnitFacade specimen = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
528
		
529
		
528

  
529

  
530 530
		//gathering period
531 531
		String collectionDateAsText = valueMap.get(COLLECTION_DATE_AS_TEXT);
532 532
		TimePeriod gatheringPeriod = TimePeriodParser.parseString(collectionDateAsText);
533
		
533

  
534 534
		try {
535 535
			gatheringPeriod.setStartDay(getIntegerDateValueOrNull(valueMap, COLLECTION_DAY1));
536 536
			gatheringPeriod.setStartMonth(getIntegerDateValueOrNull(valueMap, COLLECTION_MONTH1));
......
544 544
		specimen.setGatheringPeriod(gatheringPeriod);
545 545

  
546 546
		specimen.setFieldNumber(valueMap.get(COLLECTION_NUMBER));
547
		
547

  
548 548
		//collector team
549 549
		String team = valueMap.get(COLLECTOR_TEAM_AS_TEXT);
550 550
		Team collectorTeam = Team.NewTitledInstance(team, team);
551
		specimen.setCollector(collectorTeam);  
552
	    
551
		specimen.setCollector(collectorTeam);
552

  
553 553
		specimen.setLocality(valueMap.get(LOCALITY));
554
		
554

  
555 555
		try {
556 556
			String latDegrees = CdmUtils.Nz(valueMap.get(LATITUDE_DEGREES));
557 557
			String latMinutes = CdmUtils.Nz(valueMap.get(LATITUDE_MINUTES));
558 558
			String latSeconds = CdmUtils.Nz(valueMap.get(LATITUDE_SECONDS));
559 559
			String direction = CdmUtils.Nz(valueMap.get(NORTH_OR_SOUTH));
560 560
			String latitude = latDegrees + "°" + latMinutes + "'" + latSeconds + "\"" + direction;
561
			
561

  
562 562
			String lonDegrees = CdmUtils.Nz(valueMap.get(LATITUDE_DEGREES));
563 563
			String lonMinutes = CdmUtils.Nz(valueMap.get(LATITUDE_MINUTES));
564 564
			String lonSeconds = CdmUtils.Nz(valueMap.get(LATITUDE_SECONDS));
565 565
			direction = CdmUtils.Nz(valueMap.get(EAST_OR_WEST));
566 566
			String longitude = lonDegrees + "°" + lonMinutes + "'" + lonSeconds + "\"" + direction;
567 567

  
568
			
568

  
569 569
			specimen.setExactLocationByParsing(longitude, latitude, null, null);
570 570
		} catch (ParseException e) {
571 571
			logger.info("Parsing exception occurred when trying to parse type exact location."  + e.getMessage());
572 572
		} catch (Exception e) {
573 573
			logger.info("Exception occurred when trying to read type exact location."  + e.getMessage());
574 574
		}
575
		
576
		
575

  
576

  
577 577
		//type annotation
578 578
		Annotation typeAnnotation = Annotation.NewInstance(TYPE_REMARKS, AnnotationType.EDITORIAL(), Language.DEFAULT());
579 579
		specimen.addAnnotation(typeAnnotation);
580
		
581
		
580

  
581

  
582 582
		//TODO  Type name
583
		//TODO "Type locations"  , eg. holotype   CAT  ,isotype   CAT  ,isotype   FI  
583
		//TODO "Type locations"  , eg. holotype   CAT  ,isotype   CAT  ,isotype   FI
584 584

  
585 585
		//TODO Geographic unit as text
586
	      
587 586

  
588
		
589
		
590
		
587

  
588

  
589

  
590

  
591 591
		//source
592 592
		Reference citation = getIpniCitation(appConfig);
593 593
		name.addSource(OriginalSourceType.Lineage, valueMap.get(ID), "Name", citation, valueMap.get(VERSION));
594
		
595
		
594

  
595

  
596 596
//		//TODO
597 597
		//SHORT Family, Infra family, Hybrid genus, Hybrid, Collation, Nomenclatural synonym, Distribution, Citation type
598
/*		EXTENDED 
598
/*		EXTENDED
599 599
 *      Species author,
600
 *       Standardised basionym author flag, 
600
 *       Standardised basionym author flag,
601 601
 *       Standardised publishing author flag
602 602
	      Full name
603 603
	      Full name without family
......
665 665

  
666 666
	private List<Person> buildAuthorList(InputStream content, ICdmApplicationConfiguration services, IIpniServiceConfigurator iConfig) throws IOException {
667 667
		IpniServiceAuthorConfigurator config = (IpniServiceAuthorConfigurator)iConfig;
668
		List<Person> result = new ArrayList<Person>(); 
668
		List<Person> result = new ArrayList<Person>();
669 669
		BufferedReader reader = new BufferedReader (new InputStreamReader(content));
670
		
670

  
671 671
		String headerLine = reader.readLine();
672 672
		if (headerLine != null){
673 673
			Map<Integer, String> parameterMap = getParameterMap(headerLine);
674
			
674

  
675 675
			String line = reader.readLine();
676 676
			while (StringUtils.isNotBlank(line)){
677 677
				Person author = getAuthorFromLine(line,parameterMap, services, config);
......
679 679
				line = reader.readLine();
680 680
			}
681 681
		}
682
		
682

  
683 683
		return result;
684 684
	}
685 685

  
......
701 701
		//Id%Version%Standard form%Default author forename%Default author surname%Taxon groups%Dates%Alternative names
702 702
		String[] splits = line.split("%");
703 703
		Map<String, String> valueMap = new HashMap<String, String>();
704
		
704

  
705 705
		for (int i = 0; i < splits.length; i++){
706 706
			valueMap.put(categoryMap.get(i), splits[i]);
707 707
		}
708
		
708

  
709 709
		Person person = Person.NewInstance();
710
		
710

  
711 711
		person.setNomenclaturalTitle(valueMap.get(STANDARD_FORM));
712 712
		person.setFirstname(valueMap.get(DEFAULT_AUTHOR_FORENAME));
713 713
		person.setLastname(valueMap.get(DEFAULT_AUTHOR_SURNAME));
714
		
715
		Reference<?> citation = getIpniCitation(appConfig);
716
		
714

  
715
		Reference citation = getIpniCitation(appConfig);
716

  
717 717
		//id, version
718 718
		person.addSource(OriginalSourceType.Lineage, valueMap.get(ID), "Author", citation, valueMap.get(VERSION));
719
		
719

  
720 720
		//dates
721 721
		TimePeriod lifespan = TimePeriodParser.parseString(valueMap.get(DATES));
722 722
		person.setLifespan(lifespan);
723
		
723

  
724 724
		//alternative_names
725 725
		String alternativeNames = valueMap.get(ALTERNATIVE_NAMES);
726 726
		if (StringUtils.isNotBlank(alternativeNames)){
......
732 732
				Extension.NewInstance(person, alternativeName, ExtensionType.INFORMAL_CATEGORY());
733 733
			}
734 734
		}
735
		
735

  
736 736
		//TODO taxonGroups
737
		
737

  
738 738
		return person;
739 739
	}
740 740

  
741
	
741

  
742 742
	private Reference getIpniCitation(ICdmApplicationConfiguration appConfig) {
743
		Reference<?> ipniReference;
743
		Reference ipniReference;
744 744
		if (appConfig != null){
745 745
			ipniReference = appConfig.getReferenceService().find(uuidIpni);
746 746
			if (ipniReference == null){
......
758 758
	 * @return
759 759
	 */
760 760
	private Reference getNewIpniReference() {
761
		Reference<?> ipniReference;
761
		Reference ipniReference;
762 762
		ipniReference = ReferenceFactory.newDatabase();
763 763
		ipniReference.setTitleCache("The International Plant Names Index (IPNI)");
764 764
		return ipniReference;
......
773 773
		return result;
774 774
	}
775 775

  
776
	public List<BotanicalName> getNamesAdvanced(String family, String genus, String species, String infraFamily, 
777
			String infraGenus, String infraSpecies, String authorAbbrev, Boolean includePublicationAuthors, 
776
	@Override
777
    public List<BotanicalName> getNamesAdvanced(String family, String genus, String species, String infraFamily,
778
			String infraGenus, String infraSpecies, String authorAbbrev, Boolean includePublicationAuthors,
778 779
			Boolean includeBasionymAuthors,
779 780
			String publicationTitle,
780
			Boolean isAPNIRecord, 
781
			Boolean isGCIRecord, 
781
			Boolean isAPNIRecord,
782
			Boolean isGCIRecord,
782 783
			Boolean isIKRecord,
783 784
			Rank rankInRangeToReturn,
784 785
			Boolean sortByFamily,
......
787 788
		IpniRank ipniRank = IpniRank.valueOf(rankInRangeToReturn);
788 789
		return getNamesAdvanced(family, genus, species, infraFamily, infraGenus, infraSpecies, authorAbbrev, includePublicationAuthors, includeBasionymAuthors, publicationTitle, isAPNIRecord, isGCIRecord, isIKRecord, ipniRank, sortByFamily, config, services);
789 790
	}
790
	
791
	public List<BotanicalName> getNamesAdvanced(String family, String genus, String species, String infraFamily, 
792
			String infraGenus, String infraSpecies, String authorAbbrev, Boolean includePublicationAuthors, 
791

  
792
	@Override
793
    public List<BotanicalName> getNamesAdvanced(String family, String genus, String species, String infraFamily,
794
			String infraGenus, String infraSpecies, String authorAbbrev, Boolean includePublicationAuthors,
793 795
			Boolean includeBasionymAuthors,
794 796
			String publicationTitle,
795
			Boolean isAPNIRecord, 
796
			Boolean isGCIRecord, 
797
			Boolean isAPNIRecord,
798
			Boolean isGCIRecord,
797 799
			Boolean isIKRecord,
798 800
			IpniRank rankToReturn,
799 801
			Boolean sortByFamily,
800 802
			IpniServiceNamesConfigurator config,
801 803
			ICdmApplicationConfiguration services) {
802
		
804

  
803 805
//		find_rankToReturn=all&output_format=normal&find_sortByFamily=on&find_sortByFamily=off&query_type=by_query&back_page=plantsearch
804 806

  
805 807
		//config
......
807 809
			config = new IpniServiceNamesConfigurator();
808 810
		}
809 811

  
810
		
812

  
811 813
		family = normalizeParameter(family);
812 814
		genus = normalizeParameter(genus);
813 815
		species = normalizeParameter(species);
......
817 819
		authorAbbrev = normalizeParameter(authorAbbrev);
818 820

  
819 821
		publicationTitle = normalizeParameter(publicationTitle);
820
		
822

  
821 823
		DelimitedFormat format = config.getFormat();
822
		
823
		String request = 
824
				"find_family=" + family + 
825
				"&find_genus=" + genus + 
826
				"&find_species=" + species + 
824

  
825
		String request =
826
				"find_family=" + family +
827
				"&find_genus=" + genus +
828
				"&find_species=" + species +
827 829
				"&find_infrafamily=" + infraFamily +
828 830
				"&find_infragenus=" + infraGenus +
829 831
				"&find_infraspecies=" + infraSpecies +
......
833 835
				getBooleanParameter("&find_find_isAPNIRecord=", includePublicationAuthors, "on", "false") +
834 836
				getBooleanParameter("&find_isGCIRecord=", includePublicationAuthors, "on", "false") +
835 837
				getBooleanParameter("&find_isIKRecord=", includePublicationAuthors, "on", "false") +
836
				
837
				
838

  
839

  
838 840
				"&find_publicationTitle=" + publicationTitle +
839 841
				"&output_format=" + format.parameter;
840
		
842

  
841 843
		return (List)queryService(request, services, getServiceUrl(IIpniService.ADVANCED_NAME_SERVICE_URL), config, ServiceType.NAME);
842 844
	}
843 845

  
844
	
846

  
845 847
	private String getBooleanParameter(String urlParamString, Boolean booleanParameter, String trueString, String falseString) {
846 848
		String result;
847 849
		if (booleanParameter == null){
848
			result = getBooleanParameter(urlParamString, true, trueString, falseString) + getBooleanParameter(urlParamString, false, trueString, falseString); 
850
			result = getBooleanParameter(urlParamString, true, trueString, falseString) + getBooleanParameter(urlParamString, false, trueString, falseString);
849 851
		}else if (booleanParameter == true){
850 852
			result = urlParamString + trueString;
851 853
		}else {
......
858 860
	/* (non-Javadoc)
859 861
	 * @see eu.etaxonomy.cdm.ext.IIpniService#getNamesSimple(java.lang.String, eu.etaxonomy.cdm.ext.IIpniService.DelimitedFormat, eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration)
860 862
	 */
861
	public List<BotanicalName> getNamesSimple(String wholeName, ICdmApplicationConfiguration services, IpniServiceNamesConfigurator config){
863
	@Override
864
    public List<BotanicalName> getNamesSimple(String wholeName, ICdmApplicationConfiguration services, IpniServiceNamesConfigurator config){
862 865
		if (config == null){
863 866
			config = new IpniServiceNamesConfigurator();
864 867
		}
865
		
866
		
868

  
869

  
867 870
//		query_type=by_query&back_page=query_ipni.html
868
		
871

  
869 872
		wholeName = normalizeParameter(wholeName);
870
		
873

  
871 874
		DelimitedFormat format = config.getFormat();
872
			
873
		String request = "find_wholeName=" + wholeName + 
875

  
876
		String request = "find_wholeName=" + wholeName +
874 877
						"&output_format=" + format.parameter;
875
		
878

  
876 879
		return (List)queryService(request, services, getServiceUrl(IIpniService.SIMPLE_NAME_SERVICE_URL), config, ServiceType.NAME);
877 880
	}
878 881

  
879 882
	/* (non-Javadoc)
880 883
	 * @see eu.etaxonomy.cdm.ext.IIpniService#getPublications(java.lang.String, java.lang.String, boolean, eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration)
881 884
	 */
882
	public List<Reference> getPublications(String title, String abbreviation, ICdmApplicationConfiguration services, IpniServicePublicationConfigurator config){
885
	@Override
886
    public List<Reference> getPublications(String title, String abbreviation, ICdmApplicationConfiguration services, IpniServicePublicationConfigurator config){
883 887
//		http://www.uk.ipni.org/ipni/advPublicationSearch.do?find_title=Spe*plant*&find_abbreviation=&output_format=normal&query_type=by_query&back_page=publicationsearch
884 888
//		http://www.uk.ipni.org/ipni/advPublicationSearch.do?find_title=*Hortus+Britannicus*&find_abbreviation=&output_format=delimited-classic&output_format=delimited
885
		
889

  
886 890
		if (config == null){
887 891
			config = new IpniServicePublicationConfigurator();
888 892
		}
889
		
893

  
890 894
		title = normalizeParameter(title);
891 895
		abbreviation = normalizeParameter(abbreviation);
892
	
896

  
893 897
		String request = "find_title=" + title +
894 898
						"&find_abbreviation=" + abbreviation +
895 899
						"&output_format=" + DelimitedFormat.CLASSIC.parameter;
896
		
900

  
897 901
		List<Reference> result = (List)queryService(request, services, getServiceUrl(IIpniService.PUBLICATION_SERVICE_URL), config, ServiceType.PUBLICATION);
898 902
		return result;
899 903
	}
900 904

  
901
	
902
	
905

  
906

  
903 907
	/**
904 908
	 * @return
905 909
	 */
......
907 911
		return DelimitedFormat.SHORT;
908 912
	}
909 913

  
910
	
914

  
911 915
	/**
912 916
	 * The service url
913 917
	 *
914 918
	 * @return the serviceUrl
915 919
	 */
916
	public URL getServiceUrl(String url) {
920
	@Override
921
    public URL getServiceUrl(String url) {
917 922
		URL serviceUrl;
918 923
		try {
919 924
			serviceUrl = new URL(url);
......
926 931

  
927 932
	@Override
928 933
	public InputStream getNamesById(String id) {
929
		
930
	
934

  
935

  
931 936
		String request = "id="+id + "&output_format=lsid-metadata";
932 937
		return queryServiceForID(request, getServiceUrl(IIpniService.ID_NAMESEARCH_SERVICE_URL));
933
		
938

  
934 939
	}
935
	
940

  
936 941
	@Override
937 942
	public InputStream getPublicationsById(String id) {
938
		
939
	
943

  
944

  
940 945
		String request = "id="+id ;
941 946
		return queryServiceForID(request, getServiceUrl(IIpniService.ID_PUBLICATION_SERVICE_URL));
942
		
947

  
943 948
	}
944 949

  
945
		
946
	
950

  
951

  
947 952
}

Also available in: Unified diff