Project

General

Profile

Download (16.2 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.remote.dto.occurrencecatalogue;
2

    
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Set;
6

    
7
import org.apache.commons.lang.StringUtils;
8
import org.apache.log4j.Logger;
9

    
10
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
11
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
12
import eu.etaxonomy.cdm.model.common.TimePeriod;
13
import eu.etaxonomy.cdm.model.location.Point;
14
import eu.etaxonomy.cdm.model.media.Rights;
15
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
16
import eu.etaxonomy.cdm.remote.controller.BaseListController;
17
import eu.etaxonomy.cdm.remote.dto.common.RemoteResponse;
18

    
19
/**
20
 * The class representing the response from the CDM Remote Web Service API to a single UUID search query.
21
 * All information contained in this class originates from a call to {@link SpecimenOrObservationBase}
22
 * <P>
23
 *
24
 * @author p.kelbert
25
 * @since march 10 2014
26
 */
27
public class OccurrenceSearch implements RemoteResponse {
28

    
29
    private OccurrenceSearchRequest request;
30
    private final List<OccurrenceSearchResponse> response;
31

    
32
    public static final Logger logger = Logger.getLogger(BaseListController.class);
33

    
34
    public OccurrenceSearch() {
35
    	this.response = new ArrayList<OccurrenceSearchResponse>();
36
    }
37

    
38
    public void setRequest(String q) {
39
        request = new OccurrenceSearchRequest();
40
        request.setQuery(q);
41
    }
42

    
43
    public OccurrenceSearchRequest getRequest() {
44
        return this.request;
45
    }
46

    
47
    public class OccurrenceSearchRequest {
48
        private String taxonUuid;
49
        public OccurrenceSearchRequest() {
50
            this.taxonUuid = "";
51
        }
52

    
53
        public void setQuery(String q) {
54
            this.taxonUuid = q;
55
        }
56

    
57
        public String getQuery() {
58
            return this.taxonUuid;
59
        }
60
    }
61

    
62
    public void addToResponse(String acceptedTaxon,
63
    		String acceptedTaxonUuid,
64
    		DerivedUnitFacade duf) {
65

    
66
    	OccurrenceSearch.OccurrenceSearchResponse osr =
67
    			new OccurrenceSearch.OccurrenceSearchResponse();
68

    
69
    	osr.setAcceptedTaxon(acceptedTaxon);
70
    	osr.setAcceptedTaxonUuid(acceptedTaxonUuid);
71

    
72
    	if(duf.getCollector() != null) {
73
    		osr.setCollector(duf.getCollector().getTitleCache());
74
    	}
75
    	if(duf.getCollection() != null) {
76
    		osr.setCollection(duf.getCollection().getName());
77
    		if(duf.getCollection().getInstitute() != null) {
78
    			osr.setInstitution(duf.getCollection().getInstitute().getName());
79
    		}
80
    	}
81

    
82
    	osr.setFieldNotes(duf.getFieldNotes());
83
    	if(duf.getType() != null) {
84
    		osr.setType(duf.getType().name());
85
    	}
86
    	osr.setUnitCount(duf.getIndividualCount());
87

    
88
    	if(duf.getDerivedUnitKindOfUnit() != null) {
89
    		osr.setKindOfUnit(duf.getDerivedUnitKindOfUnit().getLabel());
90
    	}
91

    
92
    	osr.setElevation(duf.getAbsoluteElevation());
93
    	osr.setMaxElevation(duf.getAbsoluteElevationMaximum());
94

    
95
    	osr.setDepth(duf.getDistanceToGround());
96
    	osr.setMaxDepth(duf.getDistanceToGroundMax());
97

    
98
    	if(duf.getGatheringPeriod() != null) {
99
    		TimePeriod tp = duf.getGatheringPeriod();
100
    		if(tp.getStart() != null) {
101
    			osr.setStartGatheringDate(tp.getStart().toString());
102
    		}
103
    		if(tp.getEnd() != null) {
104
    			osr.setEndGatheringDate(tp.getEnd().toString());
105
    		}
106
    	}
107

    
108

    
109
    	OccurrenceSearch.OccurrenceSearchResponse.Location loc =
110
    			osr.getLocation();
111

    
112
    	Point exactLocation = duf.getExactLocation();
113
    	if(exactLocation != null) {
114
    		loc.setDecimalLatitude(exactLocation.getLatitude());
115
    		loc.setDecimalLongitude(exactLocation.getLongitude());
116
    		loc.setErrorRadius(exactLocation.getErrorRadius());
117
    		if(exactLocation.getReferenceSystem() != null) {
118
    			loc.setReferenceSystem(exactLocation.getReferenceSystem().getTitleCache());
119
    		}
120

    
121
    	}
122
    	if(duf.getCountry() != null) {
123
    		loc.setCountry(duf.getCountry().getTitleCache());
124
    	}
125

    
126
    	if(duf.getLocality() != null) {
127
    		loc.setLocality(duf.getLocality().getText());
128
    	}
129

    
130
    	osr.setFieldNumber(duf.getFieldNumber());
131
    	osr.setAccessionNumber(duf.getAccessionNumber());
132
    	osr.setCatalogNumber(duf.getCatalogNumber());
133

    
134
    	Set<IdentifiableSource> sources = duf.getSources();
135
    	boolean dateFound = false;
136
    	String datePublishedString = null;
137
    	List<String> sourceTitleList = new ArrayList<String>();
138
    	for (IdentifiableSource source:sources) {
139
    		String citation = source.getCitation().getTitleCache();
140

    
141
    		datePublishedString = source.getCitation().getDatePublishedString();
142
    		if (!dateFound && !StringUtils.isEmpty(datePublishedString)){
143
    			osr.setPublicationDate(datePublishedString);
144
    			dateFound=true;
145
    		}
146
    		String  micro = source.getCitationMicroReference();
147

    
148
    		if(citation == null) {
149
    			citation = "";
150
    		}
151
    		if(micro == null) {
152
    			micro = "";
153
    		}
154
    		sourceTitleList.add(citation + " " + micro);
155
    	}
156
    	osr.setSources(sourceTitleList);
157

    
158
    	osr.setPublicationDate(datePublishedString);
159

    
160
    	List<String> rightsTextList = new ArrayList<String>();
161
    	Set<Rights> rightsSet = duf.innerDerivedUnit().getRights();
162
    	for(Rights rights : rightsSet) {
163
    		if(rights.getAbbreviatedText() != null) {
164
    			rightsTextList.add(rights.getAbbreviatedText());
165
    		}
166
    	}
167
    	osr.setRights(rightsTextList);
168
    	response.add(osr);
169
    }
170

    
171
    public List<OccurrenceSearchResponse> getResponse() {
172
        return this.response;
173
    }
174

    
175

    
176
    public OccurrenceSearchResponse createResponse(DerivedUnitFacade duFacade) {
177
    	OccurrenceSearch.OccurrenceSearchResponse osResponse =
178
    			new OccurrenceSearch.OccurrenceSearchResponse();
179

    
180
    	return osResponse;
181
    }
182

    
183
    public class OccurrenceSearchResponse {
184

    
185
        private String acceptedTaxon;
186
        private String acceptedTaxonUuid;
187

    
188
        private String collector;
189
        private String collection;
190
        private String institution;
191

    
192
        private String fieldNotes;
193

    
194
        //
195
        private String type;
196
        private String unitCount;
197
        private String kindOfUnit;
198

    
199
        //ELEVATION
200
        private Object elevation;
201
        private Object maxElevation;
202

    
203
        //DEPTH
204
        private Object depth;
205
        private Object maxDepth;
206

    
207
        private String startGatherinDate;
208
        private String endGatheringDate;
209

    
210
        private Location location;
211

    
212
        private String fieldNumber;
213
        private String accessionNumber;
214
        private String catalogNumber;
215
        private String barcode;
216
        private String publicationDate;
217

    
218

    
219
		private List<String> rights;
220
        private List<String> sources;
221

    
222
        //FIXME: Ignoring the fields below for the moment
223
        //       Will come back to them when requested and
224
        //       when the model allows it properly
225

    
226
//      private String citation;
227

    
228
        public OccurrenceSearchResponse() {
229
        	location = new Location();
230
        	rights = new ArrayList<String>();
231
        	sources = new ArrayList<String>();
232

    
233
        }
234

    
235
        /**
236
         * @return the specimenOrObservationType
237
         */
238
        public String getType() {
239
            return type;
240
        }
241

    
242
        /**
243
         * @param specimenOrObservationType the specimenOrObservationType to set
244
         */
245
        public void setType(String type) {
246
            this.type = type;
247
        }
248

    
249
        /**
250
         * @return the acceptedTaxon
251
         */
252
        public String getAcceptedTaxon() {
253
            return acceptedTaxon;
254
        }
255

    
256
        /**
257
         * @param acceptedTaxon the acceptedTaxon to set
258
         */
259
        public void setAcceptedTaxon(String acceptedTaxon) {
260
            if (acceptedTaxon !=null) {
261
                this.acceptedTaxon = acceptedTaxon.split(" sec.")[0];
262
            } else {
263
                this.acceptedTaxon = acceptedTaxon;
264
            }
265
        }
266

    
267

    
268
        /**
269
         * @return the collector
270
         */
271
        public String getCollector() {
272
            return collector;
273
        }
274

    
275
        /**
276
         * @param collector the collector to set
277
         */
278
        public void setCollector(String collector) {
279
            this.collector = collector;
280
        }
281

    
282

    
283
        /**
284
         * @param acceptedTaxonUuid the acceptedTaxonUuid to set
285
         */
286
        public void setAcceptedTaxonUuid(String acceptedTaxonUuid) {
287
            this.acceptedTaxonUuid = acceptedTaxonUuid;
288
        }
289

    
290

    
291
        /**
292
         * @return the nameUuid
293
         */
294
        public String getAcceptedTaxonUuid() {
295
            return acceptedTaxonUuid;
296
        }
297

    
298

    
299
        /**
300
         * @return the accessionNumber
301
         */
302

    
303
        public String getAccessionNumber() {
304
            return accessionNumber;
305
        }
306

    
307
        /**
308
         * @param accessionNumber the accessionNumber to set
309
         */
310

    
311
        public void setAccessionNumber(String accessionNumber) {
312
            this.accessionNumber = accessionNumber;
313
        }
314

    
315
        /**
316
         * @return the catalogNumber
317
         */
318
        public String getCatalogNumber() {
319
            return catalogNumber;
320
        }
321

    
322
        /**
323
         * @param catalogNumber the catalogNumber to set
324
         */
325
        public void setCatalogNumber(String catalogNumber) {
326
            this.catalogNumber = catalogNumber;
327
        }
328

    
329
        /**
330
         * @return the fieldNumber
331
         */
332
        public String getFieldNumber() {
333
            return fieldNumber;
334
        }
335

    
336
        /**
337
         * @param fieldNumber the fieldNumber to set
338
         */
339
        public void setFieldNumber(String fieldNumber) {
340
            this.fieldNumber = fieldNumber;
341
        }
342

    
343
        /**
344
         * @return the minElevation
345
         */
346
        public Object getElevation() {
347
            return elevation;
348
        }
349

    
350
        /**
351
         * @param minElevation the minElevation to set
352
         */
353
        public void setElevation(Integer elevation) {
354
            this.elevation = elevation;
355
        }
356

    
357
        /**
358
         * @return the maxElevation
359
         */
360
        public Object getMaxElevation() {
361
            return maxElevation;
362
        }
363

    
364
        /**
365
         * @param maxElevation the maxElevation to set
366
         */
367
        public void setMaxElevation(Integer maxElevation) {
368
            this.maxElevation = maxElevation;
369
        }
370

    
371
        /**
372
         * @return the dateBegin
373
         */
374
        public String getStartGatheringDate() {
375
            return startGatherinDate;
376
        }
377

    
378
        /**
379
         * @param dateBegin the dateBegin to set
380
         */
381
        public void setStartGatheringDate(String dateBegin) {
382
            this.startGatherinDate = dateBegin;
383
        }
384

    
385
        /**
386
         * @return the dateEnd
387
         */
388
        public String getEndGatheringDate() {
389
            return endGatheringDate;
390
        }
391

    
392
        /**
393
         * @param dateEnd the dateEnd to set
394
         */
395
        public void setEndGatheringDate(String dateEnd) {
396
            this.endGatheringDate = dateEnd;
397
        }
398

    
399
        /**
400
         * @return the unitCount
401
         */
402
        public String getUnitCount() {
403
            return unitCount;
404
        }
405

    
406
        /**
407
         * @param unitCount the unitCount to set
408
         */
409
        public void setUnitCount(String unitCount) {
410
            this.unitCount = unitCount;
411
        }
412

    
413
        /**
414
         * @return the barcode
415
         */
416
        public String getBarcode() {
417
            return barcode;
418
        }
419

    
420
        /**
421
         * @param barcode the barcode to set
422
         */
423
        public void setBarcode(String barcode) {
424
            this.barcode = barcode;
425
        }
426

    
427

    
428
		public String getPublicationDate() {
429
			return publicationDate;
430
		}
431

    
432
		public void setPublicationDate(String publicationDate) {
433
			this.publicationDate = publicationDate;
434
		}
435

    
436
        /**
437
         * @return the kindOfUnit
438
         */
439
        public String getKindOfUnit() {
440
            return kindOfUnit;
441
        }
442

    
443
        /**
444
         * @param kindOfUnit the kindOfUnit to set
445
         */
446
        public void setKindOfUnit(String kindOfUnit) {
447
            this.kindOfUnit = kindOfUnit;
448
        }
449

    
450
        /**
451
         * @return the sources
452
         */
453
        public List<String> getSources() {
454
            return sources;
455
        }
456

    
457
        /**
458
         * @param sources the sources to set
459
         */
460
        public void setSources(List<String> sources) {
461
            this.sources = sources;
462
        }
463

    
464
        /**
465
         * @return the collection
466
         */
467
        public String getCollection() {
468
            return collection;
469
        }
470

    
471
        /**
472
         * @param collection the collection to set
473
         */
474
        public void setCollection(String collection) {
475
            this.collection = collection;
476
        }
477

    
478
        /**
479
         * @return the institution
480
         */
481
        public String getInstitution() {
482
            return institution;
483
        }
484

    
485
        /**
486
         * @param institution the institution to set
487
         */
488
        public void setInstitution(String institution) {
489
            this.institution = institution;
490
        }
491

    
492
        /**
493
         * @return the depth
494
         */
495
        public Object getDepth() {
496
            return depth;
497
        }
498

    
499
        /**
500
         * @param depth the depth to set
501
         */
502
        public void setDepth(Double depth) {
503
            this.depth = depth;
504
        }
505

    
506
        /**
507
         * @return the maxDepth
508
         */
509
        public Object getMaxDepth() {
510
            return maxDepth;
511
        }
512

    
513
        /**
514
         * @param maxDepth the maxDepth to set
515
         */
516
        public void setMaxDepth(Double maxDepth) {
517
            this.maxDepth = maxDepth;
518
        }
519

    
520
        /**
521
         * @return the fieldNotes
522
         */
523
        public String getFieldNotes() {
524
            return fieldNotes;
525
        }
526

    
527
        /**
528
         * @param fieldNotes the fieldNotes to set
529
         */
530
        public void setFieldNotes(String fieldNotes) {
531
            this.fieldNotes = fieldNotes;
532
        }
533

    
534
//        /**
535
//         * @return the dataResourceCitation
536
//         */
537
//        public String getCitation() {
538
//            return citation;
539
//        }
540
//
541
//        /**
542
//         * @param dataResourceCitation the dataResourceCitation to set
543
//         */
544
//        public void setCitation(String citation) {
545
//            this.citation = citation;
546
//        }
547

    
548
        /**
549
         * @return the dataResourceRights
550
         */
551
        public List<String> getRights() {
552
            return rights;
553
        }
554

    
555
        /**
556
         * @param dataResourceRights the dataResourceRights to set
557
         */
558
        public void setRights(List<String> rights) {
559
            this.rights = rights;
560
        }
561

    
562
        public Location getLocation() {
563
			return location;
564
		}
565

    
566
		public void setLocation(Location location) {
567
			this.location = location;
568
		}
569

    
570
        public class Location {
571
        	private Object decimalLatitude;
572
			private Object decimalLongitude;
573
        	private Object errorRadius;
574
        	private String country;
575
        	private String locality;
576
        	private String referenceSystem;
577

    
578
        	public Object getDecimalLatitude() {
579
				return decimalLatitude;
580
			}
581
			public void setDecimalLatitude(Double decimalLatitude) {
582
				this.decimalLatitude = decimalLatitude;
583
			}
584
			public Object getDecimalLongitude() {
585
				return decimalLongitude;
586
			}
587
			public void setDecimalLongitude(Double decimalLongitude) {
588
				this.decimalLongitude = decimalLongitude;
589
			}
590
			public Object getErrorRadius() {
591
				return errorRadius;
592
			}
593
			public void setErrorRadius(Integer errorRadius) {
594
				this.errorRadius = errorRadius;
595
			}
596
			public String getCountry() {
597
				return country;
598
			}
599
			public void setCountry(String country) {
600
				this.country = country;
601
			}
602
			public String getLocality() {
603
				return locality;
604
			}
605
			public void setLocality(String locality) {
606
				this.locality = locality;
607
			}
608
			public String getReferenceSystem() {
609
				return referenceSystem;
610
			}
611
			public void setReferenceSystem(String referenceSystem) {
612
				this.referenceSystem = referenceSystem;
613
			}
614

    
615
        }
616

    
617
    }
618

    
619
}
    (1-1/1)