第2段階 部署削除機能

This commit is contained in:
s-sakiyama
2026-10-13 16:26:40 +09:00
parent 4c134b81b8
commit 815d957a31
9 changed files with 398 additions and 210 deletions

View File

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

View File

@@ -0,0 +1,6 @@
package com.example.rhizome.app.domain.service;
public interface DeleteDepartment {
void deleteDepartment(Integer idDepartment);
}

View File

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

View File

@@ -0,0 +1,33 @@
package com.example.rhizome.app.domain.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.example.rhizome.app.domain.service.DeleteDepartment;
import com.example.rhizome.app.infra.repository.DepartmentRepository;
/**
* Employee レコード削除関連の機能を持つサービス
*/
@Service
@Transactional
public class DeleteDepartmentImpl implements DeleteDepartment {
DepartmentRepository departmentRepository;
@Autowired
public DeleteDepartmentImpl(DepartmentRepository departmentRepository) {
this.departmentRepository = departmentRepository;
}
/**
* idEmployee を元に employee データを削除
*
* @param idEmployee 削除対象のidEmployee
*/
public void deleteDepartment(Integer idDepartment) {
departmentRepository.deleteById(idDepartment);
}
}

View File

@@ -1,17 +1,18 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.example.rhizome.app.domain.model.Department; import com.example.rhizome.app.domain.model.Department;
import com.example.rhizome.app.domain.model.SearchConditionDepartment; import com.example.rhizome.app.domain.model.SearchConditionDepartment;
import com.example.rhizome.app.domain.service.SearchDepartment; import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.infra.entity.DepartmentEntity; import com.example.rhizome.app.infra.entity.DepartmentEntity;
import com.example.rhizome.app.infra.repository.DepartmentRepository; import com.example.rhizome.app.infra.repository.DepartmentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/** /**
* 部署情報検索系の機能を集約させるサービスクラスです。 * 部署情報検索系の機能を集約させるサービスクラスです。
@@ -20,63 +21,67 @@ import java.util.List;
@Transactional @Transactional
public class SearchDepartmentImpl implements SearchDepartment { public class SearchDepartmentImpl implements SearchDepartment {
DepartmentRepository departmentRepository; DepartmentRepository departmentRepository;
/** /**
* コンストラクタ * コンストラクタ
* *
* @param departmentRepository DI対象 * @param departmentRepository DI対象
*/ */
@Autowired @Autowired
public SearchDepartmentImpl(DepartmentRepository departmentRepository) { public SearchDepartmentImpl(DepartmentRepository departmentRepository) {
this.departmentRepository = departmentRepository; this.departmentRepository = departmentRepository;
} }
/** /**
* 部署情報を全件取得する * 部署情報を全件取得する
* *
* @return 取得した部署情報レコード全件 * @return 取得した部署情報レコード全件
*/ */
public List<Department> selectAll() { public List<Department> selectAll() {
return DepartmentEntity.createDepartmentList(departmentRepository.findAll()); return DepartmentEntity.createDepartmentList(departmentRepository.findAll());
} }
/** /**
* searchConditionDepartment の情報を元に Department のレコードを取得 * searchConditionDepartment の情報を元に Department のレコードを取得
* *
* @param searchConditionDepartment 検索条件 * @param searchConditionDepartment 検索条件
* @return 検索結果のレコード * @return 検索結果のレコード
*/ */
public List<Department> searchBy(SearchConditionDepartment searchConditionDepartment) { public List<Department> searchBy(SearchConditionDepartment searchConditionDepartment) {
// 動的に検索条件を絞り込む // 動的に検索条件を絞り込む
// Specification は Criteria API の Predicate をラップしたもの // Specification は Criteria API の Predicate をラップしたもの
return DepartmentEntity return DepartmentEntity
.createDepartmentList( .createDepartmentList(
departmentRepository.findAll(Specification departmentRepository.findAll(Specification
.where(DepartmentRepository.idDepartmentEqual(searchConditionDepartment.getIdDepartment())) .where(DepartmentRepository
.and(DepartmentRepository.nmDepartmentEqual(searchConditionDepartment.getNmDepartment())) .idDepartmentEqual(searchConditionDepartment.getIdDepartment()))
) .and(DepartmentRepository
); .nmDepartmentEqual(searchConditionDepartment.getNmDepartment()))));
} }
/** /**
* searchConditionDepartment の情報を元に Department のレコードを取得 * searchConditionDepartment の情報を元に Department のレコードを取得
* 部分一致検索 * 部分一致検索
* *
* @param searchConditionDepartment 検索条件 * @param searchConditionDepartment 検索条件
* @return 検索結果のレコード * @return 検索結果のレコード
*/ */
public List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment) { public List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment) {
// 動的に検索条件を絞り込む // 動的に検索条件を絞り込む
// Specification は Criteria API の Predicate をラップしたもの // Specification は Criteria API の Predicate をラップしたもの
return DepartmentEntity return DepartmentEntity
.createDepartmentList( .createDepartmentList(
departmentRepository.findAll(Specification departmentRepository.findAll(Specification
.where(DepartmentRepository.idDepartmentEqual(searchConditionDepartment.getIdDepartment())) .where(DepartmentRepository
.and(DepartmentRepository.nmDepartmentLike(searchConditionDepartment.getNmDepartment())) .idDepartmentEqual(searchConditionDepartment.getIdDepartment()))
) .and(DepartmentRepository
); .nmDepartmentLike(searchConditionDepartment.getNmDepartment()))));
} }
public Optional<Department> searchDepartmentByIdDepartment(Integer idDepartment) {
return DepartmentEntity.createDepartmentList(departmentRepository.findById(idDepartment));
}
} }

