8 Commits

15 changed files with 443 additions and 307 deletions

View File

@@ -5,9 +5,9 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(EmSpringApplication.class);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(EmSpringApplication.class);
}
}

View File

@@ -1,111 +1,77 @@
package com.example.rhizome.aop.Handler;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.LoginInfoForm;
import com.example.rhizome.app.presentation.form.MessageForm;
import com.example.rhizome.exception.InsufficientPermissionException;
import com.example.rhizome.exception.NoSessionException;
import static com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.ui.Model;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.LoginInfoForm;
import com.example.rhizome.app.presentation.form.MessageForm;
import com.example.rhizome.exception.InsufficientPermissionException;
import com.example.rhizome.exception.NoSessionException;
import static com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword.LOGIN_INFO_FORM;
import static com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword.MESSAGE_ERROR;
/**
* 例外処理用のコントローラ
*/
@ControllerAdvice
public class GlobalExceptionHandler {
private final static Logger LOGGER = Logger.getLogger(GlobalExceptionHandler.class.getName());
private final static Logger LOGGER = Logger.getLogger(GlobalExceptionHandler.class.getName());
private final String SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION = "不正な遷移です。";
private final String SEVERE_ERROR_MESSAGE_BAD_REQUEST = "不正なリクエストです。";
private final String SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION = "不正な遷移です。";
private final String SEVERE_ERROR_MESSAGE_BAD_REQUEST = "不正なリクエストです。";
/**
* セッションが切れている場合の例外処理
*
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@ExceptionHandler(NoSessionException.class)
public String handleNoSessionException(Model model, Exception e) {
@ExceptionHandler(NoSessionException.class)
public String handleNoSessionException(Model model, Exception e) {
model.addAttribute(MESSAGE_ERROR, new MessageForm(SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION));
model.addAttribute(LOGIN_INFO_FORM, new LoginInfoForm());
model.addAttribute(MESSAGE_ERROR, new MessageForm(SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION));
model.addAttribute(LOGIN_INFO_FORM, new LoginInfoForm());
e.printStackTrace();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
return TransitionTargetPageNameKeyword.LOGIN_HTML;
}
return TransitionTargetPageNameKeyword.LOGIN_HTML;
}
/**
* 権限がない場合の例外処理
*
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@ExceptionHandler(InsufficientPermissionException.class)
public String handleInsufficientPermissionException(Model model, Exception e) {
@ExceptionHandler(InsufficientPermissionException.class)
public String handleInsufficientPermissionException(Model model, Exception e) {
model.addAttribute(MESSAGE_ERROR, new MessageForm(SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION));
model.addAttribute(LOGIN_INFO_FORM, new LoginInfoForm());
model.addAttribute(MESSAGE_ERROR, new MessageForm(SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION));
model.addAttribute(LOGIN_INFO_FORM, new LoginInfoForm());
e.printStackTrace();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
return TransitionTargetPageNameKeyword.LOGIN_HTML;
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
/**
* リクエストメソッドが不正な場合の例外処理
*
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public String handleBadRequestException(Model model, Exception e) {
// エラーメッセージやその他の情報をモデルに追加する
model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST);
model.addAttribute("status", HttpStatus.BAD_REQUEST.value());
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public String handleBadRequestException(Model model, Exception e) {
model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST);
model.addAttribute("status", HttpStatus.BAD_REQUEST.value());
e.printStackTrace();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
// カスタムエラーページにリダイレクト
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
/**
* その他の例外処理
*
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@ExceptionHandler(Exception.class)
public String AllException(Model model, Exception e) {
// エラーメッセージやその他の情報をモデルに追加する
model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST);
@ExceptionHandler(Exception.class)
public String AllException(Model model, Exception e) {
model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST);
e.printStackTrace();
e.printStackTrace();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
// カスタムエラーページにリダイレクト
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}

View File

@@ -5,10 +5,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* SessionCheckアノテーション
* セッションチェックを行うメソッドに付与する
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface PermissionCheck {

View File

@@ -1,114 +1,76 @@
package com.example.rhizome.aop.aspect;
import com.example.rhizome.app.presentation.controller.pageproperty.SessionKeyword;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.LoginUserForm;
import com.example.rhizome.exception.InsufficientPermissionException;
import javax.servlet.http.HttpServletRequest;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import com.example.rhizome.app.presentation.controller.pageproperty.SessionKeyword;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.LoginUserForm;
import com.example.rhizome.exception.InsufficientPermissionException;
/**
* 権限チェック用のAOP
*/
@Aspect
@Component
public class PermissionCheckAspect {
HttpServletRequest request;
HttpServletRequest request;
@Autowired
public PermissionCheckAspect(HttpServletRequest request) {
this.request = request;
}
@Autowired
public PermissionCheckAspect(HttpServletRequest request) {
this.request = request;
}
// Aspectのフックを定義(今回はPermissionCheckアノテーションが定義されているメソッドが動作するタイミング)
@Pointcut("@annotation(com.example.rhizome.aop.aspect.PermissionCheck)")
public void permissionCheckMethod() {
}
@Pointcut("@annotation(com.example.rhizome.aop.aspect.PermissionCheck)")
public void permissionCheckMethod() {
}
/**
* 権限チェック
*/
@Before("permissionCheckMethod()")
public void checkPermission() {
// ログインユーザの取得
LoginUserForm loginUserForm = (LoginUserForm) request.getSession().getAttribute(SessionKeyword.LOGIN_USER);
@Before("permissionCheckMethod()")
public void checkPermission() {
LoginUserForm loginUserForm = (LoginUserForm) request.getSession().getAttribute(SessionKeyword.LOGIN_USER);
// ログインユーザが取得できない場合、または権限がない場合はエラー画面に遷移
if (loginUserForm == null || !hasRequiredPermission(request.getRequestURI(), loginUserForm)) {
throw new InsufficientPermissionException("不正な遷移です");
}
if (loginUserForm == null || !hasRequiredPermission(request.getRequestURI(), loginUserForm)) {
throw new InsufficientPermissionException("不正な遷移です");
}
}
}
/**
* 遷移先のURLとログインユーザの権限から、遷移可否を判定する
*
* @param targetURL 遷移したいURL
* @param loginUserForm リクエスト元のユーザ
* @return true:遷移可 false:遷移不可
*/
private boolean hasRequiredPermission(String targetURL, LoginUserForm loginUserForm) {
private boolean hasRequiredPermission(String targetURL, LoginUserForm loginUserForm) {
// 管理者権限
if (isAdminTransition(targetURL, loginUserForm)) {
return true;
}
if (isAdminTransition(targetURL, loginUserForm)) {
return true;
}
// 一般権限
if (isUserTransition(targetURL, loginUserForm)) {
return true;
}
if (isUserTransition(targetURL, loginUserForm)) {
return true;
}
// アクセス不許可の場合の処理(不正アクセス画面に遷移)
return false;
return false;
}
}
/**
* 管理者用のアカウントで管理者向けのページアクセスか
*
* @param targetURL 遷移したいURL
* @param loginUserForm リクエスト元のユーザ
* @return true:遷移可 false:遷移不可
*/
private boolean isAdminTransition(String targetURL, LoginUserForm loginUserForm) {
private boolean isAdminTransition(String targetURL, LoginUserForm loginUserForm) {
// 管理者か
if (!loginUserForm.isAdminUser()) {
return false;
}
if (!loginUserForm.isAdminUser()) {
return false;
}
if (!TransitionTargetPageNameKeyword.getAdminPageList().contains(targetURL)) {
return false;
}
// 管理者向けのページ遷移か
if (!TransitionTargetPageNameKeyword.getAdminPageList().contains(targetURL)) {
return false;
}
return true;
}
return true;
}
private boolean isUserTransition(String targetURL, LoginUserForm loginUserForm) {
/**
* 一般ユーザ用のアカウントで一般ユーザ向けのページアクセスか
*
* @param targetURL 遷移したいURL
* @param loginUserForm リクエスト元のユーザ
* @return true:遷移可 false:遷移不可
*/
private boolean isUserTransition(String targetURL, LoginUserForm loginUserForm) {
if (loginUserForm.isAdminUser()) {
return false;
}
// 管理者か
if (loginUserForm.isAdminUser()) {
return false;
}
return TransitionTargetPageNameKeyword.getUserPageList().contains(targetURL);
// 一般ユーザ向けのページ遷移か
return TransitionTargetPageNameKeyword.getUserPageList().contains(targetURL);
}
}
}

View File

@@ -5,10 +5,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* SessionCheckアノテーション
* セッションチェックを行うメソッドに付与する
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface SessionCheck {

View File

@@ -1,47 +1,40 @@
package com.example.rhizome.aop.aspect;
import com.example.rhizome.app.presentation.controller.pageproperty.SessionKeyword;
import com.example.rhizome.exception.NoSessionException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.example.rhizome.app.presentation.controller.pageproperty.SessionKeyword;
import com.example.rhizome.exception.NoSessionException;
/**
* セッションチェック用のAOP
*/
@Aspect
@Component
public class SessionCheckAspect {
HttpServletRequest request;
HttpServletRequest request;
@Autowired
public SessionCheckAspect(HttpServletRequest request) {
this.request = request;
}
@Autowired
public SessionCheckAspect(HttpServletRequest request) {
this.request = request;
}
@Pointcut("@annotation(com.example.rhizome.aop.aspect.SessionCheck)")
public void sessionCheckMethod() {
}
@Pointcut("@annotation(com.example.rhizome.aop.aspect.SessionCheck)")
public void sessionCheckMethod() {
}
/**
* セッションチェック
*/
@Before("sessionCheckMethod()")
public void checkSession() {
// セッションの取得
HttpSession session = request.getSession(false);
@Before("sessionCheckMethod()")
public void checkSession() {
HttpSession session = request.getSession(false);
// セッションが取得できない場合はエラー画面に遷移
if (session == null || session.getAttribute(SessionKeyword.LOGIN_USER) == null) {
throw new NoSessionException("不正なログインです");
}
if (session == null || session.getAttribute(SessionKeyword.LOGIN_USER) == null) {
throw new NoSessionException("不正なログインです");
}
}
}
}

View File

@@ -1,14 +1,19 @@
package com.example.rhizome.app.domain.service;
import java.util.List;
import com.example.rhizome.app.domain.model.Department;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
import java.util.List;
public interface SearchDepartment {
List<Department> selectAll();
List<Department> selectAll();
List<Department> searchBy(SearchConditionDepartment searchConditionDepartment);
List<Department> searchBy(SearchConditionDepartment searchConditionDepartment);
List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment);
List<Department> searchByDepartmentName(SearchConditionDepartment searchConditionDepartment);
List<Department> searchByDepartmentId(SearchConditionDepartment searchConditionDepartment);
List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment);
}

