1 Commits

Author SHA1 Message Date
8baa2139f7 no message 2026-09-10 17:10:54 +09:00
115 changed files with 3657 additions and 2627 deletions

41
.classpath Normal file
View File

@@ -0,0 +1,41 @@
<?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>

2
.gitignore vendored Normal file
View File

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

37
.project Normal file
View File

@@ -0,0 +1,37 @@
<?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>

13
.settings/.jsdtscope Normal file
View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/node_modules/*|**/*.min.js|**/bower_components/*" kind="src" path="src/main/webapp"/>
<classpathentry 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

@@ -0,0 +1,6 @@
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

@@ -0,0 +1,11 @@
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

@@ -0,0 +1,10 @@
<?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

@@ -0,0 +1,7 @@
<?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

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

View File

@@ -0,0 +1 @@
Window

View File

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

View File

@@ -15,7 +15,7 @@
<packaging>war</packaging> <packaging>war</packaging>
<name>EM-Spring</name> <name>EM-Spring</name>
<description>Demo project for Spring Boot</description> <description>Demo project for Spring Boot</description>
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>
<lombok.version>1.18.34</lombok.version> <lombok.version>1.18.34</lombok.version>
</properties> </properties>

View File

@@ -8,8 +8,8 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
@EnableAspectJAutoProxy(proxyTargetClass = true) @EnableAspectJAutoProxy(proxyTargetClass = true)
public class EmSpringApplication { public class EmSpringApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(EmSpringApplication.class, args); SpringApplication.run(EmSpringApplication.class, args);
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,10 +3,19 @@ package com.example.rhizome.app.domain.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
/**
* 部署情報の概念を表現するモデルクラスです。
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class Department { public class Department {
private final Integer idDepartment; /**
private final String nmDepartment; * 部署ID
*/
private final Integer idDepartment;
/**
* 部署名
*/
private final String nmDepartment;
} }

View File

@@ -3,15 +3,39 @@ package com.example.rhizome.app.domain.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
/**
* 社員を表現するモデルクラスです
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class Employee { public class Employee {
private final Integer idEmployee; /**
private final String nmEmployee; * 社員ID
private final String knEmployee; */
private final String mailAddress; private final Integer idEmployee;
private final String password; /**
private final Integer adminAuth; * 社員名
private final Integer idDepartment; */
private final String nmEmployee;
/**
* 社員名カナ
*/
private final String knEmployee;
/**
* メールアドレス
*/
private final String mailAddress;
/**
* パスワード
*/
private final String password;
/**
* 管理者権限
*/
private final Integer adminAuth;
/**
* 部署ID
*/
private final Integer idDepartment;
} }

View File

@@ -1,14 +1,28 @@
/*
* EmployeeInfo.java
* 作成 IT-College 2016
*------------------------------------------------------------
* Copyright(c) Rhizome Inc. All Rights Reserved.
*/
package com.example.rhizome.app.domain.model; package com.example.rhizome.app.domain.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
/**
* 社員情報の概念を表現するモデルクラスです。
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class EmployeeInfo { public class EmployeeInfo {
private final Employee employee; /**
* 社員情報
private final Department department; */
private final Employee employee;
/**
* 部署名
*/
private final Department department;
} }

View File

@@ -3,12 +3,20 @@ package com.example.rhizome.app.domain.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
/**
* ログインを試みる人を表現するモデルクラスです
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class LoginInfo { public class LoginInfo {
/**
private String mailAddress; * メールアドレス
*/
private String password; private String mailAddress;
/**
* パスワード
*/
private String password;
} }

View File

@@ -3,24 +3,49 @@ package com.example.rhizome.app.domain.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
/**
* ログイン者を表現するクラスです
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class LoginUser { public class LoginUser {
private final Integer idEmployee; /**
* 社員ID
*/
private final Integer idEmployee;
/**
* 社員名
*/
private final String nmEmployee;
/**
* 社員名カナ
*/
private final String knEmployee;
/**
* メールアドレス
*/
private final String mailAddress;
/**
* パスワード
*/
private final String password;
private final String nmEmployee; /**
* 管理者権限
*/
private final Integer adminAuth;
private final String knEmployee; /**
* 部署ID
*/
private final Integer idDepartment;
private final String mailAddress; /**
* ログインユーザが管理者か
private final String password; *
* @return true:管理者 false:一般権限
private final Integer adminAuth; */
public boolean isAdminUser() {
private final Integer idDepartment; return getAdminAuth() == 1;
}
public boolean isAdminUser() {
return getAdminAuth() == 1;
}
} }

View File

@@ -3,11 +3,20 @@ package com.example.rhizome.app.domain.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
/**
* 部署情報の検索要件を表現するモデルクラスです。
*画面の検索条件を受け取る
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class SearchConditionDepartment { public class SearchConditionDepartment {
private final Integer idDepartment; /**
* 部署ID
private final String nmDepartment; */
private final Integer idDepartment;
/**
* 部署名
*/
private final String nmDepartment;
} }

View File

@@ -3,13 +3,31 @@ package com.example.rhizome.app.domain.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
/**
* 社員情報の検索条件という概念を表現するモデルクラスです
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class SearchConditionEmployee { public class SearchConditionEmployee {
private final Integer idEmployee; /**
private final String nmEmployee; * 社員ID
private final String knEmployee; */
private final String mailAddress; private final Integer idEmployee;
private final Integer idDepartment; /**
* 社員名
*/
private final String nmEmployee;
/**
* 社員名カナ
*/
private final String knEmployee;
/**
* メールアドレス
*/
private final String mailAddress;
/**
* 部署ID
*/
private final Integer idDepartment;
} }

View File

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

View File

@@ -1,6 +1,6 @@
package com.example.rhizome.app.domain.service; package com.example.rhizome.app.domain.service;
public interface DeleteEmployee { public interface DeleteEmployee {
void deleteEmployee(Integer idEmployee); void deleteEmployee(Integer idEmployee);
} }

View File

@@ -4,7 +4,7 @@ import com.example.rhizome.app.domain.model.LoginInfo;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
public interface Login { public interface Login {
LoginUser doLogin(LoginInfo loginInfo); LoginUser doLogin(LoginInfo loginInfo);
boolean canLogin(LoginInfo loginInfo); boolean canLogin(LoginInfo loginInfo);
} }

View File

@@ -3,5 +3,5 @@ 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 RegisterDepartment { public interface RegisterDepartment {
void registerDepartment(Department department); void registerDepartment(Department department);
} }

View File

@@ -3,5 +3,5 @@ package com.example.rhizome.app.domain.service;
import com.example.rhizome.app.domain.model.Employee; import com.example.rhizome.app.domain.model.Employee;
public interface RegisterEmployee { public interface RegisterEmployee {
void registerEmployee(Employee employee); void registerEmployee(Employee employee);
} }

View File

@@ -1,3 +1,5 @@
//サービス
package com.example.rhizome.app.domain.service; package com.example.rhizome.app.domain.service;
import java.util.List; import java.util.List;
@@ -6,14 +8,14 @@ import com.example.rhizome.app.domain.model.Department;
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(); //DBから全取得
List<Department> searchBy(SearchConditionDepartment searchConditionDepartment);
List<Department> searchBy(SearchConditionDepartment searchConditionDepartment); List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment); //条件検索
List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment);
List<Department> searchByDepartmentName(SearchConditionDepartment searchConditionDepartment);
List<Department> searchByDepartmentId(SearchConditionDepartment searchConditionDepartment);
} }
//controller→SeachDepartment→Repository→DB

View File

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

View File

@@ -1,12 +1,12 @@
package com.example.rhizome.app.domain.service; package com.example.rhizome.app.domain.service;
import java.util.List;
import com.example.rhizome.app.domain.model.EmployeeInfo; import com.example.rhizome.app.domain.model.EmployeeInfo;
import com.example.rhizome.app.domain.model.SearchConditionEmployee; import com.example.rhizome.app.domain.model.SearchConditionEmployee;
public interface SearchEmployeeInfo { import java.util.List;
List<EmployeeInfo> selectAll();
List<EmployeeInfo> searchBy(SearchConditionEmployee searchConditionEmployee); public interface SearchEmployeeInfo {
List<EmployeeInfo> selectAll();
List<EmployeeInfo> searchBy(SearchConditionEmployee searchConditionEmployee);
} }

View File

@@ -1,8 +0,0 @@
package com.example.rhizome.app.domain.service;
import com.example.rhizome.app.domain.model.Department;
public interface UpdateDepartment {
void updateDepartment(Department beforeDepartment, Department updateDepartment);
}

View File

@@ -3,6 +3,6 @@ package com.example.rhizome.app.domain.service;
import com.example.rhizome.app.domain.model.Employee; import com.example.rhizome.app.domain.model.Employee;
public interface UpdateEmployee { public interface UpdateEmployee {
void updateEmployee(Employee beforeEmployee, Employee updateEmployee); void updateEmployee(Employee beforeEmployee, Employee updateEmployee);
} }

View File

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

View File

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

View File

@@ -1,38 +1,55 @@
package com.example.rhizome.app.domain.service.impl; 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.LoginInfo; import com.example.rhizome.app.domain.model.LoginInfo;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
import com.example.rhizome.app.domain.service.Login; import com.example.rhizome.app.domain.service.Login;
import com.example.rhizome.app.infra.entity.EmployeeEntity; import com.example.rhizome.app.infra.entity.EmployeeEntity;
import com.example.rhizome.app.infra.repository.EmployeeRepository; import com.example.rhizome.app.infra.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* ログイン系の機能を集約させるサービスクラスです。
*/
@Service @Service
@Transactional @Transactional
public class LoginImpl implements Login { public class LoginImpl implements Login {
EmployeeRepository employeeRepository; EmployeeRepository employeeRepository;
@Autowired @Autowired
public LoginImpl(EmployeeRepository employeeRepository) { public LoginImpl(EmployeeRepository employeeRepository) {
this.employeeRepository = employeeRepository; this.employeeRepository = employeeRepository;
} }
public LoginUser doLogin(LoginInfo loginInfo) {
return employeeRepository
.findByMailAddressAndPassword(loginInfo.getMailAddress(), loginInfo.getPassword())
.orElse(new EmployeeEntity())
.createLoginUser();
} /**
* メールアドレス、パスワードでログイン判定を行う
*
* @param loginInfo ログインを試みるアカウント
* @return loginUser のインスタンス
*/
public LoginUser doLogin(LoginInfo loginInfo) {
// ログイン情報を元にログインユーザーを取得
return employeeRepository
.findByMailAddressAndPassword(loginInfo.getMailAddress(), loginInfo.getPassword())
.orElse(new EmployeeEntity())
.createLoginUser();
public boolean canLogin(LoginInfo loginInfo) { }
return employeeRepository
.findByMailAddressAndPassword(loginInfo.getMailAddress(), loginInfo.getPassword())
.isPresent();
} /**
* メールアドレス、パスワードでログイン判定を行う
*
* @param loginInfo ログインを試みるアカウント
* @return loginUser のインスタンス
*/
public boolean canLogin(LoginInfo loginInfo) {
// ログイン情報を元にログインユーザーを取得
return employeeRepository
.findByMailAddressAndPassword(loginInfo.getMailAddress(), loginInfo.getPassword())
.isPresent();
}
} }

View File

@@ -1,5 +1,6 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -9,19 +10,26 @@ import com.example.rhizome.app.domain.service.RegisterDepartment;
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;
/**
* Employee テーブルの登録系の機能を集約させるサービスクラスです。
*/
@Service @Service
@Transactional @Transactional
public class RegisterDepartmentImpl implements RegisterDepartment { public class RegisterDepartmentImpl implements RegisterDepartment {
DepartmentRepository departmentRepository; DepartmentRepository departmentRepository;
@Autowired @Autowired
public RegisterDepartmentImpl(DepartmentRepository departmentRepository) { public RegisterDepartmentImpl(DepartmentRepository DepartmentRepository) {
this.departmentRepository = departmentRepository; this.departmentRepository = DepartmentRepository;
} }
@Override /**
public void registerDepartment(Department department) { * employee インスタンスの内容を登録する
departmentRepository.save(DepartmentEntity.convertFrom(department)); *
} * @param employee 登録対象のデータ
*/
public void registerDepartment(Department department) {
departmentRepository.save(DepartmentEntity.convertFrom(department));
}
} }

View File

@@ -1,26 +1,34 @@
package com.example.rhizome.app.domain.service.impl; 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.Employee; import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.service.RegisterEmployee; import com.example.rhizome.app.domain.service.RegisterEmployee;
import com.example.rhizome.app.infra.entity.EmployeeEntity; import com.example.rhizome.app.infra.entity.EmployeeEntity;
import com.example.rhizome.app.infra.repository.EmployeeRepository; import com.example.rhizome.app.infra.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Employee テーブルの登録系の機能を集約させるサービスクラスです。
*/
@Service @Service
@Transactional @Transactional
public class RegisterEmployeeImpl implements RegisterEmployee { public class RegisterEmployeeImpl implements RegisterEmployee {
EmployeeRepository employeeRepository; EmployeeRepository employeeRepository;
@Autowired @Autowired
public RegisterEmployeeImpl(EmployeeRepository employeeRepository) { public RegisterEmployeeImpl(EmployeeRepository employeeRepository) {
this.employeeRepository = employeeRepository; this.employeeRepository = employeeRepository;
} }
public void registerEmployee(Employee employee) { /**
employeeRepository.save(EmployeeEntity.convertFrom(employee)); * employee インスタンスの内容を登録する
} *
* @param employee 登録対象のデータ
*/
public void registerEmployee(Employee employee) {
employeeRepository.save(EmployeeEntity.convertFrom(employee));
}
} }

View File

@@ -1,5 +1,6 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -13,63 +14,71 @@ 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;
/**
* 部署情報検索系の機能を集約させるサービスクラスです。
*/
@Service @Service
@Transactional @Transactional
public class SearchDepartmentImpl implements SearchDepartment { public class SearchDepartmentImpl implements SearchDepartment {
DepartmentRepository departmentRepository; DepartmentRepository departmentRepository;
@Autowired /**
public SearchDepartmentImpl(DepartmentRepository departmentRepository) { * コンストラクタ
this.departmentRepository = departmentRepository; *
} * @param departmentRepository DI対象
*/
@Autowired
public SearchDepartmentImpl(DepartmentRepository departmentRepository) {
this.departmentRepository = departmentRepository;
}
public List<Department> selectAll() { /**
return DepartmentEntity.createDepartmentList(departmentRepository.findAll()); * 部署情報を全件取得する
} *
* @return 取得した部署情報レコード全件
*/
public List<Department> selectAll() {
return DepartmentEntity.createDepartmentList(departmentRepository.findAll());
}
public List<Department> searchBy(SearchConditionDepartment searchConditionDepartment) { /**
return DepartmentEntity *seachBy完全一致検索用メソッド
.createDepartmentList( * searchConditionDepartment の情報を元に Department のレコードを取得
departmentRepository.findAll(Specification *
.where(DepartmentRepository * @param searchConditionDepartment 検索条件
.idDepartmentEqual(searchConditionDepartment.getIdDepartment())) * @return 検索結果のレコード
.and(DepartmentRepository */
.nmDepartmentEqual(searchConditionDepartment.getNmDepartment())))); public List<Department> searchBy(SearchConditionDepartment searchConditionDepartment) {
// 動的に検索条件を絞り込む
// Specification は Criteria API の Predicate をラップしたもの
return DepartmentEntity
.createDepartmentList(
departmentRepository.findAll(Specification
.where(DepartmentRepository.idDepartmentEqual(searchConditionDepartment.getIdDepartment()))
.and(DepartmentRepository.nmDepartmentEqual(searchConditionDepartment.getNmDepartment()))
)
);
} }
public List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment) { /**
return DepartmentEntity * searchConditionDepartment の情報を元に Department のレコードを取得
.createDepartmentList( * 部分一致検索
departmentRepository.findAll(Specification *
.where(DepartmentRepository * @param searchConditionDepartment 検索条件
.idDepartmentEqual(searchConditionDepartment.getIdDepartment())) * @return 検索結果のレコード
.and(DepartmentRepository */
.nmDepartmentLike(searchConditionDepartment.getNmDepartment())))); public List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment) {
// 動的に検索条件を絞り込む
} // Specification は Criteria API の Predicate をラップしたもの
return DepartmentEntity
@Override .createDepartmentList(
public List<Department> searchByDepartmentName(SearchConditionDepartment searchConditionDepartment) { departmentRepository.findAll(Specification
.where(DepartmentRepository.idDepartmentEqual(searchConditionDepartment.getIdDepartment()))
return DepartmentEntity .and(DepartmentRepository.nmDepartmentLike(searchConditionDepartment.getNmDepartment()))
.createDepartmentList( )
departmentRepository.findAll(Specification );
.where(DepartmentRepository
.nmDepartmentEqual(searchConditionDepartment.getNmDepartment()))));
}
@Override
public List<Department> searchByDepartmentId(SearchConditionDepartment searchConditionDepartment) {
return DepartmentEntity
.createDepartmentList(
departmentRepository.findAll(Specification
.where(DepartmentRepository
.idDepartmentEqual(searchConditionDepartment.getIdDepartment()))));
}
}
} }

View File