View File

@@ -6,15 +6,22 @@
*/ */
package com.example.rhizome.app.infra.entity; package com.example.rhizome.app.infra.entity;
import java.util.List;
import java.util.Optional;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.example.rhizome.app.domain.model.Department; import com.example.rhizome.app.domain.model.Department;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.List;
/** /**
* Department テーブルの Entity * Department テーブルの Entity
* *
@@ -27,46 +34,52 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class DepartmentEntity { public class DepartmentEntity {
/** /**
* 部署ID * 部署ID
*/ */
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_department", nullable = false) @Column(name = "id_department", nullable = false)
private Integer idDepartment; private Integer idDepartment;
/** /**
* 部署名 * 部署名
*/ */
@Column(name = "nm_department", nullable = false) @Column(name = "nm_department", nullable = false)
private String nmDepartment; private String nmDepartment;
/** /**
* DepartmentEntity(DataAccess層依存)から Department(BusinessLogic層依存型)に変換します。 * DepartmentEntity(DataAccess層依存)から Department(BusinessLogic層依存型)に変換します。
* *
* @param departmentEntityList department Table のリスト * @param departmentEntityList department Table のリスト
* @return List<Department> リスト * @return List<Department> リスト
*/ */
public static List<Department> createDepartmentList(List<DepartmentEntity> departmentEntityList) { public static List<Department> createDepartmentList(List<DepartmentEntity> departmentEntityList) {
// Stream API を利用するとこうなります。 // Stream API を利用するとこうなります。
return departmentEntityList return departmentEntityList
.stream() .stream()
.map(departmentEntity -> new Department( .map(departmentEntity -> new Department(
departmentEntity.getIdDepartment(), departmentEntity.getIdDepartment(),
departmentEntity.getNmDepartment() departmentEntity.getNmDepartment()))
)).toList(); .toList();
} }
/**
* Department(BusinessLogic層依存型) から DepartmentEntity(DataAccess層依存)に変換します。
*
* @param department department モデルの値
* @return DepartmentEntity に変換したインスタンス
*/
public static DepartmentEntity convertFrom(Department department) {
return new DepartmentEntity(
department.getIdDepartment(),
department.getNmDepartment());
}
public static Optional<Department> createDepartmentList(Optional<DepartmentEntity> departmentEntityList) {
return departmentEntityList.map(departmentEntity -> new Department(departmentEntity.getIdDepartment(),
departmentEntity.getNmDepartment()));
}
/**
* Department(BusinessLogic層依存型) から DepartmentEntity(DataAccess層依存)に変換します。
*
* @param department department モデルの値
* @return DepartmentEntity に変換したインスタンス
*/
public static DepartmentEntity convertFrom(Department department) {
return new DepartmentEntity(
department.getIdDepartment(),
department.getNmDepartment()
);
}
} }

