4 Commits

Author SHA1 Message Date
s-sakiyama
182f901a4d コメントの修正
社員のものからコピーしたままになっていたので部署に合うように変更
2026-10-14 16:33:42 +09:00
s-sakiyama
0f1141e689 第3段階 部署更新機能 2026-10-14 15:48:42 +09:00
s-sakiyama
815d957a31 第2段階 部署削除機能 2026-10-13 16:26:40 +09:00
s-sakiyama
4c134b81b8 第一段階目 部署検索機能 2026-10-13 10:23:24 +09:00
39 changed files with 782 additions and 1015 deletions

View File

@@ -1,41 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

1
.gitignore vendored
View File

@@ -1 +0,0 @@
/target/

View File

@@ -1,37 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>em-spring</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>

View File

@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry excluding="**/node_modules/*|**/*.min.js|**/bower_components/*" kind="src" path="target/m2e-wtp/web-resources"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>

View File

@@ -1,6 +0,0 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@@ -1,11 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17

View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="EM-Spring-0.0.1-SNAPSHOT">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="EM-Spring"/>
<property name="java-output-path" value="/em-spring/target/classes"/>
</wb-module>
</project-modules>

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="17"/>
<installed facet="jst.web" version="4.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

View File

@@ -1 +0,0 @@
org.eclipse.wst.jsdt.launching.baseBrowserLibrary

View File

@@ -1 +0,0 @@
Window

View File

@@ -1,2 +0,0 @@
disabled=06target
eclipse.preferences.version=1

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

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

View File

@@ -3,18 +3,15 @@ package com.example.rhizome.app.domain.service;
import java.util.List; import java.util.List;
import com.example.rhizome.app.domain.model.Department; import com.example.rhizome.app.domain.model.Department;
import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.LoginUser;
import com.example.rhizome.app.domain.model.SearchConditionDepartment; import com.example.rhizome.app.domain.model.SearchConditionDepartment;
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); List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment);
LoginUser searchLoginUser(String mailAddress); Department searchDepartmentByIdDepartment(Integer idDepartment);
Employee searchEmployeeByIdEmployee(Integer idEmployee);
} }

View File

@@ -3,5 +3,6 @@ package com.example.rhizome.app.domain.service;
import com.example.rhizome.app.domain.model.Department; import com.example.rhizome.app.domain.model.Department;
public interface UpdateDepartment { public interface UpdateDepartment {
void updateDepartment(Department department); void updateDepartment(Department beforeDepartment, Department updateDepartment);
} }

View File

@@ -24,9 +24,10 @@ public class DeleteDepartmentImpl implements DeleteDepartment {
/** /**
* idDepartment を元に department データを削除 * idDepartment を元に department データを削除
* *
* @param idDepartment 削除対象のidDepartmnet * @param idDepartment 削除対象のidDepartment
*/ */
public void deleteDepartment(Integer idDepartment) { public void deleteDepartment(Integer idDepartment) {
departmentRepository.deleteById(idDepartment); departmentRepository.deleteById(idDepartment);
} }
} }

View File

@@ -1,34 +0,0 @@
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.model.Department;
import com.example.rhizome.app.domain.service.RegisterDepartment;
import com.example.rhizome.app.infra.entity.DepartmentEntity;
import com.example.rhizome.app.infra.repository.DepartmentRepository;
/**
* Department テーブルの登録系の機能を集約させるサービスクラスです。
*/
@Service
@Transactional
public class RegisterDepartmentImpl implements RegisterDepartment {
DepartmentRepository departmentRepository;
@Autowired
public RegisterDepartmentImpl(DepartmentRepository departmentRepository) {
this.departmentRepository = departmentRepository;
}
/**
* employee インスタンスの内容を登録する
*
* @param employee 登録対象のデータ
*/
public void registerDepartment(Department department) {
departmentRepository.save(DepartmentEntity.convertFrom(department));
}
}

View File

@@ -8,19 +8,18 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; 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.Employee;
import com.example.rhizome.app.domain.model.LoginUser;
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;
/** /**
* Department テーブル検索系の機能を集約させるサービスクラスです。 * 部署情報検索系の機能を集約させるサービスクラスです。
*/ */
@Service @Service
@Transactional @Transactional
public class SearchDepartmentImpl implements SearchDepartment { public class SearchDepartmentImpl implements SearchDepartment {
DepartmentRepository departmentRepository; DepartmentRepository departmentRepository;
/** /**
@@ -81,16 +80,9 @@ public class SearchDepartmentImpl implements SearchDepartment {
} }
@Override //idDepartmentに合致するレコード取得
public LoginUser searchLoginUser(String mailAddress) { public Department searchDepartmentByIdDepartment(Integer idDepartment) {
// TODO 自動生成されたメソッド・スタブ return DepartmentEntity
return null; .createDepartment(departmentRepository.findByIdDepartment(idDepartment).orElse(new DepartmentEntity()));
} }
@Override
public Employee searchEmployeeByIdEmployee(Integer idEmployee) {
// TODO 自動生成されたメソッド・スタブ
return null;
}
} }

View File

@@ -5,12 +5,17 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; 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.service.UpdateDepartment;
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;
/**
* department の更新系の機能を集約させるサービスクラスです。
*/
@Service @Service
@Transactional @Transactional
public class UpdateDepartmentImpl { public class UpdateDepartmentImpl implements UpdateDepartment {
DepartmentRepository departmentRepository; DepartmentRepository departmentRepository;
@Autowired @Autowired
@@ -18,9 +23,31 @@ public class UpdateDepartmentImpl {
this.departmentRepository = departmentRepository; this.departmentRepository = departmentRepository;
} }
public void updateDepartment(Department department) { /**
// ★考える:Model を Entity に変換(DepartmentEntity.convertFrom)して、Repository の save に渡す * department の情報を元に department table のレコードを更新する
departmentRepository.save(DepartmentEntity.convertFrom(department)); *
* @param beforeDepartment 更新前のデータ
* @param updateDepartment 更新後のデータ
*/
public void updateDepartment(Department beforeDepartment, Department updateDepartment) {
// TODO 自動生成されたメソッド・スタブ
departmentRepository.save(DepartmentEntity.convertFrom(mergeDepartment(beforeDepartment, updateDepartment)));
}
/**
* 更新前のデータと更新対象のデータをマージする
*
* @param beforeDepartment 更新前のデータ
* @param updateDepartment 更新対象のデータ
* @return マージしたデータ
*/
private Department mergeDepartment(Department beforeDepartment, Department updateDepartment) {
return new Department(
updateDepartment.getIdDepartment(),
updateDepartment.getNmDepartment());
} }
} }

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,59 @@ 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()));
}
public static Department createDepartment(DepartmentEntity DepartmentEntity) {
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
return 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,13 @@
package com.example.rhizome.app.infra.repository; package com.example.rhizome.app.infra.repository;
import com.example.rhizome.app.infra.entity.DepartmentEntity; import java.util.Optional;
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 +22,35 @@ 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) {
}
//idで検索
Optional<DepartmentEntity> findByIdDepartment(Integer idDepartment);
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