View File

@@ -6,11 +6,11 @@ import com.example.rhizome.app.domain.model.LoginUser;
import java.util.List;
public interface SearchEmployee {
List<Employee> searchEmployee(String mailAddress);
List<Employee> searchEmployee(String mailAddress);
List<Employee> searchEmployeeByIdDepartment(Integer idDepartment);
List<Employee> searchEmployeeByIdDepartment(Integer idDepartment);
LoginUser searchLoginUser(String mailAddress);
LoginUser searchLoginUser(String mailAddress);
Employee searchEmployeeByIdEmployee(Integer idEmployee);
Employee searchEmployeeByIdEmployee(Integer idEmployee);
}

View File

@@ -0,0 +1,82 @@
package com.example.rhizome.app.presentation.controller;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.domain.service.SearchEmployeeInfo;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.DepartmentForm;
import com.example.rhizome.app.presentation.form.SearchConditionDepartmentForm;
@Controller
public class SelectDepartmentController {
private final static Logger LOGGER = Logger.getLogger(SelectDepartmentController.class.getName());
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession;
SearchDepartment searchDepartment;
SearchEmployeeInfo searchEmployeeInfo;
@Autowired
public SelectDepartmentController(HttpSession httpSession, SearchDepartment searchDepartment,
SearchEmployeeInfo searchEmployeeInfo) {
this.httpSession = httpSession;
this.searchDepartment = searchDepartment;
this.searchEmployeeInfo = searchEmployeeInfo;
}
@ModelAttribute
public SearchConditionDepartmentForm searchConditionDepartmentForm() {
return new SearchConditionDepartmentForm();
}
@SessionCheck
@PermissionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT, method = RequestMethod.POST)
public String select(SearchConditionDepartmentForm searchConditionDepartmentForm, Model model) {
try {
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(
searchDepartment
.searchByWithLike(SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm))));
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
} catch (Exception e) {
httpSession.invalidate();
e.printStackTrace();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
@SessionCheck
@PermissionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO_FORM_EMPTY, method = RequestMethod.POST)
public String select(Model model) {
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(
searchDepartment.searchBy(SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm()))));
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
}
}

