1 // vim:set ts=4 sts=4 sw=4 noet fenc=utf-8:
3 Copyright 2009 senju@users.sourceforge.jp
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
18 package jp.sourceforge.rabbitBTS.services;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Date;
23 import java.util.List;
25 import jp.sourceforge.rabbitBTS.dao.AccountDao;
26 import jp.sourceforge.rabbitBTS.dao.BbsDao;
27 import jp.sourceforge.rabbitBTS.models.Account;
28 import jp.sourceforge.rabbitBTS.models.BbsPost;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.orm.ObjectRetrievalFailureException;
36 public class BbsService {
38 private BbsDao bbsDao;
40 private AccountDao accountDao;
45 * TODO: 日付順、件数制限、ページング
49 public List<BbsPost> fetchPosts() {
50 final Collection<BbsPost> posts = this.bbsDao.getAllPosts();
51 for (final BbsPost bbsPost : posts) {
54 if (bbsPost.getAuthorId() != null) {
55 final Account acc = this.accountDao.get(bbsPost
57 bbsPost.setAuthor(acc);
59 bbsPost.setAuthor(null);
60 bbsPost.setAuthorId(null);
62 } catch (final ObjectRetrievalFailureException e) {
63 bbsPost.setAuthor(null);
64 bbsPost.setAuthorId(null);
67 return new ArrayList<BbsPost>(posts);
78 public void addNewPost(BbsPost bbsPost, Account account) {
79 // 投稿者の存在チェック(見つからない場合ランタイム例外)
80 this.accountDao.get(account.getAccountId());
83 bbsPost.setAuthorId(account.getAccountId());
84 bbsPost.setDate(new Date());
86 this.bbsDao.savePost(bbsPost);