-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathEncounter.java
4633 lines (3993 loc) · 169 KB
/
Encounter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.ecocean;
import org.apache.commons.codec.digest.DigestUtils;
import java.io.*;
import java.lang.Math;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Vector;
import javax.jdo.Query;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import javax.servlet.http.HttpServletRequest;
import org.ecocean.genetics.*;
import org.ecocean.ia.IA;
import org.ecocean.identity.IBEISIA;
import org.ecocean.media.*;
import org.ecocean.security.Collaboration;
import org.ecocean.servlet.importer.ImportTask;
import org.ecocean.social.Membership;
import org.ecocean.social.SocialUnit;
import org.ecocean.tag.AcousticTag;
import org.ecocean.tag.DigitalArchiveTag;
import org.ecocean.tag.MetalTag;
import org.ecocean.tag.SatelliteTag;
import org.ecocean.Util.MeasurementDesc;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.datanucleus.api.rest.orgjson.JSONArray;
import org.datanucleus.api.rest.orgjson.JSONException;
import org.datanucleus.api.rest.orgjson.JSONObject;
/**
* An <code>encounter</code> object stores the complete data for a single sighting/capture report.
* <code>Encounters</code> are added to MarkedIndividual objects as multiple encounters are associated with known individuals.
* <p/>
*
* @author Jason Holmberg
* @version 2.0
*/
public class Encounter extends Base implements java.io.Serializable {
static final long serialVersionUID = -146404246317385604L;
public static final String STATE_MATCHING_ONLY = "matching_only";
@Override public String opensearchIndexName() { return "encounter"; }
// at least one frame/image (e.g. from YouTube detection) must have this confidence or encounter will be ignored
public static final double ENCOUNTER_AUTO_SOURCE_CONFIDENCE_CUTOFF = 0.7;
public static final String STATE_AUTO_SOURCED = "auto_sourced";
/**
* The following attributes are described in the Darwin Core quick reference at:
* http://rs.tdwg.org/dwc/terms/#dcterms:type
* <p/>
* Wherever possible, this class will be extended with Darwin Core attributes for greater adoption of the standard.
*/
private String sex = null;
private String locationID = null;
private Double maximumDepthInMeters;
private Double maximumElevationInMeters;
private String catalogNumber = "";
// private String individualID;
private MarkedIndividual individual;
private int day = 0;
private int month = -1;
private int year = 0;
private Double decimalLatitude;
private Double decimalLongitude;
private Double endDecimalLatitude;
private Double endDecimalLongitude;
private String verbatimLocality;
private String occurrenceRemarks = "";
private String modified;
private String occurrenceID;
private String recordedBy;
private String otherCatalogNumbers;
private String behavior;
private String eventID;
private String measurementUnit;
private String verbatimEventDate;
private String dynamicProperties;
public String identificationRemarks = "";
public String genus = "";
public String specificEpithet;
public String lifeStage;
public String country;
public String zebraClass = ""; // via lewa: lactating female, territorial male, etc etc
// fields from Dan's sample csv
private String imageSet;
private String soil;
private String reproductiveStage;
private Double bodyCondition;
private Double parasiteLoad;
private Double immunoglobin;
private Boolean sampleTakenForDiet;
private Boolean injured;
private ArrayList<Observation> observations = new ArrayList<Observation>();
public String getSoil() { return soil; }
public void setSoil(String soil) { this.soil = soil; }
public String getReproductiveStage() { return reproductiveStage; }
public void setReproductiveStage(String reproductiveStage) {
this.reproductiveStage = reproductiveStage;
}
public Double getBodyCondition() { return bodyCondition; }
public void setBodyCondition(Double bodyCondition) { this.bodyCondition = bodyCondition; }
public Double getParasiteLoad() { return parasiteLoad; }
public void setParasiteLoad(Double parasiteLoad) { this.parasiteLoad = parasiteLoad; }
public Double getImmunoglobin() { return immunoglobin; }
public void setImmunoglobin(Double immunoglobin) { this.immunoglobin = immunoglobin; }
public Boolean getSampleTakenForDiet() { return sampleTakenForDiet; }
public void setSampleTakenForDiet(Boolean sampleTakenForDiet) {
this.sampleTakenForDiet = sampleTakenForDiet;
}
public Boolean getInjured() { return injured; }
public void setInjured(Boolean injured) { this.injured = injured; }
// for searchability
private String imageNames;
private List<User> submitters;
private List<User> photographers;
private List<User> informOthers;
private static HashMap<String, ArrayList<Encounter> > _matchEncounterCache = new HashMap<String,
ArrayList<Encounter> >();
/*
* The following fields are specific to this mark-recapture project and do not have an easy to map Darwin Core equivalent.
*/
// An URL to a thumbnail image representing the encounter.
private String dwcImageURL;
// Defines whether the sighting represents a living or deceased individual.
// Currently supported values are: "alive" and "dead".
private String livingStatus;
// observed age (if any) via IBEIS zebra projects
private Double age;
// Date the encounter was added to the library.
private String dwcDateAdded;
private Long dwcDateAddedLong;
// If Encounter spanned more than one day, date of release
private Date releaseDate;
private Long releaseDateLong;
// Size of the individual in meters
private Double size;
// Additional comments added by library users
private String researcherComments = "None";
// username of the logged in researcher assigned to the encounter
// this String is matched to an org.ecocean.User object to obtain more information
private String submitterID;
// name, email, phone, address of the encounter reporter
private String submitterEmail, submitterPhone, submitterAddress;
private String hashedSubmitterEmail;
private String hashedPhotographerEmail;
private String hashedInformOthers;
private String informothers;
// name, email, phone, address of the encounter photographer
private String photographerName, photographerEmail, photographerPhone, photographerAddress;
// a Vector of Strings defining the relative path to each photo. The path is relative to the servlet base directory
public Vector additionalImageNames = new Vector();
// a Vector of Strings of email addresses to notify when this encounter is modified
private Vector interestedResearchers = new Vector();
// time metrics of the report
private int hour = 0;
private String minutes = "00";
private String state = "";
// the globally unique identifier (GUID) for this Encounter
private String guid;
private Long endDateInMilliseconds;
private Long dateInMilliseconds;
// describes how the shark was measured
private String size_guess = "none provided";
// String reported GPS values for lat and long of the encounter
private String gpsLongitude = "", gpsLatitude = "";
private String gpsEndLongitude = "", gpsEndLatitude = "";
// whether this encounter has been rejected and should be hidden from public display
// unidentifiable encounters generally contain some data worth saving but not enough for accurate photo-identification
// private boolean unidentifiable = false;
// whether this encounter has a left-side spot image extracted
// public boolean hasSpotImage = false;
// whether this encounter has a right-side spot image extracted
// public boolean hasRightSpotImage = false;
// whether this encounter has been approved for public display
// private boolean approved = true;
// integers of the latitude and longitude degrees
// private int lat=-1000, longitude=-1000;
// name of the stored file from which the left-side spots were extracted
public String spotImageFileName = "";
// name of the stored file from which the right-side spots were extracted
public String rightSpotImageFileName = "";
// string descriptor of the most obvious scar (if any) as reported by the original submitter
// we also use keywords to be more specific
public String distinguishingScar = "None";
// describes how this encounter was matched to an existing shark - by eye, by pattern recognition algorithm etc.
// DEPRECATING OLD DATA CONSTRUCT
// private int numSpotsLeft = 0;
// private int numSpotsRight = 0;
// SPOTS
// an array of the extracted left-side superSpots
// private superSpot[] spots;
private ArrayList<SuperSpot> spots;
// an array of the extracted right-side superSpots
// private superSpot[] rightSpots;
private ArrayList<SuperSpot> rightSpots;
// an array of the three extracted left-side superSpots used for the affine transform of the I3S algorithm
// private superSpot[] leftReferenceSpots;
private ArrayList<SuperSpot> leftReferenceSpots;
// an array of the three extracted right-side superSpots used for the affine transform of the I3S algorithm
// private superSpot[] rightReferenceSpots;
private ArrayList<SuperSpot> rightReferenceSpots;
// an open ended string that allows a type of patterning to be identified.
// as an example, see the use of color codes at splashcatalog.org, allowing pre-defined fluke patterning types
// to be used to help narrow the search for a marked individual
private String patterningCode;
// submitting organization and project further detail the scope of who submitted this project
private String submitterOrganization;
private String submitterProject;
private List<String> submitterResearchers;
// hold submittedData
// private List<DataCollectionEvent> collectedData;
private List<TissueSample> tissueSamples;
private List<SinglePhotoVideo> images;
// private ArrayList<MediaAsset> media;
private ArrayList<Annotation> annotations;
private List<Measurement> measurements;
private List<MetalTag> metalTags;
private AcousticTag acousticTag;
private SatelliteTag satelliteTag;
private DigitalArchiveTag digitalArchiveTag;
private Boolean mmaCompatible = false;
// Variables used in the Survey, SurveyTrack, Path, Location model
private String correspondingSurveyTrackID = null;
private String correspondingSurveyID = null;
// This is the eventual replacement for the old decimal lat lon and other location data.
private PointLocation pointLocation;
// This is the number used to cross reference with dates to find occurances. (Read Lab)
private String sightNo = "";
// This is what researchers eyeball is the individual's ID in the field
// it could be a name that only has meaning in the context of that day's work
// (not necessarily an individual name from the WB database)
private String fieldID;
// This is a standard 1-5 color scale used by cetacean researchers
private Integer flukeType;
// added by request for ASWN, this is the role an individual served in its occurrence
// (from a standard list like Escort Male)
private String groupRole;
// identifies the import/dataset this came from for data provenance
private String dataSource;
// start constructors
/**
* empty constructor required by the JDO Enhancer
*/
public Encounter() {}
public Encounter(boolean skipSetup) {
if (skipSetup) return;
this.catalogNumber = Util.generateUUID();
this.setDWCDateAdded();
this.setDWCDateLastModified();
this.resetDateInMilliseconds();
this.annotations = new ArrayList<Annotation>();
}
/**
* Use this constructor to add the minimum level of information for a new encounter The Vector <code>additionalImages</code> must be a Vector of
* Blob objects
*
* NOTE: technically this is DEPRECATED cuz, SinglePhotoVideos? really?
*/
public Encounter(int day, int month, int year, int hour, String minutes, String size_guess,
String location) {
if (images != null)
System.out.println(
"WARNING: danger! deprecated SinglePhotoVideo-based Encounter constructor used!");
this.verbatimLocality = location;
// this.recordedBy = submitterName;
// this.submitterEmail = submitterEmail;
// now we need to set the hashed form of the email addresses
// this.hashedSubmitterEmail = Encounter.getHashOfEmailString(submitterEmail);
this.images = images;
this.day = day;
this.month = month;
this.year = year;
this.hour = hour;
this.minutes = minutes;
this.size_guess = size_guess;
this.setDWCDateAdded();
this.setDWCDateLastModified();
this.resetDateInMilliseconds();
}
public Encounter(Annotation ann) {
this(new ArrayList<Annotation>(Arrays.asList(ann)));
}
public Encounter(ArrayList<Annotation> anns) {
this.catalogNumber = Util.generateUUID();
this.annotations = anns;
if (!this.annotationsAreEmpty()) {
this.setDateFromAssets();
this.setSpeciesFromAnnotations();
this.setLatLonFromAssets();
}
this.setDWCDateAdded();
this.setDWCDateLastModified();
this.resetDateInMilliseconds();
}
private boolean annotationsAreEmpty() {
return (this.annotations == null || this.annotations.size() == 0 ||
(this.annotations.size() == 1 && (this.annotations.get(0) == null)));
}
// space saver since we're about to use this hundreds of times
private boolean shouldReplace(String str1, String str2) {
return Util.shouldReplace(str1, str2);
}
// also returns true when str1 is a superstring of str2.
private boolean shouldReplaceSuperStr(String str1, String str2) {
return (shouldReplace(str1, str2) || (Util.stringExists(str1) && str1.contains(str2)));
}
public void mergeAndDelete(Encounter enc2, Shepherd myShepherd) {
mergeDataFrom(enc2);
MarkedIndividual ind = myShepherd.getMarkedIndividual(enc2);
if (ind != null) {
ind.removeEncounter(enc2);
ind.addEncounter(this); // duplicate-safe
}
Occurrence occ = myShepherd.getOccurrence(enc2);
if (occ != null) {
occ.removeEncounter(enc2);
occ.addEncounter(this); // duplicate-safe
}
// Remove it from an ImportTask if needed
ImportTask task = myShepherd.getImportTaskForEncounter(enc2.getCatalogNumber());
if (task != null) {
task.removeEncounter(enc2);
myShepherd.updateDBTransaction();
}
// Remove from Project if needed
List<Project> projects = myShepherd.getProjectsForEncounter(enc2);
if (projects != null && !projects.isEmpty()) {
for (Project project : projects) {
project.removeEncounter(enc2);
myShepherd.updateDBTransaction();
}
}
// remove tissue samples because of bogus foreign key constraint that prevents deletion
int numTissueSamples = 0;
if (enc2.getTissueSamples() != null) numTissueSamples = enc2.getTissueSamples().size();
for (int i = 0; i < numTissueSamples; i++) {
enc2.removeTissueSample(0);
}
this.addComments("<p>Merged in encounter " + enc2.getCatalogNumber() + ".");
myShepherd.throwAwayEncounter(enc2);
}
// copies otherEnc's data into thisEnc, not overwriting anything
public void mergeDataFrom(Encounter enc2) {
if (enc2.getIndividual() != null) setIndividual(enc2.getIndividual());
// simple string fields
if (shouldReplace(enc2.getSex(), getSex())) setSex(enc2.getSex());
if (shouldReplace(enc2.getLocationID(), getLocationID()))
setLocationID(enc2.getLocationID());
if (shouldReplace(enc2.getVerbatimLocality(), getVerbatimLocality()))
setVerbatimLocality(enc2.getVerbatimLocality());
if (shouldReplace(enc2.getOccurrenceID(), getOccurrenceID()))
setOccurrenceID(enc2.getOccurrenceID());
if (shouldReplace(enc2.getRecordedBy(), getRecordedBy()))
setRecordedBy(enc2.getRecordedBy());
if (shouldReplace(enc2.getEventID(), getEventID())) setEventID(enc2.getEventID());
if (shouldReplace(enc2.getGenus(), getGenus())) setGenus(enc2.getGenus());
if (shouldReplace(enc2.getSpecificEpithet(), getSpecificEpithet()))
setSpecificEpithet(enc2.getSpecificEpithet());
if (shouldReplace(enc2.getLifeStage(), getLifeStage())) setLifeStage(enc2.getLifeStage());
if (shouldReplace(enc2.getCountry(), getCountry())) setCountry(enc2.getCountry());
if (shouldReplace(enc2.getZebraClass(), getZebraClass()))
setZebraClass(enc2.getZebraClass());
if (shouldReplace(enc2.getSoil(), getSoil())) setSoil(enc2.getSoil());
if (shouldReplace(enc2.getReproductiveStage(), getReproductiveStage()))
setReproductiveStage(enc2.getReproductiveStage());
if (shouldReplace(enc2.getLivingStatus(), getLivingStatus()))
setLivingStatus(enc2.getLivingStatus());
if (shouldReplace(enc2.getSubmitterEmail(), getSubmitterEmail()))
setSubmitterEmail(enc2.getSubmitterEmail());
if (shouldReplace(enc2.getSubmitterPhone(), getSubmitterPhone()))
setSubmitterPhone(enc2.getSubmitterPhone());
if (shouldReplace(enc2.getSubmitterAddress(), getSubmitterAddress()))
setSubmitterAddress(enc2.getSubmitterAddress());
if (shouldReplace(enc2.getState(), getState())) setState(enc2.getState());
if (shouldReplace(enc2.getGPSLongitude(), getGPSLongitude()))
setGPSLongitude(enc2.getGPSLongitude());
if (shouldReplace(enc2.getGPSLatitude(), getGPSLatitude()))
setGPSLatitude(enc2.getGPSLatitude());
if (shouldReplace(enc2.getPatterningCode(), getPatterningCode()))
setPatterningCode(enc2.getPatterningCode());
if (shouldReplace(enc2.getSubmitterOrganization(), getSubmitterOrganization()))
setSubmitterOrganization(enc2.getSubmitterOrganization());
if (shouldReplace(enc2.getSubmitterProject(), getSubmitterProject()))
setSubmitterProject(enc2.getSubmitterProject());
if (shouldReplace(enc2.getFieldID(), getFieldID())) setFieldID(enc2.getFieldID());
if (shouldReplace(enc2.getGroupRole(), getGroupRole())) setGroupRole(enc2.getGroupRole());
// now string fields that might need to be combined rather than replaced
if (shouldReplaceSuperStr(enc2.getDynamicProperties(), getDynamicProperties())) {
setDynamicProperties(enc2.getDynamicProperties());
} else if (Util.stringExists(enc2.getDynamicProperties())) { // shouldn't replace, should combine
addDynamicProperties(enc2.getDynamicProperties());
}
if (shouldReplaceSuperStr(enc2.getOccurrenceRemarks(), getOccurrenceRemarks())) {
setOccurrenceRemarks(enc2.getOccurrenceRemarks());
} else if (Util.stringExists(enc2.getOccurrenceRemarks())) { // shouldn't replace, should combine
setOccurrenceRemarks(getOccurrenceRemarks() + " " + enc2.getOccurrenceRemarks());
}
// now combine list fields making sure not to add duplicate entries
setAnnotations(Util.combineArrayListsInPlace(getAnnotations(), enc2.getAnnotations()));
setObservationArrayList(Util.combineArrayListsInPlace(getObservationArrayList(),
enc2.getObservationArrayList()));
setSubmitterResearchers(Util.combineListsInPlace(getSubmitterResearchers(),
enc2.getSubmitterResearchers()));
// custom no-duplicate logic bc the same sampleID may have been added on both encounters, but this would create unique tissuesample objects
Set<String> sampleIDs = getTissueSampleIDs();
for (TissueSample samp : enc2.getTissueSamples()) {
if (!sampleIDs.contains(samp.getSampleID())) addTissueSample(samp);
}
setMeasurements(Util.combineListsInPlace(getMeasurements(), enc2.getMeasurements()));
setMetalTags(Util.combineListsInPlace(getMetalTags(), enc2.getMetalTags()));
// spot lists
setSpots(Util.combineArrayListsInPlace(getSpots(), enc2.getSpots()));
setRightSpots(Util.combineArrayListsInPlace(getRightSpots(), enc2.getRightSpots()));
setLeftReferenceSpots(Util.combineArrayListsInPlace(getLeftReferenceSpots(),
enc2.getLeftReferenceSpots()));
setRightReferenceSpots(Util.combineArrayListsInPlace(getRightReferenceSpots(),
enc2.getRightReferenceSpots()));
// tags
if (enc2.getAcousticTag() != null && getAcousticTag() == null)
setAcousticTag(enc2.getAcousticTag());
if (enc2.getSatelliteTag() != null && getSatelliteTag() == null)
setSatelliteTag(enc2.getSatelliteTag());
if (enc2.getDTag() != null && getDTag() == null) setDTag(enc2.getDTag());
// skip time stuff bc if the time is different we probably don't want to combine the encounters anyway.
}
public String getZebraClass() {
return zebraClass;
}
public void setZebraClass(String c) {
zebraClass = c;
}
public String getImageNames() {
return imageNames;
}
public void addImageName(String name) {
if (imageNames == null) imageNames = name;
else if (name != null) imageNames += (", " + name);
}
public String addAllImageNamesFromAnnots(boolean overwrite) {
if (overwrite) imageNames = null;
return addAllImageNamesFromAnnots();
}
public String addAllImageNamesFromAnnots() {
for (Annotation ann : getAnnotations()) {
for (Feature feat : ann.getFeatures()) {
try {
MediaAsset ma = feat.getMediaAsset();
addImageName(ma.getFilename());
} catch (Exception e) {
System.out.println("exception parsing image name from feature " + feat);
}
}
}
return imageNames;
}
/**
* Returns an array of all of the superSpots for this encounter.
*
* @return the array of superSpots, taken from the croppedImage, that make up the digital fingerprint for this encounter
*/
public ArrayList<SuperSpot> getSpots() {
// return HACKgetSpots();
return spots;
}
public ArrayList<SuperSpot> getRightSpots() {
// return HACKgetRightSpots();
return rightSpots;
}
/**
* Returns an array of all of the superSpots for this encounter.
*
* @return the array of superSpots, taken from the croppedImage, that make up the digital fingerprint for this encounter
*/
/* these have gone away! dont be setting spots on Encounter any more .... NOT SO FAST... we regress for whaleshark.org... */
public void setSpots(ArrayList<SuperSpot> newSpots) {
spots = newSpots;
}
public void setRightSpots(ArrayList<SuperSpot> newSpots) {
rightSpots = newSpots;
}
/**
* Removes any spot data
*/
public void removeSpots() {
spots = null;
}
public void removeRightSpots() {
rightSpots = null;
}
public Integer getFlukeType() { return this.flukeType; }
public void setFlukeType(Integer flukeType) { this.flukeType = flukeType; }
// this averages all the fluketypes
public void setFlukeTypeFromKeywords() {
int totalFlukeType = 0;
int numFlukes = 0;
for (Annotation ann : getAnnotations()) {
Integer thisFlukeType = getFlukeTypeFromAnnotation(ann);
if (thisFlukeType != null) {
totalFlukeType += thisFlukeType;
numFlukes++;
}
}
if (numFlukes == 0) return;
setFlukeType(totalFlukeType / numFlukes);
}
// assuming the list is of erroneously-duplicated encounters, returns the one we want to keep
public static Encounter chooseFromDupes(List<Encounter> encs) {
int maxAnns = -1;
int encWithMax = 0;
for (int i = 0; i < encs.size(); i++) {
Encounter enc = encs.get(i);
if (enc.numAnnotations() > maxAnns) {
maxAnns = enc.numAnnotations();
encWithMax = i;
}
}
return encs.get(encWithMax);
}
public static Integer getFlukeTypeFromAnnotation(Annotation ann) {
return getFlukeTypeFromAnnotation(ann, 5);
}
// int maxScore is used because some people store flukeType on a 5 point (most standard), some on a 9 point scale
public static Integer getFlukeTypeFromAnnotation(Annotation ann, int maxScore) {
MediaAsset ma = ann.getMediaAsset();
if (ma == null || !ma.hasKeywords()) return null;
String flukeTypeKwPrefix = "fluke" + maxScore + ":";
for (Keyword kw : ma.getKeywords()) {
String kwName = kw.getReadableName();
if (kwName.contains(flukeTypeKwPrefix)) {
String justScore = kwName.split(flukeTypeKwPrefix)[1];
try {
Integer score = Integer.parseInt(justScore);
if (score != null) return score;
} catch (NumberFormatException nfe) {
System.out.println("NFE on getFlukeTypeFromAnnotation! For ann " + ann +
" and kwPrefix " + flukeTypeKwPrefix);
}
}
}
return null;
}
// yes, there "should" be only one of each of these, but we be thorough!
public void removeLeftSpotMediaAssets(Shepherd myShepherd) {
ArrayList<MediaAsset> spotMAs = this.findAllMediaByLabel(myShepherd, "_spot");
for (MediaAsset ma : spotMAs) {
System.out.println("INFO: removeLeftSpotMediaAsset() detaching " + ma +
" from parent id=" + ma.getParentId());
ma.setParentId(null);
}
}
public void removeRightSpotMediaAssets(Shepherd myShepherd) {
ArrayList<MediaAsset> spotMAs = this.findAllMediaByLabel(myShepherd, "_spotRight");
for (MediaAsset ma : spotMAs) {
System.out.println("INFO: removeRightSpotMediaAsset() detaching " + ma +
" from parent id=" + ma.getParentId());
ma.setParentId(null);
}
}
public void nukeAllSpots() {
leftReferenceSpots = null;
rightReferenceSpots = null;
spots = null;
rightSpots = null;
}
/**
* Returns the number of spots in the cropped image stored for this encounter.
*
* @return the number of superSpots that make up the digital fingerprint for this encounter
*/
public int getNumSpots() {
return (spots == null) ? 0 : spots.size();
/*
ArrayList<SuperSpot> fakeSpots = HACKgetSpots();
if(fakeSpots!=null){return fakeSpots.size();}
else{return 0;}
*/
}
public int getNumRightSpots() {
return (rightSpots == null) ? 0 : rightSpots.size();
/*
ArrayList<SuperSpot> fakeRightSpots = HACKgetRightSpots();
if(fakeRightSpots!=null){return fakeRightSpots.size();}
else{return 0;}
*/
}
public boolean hasLeftSpotImage() {
return (this.getNumSpots() > 0);
}
public boolean hasRightSpotImage() {
return (this.getNumRightSpots() > 0);
}
/**
* Sets the recorded length of the shark for this encounter.
*/
public void setSize(Double mysize) {
if (mysize != null) { size = mysize; } else { size = null; }
}
/**
* Returns the recorded length of the shark for this encounter.
*
* @return the length of the shark
*/
public double getSize() {
return size.doubleValue();
}
public Double getSizeAsDouble() {
return size;
}
/**
* Sets the units of the recorded size and depth of the shark for this encounter. Acceptable entries are either "Feet" or "Meters"
*/
public void setMeasureUnits(String measure) {
measurementUnit = measure;
}
/**
* Returns the units of the recorded size and depth of the shark for this encounter.
*
* @return the units of measure used by the recorded of this encounter, either "feet" or "meters"
*/
public String getMeasureUnits() {
return measurementUnit;
}
public String getMeasurementUnit() {
return measurementUnit;
}
/**
* Returns the recorded location of this encounter.
*
* @return the location of this encounter
*/
public String getLocation() {
return verbatimLocality;
}
public void setLocation(String location) {
this.verbatimLocality = location;
}
/**
* Sets the recorded sex of the shark in this encounter. Acceptable values are "Male" or "Female"
*/
public void setSex(String thesex) {
if (thesex != null) { sex = thesex; } else { sex = null; }
}
/**
* Returns the recorded sex of the shark in this encounter.
*
* @return the sex of the shark, either "male" or "female"
*/
public String getSex() {
return sex;
}
/**
* Returns any submitted comments about scarring on the shark.
*
* @return any comments regarding observed scarring on the shark's body
*/
public boolean getMmaCompatible() {
if (mmaCompatible == null) return false;
return mmaCompatible;
}
public void setMmaCompatible(boolean b) {
mmaCompatible = b;
}
/**
* Returns Occurrence Remarks.
*
* @return Occurrence Remarks String
*/
@Override public String getComments() {
return occurrenceRemarks;
}
/**
* Sets the initially submitted comments about markings and additional details on the shark.
*
* @param newComments Occurrence remarks to set
*/
@Override public void setComments(String newComments) {
occurrenceRemarks = newComments;
}
/**
* Returns any comments added by researchers
*
* @return any comments added by authroized researchers
*/
public String getRComments() {
return researcherComments;
}
/**
* Adds additional comments about the encounter
*
* @param newComments any additional comments to be added to the encounter
*/
@Override public void addComments(String newComments) {
if ((researcherComments != null) && (!(researcherComments.equals("None")))) {
researcherComments += newComments;
} else {
researcherComments = newComments;
}
}
/**
* Returns the name of the person who submitted this encounter data.
*
* @return the name of the person who submitted this encounter to the database
*/
public String getSubmitterName() {
return recordedBy;
}
public void setSubmitterName(String newname) {
if (newname == null) {
recordedBy = null;
} else {
recordedBy = newname;
}
}
/**
* Returns the e-mail address of the person who submitted this encounter data
*
* @return the e-mail address of the person who submitted this encounter data
*/
public String getSubmitterEmail() {
return submitterEmail;
}
public void setSubmitterEmail(String newemail) {
if (newemail == null) {
submitterEmail = null;
this.hashedSubmitterEmail = null;
} else {
submitterEmail = newemail;
this.hashedSubmitterEmail = Encounter.getHashOfEmailString(newemail);
}
}
/**
* Returns the phone number of the person who submitted this encounter data.
*
* @return the phone number of the person who submitted this encounter data
*/
public String getSubmitterPhone() {
return submitterPhone;
}
/**
* Sets the phone number of the person who submitted this encounter data.
*/
public void setSubmitterPhone(String newphone) {
if (newphone == null) {
submitterPhone = null;
} else {
submitterPhone = newphone;
}
}
/**
* Returns the mailing address of the person who submitted this encounter data.
*
* @return the mailing address of the person who submitted this encounter data
*/
public String getSubmitterAddress() {
return submitterAddress;
}
/**
* Sets the mailing address of the person who submitted this encounter data.
*/
public void setSubmitterAddress(String address) {
if (address == null) {
submitterAddress = null;
} else {
submitterAddress = address;
}
}
/**
* Returns the name of the person who took the primaryImage this encounter.
*
* @return the name of the photographer who took the primary image for this encounter
*/
public String getPhotographerName() {
return photographerName;
}
/**
* Sets the name of the person who took the primaryImage this encounter.
*/
public void setPhotographerName(String name) {
if (name == null) {
photographerName = null;
} else {
photographerName = name;
}
}
/**
* Returns the e-mail address of the person who took the primaryImage this encounter.
*
* @return @return the e-mail address of the photographer who took the primary image for this encounter
*/
public String getPhotographerEmail() {
return photographerEmail;
}
/**
* Sets the e-mail address of the person who took the primaryImage this encounter.
*/
public void setPhotographerEmail(String email) {
if (email == null) {
photographerEmail = null;
this.hashedPhotographerEmail = null;
} else {
photographerEmail = email;
this.hashedPhotographerEmail = Encounter.getHashOfEmailString(email);
}
}
/**
* Returns the phone number of the person who took the primaryImage this encounter.
*
* @return the phone number of the photographer who took the primary image for this encounter
*/
public String getPhotographerPhone() {
return photographerPhone;
}
// this is a cruddy "solution" to .submitterName and .submitters existing simultaneously
public Set<String> getAllSubmitterIds(Shepherd myShepherd) {
Set<String> all = new HashSet<String>();
User owner = this.getSubmitterUser(myShepherd);
if (owner == null) {
all.add(this.submitterID);
all.add(this.submitterEmail);
} else {
all.add(owner.getUsername());
all.add(owner.getFullName());
all.add(owner.getId());
all.add(owner.getEmailAddress());
}
if (this.submitters != null)
for (User user : this.submitters) {
all.add(user.getUsername());
all.add(user.getFullName());
all.add(user.getId());
all.add(user.getEmailAddress());
}
all.remove(null);
all.remove("");
return all;
}
// similar to above
public Set<String> getAllPhotographerIds() {
Set<String> all = new HashSet<String>();
all.add(this.photographerName);
if (this.photographers != null)
for (User user : this.photographers) {