@@ -1,43 +1,70 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
import java.util.List;
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.Employee; import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
import com.example.rhizome.app.domain.service.SearchEmployee; import com.example.rhizome.app.domain.service.SearchEmployee;
import com.example.rhizome.app.infra.entity.EmployeeEntity; import com.example.rhizome.app.infra.entity.EmployeeEntity;
import com.example.rhizome.app.infra.repository.EmployeeRepository; import com.example.rhizome.app.infra.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* Employee テーブル検索系の機能を集約させるサービスクラスです。
*/
@Service @Service
@Transactional @Transactional
public class SearchEmployeeImpl implements SearchEmployee { public class SearchEmployeeImpl implements SearchEmployee {
EmployeeRepository employeeRepository; EmployeeRepository employeeRepository;
@Autowired @Autowired
public SearchEmployeeImpl(EmployeeRepository employeeRepository) { public SearchEmployeeImpl(EmployeeRepository employeeRepository) {
this.employeeRepository = employeeRepository; this.employeeRepository = employeeRepository;
} }
public List<Employee> searchEmployee(String mailAddress) {
return EmployeeEntity.createEmployeeList(employeeRepository.findByMailAddress(mailAddress).stream().toList());
}
public LoginUser searchLoginUser(String mailAddress) { /**
return employeeRepository.findByMailAddress(mailAddress).orElse(new EmployeeEntity()).createLoginUser(); * mailAddress を元に Employee Table を検索します。
} *
* @param mailAddress 検索対象の mailAddress
* @return Table から取得したレコードの情報
*/
public List<Employee> searchEmployee(String mailAddress) {
return EmployeeEntity.createEmployeeList(employeeRepository.findByMailAddress(mailAddress).stream().toList());
}
public Employee searchEmployeeByIdEmployee(Integer idEmployee) { /**
return EmployeeEntity * mailAddress を元に ログイン者の情報 を検索します。
.createEmployee(employeeRepository.findByIdEmployee(idEmployee).orElse(new EmployeeEntity())); *
} * @param mailAddress 検索対象の mailAddress
* @return login者の情報
*/
public LoginUser searchLoginUser(String mailAddress) {
return employeeRepository.findByMailAddress(mailAddress).orElse(new EmployeeEntity()).createLoginUser();
}
@Override /**
public List<Employee> searchEmployeeByIdDepartment(Integer idDepartment) { * idEmployee を元に Employee Table を検索します。
return EmployeeEntity.createEmployeeList(employeeRepository.findByIdDepartment(idDepartment)); *
} * @param idEmployee 検索対象の idEmployee
* @return Table から取得したレコードの情報
*/
public Employee searchEmployeeByIdEmployee(Integer idEmployee) {
return EmployeeEntity.createEmployee(employeeRepository.findByIdEmployee(idEmployee).orElse(new EmployeeEntity()));
}
/**
* idDepartment を元に Employee Table を検索します。
*
* @param idDepartment 部署ID
* @return Table から取得したレコードの情報
*/
@Override
public List<Employee> searchEmployeeByIdDepartment(Integer idDepartment) {
return EmployeeEntity.createEmployeeList(employeeRepository.findByIdDepartment(idDepartment));
}
} }

View File

@@ -1,45 +1,62 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
import java.util.List;
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.EmployeeInfo; import com.example.rhizome.app.domain.model.EmployeeInfo;
import com.example.rhizome.app.domain.model.SearchConditionEmployee; import com.example.rhizome.app.domain.model.SearchConditionEmployee;
import com.example.rhizome.app.domain.service.SearchEmployeeInfo; import com.example.rhizome.app.domain.service.SearchEmployeeInfo;
import com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity; import com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity;
import com.example.rhizome.app.infra.repository.EmployeeInfoRepository; import com.example.rhizome.app.infra.repository.EmployeeInfoRepository;
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;
/**
* SearchEmployeeInfoImpl (employee join department) 検索系の機能を集約させるサービスクラスです
*/
@Service @Service
@Transactional @Transactional
public class SearchEmployeeInfoImpl implements SearchEmployeeInfo { public class SearchEmployeeInfoImpl implements SearchEmployeeInfo {
EmployeeInfoRepository employeeInfoRepository; EmployeeInfoRepository employeeInfoRepository;
@Autowired @Autowired
public SearchEmployeeInfoImpl(EmployeeInfoRepository employeeInfoRepository) { public SearchEmployeeInfoImpl(EmployeeInfoRepository employeeInfoRepository) {
this.employeeInfoRepository = employeeInfoRepository; this.employeeInfoRepository = employeeInfoRepository;
} }
public List<EmployeeInfo> selectAll() {
return EmployeeDepartmentEntity.createEmployeeInfoList(employeeInfoRepository.findAll()); /**
* EmployeeInfo (employee join department) のレコードを全件取得
*
* @return 取得したレコード全件
*/
public List<EmployeeInfo> selectAll() {
} return EmployeeDepartmentEntity.createEmployeeInfoList(employeeInfoRepository.findAll());
public List<EmployeeInfo> searchBy(SearchConditionEmployee searchConditionEmployee) { }
return EmployeeDepartmentEntity
.createEmployeeInfoList(
employeeInfoRepository.findAll(Specification
.where(EmployeeInfoRepository.idEmployeeEqual(searchConditionEmployee.getIdEmployee()))
.and(EmployeeInfoRepository.nmEmployeeEqual(searchConditionEmployee.getNmEmployee()))
.and(EmployeeInfoRepository.knEmployeeEqual(searchConditionEmployee.getKnEmployee()))
.and(EmployeeInfoRepository.mailAddressEqual(searchConditionEmployee.getMailAddress()))
.and(EmployeeInfoRepository
.idDepartmentEqual(searchConditionEmployee.getIdDepartment()))));
} /**
* SearchConditionEmployee の情報を元に EmployeeInfo (employee join department) のレコードを取得
*
* @param searchConditionEmployee 検索条件
* @return 検索結果のレコードリスト
*/
public List<EmployeeInfo> searchBy(SearchConditionEmployee searchConditionEmployee) {
// 動的に検索条件を絞り込む
// Specification は Criteria API の Predicate をラップしたもの
return EmployeeDepartmentEntity
.createEmployeeInfoList(
employeeInfoRepository.findAll(Specification
.where(EmployeeInfoRepository.idEmployeeEqual(searchConditionEmployee.getIdEmployee()))
.and(EmployeeInfoRepository.nmEmployeeEqual(searchConditionEmployee.getNmEmployee()))
.and(EmployeeInfoRepository.knEmployeeEqual(searchConditionEmployee.getKnEmployee()))
.and(EmployeeInfoRepository.mailAddressEqual(searchConditionEmployee.getMailAddress()))
.and(EmployeeInfoRepository.idDepartmentEqual(searchConditionEmployee.getIdDepartment()))
)
);
}
} }

View File

@@ -1,37 +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.UpdateDepartment;
import com.example.rhizome.app.infra.entity.DepartmentEntity;
import com.example.rhizome.app.infra.repository.DepartmentRepository;
@Service
@Transactional
public class UpdateDepartmentImpl implements UpdateDepartment {
DepartmentRepository departmentRepository;
@Autowired
public UpdateDepartmentImpl(DepartmentRepository departmentRepository) {
this.departmentRepository = departmentRepository;
}
@Override
public void updateDepartment(Department beforeDepartment, Department updateDepartment) {
departmentRepository.save(DepartmentEntity.convertFrom(mergeDepartment(beforeDepartment, updateDepartment)));
}
private Department mergeDepartment(Department beforeDepartment, Department updateDepartment) {
return new Department(
updateDepartment.getIdDepartment(),
updateDepartment.getNmDepartment());
}
}

View File

@@ -1,42 +1,60 @@
package com.example.rhizome.app.domain.service.impl; 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.Employee; import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.service.UpdateEmployee; import com.example.rhizome.app.domain.service.UpdateEmployee;
import com.example.rhizome.app.infra.entity.EmployeeEntity; import com.example.rhizome.app.infra.entity.EmployeeEntity;
import com.example.rhizome.app.infra.repository.EmployeeRepository; import com.example.rhizome.app.infra.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* employee の更新系の機能を集約させるサービスクラスです。
*/
@Service @Service
@Transactional @Transactional
public class UpdateEmployeeImpl implements UpdateEmployee { public class UpdateEmployeeImpl implements UpdateEmployee {
EmployeeRepository employeeRepository; EmployeeRepository employeeRepository;
@Autowired @Autowired
public UpdateEmployeeImpl(EmployeeRepository employeeRepository) { public UpdateEmployeeImpl(EmployeeRepository employeeRepository) {
this.employeeRepository = employeeRepository; this.employeeRepository = employeeRepository;
} }
public void updateEmployee(Employee beforeEmployee, Employee updateEmployee) { /**
* employee の情報を元に employee table のレコードを更新する
*
* @param beforeEmployee 更新前のデータ
* @param updateEmployee 更新後のデータ
*/
public void updateEmployee(Employee beforeEmployee, Employee updateEmployee) {
employeeRepository.save(EmployeeEntity.convertFrom(mergeEmployee(beforeEmployee, updateEmployee))); employeeRepository.save(EmployeeEntity.convertFrom(mergeEmployee(beforeEmployee, updateEmployee)));
} }
private Employee mergeEmployee(Employee beforeEmployee, Employee updateEmployee) { /**
return new Employee( * 更新前のデータと更新対象のデータをマージする
updateEmployee.getIdEmployee(), *
updateEmployee.getNmEmployee(), * @param beforeEmployee 更新前のデータ
updateEmployee.getKnEmployee(), * @param updateEmployee 更新対象のデータ
updateEmployee.getMailAddress(), * @return マージしたデータ
updateEmployee.getPassword().isBlank() ? beforeEmployee.getPassword() : updateEmployee.getPassword(), */
updateEmployee.getAdminAuth() == null ? beforeEmployee.getAdminAuth() : updateEmployee.getAdminAuth(), private Employee mergeEmployee(Employee beforeEmployee, Employee updateEmployee) {
updateEmployee.getIdDepartment() == null ? beforeEmployee.getIdDepartment() // 更新対象のデータのパスワードが空文字の場合は、更新前のパスワードを使用する
: updateEmployee.getIdDepartment()); // 更新対象のデータの管理者権限が null の場合は、更新前の管理者権限を使用する
// 更新対象のデータの部署IDが null の場合は、更新前の部署IDを使用する
return new Employee(
updateEmployee.getIdEmployee(),
updateEmployee.getNmEmployee(),
updateEmployee.getKnEmployee(),
updateEmployee.getMailAddress(),
updateEmployee.getPassword().isBlank() ? beforeEmployee.getPassword() : updateEmployee.getPassword(),
updateEmployee.getAdminAuth() == null ? beforeEmployee.getAdminAuth() : updateEmployee.getAdminAuth(),
updateEmployee.getIdDepartment() == null ? beforeEmployee.getIdDepartment() : updateEmployee.getIdDepartment()
);
} }
} }

View File

@@ -1,20 +1,25 @@
/*
* Department.java
* 作成 IT-College 2016
*------------------------------------------------------------
* Copyright(c) Rhizome Inc. All Rights Reserved.
*/
package com.example.rhizome.app.infra.entity; package com.example.rhizome.app.infra.entity;
import java.util.List;
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
*
* @author IT-College
*/
@Entity @Entity
@Table(name = "department") @Table(name = "department")
@Data @Data
@@ -22,26 +27,46 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
public class DepartmentEntity { public class DepartmentEntity {
@Id /**
@GeneratedValue(strategy = GenerationType.IDENTITY) * 部署ID
@Column(name = "id_department", nullable = false) */
private Integer idDepartment; @Id
@Column(name = "nm_department", nullable = false) @GeneratedValue(strategy = GenerationType.IDENTITY)
private String nmDepartment; @Column(name = "id_department", nullable = false)
private Integer idDepartment;
/**
* 部署名
*/
@Column(name = "nm_department", nullable = false)
private String nmDepartment;
public static List<Department> createDepartmentList(List<DepartmentEntity> departmentEntityList) { /**
* DepartmentEntity(DataAccess層依存)から Department(BusinessLogic層依存型)に変換します。
*
* @param departmentEntityList department Table のリスト
* @return List<Department> リスト
*/
public static List<Department> createDepartmentList(List<DepartmentEntity> departmentEntityList) {
return departmentEntityList // Stream API を利用するとこうなります。
.stream() return departmentEntityList
.map(departmentEntity -> new Department( .stream()
departmentEntity.getIdDepartment(), .map(departmentEntity -> new Department(
departmentEntity.getNmDepartment())) departmentEntity.getIdDepartment(),
.toList(); departmentEntity.getNmDepartment()
} )).toList();
}
public static DepartmentEntity convertFrom(Department department) { /**
return new DepartmentEntity( * Department(BusinessLogic層依存型) から DepartmentEntity(DataAccess層依存)に変換します。
department.getIdDepartment(), *
department.getNmDepartment()); * @param department department モデルの値
} * @return DepartmentEntity に変換したインスタンス
*/
public static DepartmentEntity convertFrom(Department department) {
return new DepartmentEntity(
department.getIdDepartment(),
department.getNmDepartment()
);
}
} }

View File

@@ -1,86 +1,118 @@
package com.example.rhizome.app.infra.entity; package com.example.rhizome.app.infra.entity;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedEntityGraph;
import javax.persistence.Table;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
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.Employee;
import com.example.rhizome.app.domain.model.EmployeeInfo; import com.example.rhizome.app.domain.model.EmployeeInfo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import javax.persistence.*;
import java.util.List;
/**
* Employee + Department の Join 情報を保持するEntity
*
* @author IT-College
*/
@Entity @Entity
@Table(name = "employee") @Table(name = "employee")
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@NamedEntityGraph(name = "employee_with_department", includeAllAttributes = true) @NamedEntityGraph(
name = "employee_with_department",
includeAllAttributes = true
)
public class EmployeeDepartmentEntity { public class EmployeeDepartmentEntity {
@Id /**
@GeneratedValue(strategy = GenerationType.IDENTITY) * 社員ID
@Column(name = "id_employee", nullable = false) */
private Integer idEmployee; @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_employee", nullable = false)
private Integer idEmployee;
@Column(name = "nm_employee", nullable = false) /**
private String nmEmployee; * 社員名
*/
@Column(name = "nm_employee", nullable = false)
private String nmEmployee;
@Column(name = "kn_employee", nullable = false) /**
private String knEmployee; * 社員名カナ
*/
@Column(name = "kn_employee", nullable = false)
private String knEmployee;
@Column(name = "mail_address", nullable = false) /**
private String mailAddress; * メールアドレス
*/
@Column(name = "mail_address", nullable = false)
private String mailAddress;
@Column(name = "password", nullable = false) /**
private String password; * パスワード
*/
@Column(name = "password", nullable = false)
private String password;
@Column(name = "admin_auth", nullable = false) /**
private Integer adminAuth; * 管理者権限
*/
@Column(name = "admin_auth", nullable = false)
private Integer adminAuth;
@ManyToOne @ManyToOne
@JoinColumn(name = "id_department", referencedColumnName = "id_department", insertable = false, updatable = false) @JoinColumn(name = "id_department", referencedColumnName = "id_department", insertable = false, updatable = false)
@Fetch(FetchMode.JOIN) @Fetch(FetchMode.JOIN)
private DepartmentEntity department; private DepartmentEntity department;
public static EmployeeInfo createEmployeeInfo(EmployeeDepartmentEntity employeeDepartmentEntity) { /**
* EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。
*
* @param employeeDepartmentEntity  EmployeeDepartmentEntity のインスタンス
* @return EmployeeInfo のインスタンス
*/
public static EmployeeInfo createEmployeeInfo(EmployeeDepartmentEntity employeeDepartmentEntity) {
return new EmployeeInfo( // コンストラクタを使って書くとSetterを使用するより簡略化出来ます。
new Employee( // 混乱してしまう人は落ち着いて EmployeeInfo のフィールドを見に行って、
employeeDepartmentEntity.getIdEmployee(), // どうしてこの書き方が出来るのかを理解できる様になりましょう。
employeeDepartmentEntity.getNmEmployee(), return new EmployeeInfo(
employeeDepartmentEntity.getKnEmployee(), new Employee(
employeeDepartmentEntity.getMailAddress(), employeeDepartmentEntity.getIdEmployee(),
employeeDepartmentEntity.getPassword(), employeeDepartmentEntity.getNmEmployee(),
employeeDepartmentEntity.getAdminAuth(), employeeDepartmentEntity.getKnEmployee(),
employeeDepartmentEntity.getDepartment() == null ? null employeeDepartmentEntity.getMailAddress(),
: employeeDepartmentEntity.getDepartment().getIdDepartment()), employeeDepartmentEntity.getPassword(),
new Department( employeeDepartmentEntity.getAdminAuth(),
employeeDepartmentEntity.getDepartment() == null ? null employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment()
: employeeDepartmentEntity.getDepartment().getIdDepartment(), ),
employeeDepartmentEntity.getDepartment() == null ? null new Department(
: employeeDepartmentEntity.getDepartment().getNmDepartment())); employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment(),
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getNmDepartment()
)
);
} }
public static List<EmployeeInfo> createEmployeeInfoList( /**
List<EmployeeDepartmentEntity> employeeDepartmentEntityList) { * EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。
* (リスト版)
*
* @param employeeDepartmentEntityList EmployeeDepartmentEntity インスタンスのリスト
* @return EmployeeInfo インスタンスのリスト
*/
public static List<EmployeeInfo> createEmployeeInfoList(List<EmployeeDepartmentEntity> employeeDepartmentEntityList) {
return employeeDepartmentEntityList.stream().map(EmployeeDepartmentEntity::createEmployeeInfo).toList(); // StreamAPI を使うとこうなります。
return employeeDepartmentEntityList.stream().map(EmployeeDepartmentEntity::createEmployeeInfo).toList();
}
}
} }

View File

@@ -1,22 +1,27 @@
/*
* Employee.java
* 作成 IT-College 2016
*------------------------------------------------------------
* Copyright(c) Rhizome Inc. All Rights Reserved.
*/
package com.example.rhizome.app.infra.entity; package com.example.rhizome.app.infra.entity;
import java.util.List;
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.Employee; import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
import com.example.rhizome.app.domain.model.SearchConditionEmployee; import com.example.rhizome.app.domain.model.SearchConditionEmployee;
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;
/**
* EmployeeテーブルのEntity
*
* @author IT-College
*/
@Entity @Entity
@Table(name = "employee") @Table(name = "employee")
@Data @Data
@@ -24,77 +29,146 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
public class EmployeeEntity { public class EmployeeEntity {
@Id /**
@GeneratedValue(strategy = GenerationType.IDENTITY) * 社員ID
@Column(name = "id_employee", nullable = false) */
private Integer idEmployee; @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_employee", nullable = false)
private Integer idEmployee;
@Column(name = "nm_employee", nullable = false) /**
private String nmEmployee; * 社員名
*/
@Column(name = "nm_employee", nullable = false)
private String nmEmployee;
@Column(name = "kn_employee", nullable = false) /**
private String knEmployee; * 社員名カナ
*/
@Column(name = "kn_employee", nullable = false)
private String knEmployee;
@Column(name = "mail_address", nullable = false) /**
private String mailAddress; * メールアドレス
*/
@Column(name = "mail_address", nullable = false)
private String mailAddress;
@Column(name = "password", nullable = false) /**
private String password; * パスワード
*/
@Column(name = "password", nullable = false)
private String password;
@Column(name = "admin_auth", nullable = false) /**
private Integer adminAuth; * 管理者権限
*/
@Column(name = "admin_auth", nullable = false)
private Integer adminAuth;
@Column(name = "id_department", nullable = false) /**
private Integer idDepartment; * 部署ID
*/
@Column(name = "id_department", nullable = false)
private Integer idDepartment;
public static EmployeeEntity convertFrom(Employee employee) {
return new EmployeeEntity(
employee.getIdEmployee(),
employee.getNmEmployee(),
employee.getKnEmployee(),
employee.getMailAddress(),
employee.getPassword(),
employee.getAdminAuth(),
employee.getIdDepartment());
}
public static EmployeeEntity convertFrom(SearchConditionEmployee searchConditionEmployee) { /**
EmployeeEntity employeeEntity = new EmployeeEntity(); * Employee(BusinessLogic 依存)を EmployeeEntity(DataAccess層依存)に変換します。
*
* @param employee Employee Table の中身
* @return EmployeeEntity のインスタンス(1レコード分)
*/
public static EmployeeEntity convertFrom(Employee employee) {
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
return new EmployeeEntity(
employee.getIdEmployee(),
employee.getNmEmployee(),
employee.getKnEmployee(),
employee.getMailAddress(),
employee.getPassword(),
employee.getAdminAuth(),
employee.getIdDepartment()
);
}
employeeEntity.setIdEmployee(searchConditionEmployee.getIdEmployee()); /**
employeeEntity.setNmEmployee(searchConditionEmployee.getNmEmployee()); * SearchConditionEmployee(BusinessLogic 依存)を EmployeeEntity(DataAccess層依存)に変換します。
employeeEntity.setKnEmployee(searchConditionEmployee.getKnEmployee()); * (コンストラクタを使用せず、Setterを利用したパターン)
employeeEntity.setMailAddress(searchConditionEmployee.getMailAddress()); *
employeeEntity.setIdDepartment(searchConditionEmployee.getIdDepartment()); * @param searchConditionEmployee 検索条件
* @return EmployeeEntity のインスタンス(1レコード分)
*/
public static EmployeeEntity convertFrom(SearchConditionEmployee searchConditionEmployee) {
EmployeeEntity employeeEntity = new EmployeeEntity();
return employeeEntity; employeeEntity.setIdEmployee(searchConditionEmployee.getIdEmployee());
employeeEntity.setNmEmployee(searchConditionEmployee.getNmEmployee());
employeeEntity.setKnEmployee(searchConditionEmployee.getKnEmployee());
employeeEntity.setMailAddress(searchConditionEmployee.getMailAddress());
employeeEntity.setIdDepartment(searchConditionEmployee.getIdDepartment());
}
public static Employee createEmployee(EmployeeEntity employeeEntity) { return employeeEntity;
return new Employee(
employeeEntity.getIdEmployee(),
employeeEntity.getNmEmployee(),
employeeEntity.getKnEmployee(),
employeeEntity.getMailAddress(),
employeeEntity.getPassword(),
employeeEntity.getAdminAuth(),
employeeEntity.getIdDepartment());
}
public static List<Employee> createEmployeeList(List<EmployeeEntity> employeeEntityList) { }
return employeeEntityList.stream().map(EmployeeEntity::createEmployee).toList();
}
public LoginUser createLoginUser() { /**
return new LoginUser( * EmployeeEntity(DataAccess層依存)から Employee (BusinessLogic層依存型)に変換します。
getIdEmployee(), *
getNmEmployee(), * @param employeeEntity Employee Table のインスタンス
getKnEmployee(), * @return employee インスタンス
getMailAddress(), */
getPassword(), public static Employee createEmployee(EmployeeEntity employeeEntity) {
getAdminAuth(), // 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
getIdDepartment()); return new Employee(
} employeeEntity.getIdEmployee(),
employeeEntity.getNmEmployee(),
employeeEntity.getKnEmployee(),
employeeEntity.getMailAddress(),
employeeEntity.getPassword(),
employeeEntity.getAdminAuth(),
employeeEntity.getIdDepartment()
);
}
/**
* EmployeeEntity(DataAccess層依存) から Employee (BusinessLogic層依存型)に変換します。(リスト版)
*
* @param employeeEntityList EmployeeEntity インスタンスのリスト
* @return Employee インスタンスのリスト
*/
public static List<Employee> createEmployeeList(List<EmployeeEntity> employeeEntityList) {
/* 従来の書き方
List<Employee> employeeList = new ArrayList<>();
for(EmployeeEntity employeeEntity:employeeEntityList){
Employee employee = EmployeeEntity.createEmployee(employeeEntity);
employeeList.add(employee);
}
return employeeList;
*/
// Stream APIを使用すると1行で書けます。
return employeeEntityList.stream().map(EmployeeEntity::createEmployee).toList();
}
/**
* EmployeeEntity(DataAccess層依存) から LoginUser (BusinessLogic層依存型)情報を作成します。
*
* @return loginUser (ログイン者の情報) インスタンス
*/
public LoginUser createLoginUser() {
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
return new LoginUser(
getIdEmployee(),
getNmEmployee(),
getKnEmployee(),
getMailAddress(),
getPassword(),
getAdminAuth(),
getIdDepartment()
);
}
} }

View File

@@ -1,31 +1,50 @@
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:
* 関数型インターフェースです。
* JPAの一部として提供されていて、エンティティの情報を元に動的にクエリを生成し、DBからデータを取得します。
* 使い方:
* toPredicate をOverrideして使います。
* パラメータ:
* Root<T>:ルートエンティティを指します。<T>に指定したエンティティ(今回はDepartmentEntity)を用いてメンバにアクセスします。
* CriteriaQuery<\?>:サブクエリを作成する際に使用します。※今回は使用しません
* CriteriaBuilder:条件式(Where句以降の条件)の部分のクエリを作るためのビルダーです。
* 戻り値はクエリを格納しているPredicateオブジェクトとなります。
*/
@Repository @Repository
public interface DepartmentRepository public interface DepartmentRepository extends JpaRepository<DepartmentEntity, Integer>, JpaSpecificationExecutor<DepartmentEntity> {
extends JpaRepository<DepartmentEntity, Integer>, JpaSpecificationExecutor<DepartmentEntity> {
static Specification<DepartmentEntity> idDepartmentEqual(Integer idDepartment) {
return idDepartment == null ? null
: (Specification<DepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
.equal(root.get("idDepartment"), idDepartment);
}
static Specification<DepartmentEntity> nmDepartmentEqual(String nmDepartment) { static Specification<DepartmentEntity> idDepartmentEqual(Integer idDepartment) {
return (nmDepartment == null || nmDepartment.isEmpty()) ? null return idDepartment == null ?
: (Specification<DepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder null :
.like(root.get("nmDepartment"), nmDepartment); // 戻り値の型 Specification<DepartmentEntity> にキャスト
} (Specification<DepartmentEntity>)
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idDepartment' = idDepartment(変数)"
// を作成している
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idDepartment"), idDepartment);
}
static Specification<DepartmentEntity> nmDepartmentLike(String nmDepartment) { static Specification<DepartmentEntity> nmDepartmentEqual(String nmDepartment) {
return (nmDepartment == null || nmDepartment.isEmpty()) ? null return (nmDepartment == null || nmDepartment.isEmpty()) ?
: (Specification<DepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder null :
.like(root.get("nmDepartment"), "%" + nmDepartment + "%"); (Specification<DepartmentEntity>)
} (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmDepartment"), nmDepartment);
}
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,42 +1,61 @@
package com.example.rhizome.app.infra.repository; package com.example.rhizome.app.infra.repository;
import com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity;
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.EmployeeDepartmentEntity; /**
* ワンポイント情報(ここで登場する関数型インターフェース Specification について解説します)
* Specification:
* 関数型インターフェースです。
* JPAの一部として提供されていて、エンティティの情報を元に動的にクエリを生成し、DBからデータを取得します。
* 使い方:
* toPredicate をOverrideして使います。
* パラメータ:
* Root<T>:ルートエンティティを指します。<T>に指定したエンティティ(今回はDepartmentEntity)を用いてメンバにアクセスします。
* CriteriaQuery<\?>:サブクエリを作成する際に使用します。※今回は使用しません
* CriteriaBuilder:条件式(Where句以降の条件)の部分のクエリを作るためのビルダーです。
* 戻り値はクエリを格納しているPredicateオブジェクトとなります。
*/
@Repository @Repository
public interface EmployeeInfoRepository public interface EmployeeInfoRepository extends JpaRepository<EmployeeDepartmentEntity, Integer>, JpaSpecificationExecutor<EmployeeDepartmentEntity> {
extends JpaRepository<EmployeeDepartmentEntity, Integer>, JpaSpecificationExecutor<EmployeeDepartmentEntity> {
static Specification<EmployeeDepartmentEntity> idEmployeeEqual(Integer idEmployee) { static Specification<EmployeeDepartmentEntity> idEmployeeEqual(Integer idEmployee) {
return idEmployee == null ? null return idEmployee == null ?
: (Specification<EmployeeDepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder null :
.equal(root.get("idEmployee"), idEmployee); // 戻り値の型 Specification<EmployeeDepartmentEntity> にキャスト
} (Specification<EmployeeDepartmentEntity>)
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idEmployee' = idEmployee(変数)"
// を作成している
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idEmployee"), idEmployee);
}
static Specification<EmployeeDepartmentEntity> nmEmployeeEqual(String nmEmployee) { static Specification<EmployeeDepartmentEntity> nmEmployeeEqual(String nmEmployee) {
return (nmEmployee == null || nmEmployee.isEmpty()) ? null return (nmEmployee == null || nmEmployee.isEmpty()) ?
: (Specification<EmployeeDepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder null :
.like(root.get("nmEmployee"), "%" + nmEmployee + "%"); (Specification<EmployeeDepartmentEntity>)
} (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmEmployee"), "%" + nmEmployee + "%");
}
static Specification<EmployeeDepartmentEntity> knEmployeeEqual(String knEmployee) { static Specification<EmployeeDepartmentEntity> knEmployeeEqual(String knEmployee) {
return (knEmployee == null || knEmployee.isEmpty()) ? null return (knEmployee == null || knEmployee.isEmpty()) ?
: (Specification<EmployeeDepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder null :
.like(root.get("knEmployee"), "%" + knEmployee + "%"); (Specification<EmployeeDepartmentEntity>)
} (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("knEmployee"), "%" + knEmployee + "%");
}
static Specification<EmployeeDepartmentEntity> mailAddressEqual(String mailAddress) { static Specification<EmployeeDepartmentEntity> mailAddressEqual(String mailAddress) {
return (mailAddress == null || mailAddress.isEmpty()) ? null return (mailAddress == null || mailAddress.isEmpty()) ?
: (Specification<EmployeeDepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder null :
.like(root.get("mailAddress"), "%" + mailAddress + "%"); (Specification<EmployeeDepartmentEntity>)
} (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("mailAddress"), "%" + mailAddress + "%");
}
static Specification<EmployeeDepartmentEntity> idDepartmentEqual(Integer idDepartment) { static Specification<EmployeeDepartmentEntity> idDepartmentEqual(Integer idDepartment) {
return (root, query, criteriaBuilder) -> idDepartment == null ? null return (root, query, criteriaBuilder) ->
: criteriaBuilder.equal(root.join("department").get("idDepartment"), idDepartment); idDepartment == null ? null :
} criteriaBuilder.equal(root.join("department").get("idDepartment"), idDepartment);
}
} }

View File

@@ -1,20 +1,28 @@
package com.example.rhizome.app.infra.repository; package com.example.rhizome.app.infra.repository;
import com.example.rhizome.app.infra.entity.EmployeeEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.example.rhizome.app.infra.entity.EmployeeEntity;
@Repository @Repository
public interface EmployeeRepository extends JpaRepository<EmployeeEntity, Integer> { public interface EmployeeRepository extends JpaRepository<EmployeeEntity, Integer> {
Optional<EmployeeEntity> findByMailAddressAndPassword(String mailAddress, String password); Optional<EmployeeEntity> findByMailAddressAndPassword(String mailAddress, String password);
Optional<EmployeeEntity> findByMailAddress(String mail); /**
* メールアドレスで検索
**/
Optional<EmployeeEntity> findByMailAddress(String mail);
Optional<EmployeeEntity> findByIdEmployee(Integer idEmployee); /**
* IDで検索
**/
Optional<EmployeeEntity> findByIdEmployee(Integer idEmployee);
List<EmployeeEntity> findByIdDepartment(Integer idDepartment); /**
* IDで検索
**/
List<EmployeeEntity> findByIdDepartment(Integer idDepartment);
} }

View File

@@ -1,8 +1,9 @@
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 static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*;
import java.util.List; import java.util.Objects;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -17,84 +18,106 @@ 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.Employee; import com.example.rhizome.app.domain.model.LoginUser;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
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.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(DeleteDepartmentController.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 = "エラーが発生しました!";
HttpSession httpSession; HttpSession httpSession;
DeleteDepartment deleteDepartment; DeleteDepartment deleteDepartment;
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
SearchEmployee searchEmployee;
@Autowired @Autowired
public DeleteDepartmentController(DeleteDepartment deleteDepartment, HttpSession httpSession, public DeleteDepartmentController(DeleteDepartment deleteDepartment, SearchDepartment searchDepartment, HttpSession httpSession) {
SearchDepartment searchDepartment, SearchEmployee searchEmployee) { this.httpSession = httpSession;
this.httpSession = httpSession; this.deleteDepartment = deleteDepartment;
this.deleteDepartment = deleteDepartment; this.searchDepartment = searchDepartment;
this.searchDepartment = searchDepartment; }
this.searchEmployee = searchEmployee;
}
@PermissionCheck /**
@SessionCheck * 削除処理のコントローラ
@RequestMapping(value = DELETE_DEPARTMENT, method = RequestMethod.POST) *
public String deleteD(@RequestParam("idDepartment") Integer idDepartment, Model model) { * @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 { try {
// 部署一覧を取得し、画面に返す用のクラスに詰め替える
// 作成した部署一覧をセット
model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll())
);
List<DepartmentForm> list = DepartmentForm.convertFrom( // 削除処理実施
searchDepartment.searchByDepartmentId(new SearchConditionDepartment(idDepartment, null))); deleteExec(
model,
idDepartment,
LoginUserForm.convertTo((LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER)));
deleteExec( // 検索画面に遷移
model, return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO_FORM_EMPTY;
idDepartment,
list);
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO_FORM_EMPTY; } catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
} catch (Exception e) { e.printStackTrace();
httpSession.invalidate(); // エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
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) {
private void deleteExec(Model model, Integer idDepartment, List<DepartmentForm> list) { final String DELETE_TARGET_ID_CAN_NOT_DELETE = "ログイン者自身は削除出来ません。";
final String DELETE_COMPLETE = "削除しました。";
final String DELETE_ID_NOT_EXISTS = "削除対象のIDが不明です。"; // ログインしている人が、削除対象かチェック
final String DELETE_TARGET_ID_CAN_NOT_DELETE = "1名以上が所属している部署は削除出来ません。"; if (Objects.equals(loginUser.getIdDepartment(), idDepartment)) {
final String DELETE_COMPLETE = "削除しました。"; // 削除対象だった場合
// エラーメッセージをセット
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DELETE_TARGET_ID_CAN_NOT_DELETE));
// 検索画面に遷移
return;
}
if (list.isEmpty()) { // 削除を実施
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DELETE_ID_NOT_EXISTS)); deleteDepartment.deleteDepartment(idDepartment);
}
List<Employee> employee = searchEmployee.searchEmployeeByIdDepartment(list.get(0).getIdDepartment()); // 削除完了したメッセージをセット
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(DELETE_COMPLETE));
if (!employee.isEmpty()) { }
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR,
new MessageForm(DELETE_TARGET_ID_CAN_NOT_DELETE));
return;
}
deleteDepartment.deleteDepartment(idDepartment);
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(DELETE_COMPLETE));
}
} }

View File

@@ -1,19 +1,5 @@
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;
@@ -26,66 +12,110 @@ 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 {
private final static Logger LOGGER = Logger.getLogger(DeleteEmployeeController.class.getName()); // ログ出力用インスタンス
private final static Logger LOGGER = Logger.getLogger(DeleteEmployeeController.class.getName());
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; // エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession; HttpSession httpSession;
DeleteEmployee deleteEmployee; DeleteEmployee deleteEmployee;
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
@Autowired @Autowired
public DeleteEmployeeController(DeleteEmployee deleteEmployee, SearchDepartment searchDepartment, public DeleteEmployeeController(DeleteEmployee deleteEmployee, SearchDepartment searchDepartment, HttpSession httpSession) {
HttpSession httpSession) { this.httpSession = httpSession;
this.httpSession = httpSession; this.deleteEmployee = deleteEmployee;
this.deleteEmployee = deleteEmployee; this.searchDepartment = searchDepartment;
this.searchDepartment = searchDepartment; }
}
@PermissionCheck /**
@SessionCheck * 削除処理のコントローラ
@RequestMapping(value = DELETE_EMPLOYEE, method = RequestMethod.POST) *
public String deleteEmployee(@RequestParam("idEmployee") Integer idEmployee, Model model) { * @param idEmployee 削除対象のemployeeId
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = DELETE_EMPLOYEE, method = RequestMethod.POST)
public String deleteEmployee(@RequestParam("idEmployee") Integer idEmployee, Model model) {
try { try {
model.addAttribute( // 部署一覧を取得し、画面に返す用のクラスに詰め替える
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, // 作成した部署一覧をセット
DepartmentForm.convertFrom(searchDepartment.selectAll())); model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll())
);
deleteExec( // 削除処理実施
model, deleteExec(
idEmployee, model,
LoginUserForm.convertTo((LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER))); idEmployee,
LoginUserForm.convertTo((LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER)));
return "forward:" + TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_INFO_FORM_EMPTY; // 検索画面に遷移
return "forward:" + TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_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); // エラーログ出力
return TransitionTargetPageNameKeyword.ERROR_HTML; LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
} // エラー画面遷移
} return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
private void deleteExec(Model model, Integer idEmployee, LoginUser loginUser) { /**
* 削除処理実施
*
* @param model ビューにデータを渡すためのコンテナ
* @param idEmployee 削除対象のemployeeId
* @param loginUser ログインユーザー情報
*/
private void deleteExec(Model model, Integer idEmployee, LoginUser loginUser) {
final String DELETE_TARGET_ID_CAN_NOT_DELETE = "ログイン者自身は削除出来ません。"; final String DELETE_TARGET_ID_CAN_NOT_DELETE = "ログイン者自身は削除出来ません。";
final String DELETE_COMPLETE = "削除しました。"; final String DELETE_COMPLETE = "削除しました。";
if (Objects.equals(loginUser.getIdEmployee(), idEmployee)) { // ログインしている人が、削除対象かチェック
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, if (Objects.equals(loginUser.getIdEmployee(), idEmployee)) {
new MessageForm(DELETE_TARGET_ID_CAN_NOT_DELETE)); // 削除対象だった場合
return; // エラーメッセージをセット
} model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DELETE_TARGET_ID_CAN_NOT_DELETE));
// 検索画面に遷移
return;
}
deleteEmployee.deleteEmployee(idEmployee); // 削除を実施
deleteEmployee.deleteEmployee(idEmployee);
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(DELETE_COMPLETE)); // 削除完了したメッセージをセット
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(DELETE_COMPLETE));
} }
} }

View File

@@ -1,42 +1,50 @@
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 com.example.rhizome.app.domain.service.impl.LoginImpl;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import javax.servlet.http.HttpSession; import com.example.rhizome.app.presentation.form.LoginUserForm;
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.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import com.example.rhizome.app.domain.service.impl.LoginImpl; import javax.servlet.http.HttpSession;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.rhizome.app.presentation.form.LoginUserForm; import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*;
@Controller @Controller
public class IndexController { public class IndexController {
HttpSession httpSession; HttpSession httpSession;
@Autowired @Autowired
public IndexController(HttpSession httpSession, LoginImpl loginImpl) { public IndexController(HttpSession httpSession, LoginImpl loginImpl) {
this.httpSession = httpSession; this.httpSession = httpSession;
} }
@ModelAttribute @ModelAttribute
public LoginUserForm loginUserForm() { public LoginUserForm loginUserForm() {
return new LoginUserForm(); return new LoginUserForm();
} }
@RequestMapping(value = { INDEX_BLANK, INDEX_SLASH, INDEX_LOGIN }) /**
public String index(Model model) { * ログイン画面表示処理
if (httpSession != null) { *
httpSession.invalidate(); * @param model ビューにデータを渡すためのコンテナ
} * @return 遷移先の画面
*/
@RequestMapping(value = {INDEX_BLANK, INDEX_SLASH, INDEX_LOGIN})
public String index(Model model) {
// セッション情報を破棄
if (httpSession != null) {
httpSession.invalidate();
}
model.addAttribute(PageReturnAttributeKeyword.LOGIN_INFO_FORM, loginUserForm()); // 空のFormをSessionに用意
model.addAttribute(PageReturnAttributeKeyword.LOGIN_INFO_FORM, loginUserForm());
return LOGIN_HTML; // ログイン画面に遷移
} return LOGIN_HTML;
}
} }

View File

@@ -1,66 +0,0 @@
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.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.domain.service.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.InsertDepartmentForm;
@Controller
public class InsertDepartmentConfirmController {
private final static Logger LOGGER = Logger.getLogger(InsertDepartmentConfirmController.class.getName());
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession;
SearchDepartment searchDepartment;
@Autowired
public InsertDepartmentConfirmController(
HttpSession httpSession,
SearchDepartmentImpl searchDepartment) {
this.httpSession = httpSession;
this.searchDepartment = searchDepartment;
}
@ModelAttribute
public InsertDepartmentForm insertDepartmentForm() {
return new InsertDepartmentForm();
}
@PermissionCheck
@SessionCheck
@RequestMapping(value = INSERT_DEPARTMENT_CONFIRM, method = RequestMethod.POST)
public String insertDepartmentConfirm(InsertDepartmentForm insertDepartmentForm, Model model) {
try {
model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm);
return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_CONFIRM_HTML;
} catch (Exception e) {
httpSession.invalidate();
e.printStackTrace();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
}

View File

@@ -1,120 +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.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.RegisterDepartment;
import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.domain.service.impl.RegisterDepartmentImpl;
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.InsertDepartmentForm;
import com.example.rhizome.app.presentation.form.MessageForm;
@Controller
public class InsertDepartmentController {
private final static Logger LOGGER = Logger.getLogger(InsertDepartmentController.class.getName());
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession;
RegisterDepartment registerDepartment;
SearchDepartment searchDepartment;
@Autowired
public InsertDepartmentController(HttpSession httpSession, RegisterDepartmentImpl registerEmployee,
SearchDepartment searchDepartment) {
this.httpSession = httpSession;
this.registerDepartment = registerEmployee;
this.searchDepartment = searchDepartment;
}
@ModelAttribute
public InsertDepartmentForm insertDepartmentForm() {
return new InsertDepartmentForm();
}
@PermissionCheck
@SessionCheck
@RequestMapping(value = INSERT_DEPARTMENT, method = RequestMethod.POST)
public String insertDepartment(InsertDepartmentForm insertDepartmentForm, Model model) {
try {
List<String> error = validateParameter(
insertDepartmentForm.getNmDepartment());
if (!error.isEmpty()) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR,
new MessageForm(String.join(", ", error) + "が不正です。"));
model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm);
return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML;
}
final String DUPLICATION = "既に同名の部署が存在します。";
SearchConditionDepartment searchConditionDepartment = new SearchConditionDepartment(null,
insertDepartmentForm.getNmDepartment());
List<Department> departmentList = searchDepartment.searchByDepartmentName(searchConditionDepartment);
if (!departmentList.isEmpty()) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION));
model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm);
return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML;
}
registerDepartment.registerDepartment(InsertDepartmentForm.convertTo(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> validateParameter(
String departmentName) {
final String DEPARTMENT_NAME_NULL_BLANK = "部署名";
List<String> error = new ArrayList<>();
if (isNullOrBlank(departmentName)) {
error.add(DEPARTMENT_NAME_NULL_BLANK);
}
return error;
}
private static boolean isNullOrBlank(String str) {
if (null == str) {
return true;
}
return str.isBlank();
}
}

View File

@@ -17,48 +17,76 @@ 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.RegisterDepartment; import com.example.rhizome.app.domain.service.RegisterDepartment;
import com.example.rhizome.app.domain.service.SearchDepartment;
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.InsertDepartmentForm; import com.example.rhizome.app.presentation.form.InsertDepartmentForm;
/**
* 登録画面表示用コントローラ
* 部署登録画面を表示するだけ
*/
@Controller @Controller
public class InsertDepartmentInputController { public class InsertDepartmentInputController {
private final static Logger LOGGER = Logger.getLogger(InsertDepartmentInputController.class.getName()); // ログ出力用インスタンス
private final static Logger LOGGER = Logger.getLogger(InsertDepartmentInputController.class.getName());
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; // エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession; HttpSession httpSession;
RegisterDepartment registerDepartment; RegisterDepartment registerDepartment;
SearchDepartment searchDepartment;
@Autowired @Autowired
public InsertDepartmentInputController(HttpSession httpSession, RegisterDepartment registerDepartment) { public InsertDepartmentInputController(HttpSession httpSession, RegisterDepartment registerDepartment, SearchDepartment searchDepartment) {
this.httpSession = httpSession; this.httpSession = httpSession;
this.registerDepartment = registerDepartment; this.registerDepartment = registerDepartment;
} this.searchDepartment = searchDepartment;
}
@ModelAttribute @ModelAttribute
public InsertDepartmentForm insertDepartmentForm() { public InsertDepartmentForm insertDepartmentForm() {
return new InsertDepartmentForm(); return new InsertDepartmentForm();
} }
@SessionCheck
@PermissionCheck
@RequestMapping(value = INSERT_DEPARTMENT_INPUT, method = RequestMethod.POST)
public String insertInput(InsertDepartmentForm insertDepartmentForm, Model model) {
try { /**
model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm); * 登録画面表示処理
*
* @param insertDepartmentForm 登録画面のフォーム
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@SessionCheck
@PermissionCheck
@RequestMapping(value = INSERT_DEPARTMENT_INPUT, method = RequestMethod.POST)
public String insertInput(InsertDepartmentForm insertDepartmentForm, Model model) {
return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML; try {
// 部署コードリストを作成し、画面に返す値としてセット
//model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(searchDepartment.selectAll()));
} catch (Exception e) { // パラメータをセット
httpSession.invalidate(); model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm);
e.printStackTrace(); // 登録画面に遷移
return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML;
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); } catch (Exception e) {
return TransitionTargetPageNameKeyword.ERROR_HTML; // ログイン情報の破棄
} httpSession.invalidate();
}
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
} }

View File

@@ -1,20 +1,5 @@
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.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.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.Employee; import com.example.rhizome.app.domain.model.Employee;
@@ -27,73 +12,122 @@ 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.InsertEmployeeForm; import com.example.rhizome.app.presentation.form.InsertEmployeeForm;
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.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_CONFIRM;
/**
* 新規登録者情報チェック用のコントローラ
*/
@Controller @Controller
public class InsertEmployeeConfirmController { public class InsertEmployeeConfirmController {
private final static Logger LOGGER = Logger.getLogger(InsertEmployeeConfirmController.class.getName()); // ログ出力用インスタンス
private final static Logger LOGGER = Logger.getLogger(InsertEmployeeConfirmController.class.getName());
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; // エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession; HttpSession httpSession;
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
SearchEmployee searchEmployee; SearchEmployee searchEmployee;
@Autowired @Autowired
public InsertEmployeeConfirmController( public InsertEmployeeConfirmController(
HttpSession httpSession, HttpSession httpSession,
SearchDepartmentImpl searchDepartment, SearchDepartmentImpl searchDepartment,
SearchEmployeeImpl searchEmployee) { SearchEmployeeImpl searchEmployee
this.httpSession = httpSession; ) {
this.searchDepartment = searchDepartment; this.httpSession = httpSession;
this.searchEmployee = searchEmployee; this.searchDepartment = searchDepartment;
} this.searchEmployee = searchEmployee;
}
@ModelAttribute @ModelAttribute
public InsertEmployeeForm insertEmployeeForm() { public InsertEmployeeForm insertEmployeeForm() {
return new InsertEmployeeForm(); return new InsertEmployeeForm();
} }
@PermissionCheck /**
@SessionCheck * 登録情報のチェックを行う
@RequestMapping(value = INSERT_EMPLOYEE_CONFIRM, method = RequestMethod.POST) *
public String insertEmployeeConfirm(InsertEmployeeForm insertEmployeeForm, Model model) { * @param insertEmployeeForm 登録情報
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = INSERT_EMPLOYEE_CONFIRM, method = RequestMethod.POST)
public String insertEmployeeConfirm(InsertEmployeeForm insertEmployeeForm, Model model) {
try { try {
model.addAttribute( // 部署一覧を取得し、画面に返す用のクラスに詰め替える
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, // 作成した部署一覧をセット
DepartmentForm.convertFrom( model.addAttribute(
searchDepartment.selectAll())); PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(
searchDepartment.selectAll()
));
List<String> error = insertEmployeeForm.validateParameter(); // 登録用パラメータチェック
List<String> error = insertEmployeeForm.validateParameter();
if (!error.isEmpty()) { // 入力内容に誤りがあるか
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, if (!error.isEmpty()) {
new MessageForm(String.join(", ", error) + "が不正です。")); // 誤りがあった場合
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm); // 誤りがあった箇所のエラーメッセージを表示
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML; model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(String.join(", ", error) + "が不正です。"));
} // 画面に返す為の登録情報をセット
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);
// 登録画面に遷移
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML;
}
final String DUPLICATION = "既に登録済みのメールアドレスです。"; final String DUPLICATION = "既に登録済みのメールアドレスです。";
List<Employee> employeeList = searchEmployee.searchEmployee(insertEmployeeForm.getMailAddress()); // 登録対象のメールアドレスを元に検索
List<Employee> employeeList = searchEmployee.searchEmployee(insertEmployeeForm.getMailAddress());
if (!employeeList.isEmpty()) { // 検索結果があるか
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION)); if (!employeeList.isEmpty()) {
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm); // 検索した結果0件ではない場合
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML; // 重複を許さないため、エラー処理
} model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION));
// 画面に返す為の登録情報をセット
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);
// 登録画面に遷移
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML;
}
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm); // 登録確認ページに遷移
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_CONFIRM_HTML; model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);
// 登録確認画面に遷移
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_CONFIRM_HTML;
} catch (Exception e) {
httpSession.invalidate();
e.printStackTrace(); } catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); e.printStackTrace();
return TransitionTargetPageNameKeyword.ERROR_HTML;
} // エラーログ出力
} LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
} }

View File

@@ -1,21 +1,5 @@
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.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.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.RegisterEmployee; import com.example.rhizome.app.domain.service.RegisterEmployee;
@@ -27,120 +11,188 @@ 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.InsertEmployeeForm; import com.example.rhizome.app.presentation.form.InsertEmployeeForm;
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.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.INSERT_EMPLOYEE;
/**
* 新規登録用のコントローラ
*/
@Controller @Controller
public class InsertEmployeeController { public class InsertEmployeeController {
private final static Logger LOGGER = Logger.getLogger(InsertEmployeeController.class.getName()); // ログ出力用インスタンス
private final static Logger LOGGER = Logger.getLogger(InsertEmployeeController.class.getName());
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; // エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession; HttpSession httpSession;
RegisterEmployee registerEmployee; RegisterEmployee registerEmployee;
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
@Autowired @Autowired
public InsertEmployeeController(HttpSession httpSession, RegisterEmployeeImpl registerEmployee, public InsertEmployeeController(HttpSession httpSession, RegisterEmployeeImpl registerEmployee, SearchDepartmentImpl searchDepartment) {
SearchDepartmentImpl searchDepartment) { this.httpSession = httpSession;
this.httpSession = httpSession; this.registerEmployee = registerEmployee;
this.registerEmployee = registerEmployee; this.searchDepartment = searchDepartment;
this.searchDepartment = searchDepartment; }
}
@ModelAttribute @ModelAttribute
public InsertEmployeeForm insertEmployeeForm() { public InsertEmployeeForm insertEmployeeForm() {
return new InsertEmployeeForm(); return new InsertEmployeeForm();
} }
@PermissionCheck /**
@SessionCheck * 新規登録画面表示処理
@RequestMapping(value = INSERT_EMPLOYEE, method = RequestMethod.POST) *
public String insertEmployee(InsertEmployeeForm insertEmployeeForm, Model model) { * @param insertEmployeeForm 登録情報
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = INSERT_EMPLOYEE, method = RequestMethod.POST)
public String insertEmployee(InsertEmployeeForm insertEmployeeForm, Model model) {
try { try {
model.addAttribute( // 部署一覧を取得し、画面に返す用のクラスに詰め替える
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, // 作成した部署一覧をセット
DepartmentForm.convertFrom( model.addAttribute(
searchDepartment.selectAll())); PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(
searchDepartment.selectAll()
));
List<String> error = validateParameter( // Confirm画面から渡ってきた値をチェック
insertEmployeeForm.getNmEmployee(), List<String> error = validateParameter(
insertEmployeeForm.getKnEmployee(), insertEmployeeForm.getNmEmployee(),
insertEmployeeForm.getMailAddress(), insertEmployeeForm.getKnEmployee(),
insertEmployeeForm.getPassword(), insertEmployeeForm.getMailAddress(),
insertEmployeeForm.getAdminAuth(), insertEmployeeForm.getPassword(),
insertEmployeeForm.getIdDepartment()); insertEmployeeForm.getAdminAuth(),
insertEmployeeForm.getIdDepartment()
);
if (!error.isEmpty()) { // エラーが1件以上有る場合
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, if (!error.isEmpty()) {
new MessageForm(String.join(", ", error) + "が不正です。")); // エラー内容を画面に表示
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML; model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(String.join(", ", error) + "が不正です。"));
} // 登録画面に遷移
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML;
}
registerEmployee.registerEmployee(InsertEmployeeForm.convertTo(insertEmployeeForm)); // 登録処理
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_RESULT_HTML; registerEmployee.registerEmployee(InsertEmployeeForm.convertTo(insertEmployeeForm));
// 登録結果画面に遷移
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_RESULT_HTML;
} catch (Exception e) { } catch (Exception e) {
httpSession.invalidate(); // ログイン情報の破棄
httpSession.invalidate();
e.printStackTrace(); e.printStackTrace();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); // エラーログ出力
return TransitionTargetPageNameKeyword.ERROR_HTML; LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
} // エラー画面遷移
} return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
private List<String> validateParameter( /**
String employeeName, * @param employeeName 登録対象の名前
String employeeKana, * @param employeeKana 登録対象のカナ
String mailAddress, * @param mailAddress 登録対象のメールアドレス
String password, * @param password 登録対象のパスワード
Integer management, * @param management システム権限
Integer departmentId) { * @param departmentId 部署ID
* @return エラーが有った場合はエラー文言、無ければ空のリストが返る
*/
private List<String> validateParameter(
String employeeName,
String employeeKana,
String mailAddress,
String password,
Integer management,
Integer departmentId
) {
final String EMPLOYEE_NAME_NULL_BLANK = "社員名"; final String EMPLOYEE_NAME_NULL_BLANK = "社員名";
final String EMPLOYEE_KANA_NULL_BLANK = "社員名フリガナ"; final String EMPLOYEE_KANA_NULL_BLANK = "社員名フリガナ";
final String MAIL_ADDRESS_NULL_BLANK = "メールアドレス"; final String MAIL_ADDRESS_NULL_BLANK = "メールアドレス";
final String PASSWORD_NULL_BLANK = "パスワード"; final String PASSWORD_NULL_BLANK = "パスワード";
final String MANAGEMENT_ERROR = "管理者権限指定"; final String MANAGEMENT_ERROR = "管理者権限指定";
final String DEPARTMENT_ID_NULL_BLANK = "所属部署"; final String DEPARTMENT_ID_NULL_BLANK = "所属部署";
List<String> error = new ArrayList<>(); List<String> error = new ArrayList<>();
if (isNullOrBlank(employeeName)) { // null or 空文字判定
error.add(EMPLOYEE_NAME_NULL_BLANK); if (isNullOrBlank(employeeName)) {
} // エラー内容を追加
error.add(EMPLOYEE_NAME_NULL_BLANK);
}
if (isNullOrBlank(employeeKana)) { // null or 空文字判定
error.add(EMPLOYEE_KANA_NULL_BLANK); if (isNullOrBlank(employeeKana)) {
} // エラー内容を追加
error.add(EMPLOYEE_KANA_NULL_BLANK);
}
if (isNullOrBlank(mailAddress)) { // null or 空文字判定
error.add(MAIL_ADDRESS_NULL_BLANK); if (isNullOrBlank(mailAddress)) {
} // エラー内容を追加
error.add(MAIL_ADDRESS_NULL_BLANK);
}
if (isNullOrBlank(password)) { // null or 空文字判定
error.add(PASSWORD_NULL_BLANK); if (isNullOrBlank(password)) {
} // エラー内容を追加
error.add(PASSWORD_NULL_BLANK);
}
if (management == null) { // 管理者権限の値が不正か
error.add(MANAGEMENT_ERROR); if (management == null) {
} // エラー内容を追加
error.add(MANAGEMENT_ERROR);
}
if (departmentId == null) { // 所属部署の値が不正か
error.add(DEPARTMENT_ID_NULL_BLANK); if (departmentId == null) {
} // エラー内容を追加
error.add(DEPARTMENT_ID_NULL_BLANK);
}
return error; return error;
} }
private static boolean isNullOrBlank(String str) { /**
if (null == str) { * 仮引数を null or 空 判定する
return true; *
} * @param str 判定対象の文字列
* @return true:null or 空 false:null or 空 では無い
*/
private static boolean isNullOrBlank(String str) {
if (null == str) {
return true;
}
return str.isBlank(); return str.isBlank();
} }
} }

View File

@@ -1,19 +1,5 @@
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.Logger;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.example.rhizome.aop.aspect.PermissionCheck; import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.service.RegisterEmployee; import com.example.rhizome.app.domain.service.RegisterEmployee;
@@ -22,51 +8,83 @@ import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAt
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.InsertEmployeeForm; import com.example.rhizome.app.presentation.form.InsertEmployeeForm;
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 javax.servlet.http.HttpSession;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT;
/**
* 登録画面表示用コントローラ
*/
@Controller @Controller
public class InsertEmployeeInputController { public class InsertEmployeeInputController {
private final static Logger LOGGER = Logger.getLogger(InsertEmployeeInputController.class.getName()); // ログ出力用インスタンス
private final static Logger LOGGER = Logger.getLogger(InsertEmployeeInputController.class.getName());
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; // エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession; HttpSession httpSession;
RegisterEmployee registerEmployee; RegisterEmployee registerEmployee;
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
@Autowired @Autowired
public InsertEmployeeInputController(HttpSession httpSession, RegisterEmployee registerEmployee, public InsertEmployeeInputController(HttpSession httpSession, RegisterEmployee registerEmployee, SearchDepartment searchDepartment) {
SearchDepartment searchDepartment) { this.httpSession = httpSession;
this.httpSession = httpSession; this.registerEmployee = registerEmployee;
this.registerEmployee = registerEmployee; this.searchDepartment = searchDepartment;
this.searchDepartment = searchDepartment; }
}
@ModelAttribute @ModelAttribute
public InsertEmployeeForm insertEmployeeForm() { public InsertEmployeeForm insertEmployeeForm() {
return new InsertEmployeeForm(); return new InsertEmployeeForm();
} }
@SessionCheck
@PermissionCheck
@RequestMapping(value = INSERT_EMPLOYEE_INPUT, method = RequestMethod.POST)
public String insertInput(InsertEmployeeForm insertEmployeeForm, Model model) {
try { /**
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, * 登録画面表示処理
DepartmentForm.convertFrom(searchDepartment.selectAll())); *
* @param insertEmployeeForm 登録画面のフォーム
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@SessionCheck
@PermissionCheck
@RequestMapping(value = INSERT_EMPLOYEE_INPUT, method = RequestMethod.POST)
public String insertInput(InsertEmployeeForm insertEmployeeForm, Model model) {
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm); try {
// 部署コードリストを作成し、画面に返す値としてセット
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(searchDepartment.selectAll()));
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML; // パラメータをセット
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);
} catch (Exception e) { // 登録画面に遷移
httpSession.invalidate(); return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML;
e.printStackTrace(); } catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); e.printStackTrace();
return TransitionTargetPageNameKeyword.ERROR_HTML;
} // エラーログ出力
} LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
} }

View File

@@ -1,18 +1,5 @@
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.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.model.LoginInfo; import com.example.rhizome.app.domain.model.LoginInfo;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
@@ -24,81 +11,138 @@ import com.example.rhizome.app.presentation.form.LoginInfoForm;
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 com.example.rhizome.app.presentation.form.UpdatePersonalUserForm; import com.example.rhizome.app.presentation.form.UpdatePersonalUserForm;
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 javax.servlet.http.HttpSession;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.DO_LOGIN;
/**
* ログイン関連のコントローラ
*/
@Controller @Controller
public class LoginController { public class LoginController {
private final static Logger LOGGER = Logger.getLogger(LoginController.class.getName()); // ログ出力用インスタンス
private final static Logger LOGGER = Logger.getLogger(LoginController.class.getName());
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; // エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession; HttpSession httpSession;
Login login; Login login;
@Autowired @Autowired
public LoginController(HttpSession httpSession, Login login) { public LoginController(HttpSession httpSession, Login login) {
this.httpSession = httpSession; this.httpSession = httpSession;
this.login = login; this.login = login;
} }
@ModelAttribute @ModelAttribute
public LoginUserForm loginUserForm() { public LoginUserForm loginUserForm() {
return new LoginUserForm(); return new LoginUserForm();
} }
@RequestMapping(value = DO_LOGIN, method = RequestMethod.POST) /**
public String doLogin(LoginInfoForm loginInfoForm, Model model) { * 画面から渡ってきたパラメータのチェックを行う
*
* @param loginInfoForm mailAddress, password を保持したインスタンス
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@RequestMapping(value = DO_LOGIN, method = RequestMethod.POST)
public String doLogin(LoginInfoForm loginInfoForm, Model model) {
final String MAIL_ADDRESS_PASSWORD_ERROR = "メールアドレス、パスワードの入力内容に誤りがあります"; // ログに出力する
final String LOGIN_ERROR = "IDまたはパスワードが間違っています"; final String MAIL_ADDRESS_PASSWORD_ERROR = "メールアドレス、パスワードの入力内容に誤りがあります";
// 発生しうるErrorに対するメッセージ
final String LOGIN_ERROR = "IDまたはパスワードが間違っています";
try { try {
if (!LoginUserForm.checkParameter(loginInfoForm)) { // mailAddress, password の入力に誤りがあるかチェック
if (!LoginUserForm.checkParameter(loginInfoForm)) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, // mail,passwordが仕様を満たしていない場合
new MessageForm(MAIL_ADDRESS_PASSWORD_ERROR)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(MAIL_ADDRESS_PASSWORD_ERROR));
model.addAttribute(PageReturnAttributeKeyword.LOGIN_INFO_FORM, loginInfoForm); // エラーだった場合に login.html に処理を戻す。mailAddress, password を login.htmlに表示するために
return TransitionTargetPageNameKeyword.LOGIN_HTML; // ここで addAttribute する
} model.addAttribute(PageReturnAttributeKeyword.LOGIN_INFO_FORM, loginInfoForm);
// login.html に遷移する様に設定
return TransitionTargetPageNameKeyword.LOGIN_HTML;
}
LoginInfo loginInfo = createLoginInfo(httpSession, loginInfoForm); // Login者情報インスタンスを作成
LoginInfo loginInfo = createLoginInfo(httpSession, loginInfoForm);
if (!login.canLogin(loginInfo)) { // login 可能かチェック
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(LOGIN_ERROR)); if (!login.canLogin(loginInfo)) {
model.addAttribute(PageReturnAttributeKeyword.LOGIN_INFO_FORM, loginInfoForm); // ログイン不可の場合、エラーメッセージをセットして入力された値とともに login.html を再表示
return TransitionTargetPageNameKeyword.LOGIN_HTML; // 画面に表示するエラーメッセージをセット
} model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(LOGIN_ERROR));
// 画面に表示する mailAddress, password をセット
model.addAttribute(PageReturnAttributeKeyword.LOGIN_INFO_FORM, loginInfoForm);
// login.html に遷移
return TransitionTargetPageNameKeyword.LOGIN_HTML;
}
LoginUser loginUser = login.doLogin(loginInfo); // ログイン(インスタンス作成)
LoginUser loginUser = login.doLogin(loginInfo);
httpSession.setAttribute(SessionKeyword.LOGIN_USER, LoginUserForm.convertFrom(loginUser)); // ログイン者の情報をセッション情報に格納
// セッションに loginUser 情報を保持し続ける = ログイン中として扱う
httpSession.setAttribute(SessionKeyword.LOGIN_USER, LoginUserForm.convertFrom(loginUser));
if (!loginUser.isAdminUser()) { // 管理者かチェック
model.addAttribute(PageReturnAttributeKeyword.UPDATE_PERSONAL_EMPLOYEE_USER_FORM, if (!loginUser.isAdminUser()) {
UpdatePersonalUserForm.convertFrom(loginUser)); // 管理者ではない場合直で自分の情報を更新するページに遷移する
return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML; // 編集対象のログイン者の情報を画面に渡す値にセット
} model.addAttribute(PageReturnAttributeKeyword.UPDATE_PERSONAL_EMPLOYEE_USER_FORM, UpdatePersonalUserForm.convertFrom(loginUser));
// 個人の情報更新ページに遷移
return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML;
}
return TransitionTargetPageNameKeyword.MENU_HTML; // メニュー画面に遷移
return TransitionTargetPageNameKeyword.MENU_HTML;
} catch (Exception e) { } catch (Exception e) {
httpSession.invalidate(); // ログイン情報の破棄
e.printStackTrace(); httpSession.invalidate();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); e.printStackTrace();
return TransitionTargetPageNameKeyword.ERROR_HTML; // エラーログ出力
} LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
} // エラー画面に遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
private static LoginInfo createLoginInfo(HttpSession httpSession, LoginInfoForm loginInfoForm) { /**
LoginUserForm loginUserForm = (LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER); * ログイン者情報のインスタンスを作成
*
* @param httpSession セッション情報
* @param loginInfoForm mailAddress, password を保持したインスタンス
*/
private static LoginInfo createLoginInfo(HttpSession httpSession, LoginInfoForm loginInfoForm) {
// セッションからログイン者情報を取得
LoginUserForm loginUserForm = (LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER);
if (loginUserForm != null) { // セッションにログイン者情報があるか
return new LoginInfo(loginUserForm.getMailAddress(), loginUserForm.getPassword()); if (loginUserForm != null) {
} // セッションにログイン者情報がある場合
return new LoginInfo(loginUserForm.getMailAddress(), loginUserForm.getPassword());
}
return new LoginInfo( // セッションにない場合は画面からの input 値 を取得
loginInfoForm.getMailAddress(), return new LoginInfo(
loginInfoForm.getPassword()); loginInfoForm.getMailAddress(),
} loginInfoForm.getPassword()
);
}
} }

View File

@@ -1,12 +1,10 @@
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 com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck;
import java.util.logging.Level; import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import java.util.logging.Logger; import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.LoginUserForm;
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;
@@ -14,46 +12,62 @@ 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 javax.servlet.http.HttpSession;
import com.example.rhizome.aop.aspect.SessionCheck; import java.util.logging.Level;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword; import java.util.logging.Logger;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.LoginUserForm;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.LOGOUT;
/**
* ログアウト処理のコントローラ
*/
@Controller @Controller
public class LogoutController { public class LogoutController {
private final static Logger LOGGER = Logger.getLogger(LogoutController.class.getName()); // ログ出力用インスタンス
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; private final static Logger LOGGER = Logger.getLogger(LogoutController.class.getName());
// エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession; HttpSession httpSession;
@Autowired @Autowired
public LogoutController(HttpSession httpSession) { public LogoutController(HttpSession httpSession) {
this.httpSession = httpSession; this.httpSession = httpSession;
} }
@ModelAttribute @ModelAttribute
public LoginUserForm loginUserForm() { public LoginUserForm loginUserForm() {
return new LoginUserForm(); return new LoginUserForm();
} }
@PermissionCheck /**
@SessionCheck * ログアウト処理
@RequestMapping(value = LOGOUT, method = RequestMethod.POST) *
public String doLogout(Model model) { * @param model ビューにデータを渡すためのコンテナ
try { * @return 遷移先の画面
httpSession.invalidate(); */
@PermissionCheck
@SessionCheck
@RequestMapping(value = LOGOUT, method = RequestMethod.POST)
public String doLogout(Model model) {
try {
// セッション情報の破棄
httpSession.invalidate();
model.addAttribute(PageReturnAttributeKeyword.LOGIN_INFO_FORM, loginUserForm()); // ログイン画面に遷移するための情報を設定
return TransitionTargetPageNameKeyword.LOGIN_HTML; model.addAttribute(PageReturnAttributeKeyword.LOGIN_INFO_FORM, loginUserForm());
// login.html に遷移
return TransitionTargetPageNameKeyword.LOGIN_HTML;
} catch (Exception e) { } catch (Exception e) {
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); // エラーログ出力
return TransitionTargetPageNameKeyword.ERROR_HTML; LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
} // エラーページに遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
} }
} }

View File

@@ -1,27 +1,33 @@
package com.example.rhizome.app.presentation.controller; package com.example.rhizome.app.presentation.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
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.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.MessageForm;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* メニュー画面表示用コントローラ
*/
@Controller @Controller
public class MenuController { public class MenuController {
@ModelAttribute @ModelAttribute
public MessageForm messageForm() { public MessageForm messageForm() {
return new MessageForm(); return new MessageForm();
} }
@PermissionCheck /**
@SessionCheck * メニュー画面に遷移
@RequestMapping(value = TransitionTargetPageNameKeyword.SHOW_MENU) */
public String showMenu() { @PermissionCheck
return TransitionTargetPageNameKeyword.MENU_HTML; @SessionCheck
} @RequestMapping(value = TransitionTargetPageNameKeyword.SHOW_MENU)
public String showMenu() {
// メニュー画面遷移
return TransitionTargetPageNameKeyword.MENU_HTML;
}
} }

View File

@@ -15,68 +15,122 @@ 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 {
private final static Logger LOGGER = Logger.getLogger(SelectDepartmentController.class.getName()); // ログ出力用インスタンス
private final static Logger LOGGER = Logger.getLogger(SelectDepartmentController.class.getName());
// エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; HttpSession httpSession;
SearchDepartment searchDepartment;
HttpSession httpSession; @Autowired
SearchDepartment searchDepartment; public SelectDepartmentController(HttpSession httpSession, SearchDepartment searchDepartment) {
SearchEmployeeInfo searchEmployeeInfo; this.httpSession = httpSession;
this.searchDepartment = searchDepartment;
}
@Autowired @ModelAttribute
public SelectDepartmentController(HttpSession httpSession, SearchDepartment searchDepartment, public SearchConditionDepartmentForm searchConditionDepartmentForm() {
SearchEmployeeInfo searchEmployeeInfo) { return new SearchConditionDepartmentForm();
this.httpSession = httpSession; }
this.searchDepartment = searchDepartment;
this.searchEmployeeInfo = searchEmployeeInfo;
}
@ModelAttribute /**
public SearchConditionDepartmentForm searchConditionDepartmentForm() { * 部署検索画面表示処理コントローラ
return new SearchConditionDepartmentForm(); *
} * @param searchConditionDepartmentForm 検索画面のフォーム
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO, method = RequestMethod.POST)
public String select(SearchConditionDepartmentForm searchConditionDepartmentForm, Model model) {
@SessionCheck try {
@PermissionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT, method = RequestMethod.POST)
public String select(SearchConditionDepartmentForm searchConditionDepartmentForm, Model model) {
try {
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom( // 部署一覧を取得し、画面に返す用のクラスに詰め替える
searchDepartment // 作成した部署一覧をセット
.searchByWithLike(SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm)))); model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll()) //部署一覧をDBから取得→List<DepartmentForm>
//DepartmentをDepartmentFormという型に変換
//model.Attributet(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,変換した部署一覧)
//DBから部署一覧を取得して
//画面表示用のDepartmentFormに変換して
//departmentFormListという名前で画面に渡す
);
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML; // 検索条件を元に検索を実施
// 取得した EmployeeInfo( employee + department )の情報を画面に返す用の型に詰め替えてセット
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_INFO_FORM_LIST,
DepartmentForm.convertFrom(
searchDepartment.searchByWithLike(
SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm))));
//SearchConditionDepartmentForm…画面から送られた検索条件
//model.Attributet(PageReturnAttributeKeyword.DEPARTMENT_INFO_FORM_LIST,変換済み検索結果)
//画面で入力された検索条件を検索用オブジェクトに変換して
//その条件で部署を検索して
//検索結果を画面表示用のDepartmentFormに変換して、
//departmentInfoFormListという名前でHTMLに渡している
// 検索ページに遷移
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
} catch (Exception e) {
httpSession.invalidate();
e.printStackTrace(); } catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); e.printStackTrace();
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
} // エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
@SessionCheck }
@PermissionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO_FORM_EMPTY, method = RequestMethod.POST)
public String select(Model model) {
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom( /**
searchDepartment.searchBy(SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm())))); * 社員検索画面表示処理コントローラ
* 検索条件無しの状態を作るため、空の検索条件で検索した結果を画面に返す
*
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO_FORM_EMPTY, method = RequestMethod.POST)
public String select(Model model) {
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML; // 部署一覧を取得し、画面に返す用のクラスに詰め替える
} // 作成した部署一覧をセット
model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll())
);
// 検索条件を元に検索を実施
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_INFO_FORM_LIST,DepartmentForm.convertFrom(
searchDepartment.searchByWithLike(
SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm()
))));
// 検索ページに遷移
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
}
} }

View File

@@ -1,17 +1,5 @@
package com.example.rhizome.app.presentation.controller; package com.example.rhizome.app.presentation.controller;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.example.rhizome.aop.aspect.PermissionCheck; import com.example.rhizome.aop.aspect.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;
@@ -21,66 +9,113 @@ 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.EmployeeInfoForm; import com.example.rhizome.app.presentation.form.EmployeeInfoForm;
import com.example.rhizome.app.presentation.form.SearchConditionEmployeeForm; import com.example.rhizome.app.presentation.form.SearchConditionEmployeeForm;
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 javax.servlet.http.HttpSession;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* 社員検索画面用コントローラ リスト全件表示、検索表示、更新、削除が可能
*/
@Controller @Controller
public class SelectEmployeeController { public class SelectEmployeeController {
private final static Logger LOGGER = Logger.getLogger(SelectEmployeeController.class.getName()); // ログ出力用インスタンス
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; private final static Logger LOGGER = Logger.getLogger(SelectEmployeeController.class.getName());
// エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession; HttpSession httpSession;
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
SearchEmployeeInfo searchEmployeeInfo; SearchEmployeeInfo searchEmployeeInfo;
@Autowired @Autowired
public SelectEmployeeController(HttpSession httpSession, SearchDepartment searchDepartment, public SelectEmployeeController(HttpSession httpSession, SearchDepartment searchDepartment, SearchEmployeeInfo searchEmployeeInfo) {
SearchEmployeeInfo searchEmployeeInfo) { this.httpSession = httpSession;
this.httpSession = httpSession; this.searchDepartment = searchDepartment;
this.searchDepartment = searchDepartment; this.searchEmployeeInfo = searchEmployeeInfo;
this.searchEmployeeInfo = searchEmployeeInfo; }
}
@ModelAttribute @ModelAttribute
public SearchConditionEmployeeForm searchConditionEmployeeForm() { public SearchConditionEmployeeForm searchConditionEmployeeForm() {
return new SearchConditionEmployeeForm(); return new SearchConditionEmployeeForm();
} }
@PermissionCheck /**
@SessionCheck * 社員検索画面表示処理コントローラ
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_INFO, method = RequestMethod.POST) *
public String select(SearchConditionEmployeeForm searchConditionEmployeeForm, Model model) { * @param searchConditionEmployeeForm 検索画面のフォーム
try { * @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_INFO, method = RequestMethod.POST)
public String select(SearchConditionEmployeeForm searchConditionEmployeeForm, Model model) {
model.addAttribute( try {
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll()));
model.addAttribute(PageReturnAttributeKeyword.EMPLOYEE_INFO_FORM_LIST, EmployeeInfoForm.convertFrom( // 部署一覧を取得し、画面に返す用のクラスに詰め替える
searchEmployeeInfo.searchBy(SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm)))); // 作成した部署一覧をセット
return TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_HTML; model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll())
);
} catch (Exception e) { // 検索条件を元に検索を実施
httpSession.invalidate(); // 取得した EmployeeInfo( employee + department )の情報を画面に返す用の型に詰め替えてセット
model.addAttribute(PageReturnAttributeKeyword.EMPLOYEE_INFO_FORM_LIST, EmployeeInfoForm.convertFrom(searchEmployeeInfo.searchBy(SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm))));
// 検索ページに遷移
return TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_HTML;
e.printStackTrace();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); } catch (Exception e) {
return TransitionTargetPageNameKeyword.ERROR_HTML; // ログイン情報の破棄
} httpSession.invalidate();
} e.printStackTrace();
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_INFO_FORM_EMPTY, method = RequestMethod.POST) // エラーログ出力
public String select(Model model) { LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
model.addAttribute( // エラー画面遷移
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, return TransitionTargetPageNameKeyword.ERROR_HTML;
DepartmentForm.convertFrom(searchDepartment.selectAll())); }
model.addAttribute(PageReturnAttributeKeyword.EMPLOYEE_INFO_FORM_LIST, }
EmployeeInfoForm.convertFrom(
searchEmployeeInfo.searchBy(
SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm()))));
return TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_HTML; /**
} * 社員検索画面表示処理コントローラ
* 検索条件無しの状態を作るため、空の検索条件で検索した結果を画面に返す
*
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_INFO_FORM_EMPTY, method = RequestMethod.POST)
public String select(Model model) {
// 部署一覧を取得し、画面に返す用のクラスに詰め替える
// 作成した部署一覧をセット
model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll())
);
// 検索条件を元に検索を実施
model.addAttribute(PageReturnAttributeKeyword.EMPLOYEE_INFO_FORM_LIST,
EmployeeInfoForm.convertFrom(
searchEmployeeInfo.searchBy(
SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm())
)));
// 検索ページに遷移
return TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_HTML;
}
} }

View File

@@ -1,83 +0,0 @@
package com.example.rhizome.app.presentation.controller;
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 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.Department;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.domain.service.SearchEmployeeInfo;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.MessageForm;
import com.example.rhizome.app.presentation.form.SearchConditionDepartmentForm;
import com.example.rhizome.app.presentation.form.UpdateDepartmentForm;
@Controller
public class UpdateDepartmentController {
private final static Logger LOGGER = Logger.getLogger(UpdateDepartmentController.class.getName());
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession;
SearchDepartment searchDepartment;
SearchEmployeeInfo searchEmployeeInfo;
@Autowired
public UpdateDepartmentController(HttpSession httpSession, SearchDepartment searchDepartment) {
this.httpSession = httpSession;
this.searchDepartment = searchDepartment;
}
@ModelAttribute
public SearchConditionDepartmentForm searchConditionDepartmentForm() {
return new SearchConditionDepartmentForm();
}
@PermissionCheck
@SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SHOW_UPDATE_DEPARTMENT, method = RequestMethod.POST)
public String showUpdateDepartment(@RequestParam("idDepartment") Integer idDepartment, Model model) {
LOGGER.info("showUpdateDepartment 실행");
final String NO_TARGET = "更新対象のデータが見つかりません。";
try {
List<Department> departmentList = searchDepartment.searchByDepartmentId(
new SearchConditionDepartment(idDepartment,
null));
if (departmentList.isEmpty()) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NO_TARGET));
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT;
}
model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM,
UpdateDepartmentForm.convertFrom(departmentList.get(0)));
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
} catch (Exception e) {
httpSession.invalidate();
e.printStackTrace();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
}

View File

@@ -1,116 +0,0 @@
package com.example.rhizome.app.presentation.controller;
import java.util.List;
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.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.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.UpdateDepartment;
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.LoginUserForm;
import com.example.rhizome.app.presentation.form.MessageForm;
import com.example.rhizome.app.presentation.form.UpdateDepartmentForm;
import com.example.rhizome.app.presentation.form.UpdateEmployeeInfoForm;
@Controller
public class UpdateDepartmentResultController {
private final static Logger LOGGER = Logger.getLogger(UpdateEmployeeController.class.getName());
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession;
SearchDepartment searchDepartment;
UpdateDepartment updateDepartment;
@Autowired
public UpdateDepartmentResultController(HttpSession httpSession, SearchDepartment searchDepartment,
UpdateDepartment updateDepartment) {
this.httpSession = httpSession;
this.searchDepartment = searchDepartment;
this.updateDepartment = updateDepartment;
}
private static boolean checkDuplicateDepartmentName(List<Department> departmentList,
UpdateDepartmentForm updateDepartmentForm) {
if (!departmentList.isEmpty()) {
return Objects.equals(departmentList.get(0).getNmDepartment(), updateDepartmentForm.getNmDepartment());
}
return true;
}
@PermissionCheck
@SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_RESULT, method = RequestMethod.POST)
public String departmentUpdateResult(@ModelAttribute UpdateDepartmentForm updateDepartmentForm, Model model) {
final String DUPLICATION = "既に同名の部署が存在するか、値が変更されていません。";
final String NOTHING = "項目が空欄です。";
final String UPDATE_COMPLETE = "更新が完了しました。";
try {
List<Department> departmentList = searchDepartment
.searchByDepartmentId(new SearchConditionDepartment(updateDepartmentForm.getIdDepartment(), null));
if (checkDuplicateDepartmentName(departmentList, updateDepartmentForm)) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, updateDepartmentForm);
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
}
if (!UpdateDepartmentForm.hasErrorParameter(updateDepartmentForm)) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NOTHING));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, updateDepartmentForm);
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
}
List<Department> beforeDepartment = searchDepartment
.searchByDepartmentId(new SearchConditionDepartment(updateDepartmentForm.getIdDepartment(), null));
updateDepartment.updateDepartment(beforeDepartment.get(0),
UpdateDepartmentForm.convertTo(updateDepartmentForm));
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(UPDATE_COMPLETE));
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;
}
}
private boolean isUpdateTargetLoginUserAdminToNormal(UpdateEmployeeInfoForm updateEmployeeInfoForm,
LoginUserForm loginUserForm) {
if (!Objects.equals(updateEmployeeInfoForm.getIdEmployee(), loginUserForm.getIdEmployee())) {
return false;
}
return updateEmployeeInfoForm.getAdminAuth().equals(0);
}
}

View File

@@ -1,19 +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.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 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.EmployeeInfo; import com.example.rhizome.app.domain.model.EmployeeInfo;
@@ -26,66 +12,96 @@ 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.SearchConditionEmployeeForm; import com.example.rhizome.app.presentation.form.SearchConditionEmployeeForm;
import com.example.rhizome.app.presentation.form.UpdateEmployeeInfoForm; import com.example.rhizome.app.presentation.form.UpdateEmployeeInfoForm;
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 org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* 更新対象の employee が存在するか確認する為のコントローラ
*/
@Controller @Controller
public class UpdateEmployeeController { public class UpdateEmployeeController {
private final static Logger LOGGER = Logger.getLogger(UpdateEmployeeController.class.getName()); // ログ出力用インスタンス
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; private final static Logger LOGGER = Logger.getLogger(UpdateEmployeeController.class.getName());
// エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession; HttpSession httpSession;
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
SearchEmployeeInfo searchEmployeeInfo; SearchEmployeeInfo searchEmployeeInfo;
@Autowired @Autowired
public UpdateEmployeeController(HttpSession httpSession, SearchDepartment searchDepartment, public UpdateEmployeeController(HttpSession httpSession, SearchDepartment searchDepartment, SearchEmployeeInfo searchEmployeeInfo) {
SearchEmployeeInfo searchEmployeeInfo) { this.httpSession = httpSession;
this.httpSession = httpSession; this.searchDepartment = searchDepartment;
this.searchDepartment = searchDepartment; this.searchEmployeeInfo = searchEmployeeInfo;
this.searchEmployeeInfo = searchEmployeeInfo; }
}
@ModelAttribute @ModelAttribute
public SearchConditionEmployeeForm searchConditionEmployeeForm() { public SearchConditionEmployeeForm searchConditionEmployeeForm() {
return new SearchConditionEmployeeForm(); return new SearchConditionEmployeeForm();
} }
@PermissionCheck /**
@SessionCheck * 更新対象の employee が存在するか確認する為のコントローラ
@RequestMapping(value = TransitionTargetPageNameKeyword.SHOW_UPDATE_EMPLOYEE, method = RequestMethod.POST) *
public String showUpdateEmployee(@RequestParam("idEmployee") Integer idEmployee, Model model) { * @param idEmployee 更新対象の employee の id
final String UPDATE_TARGET_ID_NOT_FOUND = "更新対象のデータが見つかりません。"; * @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SHOW_UPDATE_EMPLOYEE, method = RequestMethod.POST)
public String showUpdateEmployee(@RequestParam("idEmployee") Integer idEmployee, Model model) {
final String UPDATE_TARGET_ID_NOT_FOUND = "更新対象のデータが見つかりません。";
try { try {
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, // 部署一覧を取得し画面に返す値としてセット
DepartmentForm.convertFrom(searchDepartment.selectAll())); model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(searchDepartment.selectAll()));
List<EmployeeInfo> employeeInfoList = searchEmployeeInfo.searchBy( // id を条件に更新対象のレコードを検索、取得する
new SearchConditionEmployee(idEmployee, List<EmployeeInfo> employeeInfoList = searchEmployeeInfo.searchBy(
null, new SearchConditionEmployee(idEmployee,
null, null,
null, null,
null)); null,
null));
if (employeeInfoList.isEmpty()) { // DBに更新対象のデータがあるか
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, if (employeeInfoList.isEmpty()) {
new MessageForm(UPDATE_TARGET_ID_NOT_FOUND)); // ない場合はエラーメッセージをセットして検索画面に戻る
return "forward:" + TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_INFO; model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(UPDATE_TARGET_ID_NOT_FOUND));
} return "forward:" + TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_INFO;
}
model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM, // 更新画面に遷移
UpdateEmployeeInfoForm.convertFrom(employeeInfoList.get(0))); model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM, UpdateEmployeeInfoForm.convertFrom(employeeInfoList.get(0)));
return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML; // Update画面に遷移
return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML;
} catch (Exception e) {
httpSession.invalidate();
e.printStackTrace(); } catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); e.printStackTrace();
return TransitionTargetPageNameKeyword.ERROR_HTML;
} // エラーログ出力
} LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
} }

View File

@@ -1,18 +1,5 @@
package com.example.rhizome.app.presentation.controller; package com.example.rhizome.app.presentation.controller;
import java.util.List;
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.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.example.rhizome.aop.aspect.PermissionCheck; import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
@@ -28,126 +15,192 @@ 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 com.example.rhizome.app.presentation.form.UpdateEmployeeInfoForm; import com.example.rhizome.app.presentation.form.UpdateEmployeeInfoForm;
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 javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* employee を更新して結果を返す為のコントローラ
*/
@Controller @Controller
public class UpdateEmployeeResultController { public class UpdateEmployeeResultController {
private final static Logger LOGGER = Logger.getLogger(UpdateEmployeeController.class.getName()); // ログ出力用インスタンス
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; private final static Logger LOGGER = Logger.getLogger(UpdateEmployeeController.class.getName());
// エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession; HttpSession httpSession;
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
SearchEmployee searchEmployee; SearchEmployee searchEmployee;
UpdateEmployee updateEmployee; UpdateEmployee updateEmployee;
@Autowired @Autowired
public UpdateEmployeeResultController(HttpSession httpSession, SearchDepartment searchDepartment, public UpdateEmployeeResultController(HttpSession httpSession, SearchDepartment searchDepartment, SearchEmployee searchEmployee, UpdateEmployee updateEmployee) {
SearchEmployee searchEmployee, UpdateEmployee updateEmployee) { this.httpSession = httpSession;
this.httpSession = httpSession; this.searchDepartment = searchDepartment;
this.searchDepartment = searchDepartment; this.searchEmployee = searchEmployee;
this.searchEmployee = searchEmployee; this.updateEmployee = updateEmployee;
this.updateEmployee = updateEmployee; }
}
private static boolean checkDuplicateMailAddress(List<Employee> employeeList, /**
UpdateEmployeeInfoForm updateEmployeeInfoForm) { * メールアドレスの重複チェック
if (!employeeList.isEmpty()) { *
return Objects.equals(employeeList.get(0).getIdEmployee(), updateEmployeeInfoForm.getIdEmployee()); * @param employeeList 元の employeeList
} * @param updateEmployeeInfoForm 更新対象のデータ
return true; * @return true:重複無し false:重複あり
} */
private static boolean checkDuplicateMailAddress(List<Employee> employeeList, UpdateEmployeeInfoForm updateEmployeeInfoForm) {
// メールアドレスが既に使われていた場合
if (!employeeList.isEmpty()) {
// 重複が有った場合に、同一人物のものであれば上書きOKとする
return Objects.equals(employeeList.get(0).getIdEmployee(), updateEmployeeInfoForm.getIdEmployee());
}
return true;
}
@PermissionCheck /**
@SessionCheck * 更新結果画面表示処理
@RequestMapping(value = TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_RESULT, method = RequestMethod.POST) *
public String employeeUpdateResult(@ModelAttribute UpdateEmployeeInfoForm updateEmployeeInfoForm, Model model) { * @param updateEmployeeInfoForm 更新画面のフォーム
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_RESULT, method = RequestMethod.POST)
public String employeeUpdateResult(@ModelAttribute UpdateEmployeeInfoForm updateEmployeeInfoForm, Model model) {
final String DUPLICATION = "既に登録済みのメールアドレスです。"; final String DUPLICATION = "既に登録済みのメールアドレスです。";
final String NOTHING = "項目が空欄です。"; final String NOTHING = "項目が空欄です。";
final String ADMIN_USER = "更新対象者がログイン者のため、管理者権限を変更できません。"; final String ADMIN_USER = "更新対象者がログイン者のため、管理者権限を変更できません。";
final String NO_TARGET = "更新対象のデータが見つかりません。"; final String NO_TARGET = "更新対象のデータが見つかりません。";
final String UPDATE_COMPLETE = "更新が完了しました。"; final String UPDATE_COMPLETE = "更新が完了しました。";
try {
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, try {
DepartmentForm.convertFrom(searchDepartment.selectAll()));
String error = UpdateEmployeeInfoForm.validatePassword( // 部署一覧取得
updateEmployeeInfoForm.getPassword(), model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(searchDepartment.selectAll()));
updateEmployeeInfoForm.getPasswordConfirm());
if (!error.isBlank()) { // パスワードが仕様を満たしているか確認
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(error)); String error = UpdateEmployeeInfoForm.validatePassword(
model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM, updateEmployeeInfoForm); updateEmployeeInfoForm.getPassword(),
updateEmployeeInfoForm.getPasswordConfirm()
);
return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML; // エラーが存在するか
} if (!error.isBlank()) {
// エラーが存在する場合、更新画面に遷移
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(error));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM, updateEmployeeInfoForm);
List<Employee> employeeList = searchEmployee.searchEmployee(updateEmployeeInfoForm.getMailAddress()); return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML;
}
if (!checkDuplicateMailAddress(employeeList, updateEmployeeInfoForm)) { // メールアドレスを元に検索
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION)); List<Employee> employeeList = searchEmployee.searchEmployee(updateEmployeeInfoForm.getMailAddress());
model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM, updateEmployeeInfoForm);
return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML; // 既に登録済みのメールアドレスが存在するか
} if (!checkDuplicateMailAddress(employeeList, updateEmployeeInfoForm)) {
// 存在する場合はエラーメッセージを設定して更新入力画面に遷移
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM, updateEmployeeInfoForm);
LoginUserForm loginUserForm = (LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER); return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML;
}
if (isUpdateTargetLoginUserAdminToNormal(updateEmployeeInfoForm, loginUserForm)) { // session 情報からログイン者の情報を取得
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(ADMIN_USER)); LoginUserForm loginUserForm = (LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER);
model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM, updateEmployeeInfoForm);
return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML;
}
if (!UpdateEmployeeInfoForm.hasErrorParameter(updateEmployeeInfoForm)) { // ログイン者が更新対象で、権限を管理者権限から一般権限に変更しようとしているかチェック
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NOTHING)); if (isUpdateTargetLoginUserAdminToNormal(updateEmployeeInfoForm, loginUserForm)) {
model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM, updateEmployeeInfoForm); // 存在する場合はエラーメッセージを設定して更新入力画面に遷移
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(ADMIN_USER));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM, updateEmployeeInfoForm);
return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML;
}
return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML; // 画面から渡ってきた値が必須を満たしているか
} if (!UpdateEmployeeInfoForm.hasErrorParameter(updateEmployeeInfoForm)) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NOTHING));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM, updateEmployeeInfoForm);
Employee beforeEmployee = searchEmployee.searchEmployeeByIdEmployee(updateEmployeeInfoForm.getIdEmployee()); return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML;
if (beforeEmployee.getIdEmployee() == null) { }
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NO_TARGET));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM, updateEmployeeInfoForm);
return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML; // 更新前のデータを取得
} Employee beforeEmployee = searchEmployee.searchEmployeeByIdEmployee(updateEmployeeInfoForm.getIdEmployee());
if (beforeEmployee.getIdEmployee() == null) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NO_TARGET));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM, updateEmployeeInfoForm);
updateEmployee.updateEmployee(beforeEmployee, UpdateEmployeeInfoForm.convertTo(updateEmployeeInfoForm)); return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML;
}
LoginUser updatedTargetEmployee = searchEmployee.searchLoginUser(updateEmployeeInfoForm.getMailAddress()); // 画面用の型からビジネスロジック用のモデルに変換し、Updateを実行
updateEmployee.updateEmployee(beforeEmployee, UpdateEmployeeInfoForm.convertTo(updateEmployeeInfoForm));
if (Objects.equals(updatedTargetEmployee.getIdEmployee(), loginUserForm.getIdEmployee())) { // Update後の情報を再取得
httpSession.setAttribute(SessionKeyword.LOGIN_USER, LoginUserForm.convertFrom(updatedTargetEmployee)); LoginUser updatedTargetEmployee = searchEmployee.searchLoginUser(updateEmployeeInfoForm.getMailAddress());
}
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(UPDATE_COMPLETE)); // ログイン者と更新した対象が同じアカウントだった場合、session情報を更新
if (Objects.equals(updatedTargetEmployee.getIdEmployee(), loginUserForm.getIdEmployee())) {
// ログイン者の情報をセッション情報に格納
httpSession.setAttribute(SessionKeyword.LOGIN_USER, LoginUserForm.convertFrom(updatedTargetEmployee));
}
return "forward:" + TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_INFO_FORM_EMPTY; // 更新結果のメッセージを画面にセットし一覧画面に遷移
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(UPDATE_COMPLETE));
} catch (Exception e) { // forward 先で不用意な動作をしないために UpdateEmployeeInfoForm をクリア
httpSession.invalidate(); return "forward:" + TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_INFO_FORM_EMPTY;
e.printStackTrace();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
} } catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
private boolean isUpdateTargetLoginUserAdminToNormal(UpdateEmployeeInfoForm updateEmployeeInfoForm, e.printStackTrace();
LoginUserForm loginUserForm) { // エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
if (!Objects.equals(updateEmployeeInfoForm.getIdEmployee(), loginUserForm.getIdEmployee())) { }
return false;
}
return updateEmployeeInfoForm.getAdminAuth().equals(0); /**
* ログイン者がログイン者自身を更新する際
* 管理者権限から一般権限に変更する内容も含まれているかチェックする
*
* @param updateEmployeeInfoForm 更新対象データ
* @param loginUserForm ログイン者情報
* @return true:ログイン者自身のデータをUpdate管理者→一般に権限変更しようとしている。
* false:Update対象者がログイン者自身ではない or 管理者権限 → 一般権限 への更新は含まれていない
*/
private boolean isUpdateTargetLoginUserAdminToNormal(UpdateEmployeeInfoForm updateEmployeeInfoForm, LoginUserForm loginUserForm) {
// ログイン者が今回の更新対象か
if (!Objects.equals(updateEmployeeInfoForm.getIdEmployee(), loginUserForm.getIdEmployee())) {
// 今回の対象者はログイン者ではない
return false;
}
// 管理者から一般権限への変更があるか
return updateEmployeeInfoForm.getAdminAuth().equals(0);
}
}
} }

View File

@@ -1,18 +1,5 @@
package com.example.rhizome.app.presentation.controller; package com.example.rhizome.app.presentation.controller;
import java.util.List;
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.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.example.rhizome.aop.aspect.PermissionCheck; import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
@@ -25,103 +12,152 @@ import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTa
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 com.example.rhizome.app.presentation.form.UpdatePersonalUserForm; import com.example.rhizome.app.presentation.form.UpdatePersonalUserForm;
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 javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* 個人情報更新用コントローラ
*/
@Controller @Controller
public class UpdatePersonalEmployeeResultController { public class UpdatePersonalEmployeeResultController {
private final static Logger LOGGER = Logger.getLogger(UpdatePersonalEmployeeResultController.class.getName()); // ログ出力用インスタンス
private final static Logger LOGGER = Logger.getLogger(UpdatePersonalEmployeeResultController.class.getName());
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; // エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession; HttpSession httpSession;
SearchEmployee searchEmployee; SearchEmployee searchEmployee;
UpdateEmployee updateEmployee; UpdateEmployee updateEmployee;
@Autowired @Autowired
public UpdatePersonalEmployeeResultController(HttpSession httpSession, SearchEmployee searchEmployee, public UpdatePersonalEmployeeResultController(HttpSession httpSession, SearchEmployee searchEmployee, UpdateEmployee updateEmployee) {
UpdateEmployee updateEmployee) { this.httpSession = httpSession;
this.httpSession = httpSession; this.searchEmployee = searchEmployee;
this.searchEmployee = searchEmployee; this.updateEmployee = updateEmployee;
this.updateEmployee = updateEmployee; }
}
private static boolean checkDuplicateMailAddress(List<Employee> employeeList, /**
UpdatePersonalUserForm updatePersonalUserForm) { * メールアドレスの重複チェック
if (!employeeList.isEmpty()) { *
return Objects.equals(employeeList.get(0).getIdEmployee(), updatePersonalUserForm.getIdEmployee()); * @param employeeList 元の employeeList
} * @param updatePersonalUserForm 更新対象のデータ
return true; * @return true:重複無し false:重複あり
} */
private static boolean checkDuplicateMailAddress(List<Employee> employeeList, UpdatePersonalUserForm updatePersonalUserForm) {
// メールアドレスが既に使われていた場合
if (!employeeList.isEmpty()) {
// 更新対象のデータと同じIDの場合は重複していないとみなす
return Objects.equals(employeeList.get(0).getIdEmployee(), updatePersonalUserForm.getIdEmployee());
}
return true;
}
@ModelAttribute @ModelAttribute
public UpdatePersonalUserForm personalUpdateUserForm() { public UpdatePersonalUserForm personalUpdateUserForm() {
return new UpdatePersonalUserForm(); return new UpdatePersonalUserForm();
} }
@PermissionCheck /**
@SessionCheck * 個人情報更新結果画面表示処理
@RequestMapping(value = TransitionTargetPageNameKeyword.PERSONAL_UPDATE_RESULT, method = RequestMethod.POST) *
public String personalEmployeeUpdateResult(UpdatePersonalUserForm updatePersonalUserForm, Model model) { * @param updatePersonalUserForm 個人情報更新画面のフォーム
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@PermissionCheck
@SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.PERSONAL_UPDATE_RESULT, method = RequestMethod.POST)
public String personalEmployeeUpdateResult(UpdatePersonalUserForm updatePersonalUserForm, Model model) {
final String NOTHING = "項目が空欄です。"; final String NOTHING = "項目が空欄です。";
final String DUPLICATION = "既に登録済みのメールアドレスです。"; final String DUPLICATION = "既に登録済みのメールアドレスです。";
try { try {
if (updatePersonalUserForm.getIdEmployee() == null) { // 更新完了画面からの遷移の場合
LoginUserForm loginUserForm = (LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER); if (updatePersonalUserForm.getIdEmployee() == null) {
model.addAttribute(PageReturnAttributeKeyword.UPDATE_PERSONAL_EMPLOYEE_USER_FORM, UpdatePersonalUserForm // ログイン者の情報を取得
.convertFrom(searchEmployee.searchLoginUser(loginUserForm.getMailAddress()))); LoginUserForm loginUserForm = (LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER);
// ログイン者の情報を元に個人情報更新画面の初期表示用のインスタンスを作成
model.addAttribute(PageReturnAttributeKeyword.UPDATE_PERSONAL_EMPLOYEE_USER_FORM, UpdatePersonalUserForm.convertFrom(searchEmployee.searchLoginUser(loginUserForm.getMailAddress())));
return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML; return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML;
} }
String error = UpdatePersonalUserForm.validatePassword( // パスワードが仕様を満たしているかチェック
updatePersonalUserForm.getPassword(), String error = UpdatePersonalUserForm.validatePassword(
updatePersonalUserForm.getPasswordConfirm()); updatePersonalUserForm.getPassword(),
updatePersonalUserForm.getPasswordConfirm()
);
if (!error.isBlank()) { // エラーがあるか
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(error)); if (!error.isBlank()) {
model.addAttribute(PageReturnAttributeKeyword.UPDATE_PERSONAL_EMPLOYEE_USER_FORM, // エラーが有る場合メッセージをセットして個人情報更新入力画面に遷移
updatePersonalUserForm); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(error));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_PERSONAL_EMPLOYEE_USER_FORM, updatePersonalUserForm);
return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML; return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML;
} }
if (!UpdatePersonalUserForm.hasErrorParameter(updatePersonalUserForm)) { // 入力必須を満たしているか
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NOTHING)); if (!UpdatePersonalUserForm.hasErrorParameter(updatePersonalUserForm)) {
model.addAttribute(PageReturnAttributeKeyword.UPDATE_PERSONAL_EMPLOYEE_USER_FORM, // 満たしていない場合、メッセージをセットして個人情報更新入力画面に遷移
updatePersonalUserForm); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NOTHING));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_PERSONAL_EMPLOYEE_USER_FORM, updatePersonalUserForm);
return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML; return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML;
} }
if (!checkDuplicateMailAddress( // メールアドレス重複チェック
searchEmployee.searchEmployee(updatePersonalUserForm.getMailAddress()), if (!checkDuplicateMailAddress(
updatePersonalUserForm)) { searchEmployee.searchEmployee(updatePersonalUserForm.getMailAddress()),
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION)); updatePersonalUserForm)
model.addAttribute(PageReturnAttributeKeyword.UPDATE_PERSONAL_EMPLOYEE_USER_FORM, ) {
updatePersonalUserForm); // メールアドレスが既に使われていた場合
// 個人情報更新ページに遷移
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_PERSONAL_EMPLOYEE_USER_FORM, updatePersonalUserForm);
return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML; return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML;
} }
updateEmployee.updateEmployee( //更新前のEmployeeの情報を取得
searchEmployee.searchEmployeeByIdEmployee(updatePersonalUserForm.getIdEmployee()), // 画面用のインスタンスから更新用のインスタンスに変換し、Update実施
UpdatePersonalUserForm.convertTo(updatePersonalUserForm)); updateEmployee.updateEmployee(
searchEmployee.searchEmployeeByIdEmployee(updatePersonalUserForm.getIdEmployee()),
UpdatePersonalUserForm.convertTo(updatePersonalUserForm)
);
httpSession.setAttribute( // ログイン者の情報をセッション情報に格納
SessionKeyword.LOGIN_USER, httpSession.setAttribute(
LoginUserForm.convertFrom( SessionKeyword.LOGIN_USER,
searchEmployee.searchLoginUser(updatePersonalUserForm.getMailAddress()))); LoginUserForm.convertFrom(
searchEmployee.searchLoginUser(updatePersonalUserForm.getMailAddress()))
);
return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_RESULT_HTML; // 更新結果画面に遷移
return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_RESULT_HTML;
} catch (Exception e) { } catch (Exception e) {
httpSession.invalidate(); // ログイン情報の破棄
httpSession.invalidate();
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); // エラーログ出力
return TransitionTargetPageNameKeyword.ERROR_HTML; LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
} // エラー画面遷移
} return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
} }

View File

@@ -1,17 +1,23 @@
package com.example.rhizome.app.presentation.controller.pageproperty; package com.example.rhizome.app.presentation.controller.pageproperty;
/**
* Servlet から Servlet に返却する際に使用する文字列を管理するクラス
* モデルに渡すキー名を定数化
*/
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 UPDATE_EMPLOYEE_INFO_FORM = "updateEmployeeInfoForm"; public static final String DEPARTMENT_FORM_LIST = "departmentFormList";
public static final String INSERT_EMPLOYEE_FORM = "insertEmployeeForm"; public static final String DEPARTMENT_INFO_FORM_LIST = "departmentInfoFormList";
public static final String LOGIN_INFO_FORM = "loginInfoForm"; public static final String UPDATE_EMPLOYEE_INFO_FORM = "updateEmployeeInfoForm";
public static final String UPDATE_PERSONAL_EMPLOYEE_USER_FORM = "updatePersonalEmployeeUserForm"; public static final String INSERT_EMPLOYEE_FORM = "insertEmployeeForm";
public static final String EMPLOYEE_INFO_FORM_LIST = "employeeInfoFormList"; public static final String LOGIN_INFO_FORM = "loginInfoForm";
public static final String UPDATE_PERSONAL_EMPLOYEE_USER_FORM = "updatePersonalEmployeeUserForm";
public static final String EMPLOYEE_INFO_FORM_LIST = "employeeInfoFormList";
public static final String INSERT_DEPARTMENT_INPUT = "insertDepartmentInput";
public static final String INSERT_DEPARTMENT_FORM = "insertDepartmentForm";
public static final String INSERT_DEPARTMENT_INPUT_HTML = "insertDepartmentInputHtml";
public static final String DEPARTMENT_FORM_LIST = "departmentFormList";
public static final String INSERT_DEPARTMENT_FORM = "insertDepartmentForm";
public static final String UPDATE_DEPARTMENT_FORM = "updateDepartmentForm";
} }

View File

@@ -1,5 +1,9 @@
package com.example.rhizome.app.presentation.controller.pageproperty; package com.example.rhizome.app.presentation.controller.pageproperty;
/**
* Sessionキーを管理する
*/
public class SessionKeyword { public class SessionKeyword {
public static final String LOGIN_USER = "loginUser"; // SESSION情報として格納したいログイン者の情報
public static final String LOGIN_USER = "loginUser";
} }

View File

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

View File

@@ -1,25 +1,47 @@
package com.example.rhizome.app.presentation.form; package com.example.rhizome.app.presentation.form;
import java.util.List;
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 java.util.List;
/**
* 画面の表示に使う部署コード管理用のクラス
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class DepartmentForm { public class DepartmentForm {
private Integer idDepartment; /**
private String nmDepartment; * 部署ID
*/
private Integer idDepartment;
/**
* 部署名
*/
private String nmDepartment;
public static DepartmentForm convertFrom(Department department) { /**
return new DepartmentForm(department.getIdDepartment(), department.getNmDepartment()); * business 層の Department クラスから画面用(presentation 層)の DepartmentForm に
} * 変換します。
*
* @param department business 層の Department インスタンス
* @return 画面用(presentation 層)の DepartmentForm インスタンス
*/
public static DepartmentForm convertFrom(Department department) {
return new DepartmentForm(department.getIdDepartment(), department.getNmDepartment());
}
public static List<DepartmentForm> convertFrom(List<Department> departmentList) { /**
return departmentList.stream().map(DepartmentForm::convertFrom).toList(); * business 層の Department クラスから画面用(presentation 層)の DepartmentForm に
} * 変換します。(リスト版)
*
* @param departmentList business 層の Department インスタンスのリスト
* @return 画面用(presentation 層)の DepartmentForm インスタンスのリスト
*/
public static List<DepartmentForm> convertFrom(List<Department> departmentList) {
return departmentList.stream().map(DepartmentForm::convertFrom).toList();
}
} }

View File

@@ -1,40 +1,82 @@
package com.example.rhizome.app.presentation.form; package com.example.rhizome.app.presentation.form;
import java.util.List;
import com.example.rhizome.app.domain.model.EmployeeInfo; import com.example.rhizome.app.domain.model.EmployeeInfo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.List;
/**
* 画面に表示するために employee と department を Join した構造を扱うクラス
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class EmployeeInfoForm { public class EmployeeInfoForm {
private Integer idEmployee; /**
private String nmEmployee; * 社員ID
private String knEmployee; */
private String mailAddress; private Integer idEmployee;
private String password; /**
private Integer adminAuth; * 社員名
private Integer idDepartment; */
private String nmDepartment; private String nmEmployee;
/**
* 社員名カナ
*/
private String knEmployee;
/**
* メールアドレス
*/
private String mailAddress;
/**
* パスワード
*/
private String password;
/**
* パスワード
*/
private Integer adminAuth;
/**
* 部署ID
*/
private Integer idDepartment;
/**
* 部署名
*/
private String nmDepartment;
public static EmployeeInfoForm convertFrom(EmployeeInfo employeeInfo) { /**
return new EmployeeInfoForm( * business 層の EmployeeInfo クラスから画面用(presentation 層)の EmployeeInfoForm に
employeeInfo.getEmployee().getIdEmployee(), * 変換します。
employeeInfo.getEmployee().getNmEmployee(), *
employeeInfo.getEmployee().getKnEmployee(), * @param employeeInfo business 層の EmployeeInfo インスタンス
employeeInfo.getEmployee().getMailAddress(), * @return クラスから画面用(presentation 層)の EmployeeInfoForm インスタンス
employeeInfo.getEmployee().getPassword(), */
employeeInfo.getEmployee().getAdminAuth(), public static EmployeeInfoForm convertFrom(EmployeeInfo employeeInfo) {
employeeInfo.getDepartment().getIdDepartment(), return new EmployeeInfoForm(
employeeInfo.getDepartment().getNmDepartment()); employeeInfo.getEmployee().getIdEmployee(),
} employeeInfo.getEmployee().getNmEmployee(),
employeeInfo.getEmployee().getKnEmployee(),
employeeInfo.getEmployee().getMailAddress(),
employeeInfo.getEmployee().getPassword(),
employeeInfo.getEmployee().getAdminAuth(),
employeeInfo.getDepartment().getIdDepartment(),
employeeInfo.getDepartment().getNmDepartment()
);
}
public static List<EmployeeInfoForm> convertFrom(List<EmployeeInfo> employeeInfoList) { /**
return employeeInfoList.stream().map(EmployeeInfoForm::convertFrom).toList(); * business 層の EmployeeInfo クラスから画面用(presentation 層)の EmployeeInfoForm に
} * 変換します。(リスト版)
*
* @param employeeInfoList business 層の EmployeeInfo インスタンスのリスト
* @return クラスから画面用(presentation 層)の EmployeeInfoForm インスタンスのリスト
*/
public static List<EmployeeInfoForm> convertFrom(List<EmployeeInfo> employeeInfoList) {
return employeeInfoList.stream().map(EmployeeInfoForm::convertFrom).toList();
}
} }

View File

@@ -9,38 +9,102 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/**
* 画面から渡ってきた登録内容をまとめ、再度画面に表示する為のクラス
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class InsertDepartmentForm { public class InsertDepartmentForm {
private String nmDepartment; /**
* 部署ID
*/
private Integer idDepartment;
/**
* 部署名
*/
private String nmDepartment;
private static boolean isNullOrBlank(String str) {
if (null == str) {
return true;
}
return str.isBlank(); /**
} * パスワードのValidation
* チェック対象にエラーが有った場合エラーリストに文言を追加する
*
* @param password 登録対象のパスワード
* @param passwordConfirm 登録対象のパスワード再入力
* @param error エラーリスト
*/
private static void checkPassword(String password, String passwordConfirm, List<String> error) {
final String PASSWORD_NULL_BLANK = "パスワード が未入力です。";
final String PASSWORD_CONFIRM_NULL_BLANK = "パスワード確認用 が未入力です。";
final String PASSWORD_MISMATCH = "パスワード と パスワード確認用 が一致しません。";
public static Department convertTo(InsertDepartmentForm insertDepartmentForm) { if (isNullOrBlank(password)) {
return new Department( error.add(PASSWORD_NULL_BLANK);
null, return;
insertDepartmentForm.getNmDepartment()); }
} if (isNullOrBlank(passwordConfirm)) {
error.add(PASSWORD_CONFIRM_NULL_BLANK);
return;
}
public List<String> validateParameter() { if (!password.equals(passwordConfirm)) {
final String DEPARTMENT_NAME_NULL_BLANK = "部署名"; error.add(PASSWORD_MISMATCH);
}
}
List<String> error = new ArrayList<>(); /**
* 仮引数を null or 空 判定する
*
* @param str 判定対象の文字列
* @return true:null or 空 false:null or 空 では無い
*/
private static boolean isNullOrBlank(String str) {
if (null == str) {
return true;
}
if (isNullOrBlank(nmDepartment)) { return str.isBlank();
error.add(DEPARTMENT_NAME_NULL_BLANK); }
}
return error; /**
* 画面から渡ってきた登録内容をまとめ、ビジネスモデルに変換
*
* @param insertEmployeeForm 画面から渡ってきた登録内容
* @return ビジネスモデルのインスタンス
*/
public static Department convertTo(InsertDepartmentForm insertDepartmentForm) {
return new Department(
insertDepartmentForm.getIdDepartment(),
insertDepartmentForm.getNmDepartment()
);
}
} /**
* 登録データのValidationを行う
*
* @return エラーが有った場合はエラー文言、無ければ空のリストが返る
*/
public List<String> validateParameter() {
final String DEPARTMENT_NAME_NULL_BLANK = "部署名"; //入力エラーになったときに返す項目
final String DEPARTMENT_ID_NULL_BLANK = "所属部署";
List<String> error = new ArrayList<>();
if (isNullOrBlank(nmDepartment)) {
error.add(DEPARTMENT_NAME_NULL_BLANK);
}
if (idDepartment == null) {
error.add(DEPARTMENT_ID_NULL_BLANK);
}
return error;
}
} }

View File

@@ -1,102 +1,152 @@
package com.example.rhizome.app.presentation.form; package com.example.rhizome.app.presentation.form;
import java.util.ArrayList;
import java.util.List;
import com.example.rhizome.app.domain.model.Employee; import com.example.rhizome.app.domain.model.Employee;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
/**
* 画面から渡ってきた登録内容をまとめ、再度画面に表示する為のクラス
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class InsertEmployeeForm { public class InsertEmployeeForm {
private String nmEmployee; /**
* 社員名
*/
private String nmEmployee;
private String knEmployee; /**
* 社員名カナ
*/
private String knEmployee;
private String mailAddress; /**
* メールアドレス
*/
private String mailAddress;
private String password; /**
* パスワード
*/
private String password;
private String passwordConfirm; /**
* 確認用パスワード
*/
private String passwordConfirm;
private Integer adminAuth; /**
* 管理者権限
*/
private Integer adminAuth;
private Integer idDepartment; /**
* 部署ID
*/
private Integer idDepartment;
private static void checkPassword(String password, String passwordConfirm, List<String> error) { /**
final String PASSWORD_NULL_BLANK = "パスワード が未入力です。"; * パスワードのValidation
final String PASSWORD_CONFIRM_NULL_BLANK = "パスワード確認用 が未入力です。"; * チェック対象にエラーが有った場合エラーリストに文言を追加する
final String PASSWORD_MISMATCH = "パスワード と パスワード確認用 が一致しません。"; *
* @param password 登録対象のパスワード
* @param passwordConfirm 登録対象のパスワード再入力
* @param error エラーリスト
*/
private static void checkPassword(String password, String passwordConfirm, List<String> error) {
final String PASSWORD_NULL_BLANK = "パスワード が未入力です。";
final String PASSWORD_CONFIRM_NULL_BLANK = "パスワード確認用 が未入力です。";
final String PASSWORD_MISMATCH = "パスワード と パスワード確認用 が一致しません。";
if (isNullOrBlank(password)) { if (isNullOrBlank(password)) {
error.add(PASSWORD_NULL_BLANK); error.add(PASSWORD_NULL_BLANK);
return; return;
} }
if (isNullOrBlank(passwordConfirm)) { if (isNullOrBlank(passwordConfirm)) {
error.add(PASSWORD_CONFIRM_NULL_BLANK); error.add(PASSWORD_CONFIRM_NULL_BLANK);
return; return;
} }
if (!password.equals(passwordConfirm)) { if (!password.equals(passwordConfirm)) {
error.add(PASSWORD_MISMATCH); error.add(PASSWORD_MISMATCH);
} }
} }
private static boolean isNullOrBlank(String str) { /**
if (null == str) { * 仮引数を null or 空 判定する
return true; *
} * @param str 判定対象の文字列
* @return true:null or 空 false:null or 空 では無い
*/
private static boolean isNullOrBlank(String str) {
if (null == str) {
return true;
}
return str.isBlank(); return str.isBlank();
} }
public static Employee convertTo(InsertEmployeeForm insertEmployeeForm) { /**
return new Employee( * 画面から渡ってきた登録内容をまとめ、ビジネスモデルに変換
null, *
insertEmployeeForm.getNmEmployee(), * @param insertEmployeeForm 画面から渡ってきた登録内容
insertEmployeeForm.getKnEmployee(), * @return ビジネスモデルのインスタンス
insertEmployeeForm.getMailAddress(), */
insertEmployeeForm.getPassword(), public static Employee convertTo(InsertEmployeeForm insertEmployeeForm) {
insertEmployeeForm.getAdminAuth(), return new Employee(
insertEmployeeForm.getIdDepartment()); null,
} insertEmployeeForm.getNmEmployee(),
insertEmployeeForm.getKnEmployee(),
insertEmployeeForm.getMailAddress(),
insertEmployeeForm.getPassword(),
insertEmployeeForm.getAdminAuth(),
insertEmployeeForm.getIdDepartment()
);
}
public List<String> validateParameter() { /**
final String EMPLOYEE_NAME_NULL_BLANK = "社員名"; * 登録データのValidationを行う
final String EMPLOYEE_KANA_NULL_BLANK = "社員名フリガナ"; *
final String MAIL_ADDRESS_NULL_BLANK = "メールアドレス"; * @return エラーが有った場合はエラー文言、無ければ空のリストが返る
final String MANAGEMENT_ERROR = "管理者権限指定"; */
final String DEPARTMENT_ID_NULL_BLANK = "所属部署"; public List<String> validateParameter() {
final String EMPLOYEE_NAME_NULL_BLANK = "社員名";
final String EMPLOYEE_KANA_NULL_BLANK = "社員名フリガナ";
final String MAIL_ADDRESS_NULL_BLANK = "メールアドレス";
final String MANAGEMENT_ERROR = "管理者権限指定";
final String DEPARTMENT_ID_NULL_BLANK = "所属部署";
List<String> error = new ArrayList<>(); List<String> error = new ArrayList<>();
if (isNullOrBlank(nmEmployee)) { if (isNullOrBlank(nmEmployee)) {
error.add(EMPLOYEE_NAME_NULL_BLANK); error.add(EMPLOYEE_NAME_NULL_BLANK);
} }
if (isNullOrBlank(knEmployee)) { if (isNullOrBlank(knEmployee)) {
error.add(EMPLOYEE_KANA_NULL_BLANK); error.add(EMPLOYEE_KANA_NULL_BLANK);
} }
if (isNullOrBlank(mailAddress)) { if (isNullOrBlank(mailAddress)) {
error.add(MAIL_ADDRESS_NULL_BLANK); error.add(MAIL_ADDRESS_NULL_BLANK);
} }
checkPassword(password, passwordConfirm, error); // パスワードが仕様を満たしているか確認
checkPassword(password, passwordConfirm, error);
if (adminAuth == null) { if (adminAuth == null) {
error.add(MANAGEMENT_ERROR); error.add(MANAGEMENT_ERROR);
} }
if (idDepartment == null) { if (idDepartment == null) {
error.add(DEPARTMENT_ID_NULL_BLANK); error.add(DEPARTMENT_ID_NULL_BLANK);
} }
return error; return error;
} }
} }

View File

@@ -4,10 +4,20 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/**
* ログインを試みる人を表現するモデルクラスです
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class LoginInfoForm { public class LoginInfoForm {
private String mailAddress; /**
private String password; * メールアドレス
*/
private String mailAddress;
/**
* パスワード
*/
private String password;
} }

View File

@@ -1,7 +1,7 @@
package com.example.rhizome.app.presentation.form; package com.example.rhizome.app.presentation.form;
import com.example.rhizome.app.domain.model.LoginUser;
import com.example.rhizome.app.domain.model.LoginUser;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@@ -10,56 +10,104 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class LoginUserForm { public class LoginUserForm {
private Integer idEmployee; /**
private String nmEmployee; * 社員ID
private String knEmployee; */
private String mailAddress; private Integer idEmployee;
private String password; /**
* 社員名
*/
private String nmEmployee;
/**
* 社員名カナ
*/
private String knEmployee;
/**
* メールアドレス
*/
private String mailAddress;
/**
* パスワード
*/
private String password;
private Integer adminAuth; /**
* 管理者権限
*/
private Integer adminAuth;
private Integer idDepartment; /**
* 部署ID
*/
private Integer idDepartment;
public static LoginUserForm convertFrom(LoginUser loginUser) { /**
return new LoginUserForm( * business 層の LoginUser クラスから画面用(presentation 層)の LoginUserForm に
loginUser.getIdEmployee(), * 変換します。
loginUser.getNmEmployee(), *
loginUser.getKnEmployee(), * @param loginUser business 層の LoginUser インスタンス
loginUser.getMailAddress(), * @return クラスから画面用(presentation 層)の LoginUserForm
loginUser.getPassword(), */
loginUser.getAdminAuth(), public static LoginUserForm convertFrom(LoginUser loginUser) {
loginUser.getIdDepartment()); return new LoginUserForm(
} loginUser.getIdEmployee(),
loginUser.getNmEmployee(),
loginUser.getKnEmployee(),
loginUser.getMailAddress(),
loginUser.getPassword(),
loginUser.getAdminAuth(),
loginUser.getIdDepartment()
);
}
public static LoginUser convertTo(LoginUserForm loginUserForm) { /**
return new LoginUser( * 画面用(presentation 層)の LoginUserForm クラスから business 層の LoginUser クラスに
loginUserForm.getIdEmployee(), * 変換します。
loginUserForm.getNmEmployee(), *
loginUserForm.getKnEmployee(), * @param loginUserForm 画面用(presentation 層)の LoginUserForm インスタンス
loginUserForm.getMailAddress(), * @return business 層の LoginUser インスタンス
loginUserForm.getPassword(), */
loginUserForm.getAdminAuth(), public static LoginUser convertTo(LoginUserForm loginUserForm) {
loginUserForm.getIdDepartment()); return new LoginUser(
} loginUserForm.getIdEmployee(),
loginUserForm.getNmEmployee(),
loginUserForm.getKnEmployee(),
loginUserForm.getMailAddress(),
loginUserForm.getPassword(),
loginUserForm.getAdminAuth(),
loginUserForm.getIdDepartment()
);
}
public static boolean checkParameter(LoginInfoForm loginInfoForm) { /**
if (null == loginInfoForm.getMailAddress()) { * 画面から渡ってきた必須の値が仕様を満たしているか確認
return false; *
} * @param loginInfoForm 画面から渡ってきた mailAddress, password を格納しているインスタンス
* @return true:仕様を満たしている , false:仕様を満たしていない
*/
public static boolean checkParameter(LoginInfoForm loginInfoForm) {
if (null == loginInfoForm.getMailAddress()) {
return false;
}
if (loginInfoForm.getMailAddress().isBlank()) { if (loginInfoForm.getMailAddress().isBlank()) {
return false; return false;
} }
if (null == loginInfoForm.getPassword()) { if (null == loginInfoForm.getPassword()) {
return false; return false;
} }
return !loginInfoForm.getPassword().isBlank(); return !loginInfoForm.getPassword().isBlank();
} }
public boolean isAdminUser() { /**
return getAdminAuth() == 1; * 管理者権限を持っているか確認
} *
* @return true:管理者権限を持っている , false:管理者権限を持っていない
*/
public boolean isAdminUser() {
return getAdminAuth() == 1;
}
} }

View File

@@ -4,9 +4,12 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/**
* 画面に表示するエラーメッセージを管理するクラスです。
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class MessageForm { public class MessageForm {
private String message; private String message;
} }

View File

@@ -6,23 +6,48 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/**
* 画面から渡ってきた検索条件をまとめ、再度画面に表示する為のクラス
*/
@Data @Data
@NoArgsConstructor @AllArgsConstructor //全フィールドを初期化するコンストラクタ生成
@AllArgsConstructor @NoArgsConstructor //デフォルトコントラスタを自動生成
public class SearchConditionDepartmentForm { public class SearchConditionDepartmentForm {
private Integer idDepartment; /**
private String nmDepartment; * 部署ID
*/
private Integer idDepartment;
/**
* 部署名
*/
private String nmDepartment;
/**
* business (サービス)層の SearchConditionEmployee クラスから画面用(presentation 層)の SearchConditionEmployeeForm に
* 変換します。
*
* @param searchConditionEmployee business 層の SearchConditionEmployee インスタンス
* @return 画面用(presentation 層)の SearchConditionEmployeeForm インスタンス
*/
public static SearchConditionDepartmentForm convertFrom(SearchConditionDepartment searchConditionDepartment) {
return new SearchConditionDepartmentForm(
searchConditionDepartment.getIdDepartment(),
searchConditionDepartment.getNmDepartment()
);
}
public static SearchConditionDepartmentForm convertFrom(SearchConditionDepartment searchConditionDepartment) { /**
return new SearchConditionDepartmentForm( * 画面用(presentation 層)の SearchConditionEmployeeForm クラスから business 層の SearchConditionEmployee クラスに
searchConditionDepartment.getIdDepartment(), * 変換します。
searchConditionDepartment.getNmDepartment()); *
} * @param searchConditionEmployeeForm 画面用(presentation 層)の SearchConditionEmployeeForm インスタンス
* @return business 層の SearchConditionEmployee インスタンス
public static SearchConditionDepartment convertTo(SearchConditionDepartmentForm searchConditionDepartmentForm) { */
return new SearchConditionDepartment( public static SearchConditionDepartment convertTo(SearchConditionDepartmentForm searchConditionDepartmentForm) {
searchConditionDepartmentForm.getIdDepartment(), return new SearchConditionDepartment(
searchConditionDepartmentForm.getNmDepartment()); searchConditionDepartmentForm.getIdDepartment(),
} searchConditionDepartmentForm.getNmDepartment()
);
}
} }

View File

@@ -1,37 +1,70 @@
package com.example.rhizome.app.presentation.form; package com.example.rhizome.app.presentation.form;
import com.example.rhizome.app.domain.model.SearchConditionEmployee; import com.example.rhizome.app.domain.model.SearchConditionEmployee;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/**
* 画面から渡ってきた検索条件をまとめ、再度画面に表示する為のクラス
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class SearchConditionEmployeeForm { public class SearchConditionEmployeeForm {
private Integer idEmployee; /**
private String nmEmployee; * 社員ID
private String knEmployee; */
private String mailAddress; private Integer idEmployee;
private Integer idDepartment; /**
* 社員名
*/
private String nmEmployee;
/**
* 社員名カナ
*/
private String knEmployee;
/**
* メールアドレス
*/
private String mailAddress;
/**
* 部署ID
*/
private Integer idDepartment;
public static SearchConditionEmployeeForm convertFrom(SearchConditionEmployee searchConditionEmployee) { /**
return new SearchConditionEmployeeForm( * business 層の SearchConditionEmployee クラスから画面用(presentation 層)の SearchConditionEmployeeForm に
searchConditionEmployee.getIdEmployee(), * 変換します。
searchConditionEmployee.getNmEmployee(), *
searchConditionEmployee.getKnEmployee(), * @param searchConditionEmployee business 層の SearchConditionEmployee インスタンス
searchConditionEmployee.getMailAddress(), * @return 画面用(presentation 層)の SearchConditionEmployeeForm インスタンス
searchConditionEmployee.getIdDepartment()); */
} public static SearchConditionEmployeeForm convertFrom(SearchConditionEmployee searchConditionEmployee) {
return new SearchConditionEmployeeForm(
searchConditionEmployee.getIdEmployee(),
searchConditionEmployee.getNmEmployee(),
searchConditionEmployee.getKnEmployee(),
searchConditionEmployee.getMailAddress(),
searchConditionEmployee.getIdDepartment()
);
}
public static SearchConditionEmployee convertTo(SearchConditionEmployeeForm searchConditionEmployeeForm) { /**
return new SearchConditionEmployee( * 画面用(presentation 層)の SearchConditionEmployeeForm クラスから business 層の SearchConditionEmployee クラスに
searchConditionEmployeeForm.getIdEmployee(), * 変換します。
searchConditionEmployeeForm.getNmEmployee(), *
searchConditionEmployeeForm.getKnEmployee(), * @param searchConditionEmployeeForm 画面用(presentation 層)の SearchConditionEmployeeForm インスタンス
searchConditionEmployeeForm.getMailAddress(), * @return business 層の SearchConditionEmployee インスタンス
searchConditionEmployeeForm.getIdDepartment()); */
} public static SearchConditionEmployee convertTo(SearchConditionEmployeeForm searchConditionEmployeeForm) {
return new SearchConditionEmployee(
searchConditionEmployeeForm.getIdEmployee(),
searchConditionEmployeeForm.getNmEmployee(),
searchConditionEmployeeForm.getKnEmployee(),
searchConditionEmployeeForm.getMailAddress(),
searchConditionEmployeeForm.getIdDepartment()
);
}
} }

View File

@@ -1,53 +0,0 @@
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 UpdateDepartmentForm {
private Integer idDepartment;
private String nmDepartment;
public static UpdateDepartmentForm convertFrom(Department department) {
return new UpdateDepartmentForm(
department.getIdDepartment(),
department.getNmDepartment());
}
public static List<UpdateDepartmentForm> convertFrom(List<Department> departmentList) {
return departmentList.stream().map(UpdateDepartmentForm::convertFrom).toList();
}
public static Department convertTo(UpdateDepartmentForm updateDepartmentForm) {
return new Department(
updateDepartmentForm.getIdDepartment(),
updateDepartmentForm.getNmDepartment());
}
public static boolean hasErrorParameter(UpdateDepartmentForm updateDepartmentForm) {
boolean errorFlag = !isNullOrBlank(updateDepartmentForm.getNmDepartment());
if (!isNullOrBlank(updateDepartmentForm.getNmDepartment())) {
errorFlag = true;
}
return errorFlag;
}
private static boolean isNullOrBlank(String str) {
if (null == str) {
return true;
}
return str.isBlank();
}
}

View File

@@ -1,104 +1,192 @@
package com.example.rhizome.app.presentation.form; package com.example.rhizome.app.presentation.form;
import java.util.List;
import com.example.rhizome.app.domain.model.Employee; import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.EmployeeInfo; import com.example.rhizome.app.domain.model.EmployeeInfo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.List;
/**
* 画面から渡ってきた更新内容をまとめ、再度画面に表示する為のクラス
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class UpdateEmployeeInfoForm { public class UpdateEmployeeInfoForm {
private Integer idEmployee; /**
private String nmEmployee; * 社員ID
private String knEmployee; */
private String mailAddress; private Integer idEmployee;
private String password; /**
private String passwordConfirm; * 社員名
private Integer adminAuth; */
private Integer idDepartment; private String nmEmployee;
/**
* 社員名カナ
*/
private String knEmployee;
/**
* メールアドレス
*/
private String mailAddress;
/**
* パスワード
*/
private String password;
/**
* パスワード確認用
*/
private String passwordConfirm;
/**
* 管理者権限
*/
private Integer adminAuth;
/**
* 部署ID
*/
private Integer idDepartment;
public static UpdateEmployeeInfoForm convertFrom(EmployeeInfo employeeInfo) { /**
return new UpdateEmployeeInfoForm( * business 層の EmployeeInfo クラスから画面用(presentation 層)の UpdateEmployeeInfoForm に
employeeInfo.getEmployee().getIdEmployee(), * 変換します。
employeeInfo.getEmployee().getNmEmployee(), *
employeeInfo.getEmployee().getKnEmployee(), * @param employeeInfo business 層の EmployeeInfo インスタンス
employeeInfo.getEmployee().getMailAddress(), * @return 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンス
employeeInfo.getEmployee().getPassword(), */
null, public static UpdateEmployeeInfoForm convertFrom(EmployeeInfo employeeInfo) {
employeeInfo.getEmployee().getAdminAuth(), return new UpdateEmployeeInfoForm(
employeeInfo.getDepartment().getIdDepartment()); employeeInfo.getEmployee().getIdEmployee(),
} employeeInfo.getEmployee().getNmEmployee(),
employeeInfo.getEmployee().getKnEmployee(),
employeeInfo.getEmployee().getMailAddress(),
employeeInfo.getEmployee().getPassword(),
null,
employeeInfo.getEmployee().getAdminAuth(),
employeeInfo.getDepartment().getIdDepartment()
);
}
public static List<UpdateEmployeeInfoForm> convertFrom(List<EmployeeInfo> employeeInfoList) { /**
return employeeInfoList.stream().map(UpdateEmployeeInfoForm::convertFrom).toList(); * business 層の EmployeeInfo クラスから画面用(presentation 層)の UpdateEmployeeInfoForm に
} * 変換します。(リスト版)
*
* @param employeeInfoList business 層の EmployeeInfo インスタンスのリスト
* @return 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンスのリスト
*/
public static List<UpdateEmployeeInfoForm> convertFrom(List<EmployeeInfo> employeeInfoList) {
return employeeInfoList.stream().map(UpdateEmployeeInfoForm::convertFrom).toList();
}
public static Employee convertTo(UpdateEmployeeInfoForm updateEmployeeInfoForm) { /**
return new Employee( * 画面用(presentation 層)の UpdateEmployeeInfoForm クラスから business 層の Employee クラスに
updateEmployeeInfoForm.getIdEmployee(), * 変換します。
updateEmployeeInfoForm.getNmEmployee(), *
updateEmployeeInfoForm.getKnEmployee(), * @param updateEmployeeInfoForm 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンス
updateEmployeeInfoForm.getMailAddress(), * @return business 層の Employee インスタンス
updateEmployeeInfoForm.getPassword(), */
updateEmployeeInfoForm.getAdminAuth(), public static Employee convertTo(UpdateEmployeeInfoForm updateEmployeeInfoForm) {
updateEmployeeInfoForm.getIdDepartment()); return new Employee(
} updateEmployeeInfoForm.getIdEmployee(),
updateEmployeeInfoForm.getNmEmployee(),
updateEmployeeInfoForm.getKnEmployee(),
updateEmployeeInfoForm.getMailAddress(),
updateEmployeeInfoForm.getPassword(),
updateEmployeeInfoForm.getAdminAuth(),
updateEmployeeInfoForm.getIdDepartment()
);
}
public static boolean hasErrorParameter(UpdateEmployeeInfoForm updateEmployeeInfoForm) { /**
* 画面から渡ってきたパラメータのチェック
*
* @param updateEmployeeInfoForm 画面から渡ってきたパラメータ
* @return true: エラー無し false:エラーあり(必須を満たしていない)
*/
public static boolean hasErrorParameter(UpdateEmployeeInfoForm updateEmployeeInfoForm) {
boolean errorFlag = !isNullOrBlank(updateEmployeeInfoForm.getNmEmployee()); boolean errorFlag = !isNullOrBlank(updateEmployeeInfoForm.getNmEmployee());
if (!isNullOrBlank(updateEmployeeInfoForm.getKnEmployee())) { if (!isNullOrBlank(updateEmployeeInfoForm.getKnEmployee())) {
errorFlag = true; errorFlag = true;
} }
if (!isNullOrBlank(updateEmployeeInfoForm.getMailAddress())) { if (!isNullOrBlank(updateEmployeeInfoForm.getMailAddress())) {
errorFlag = true; errorFlag = true;
} }
if (!isNullOrBlank(updateEmployeeInfoForm.getPassword())) { if (!isNullOrBlank(updateEmployeeInfoForm.getPassword())) {
errorFlag = true; errorFlag = true;
} }
return errorFlag;
}
public static String validatePassword(String password, String passwordConfirm) { return errorFlag;
}
final String ERROR = "パスワードが一致していません"; /**
* パスワードの仕様チェック
* パスワードが仕様を満たしてないか確認
*
* @param password 更新対象のパスワード
* @param passwordConfirm 更新対象の確認用パスワード
* @return 空文字: エラー無し それ以外:エラー内容
*/
public static String validatePassword(String password, String passwordConfirm) {
if (areBothBlank(password, passwordConfirm)) { final String ERROR = "パスワードが一致していません";
return "";
}
if (isEitherBlank(password, passwordConfirm)) { if (areBothBlank(password, passwordConfirm)) {
return ERROR; // どちらもnullまたは空白の場合はOK
} return "";
}
if (!password.equals(passwordConfirm)) { // どちらかがnullまたは空白の場合のエラーハンドリング
return ERROR; if (isEitherBlank(password, passwordConfirm)) {
} return ERROR;
return ""; }
} // 値が異なった場合はエラーハンドリング
if (!password.equals(passwordConfirm)) {
return ERROR;
}
return "";
private static boolean isNullOrBlank(String str) { }
if (null == str) {
return true;
}
return str.isBlank();
}
private static boolean areBothBlank(String password, String passwordConfirm) { /**
return (password == null || password.isBlank()) && (passwordConfirm == null || passwordConfirm.isBlank()); * 仮引数を 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();
}
private static boolean isEitherBlank(String password, String passwordConfirm) { /**
return password == null || password.isBlank() || passwordConfirm == null || passwordConfirm.isBlank(); * パスワードが今回更新対象に含まれているかチェック
} *
* @param password 更新対象のパスワード
* @param passwordConfirm 更新対象の確認用パスワード
* @return true:どちらもnullまたは空白の場合 false:それ以外
*/
private static boolean areBothBlank(String password, String passwordConfirm) {
return (password == null || password.isBlank()) && (passwordConfirm == null || passwordConfirm.isBlank());
}
/**
* パスワードが今回更新対象に含まれているかチェック その2
*
* @param password 更新対象のパスワード
* @param passwordConfirm 更新対象の確認用パスワード
* @return true: 問題なし false:どちらかがnullまたは空白の場合
*/
// どちらかがnullまたは空白の場合のエラーハンドリング
private static boolean isEitherBlank(String password, String passwordConfirm) {
return password == null || password.isBlank() || passwordConfirm == null || passwordConfirm.isBlank();
}
} }

View File

@@ -2,101 +2,184 @@ package com.example.rhizome.app.presentation.form;
import com.example.rhizome.app.domain.model.Employee; import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/**
* 個人情報更新画面のフォームクラスです。
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class UpdatePersonalUserForm { public class UpdatePersonalUserForm {
private Integer idEmployee; /**
private String nmEmployee; * 社員ID
private String knEmployee; */
private String mailAddress; private Integer idEmployee;
private String password; /**
private String passwordConfirm; * 社員名
*/
private String nmEmployee;
/**
* 社員名カナ
*/
private String knEmployee;
/**
* メールアドレス
*/
private String mailAddress;
/**
* パスワード
*/
private String password;
/**
* パスワード確認用
*/
private String passwordConfirm;
public static Employee convertTo(UpdatePersonalUserForm updatePersonalUserForm) {
return new Employee(
updatePersonalUserForm.getIdEmployee(),
updatePersonalUserForm.getNmEmployee(),
updatePersonalUserForm.getKnEmployee(),
updatePersonalUserForm.getMailAddress(),
updatePersonalUserForm.getPassword(),
null,
null);
}
public static UpdatePersonalUserForm convertFrom(Employee employee) { /**
return new UpdatePersonalUserForm( * 画面用(presentation 層)の UpdatePersonalUserForm クラスから business 層の Employee クラスに
employee.getIdEmployee(), * 変換します。
employee.getNmEmployee(), *
employee.getKnEmployee(), * @param updatePersonalUserForm 画面用(presentation 層)の UpdatePersonalUserForm インスタンス
employee.getMailAddress(), * @return business 層の Employee インスタンス
employee.getPassword(), */
null); public static Employee convertTo(UpdatePersonalUserForm updatePersonalUserForm) {
} return new Employee(
updatePersonalUserForm.getIdEmployee(),
updatePersonalUserForm.getNmEmployee(),
updatePersonalUserForm.getKnEmployee(),
updatePersonalUserForm.getMailAddress(),
updatePersonalUserForm.getPassword(),
null,
null
);
}
public static UpdatePersonalUserForm convertFrom(LoginUser loginUser) { /**
return new UpdatePersonalUserForm( * business 層の Employee クラスから画面用(presentation 層)の UpdatePersonalUserForm に
loginUser.getIdEmployee(), * 変換します。(リスト版)
loginUser.getNmEmployee(), *
loginUser.getKnEmployee(), * @param employee business 層の employee インスタンスのリスト
loginUser.getMailAddress(), * @return クラスから画面用(presentation 層)の UpdatePersonalUserForm インスタンスのリスト
loginUser.getPassword(), */
null); public static UpdatePersonalUserForm convertFrom(Employee employee) {
} return new UpdatePersonalUserForm(
employee.getIdEmployee(),
employee.getNmEmployee(),
employee.getKnEmployee(),
employee.getMailAddress(),
employee.getPassword(),
null
);
}
public static boolean hasErrorParameter(UpdatePersonalUserForm updatePersonalUserForm) { /**
* business 層の Employee クラスから画面用(presentation 層)の UpdatePersonalUserForm に
* 変換します。(リスト版)
*
* @param loginUser business 層の loginUser インスタンスのリスト
* @return クラスから画面用(presentation 層)の UpdatePersonalUserForm インスタンスのリスト
*/
public static UpdatePersonalUserForm convertFrom(LoginUser loginUser) {
return new UpdatePersonalUserForm(
loginUser.getIdEmployee(),
loginUser.getNmEmployee(),
loginUser.getKnEmployee(),
loginUser.getMailAddress(),
loginUser.getPassword(),
null
);
}
boolean errorFlag = !isNullOrBlank(updatePersonalUserForm.getNmEmployee()); /**
* 画面から渡ってきたパラメータのチェック
*
* @param updatePersonalUserForm 画面から渡ってきたパラメータ
* @return true: エラー無し false:エラーあり(必須を満たしていない)
*/
public static boolean hasErrorParameter(UpdatePersonalUserForm updatePersonalUserForm) {
if (!isNullOrBlank(updatePersonalUserForm.getKnEmployee())) { boolean errorFlag = !isNullOrBlank(updatePersonalUserForm.getNmEmployee());
errorFlag = true;
}
if (!isNullOrBlank(updatePersonalUserForm.getMailAddress())) {
errorFlag = true;
}
if (!isNullOrBlank(updatePersonalUserForm.getPassword())) {
errorFlag = true;
}
return errorFlag; if (!isNullOrBlank(updatePersonalUserForm.getKnEmployee())) {
} errorFlag = true;
}
if (!isNullOrBlank(updatePersonalUserForm.getMailAddress())) {
errorFlag = true;
}
if (!isNullOrBlank(updatePersonalUserForm.getPassword())) {
errorFlag = true;
}
public static String validatePassword(String password, String passwordConfirm) {
final String ERROR = "パスワードが一致していません"; return errorFlag;
}
if (areBothBlank(password, passwordConfirm)) { /**
return ""; * パスワードの仕様チェック
} * パスワードが仕様を満たしてないか確認
*
* @param password 更新対象のパスワード
* @param passwordConfirm 更新対象の確認用パスワード
* @return 空文字: エラー無し それ以外:エラー内容
*/
public static String validatePassword(String password, String passwordConfirm) {
if (isEitherBlank(password, passwordConfirm)) { final String ERROR = "パスワードが一致していません";
return ERROR;
}
if (!password.equals(passwordConfirm)) { if (areBothBlank(password, passwordConfirm)) {
return ERROR; // どちらもnullまたは空白の場合はOK
} return "";
return ""; }
} // どちらかがnullまたは空白の場合のエラーハンドリング
if (isEitherBlank(password, passwordConfirm)) {
return ERROR;
}
private static boolean isNullOrBlank(String str) { // 値が異なった場合はエラーハンドリング
if (null == str) { if (!password.equals(passwordConfirm)) {
return true; return ERROR;
} }
return str.isBlank(); return "";
}
private static boolean areBothBlank(String password, String passwordConfirm) { }
return (password == null || password.isBlank()) && (passwordConfirm == null || passwordConfirm.isBlank());
}
private static boolean isEitherBlank(String password, String passwordConfirm) { /**
return password == null || password.isBlank() || passwordConfirm == null || passwordConfirm.isBlank(); * 仮引数を 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();
}
/**
* パスワードが今回更新対象に含まれているかチェック
*
* @param password 更新対象のパスワード
* @param passwordConfirm 更新対象の確認用パスワード
* @return true:どちらもnullまたは空白の場合 false:それ以外
*/
private static boolean areBothBlank(String password, String passwordConfirm) {
return (password == null || password.isBlank()) && (passwordConfirm == null || passwordConfirm.isBlank());
}
/**
* パスワードが今回更新対象に含まれているかチェック その2
*
* @param password 更新対象のパスワード
* @param passwordConfirm 更新対象の確認用パスワード
* @return true: 問題なし false:どちらかがnullまたは空白の場合
*/
private static boolean isEitherBlank(String password, String passwordConfirm) {
return password == null || password.isBlank() || passwordConfirm == null || passwordConfirm.isBlank();
}
} }