View File

@@ -1,11 +1,11 @@
package com.example.rhizome.app.infra.repository; package com.example.rhizome.app.infra.repository;
import com.example.rhizome.app.infra.entity.DepartmentEntity;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import com.example.rhizome.app.infra.entity.DepartmentEntity;
/** /**
* Specification: * Specification:
@@ -20,31 +20,32 @@ import org.springframework.stereotype.Repository;
* 戻り値はクエリを格納しているPredicateオブジェクトとなります。 * 戻り値はクエリを格納しているPredicateオブジェクトとなります。
*/ */
@Repository @Repository
public interface DepartmentRepository extends JpaRepository<DepartmentEntity, Integer>, JpaSpecificationExecutor<DepartmentEntity> { public interface DepartmentRepository
extends JpaRepository<DepartmentEntity, Integer>, JpaSpecificationExecutor<DepartmentEntity> {
static Specification<DepartmentEntity> idDepartmentEqual(Integer idDepartment) {
return idDepartment == null ? null :
// 戻り値の型 Specification<DepartmentEntity> にキャスト
(Specification<DepartmentEntity>)
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idDepartment' = idDepartment(変数)"
// を作成している
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idDepartment"), idDepartment);
}
static Specification<DepartmentEntity> idDepartmentEqual(Integer idDepartment) { static Specification<DepartmentEntity> nmDepartmentEqual(String nmDepartment) {
return idDepartment == null ? return (nmDepartment == null || nmDepartment.isEmpty()) ? null
null : : (Specification<DepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
// 戻り値の型 Specification<DepartmentEntity> にキャスト .like(root.get("nmDepartment"), nmDepartment);
(Specification<DepartmentEntity>) }
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idDepartment' = idDepartment(変数)"
// を作成している
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idDepartment"), idDepartment);
}
static Specification<DepartmentEntity> nmDepartmentEqual(String nmDepartment) { static Specification<DepartmentEntity> nmDepartmentLike(String nmDepartment) {
return (nmDepartment == null || nmDepartment.isEmpty()) ? return (nmDepartment == null || nmDepartment.isEmpty()) ? null
null : : (Specification<DepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
(Specification<DepartmentEntity>) .like(root.get("nmDepartment"), "%" + nmDepartment + "%");
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmDepartment"), nmDepartment); }
}
static void deleteBy(Integer id) {
}
static Specification<DepartmentEntity> nmDepartmentLike(String nmDepartment) {
return (nmDepartment == null || nmDepartment.isEmpty()) ?
null :
(Specification<DepartmentEntity>)
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmDepartment"), "%" + nmDepartment + "%");
}
} }

View File

@@ -0,0 +1,125 @@
package com.example.rhizome.app.presentation.controller;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.model.LoginUser;
import com.example.rhizome.app.domain.service.DeleteDepartment;
import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.domain.service.SearchEmployee;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
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.DepartmentForm;
import com.example.rhizome.app.presentation.form.LoginUserForm;
import com.example.rhizome.app.presentation.form.MessageForm;
/**
* 削除処理のコントロータ
*/
@Controller
public class DeleteDepartmentController {
// ログ出力用インスタンス
private final static Logger LOGGER = Logger.getLogger(DeleteDepartmentController.class.getName());
// エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession;
DeleteDepartment deleteDepartment;
SearchDepartment searchDepartment;
SearchEmployee searchEmployee;
@Autowired
public DeleteDepartmentController(DeleteDepartment deleteDepartment, SearchDepartment searchDepartment,
HttpSession httpSession, SearchEmployee searchEmployee) {
this.httpSession = httpSession;
this.deleteDepartment = deleteDepartment;
this.searchDepartment = searchDepartment;
this.searchEmployee = searchEmployee;
}
/**
* 削除処理のコントローラ
*
* @param idEmployee 削除対象のemployeeId
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = DELETE_DEPARTMENT, method = RequestMethod.POST)
public String deleteDepartment(@RequestParam("idDepartment") Integer idDepartment, Model model) {
try {
// 部署一覧を取得し、画面に返す用のクラスに詰め替える
// 作成した部署一覧をセット
model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll()));
// 削除処理実施
deleteExec(
model,
idDepartment,
LoginUserForm.convertTo((LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER)));
// 検索画面に遷移
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO_FORM_EMPTY;
} catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
/**
* 削除処理実施
*
* @param model ビューにデータを渡すためのコンテナ
* @param idEmployee 削除対象のemployeeId
* @param loginUser ログインユーザー情報
*/
private void deleteExec(Model model, Integer idDepartment, LoginUser loginUser) {
final String DELETE_COMPLETE = "削除しました。";
final String ID_TO_DELETED_IS_UNKNOWN = "削除対象のIDが不明です。";
final String YOU_CANNOT_DELETE_A_DEPARTMENT_THAT_HAS_ONE_OR_MORE_MEMBERS_ASSIGNED_TO_IT = "1名以上が所属している部署は削除出来ません。";
if (searchDepartment.searchDepartmentByIdDepartment(idDepartment).isEmpty()) {
// エラーメッセージをセット
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(ID_TO_DELETED_IS_UNKNOWN));
return;
}
if (!searchEmployee.searchEmployeeByIdDepartment(idDepartment).isEmpty()) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR,
new MessageForm(YOU_CANNOT_DELETE_A_DEPARTMENT_THAT_HAS_ONE_OR_MORE_MEMBERS_ASSIGNED_TO_IT));
return;
}
// 削除を実施
deleteDepartment.deleteDepartment(idDepartment);
// 削除完了したメッセージをセット
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(DELETE_COMPLETE));
}
}