View File

@@ -1,18 +1,17 @@
package com.example.rhizome.app.presentation.controller.pageproperty;
/**
* Servlet から Servlet に返却する際に使用する文字列を管理するクラス
*/
public class PageReturnAttributeKeyword {
public static final String MESSAGE_ERROR = "messageError";
public static final String MESSAGE_INFO = "messageInfo";
public static final String MESSAGE_ERROR = "messageError";
public static final String MESSAGE_INFO = "messageInfo";
public static final String DEPARTMENT_FORM_LIST = "departmentFormList";
public static final String UPDATE_EMPLOYEE_INFO_FORM = "updateEmployeeInfoForm";
public static final String INSERT_EMPLOYEE_FORM = "insertEmployeeForm";
public static final String LOGIN_INFO_FORM = "loginInfoForm";
public static final String UPDATE_PERSONAL_EMPLOYEE_USER_FORM = "updatePersonalEmployeeUserForm";
public static final String EMPLOYEE_INFO_FORM_LIST = "employeeInfoFormList";
public static final String UPDATE_EMPLOYEE_INFO_FORM = "updateEmployeeInfoForm";
public static final String INSERT_EMPLOYEE_FORM = "insertEmployeeForm";
public static final String LOGIN_INFO_FORM = "loginInfoForm";
public static final String UPDATE_PERSONAL_EMPLOYEE_USER_FORM = "updatePersonalEmployeeUserForm";
public static final String EMPLOYEE_INFO_FORM_LIST = "employeeInfoFormList";
public static final String DEPARTMENT_FORM_LIST = "departmentFormList";
public static final String INSERT_DEPARTMENT_FORM = "insertDepartmentForm";
public static final String UPDATE_DEPARTMENT_FORM = "updateDepartmentForm";
}

