1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.ext.ipni;
|
10
|
|
11
|
import java.io.BufferedReader;
|
12
|
import java.io.IOException;
|
13
|
import java.io.InputStream;
|
14
|
import java.io.InputStreamReader;
|
15
|
import java.net.HttpURLConnection;
|
16
|
import java.net.MalformedURLException;
|
17
|
import java.net.URI;
|
18
|
import java.net.URISyntaxException;
|
19
|
import java.net.URL;
|
20
|
import java.text.ParseException;
|
21
|
import java.util.ArrayList;
|
22
|
import java.util.HashMap;
|
23
|
import java.util.List;
|
24
|
import java.util.Map;
|
25
|
import java.util.regex.Matcher;
|
26
|
import java.util.regex.Pattern;
|
27
|
|
28
|
import javax.validation.constraints.NotNull;
|
29
|
|
30
|
import org.apache.commons.lang.StringUtils;
|
31
|
import org.apache.http.HttpResponse;
|
32
|
import org.apache.log4j.Logger;
|
33
|
import org.springframework.stereotype.Component;
|
34
|
|
35
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
36
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
37
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
38
|
import eu.etaxonomy.cdm.common.UriUtils;
|
39
|
import eu.etaxonomy.cdm.model.agent.Person;
|
40
|
import eu.etaxonomy.cdm.model.agent.Team;
|
41
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
42
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
43
|
import eu.etaxonomy.cdm.model.common.Extension;
|
44
|
import eu.etaxonomy.cdm.model.common.ExtensionType;
|
45
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
46
|
import eu.etaxonomy.cdm.model.common.Language;
|
47
|
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
|
48
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
49
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
50
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
51
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
52
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
53
|
import eu.etaxonomy.cdm.model.name.Rank;
|
54
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
55
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
56
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
57
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
58
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
59
|
import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException;
|
60
|
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
|
61
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
62
|
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
|
63
|
|
64
|
/**
|
65
|
* @author a.mueller
|
66
|
* @since Aug 16, 2010
|
67
|
*
|
68
|
* TODO the whole ipni service should be refactored to use UriUtils. I did this for the queryService method only because we ran into timeout
|
69
|
* problems in tests. UriUtils handles these problems already.
|
70
|
*
|
71
|
*/
|
72
|
@Component
|
73
|
public class IpniService implements IIpniService{
|
74
|
private static final Logger logger = Logger.getLogger(IpniService.class);
|
75
|
|
76
|
|
77
|
//TYPE
|
78
|
private static final String EAST_OR_WEST = "East or west";
|
79
|
|
80
|
private static final String NORTH_OR_SOUTH = "North or south";
|
81
|
|
82
|
private static final String LATITUDE_SECONDS = "Latitude seconds";
|
83
|
|
84
|
private static final String LATITUDE_MINUTES = "Latitude minutes";
|
85
|
|
86
|
private static final String LATITUDE_DEGREES = "Latitude degrees";
|
87
|
|
88
|
private static final String LONGITUDE_SECONDS = "Longitude seconds";
|
89
|
|
90
|
private static final String LONGITUDE_MINUTES = "Longitude minutes";
|
91
|
|
92
|
private static final String LONGITUDE_DEGREES = "Longitude degrees";
|
93
|
|
94
|
|
95
|
|
96
|
private static final String COLLECTION_DATE_AS_TEXT = "Collection date as text";
|
97
|
|
98
|
private static final String COLLECTION_DAY1 = "Collection day1";
|
99
|
|
100
|
private static final String COLLECTION_MONTH1 = "Collection month1";
|
101
|
|
102
|
private static final String COLLECTION_YEAR1 = "Collection year1";
|
103
|
|
104
|
private static final String COLLECTION_DAY2 = "Collection day2";
|
105
|
|
106
|
private static final String COLLECTION_MONTH2 = "Collection month2";
|
107
|
|
108
|
private static final String COLLECTION_YEAR2 = "Collection year2";
|
109
|
|
110
|
private static final String COLLECTION_NUMBER = "Collection number";
|
111
|
|
112
|
private static final String COLLECTOR_TEAM_AS_TEXT = "Collector team as text";
|
113
|
|
114
|
private static final String LOCALITY = "Locality";
|
115
|
|
116
|
private static final String TYPE_REMARKS = "Type remarks";
|
117
|
|
118
|
|
119
|
// GENERAL
|
120
|
public static String ID = "Id";
|
121
|
public static String VERSION = "Version";
|
122
|
public static final String REMARKS = "Remarks";
|
123
|
|
124
|
//NAMES
|
125
|
public static final String FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS = "Full name without family and authors";
|
126
|
public static final String AUTHORS = "Authors";
|
127
|
public static final String FAMILY = "Family";
|
128
|
public static final String GENUS = "Genus";
|
129
|
public static final String INFRA_GENUS = "Infra genus";
|
130
|
public static final String SPECIES = "Species";
|
131
|
public static final String INFRA_SPECIFIC = "Infra species";
|
132
|
public static final String HYBRID = "Hybrid";
|
133
|
public static final String RANK = "Rank";
|
134
|
public static final String BASIONYM_AUTHOR = "Basionym author";
|
135
|
public static final String PUBLISHING_AUTHOR = "Publishing author";
|
136
|
public static final String PUBLICATION = "Publication";
|
137
|
public static final String COLLATION = "Collation";
|
138
|
public static final String PUBLICATION_YEAR_FULL = "Publication year full";
|
139
|
public static final String NAME_STATUS = "Name status";
|
140
|
public static final String BASIONYM = "Basionym";
|
141
|
public static final String REPLACED_SYNONYM = "Replaced synonym";
|
142
|
|
143
|
|
144
|
//AUTHORS
|
145
|
|
146
|
public static final String STANDARD_FORM = "Standard Form";
|
147
|
|
148
|
public static final String DEFAULT_AUTHOR_FORENAME = "Default author forename";
|
149
|
public static final String DEFAULT_AUTHOR_SURNAME = "Default author surname";
|
150
|
public static final String TAXON_GROUPS = "Taxon groups";
|
151
|
public static final String DATES = "Dates";
|
152
|
public static final String ALTERNATIVE_NAMES = "Alternative names";
|
153
|
|
154
|
public static final String DEFAULT_AUTHOR_NAME = "Default author name";
|
155
|
|
156
|
public static final String NAME_NOTES = "Name notes";
|
157
|
public static final String NAME_SOURCE = "Name source";
|
158
|
public static final String DATE_TYPE_CODE = "Date type code";
|
159
|
public static final String DATE_TYPE_STRING = "Date type string";
|
160
|
|
161
|
public static final String ALTERNATIVE_ABBREVIATIONS = "Alternative abbreviations";
|
162
|
public static final String EXAMPLE_OF_NAME_PUBLISHED = "Example of name published";
|
163
|
|
164
|
|
165
|
//PUBLICATIONS
|
166
|
|
167
|
public static final String ABBREVIATION = "Abbreviation";
|
168
|
public static final String TITLE = "Title";
|
169
|
public static final String BPH_NUMBER = "BPH number";
|
170
|
public static final String ISBN = "ISBN";
|
171
|
public static final String ISSN = "ISSN";
|
172
|
public static final String AUTHORS_ROLE = "Authors role";
|
173
|
public static final String EDITION = "Edition";
|
174
|
public static final String DATE = "Date";
|
175
|
public static final String IN_PUBLICATION_FACADE = "In publication facade";
|
176
|
public static final String LC_NUMBER = "LC number";
|
177
|
public static final String PLACE = "Place";
|
178
|
public static final String PUBLICATION_AUTHOR_TEAM = "Publication author team";
|
179
|
public static final String PRECEDED_BY = "Preceded";
|
180
|
public static final String TL2_AUTHOR = "TL2 author";
|
181
|
public static final String TL2_NUMBER = "TL2 number";
|
182
|
public static final String TDWG_ABBREVIATION = "TDWG abbreviation";
|
183
|
|
184
|
private enum ServiceType{
|
185
|
AUTHOR,
|
186
|
NAME,
|
187
|
PUBLICATION,
|
188
|
ID
|
189
|
}
|
190
|
|
191
|
public enum IpniRank{
|
192
|
ALL ("All"),
|
193
|
FAMILIAL ("Familial"),
|
194
|
INFRA_FAMILIAL ("Infrafamilial"),
|
195
|
GENERIC("Generic"),
|
196
|
INFRA_GENERIC("Infrageneric"),
|
197
|
SPECIFIC ("Specific"),
|
198
|
INFRA_SPECIFIC("InfraSpecific");
|
199
|
|
200
|
String strRank;
|
201
|
IpniRank(String strRank){
|
202
|
this.strRank = strRank;
|
203
|
}
|
204
|
|
205
|
public static IpniRank valueOf(Rank rank){
|
206
|
if (rank == null){
|
207
|
return ALL;
|
208
|
}else if (rank.isInfraSpecific()){
|
209
|
return INFRA_SPECIFIC;
|
210
|
}else if (rank.isSpecies()){
|
211
|
return SPECIFIC;
|
212
|
}else if (rank.isInfraGeneric()){
|
213
|
return INFRA_GENERIC;
|
214
|
}else if (rank.isGenus()){
|
215
|
return GENERIC;
|
216
|
}else if (rank.isLower(Rank.FAMILY())){
|
217
|
return INFRA_FAMILIAL;
|
218
|
}else if (rank.isHigher(Rank.SUBFAMILY())){
|
219
|
return FAMILIAL;
|
220
|
}else{
|
221
|
logger.warn("Rank could not be transformed to ipni rank. Use ALL instead");
|
222
|
return ALL;
|
223
|
}
|
224
|
}
|
225
|
}
|
226
|
|
227
|
|
228
|
// private URL serviceUrl;
|
229
|
|
230
|
// ******************************** CONSTRUCTOR **************************************
|
231
|
|
232
|
// ****************************** METHODS ****************************************************/
|
233
|
|
234
|
@Override
|
235
|
public List<Person> getAuthors(String abbreviation, String surname, String forename, String isoCountry, ICdmRepository services, IpniServiceAuthorConfigurator config){
|
236
|
//config
|
237
|
if (config == null){
|
238
|
config = new IpniServiceAuthorConfigurator();
|
239
|
}
|
240
|
|
241
|
|
242
|
abbreviation = normalizeParameter(abbreviation);
|
243
|
surname = normalizeParameter(surname);
|
244
|
isoCountry = normalizeParameter(isoCountry);
|
245
|
forename = normalizeParameter(forename);
|
246
|
|
247
|
DelimitedFormat format = config.getFormat();
|
248
|
|
249
|
String request = "find_abbreviation=" + abbreviation +
|
250
|
"&find_surname=" + surname +
|
251
|
"&find_isoCountry=" + isoCountry +
|
252
|
"&find_forename=" + forename +
|
253
|
"&output_format=" + format.parameter;
|
254
|
|
255
|
return (List)queryService(request, services, getServiceUrl(IIpniService.AUTHOR_SERVICE_URL), config, ServiceType.AUTHOR);
|
256
|
}
|
257
|
|
258
|
|
259
|
/**
|
260
|
* FIXME rewrote this method to rely on {@link UriUtils}. The whole class should be
|
261
|
* adjusted to reflect this change.
|
262
|
* Also see comments in the class' documentation block.
|
263
|
*
|
264
|
* @param restRequest
|
265
|
* @return
|
266
|
*/
|
267
|
private List<? extends IdentifiableEntity> queryService(String request, ICdmRepository repository, URL serviceUrl,
|
268
|
IIpniServiceConfigurator config, ServiceType serviceType){
|
269
|
if (config == null){
|
270
|
throw new NullPointerException("Ipni service configurator should not be null");
|
271
|
}
|
272
|
try {
|
273
|
|
274
|
// create the request url
|
275
|
URL newUrl = new URL(serviceUrl.getProtocol(),
|
276
|
serviceUrl.getHost(),
|
277
|
serviceUrl.getPort(),
|
278
|
serviceUrl.getPath()
|
279
|
+ "?" + request);
|
280
|
|
281
|
URI newUri = newUrl.toURI();
|
282
|
logger.info("Firing request for URI: " + newUri);
|
283
|
HttpResponse response = UriUtils.getResponse(newUri, null);
|
284
|
|
285
|
int responseCode = response.getStatusLine().getStatusCode();
|
286
|
|
287
|
// get the content at the resource
|
288
|
InputStream content = response.getEntity().getContent();
|
289
|
// build the result
|
290
|
List<? extends IdentifiableEntity<?>> result;
|
291
|
if (serviceType.equals(ServiceType.AUTHOR)){
|
292
|
result = buildAuthorList(content, repository, config);
|
293
|
}else if (serviceType.equals(ServiceType.NAME)){
|
294
|
result = buildNameList(content, repository, config);
|
295
|
}else {
|
296
|
result = buildPublicationList(content, repository, config);
|
297
|
}
|
298
|
if(responseCode == HttpURLConnection.HTTP_OK){
|
299
|
return result;
|
300
|
}else{
|
301
|
//TODO error handling
|
302
|
logger.error("No Http_OK");
|
303
|
}
|
304
|
|
305
|
} catch (IOException e) {
|
306
|
logger.error("No content for request: " + request);
|
307
|
} catch (URISyntaxException e) {
|
308
|
logger.error("Given URL could not be transformed into URI", e);
|
309
|
}
|
310
|
|
311
|
// error
|
312
|
return null;
|
313
|
}
|
314
|
|
315
|
public InputStream queryServiceForID (String request, URL serviceUrl){
|
316
|
|
317
|
try {
|
318
|
|
319
|
// create the request url
|
320
|
URL newUrl = new URL(serviceUrl.getProtocol(),
|
321
|
serviceUrl.getHost(),
|
322
|
serviceUrl.getPort(),
|
323
|
serviceUrl.getPath()
|
324
|
+ "?" + request);
|
325
|
|
326
|
|
327
|
URI newUri = newUrl.toURI();
|
328
|
|
329
|
logger.info("Firing request for URI: " + newUri);
|
330
|
|
331
|
HttpResponse response = UriUtils.getResponse(newUri, null);
|
332
|
|
333
|
int responseCode = response.getStatusLine().getStatusCode();
|
334
|
|
335
|
// get the content at the resource
|
336
|
InputStream content = response.getEntity().getContent();
|
337
|
return content;
|
338
|
|
339
|
} catch (IOException e) {
|
340
|
logger.error("No content for request: " + request);
|
341
|
throw new RuntimeException(e);
|
342
|
} catch (URISyntaxException e) {
|
343
|
logger.error("Given URL could not be transformed into URI", e);
|
344
|
throw new RuntimeException(e);
|
345
|
}
|
346
|
|
347
|
}
|
348
|
|
349
|
|
350
|
|
351
|
|
352
|
private List<Reference> buildPublicationList( InputStream content, ICdmRepository services, IIpniServiceConfigurator iConfig) throws IOException {
|
353
|
IpniServicePublicationConfigurator config = (IpniServicePublicationConfigurator)iConfig;
|
354
|
|
355
|
List<Reference> result = new ArrayList<>();
|
356
|
BufferedReader reader = new BufferedReader (new InputStreamReader(content));
|
357
|
|
358
|
String headerLine = reader.readLine();
|
359
|
Map<Integer, String> parameterMap = getParameterMap(headerLine);
|
360
|
|
361
|
String line = reader.readLine();
|
362
|
while (isNotBlank(line)){
|
363
|
Reference reference = getPublicationFromLine(line, parameterMap, services, config);
|
364
|
result.add(reference);
|
365
|
line = reader.readLine();
|
366
|
}
|
367
|
|
368
|
return result;
|
369
|
}
|
370
|
|
371
|
|
372
|
/**
|
373
|
* @param line
|
374
|
* @param parameterMap
|
375
|
* @param repository
|
376
|
* @param config
|
377
|
* @return
|
378
|
*/
|
379
|
private Reference getPublicationFromLine(String line, Map<Integer, String> parameterMap,
|
380
|
ICdmRepository repository, IpniServicePublicationConfigurator config) {
|
381
|
//fill value map
|
382
|
String[] splits = line.split("%");
|
383
|
|
384
|
Map<String, String> valueMap = fillValueMap(parameterMap, splits);
|
385
|
|
386
|
//create reference object
|
387
|
Reference ref = ReferenceFactory.newGeneric();
|
388
|
|
389
|
//reference
|
390
|
if (config.isUseAbbreviationAsTitle() == true){
|
391
|
ref.setTitle(valueMap.get(ABBREVIATION));
|
392
|
//TODO handle title as extension
|
393
|
}else{
|
394
|
ref.setTitle(valueMap.get(TITLE));
|
395
|
//TODO handle abbreviation as extension
|
396
|
}
|
397
|
ref.setIsbn(valueMap.get(ISBN));
|
398
|
ref.setIssn(valueMap.get(ISSN));
|
399
|
ref.setEdition(valueMap.get(EDITION));
|
400
|
ref.setPlacePublished(valueMap.get(PLACE));
|
401
|
|
402
|
String author = valueMap.get(PUBLICATION_AUTHOR_TEAM);
|
403
|
if (isNotBlank(author)){
|
404
|
Team team = Team.NewTitledInstance(author, author);
|
405
|
ref.setAuthorship(team);
|
406
|
}
|
407
|
|
408
|
//remarks
|
409
|
String remarks = valueMap.get(REMARKS);
|
410
|
if (remarks != null){
|
411
|
Annotation annotation = Annotation.NewInstance(remarks, AnnotationType.EDITORIAL(), Language.ENGLISH());
|
412
|
ref.addAnnotation(annotation);
|
413
|
}
|
414
|
|
415
|
|
416
|
String tl2AuthorString = valueMap.get(TL2_AUTHOR);
|
417
|
if (ref.getAuthorship() == null){
|
418
|
Team tl2Author = Team.NewTitledInstance(tl2AuthorString, null);
|
419
|
ref.setAuthorship(tl2Author);
|
420
|
}else{
|
421
|
//TODO parse name,
|
422
|
ref.getAuthorship().setTitleCache(tl2AuthorString, true);
|
423
|
ref.addAnnotation(Annotation.NewInstance(tl2AuthorString, AnnotationType.EDITORIAL(), Language.ENGLISH()));
|
424
|
}
|
425
|
|
426
|
|
427
|
//dates
|
428
|
TimePeriod date = TimePeriodParser.parseString(valueMap.get(DATE));
|
429
|
ref.setDatePublished(date);
|
430
|
|
431
|
|
432
|
//source
|
433
|
Reference citation = getIpniCitation(repository);
|
434
|
ref.addSource(OriginalSourceType.Lineage, valueMap.get(ID), "Publication", citation, valueMap.get(VERSION));
|
435
|
|
436
|
|
437
|
|
438
|
/* TODO
|
439
|
BPH number
|
440
|
Authors role
|
441
|
In publication facade
|
442
|
LC number
|
443
|
Preceded by
|
444
|
TL2 number
|
445
|
TDWG abbreviation
|
446
|
*/
|
447
|
|
448
|
return ref;
|
449
|
}
|
450
|
|
451
|
|
452
|
private List<TaxonName> buildNameList( InputStream content, ICdmRepository repository, IIpniServiceConfigurator iConfig) throws IOException {
|
453
|
IpniServiceNamesConfigurator config = (IpniServiceNamesConfigurator)iConfig;
|
454
|
List<TaxonName> result = new ArrayList<>();
|
455
|
BufferedReader reader = new BufferedReader (new InputStreamReader(content));
|
456
|
|
457
|
String headerLine = reader.readLine();
|
458
|
// System.out.println(headerLine);
|
459
|
Map<Integer, String> parameterMap = getParameterMap(headerLine);
|
460
|
|
461
|
String line = reader.readLine();
|
462
|
while (isNotBlank(line)){
|
463
|
// System.out.println(line);
|
464
|
TaxonName name = (TaxonName)getNameFromLine(line,parameterMap, repository, config);
|
465
|
result.add(name);
|
466
|
line = reader.readLine();
|
467
|
}
|
468
|
|
469
|
return result;
|
470
|
}
|
471
|
|
472
|
|
473
|
private static final NonViralNameParserImpl nvnParser = NonViralNameParserImpl.NewInstance();
|
474
|
|
475
|
private IBotanicalName getNameFromLine(String line, Map<Integer, String> parameterMap, ICdmRepository repository, IpniServiceNamesConfigurator config) {
|
476
|
//Id%Version%Standard form%Default author forename%Default author surname%Taxon groups%Dates%Alternative names
|
477
|
String[] splits = line.split("%");
|
478
|
|
479
|
Map<String, String> valueMap = fillValueMap(parameterMap, splits);
|
480
|
|
481
|
IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(null);
|
482
|
|
483
|
//epithets
|
484
|
name.setGenusOrUninomial(valueMap.get(GENUS));
|
485
|
name.setInfraGenericEpithet(valueMap.get(INFRA_GENUS));
|
486
|
name.setSpecificEpithet(valueMap.get(SPECIES));
|
487
|
name.setInfraSpecificEpithet(valueMap.get(INFRA_SPECIFIC));
|
488
|
|
489
|
//rank
|
490
|
try {
|
491
|
String rankStr = nomalizeRank(valueMap.get(RANK));
|
492
|
Rank rank = Rank.getRankByNameOrIdInVoc(rankStr, NomenclaturalCode.ICNAFP, true);
|
493
|
name.setRank(rank);
|
494
|
} catch (UnknownCdmTypeException e) {
|
495
|
logger.warn("Rank was unknown");
|
496
|
}
|
497
|
//caches
|
498
|
String pureName = valueMap.get(FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS);
|
499
|
String nameCache = name.getNameCache();
|
500
|
if (!Nz(pureName).equals(nameCache)) {
|
501
|
nvnParser.parseSimpleName(name, valueMap.get(FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS), name.getRank(), true);
|
502
|
// name.setNameCache(valueMap.get(FULL_NAME_WITHOUT_FAMILY_AND_AUTHORS), true);
|
503
|
}
|
504
|
|
505
|
|
506
|
|
507
|
String authors = "";
|
508
|
//authors
|
509
|
if (valueMap.get(BASIONYM_AUTHOR)!= null){
|
510
|
authors = valueMap.get(BASIONYM_AUTHOR);
|
511
|
// name.setBasionymAuthorship(Team.NewTitledInstance(valueMap.get(BASIONYM_AUTHOR), valueMap.get(BASIONYM_AUTHOR)));
|
512
|
}
|
513
|
if (valueMap.get(PUBLISHING_AUTHOR)!= null){
|
514
|
authors += valueMap.get(PUBLISHING_AUTHOR);
|
515
|
// name.setCombinationAuthorship(Team.NewTitledInstance(valueMap.get(PUBLISHING_AUTHOR), valueMap.get(PUBLISHING_AUTHOR)));
|
516
|
}
|
517
|
try {
|
518
|
nvnParser.parseAuthors(name, authors);
|
519
|
} catch (StringNotParsableException e1) {
|
520
|
//
|
521
|
}
|
522
|
if (!Nz(valueMap.get(AUTHORS)).equals(name.getAuthorshipCache())) {
|
523
|
name.setAuthorshipCache(valueMap.get(AUTHORS), true);
|
524
|
}
|
525
|
if ("Y".equals(valueMap.get(HYBRID))){
|
526
|
if (!name.isHybrid()){
|
527
|
//Is there a concrete way to include the hybrid flag info? As it does not say which type of hybrid it seems
|
528
|
//to be best to handle hybrids via parsing. But there might be a better errror handling possible.
|
529
|
logger.warn("Name is flagged as hybrid at IPNI but CDM name has no hybrid flag set: " + name.getTitleCache());
|
530
|
}
|
531
|
}
|
532
|
|
533
|
//publication
|
534
|
if (valueMap.get(PUBLICATION)!= null || valueMap.get(COLLATION)!= null || valueMap.get(PUBLICATION_YEAR_FULL) != null){
|
535
|
Reference ref = ReferenceFactory.newGeneric();
|
536
|
|
537
|
//TODO probably we can do better parsing here
|
538
|
String pub = CdmUtils.concat(" ", valueMap.get(PUBLICATION), valueMap.get(COLLATION));
|
539
|
if (isNotBlank(pub)){
|
540
|
String nomRefTitle = pub;
|
541
|
String[] split = nomRefTitle.split(":");
|
542
|
if (split.length > 1){
|
543
|
String detail = split[split.length-1];
|
544
|
name.setNomenclaturalMicroReference(detail.trim());
|
545
|
nomRefTitle = nomRefTitle.substring(0, nomRefTitle.length() - detail.length() - 1).trim();
|
546
|
}
|
547
|
|
548
|
ref.setAbbrevTitle(nomRefTitle);
|
549
|
}
|
550
|
|
551
|
TimePeriod datePublished = parsePublicationFullYear(valueMap.get(PUBLICATION_YEAR_FULL));
|
552
|
ref.setDatePublished(datePublished);
|
553
|
|
554
|
name.setNomenclaturalReference(ref);
|
555
|
}
|
556
|
|
557
|
//name status
|
558
|
NomenclaturalStatusType statusType = null;
|
559
|
String statusString = valueMap.get(NAME_STATUS);
|
560
|
if (isNotBlank(statusString)){
|
561
|
try {
|
562
|
statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusString, name);
|
563
|
NomenclaturalStatus nomStatus = NomenclaturalStatus.NewInstance(statusType);
|
564
|
name.addStatus(nomStatus);
|
565
|
} catch (UnknownCdmTypeException e) {
|
566
|
logger.warn("Name status not recognized: " + statusString);
|
567
|
Annotation annotation = Annotation.NewInstance("Name status: " + statusString, AnnotationType.EDITORIAL(), Language.ENGLISH());
|
568
|
name.addAnnotation(annotation);
|
569
|
}
|
570
|
}
|
571
|
|
572
|
//remarks
|
573
|
String remarks = valueMap.get(REMARKS);
|
574
|
if (remarks != null){
|
575
|
Annotation annotation = Annotation.NewInstance(remarks, AnnotationType.EDITORIAL(), Language.ENGLISH());
|
576
|
name.addAnnotation(annotation);
|
577
|
}
|
578
|
|
579
|
//basionym
|
580
|
if (config.isDoBasionyms() && valueMap.get(BASIONYM)!= null){
|
581
|
TaxonName basionym = TaxonNameFactory.NewBotanicalInstance(null);
|
582
|
basionym.setTitleCache(valueMap.get(BASIONYM), true);
|
583
|
name.addBasionym(basionym);
|
584
|
}
|
585
|
|
586
|
//replaced synonym
|
587
|
if (config.isDoBasionyms() && valueMap.get(REPLACED_SYNONYM)!= null){
|
588
|
TaxonName replacedSynoynm = TaxonNameFactory.NewBotanicalInstance(null);
|
589
|
replacedSynoynm.setTitleCache(valueMap.get(REPLACED_SYNONYM), true);
|
590
|
name.addReplacedSynonym(replacedSynoynm, null, null, null);
|
591
|
}
|
592
|
|
593
|
//type information
|
594
|
if (config.isDoType() && valueMap.get(COLLECTION_DATE_AS_TEXT)!= null || valueMap.get(COLLECTION_NUMBER) != null
|
595
|
|| valueMap.get(COLLECTION_DAY1) != null || valueMap.get(COLLECTION_DAY2) != null
|
596
|
|| valueMap.get(COLLECTION_MONTH1) != null || valueMap.get(COLLECTION_MONTH2) != null
|
597
|
|| valueMap.get(COLLECTION_YEAR1) != null || valueMap.get(COLLECTION_YEAR2) != null
|
598
|
|| valueMap.get(COLLECTOR_TEAM_AS_TEXT) != null || valueMap.get(LOCALITY)!= null
|
599
|
|| valueMap.get(LATITUDE_DEGREES) != null || valueMap.get(LATITUDE_MINUTES) != null
|
600
|
|| valueMap.get(LATITUDE_SECONDS) != null || valueMap.get(NORTH_OR_SOUTH) != null
|
601
|
|| valueMap.get(COLLECTION_YEAR1) != null || valueMap.get(COLLECTION_YEAR2) != null
|
602
|
//TODO TBC
|
603
|
){
|
604
|
DerivedUnitFacade specimen = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
605
|
|
606
|
|
607
|
//gathering period
|
608
|
String collectionDateAsText = valueMap.get(COLLECTION_DATE_AS_TEXT);
|
609
|
TimePeriod gatheringPeriod = TimePeriodParser.parseString(collectionDateAsText);
|
610
|
|
611
|
try {
|
612
|
gatheringPeriod.setStartDay(getIntegerDateValueOrNull(valueMap, COLLECTION_DAY1));
|
613
|
gatheringPeriod.setStartMonth(getIntegerDateValueOrNull(valueMap, COLLECTION_MONTH1));
|
614
|
gatheringPeriod.setStartYear(getIntegerDateValueOrNull(valueMap, COLLECTION_YEAR1));
|
615
|
gatheringPeriod.setEndDay(getIntegerDateValueOrNull(valueMap, COLLECTION_DAY2));
|
616
|
gatheringPeriod.setEndMonth(getIntegerDateValueOrNull(valueMap, COLLECTION_MONTH2));
|
617
|
gatheringPeriod.setEndYear(getIntegerDateValueOrNull(valueMap, COLLECTION_YEAR2));
|
618
|
} catch (IndexOutOfBoundsException e) {
|
619
|
logger.info("Exception occurred when trying to fill gathering period");
|
620
|
}
|
621
|
specimen.setGatheringPeriod(gatheringPeriod);
|
622
|
|
623
|
specimen.setFieldNumber(valueMap.get(COLLECTION_NUMBER));
|
624
|
|
625
|
//collector team
|
626
|
String team = valueMap.get(COLLECTOR_TEAM_AS_TEXT);
|
627
|
if (team != null){
|
628
|
Team collectorTeam = Team.NewTitledInstance(team, team);
|
629
|
specimen.setCollector(collectorTeam);
|
630
|
}
|
631
|
|
632
|
specimen.setLocality(valueMap.get(LOCALITY));
|
633
|
|
634
|
try {
|
635
|
String latDegrees = CdmUtils.Nz(valueMap.get(LATITUDE_DEGREES));
|
636
|
String latMinutes = CdmUtils.Nz(valueMap.get(LATITUDE_MINUTES));
|
637
|
String latSeconds = CdmUtils.Nz(valueMap.get(LATITUDE_SECONDS));
|
638
|
String direction = CdmUtils.Nz(valueMap.get(NORTH_OR_SOUTH));
|
639
|
String latitude = latDegrees + "°" + latMinutes + "'" + latSeconds + "\"" + direction;
|
640
|
|
641
|
String lonDegrees = CdmUtils.Nz(valueMap.get(LONGITUDE_DEGREES));
|
642
|
String lonMinutes = CdmUtils.Nz(valueMap.get(LONGITUDE_MINUTES));
|
643
|
String lonSeconds = CdmUtils.Nz(valueMap.get(LONGITUDE_SECONDS));
|
644
|
direction = CdmUtils.Nz(valueMap.get(EAST_OR_WEST));
|
645
|
String longitude = lonDegrees + "°" + lonMinutes + "'" + lonSeconds + "\"" + direction;
|
646
|
|
647
|
specimen.setExactLocationByParsing(longitude, latitude, null, null);
|
648
|
} catch (ParseException e) {
|
649
|
logger.info("Parsing exception occurred when trying to parse type exact location." + e.getMessage());
|
650
|
} catch (Exception e) {
|
651
|
logger.info("Exception occurred when trying to read type exact location." + e.getMessage());
|
652
|
}
|
653
|
|
654
|
|
655
|
//type annotation
|
656
|
if (valueMap.get(TYPE_REMARKS)!= null){
|
657
|
Annotation typeAnnotation = Annotation.NewInstance(valueMap.get(TYPE_REMARKS), AnnotationType.EDITORIAL(), Language.DEFAULT());
|
658
|
specimen.addAnnotation(typeAnnotation);
|
659
|
}
|
660
|
}
|
661
|
|
662
|
//TODO Type name
|
663
|
//TODO "Type locations" , eg. holotype CAT ,isotype CAT ,isotype FI
|
664
|
|
665
|
//TODO Geographic unit as text
|
666
|
|
667
|
|
668
|
//source
|
669
|
Reference citation = getIpniCitation(repository);
|
670
|
name.addSource(OriginalSourceType.Lineage, valueMap.get(ID), "Name", citation, valueMap.get(VERSION));
|
671
|
|
672
|
|
673
|
// //TODO
|
674
|
//SHORT Family, Infra family, Hybrid genus, Hybrid, Collation, Nomenclatural synonym, Distribution, Citation type
|
675
|
/* EXTENDED
|
676
|
* Species author,
|
677
|
* Standardised basionym author flag,
|
678
|
* Standardised publishing author flag
|
679
|
Full name
|
680
|
Full name without family
|
681
|
Full name without authors
|
682
|
|
683
|
Reference
|
684
|
Standardised publication flag
|
685
|
Publication year
|
686
|
publication year note
|
687
|
Publication year text
|
688
|
Volume
|
689
|
Start page
|
690
|
End page
|
691
|
Primary pagination
|
692
|
Secondary pagination
|
693
|
Reference remarks
|
694
|
Hybrid parents
|
695
|
Replaced synonym Author team
|
696
|
Other links
|
697
|
Same citation as
|
698
|
Bibliographic reference
|
699
|
Bibliographic type info
|
700
|
|
701
|
Original taxon name
|
702
|
Original taxon name author team
|
703
|
Original replaced synonym
|
704
|
Original replaced synonym author team
|
705
|
Original basionym
|
706
|
Original basionym author team
|
707
|
Original parent citation taxon name author team
|
708
|
Original taxon distribution
|
709
|
Original hybrid parentage
|
710
|
Original cited type
|
711
|
Original remarks
|
712
|
|
713
|
*/
|
714
|
return name;
|
715
|
}
|
716
|
|
717
|
private String datePatternStr = "([12][0789]\\d{2})\\s\\[([123]?\\d\\s[A-Z][a-z][a-z]\\s[1-2][0789]\\d{2})\\]";
|
718
|
private Pattern datePattern = Pattern.compile(datePatternStr);
|
719
|
|
720
|
/**
|
721
|
* Parses the full year string as a {@link TimePeriod}
|
722
|
* @param string
|
723
|
* @return
|
724
|
*/
|
725
|
private TimePeriod parsePublicationFullYear(String fullYearStr) {
|
726
|
TimePeriod result = null;
|
727
|
|
728
|
if (fullYearStr != null){
|
729
|
Matcher matcher = datePattern.matcher(fullYearStr);
|
730
|
if (matcher.matches()){
|
731
|
String yearStr = matcher.group(1);
|
732
|
Integer year = Integer.valueOf(yearStr);
|
733
|
String exactDate = matcher.group(2);
|
734
|
result = TimePeriodParser.parseString(exactDate);
|
735
|
if (!year.equals(result.getStartYear())){
|
736
|
logger.warn("Year and exact date year do not match");
|
737
|
result = TimePeriod.NewInstance(year);
|
738
|
result.setFreeText(fullYearStr);
|
739
|
}
|
740
|
}else{
|
741
|
result = TimePeriodParser.parseString(fullYearStr);
|
742
|
}
|
743
|
}
|
744
|
return result;
|
745
|
}
|
746
|
|
747
|
|
748
|
/**
|
749
|
* Fills the map where the key is the parameter name from the parameterMap and the value is the value from the split.
|
750
|
* @param parameterMap
|
751
|
* @param splits
|
752
|
* @param valueMap
|
753
|
*/
|
754
|
private Map<String, String> fillValueMap(Map<Integer, String> parameterMap, String[] splits) {
|
755
|
Map<String, String> result = new HashMap<>();
|
756
|
for (int i = 0; i < splits.length; i++){
|
757
|
String key = parameterMap.get(i);
|
758
|
String value = splits[i];
|
759
|
if (isNotBlank(value)){
|
760
|
result.put(key, value);
|
761
|
}
|
762
|
}
|
763
|
return result;
|
764
|
}
|
765
|
|
766
|
/**
|
767
|
* @param valueMap
|
768
|
* @return
|
769
|
*/
|
770
|
private Integer getIntegerDateValueOrNull(Map<String, String> valueMap, String key) {
|
771
|
try {
|
772
|
Integer result = Integer.valueOf(valueMap.get(key));
|
773
|
if (result == 0){
|
774
|
result = null;
|
775
|
}
|
776
|
return result;
|
777
|
} catch (NumberFormatException e) {
|
778
|
if (logger.isDebugEnabled()){
|
779
|
logger.debug("Number Format exception for " + valueMap.get(key));
|
780
|
}
|
781
|
return null;
|
782
|
}
|
783
|
}
|
784
|
|
785
|
|
786
|
private List<Person> buildAuthorList(InputStream content, ICdmRepository repository, IIpniServiceConfigurator iConfig) throws IOException {
|
787
|
IpniServiceAuthorConfigurator config = (IpniServiceAuthorConfigurator)iConfig;
|
788
|
List<Person> result = new ArrayList<>();
|
789
|
BufferedReader reader = new BufferedReader (new InputStreamReader(content));
|
790
|
|
791
|
String headerLine = reader.readLine();
|
792
|
if (headerLine != null){
|
793
|
Map<Integer, String> parameterMap = getParameterMap(headerLine);
|
794
|
|
795
|
String line = reader.readLine();
|
796
|
while (isNotBlank(line)){
|
797
|
Person author = getAuthorFromLine(line,parameterMap, repository, config);
|
798
|
result.add(author);
|
799
|
line = reader.readLine();
|
800
|
}
|
801
|
}
|
802
|
|
803
|
return result;
|
804
|
}
|
805
|
|
806
|
|
807
|
|
808
|
private Map<Integer, String> getParameterMap(String headerLine) {
|
809
|
Map<Integer, String> result = new HashMap<Integer, String>();
|
810
|
if ( headerLine != null ){
|
811
|
String[] splits = headerLine.split("%");
|
812
|
for (int i = 0; i < splits.length ; i ++){
|
813
|
result.put(i, splits[i]);
|
814
|
}
|
815
|
}
|
816
|
return result;
|
817
|
}
|
818
|
|
819
|
|
820
|
private Person getAuthorFromLine(String line, Map<Integer, String> categoryMap, ICdmRepository repository, IpniServiceAuthorConfigurator config) {
|
821
|
//Id%Version%Standard form%Default author forename%Default author surname%Taxon groups%Dates%Alternative names
|
822
|
String[] splits = line.split("%");
|
823
|
Map<String, String> valueMap = fillValueMap(categoryMap, splits);
|
824
|
|
825
|
Person person = Person.NewInstance();
|
826
|
|
827
|
person.setNomenclaturalTitle(valueMap.get(STANDARD_FORM));
|
828
|
person.setFirstname(valueMap.get(DEFAULT_AUTHOR_FORENAME));
|
829
|
person.setLastname(valueMap.get(DEFAULT_AUTHOR_SURNAME));
|
830
|
|
831
|
Reference citation = getIpniCitation(repository);
|
832
|
|
833
|
//id, version
|
834
|
person.addSource(OriginalSourceType.Lineage, valueMap.get(ID), "Author", citation, valueMap.get(VERSION));
|
835
|
|
836
|
//dates
|
837
|
TimePeriod lifespan = TimePeriodParser.parseString(valueMap.get(DATES));
|
838
|
person.setLifespan(lifespan);
|
839
|
|
840
|
//alternative_names
|
841
|
String alternativeNames = valueMap.get(ALTERNATIVE_NAMES);
|
842
|
if (isNotBlank(alternativeNames)){
|
843
|
String[] alternativeNameSplits = alternativeNames.split("%");
|
844
|
for (String alternativeName : alternativeNameSplits){
|
845
|
if (alternativeName.startsWith(">")){
|
846
|
alternativeName = alternativeName.substring(1);
|
847
|
}
|
848
|
Extension.NewInstance(person, alternativeName, ExtensionType.INFORMAL_CATEGORY());
|
849
|
}
|
850
|
}
|
851
|
|
852
|
//TODO taxonGroups
|
853
|
|
854
|
return person;
|
855
|
}
|
856
|
|
857
|
|
858
|
private Reference getIpniCitation(ICdmRepository appConfig) {
|
859
|
Reference ipniReference;
|
860
|
if (appConfig != null){
|
861
|
ipniReference = appConfig.getReferenceService().find(uuidIpni);
|
862
|
if (ipniReference == null){
|
863
|
ipniReference = getNewIpniReference();
|
864
|
ipniReference.setUuid(uuidIpni);
|
865
|
appConfig.getReferenceService().save(ipniReference);
|
866
|
}
|
867
|
}else{
|
868
|
ipniReference = getNewIpniReference();
|
869
|
}
|
870
|
return ipniReference;
|
871
|
}
|
872
|
|
873
|
/**
|
874
|
* @return
|
875
|
*/
|
876
|
private Reference getNewIpniReference() {
|
877
|
Reference ipniReference;
|
878
|
ipniReference = ReferenceFactory.newDatabase();
|
879
|
ipniReference.setTitle("The International Plant Names Index (IPNI)");
|
880
|
return ipniReference;
|
881
|
}
|
882
|
|
883
|
|
884
|
|
885
|
@Override
|
886
|
public List<IBotanicalName> getNamesAdvanced(String family, String genus, String species, String infraFamily,
|
887
|
String infraGenus, String infraSpecies, String authorAbbrev,
|
888
|
String publicationTitle,
|
889
|
Rank rankInRangeToReturn,
|
890
|
IpniServiceNamesConfigurator config,
|
891
|
ICdmRepository services){
|
892
|
IpniRank ipniRank = IpniRank.valueOf(rankInRangeToReturn);
|
893
|
return getNamesAdvanced(family, genus, species, infraFamily, infraGenus, infraSpecies, authorAbbrev, publicationTitle, ipniRank, config, services);
|
894
|
}
|
895
|
|
896
|
@Override
|
897
|
public List<IBotanicalName> getNamesAdvanced(String family, String genus, String species, String infraFamily,
|
898
|
String infraGenus, String infraSpecies, String authorAbbrev,
|
899
|
String publicationTitle,
|
900
|
IpniRank rankToReturn,
|
901
|
IpniServiceNamesConfigurator config,
|
902
|
ICdmRepository services) {
|
903
|
|
904
|
// find_rankToReturn=all&output_format=normal&find_sortByFamily=on&find_sortByFamily=off&query_type=by_query&back_page=plantsearch
|
905
|
|
906
|
//config
|
907
|
if (config == null){
|
908
|
config = new IpniServiceNamesConfigurator();
|
909
|
}
|
910
|
|
911
|
|
912
|
family = normalizeParameter(family);
|
913
|
genus = normalizeParameter(genus);
|
914
|
species = normalizeParameter(species);
|
915
|
infraFamily = normalizeParameter(infraFamily);
|
916
|
infraGenus = normalizeParameter(infraGenus);
|
917
|
infraSpecies = normalizeParameter(infraSpecies);
|
918
|
authorAbbrev = normalizeParameter(authorAbbrev);
|
919
|
|
920
|
publicationTitle = normalizeParameter(publicationTitle);
|
921
|
|
922
|
DelimitedFormat format = config.getFormat();
|
923
|
|
924
|
String request =
|
925
|
"find_family=" + family +
|
926
|
"&find_genus=" + genus +
|
927
|
"&find_species=" + species +
|
928
|
"&find_infrafamily=" + infraFamily +
|
929
|
"&find_infragenus=" + infraGenus +
|
930
|
"&find_infraspecies=" + infraSpecies +
|
931
|
"&find_authorAbbrev=" + authorAbbrev +
|
932
|
getBooleanParameter("&find_includePublicationAuthors=", config.isIncludePublicationAuthors(), "on", "off") +
|
933
|
getBooleanParameter("&find_includeBasionymAuthors=", config.isIncludeBasionymAuthors(), "on", "off") +
|
934
|
getBooleanParameter("&find_isAPNIRecord=", config.isDoApni(), "on", "false") +
|
935
|
getBooleanParameter("&find_isGCIRecord=", config.isDoGci(), "on", "false") +
|
936
|
getBooleanParameter("&find_isIKRecord=", config.isDoIk(), "on", "false") +
|
937
|
getBooleanParameter("&find_sortByFamily=", config.isSortByFamily(), "on", "off") +
|
938
|
(rankToReturn == null? "all" : rankToReturn.strRank)+
|
939
|
"&find_publicationTitle=" + publicationTitle +
|
940
|
"&output_format=" + format.parameter;
|
941
|
|
942
|
System.out.println(request);
|
943
|
return (List)queryService(request, services, getServiceUrl(IIpniService.ADVANCED_NAME_SERVICE_URL), config, ServiceType.NAME);
|
944
|
}
|
945
|
|
946
|
|
947
|
|
948
|
private String getBooleanParameter(String urlParamString, Boolean booleanParameter, String trueString, String falseString) {
|
949
|
String result;
|
950
|
if (booleanParameter == null){
|
951
|
result = getBooleanParameter(urlParamString, true, trueString, falseString) + getBooleanParameter(urlParamString, false, trueString, falseString);
|
952
|
}else if (booleanParameter == true){
|
953
|
result = urlParamString + trueString;
|
954
|
}else {
|
955
|
result = urlParamString + falseString;
|
956
|
}
|
957
|
return result;
|
958
|
}
|
959
|
|
960
|
|
961
|
@Override
|
962
|
public List<IBotanicalName> getNamesSimple(String wholeName, ICdmRepository repository,
|
963
|
IpniServiceNamesConfigurator config){
|
964
|
if (config == null){
|
965
|
config = new IpniServiceNamesConfigurator();
|
966
|
}
|
967
|
|
968
|
// query_type=by_query&back_page=query_ipni.html
|
969
|
|
970
|
wholeName = normalizeParameter(wholeName);
|
971
|
|
972
|
DelimitedFormat format = config.getFormat();
|
973
|
|
974
|
String request = "find_wholeName=" + wholeName +
|
975
|
"&output_format=" + format.parameter;
|
976
|
|
977
|
return (List)queryService(request, repository, getServiceUrl(IIpniService.SIMPLE_NAME_SERVICE_URL), config, ServiceType.NAME);
|
978
|
}
|
979
|
|
980
|
@Override
|
981
|
public List<Reference> getPublications(String title, String abbreviation, ICdmRepository services, IpniServicePublicationConfigurator config){
|
982
|
// http://www.uk.ipni.org/ipni/advPublicationSearch.do?find_title=Spe*plant*&find_abbreviation=&output_format=normal&query_type=by_query&back_page=publicationsearch
|
983
|
// http://www.uk.ipni.org/ipni/advPublicationSearch.do?find_title=*Hortus+Britannicus*&find_abbreviation=&output_format=delimited-classic&output_format=delimited
|
984
|
|
985
|
if (config == null){
|
986
|
config = new IpniServicePublicationConfigurator();
|
987
|
}
|
988
|
|
989
|
title = normalizeParameter(title);
|
990
|
abbreviation = normalizeParameter(abbreviation);
|
991
|
|
992
|
String request = "find_title=" + title +
|
993
|
"&find_abbreviation=" + abbreviation +
|
994
|
"&output_format=" + DelimitedFormat.CLASSIC.parameter;
|
995
|
|
996
|
List<Reference> result = (List)queryService(request, services, getServiceUrl(IIpniService.PUBLICATION_SERVICE_URL), config, ServiceType.PUBLICATION);
|
997
|
return result;
|
998
|
}
|
999
|
|
1000
|
|
1001
|
/**
|
1002
|
* The service url
|
1003
|
*
|
1004
|
* @return the serviceUrl
|
1005
|
*/
|
1006
|
@Override
|
1007
|
public URL getServiceUrl(String url) {
|
1008
|
URL serviceUrl;
|
1009
|
try {
|
1010
|
serviceUrl = new URL(url);
|
1011
|
} catch (MalformedURLException e) {
|
1012
|
throw new RuntimeException("This should not happen", e);
|
1013
|
}
|
1014
|
return serviceUrl;
|
1015
|
}
|
1016
|
|
1017
|
|
1018
|
@Override
|
1019
|
public InputStream getNamesById(String id) {
|
1020
|
String request = "id="+id + "&output_format=lsid-metadata";
|
1021
|
return queryServiceForID(request, getServiceUrl(IIpniService.ID_NAMESEARCH_SERVICE_URL));
|
1022
|
}
|
1023
|
|
1024
|
@Override
|
1025
|
public InputStream getPublicationsById(String id) {
|
1026
|
String request = "id="+id ;
|
1027
|
return queryServiceForID(request, getServiceUrl(IIpniService.ID_PUBLICATION_SERVICE_URL));
|
1028
|
}
|
1029
|
|
1030
|
|
1031
|
/**
|
1032
|
* @param parameter
|
1033
|
*/
|
1034
|
private String normalizeParameter(String parameter) {
|
1035
|
String result = CdmUtils.Nz(parameter).replace(" ", "+");
|
1036
|
return result;
|
1037
|
}
|
1038
|
|
1039
|
private String nomalizeRank(String string) {
|
1040
|
if (string == null){
|
1041
|
return null;
|
1042
|
}
|
1043
|
String result = string.replace("spec.", "sp.");
|
1044
|
return result;
|
1045
|
}
|
1046
|
|
1047
|
/**
|
1048
|
* @return
|
1049
|
*/
|
1050
|
private DelimitedFormat getDefaultFormat() {
|
1051
|
return DelimitedFormat.SHORT;
|
1052
|
}
|
1053
|
|
1054
|
private boolean isNotBlank(String line) {
|
1055
|
return StringUtils.isNotBlank(line);
|
1056
|
}
|
1057
|
|
1058
|
@NotNull
|
1059
|
private String Nz(String string) {
|
1060
|
return CdmUtils.Nz(string);
|
1061
|
}
|
1062
|
|
1063
|
|
1064
|
}
|