Skip to content

Commit

Permalink
ZooniverseClient: requestMoreItemsSync(): Take a groupID parameter
Browse files Browse the repository at this point in the history
So that the caller must specify it instead of that knowledge being
inside the client. This is in preparation for when we retreive the
workflow IDs (like group IDs) based on the project ID.
  • Loading branch information
murraycu committed Jan 10, 2019
1 parent 42eed17 commit 877d33e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void testMoreItems() throws IOException, InterruptedException, Zooniverse
final ZooniverseClient client = createZooniverseClient(server);

final int COUNT = 10;
final List<ZooniverseClient.Subject> subjects = client.requestMoreItemsSync(COUNT);
final List<ZooniverseClient.Subject> subjects = client.requestMoreItemsSync(TEST_GROUP_ID, COUNT);
assertNotNull(subjects);
assertEquals(COUNT, subjects.size());

Expand Down Expand Up @@ -290,7 +290,7 @@ public void testMoreItemsWithBadResponseContent() throws IOException {

//Mostly we want to check that it doesn't crash on a bad HTTP response.
try {
final List<ZooniverseClient.Subject> subjects = client.requestMoreItemsSync(5);
final List<ZooniverseClient.Subject> subjects = client.requestMoreItemsSync(TEST_GROUP_ID, 5);
assertTrue((subjects == null) || (subjects.isEmpty()));
} catch (final ZooniverseClient.RequestMoreItemsException e) {
/* We don't care about the actual cause.
Expand Down Expand Up @@ -320,7 +320,7 @@ public void testMoreItemsWithBadResponseCode() throws IOException {
//Mostly we want to check that it doesn't crash on a bad HTTP response.

try {
final List<ZooniverseClient.Subject> subjects = client.requestMoreItemsSync(5);
final List<ZooniverseClient.Subject> subjects = client.requestMoreItemsSync(TEST_GROUP_ID, 5);
assertTrue((subjects == null) || (subjects.isEmpty()));
} catch (final ZooniverseClient.RequestMoreItemsException e) {
assertNotNull(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testMoreItems() throws IOException, ZooniverseClient.RequestMoreItem
// Do this enough times that we are very likely to excercise all groups:
final int count = Config.SUBJECT_GROUPS.size() * 5;
for (int i = 0; i < count; ++i) {
final List<ZooniverseClient.Subject> subjects = client.requestMoreItemsSync(1);
final List<ZooniverseClient.Subject> subjects = client.requestMoreItemsSync(Config.SUBJECT_GROUP_ID_GAMA_15,1);
assertNotNull(subjects);
assertTrue(subjects.size() == 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,8 @@ selection, prependToArray(selectionArgs, uriParts.itemId),
for(int i = 0; i < 3; i++) {
List<ZooniverseClient.Subject> subjects = null;
try {
subjects = mZooniverseClient.requestMoreItemsSync(1);
final String groupId = mZooniverseClient.getGroupIdForNextQuery();
subjects = mZooniverseClient.requestMoreItemsSync(groupId, 1);
} catch (final HttpUtils.NoNetworkException e) {
//Return the empty cursor,
//and let the caller guess at the cause.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static Gson createGson() {
*
* @return
*/
private static String getGroupIdForNextQuery() {
public static String getGroupIdForNextQuery() {

//Get a list of only the groups that should be used for new queries.
//TODO: Avoid doing this each time?
Expand Down Expand Up @@ -155,7 +155,7 @@ public LoginUtils.LoginResult loginSync(final String username, final String pass
* @param count
* @return
*/
public List<Subject> requestMoreItemsSync(int count) throws RequestMoreItemsException {
public List<Subject> requestMoreItemsSync(final String groupId, int count) throws RequestMoreItemsException {
throwIfNoNetwork();

//Avoid suddenly doing too much network and disk IO
Expand All @@ -167,7 +167,7 @@ public List<Subject> requestMoreItemsSync(int count) throws RequestMoreItemsExce
Response<SubjectsResponse> response = null;

try {
final Call<SubjectsResponse> call = callGetSubjects(count);
final Call<SubjectsResponse> call = callGetSubjects(groupId, count);
response = call.execute();
} catch (final IOException e) {
Log.error("requestMoreItemsSync(): request failed.", e);
Expand Down Expand Up @@ -286,12 +286,12 @@ public List<Workflow> requestWorkflowSync(final String workflowId) throws Reques
return result;
}

public void requestMoreItemsAsync(final int count, final Callback<SubjectsResponse> callback) {
public void requestMoreItemsAsync(final String groupId, final int count, final Callback<SubjectsResponse> callback) {
throwIfNoNetwork();

Log.info("requestMoreItemsAsync(): count=" + count);

final Call<SubjectsResponse> call = callGetSubjects(count);
final Call<SubjectsResponse> call = callGetSubjects(groupId, count);
call.enqueue(callback);
}

Expand All @@ -302,8 +302,8 @@ public void requestWorkflowAsync(final String workflowId, final Callback<Workflo
call.enqueue(callback);
}

private Call<SubjectsResponse> callGetSubjects(final int count) {
return mRetrofitService.getSubjects(getGroupIdForNextQuery(), count);
private Call<SubjectsResponse> callGetSubjects(final String groupId, final int count) {
return mRetrofitService.getSubjects(groupId, count);
}

private Call<ProjectsResponse> callGetProject(final String projectSlug) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private void doRegularTasks() {
//Do the download first, to avoid the UI having to wait for new subjects to classify.


downloadMinimumSubjectsAsync();
downloadMinimumSubjectsAsync(ZooniverseClient.getGroupIdForNextQuery());
downloadMissingImages();

//Do less urgent things next:
Expand Down Expand Up @@ -164,17 +164,17 @@ private ContentResolver getContentResolver() {
*
* @return Return true if we know for sure that no further downloading is currently necessary.
*/
private boolean downloadMinimumSubjectsAsync() {
private boolean downloadMinimumSubjectsAsync(final String groupId) {
final int missing = getNotDoneNeededForCache();
if (missing > 0) {
requestMoreItemsAsync(missing);
requestMoreItemsAsync(groupId, missing);
return false;
} else {
return true; //Tell the caller that no action was necessary.
}
}

private void requestMoreItemsAsync(final int count) {
private void requestMoreItemsAsync(final String groupId, final int count) {
if(mRequestMoreItemsTaskInProgress) {
//Do just one of these at a time,
//to avoid requesting more while we are processing the results from a first one.
Expand All @@ -188,7 +188,7 @@ private void requestMoreItemsAsync(final int count) {
mRequestMoreItemsTaskInProgress = true;

try {
mClient.requestMoreItemsAsync(count,
mClient.requestMoreItemsAsync(groupId, count,
new Callback<ZooniverseClient.SubjectsResponse>() {
@Override
public void onResponse(final Call<ZooniverseClient.SubjectsResponse> call, final retrofit2.Response<ZooniverseClient.SubjectsResponse> response) {
Expand Down

0 comments on commit 877d33e

Please sign in to comment.