View File

@@ -2,92 +2,92 @@ package com.example.rhizome.app.presentation.controller.pageproperty;
import java.util.Set;
/**
* システムで利用しているJSPのリスト
*/
public class TransitionTargetPageNameKeyword {
// 共通
public static final String LOGIN_HTML = "login";
public static final String LOGIN_HTML = "login";
// 一般向け
public static final String UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML = "updatePersonalEmployeeInput";
public static final String UPDATE_PERSONAL_RESULT_HTML = "updatePersonalEmployeeResult";
public static final String UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML = "updatePersonalEmployeeInput";
public static final String UPDATE_PERSONAL_RESULT_HTML = "updatePersonalEmployeeResult";
// 管理者向け
public static final String MENU_HTML = "menu";
public static final String SELECT_EMPLOYEE_HTML = "selectEmployee";
public static final String INSERT_EMPLOYEE_INPUT_HTML = "insertEmployeeInput";
public static final String INSERT_EMPLOYEE_CONFIRM_HTML = "insertEmployeeConfirm";
public static final String INSERT_EMPLOYEE_RESULT_HTML = "insertEmployeeResult";
public static final String UPDATE_EMPLOYEE_INPUT_HTML = "updateEmployeeInput";
public static final String MENU_HTML = "menu";
public static final String SELECT_EMPLOYEE_HTML = "selectEmployee";
public static final String INSERT_EMPLOYEE_INPUT_HTML = "insertEmployeeInput";
public static final String INSERT_EMPLOYEE_CONFIRM_HTML = "insertEmployeeConfirm";
public static final String INSERT_EMPLOYEE_RESULT_HTML = "insertEmployeeResult";
public static final String UPDATE_EMPLOYEE_INPUT_HTML = "updateEmployeeInput";
public static final String ERROR_HTML = "error";
public static final String SELECT_DEPARTMENT_HTML = "selectDepartment";
// 共通(Controller)
public static final String INDEX_BLANK = "";
public static final String INDEX_SLASH = "/";
public static final String INDEX_LOGIN = "/login";
public static final String LOGOUT = "/logout";
public static final String DO_LOGIN = "/doLogin";
public static final String ERROR_HTML = "error";
// 一般向け(Controller)
public static final String PERSONAL_UPDATE_RESULT = "/updatePersonalEmployeeResult";
public static final String INDEX_BLANK = "";
public static final String INDEX_SLASH = "/";
public static final String INDEX_LOGIN = "/login";
public static final String LOGOUT = "/logout";
public static final String DO_LOGIN = "/doLogin";
// 管理者向け(Controller)
public static final String DELETE_EMPLOYEE = "/deleteEmployee";
public static final String INSERT_EMPLOYEE_INPUT = "/insertEmployeeInput";
public static final String INSERT_EMPLOYEE_CONFIRM = "/insertEmployeeConfirm";
public static final String INSERT_EMPLOYEE = "/insertEmployee";
public static final String SHOW_MENU = "/showMenu";
public static final String SELECT_EMPLOYEE_INFO = "/selectEmployeeInfo";
public static final String SELECT_EMPLOYEE_INFO_FORM_EMPTY = "/selectAll";
public static final String SHOW_UPDATE_EMPLOYEE = "/showUpdateEmployee";
public static final String UPDATE_EMPLOYEE_RESULT = "/updateEmployeeResult";
public static final String PERSONAL_UPDATE_RESULT = "/updatePersonalEmployeeResult";
// Department
// HTML
// Controller
public static final String DELETE_EMPLOYEE = "/deleteEmployee";
public static final String INSERT_EMPLOYEE_INPUT = "/insertEmployeeInput";
public static final String INSERT_EMPLOYEE_CONFIRM = "/insertEmployeeConfirm";
public static final String INSERT_EMPLOYEE = "/insertEmployee";
public static final String SHOW_MENU = "/showMenu";
public static final String SELECT_EMPLOYEE_INFO = "/selectEmployeeInfo";
public static final String SELECT_EMPLOYEE_INFO_FORM_EMPTY = "/selectAll";
public static final String SHOW_UPDATE_EMPLOYEE = "/showUpdateEmployee";
public static final String UPDATE_EMPLOYEE_RESULT = "/updateEmployeeResult";
/**
* 管理者向けのページリストを返す
*
* @return 管理者向けのページリスト
*/
public static Set<String> getAdminPageList() {
public static final String SELECT_DEPARTMENT = "/selectDepartment";
public static final String SELECT_DEPARTMENT_INFO_FORM_EMPTY = "/selectDepartmentAll";
public static final String INSERT_DEPARTMENT_INPUT = "/insertDepartmentInput";
public static final String INSERT_DEPARTMENT_CONFIRM = "/insertDepartmentConfirm";
public static final String INSERT_DEPARTMENT = "/insertDepartment";
public static final String DELETE_DEPARTMENT = "/deleteDepartment";
public static final String SHOW_UPDATE_DEPARTMENT = "/showUpdateDepartment";
public static final String UPDATE_DEPARTMENT_RESULT = "/updateDepartmentResult";
return Set.of(
INDEX_BLANK,
INDEX_SLASH,
INDEX_LOGIN,
LOGOUT,
DO_LOGIN,
DELETE_EMPLOYEE,
INSERT_EMPLOYEE_INPUT,
INSERT_EMPLOYEE_CONFIRM,
INSERT_EMPLOYEE,
SHOW_MENU,
SELECT_EMPLOYEE_INFO,
SELECT_EMPLOYEE_INFO_FORM_EMPTY,
SHOW_UPDATE_EMPLOYEE,
UPDATE_EMPLOYEE_RESULT
);
}
public static final String INSERT_DEPARTMENT_INPUT_HTML = "insertDepartmentInput";
public static final String INSERT_DEPARTMENT_CONFIRM_HTML = "insertDepartmentConfirm";
public static final String INSERT_DEPARTMENT_RESULT_HTML = "insertDepartmentResult";
/**
* 一般向けのページリストを返す
*
* @return 一般向けのページリスト
*/
public static Set<String> getUserPageList() {
return Set.of(
INDEX_BLANK,
INDEX_SLASH,
INDEX_LOGIN,
LOGOUT,
DO_LOGIN,
PERSONAL_UPDATE_RESULT
);
}
public static final String UPDATE_DEPARTMENT_INPUT_HTML = "updateDepartmentInput";
public static Set<String> getAdminPageList() {
return Set.of(
INDEX_BLANK,
INDEX_SLASH,
INDEX_LOGIN,
LOGOUT,
DO_LOGIN,
DELETE_EMPLOYEE,
INSERT_EMPLOYEE_INPUT,
INSERT_EMPLOYEE_CONFIRM,
INSERT_EMPLOYEE,
SHOW_MENU,
SELECT_EMPLOYEE_INFO,
SELECT_EMPLOYEE_INFO_FORM_EMPTY,
SHOW_UPDATE_EMPLOYEE,
UPDATE_EMPLOYEE_RESULT,
SELECT_DEPARTMENT,
SELECT_DEPARTMENT_INFO_FORM_EMPTY,
INSERT_DEPARTMENT_INPUT,
INSERT_DEPARTMENT_CONFIRM,
INSERT_DEPARTMENT,
DELETE_DEPARTMENT,
SHOW_UPDATE_DEPARTMENT,
UPDATE_DEPARTMENT_RESULT);
}
public static Set<String> getUserPageList() {
return Set.of(
INDEX_BLANK,
INDEX_SLASH,
INDEX_LOGIN,
LOGOUT,
DO_LOGIN,
PERSONAL_UPDATE_RESULT);
}
}