@@ -1,5 +1,7 @@
package com.example.rhizome.app.presentation.controller; 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.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -12,22 +14,26 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import com.example.rhizome.app.domain.model.SearchConditionDepartment; 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.DeleteDepartment;
import com.example.rhizome.app.domain.service.SearchDepartment; import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.domain.service.SearchEmployee; 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.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.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.DepartmentForm; import com.example.rhizome.app.presentation.form.DepartmentForm;
import com.example.rhizome.app.presentation.form.LoginUserForm;
import com.example.rhizome.app.presentation.form.MessageForm; import com.example.rhizome.app.presentation.form.MessageForm;
/** /**
* 削除処理のコントロータ * 削除処理のコントローラ
*/ */
@Controller @Controller
public class DeleteDepartmentController { public class DeleteDepartmentController {
// ログ出力用インスタンス // ログ出力用インスタンス
private final static Logger LOGGER = Logger.getLogger(DeleteEmployeeController.class.getName()); private final static Logger LOGGER = Logger.getLogger(DeleteDepartmentController.class.getName());
// エラーメッセージ用の定数フィールド // エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
@@ -35,7 +41,7 @@ public class DeleteDepartmentController {
HttpSession httpSession; HttpSession httpSession;
DeleteDepartment deleteDepartment; DeleteDepartment deleteDepartment;
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
SearchEmployee searchEmployee; // 所属社員の確認に使う(既存) SearchEmployee searchEmployee;
@Autowired @Autowired
public DeleteDepartmentController(DeleteDepartment deleteDepartment, SearchDepartment searchDepartment, public DeleteDepartmentController(DeleteDepartment deleteDepartment, SearchDepartment searchDepartment,
@@ -53,13 +59,10 @@ public class DeleteDepartmentController {
* @param model ビューにデータを渡すためのコンテナ * @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面 * @return 遷移先の画面
*/ */
@PermissionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.DELETE_DEPARTMENT, method = RequestMethod.POST) @SessionCheck
public String deleteDepartment(@RequestParam(value = "idDepartment", required = false) Integer idDepartment, @RequestMapping(value = DELETE_DEPARTMENT, method = RequestMethod.POST)
Model model) { public String deleteDepartment(@RequestParam("idDepartment") Integer idDepartment, Model model) {
final String UNKNOWN_ID = "削除対象のIDが不明です。";
try { try {
// 部署一覧を取得し、画面に返す用のクラスに詰め替える // 部署一覧を取得し、画面に返す用のクラスに詰め替える
// 作成した部署一覧をセット // 作成した部署一覧をセット
@@ -67,20 +70,19 @@ public class DeleteDepartmentController {
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll())); DepartmentForm.convertFrom(searchDepartment.selectAll()));
if (idDepartment == null
|| searchDepartment.searchBy(new SearchConditionDepartment(idDepartment, null)) == null) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(UNKNOWN_ID));
}
// 削除処理実施 // 削除処理実施
deleteExec(model, idDepartment); deleteExec(
model,
idDepartment,
LoginUserForm.convertTo((LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER)));
// 検索画面に遷移 // 検索画面に遷移
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_FORM_EMPTY; return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO_FORM_EMPTY;
} catch (Exception e) { } catch (Exception e) {
// ログイン情報の破棄 // ログイン情報の破棄
httpSession.invalidate(); httpSession.invalidate();
e.printStackTrace(); e.printStackTrace();
// エラーログ出力 // エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
@@ -93,23 +95,26 @@ public class DeleteDepartmentController {
* 削除処理実施 * 削除処理実施
* *
* @param model ビューにデータを渡すためのコンテナ * @param model ビューにデータを渡すためのコンテナ
* @param idEmployee 削除対象のDepartmentId * @param idDepartment 削除対象のdepartmentId
* @param loginUser ログインユーザー情報
*/ */
private void deleteExec(Model model, Integer idDepartment) { private void deleteExec(Model model, Integer idDepartment, LoginUser loginUser) {
final String DELETE_DPARTMENT_TARGET_ID_CAN_NOT_DELETE = "1名以上が所属している部署は削除出来ません。";
final String DELETE_COMPLETE = "削除しました。"; 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名以上が所属している部署は削除出来ません。";
// 削除対象部署が1名以上所属しているかチェック if (searchDepartment.searchDepartmentByIdDepartment(idDepartment) == null) {
if (!searchEmployee.searchEmployeeByIdDepartment(idDepartment).isEmpty()) {
// 削除対象だった場合
// エラーメッセージをセット // エラーメッセージをセット
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(ID_TO_DELETED_IS_UNKNOWN));
new MessageForm(DELETE_DPARTMENT_TARGET_ID_CAN_NOT_DELETE));
// 検索画面に遷移
return; 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); deleteDepartment.deleteDepartment(idDepartment);

View File

@@ -1,21 +1,6 @@
package com.example.rhizome.app.presentation.controller; package com.example.rhizome.app.presentation.controller;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*;
import java.util.Objects;
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.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
@@ -27,9 +12,22 @@ import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTa
import com.example.rhizome.app.presentation.form.DepartmentForm; import com.example.rhizome.app.presentation.form.DepartmentForm;
import com.example.rhizome.app.presentation.form.LoginUserForm; import com.example.rhizome.app.presentation.form.LoginUserForm;
import com.example.rhizome.app.presentation.form.MessageForm; import com.example.rhizome.app.presentation.form.MessageForm;
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 javax.servlet.http.HttpSession;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.DELETE_EMPLOYEE;
/** /**
* 削除処理のコントローラ * 削除処理のコントロータ
*/ */
@Controller @Controller
public class DeleteEmployeeController { public class DeleteEmployeeController {

View File

@@ -1,125 +0,0 @@
package com.example.rhizome.app.presentation.controller;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*;
import java.util.ArrayList;
import java.util.List;
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.app.domain.service.RegisterDepartment;
import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.domain.service.impl.RegisterDepartmentImpl;
import com.example.rhizome.app.domain.service.impl.SearchDepartmentImpl;
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.InsertDepartmentForm;
import com.example.rhizome.app.presentation.form.MessageForm;
@Controller
public class InsertDepartmentController {
// ログ出力用インスタンス
private final static Logger LOGGER = Logger.getLogger(InsertEmployeeController.class.getName());
// エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession;
RegisterDepartment registerDepartment;
SearchDepartment searchDepartment;
@Autowired
public InsertDepartmentController(HttpSession httpSession, RegisterDepartmentImpl registerDepartment,
SearchDepartmentImpl searchDepartment) {
this.httpSession = httpSession;
this.registerDepartment = registerDepartment;
this.searchDepartment = searchDepartment;
}
@ModelAttribute
public InsertDepartmentForm insertDepartmentForm() {
return new InsertDepartmentForm();
}
@RequestMapping(value = INSERT_DEPARTMENT_INPUT, method = RequestMethod.POST)
public String insertDepartment(InsertDepartmentForm insertDepartmentForm, Model model) {
try {
model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(
searchDepartment.selectAll()));
List<String> error2 = validateParameter2(
insertDepartmentForm.getIdDepartment(),
insertDepartmentForm.getNmDepartment());
// エラーが1件以上有る場合
if (!error2.isEmpty()) {
// エラー内容を画面に表示
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR,
new MessageForm(String.join(", ", error2) + "が不正です。"));
// 登録画面に遷移
return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML;
}
// 登録処理
registerDepartment.registerDepartment(InsertDepartmentForm.convertToo(insertDepartmentForm));
// 登録結果画面に遷移
return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_RESULT_HTML;
} catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
private List<String> validateParameter2(
Integer departmentId,
String departmentNm) {
final String DEPARTMENT_ID_NULL_BLANK = "所属部署";
final String DEPARTMENT_NAME_NULL_BLANK = "部署名";
List<String> error2 = new ArrayList<>();
// null or 空文字判定
if (departmentId == null) {
// エラー内容を追加
error2.add(DEPARTMENT_ID_NULL_BLANK);
}
// null or 空文字判定
if (isNullOrBlank(departmentNm)) {
// エラー内容を追加
error2.add(DEPARTMENT_NAME_NULL_BLANK);
}
return error2;
}
private static boolean isNullOrBlank(String str) {
if (null == str) {
return true;
}
return str.isBlank();
}
}

View File

@@ -15,13 +15,16 @@ import org.springframework.web.bind.annotation.RequestMethod;
import com.example.rhizome.aop.aspect.PermissionCheck; import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.service.SearchDepartment; 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.PageReturnAttributeKeyword;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword; import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.DepartmentForm; import com.example.rhizome.app.presentation.form.DepartmentForm;
import com.example.rhizome.app.presentation.form.SearchConditionDepartmentForm; import com.example.rhizome.app.presentation.form.SearchConditionDepartmentForm;
/**
* 部署画面用コントローラ リスト全件表示、検索表示、更新、削除が可能
*/
@Controller @Controller
public class SelectDepartmentController { public class SelectDepartmentController {
// ログ出力用インスタンス // ログ出力用インスタンス
@@ -31,11 +34,14 @@ public class SelectDepartmentController {
HttpSession httpSession; HttpSession httpSession;
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
SearchEmployeeInfo searchEmployeeInfo;
@Autowired @Autowired
public SelectDepartmentController(HttpSession httpSession, SearchDepartment searchDepartment) { public SelectDepartmentController(HttpSession httpSession, SearchDepartment searchDepartment,
SearchEmployeeInfo searchEmployeeInfo) {
this.httpSession = httpSession; this.httpSession = httpSession;
this.searchDepartment = searchDepartment; this.searchDepartment = searchDepartment;
this.searchEmployeeInfo = searchEmployeeInfo;
} }
@ModelAttribute @ModelAttribute
@@ -44,17 +50,16 @@ public class SelectDepartmentController {
} }
/** /**
* 部署検索画面表示処理コントローラ * 社員検索画面表示処理コントローラ
* *
* @param searchConditionEmployeeForm 検索画面のフォーム * @param searchConditionDepartmentForm 検索画面のフォーム
* @param model ビューにデータを渡すためのコンテナ * @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面 * @return 遷移先の画面
*/ */
@PermissionCheck @PermissionCheck
@SessionCheck @SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT, method = RequestMethod.POST) @RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO, method = RequestMethod.POST)
public String select(SearchConditionDepartmentForm searchConditionDepartmentForm, Model model) { public String select(SearchConditionDepartmentForm searchConditionDepartmentForm, Model model) {
try { try {
// 部署一覧を取得し、画面に返す用のクラスに詰め替える // 部署一覧を取得し、画面に返す用のクラスに詰め替える
@@ -62,13 +67,11 @@ public class SelectDepartmentController {
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll())); DepartmentForm.convertFrom(searchDepartment.selectAll()));
// 検索条件を元に検索を実施
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom( model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(
searchDepartment.searchBy(SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm)))); searchDepartment
//部分一致検索 .searchByWithLike(SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm))));
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(
searchDepartment.searchByWithLike(
SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm))));
// 検索ページに遷移 // 検索ページに遷移
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML; return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
@@ -76,7 +79,6 @@ public class SelectDepartmentController {
} catch (Exception e) { } catch (Exception e) {
// ログイン情報の破棄 // ログイン情報の破棄
httpSession.invalidate(); httpSession.invalidate();
e.printStackTrace(); e.printStackTrace();
// エラーログ出力 // エラーログ出力
@@ -96,7 +98,7 @@ public class SelectDepartmentController {
*/ */
@PermissionCheck @PermissionCheck
@SessionCheck @SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_FORM_EMPTY, method = RequestMethod.POST) @RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO_FORM_EMPTY, method = RequestMethod.POST)
public String select(Model model) { public String select(Model model) {
// 部署一覧を取得し、画面に返す用のクラスに詰め替える // 部署一覧を取得し、画面に返す用のクラスに詰め替える
@@ -105,17 +107,6 @@ public class SelectDepartmentController {
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll())); DepartmentForm.convertFrom(searchDepartment.selectAll()));
// 検索条件を元に検索を実施
// model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
// DepartmentForm.convertFrom(
// searchDepartment.searchBy(
// SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm()))));
//部分一致検索
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(
searchDepartment.searchByWithLike(
SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm()))));
// 検索ページに遷移 // 検索ページに遷移
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML; return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
} }

View File

@@ -1,6 +1,5 @@
package com.example.rhizome.app.presentation.controller; package com.example.rhizome.app.presentation.controller;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -9,66 +8,67 @@ import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; 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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import com.example.rhizome.app.domain.model.Department; import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.app.domain.model.SearchConditionDepartment; import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.service.RegisterDepartment;
import com.example.rhizome.app.domain.service.SearchDepartment; import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.domain.service.impl.RegisterDepartmentImpl; import com.example.rhizome.app.domain.service.SearchEmployeeInfo;
import com.example.rhizome.app.domain.service.impl.SearchDepartmentImpl;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword; import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword; import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.MessageForm; import com.example.rhizome.app.presentation.form.DepartmentForm;
import com.example.rhizome.app.presentation.form.UpdateDepartmentForm; import com.example.rhizome.app.presentation.form.SearchConditionEmployeeForm;
/**
* 更新対象の Department が存在するか確認する為のコントローラ
*/
@Controller @Controller
public class UpdateDepartmentController { public class UpdateDepartmentController {
// ログ出力用インスタンス // ログ出力用インスタンス
private final static Logger LOGGER = Logger.getLogger(UpdateEmployeeController.class.getName()); private final static Logger LOGGER = Logger.getLogger(UpdateDepartmentController.class.getName());
// エラーメッセージ用の定数フィールド // エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession; HttpSession httpSession;
RegisterDepartment registerDepartment;
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
SearchEmployeeInfo searchEmployeeInfo;
@Autowired @Autowired
public UpdateDepartmentController(HttpSession httpSession, RegisterDepartmentImpl registerDepartment, public UpdateDepartmentController(HttpSession httpSession, SearchDepartment searchDepartment,
SearchDepartmentImpl searchDepartment) { SearchEmployeeInfo searchEmployeeInfo) {
this.httpSession = httpSession; this.httpSession = httpSession;
this.registerDepartment = registerDepartment;
this.searchDepartment = searchDepartment; this.searchDepartment = searchDepartment;
this.searchEmployeeInfo = searchEmployeeInfo;
} }
@RequestMapping(value = TransitionTargetPageNameKeyword.SHOW_UPDATE_DEPARTMENT, method = RequestMethod.POST) @ModelAttribute
public String showUpdateDepartment(@RequestParam("idDepartment") Integer idDepartment, Model model) { public SearchConditionEmployeeForm searchConditionEmployeeForm() {
return new SearchConditionEmployeeForm();
}
/**
* 更新対象の department が存在するか確認する為のコントローラ
*
* @param idDepartment 更新対象の employee の id
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SHOW_UPDATE_DAPERTMENT, method = RequestMethod.POST)
public String showUpdateDepatment(@RequestParam("idDepartment") Integer idDepartment, Model model) {
final String UPDATE_TARGET_ID_NOT_FOUND = "更新対象のデータが見つかりません。"; final String UPDATE_TARGET_ID_NOT_FOUND = "更新対象のデータが見つかりません。";
try { try {
// ★① searchDepartment.searchBy(new SearchConditionDepartment(idDepartment, null)) で対象を検索 // 部署一覧を取得し画面に返す値としてセット
// ★② 結果が空なら MESSAGE_ERROR を載せて "forward:" + SELECT_DEPARTMENT_FORM_EMPTY model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
// ★③ あれば UpdateDepartmentForm.convertFrom(結果の先頭) を DepartmentForm.convertFrom(searchDepartment.searchDepartmentByIdDepartment(idDepartment)));
// UPDATE_DEPARTMENT_FORM という名前で model に載せ、UPDATE_DEPARTMENT_INPUT_HTML を返す
List<Department> DepartmentList = searchDepartment.searchBy(
new SearchConditionDepartment(idDepartment, null));
// DBに更新対象のデータがあるか
if (DepartmentList.isEmpty()) {
// ない場合はエラーメッセージをセットして検索画面に戻る
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR,
new MessageForm(UPDATE_TARGET_ID_NOT_FOUND));
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_FORM_EMPTY;
}
// 更新画面に遷移
model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM,
UpdateDepartmentForm.convertFrom(DepartmentList.get(0)));
// Update画面に遷移 // Update画面に遷移
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML; return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
} catch (Exception e) { } catch (Exception e) {
// ログイン情報の破棄 // ログイン情報の破棄
httpSession.invalidate(); httpSession.invalidate();

View File

@@ -12,14 +12,22 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; 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.model.Department;
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.domain.service.SearchEmployee;
import com.example.rhizome.app.domain.service.UpdateDepartment; import com.example.rhizome.app.domain.service.UpdateDepartment;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword; import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword; import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.DepartmentForm; import com.example.rhizome.app.presentation.form.DepartmentForm;
import com.example.rhizome.app.presentation.form.MessageForm; import com.example.rhizome.app.presentation.form.MessageForm;
import com.example.rhizome.app.presentation.form.UpdateDepartmentForm; import com.example.rhizome.app.presentation.form.UpdateDepartmentInfoForm;
/**
* employee を更新して結果を返す為のコントローラ
*/
@Controller @Controller
public class UpdateDepartmentResultController { public class UpdateDepartmentResultController {
@@ -30,68 +38,92 @@ public class UpdateDepartmentResultController {
HttpSession httpSession; HttpSession httpSession;
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
SearchEmployee searchEmployee;
UpdateDepartment updateDepartment; UpdateDepartment updateDepartment;
@Autowired @Autowired
public UpdateDepartmentResultController(HttpSession httpSession, SearchDepartment searchDepartment, public UpdateDepartmentResultController(HttpSession httpSession, SearchDepartment searchDepartment,
UpdateDepartment updateDepartment) { SearchEmployee searchEmployee, UpdateDepartment updateDepartment) {
this.httpSession = httpSession; this.httpSession = httpSession;
this.searchDepartment = searchDepartment; this.searchDepartment = searchDepartment;
this.searchEmployee = searchEmployee;
this.updateDepartment = updateDepartment; this.updateDepartment = updateDepartment;
} }
/**
* 更新結果画面表示処理
*
* @param updateDepartmentInfoForm 更新画面のフォーム
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_RESULT, method = RequestMethod.POST) @RequestMapping(value = TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_RESULT, method = RequestMethod.POST)
public String departmentUpdateResult(@ModelAttribute UpdateDepartmentForm updateDepartmentForm, Model model) { public String employeeUpdateResult(@ModelAttribute UpdateDepartmentInfoForm updateDepartmentInfoForm, Model model) {
final String DEPARTMENT_WITH_THE_SAME_NAME = "既に同名の部署が存在するか、値が変更されていません。";
final String NOTHING = "項目が空欄です。"; final String NOTHING = "項目が空欄です。";
final String DUPLICATION = "既に同名の部署が存在するか、値が変更されていません。";
final String NO_TARGET = "更新対象のデータが見つかりません。"; final String NO_TARGET = "更新対象のデータが見つかりません。";
final String UPDATE_COMPLETE = "更新が完了しました。"; final String UPDATE_COMPLETE = "更新が完了しました。";
try { try {
// 部署一覧取得 // 部署一覧取得
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(searchDepartment.selectAll())); model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll()));
// 既に登録済みの部署名が存在するか
updateDepartmentForm.hasRequiredValue(); if (searchDepartment.searchBy(
new SearchConditionDepartment(null, updateDepartmentInfoForm.getNmDepartment())).size() != 0) {
if(updateDepartmentForm.hasRequiredValue() == false) { System.out.println("同一部署名");
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NOTHING));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, updateDepartmentForm);
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
}
if(searchDepartment.searchBy(null) != null){
// 存在する場合はエラーメッセージを設定して更新入力画面に遷移 // 存在する場合はエラーメッセージを設定して更新入力画面に遷移
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR,
model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, updateDepartmentForm); new MessageForm(DEPARTMENT_WITH_THE_SAME_NAME));
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, updateDepartmentInfoForm);
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
}
// 画面から渡ってきた値が必須を満たしているか(空白チェック)
if (!UpdateDepartmentInfoForm.hasErrorParameter(updateDepartmentInfoForm)) {
System.out.println("部署必須否");
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NOTHING));
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, updateDepartmentInfoForm);
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML; return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
} }
// 更新前のデータを取得
if(searchDepartment.searchBy(null) != null) { Department beforeDepartment = searchDepartment
.searchDepartmentByIdDepartment(updateDepartmentInfoForm.getIdDepartment());
if (beforeDepartment.getIdDepartment() == null) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NO_TARGET)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NO_TARGET));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, updateDepartmentForm); model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, updateDepartmentInfoForm);
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML; return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
} }
// 更新結果のメッセージを画面にセットし一覧画面に遷移 // 画面用の型からビジネスロジック用のモデルに変換し、Updateを実行
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(UPDATE_COMPLETE)); updateDepartment.updateDepartment(beforeDepartment,
updateDepartmentInfoForm.convertTo(updateDepartmentInfoForm));
// forward 先で不用意な動作をしないために UpdateEmployeeInfoForm をクリア // 更新結果のメッセージを画面にセットし一覧画面に遷移
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_FORM_EMPTY; model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(UPDATE_COMPLETE));
// forward 先で不用意な動作をしないために updateDepartmentInfoForm をクリア
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO_FORM_EMPTY;
} catch (Exception e) { } catch (Exception e) {
// 他と同じ
// ログイン情報の破棄 // ログイン情報の破棄
httpSession.invalidate(); httpSession.invalidate();
e.printStackTrace(); e.printStackTrace();
// エラーログ出力 // エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移 // エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML; return TransitionTargetPageNameKeyword.ERROR_HTML;
} }
} }
} }

View File

@@ -5,15 +5,16 @@ package com.example.rhizome.app.presentation.controller.pageproperty;
*/ */
public class PageReturnAttributeKeyword { public class PageReturnAttributeKeyword {
public static final String MESSAGE_ERROR = "messageError"; public static final String MESSAGE_ERROR = "messageError";
public static final String MESSAGE_INFO = "messageInfo"; public static final String MESSAGE_INFO = "messageInfo";
public static final String DEPARTMENT_FORM_LIST = "departmentFormList"; public static final String DEPARTMENT_FORM_LIST = "departmentFormList";
public static final String UPDATE_DEPARTMENT_FORM = "updateDepartmentForm"; public static final String UPDATE_EMPLOYEE_INFO_FORM = "updateEmployeeInfoForm";
public static final String UPDATE_EMPLOYEE_INFO_FORM = "updateEmployeeInfoForm";
public static final String INSERT_EMPLOYEE_FORM = "insertEmployeeForm"; public static final String INSERT_EMPLOYEE_FORM = "insertEmployeeForm";
public static final String LOGIN_INFO_FORM = "loginInfoForm"; public static final String LOGIN_INFO_FORM = "loginInfoForm";
public static final String UPDATE_PERSONAL_EMPLOYEE_USER_FORM = "updatePersonalEmployeeUserForm"; public static final String UPDATE_PERSONAL_EMPLOYEE_USER_FORM = "updatePersonalEmployeeUserForm";
public static final String EMPLOYEE_INFO_FORM_LIST = "employeeInfoFormList"; public static final String EMPLOYEE_INFO_FORM_LIST = "employeeInfoFormList";
public static final String UPDATE_DEPARTMENT_INFO_FORM = "updateDepartmentInfoForm";
} }

View File

@@ -49,17 +49,15 @@ public class TransitionTargetPageNameKeyword {
// HTML // HTML
public static final String SELECT_DEPARTMENT_HTML = "selectDepartment"; public static final String SELECT_DEPARTMENT_HTML = "selectDepartment";
public static final String UPDATE_DEPARTMENT_INPUT_HTML = "updateDepartmentInput"; public static final String UPDATE_DEPARTMENT_INPUT_HTML = "updateDepartmentInput";
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";
// Controller // Controller
public static final String SELECT_DEPARTMENT = "/selectDepartment"; public static final String SELECT_DEPARTMENT_INFO = "/selectDepartmentInfo";
public static final String SELECT_DEPARTMENT_FORM_EMPTY = "/selectAll2"; public static final String SELECT_DEPARTMENT_INFO_FORM_EMPTY = "/departmentAll";
public static final String SHOW_UPDATE_DEPARTMENT = "/showUpdateDepartment";
public static final String UPDATE_DEPARTMENT_RESULT = "/updateDepartmentResult";
public static final String INSERT_DEPARTMENT_INPUT = "/insertDepartmentInput";
public static final String DELETE_DEPARTMENT = "/deleteDepartment"; public static final String DELETE_DEPARTMENT = "/deleteDepartment";
public static final String INSERT_DEPARTMENT_INPUT = "/";
public static final String INSERT_DEPARTMENT_CONFIRM = "/";
public static final String INSERT_DEPARTMENT = "/";
public static final String SHOW_UPDATE_DAPERTMENT = "/showUpdateDepartment";
public static final String UPDATE_DEPARTMENT_RESULT = "/updateDepartmentResult";
/** /**
* 管理者向けのページリストを返す * 管理者向けのページリストを返す
@@ -83,12 +81,11 @@ public class TransitionTargetPageNameKeyword {
SELECT_EMPLOYEE_INFO_FORM_EMPTY, SELECT_EMPLOYEE_INFO_FORM_EMPTY,
SHOW_UPDATE_EMPLOYEE, SHOW_UPDATE_EMPLOYEE,
UPDATE_EMPLOYEE_RESULT, UPDATE_EMPLOYEE_RESULT,
SELECT_DEPARTMENT, SELECT_DEPARTMENT_INFO,
SELECT_DEPARTMENT_FORM_EMPTY, SELECT_DEPARTMENT_INFO_FORM_EMPTY,
INSERT_DEPARTMENT_INPUT, DELETE_DEPARTMENT,
SHOW_UPDATE_DEPARTMENT, SHOW_UPDATE_DAPERTMENT,
SHOW_UPDATE_DEPARTMENT); UPDATE_DEPARTMENT_RESULT);
} }
/** /**

View File

@@ -1,24 +0,0 @@
package com.example.rhizome.app.presentation.form;
import com.example.rhizome.app.domain.model.Department;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class InsertDepartmentForm {
private String nmEmployee;
private Integer idDepartment;
private String nmDepartment;
public static Department convertToo(InsertDepartmentForm insertDepartmentForm) {
return new Department(
insertDepartmentForm.getIdDepartment(),
insertDepartmentForm.getNmDepartment());
}
}

View File

@@ -6,38 +6,46 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/**
* 画面から渡ってきた検索条件をまとめ、再度画面に表示する為のクラス
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class SearchConditionDepartmentForm { public class SearchConditionDepartmentForm {
/** /**
* 部署ID * 部署ID
*/ */
private Integer idDepartment; private Integer idDepartment;
/** /**
* 部署名 * 部署名
*/ */
private String nmDepartment; private String nmDepartment;
/**
* business 層の SearchConditionDepartment クラスから画面用(presentation 層)の SearchConditionDepartmentForm に
* 変換します。
*
* @param searchConditionDepartment business 層の SearchConditionDepartment インスタンス
* @return 画面用(presentation 層)の SearchConditionDepartmentForm インスタンス
*/
public static SearchConditionDepartmentForm convertFrom(SearchConditionDepartment searchConditionDepartment) { public static SearchConditionDepartmentForm convertFrom(SearchConditionDepartment searchConditionDepartment) {
return new SearchConditionDepartmentForm( return new SearchConditionDepartmentForm(
searchConditionDepartment.getIdDepartment(), searchConditionDepartment.getIdDepartment(),
searchConditionDepartment.getNmDepartment() searchConditionDepartment.getNmDepartment());
); }
}
/** /**
* 画面用(presentation 層)の SearchConditionEmployeeForm クラスから business 層の SearchConditionEmployee クラスに * 画面用(presentation 層)の SearchConditionDepartmentForm クラスから business 層の SearchConditionDepartment クラスに
* 変換します。 * 変換します。
* *
* @param searchConditionEmployeeForm 画面用(presentation 層)の SearchConditionEmployeeForm インスタンス * @param searchConditionDepartmentForm 画面用(presentation 層)の SearchConditionDepartmentForm インスタンス
* @return business 層の SearchConditionEmployee インスタンス * @return business 層の SearchConditionDepartment インスタンス
*/ */
public static SearchConditionDepartment convertTo(SearchConditionDepartmentForm searchConditionDepartmentForm) { public static SearchConditionDepartment convertTo(SearchConditionDepartmentForm searchConditionDepartmentForm) {
return new SearchConditionDepartment( return new SearchConditionDepartment(
searchConditionDepartmentForm.getIdDepartment(), searchConditionDepartmentForm.getIdDepartment(),
searchConditionDepartmentForm.getNmDepartment() searchConditionDepartmentForm.getNmDepartment());
); }
}
} }

View File

@@ -1,32 +0,0 @@
package com.example.rhizome.app.presentation.form;
import com.example.rhizome.app.domain.model.Department;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UpdateDepartmentForm {
private Integer idDepartment;
private String nmDepartment;
/** Model(Department) → Form */
public static UpdateDepartmentForm convertFrom(Department department) {
return new UpdateDepartmentForm(department.getIdDepartment(), department.getNmDepartment());
}
/** Form → Model(Department) */
public static Department convertTo(UpdateDepartmentForm form) {
return new Department(form.getIdDepartment(), form.getNmDepartment());
}
/** 必須チェック。true:OK/false:部署ID か部署名が空 */
public boolean hasRequiredValue() {
// ★考える:idDepartment が null でなく、nmDepartment が null でも空白だけでもない
if(idDepartment != null && nmDepartment.isBlank() && nmDepartment.isEmpty());
return false;
}
}

View File

@@ -0,0 +1,91 @@
package com.example.rhizome.app.presentation.form;
import java.util.List;
import com.example.rhizome.app.domain.model.Department;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 画面から渡ってきた更新内容をまとめ、再度画面に表示する為のクラス
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UpdateDepartmentInfoForm {
/**
* 部署ID
*/
private Integer idDepartment;
/**
* 部署名
*/
private String nmDepartment;
/**
* business 層の Department クラスから画面用(presentation 層)の UpdateDepartmentInfoForm に
* 変換します。
*
* @param department business 層の Department インスタンス
* @return 画面用(presentation 層)の UpdateDepartmentInfoForm インスタンス
*/
public static UpdateDepartmentInfoForm convertFrom(Department department) {
return new UpdateDepartmentInfoForm(
department.getIdDepartment(),
department.getNmDepartment());
}
/**
* business 層の Department クラスから画面用(presentation 層)の UpdateDepartmentInfoForm に
* 変換します。(リスト版)
*
* @param departmentList business 層の Department インスタンスのリスト
* @return 画面用(presentation 層)の UpdateDepartmentInfoForm インスタンスのリスト
*/
public static List<UpdateDepartmentInfoForm> convertFrom(List<Department> departmentList) {
return departmentList.stream().map(UpdateDepartmentInfoForm::convertFrom).toList();
}
/**
* 画面用(presentation 層)の UpdateDepartmentInfoForm クラスから business 層の Department クラスに
* 変換します。
*
* @param updateDepartmentInfoForm 画面用(presentation 層)の UpdateDepartmentInfoForm インスタンス
* @return business 層の Department インスタンス
*/
public static Department convertTo(UpdateDepartmentInfoForm updateDepartmentInfoForm) {
return new Department(
updateDepartmentInfoForm.getIdDepartment(),
updateDepartmentInfoForm.getNmDepartment());
}
/**
* 画面から渡ってきたパラメータのチェック
*
* @param updateDepartmentInfoForm 画面から渡ってきたパラメータ
* @return true: エラー無し false:エラーあり(必須を満たしていない)
*/
public static boolean hasErrorParameter(UpdateDepartmentInfoForm updateDepartmentInfoForm) {
boolean errorFlag = !isNullOrBlank(updateDepartmentInfoForm.getNmDepartment());
return errorFlag;
}
/**
* 仮引数を null or 空 判定する
*
* @param str 判定対象の文字列
* @return true:null or 空 false:null or 空 では無い
*/
private static boolean isNullOrBlank(String str) {
if (null == str) {
return true;
}
return str.isBlank();
}
}

View File

@@ -1,18 +0,0 @@
<!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>
</body>
</html>

View File

@@ -1,56 +0,0 @@
<!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="insertDepatmentConfirm" method="post" th:object="${insertDepartmentForm}">
<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>
<label>
<input class="readOnly" readonly="readonly" type="text" value="自動で設定されます" />
</label>
</td>
</tr>
<tr>
<th class="header">部署名</th>
<td>
<label>
<input maxlength="50" placeholder="部署名" required="required" th:field="*{nmDepartment}"
type="text" />
</label>
</td>
</tr>
<tr>
<td class="btnArea" colspan="2">
<input type="submit" value="登録確認" />
</td>
</tr>
</table>
</form>
<a href="showMenu">メニューに戻る</a>
</body>
</html>

View File

@@ -1,18 +0,0 @@
<!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>
</body>
</html>

View File

@@ -3,126 +3,125 @@
<head> <head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<!-- 外部のスクリプトファイルを読み込む --> <!-- 外部のスクリプトファイルを読み込む -->
<script th:src="@{/js/common.js}"></script> <script th:src="@{/js/common.js}"></script>
<!-- CSSの読み込み --> <!-- CSSの読み込み -->
<link rel="stylesheet" th:href="@{/css/all.css}"> <link rel="stylesheet" th:href="@{/css/all.css}">
<link rel=stylesheet th:href="@{/css/style.css}" type="text/css"> <link rel=stylesheet th:href="@{/css/style.css}" type="text/css">
<title>メニュー</title> <title>メニュー</title>
</head> </head>
<body> <body>
<h1> <h1>
メインメニュー    メインメニュー   
<div class="rightSection"> <div class="rightSection">
<span class="loginInfo">ログイン者名:<span th:text="${session.loginUser.nmEmployee}"></span></span> <span class="loginInfo">ログイン者名:<span th:text="${session.loginUser.nmEmployee}"></span></span>
<button class="logoutButton" onclick="logoutSubmit()">ログアウト</button> <button class="logoutButton" onclick="logoutSubmit()">ログアウト</button>
</div> </div>
</h1> </h1>
<table class="menuClass"> <table class="menuClass">
<tr> <tr>
<td><a class="menuClass" href="javascript:selectEmployeeSubmit()"><i class="fas fa-search"></i> 社員検索 </a> <td><a class="menuClass" href="javascript:selectEmployeeSubmit()"><i class="fas fa-search"></i> 社員検索 </a>
</td> </td>
<td class="description">登録済みのユーザ一覧表示と</br>更新、削除を行います。</td> <td class="description">登録済みのユーザ一覧表示と</br>更新、削除を行います。</td>
</tr> </tr>
<tr> <tr>
<td><a class="menuClass" href="javascript:insertEmployeeSubmit()"><i class="fas fa-plus"></i> 社員登録 </a></td> <td><a class="menuClass" href="javascript:insertEmployeeSubmit()"><i class="fas fa-plus"></i> 社員登録 </a></td>
<td class="description">新規でユーザ追加を行います。</td> <td class="description">新規でユーザ追加を行います。</td>
</tr> </tr>
<tr>
<td><a class="menuClass" href="javascript:selectDepartmentSubmit()"><i class="fas fa-search"></i> 部署検索 </a>
</td>
<td class="description">登録済みの部署一覧表示と</br>更新、削除を行います。</td>
</tr>
<tr> <tr>
<td><a class="menuClass" href="javascript:selectDepartmentSubmit()"><i class="fas fa-search"></i> 部署検索 </a> <td><a class="menuClass" href="javascript:insertEmployeeSubmit()"><i class="fas fa-plus"></i> 部署登録 </a></td>
</td> <td class="description">新規で部署追加を行います。</td>
<td class="description">登録済みの部署一覧表示と</br>更新、削除を行います。</td> </tr>
</tr>
<tr> </table>
<td><a class="menuClass" href="javascript:insertDepartmentSubmit()"><i class="fas fa-plus"></i> 部署登録 </a></td>
<td class="description">新規で部署追加を行います。</td>
</tr>
</table>
</body> </body>
<script type="text/javascript"> <script type="text/javascript">
function selectEmployeeSubmit() { function selectEmployeeSubmit() {
const form = document.createElement('form'); const form = document.createElement('form');
form.setAttribute('method', 'post'); form.setAttribute('method', 'post');
form.setAttribute('action', 'selectEmployeeInfo'); form.setAttribute('action', 'selectEmployeeInfo');
// 動的送信用のHidden // 動的送信用のHidden
// 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない // 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない
const inputField = document.createElement("input"); const inputField = document.createElement("input");
inputField.setAttribute("type", "hidden"); inputField.setAttribute("type", "hidden");
inputField.setAttribute("value", "selectEmployeeInfo"); inputField.setAttribute("value", "selectEmployeeInfo");
form.appendChild(inputField); form.appendChild(inputField);
// フォームをDOMに追加 // フォームをDOMに追加
document.body.appendChild(form); document.body.appendChild(form);
form.submit(); form.submit();
} }
function selectDepartmentSubmit() { function selectDepartmentSubmit() {
const form = document.createElement('form'); const form = document.createElement('form');
form.setAttribute('method', 'post'); form.setAttribute('method', 'post');
form.setAttribute('action', 'selectDepartment'); form.setAttribute('action', 'selectDepartmentInfo');
// 動的送信用のHidden // 動的送信用のHidden
// 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない // 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない
const inputField = document.createElement("input"); const inputField = document.createElement("input");
inputField.setAttribute("type", "hidden"); inputField.setAttribute("type", "hidden");
inputField.setAttribute("value", "selectDepartment"); inputField.setAttribute("value", "selectDepartment");
form.appendChild(inputField); form.appendChild(inputField);
// フォームをDOMに追加 // フォームをDOMに追加
document.body.appendChild(form); document.body.appendChild(form);
form.submit(); form.submit();
} }
function insertEmployeeSubmit() { function insertEmployeeSubmit() {
const form = document.createElement('form'); const form = document.createElement('form');
form.setAttribute('method', 'post'); form.setAttribute('method', 'post');
form.setAttribute('action', 'insertEmployeeInput'); form.setAttribute('action', 'insertEmployeeInput');
// 動的送信用のHidden // 動的送信用のHidden
// 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない // 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない
const inputField = document.createElement("input"); const inputField = document.createElement("input");
inputField.setAttribute("type", "hidden"); inputField.setAttribute("type", "hidden");
inputField.setAttribute("value", "insertEmployeeInput"); inputField.setAttribute("value", "insertEmployeeInput");
form.appendChild(inputField); form.appendChild(inputField);
// フォームをDOMに追加 // フォームをDOMに追加
document.body.appendChild(form); document.body.appendChild(form);
form.submit(); form.submit();
} }
function insertDepartmentSubmit() { function insertDepartmentSubmit() {
const form = document.createElement('form'); const form = document.createElement('form');
form.setAttribute('method', 'post'); form.setAttribute('method', 'post');
form.setAttribute('action', 'insertDepartmentInput'); form.setAttribute('action', 'insertDepartmentInput');
// 動的送信用のHidden // 動的送信用のHidden
// 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない // 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない
const inputField = document.createElement("input"); const inputField = document.createElement("input");
inputField.setAttribute("type", "hidden"); inputField.setAttribute("type", "hidden");
inputField.setAttribute("value", "insertDepartmentInput"); inputField.setAttribute("value", "insertDepartmentInput");
form.appendChild(inputField); form.appendChild(inputField);
// フォームをDOMに追加 // フォームをDOMに追加
document.body.appendChild(form); document.body.appendChild(form);
form.submit(); form.submit();
} }
</script> </script>
</html> </html>

View File

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

View File

@@ -2,58 +2,87 @@
<html xmlns:th="http://www.thymeleaf.org"> <html xmlns:th="http://www.thymeleaf.org">
<head> <head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<!-- 外部のスクリプトファイルを読み込む --> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<script th:src="@{/js/common.js}"></script> <!-- 外部のスクリプトファイルを読み込む -->
<!-- CSSの読み込み --> <script th:src="@{/js/common.js}"></script>
<link rel="stylesheet" th:href="@{/css/all.css}"> <!-- CSSの読み込み -->
<link rel=stylesheet th:href="@{/css/style.css}" type="text/css"> <link rel="stylesheet" th:href="@{/css/all.css}">
<title>部署登録更新</title> <link rel=stylesheet th:href="@{/css/style.css}" type="text/css">
<title>部署情報更新</title>
</head> </head>
<body> <body>
<h1> <h1>
社員情報更新    部署情報更新   
<div class="rightSection"> <div class="rightSection">
<span class="loginInfo">ログイン者名:<span th:text="${session.loginUser.nmEmployee}"></span></span> <span class="loginInfo">ログイン者名:<span th:text="${session.loginUser.nmEmployee}"></span></span>
<button class="logoutButton" onclick="logoutSubmit()">ログアウト</button> <button class="logoutButton" onclick="logoutSubmit()">ログアウト</button>
</div> </div>
</h1> </h1>
<form action="updateDepartmentResult" method="post" onsubmit="return confirm('本当によろしいですか?');" <form action="/updateDepartmentResult"
th:object="${updateDepartmentForm}"> method="post"
onsubmit="return confirm('本当によろしいですか?');"
<div class="msgBox error" th:if="${messageError != null}"> th:object="${departmentFormList}"
<span class="error" th:text="${messageError.message}"></span> >
</div> <div class="msgBox error" th:if="${messageError != null}">
<table> <span class="error" th:each="message : ${messageError.message}" th:text="${message}"></span>
<tr> </div>
<th class="header">部署ID</th> <table>
<td> <tr>
<input class="readOnly" readonly="readonly" th:field="*{idDepartment}" type="text" /> <th class="header">部署ID</th>
</td> <td>
</tr> <label>
<tr> <input class="readOnly"
<th class="header">部署名</th> readonly="readonly"
<td> th:field="*{idDepartment}"
<input maxlength="50" placeholder="部署名" required="required" th:field="*{nmDepartment}" type="text"
type="text" /> />
</td> </label>
</tr> </td>
<tr> </tr>
<td class="btnArea" colspan="2"><input type="submit" value="更新" /></td> <tr>
</tr> <th class="header">部署名</th>
</table> <td>
</form> <label>
<a href="javascript:selectDepartmentSubmit()">一覧に戻る</a> <input maxlength="50"
<script type="text/javascript"> placeholder="部署名"
function selectDepartmentSubmit() { required="required"
const form = document.createElement('form'); th:field="*{nmDepartment}"
form.setAttribute('method', 'post'); type="text"
form.setAttribute('action', 'selectDepartment'); />
document.body.appendChild(form); </label>
form.submit(); </td>
} </tr>
</script> <tr>
<td class="btnArea" colspan="2">
<input type="submit" value="更新"/>
</td>
</tr>
</table>
</form>
<a href="javascript:selectSubmit()">一覧に戻る</a>
</body> </body>
<script>
function selectSubmit() {
const form = document.createElement('form');
form.setAttribute('method', 'post');
form.setAttribute('action', 'departmentAll');
// 動的送信用のHidden
// 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない
const inputField = document.createElement("input");
inputField.setAttribute("type", "hidden");
inputField.setAttribute("value", "departmentAll");
form.appendChild(inputField);
// フォームをDOMに追加
document.body.appendChild(form);
form.submit();
}
</script>
</html> </html>