com.in28minutes.domain.TodoItem Java Examples

The following examples show how to use com.in28minutes.domain.TodoItem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpdateTodoServlet.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 6 votes vote down vote up
@Override
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	final String id = request.getParameter("todoId");

	try {
		long todoId = Long.parseLong(id);
		TodoItem todoItem = todoService.getTodoById(todoId);
		request.setAttribute("todo", todoItem);
		request.getRequestDispatcher(UPDATE_TODO_PAGE).forward(request,
				response);
	} catch (NumberFormatException e) {
		request.setAttribute(
				"error",
				MessageFormat.format(
						resourceBundle.getString("no.such.todo"), id));
		request.getRequestDispatcher(ERROR_PAGE).forward(request, response);
	}

}
 
Example #2
Source File: DeleteTodoServlet.java    From MavenIn28Minutes with MIT License 6 votes vote down vote up
@Override
protected void doPost(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	final String id = request.getParameter("todoId");
	try {
		long todoId = Long.parseLong(id);
		TodoItem todoItem = todoService.getTodoById(todoId);
		if (todoItem != null) {
			todoService.remove(todoItem);
			request.getRequestDispatcher("/todos").forward(request,
					response);
		} else {
			redirectToErrorPage(request, response, id);
		}
	} catch (NumberFormatException e) {
		redirectToErrorPage(request, response, id);
	}
}
 
Example #3
Source File: UpdateTodoServlet.java    From MavenIn28Minutes with MIT License 6 votes vote down vote up
@Override
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	final String id = request.getParameter("todoId");

	try {
		long todoId = Long.parseLong(id);
		TodoItem todoItem = todoService.getTodoById(todoId);
		request.setAttribute("todo", todoItem);
		request.getRequestDispatcher(UPDATE_TODO_PAGE).forward(request,
				response);
	} catch (NumberFormatException e) {
		request.setAttribute(
				"error",
				MessageFormat.format(
						resourceBundle.getString("no.such.todo"), id));
		request.getRequestDispatcher(ERROR_PAGE).forward(request, response);
	}

}
 
Example #4
Source File: TodoDataServiceImpl.java    From MavenIn28Minutes with MIT License 5 votes vote down vote up
public TodoItemList getTodoListByUserAndTitle(final long userId,
		final String title) {
	TypedQuery<TodoItem> query = entityManager.createNamedQuery(
			"findTodosByTitle", TodoItem.class);
	query.setParameter(1, userId);
	query.setParameter(2, "%" + title.toUpperCase() + "%");
	return new TodoItemList(query.getResultList());
}
 
