Skip to content

Commit 74eeb66

Browse files
authored
Merge pull request #1294 from WildMeOrg/occurrence-legacy-fields-gs
add Occurrence legacy fields (from GiraffeSpotter) to bulk-import
2 parents 3d7ca98 + 470bef0 commit 74eeb66

File tree

4 files changed

+220
-18
lines changed

4 files changed

+220
-18
lines changed

src/main/java/org/ecocean/Occurrence.java

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ public class Occurrence extends Base implements java.io.Serializable {
115115

116116
private Long dateTimeLong; // this is for searching
117117

118+
// Start legacy GiraffeSpotter fields
119+
private String vegetation;
120+
private String terrain;
121+
private String monitoringZone;
122+
private Integer groupSize;
123+
private Integer numAdultMales;
124+
private Integer numAdultFemales;
125+
private Integer numSubMales;
126+
private Integer numSubFemales;
127+
private Integer numSubAdults;
128+
private Integer wp; // i think this is waypoint???
129+
// End legacy GiraffeSpotter fields
130+
118131
// empty constructor used by the JDO enhancer
119132
public Occurrence() {}
120133

@@ -1537,4 +1550,87 @@ public void run() {
15371550
return
15381551
"SELECT \"OCCURRENCEID\", CAST(COALESCE(EXTRACT(EPOCH FROM CAST(\"MODIFIED\" AS TIMESTAMP))*1000,-1) AS BIGINT) AS version FROM \"OCCURRENCE\" ORDER BY version";
15391552
}
1553+
1554+
/*LEGACY GiraffeSpotter Customizations*/
1555+
public Integer getNumAdultMales() {
1556+
return this.numAdultMales;
1557+
}
1558+
1559+
public void setNumAdultMales(Integer s) {
1560+
this.numAdultMales = s;
1561+
}
1562+
1563+
public Integer getNumAdultFemales() {
1564+
return this.numAdultFemales;
1565+
}
1566+
1567+
public void setNumAdultFemales(Integer s) {
1568+
this.numAdultFemales = s;
1569+
}
1570+
1571+
public Integer getNumSubMales() {
1572+
return this.numSubMales;
1573+
}
1574+
1575+
public void setNumSubMales(Integer s) {
1576+
this.numSubMales = s;
1577+
}
1578+
1579+
public Integer getNumSubFemales() {
1580+
return this.numSubFemales;
1581+
}
1582+
1583+
public void setNumSubFemales(Integer s) {
1584+
this.numSubFemales = s;
1585+
}
1586+
1587+
public Integer getNumSubAdults() {
1588+
return this.numSubAdults;
1589+
}
1590+
1591+
public void setNumSubAdults(Integer s) {
1592+
this.numSubAdults = s;
1593+
}
1594+
1595+
public String getVegetation() {
1596+
return this.vegetation;
1597+
}
1598+
1599+
public void setVegetation(String h) {
1600+
this.vegetation = h;
1601+
}
1602+
1603+
public String getTerrain() {
1604+
return this.terrain;
1605+
}
1606+
1607+
public void setTerrain(String h) {
1608+
this.terrain = h;
1609+
}
1610+
1611+
public String getMonitoringZone() {
1612+
return this.monitoringZone;
1613+
}
1614+
1615+
public void setMonitoringZone(String h) {
1616+
this.monitoringZone = h;
1617+
}
1618+
1619+
public Integer getWp() {
1620+
return this.wp;
1621+
}
1622+
1623+
public void setWp(Integer s) {
1624+
this.wp = s;
1625+
}
1626+
1627+
public Integer getGroupSize() {
1628+
return this.groupSize;
1629+
}
1630+
1631+
public void setGroupSize(Integer s) {
1632+
this.groupSize = s;
1633+
}
1634+
1635+
/*LEGACY GiraffeSpotter Customizations*/
15401636
}

src/main/java/org/ecocean/api/bulk/BulkImporter.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,46 @@ private void processRow(List<BulkValidator> fields) {
603603
}
604604
break;
605605

