Skip to content

Commit

Permalink
fixed Npe for obs. levels in v1 get studies call
Browse files Browse the repository at this point in the history
  • Loading branch information
chaneylc committed Jun 29, 2023
1 parent 3b08443 commit 3ae0c25
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,23 @@ public void getPlotDetails(final String studyDbId,
final Function<BrapiStudyDetails, Void> function,
final Function<Integer, Void> failFunction) {
try {

//level is not a required field, so passing null here is fine
//otherwise this was causing a NPE when observationLevel was null
//check if observationLevel is null
@Nullable
String levelName = null;
if (observationLevel != null) {

if (observationLevel.getObservationLevelName() != null) {

levelName = observationLevel.getObservationLevelName();

}
}

final String level = levelName;

final AtomicInteger currentPage = new AtomicInteger(0);
final Integer pageSize = Integer.parseInt(context.getSharedPreferences(GeneralKeys.SHARED_PREF_FILE_NAME, 0)
.getString(GeneralKeys.BRAPI_PAGE_SIZE, "50"));
Expand Down Expand Up @@ -481,13 +498,6 @@ public void onSuccess(ObservationUnitsResponse1 response, int i, Map<String, Lis
}else {
try {

//level is not a required field, so passing null here is fine
//otherwise this was causing a NPE when observationLevel was null
@Nullable String level = null;
if (observationLevel != null) {
level = observationLevel.getObservationLevelName();
}

studiesApi.studiesStudyDbIdObservationunitsGetAsync(
studyDbId, level, currentPage.get(), pageSize,
getBrapiToken(), this);
Expand All @@ -508,7 +518,7 @@ public void onFailure(ApiException error, int i, Map<String, List<String>> map)
};

studiesApi.studiesStudyDbIdObservationunitsGetAsync(
studyDbId, observationLevel.getObservationLevelName(), 0, pageSize,
studyDbId, level, 0, pageSize,
getBrapiToken(), callback);

} catch (ApiException e) {
Expand Down

0 comments on commit 3ae0c25

Please sign in to comment.