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.controllers;
20 import java.util.ArrayList;
21 import java.util.List;
23 import jp.sourceforge.rabbitBTS.Sht;
24 import jp.sourceforge.rabbitBTS.forms.MemberSearchForm;
25 import jp.sourceforge.rabbitBTS.models.Account;
26 import jp.sourceforge.rabbitBTS.services.AccountService;
28 import org.apache.commons.lang.StringUtils;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Controller;
31 import org.springframework.ui.ModelMap;
32 import org.springframework.validation.BindingResult;
33 import org.springframework.web.bind.annotation.RequestMapping;
34 import org.springframework.web.bind.annotation.RequestMethod;
35 import org.springframework.web.bind.annotation.RequestParam;
41 public class MembersController extends BaseController implements IController {
43 private AccountService accountService;
48 @RequestMapping(method = RequestMethod.GET)
49 public void index(MemberSearchForm form, BindingResult result, ModelMap map) {
51 if (StringUtils.isEmpty(form.getNickName())) {
52 final List<Account> accList = this.accountService.fetchAccounts();
53 map.addAttribute("accounts", accList);
57 final Account account = this.accountService.fetchAccountByNickName(form
59 final List<Account> accList = new ArrayList<Account>(1);
60 map.addAttribute("accounts", accList);
61 if (account == null) {
62 result.reject("account.not.found");
68 @RequestMapping(method = RequestMethod.GET)
69 public void delete(@RequestParam("id") Long accountId, ModelMap map) {
71 Account account = null;
72 if (accountId != null) {
73 account = this.accountService.fetchAccountById(accountId);
76 if (account == null) {
77 Sht.log(this).warning("存在しないアカウントの削除が試行されました。");
80 map.addAttribute("accForDel", account);
83 @RequestMapping(method = RequestMethod.POST)
84 public String delete(Long accountId) {
86 // 再試行の必要なし。メンバー一覧に戻る。
87 return "redirect:/members/";
90 if (accountId != null) {
91 final Account accForDel = this.accountService
92 .fetchAccountById(accountId);
94 this.accountService.deleteAccount(accForDel);
97 return "redirect:/members/";