606+
case "Sighting.vegetation":
607+
occ.setVegetation(bv.getValueString());
608+
break;
609+
610+
case "Sighting.terrain":
611+
occ.setTerrain(bv.getValueString());
612+
break;
613+
614+
case "Sighting.monitoringZone":
615+
occ.setMonitoringZone(bv.getValueString());
616+
break;
617+
618+
case "Sighting.groupSize":
619+
occ.setGroupSize(bv.getValueInteger());
620+
break;
621+
622+
case "Sighting.numAdultMales":
623+
occ.setNumAdultMales(bv.getValueInteger());
624+
break;
625+
626+
case "Sighting.numAdultFemales":
627+
occ.setNumAdultFemales(bv.getValueInteger());
628+
break;
629+
630+
case "Sighting.numSubMales":
631+
occ.setNumSubMales(bv.getValueInteger());
632+
break;
633+
634+
case "Sighting.numSubFemales":
635+
occ.setNumSubFemales(bv.getValueInteger());
636+
break;
637+
638+
case "Sighting.numSubAdults":
639+
occ.setNumSubAdults(bv.getValueInteger());
640+
break;
641+
642+
case "Sighting.wp":
643+
occ.setWp(bv.getValueInteger());
644+
break;
645+
606646
case "Survey.comments":
607647
if (!bv.valueIsNull() &&
608648
((occ.getComments() == null) ||

src/main/java/org/ecocean/api/bulk/BulkValidator.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ public class BulkValidator {
4343
"Sighting.groupComposition", "Sighting.hour", "Sighting.humanActivityNearby",
4444
"Sighting.individualCount", "Sighting.initialCue", "Sighting.maxGroupSizeEstimate",
4545
"Sighting.millis", "Sighting.minGroupSizeEstimate", "Sighting.minutes", "Sighting.month",
46-
"Sighting.numAdults", "Sighting.numCalves", "Sighting.numJuveniles", "Sighting.observer",
47-
"Sighting.sightingID", "Sighting.seaState", "Sighting.groupSize", "Sighting.numSubAdults",
48-
"Sighting.numAdultMales", "Sighting.numAdultFemales", "Sighting.numSubFemales",
49-
"Sighting.numSubMales", "Sighting.seaSurfaceTemp", "Sighting.seaSurfaceTemperature",
50-
"Sighting.swellHeight", "Sighting.terrain", "Sighting.transectBearing",
51-
"Sighting.transectName", "Sighting.vegetation", "Sighting.visibilityIndex", "Sighting.year",
46+
"Sighting.monitoringZone", "Sighting.numAdults", "Sighting.numCalves",
47+
"Sighting.numJuveniles", "Sighting.observer", "Sighting.sightingID", "Sighting.seaState",
48+
"Sighting.groupSize", "Sighting.numSubAdults", "Sighting.numAdultMales",
49+
"Sighting.numAdultFemales", "Sighting.numSubFemales", "Sighting.numSubMales",
50+
"Sighting.seaSurfaceTemp", "Sighting.seaSurfaceTemperature", "Sighting.swellHeight",
51+
"Sighting.terrain", "Sighting.transectBearing", "Sighting.transectName",
52+
"Sighting.vegetation", "Sighting.visibilityIndex", "Sighting.wp", "Sighting.year",
5253
"SatelliteTag.serialNumber", "SexAnalysis.processingLabTaskID", "SexAnalysis.sex",
5354
"SocialUnit.socialUnitName", "Survey.comments", "Survey.id", "Survey.type", "Survey.vessel",
5455
"SurveyTrack.vesselID", "TissueSample.sampleID", "TissueSample.tissueType"));
@@ -69,24 +70,25 @@ public class BulkValidator {
6970
// validated, but just accepted as-is and set on appropriate object
7071
public static final Set<String> MINIMAL_FIELD_NAMES_STRING = new HashSet<>(Arrays.asList(
7172
"Encounter.alternateID", "Encounter.distinguishingScar", "Encounter.groupRole",
72-
"Encounter.individualID", "Encounter.sightingID", "Encounter.sightingRemarks",
73-
"Encounter.otherCatalogNumbers", "Encounter.patterningCode", "Encounter.submitterName",
74-
"Encounter.submitterOrganization", "MarkedIndividual.name", "MarkedIndividual.nickname",
75-
"MarkedIndividual.nickName", "Membership.role", "MicrosatelliteMarkersAnalysis.alleleNames",
76-
"MicrosatelliteMarkersAnalysis.analysisID", "MitochondrialDNAAnalysis.haplotype",
77-
"Sighting.comments", "Sighting.fieldStudySite", "Sighting.groupBehavior",
78-
"Sighting.groupComposition", "Sighting.humanActivityNearby", "Sighting.initialCue",
79-
"Sighting.observer", "Sighting.sightingID", "Sighting.terrain", "Sighting.transectName",
80-
"Sighting.vegetation", "SatelliteTag.serialNumber", "SexAnalysis.processingLabTaskID",
81-
"SocialUnit.socialUnitName", "Survey.comments", "Survey.id", "Survey.type",
82-
"SurveyTrack.vesselID", "Survey.vessel", "TissueSample.tissueType"));
73+
"Encounter.identificationRemarks", "Encounter.individualID", "Encounter.sightingID",
74+
"Encounter.sightingRemarks", "Encounter.otherCatalogNumbers", "Encounter.patterningCode",
75+
"Encounter.submitterName", "Encounter.submitterOrganization", "MarkedIndividual.name",
76+
"MarkedIndividual.nickname", "MarkedIndividual.nickName", "Membership.role",
77+
"MicrosatelliteMarkersAnalysis.alleleNames", "MicrosatelliteMarkersAnalysis.analysisID",
78+
"MitochondrialDNAAnalysis.haplotype", "Sighting.comments", "Sighting.fieldStudySite",
79+
"Sighting.groupBehavior", "Sighting.groupComposition", "Sighting.humanActivityNearby",
80+
"Sighting.initialCue", "Sighting.monitoringZone", "Sighting.observer",
81+
"Sighting.sightingID", "Sighting.terrain", "Sighting.transectName", "Sighting.vegetation",
82+
"SatelliteTag.serialNumber", "SexAnalysis.processingLabTaskID", "SocialUnit.socialUnitName",
83+
"Survey.comments", "Survey.id", "Survey.type", "SurveyTrack.vesselID", "Survey.vessel",
84+
"TissueSample.tissueType"));
8385
public static final Set<String> MINIMAL_FIELD_NAMES_INT = new HashSet<>(Arrays.asList(
8486
"Sighting.fieldSurveyCode", "Sighting.groupSize", "Sighting.individualCount",
8587
"Sighting.maxGroupSizeEstimate", "Sighting.minGroupSizeEstimate",
8688
"Sighting.numAdultFemales", "Sighting.numAdultMales", "Sighting.numAdults",
8789
"Sighting.numCalves", "Sighting.numJuveniles", "Sighting.numSubAdults",
8890
"Sighting.numSubFemales", "Sighting.numSubMales", "Sighting.seaState",
89-
"Sighting.visibilityIndex"));
91+
"Sighting.visibilityIndex", "Sighting.wp"));
9092
public static final Set<String> MINIMAL_FIELD_NAMES_DOUBLE = new HashSet<>(Arrays.asList(
9193
"Encounter.depth", "Encounter.elevation", "Sighting.bearing",
9294
"Sighting.bestGroupSizeEstimate", "Sighting.distance", "Sighting.effortCode",

src/test/java/org/ecocean/api/bulk/BulkApiPostTest.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,4 +640,68 @@ private boolean hasError(JSONObject rtnJson, int rowNumber, String fieldName) {
640640
}
641641
}
642642

643+
@Test void apiPostValidAdditionalFields()
644+
throws ServletException, IOException {
645+
User user = mock(User.class);
646+
Occurrence occ = new Occurrence();
647+
String requestBody = getValidPayloadArrays();
648+
649+
// addToRows() only affects row[0] so lets kill the rest
650+
JSONObject tmpObj = new JSONObject(requestBody);
651+
JSONArray tmpArr = new JSONArray();
652+
653+
tmpArr.put(tmpObj.getJSONArray("rows").getJSONArray(0));
654+
tmpObj.put("rows", tmpArr);
655+
requestBody = tmpObj.toString();
656+
657+
// now we alter our only row
658+
requestBody = addToRows(requestBody, "Sighting.vegetation", "vegetation-test");
659+
requestBody = addToRows(requestBody, "Sighting.terrain", "terrain-test");
660+
requestBody = addToRows(requestBody, "Sighting.monitoringZone", "monitoringZone-test");
661+
requestBody = addToRows(requestBody, "Sighting.groupSize", 1);
662+
requestBody = addToRows(requestBody, "Sighting.numAdultMales", 2);
663+
requestBody = addToRows(requestBody, "Sighting.numAdultFemales", 3);
664+
requestBody = addToRows(requestBody, "Sighting.numSubMales", 4);
665+
requestBody = addToRows(requestBody, "Sighting.numSubFemales", 5);
666+
requestBody = addToRows(requestBody, "Sighting.numSubAdults", 6);
667+
requestBody = addToRows(requestBody, "Sighting.wp", 7);
668+
669+
when(mockRequest.getRequestURI()).thenReturn("/api/v3/bulk-import");
670+
when(mockRequest.getReader()).thenReturn(new BufferedReader(new StringReader(requestBody)));
671+
672+
try (MockedConstruction<Shepherd> mockShepherd = mockConstruction(Shepherd.class,
673+
(mock, context) -> {
674+
when(mock.getUser(any(HttpServletRequest.class))).thenReturn(user);
675+
when(mock.getUser(any(String.class))).thenReturn(user);
676+
when(mock.isValidTaxonomyName(any(String.class))).thenReturn(true);
677+
when(mock.getOrCreateOccurrence(any(String.class))).thenReturn(occ);
678+
when(mock.getOrCreateOccurrence(null)).thenReturn(occ);
679+
})) {
680+
try (MockedStatic<UploadedFiles> mockUF = mockStatic(UploadedFiles.class)) {
681+
mockUF.when(() -> UploadedFiles.findFiles(any(HttpServletRequest.class),
682+
any(String.class))).thenReturn(emptyFiles);
683+
try (MockedStatic<ShepherdPMF> mockService = mockStatic(ShepherdPMF.class)) {
684+
mockService.when(() -> ShepherdPMF.getPMF(any(String.class))).thenReturn(
685+
mockPMF);
686+
apiServlet.doPost(mockRequest, mockResponse);
687+
responseOut.flush();
688+
JSONObject jout = new JSONObject(responseOut.toString());
689+
verify(mockResponse).setStatus(200);
690+
assertTrue(jout.getBoolean("success"));
691+
assertEquals(jout.getJSONArray("encounters").length(), 1);
692+
assertEquals(jout.getJSONArray("sightings").length(), 1);
693+
assertEquals(occ.getVegetation(), "vegetation-test");
694+
assertEquals(occ.getTerrain(), "terrain-test");
695+
assertEquals(occ.getMonitoringZone(), "monitoringZone-test");
696+
assertTrue(occ.getGroupSize() == 1);
697+
assertTrue(occ.getNumAdultMales() == 2);
698+
assertTrue(occ.getNumAdultFemales() == 3);
699+
assertTrue(occ.getNumSubMales() == 4);
700+
assertTrue(occ.getNumSubFemales() == 5);
701+
assertTrue(occ.getNumSubAdults() == 6);
702+
assertTrue(occ.getWp() == 7);
703+
}
704+
}
705+
}
706+
}
643707
}

0 commit comments

Comments
 (0)