Package sino.entities

Examples of sino.entities.Post


    public void deletePost(long id) throws PostServiceException {
        ParamUtility.checkNotNegative(null, id, "id");
        ParamUtility.checkState(null, this.postDao, "postDao");

        try {
            Post post = this.postDao.retrieve(id);
            if (post != null) {
                this.postDao.delete(post);
            }
        } catch (DaoException e) {
            throw new PostServiceException("Cannot delete post. Dao exception: " + e.getMessage(), e);
View Full Code Here


    public void testA() throws Exception {
        PostDaoImpl postDao = new PostDaoImpl();
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("persistenceUnit");
        postDao.setEntityManager(factory.createEntityManager());
        postDao.getEntityManager().getTransaction().begin();
        Post post = new Post();
        post.setContent("内容");
        post.setTitle("标题");
        post.setPreview("预览");
        post.setModificationDate(new Date());
        post.setCreationDate(new Date());
        post.setType(PostType.NEWS);
        postDao.persist(post);
        postDao.getEntityManager().getTransaction().commit();
        postDao.setEntityManager(factory.createEntityManager());
        System.out.println(postDao.retrieve(post.getId()).getContent());
        System.out.println(postDao.retrieve(1).getPreview());
    }
View Full Code Here

    }

    public void testB() throws Exception {
        ApplicationContext context = new ClassPathXmlApplicationContext("/config.xml");
        PostService postService = (PostService) context.getBean("postService");
        Post post = new Post();
        post.setContent("内容");
        post.setTitle("标题");
        post.setPreview("预览");
        post.setModificationDate(new Date());
        post.setCreationDate(new Date());
        post.setType(PostType.NEWS);
        postService.createPost(post);
        System.out.println(postService.getPost(post.getId()).getContent());
    }
View Full Code Here

    @RequestMapping(value = "/{type}/edit.do")
    public ModelAndView editPost(@PathVariable("type") String type,
            @RequestParam(value = "id", required = false, defaultValue = "-1") long id) throws PostControllerException,
            PostServiceException {
        Post post;
        if (id == -1) {
            post = new Post();
        } else {
            post = getPostService().getPost(id);
        }

        ModelAndView mov = new ModelAndView(this.editPostView);
View Full Code Here

            @RequestParam(value = "previewpicture", required = false) CommonsMultipartFile file)
            throws PostControllerException, PostServiceException, ImageConverterException {
        ParamUtility.checkStringNotNullOrEmpty(null, type, "type");
        ParamUtility.checkNotNull(null, post, "post");

        Post originalPost = getPostService().getPost(id);
        if (originalPost == null) {
            throw new PostControllerException("Cannot find Post with the id: " + id);
        }

        deletePreviewFile(originalPost);

        originalPost.setTitle(post.getTitle());
        if (file != null) {
            File outputFile = saveFile(file, true);
            originalPost.setPreview(outputFile.getName());
        }
        originalPost.setContent(post.getContent());
        originalPost.setModificationDate(new Date());

        getPostService().updatePost(originalPost);

        return redirectToViewPosts(type);
    }
View Full Code Here

    public String deletePost(@PathVariable("type") String type, @RequestParam("id") long id)
            throws PostServiceException, PostControllerException {
        ParamUtility.checkStringNotNullOrEmpty(null, type, "type");
        ParamUtility.checkNotNegative(null, id, "id");

        Post post = getPostService().getPost(id);
        if (post != null) {
            deletePreviewFile(post);
            getPostService().deletePost(id);
        }
View Full Code Here

TOP

Related Classes of sino.entities.Post

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.