use of org.glassfish.jersey.examples.oauth2.googleclient.model.AllTaskListsModel in project jersey by jersey.
the class TaskResource method getTasksResponse.
/**
* Queries task data from google.
*
* @param client Client configured for authentication with access token.
* @return Google task data response or redirect to google authorize page response.
*/
private Response getTasksResponse(final Client client) {
client.register(JacksonFeature.class);
client.register(new LoggingFeature(Logger.getLogger("example.client.tasks"), LoggingFeature.Verbosity.PAYLOAD_ANY));
final WebTarget baseTarget = client.target(GOOGLE_TASKS_BASE_URI);
final Response response = baseTarget.path("users/@me/lists").request().get();
final List<TaskListModel> listOfTaskLists;
switch(response.getStatus()) {
case //Response.Status.UNAUTHORIZED
401:
SimpleOAuthService.setAccessToken(null);
return googleAuthRedirect();
case //Response.Status.OK
200:
listOfTaskLists = processTaskLists(baseTarget, response.readEntity(TaskRootBean.class));
break;
default:
listOfTaskLists = null;
}
final AllTaskListsModel tasks = new AllTaskListsModel(listOfTaskLists);
return Response.ok(tasks).build();
}
Aggregations