View File

@@ -51,7 +51,7 @@ public class TransitionTargetPageNameKeyword {
// Controller // Controller
public static final String SELECT_DEPARTMENT_INFO = "/selectDepartmentInfo"; public static final String SELECT_DEPARTMENT_INFO = "/selectDepartmentInfo";
public static final String SELECT_DEPARTMENT_INFO_FORM_EMPTY = "/departmentAll"; public static final String SELECT_DEPARTMENT_INFO_FORM_EMPTY = "/departmentAll";
public static final String DELETE_DEPARTMENT = "a"; public static final String DELETE_DEPARTMENT = "/deleteDepartment";
public static final String INSERT_DEPARTMENT_INPUT = "i"; public static final String INSERT_DEPARTMENT_INPUT = "i";
public static final String INSERT_DEPARTMENT_CONFIRM = "u"; public static final String INSERT_DEPARTMENT_CONFIRM = "u";
public static final String INSERT_DEPARTMENT = "e"; public static final String INSERT_DEPARTMENT = "e";
@@ -81,7 +81,8 @@ public class TransitionTargetPageNameKeyword {
SHOW_UPDATE_EMPLOYEE, SHOW_UPDATE_EMPLOYEE,
UPDATE_EMPLOYEE_RESULT, UPDATE_EMPLOYEE_RESULT,
SELECT_DEPARTMENT_INFO, SELECT_DEPARTMENT_INFO,
SELECT_DEPARTMENT_INFO_FORM_EMPTY); SELECT_DEPARTMENT_INFO_FORM_EMPTY,
DELETE_DEPARTMENT);
} }
/** /**