Example #5
Source File: DeleteTodoServlet.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 5 votes vote down vote up
@Override
protected void doPost(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {
	final String id = request.getParameter("todoId");
	long todoId = Long.parseLong(id);
	TodoItem todoItem = todoService.getTodoById(todoId);
	if (todoItem != null) {
		todoService.remove(todoItem);
		request.getRequestDispatcher("/todos").forward(request, response);
	}
}
 
Example #6
Source File: TodoController.java    From SpringIn28Minutes with MIT License 5 votes vote down vote up
@RequestMapping(value = "/user/todos/new", method = RequestMethod.GET)
public String showCreateTodo(Model model) {
	model.addAttribute("today", new SimpleDateFormat(
			TodoListUtils.DATE_FORMAT).format(new Date()));
	model.addAttribute("todo", new TodoItem());
	return "todo/create";
}
 
Example #7
Source File: TodoController.java    From SpringIn28Minutes with MIT License 5 votes vote down vote up
@RequestMapping(value = "/user/todos/new", method = RequestMethod.POST)
public String createNewTodo(@ModelAttribute TodoItem todoItem) {
	final User user = sessionData.getUser();
	todoItem.setDone(false);
	todoItem.setUserId(user.getId());
	todoService.create(todoItem);
	return REDIRECT_TO_VIEW_TODOS_CONTROLLER;
}
 
Example #8
Source File: TodoDataServiceImpl.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 5 votes vote down vote up
public TodoItemList getTodoListByUserAndTitle(final long userId,
		final String title) {
	TypedQuery<TodoItem> query = entityManager.createNamedQuery(
			"findTodosByTitle", TodoItem.class);
	query.setParameter(1, userId);
	query.setParameter(2, "%" + title.toUpperCase() + "%");
	return new TodoItemList(query.getResultList());
}
 
Example #9
Source File: TodoController.java    From SpringIn28Minutes with MIT License 5 votes vote down vote up
@RequestMapping("/user/todos/{todoId}/update")
public String showUpdateTodo(@PathVariable long todoId, Model model) {
	LOGGER.info("Updating TODO");
	TodoItem todoItem = todoService.getTodoById(todoId);
	model.addAttribute("todo", todoItem);
	return "todo/update";
}
 
Example #10
Source File: TodoController.java    From SpringIn28Minutes with MIT License 5 votes vote down vote up
@RequestMapping(value = "/user/todos/{todoId}/delete", method = RequestMethod.POST)
public ModelAndView deleteTodo(@PathVariable long todoId) {

	TodoItem todoItem = todoService.getTodoById(todoId);
	if (todoItem == null) {
		String errorMessage = messageSource.getMessage("no.such.todo",
				new Object[] { todoId }, sessionData.getLocale());
		return redirectToErrorPageWithMessage(errorMessage);
	}

	todoService.remove(todoItem);

	return new ModelAndView(REDIRECT_TO_VIEW_TODOS_CONTROLLER);

}
 
Example #11
Source File: TodoDataServiceImpl.java    From SpringIn28Minutes with MIT License 5 votes vote down vote up
public TodoItemList getTodoListByUserAndTitle(final long userId,
		final String title) {
	TypedQuery<TodoItem> query = entityManager.createNamedQuery(
			"findTodosByTitle", TodoItem.class);
	query.setParameter(1, userId);
	query.setParameter(2, "%" + title.toUpperCase() + "%");
	return new TodoItemList(query.getResultList());
}
 
Example #12
Source File: TodoDataServiceImpl.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 4 votes vote down vote up
public void remove(final TodoItem todoItem) {
	TodoItem t = entityManager.find(TodoItem.class, todoItem.getId());
	entityManager.remove(t);
}
 
Example #13
Source File: CreateTodoServlet.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 4 votes vote down vote up
@Override
protected void doPost(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	HttpSession session = request.getSession();
	User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

	String title = request.getParameter("title");
	String dueDate = request.getParameter("dueDate");
	String priority = request.getParameter("priority");

	TodoItem todoItem = new TodoItem(user.getId(), title, false,
			Priority.valueOf(priority), new Date(dueDate));

	todoService.create(todoItem);

	request.getRequestDispatcher("/todos").forward(request, response);

}
 
Example #14
Source File: TodoServiceTest.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 4 votes vote down vote up
@Test
public void testGetTodoById() {
	TodoItem todoItem = todoService.getTodoById(1);
	assertNotNull(todoItem);
	assertEquals(1, todoItem.getId());
}
 
Example #15
Source File: UpdateTodoServlet.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 4 votes vote down vote up
@Override
protected void doPost(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	long todoId = Long.parseLong(request.getParameter("todoId"));

	TodoItem todoItem = todoService.getTodoById(todoId);

	todoItem.setTitle(request.getParameter("title"));
	todoItem.setDueDate(new Date(request.getParameter("dueDate")));
	todoItem.setDone(Boolean.valueOf(request.getParameter("status")));
	todoItem.setPriority(Priority.valueOf(request.getParameter("priority")));

	todoService.update(todoItem);

	request.getRequestDispatcher("/todos").forward(request, response);

}
 
Example #16
Source File: TodoDataServiceImpl.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 4 votes vote down vote up
public TodoItem getTodoById(final long id) {
	return entityManager.find(TodoItem.class, id);
}
 
Example #17
Source File: TodoServiceImpl.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 4 votes vote down vote up
public TodoItem getTodoById(final long id) {
	return todoDataService.getTodoById(id);
}
 
Example #18
Source File: TodoServiceImpl.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 4 votes vote down vote up
@Transactional
public TodoItem update(TodoItem todoItem) {
	return todoDataService.update(todoItem);
}
 
Example #19
Source File: TodoServiceImpl.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 4 votes vote down vote up
@Transactional
public TodoItem create(final TodoItem todoItem) {
	return todoDataService.create(todoItem);
}
 
Example #20
Source File: TodoServiceImpl.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 4 votes vote down vote up
@Transactional
public void remove(final TodoItem todoItem) {
	todoDataService.remove(todoItem);
}
 
Example #21
Source File: CreateTodoServlet.java    From MavenIn28Minutes with MIT License 4 votes vote down vote up
@Override
protected void doPost(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	HttpSession session = request.getSession();
	User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

	String title = request.getParameter("title");
	String dueDate = request.getParameter("dueDate");
	String priority = request.getParameter("priority");

	TodoItem todoItem = new TodoItem(user.getId(), title, false,
			Priority.valueOf(priority), new Date(dueDate));

	todoService.create(todoItem);

	request.getRequestDispatcher("/todos").forward(request, response);

}
 
Example #22
Source File: TodoDataServiceImpl.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 4 votes vote down vote up
public TodoItem create(final TodoItem todoItem) {
	entityManager.persist(todoItem);
	return todoItem;
}
 
Example #23
Source File: TodoServiceImpl.java    From SpringIn28Minutes with MIT License 4 votes vote down vote up
@Transactional
public void remove(final TodoItem todoItem) {
	todoDataService.remove(todoItem);
}
 
Example #24
Source File: TodoServiceImpl.java    From SpringIn28Minutes with MIT License 4 votes vote down vote up
@Transactional
public TodoItem create(final TodoItem todoItem) {
	return todoDataService.create(todoItem);
}
 
Example #25
Source File: TodoServiceImpl.java    From SpringIn28Minutes with MIT License 4 votes vote down vote up
@Transactional
public TodoItem update(TodoItem todoItem) {
	return todoDataService.update(todoItem);
}
 
Example #26
Source File: TodoServiceImpl.java    From SpringIn28Minutes with MIT License 4 votes vote down vote up
public TodoItem getTodoById(final long id) {
	return todoDataService.getTodoById(id);
}
 
Example #27
Source File: TodoDataServiceImpl.java    From SpringIn28Minutes with MIT License 4 votes vote down vote up
public void remove(final TodoItem todoItem) {
	TodoItem t = entityManager.find(TodoItem.class, todoItem.getId());
	entityManager.remove(t);
}
 
Example #28
Source File: TodoDataServiceImpl.java    From SpringIn28Minutes with MIT License 4 votes vote down vote up
public TodoItem create(final TodoItem todoItem) {
	entityManager.persist(todoItem);
	return todoItem;
}
 
Example #29
Source File: TodoDataServiceImpl.java    From SpringIn28Minutes with MIT License 4 votes vote down vote up
public TodoItem update(TodoItem todoItem) {
	return entityManager.merge(todoItem);
}
 
Example #30
Source File: TodoDataServiceImpl.java    From SpringIn28Minutes with MIT License 4 votes vote down vote up
public TodoItemList getTodoListByUser(final long userId) {
	TypedQuery<TodoItem> query = entityManager.createNamedQuery(
			"findTodosByUser", TodoItem.class);
	query.setParameter(1, userId);
	return new TodoItemList(query.getResultList());
}