/*
 * JBoss, Home of Professional Open Source
 * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @authors tag. All rights reserved.
 */
package org.jboss.planet.controller;

import java.text.DateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.enterprise.inject.Model;
import javax.inject.Inject;

import org.jboss.planet.model.Post;
import org.jboss.planet.service.PostService;

/**
 * Model for {@link Post}
 * 
 * @author Libor Krzyzanek
 */
@Model
public class PostController {

	@Inject
	private Logger log;

	@Inject
	private PostService postService;

	private Post post;

	private String titleAsId;

	public void loadPost() {
		log.log(Level.FINE, "Load post with id: {0}", titleAsId);

		post = postService.find(titleAsId);
		if (post == null) {
			// TODO: Return NOT_FOUND
		} else {
			DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
			post.setPublishedDate(df.format(post.getPublished()));
		}
	}

	public Post getPost() {
		return post;
	}

	public void setPost(Post post) {
		this.post = post;
	}

	public String getTitleAsId() {
		return titleAsId;
	}

	public void setTitleAsId(String titleAsId) {
		this.titleAsId = titleAsId;
	}

}

@@ -226,96 +226,121 @@
 ort 
-java.text.DateFormat;%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger
+org.jboss.planet.model.Post;%0Aimport org.jboss.planet.service.PostService;%0A%0Aimport javax.enterprise.inject.Model
 ;%0A
-%0A
 impo
@@ -348,39 +348,42 @@
 t javax.
-enterprise.inject.Model
+faces.context.FacesContext
 ;%0Aimport
@@ -408,88 +408,175 @@
 ct;%0A
-%0A
 import 
-org.jboss.planet.model.Post;%0Aimport org.jboss.planet.service.PostService
+javax.servlet.http.HttpServletResponse;%0Aimport java.io.IOException;%0Aimport java.text.DateFormat;%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger
 ;%0A%0A/
@@ -752,16 +752,62 @@
 rvice;%0A%0A
+%09@Inject%0A%09private FacesContext facesContext;%0A%0A
 %09private
@@ -866,24 +866,43 @@
 d loadPost()
+ throws IOException
  %7B%0A%09%09log.log
@@ -1020,33 +1020,117 @@
 %0A%09%09%09
-// TODO: Return NOT_FOUND
+facesContext.getExternalContext().responseSendError(HttpServletResponse.SC_NOT_FOUND, %22Blog Post Not Found%22);
 %0A%09%09%7D

return 404 when post not found. fixes #ORG-1985