Skip to content

Commit

Permalink
Merge pull request #647 from PhenoApps/issue/640/brapi_v1_categories_bug
Browse files Browse the repository at this point in the history
fix for v1 brapi categories not importing correctly
  • Loading branch information
trife authored Jul 10, 2023
2 parents 4637c78 + 3ae0c25 commit 4655d9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ dependencies {
implementation 'com.github.breeding-insight:brapi:2.0.3'
implementation("com.squareup.okhttp3:okhttp:4.9.3")
implementation("com.squareup.okhttp3:logging-interceptor:4.9.3")
implementation("io.gsonfire:gson-fire:1.8.4") //required v1

implementation 'org.jsoup:jsoup:1.8.1'
implementation 'net.sourceforge.jexcelapi:jxl:2.6.10'
Expand Down
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 Expand Up @@ -1006,6 +1016,7 @@ private String buildCategoryList(List<String> categories) {
c.setValue(value);
c.setLabel(value);
}
scale.add(c);
}
return CategoryJsonUtil.Companion.encode(scale);
} catch (Exception e) {
Expand Down

0 comments on commit 4655d9a

Please sign in to comment.