use of org.glassfish.jersey.examples.oauth2.googleclient.model.TaskListModel 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();
}
use of org.glassfish.jersey.examples.oauth2.googleclient.model.TaskListModel in project jersey by jersey.
the class TaskResource method processTaskLists.
/**
* Process users task lists and read task details. Collect just
* @param baseTarget base JAX-RS client target with oauth context configured
* @param taskRootBean root task bean to be processed
* @return Detailed list of non-completed tasks or {@code null} if there is no task list available.
*/
private List<TaskListModel> processTaskLists(final WebTarget baseTarget, final TaskRootBean taskRootBean) {
final List<TaskListModel> listOfTaskLists = new ArrayList<>();
for (final TaskListBean taskListBean : taskRootBean.getItems()) {
final List<TaskModel> taskList = new ArrayList<>();
final WebTarget listTarget = baseTarget.path("lists/{tasklist}/tasks").resolveTemplate("tasklist", taskListBean.getId());
final TaskListBean fullTaskListBean = listTarget.request().get(TaskListBean.class);
for (final TaskBean taskBean : fullTaskListBean.getTasks()) {
if (taskBean.getCompleted() == null) {
taskList.add(new TaskModel(taskBean.getTitle()));
}
}
listOfTaskLists.add(new TaskListModel(taskListBean.getTitle(), taskList.size() > 0 ? taskList : null));
}
return listOfTaskLists.size() > 0 ? listOfTaskLists : null;
}
Aggregations