View File

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

View File

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

View File

@@ -1,10 +1,3 @@
spring.datasource.url=jdbc:mysql://localhost:3306/springdb spring.datasource.url=jdbc:mysql://localhost:3306/springdb
spring.datasource.username=rezouser spring.datasource.username=rezouser
spring.datasource.password=Rezo_0000 spring.datasource.password=Rezo_0000
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.show-sql=true
logging.level.org.hibernate.type.descriptor.sql=trace

View File

@@ -14,21 +14,25 @@ h1 {
min-width: 640px; min-width: 640px;
font-size: 15pt; font-size: 15pt;
font-weight: bold; font-weight: bold;
display: flex; display: flex; /* フレックスボックスを使う */
justify-content: space-between; justify-content: space-between; /* 左右の要素を端に寄せる */
align-items: center; align-items: center; /* 上下中央に配置 */
} }
.rightSection { .rightSection {
display: flex; display: flex; /* フレックスボックスを使う */
align-items: center; align-items: center; /* 上下中央に配置 */
} }
/* 入力フォーム */
input, button, select { input, button, select {
padding: 5px 15px 5px 15px; padding: 5px 15px 5px 15px;
margin: 3px; margin: 3px;
/* border-radius: 5px; /* CSS3草案 */
/* -webkit-border-radius: 5px; /* Safari,Google Chrome用 */
/* -moz-border-radius: 5px; /* Firefox用 */
} }
input.readOnly { input.readOnly {
@@ -36,6 +40,7 @@ input.readOnly {
color: #ffffff; color: #ffffff;
} }
/* メッセージボックスデザイン */
.msgBox { .msgBox {
font-weight: bold; font-weight: bold;
@@ -59,6 +64,7 @@ input.readOnly {
color: #000000; color: #000000;
} }
/* 個別デザイン */
th.header { th.header {
width: 150px; width: 150px;
@@ -68,7 +74,7 @@ th.header {
.loginInfo { .loginInfo {
font-size: 9pt; font-size: 9pt;
color: #008080; color: #008080;
margin-right: 10px; margin-right: 10px; /* ログアウトボタンとの間隔 */
} }
.logoutButton { .logoutButton {
@@ -85,9 +91,10 @@ td.btnArea {
} }
.header-spacing { .header-spacing {
margin-top: 20px; margin-top: 20px; /* 上部に20ピクセルのマージン */
} }
/* グリッドラインの追加 */
.table-grid { .table-grid {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: collapse;
@@ -103,14 +110,17 @@ td.btnArea {
background-color: #f2f2f2; background-color: #f2f2f2;
} }
/* ストライプ効果(奇数行と偶数行で色を交互に) */
.table-striped tbody tr:nth-child(odd) { .table-striped tbody tr:nth-child(odd) {
background-color: #f2f2f2; background-color: #f2f2f2;
} }
/* ホバー効果(マウスオーバー時に行の色を変更) */
.table-hover tbody tr:hover { .table-hover tbody tr:hover {
background-color: #ccffcc; background-color: #ccffcc; /* パステルグリーンの背景色 */
} }
/* レスポンシブデザイン(小さい画面でスクロール) */
.table-responsive { .table-responsive {
overflow-x: auto; overflow-x: auto;
display: block; display: block;
@@ -145,17 +155,17 @@ table.menuClass td.description {
} }
input[type="submit"], input[type="reset"], button { input[type="submit"], input[type="reset"], button {
color: #008080; color: #008080; /* ターコイズ色 */
text-decoration: none; text-decoration: none; /* 下線をなくす */
padding: 10px 20px; padding: 10px 20px; /* パディングを追加 */
border: 1px solid #008080; border: 1px solid #008080; /* 枠線を追加 */
border-radius: 5px; border-radius: 5px; /* 角を丸くする */
background-color: transparent; background-color: transparent; /* 背景色を透明に */
cursor: pointer; cursor: pointer; /* カーソルをポインターに */
transition: 0.3s; transition: 0.3s; /* アニメーション効果 */
} }
input[type="submit"]:hover, input[type="reset"]:hover, button:hover { input[type="submit"]:hover, input[type="reset"]:hover, button:hover {
background-color: #008080; background-color: #008080; /* マウスオーバー時の背景色 */
color: #ffffff; color: #ffffff; /* マウスオーバー時の文字色 */
} }

View File

@@ -1,6 +1,8 @@
function convertToKatakana(input) { function convertToKatakana(input) {
// 漢字とローマ字を削除
const valueWithoutKanjiAndRomaji = input.value.replace(/[\u4E00-\u9FFF\u0041-\u009F]/g, ''); const valueWithoutKanjiAndRomaji = input.value.replace(/[\u4E00-\u9FFF\u0041-\u009F]/g, '');
// ひらがなをカタカナに変換
const katakanaValue = valueWithoutKanjiAndRomaji.replace(/[\u3041-\u3096]/g, function (match) { const katakanaValue = valueWithoutKanjiAndRomaji.replace(/[\u3041-\u3096]/g, function (match) {
const chr = match.charCodeAt(0) + 0x60; const chr = match.charCodeAt(0) + 0x60;
return String.fromCharCode(chr); return String.fromCharCode(chr);
@@ -14,12 +16,15 @@ function logoutSubmit() {
form.setAttribute('method', 'post'); form.setAttribute('method', 'post');
form.setAttribute('action', 'logout'); form.setAttribute('action', 'logout');
// 動的送信用のHidden
// 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない
const inputField = document.createElement("input"); const inputField = document.createElement("input");
inputField.setAttribute("type", "hidden"); inputField.setAttribute("type", "hidden");
inputField.setAttribute("value", "logout"); inputField.setAttribute("value", "logout");
form.appendChild(inputField); form.appendChild(inputField);
// フォームをDOMに追加
document.body.appendChild(form); document.body.appendChild(form);
form.submit(); form.submit();

View File

@@ -15,11 +15,6 @@
<h1>エラーが発生しました。</h1> <h1>エラーが発生しました。</h1>
<div>ログインからやり直してください。</div> <div>ログインからやり直してください。</div>
<div class="msgBox error" th:if="${messageError} != null">
<span class="error" th:text="${messageError.message}"></span>
</div>
<a href="login">ログイン</a> <a href="login">ログイン</a>
</body> </body>
</html> </html>

View File

@@ -1,86 +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="insertDepartment"
id="insertForm"
method="post"
th:object="${insertDepartmentForm}">
<div class="msgBox error" th:if="${messageError != null}">
<span class="error" th:each="message : ${messageError.message}" th:text="${message}"></span>
</div>
<table>
<tr>
<th class="header">部署ID</th>
<td>
<label>
<input class="readOnly"
name="dptId"
readonly="readonly"
type="text"
value="自動で設定されます"/>
</label>
</td>
</tr>
<tr>
<th class="header">部署名</th>
<td>
<label>
<input class="readOnly"
name="nmDepartment"
readonly="readonly"
th:value="*{nmDepartment}"
type="text"/>
</label>
</td>
</tr>
<tr>
<td class="btnArea" colspan="2">
<input type="submit" value="登録"/>
</td>
</tr>
</table>
<a href="javascript:onClickEdit()">登録内容の編集</a> | <a href="showMenu">メニューに戻る</a>
</form>
<script type="text/javascript">
function onClickEdit() {
const form = document.getElementById('insertForm');
form.setAttribute('method', 'post');
form.setAttribute('action', 'insertDepartmentInput');
const inputField = document.createElement("input");
inputField.setAttribute("type", "hidden");
inputField.setAttribute("name", "backFlg");
inputField.setAttribute("value", "edit");
form.appendChild(inputField);
document.body.appendChild(form);
form.submit();
}
</script>
</body>
</html>

View File

@@ -46,7 +46,7 @@
<td> <td>
<label> <label>
<input maxlength="50" <input maxlength="50"
placeholder="社員名" placeholder="部署名"
required="required" required="required"
th:field="*{nmDepartment}" th:field="*{nmDepartment}"
type="text" type="text"

View File

@@ -1,35 +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>
<link rel="stylesheet" th:href="@{/css/all.css}">
<link rel=stylesheet th:href="@{/css/style.css}" type="text/css">
<title>社員登録完了</title>
</head>
<body>
<h2>社員登録が完了しました</h2>
<br/>
<a href="javascript:insertSubmit()">続けて登録する</a> | <a href="showMenu">メニューに戻る</a>
</body>
<script type="text/javascript">
function insertSubmit() {
const form = document.createElement('form');
form.setAttribute('method', 'post');
form.setAttribute('action', 'insertDepartmentInput');
const inputField = document.createElement("input");
inputField.setAttribute("type", "hidden");
inputField.setAttribute("value", "select");
form.appendChild(inputField);
document.body.appendChild(form);
form.submit();
}
</script>
</html>

View File

@@ -4,7 +4,9 @@
<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の読み込み -->
<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>
@@ -136,6 +138,7 @@
form.setAttribute('method', 'post'); form.setAttribute('method', 'post');
form.setAttribute('action', 'insertEmployeeInput'); form.setAttribute('action', 'insertEmployeeInput');
// 確認画面から編集画面に戻ってきたときのフラグ(未使用)
const inputField = document.createElement("input"); const inputField = document.createElement("input");
inputField.setAttribute("type", "hidden"); inputField.setAttribute("type", "hidden");
inputField.setAttribute("name", "backFlg"); inputField.setAttribute("name", "backFlg");
@@ -143,6 +146,7 @@
form.appendChild(inputField); form.appendChild(inputField);
// フォームをDOMに追加
document.body.appendChild(form); document.body.appendChild(form);
form.submit(); form.submit();

View File

@@ -4,7 +4,9 @@
<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の読み込み -->
<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>
@@ -21,12 +23,15 @@
form.setAttribute('method', 'post'); form.setAttribute('method', 'post');
form.setAttribute('action', 'insertEmployeeInput'); form.setAttribute('action', 'insertEmployeeInput');
// 動的送信用のHidden
// 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない
const inputField = document.createElement("input"); const inputField = document.createElement("input");
inputField.setAttribute("type", "hidden"); inputField.setAttribute("type", "hidden");
inputField.setAttribute("value", "select"); inputField.setAttribute("value", "select");
form.appendChild(inputField); form.appendChild(inputField);
// フォームをDOMに追加
document.body.appendChild(form); document.body.appendChild(form);
form.submit(); form.submit();

View File

@@ -30,7 +30,7 @@
required="required" required="required"
style="width: 100%;" style="width: 100%;"
th:field="*{mailAddress}" th:field="*{mailAddress}"
type="email"/> type="text"/>
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@@ -4,7 +4,9 @@
<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の読み込み -->
<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>
@@ -25,20 +27,22 @@
</td> </td>
<td class="description">登録済みのユーザ一覧表示と</br>更新、削除を行います。</td> <td class="description">登録済みのユーザ一覧表示と</br>更新、削除を行います。</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>
<td><a class="menuClass" href="javascript:insertDepartmentSubmit()"><i class="fas fa-search"></i> 部署登録 </a>
</td>
<td class="description">部署の新規登録を行います。</br></td>
</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>
<td><a class="menuClass" href="javascript:insertDepartmentSubmit()"><i class="fas fa-plus"></i> 部署登録 </a></td>
<td class="description">新規で部署追加を行います。</td>
</tr>
</table> </table>
</body> </body>
@@ -49,12 +53,15 @@
form.setAttribute('method', 'post'); form.setAttribute('method', 'post');
form.setAttribute('action', 'selectEmployeeInfo'); form.setAttribute('action', 'selectEmployeeInfo');
// 動的送信用のHidden
// 動的に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に追加
document.body.appendChild(form); document.body.appendChild(form);
form.submit(); form.submit();
@@ -63,14 +70,17 @@
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
// 動的に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", "selectDepartmentInfo");
form.appendChild(inputField); form.appendChild(inputField);
// フォームをDOMに追加
document.body.appendChild(form); document.body.appendChild(form);
form.submit(); form.submit();
@@ -81,12 +91,15 @@
form.setAttribute('method', 'post'); form.setAttribute('method', 'post');
form.setAttribute('action', 'insertEmployeeInput'); form.setAttribute('action', 'insertEmployeeInput');
// 動的送信用のHidden
// 動的に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に追加
document.body.appendChild(form); document.body.appendChild(form);
form.submit(); form.submit();
@@ -97,12 +110,15 @@
form.setAttribute('method', 'post'); form.setAttribute('method', 'post');
form.setAttribute('action', 'insertDepartmentInput'); form.setAttribute('action', 'insertDepartmentInput');
// 動的送信用のHidden
// 動的に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に追加
document.body.appendChild(form); document.body.appendChild(form);
form.submit(); form.submit();

View File

@@ -20,7 +20,7 @@
<button class="logoutButton" onclick="logoutSubmit()">ログアウト</button> <button class="logoutButton" onclick="logoutSubmit()">ログアウト</button>
</div> </div>
</h1> </h1>
<form action="selectDepartment" <form action="selectDepartmentInfo"
method="post" method="post"
th:object="${searchConditionDepartmentForm}"> th:object="${searchConditionDepartmentForm}">
@@ -44,8 +44,7 @@
type="text"/> type="text"/>
</td> </td>
</tr> </tr>
<tr>
<tr>
<td class="btnArea" colspan="2"> <td class="btnArea" colspan="2">
<input type="submit" value="検索"/> <input type="submit" value="検索"/>
</td> </td>
@@ -66,30 +65,30 @@
</script> </script>
</th:block> </th:block>
<div class="header-spacing"></div> <div class="header-spacing"></div>
<th:block th:if="${departmentFormList != null and departmentFormList.size() > 0}"> <th:block th:if="${departmentInfoFormList != null and departmentInfoFormList.size() > 0}">
<!-- 検索結果が1件以上ある場合 --> <!-- 検索結果が1件以上ある場合 -->
<table class="table-grid table-striped table-hover"> <table class="table-grid table-striped table-hover">
<thead> <thead>
<tr> <tr>
<th style="width: 100px;">部署ID</th> <th style="width: 60px;">部署ID</th>
<th style="width: 150px;">部署名</th> <th style="width: 100px;">部署名</th>
<th style="width: 150px;">操作</th> <th style="width: 150px;">操作</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr th:each="departmentForm : ${departmentFormList}"> <tr th:each="departmentInfoForm : ${departmentInfoFormList}">
<td th:text="${departmentForm.idDepartment}"></td> <td th:text="${departmentInfoForm.idDepartment}"></td>
<td th:text="${departmentForm.nmDepartment}"></td> <td th:text="${departmentInfoForm.nmDepartment}"></td>
<td> <td>
<!-- 更新フォーム --> <!-- 更新フォーム -->
<form action="showUpdateDepartment" method="post" style="display: inline;"> <form action="showUpdateDepartment" method="post" style="display: inline;">
<input name="idDepartment" th:value="${departmentForm.idDepartment}" type="hidden"> <input name="idDepartment" th:value="${departmentInfoForm.idDepartment}" type="hidden">
<input type="submit" value="更新"> <input type="submit" value="更新">
</form> </form>
<!-- 削除フォーム --> <!-- 削除フォーム -->
<form action="deleteDepartment" method="post" onsubmit="return confirm('本当に削除しますか?');" <form action="deleteDepartment" method="post" onsubmit="return confirm('本当に削除しますか?');"
style="display: inline;"> style="display: inline;">
<input name="idDepartment" th:value="${departmentForm.idDepartment}" type="hidden"> <input name="idDepartment" th:value="${departmentInfoForm.idDepartment}" type="hidden">
<input type="submit" value="削除"> <input type="submit" value="削除">
</form> </form>
</td> </td>
@@ -97,7 +96,7 @@
</tbody> </tbody>
</table> </table>
</th:block> </th:block>
<th:block th:if="${departmentFormList == null or departmentFormList.size() == 0}"> <th:block th:if="${departmentInfoFormList == null or departmentInfoFormList.size() == 0}">
<!-- 検索結果が0件の場合 --> <!-- 検索結果が0件の場合 -->
検索結果はありません。 検索結果はありません。
</th:block> </th:block>

Some files were not shown because too many files have changed in this diff Show More