View File

@@ -0,0 +1,28 @@
package com.example.rhizome.app.presentation.form;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SearchConditionDepartmentForm {
private Integer idDepartment;
private String nmDepartment;
public static SearchConditionDepartmentForm convertFrom(SearchConditionDepartment searchConditionDepartment) {
return new SearchConditionDepartmentForm(
searchConditionDepartment.getIdDepartment(),
searchConditionDepartment.getNmDepartment());
}
public static SearchConditionDepartment convertTo(SearchConditionDepartmentForm searchConditionDepartmentForm) {
return new SearchConditionDepartment(
searchConditionDepartmentForm.getIdDepartment(),
searchConditionDepartmentForm.getNmDepartment());
}
}

View File

@@ -1,12 +1,9 @@
package com.example.rhizome.exception;
/**
* 権限不足の例外を表現するクラスです。
*/
public class InsufficientPermissionException extends RuntimeException {
public InsufficientPermissionException(String message) {
super(message);
}
public InsufficientPermissionException(String message) {
super(message);
}
}

View File

@@ -1,12 +1,9 @@
package com.example.rhizome.exception;
/**
* 権限不足の例外を表現するクラスです。
*/
public class NoSessionException extends RuntimeException {
public NoSessionException(String message) {
super(message);
}
public NoSessionException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,115 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<!-- 外部のスクリプトファイルを読み込む -->
<script th:src="@{/js/common.js}"></script>
<!-- CSSの読み込み -->
<link rel="stylesheet" th:href="@{/css/all.css}">
<link rel=stylesheet th:href="@{/css/style.css}" type="text/css">
<title>検索</title>
</head>
<body>
<h1>
検索条件入力   
<div class="rightSection">
<span class="loginInfo">ログイン者名:<span th:text="${session.loginUser.nmEmployee}"></span></span>
<button class="logoutButton" onclick="logoutSubmit()">ログアウト</button>
</div>
</h1>
<form action="selectDepartment"
method="post"
th:object="${searchConditionDepartmentForm}">
<div class="msgBox error" th:if="${messageError} != null">
<span class="error" th:text="${messageError.message}"></span>
</div>
<table>
<tr>
<th class="header">部署ID</th>
<td>
<input placeholder="部署ID"
th:field="*{idDepartment}"
type="number"/>
</td>
</tr>
<tr>
<th class="header">部署名</th>
<td>
<input placeholder="部署名"
th:field="*{nmDepartment}"
type="text"/>
</td>
</tr>
<tr>
<td class="btnArea" colspan="2">
<input type="submit" value="検索"/>
</td>
<td class="btnArea" colspan="2">
<button onclick="clearInput()">クリア</button>
</td>
</tr>
</table>
</form>
<div class="header-spacing"></div>
<a href="showMenu">メニューに戻る</a>
<div class="header-spacing"></div>
<h1><span>検索結果</span></h1>
<div class="header-spacing"></div>
<th:block th:if="${messageInfo != null}">
<script th:inline="javascript">
alert([[${messageInfo.message}]]);
</script>
</th:block>
<div class="header-spacing"></div>
<th:block th:if="${departmentFormList != null and departmentFormList.size() > 0}">
<!-- 検索結果が1件以上ある場合 -->
<table class="table-grid table-striped table-hover">
<thead>
<tr>
<th style="width: 100px;">部署ID</th>
<th style="width: 150px;">部署名</th>
<th style="width: 150px;">操作</th>
</tr>
</thead>
<tbody>
<tr th:each="departmentForm : ${departmentFormList}">
<td th:text="${departmentForm.idDepartment}"></td>
<td th:text="${departmentForm.nmDepartment}"></td>
<td>
<!-- 更新フォーム -->
<form action="showUpdateDepartment" method="post" style="display: inline;">
<input name="idDepartment" th:value="${departmentForm.idDepartment}" type="hidden">
<input type="submit" value="更新">
</form>
<!-- 削除フォーム -->
<form action="deleteDepartment" method="post" onsubmit="return confirm('本当に削除しますか?');"
style="display: inline;">
<input name="idDepartment" th:value="${departmentForm.idDepartment}" type="hidden">
<input type="submit" value="削除">
</form>
</td>
</tr>
</tbody>
</table>
</th:block>
<th:block th:if="${departmentFormList == null or departmentFormList.size() == 0}">
<!-- 検索結果が0件の場合 -->
検索結果はありません。
</th:block>
</body>
<script type="text/javascript">
function clearInput() {
document.getElementById('idDepartment').value = '';
document.getElementById('nmDepartment').value = '';
}
</script>
</html>