diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..3122b27 --- /dev/null +++ b/.classpath @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/.project b/.project new file mode 100644 index 0000000..8aa533d --- /dev/null +++ b/.project @@ -0,0 +1,37 @@ + + + em-spring + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 0000000..e4a0c2d --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..29abf99 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -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/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..f9e3458 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..5517781 --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..36d3a1f --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/src/main/java/com/example/rhizome/app/domain/service/RegisterDepartment.java b/src/main/java/com/example/rhizome/app/domain/service/RegisterDepartment.java index 73eefcb..e0bd7b4 100644 --- a/src/main/java/com/example/rhizome/app/domain/service/RegisterDepartment.java +++ b/src/main/java/com/example/rhizome/app/domain/service/RegisterDepartment.java @@ -2,6 +2,7 @@ package com.example.rhizome.app.domain.service; import com.example.rhizome.app.domain.model.Department; + public interface RegisterDepartment { void registerDepartment(Department department); } diff --git a/src/main/java/com/example/rhizome/app/domain/service/RegisterDepartmentImpl.java b/src/main/java/com/example/rhizome/app/domain/service/RegisterDepartmentImpl.java new file mode 100644 index 0000000..1635ac5 --- /dev/null +++ b/src/main/java/com/example/rhizome/app/domain/service/RegisterDepartmentImpl.java @@ -0,0 +1,26 @@ +package com.example.rhizome.app.domain.service; + +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.infra.entity.DepartmentEntity; +import com.example.rhizome.app.infra.repository.DepartmentRepository; + +@Service +@Transactional +public class RegisterDepartmentImpl implements RegisterDepartment { + + DepartmentRepository departmentRepository; + + @Autowired + public RegisterDepartmentImpl(DepartmentRepository departmentRepository) { + this.departmentRepository = departmentRepository; + } + + public void registerDepartment(Department department) { + departmentRepository.save(DepartmentEntity.convertFrom(department)); + } + +} diff --git a/src/main/java/com/example/rhizome/app/domain/service/SearchDepartmentInfo.java b/src/main/java/com/example/rhizome/app/domain/service/SearchDepartmentInfo.java new file mode 100644 index 0000000..84c12bf --- /dev/null +++ b/src/main/java/com/example/rhizome/app/domain/service/SearchDepartmentInfo.java @@ -0,0 +1,12 @@ +package com.example.rhizome.app.domain.service; + +import java.util.List; + +import com.example.rhizome.app.domain.model.Department; +import com.example.rhizome.app.domain.model.SearchConditionDepartment; + +public interface SearchDepartmentInfo { + List selectAll(); + + List searchBy(SearchConditionDepartment searchConditionDepartment); +} diff --git a/src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentController.java b/src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentController.java new file mode 100644 index 0000000..d3f795e --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentController.java @@ -0,0 +1,95 @@ +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 com.example.rhizome.aop.aspect.PermissionCheck; +import com.example.rhizome.aop.aspect.SessionCheck; +import com.example.rhizome.app.domain.service.RegisterDepartment; +import com.example.rhizome.app.domain.service.SearchDepartment; +import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword; +import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword; +import com.example.rhizome.app.presentation.form.DepartmentForm; +import com.example.rhizome.app.presentation.form.InsertDepartmentForm; +import com.example.rhizome.app.presentation.form.MessageForm; + +@Controller +public class InsertDepartmentController { + + private final static Logger LOGGER = Logger.getLogger(InsertDepartmentController.class.getName()); + private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; + + private final HttpSession httpSession; + private final RegisterDepartment registerDepartment; + private final SearchDepartment searchDepartment; + + @Autowired + public InsertDepartmentController(HttpSession httpSession, RegisterDepartment registerDepartment, + SearchDepartment searchDepartment) { + this.httpSession = httpSession; + this.registerDepartment = registerDepartment; + this.searchDepartment = searchDepartment; + } + + @ModelAttribute + public InsertDepartmentForm insertDepartmentForm() { + return new InsertDepartmentForm(); + } + + @PermissionCheck + @SessionCheck + @RequestMapping(value = "/insertDepartmentInput", method = RequestMethod.POST) + public String showInsertInput(@ModelAttribute("insertDepartmentForm") InsertDepartmentForm insertDepartmentForm) { + return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML; + } + + @PermissionCheck + @SessionCheck + @RequestMapping(value = "/insertDepartmentConfirm", method = RequestMethod.POST) + public String confirmDepartment(@ModelAttribute("insertDepartmentForm") InsertDepartmentForm insertDepartmentForm, + Model model) { + + List error = insertDepartmentForm.validateParameter(); + + if (!error.isEmpty()) { + model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, + new MessageForm(String.join(", ", error) + "が不正です。")); + return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML; + } + + return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_CONFIRM_HTML; + } + + @PermissionCheck + @SessionCheck + @RequestMapping(value = "/insertDepartment", method = RequestMethod.POST) + public String insertDepartment(@ModelAttribute("insertDepartmentForm") InsertDepartmentForm insertDepartmentForm, + Model model) { + try { + model.addAttribute( + PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, + DepartmentForm.convertFrom(searchDepartment.selectAll())); + + 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; + } + } +} diff --git a/src/main/java/com/example/rhizome/app/presentation/controller/InsertEmployeeController.java b/src/main/java/com/example/rhizome/app/presentation/controller/InsertEmployeeController.java index a532295..862364a 100644 --- a/src/main/java/com/example/rhizome/app/presentation/controller/InsertEmployeeController.java +++ b/src/main/java/com/example/rhizome/app/presentation/controller/InsertEmployeeController.java @@ -1,5 +1,21 @@ 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.service.RegisterEmployee; @@ -11,20 +27,6 @@ import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTa import com.example.rhizome.app.presentation.form.DepartmentForm; import com.example.rhizome.app.presentation.form.InsertEmployeeForm; 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; /** * 新規登録用のコントローラ @@ -32,167 +34,163 @@ import static com.example.rhizome.app.presentation.controller.pageproperty.Trans @Controller 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; - RegisterEmployee registerEmployee; - SearchDepartment searchDepartment; + HttpSession httpSession; + RegisterEmployee registerEmployee; + SearchDepartment searchDepartment; - @Autowired - public InsertEmployeeController(HttpSession httpSession, RegisterEmployeeImpl registerEmployee, SearchDepartmentImpl searchDepartment) { - this.httpSession = httpSession; - this.registerEmployee = registerEmployee; - this.searchDepartment = searchDepartment; - } + @Autowired + public InsertEmployeeController(HttpSession httpSession, RegisterEmployeeImpl registerEmployee, + SearchDepartmentImpl searchDepartment) { + this.httpSession = httpSession; + this.registerEmployee = registerEmployee; + this.searchDepartment = searchDepartment; + } - @ModelAttribute - public InsertEmployeeForm insertEmployeeForm() { - return new InsertEmployeeForm(); - } + @ModelAttribute + public InsertEmployeeForm insertEmployeeForm() { + return new InsertEmployeeForm(); + } - /** - * 新規登録画面表示処理 - * - * @param insertEmployeeForm 登録情報 - * @param model ビューにデータを渡すためのコンテナ - * @return 遷移先の画面 - */ - @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 { - // 部署一覧を取得し、画面に返す用のクラスに詰め替える - // 作成した部署一覧をセット - model.addAttribute( - PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, - DepartmentForm.convertFrom( - searchDepartment.selectAll() - )); + try { + // 部署一覧を取得し、画面に返す用のクラスに詰め替える + // 作成した部署一覧をセット + model.addAttribute( + PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, + DepartmentForm.convertFrom( + searchDepartment.selectAll())); - // Confirm画面から渡ってきた値をチェック - List error = validateParameter( - insertEmployeeForm.getNmEmployee(), - insertEmployeeForm.getKnEmployee(), - insertEmployeeForm.getMailAddress(), - insertEmployeeForm.getPassword(), - insertEmployeeForm.getAdminAuth(), - insertEmployeeForm.getIdDepartment() - ); + // Confirm画面から渡ってきた値をチェック + List error = validateParameter( + insertEmployeeForm.getNmEmployee(), + insertEmployeeForm.getKnEmployee(), + insertEmployeeForm.getMailAddress(), + insertEmployeeForm.getPassword(), + insertEmployeeForm.getAdminAuth(), + insertEmployeeForm.getIdDepartment()); - // エラーが1件以上有る場合 - if (!error.isEmpty()) { - // エラー内容を画面に表示 - model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(String.join(", ", error) + "が不正です。")); - // 登録画面に遷移 - return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML; - } + // エラーが1件以上有る場合 + if (!error.isEmpty()) { + // エラー内容を画面に表示 + 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) { - // ログイン情報の破棄 - httpSession.invalidate(); + } catch (Exception e) { + // ログイン情報の破棄 + 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; + } + } - /** - * @param employeeName 登録対象の名前 - * @param employeeKana 登録対象のカナ - * @param mailAddress 登録対象のメールアドレス - * @param password 登録対象のパスワード - * @param management システム権限 - * @param departmentId 部署ID - * @return エラーが有った場合はエラー文言、無ければ空のリストが返る - */ - private List validateParameter( - String employeeName, - String employeeKana, - String mailAddress, - String password, - Integer management, - Integer departmentId - ) { + /** + * @param employeeName 登録対象の名前 + * @param employeeKana 登録対象のカナ + * @param mailAddress 登録対象のメールアドレス + * @param password 登録対象のパスワード + * @param management システム権限 + * @param departmentId 部署ID + * @return エラーが有った場合はエラー文言、無ければ空のリストが返る + */ + private List validateParameter( + String employeeName, + String employeeKana, + String mailAddress, + String password, + Integer management, + Integer departmentId) { - final String EMPLOYEE_NAME_NULL_BLANK = "社員名"; - final String EMPLOYEE_KANA_NULL_BLANK = "社員名フリガナ"; - final String MAIL_ADDRESS_NULL_BLANK = "メールアドレス"; - final String PASSWORD_NULL_BLANK = "パスワード"; - final String MANAGEMENT_ERROR = "管理者権限指定"; - final String DEPARTMENT_ID_NULL_BLANK = "所属部署"; + final String EMPLOYEE_NAME_NULL_BLANK = "社員名"; + final String EMPLOYEE_KANA_NULL_BLANK = "社員名フリガナ"; + final String MAIL_ADDRESS_NULL_BLANK = "メールアドレス"; + final String PASSWORD_NULL_BLANK = "パスワード"; + final String MANAGEMENT_ERROR = "管理者権限指定"; + final String DEPARTMENT_ID_NULL_BLANK = "所属部署"; - List error = new ArrayList<>(); + List error = new ArrayList<>(); - // null or 空文字判定 - if (isNullOrBlank(employeeName)) { - // エラー内容を追加 - error.add(EMPLOYEE_NAME_NULL_BLANK); - } + // null or 空文字判定 + if (isNullOrBlank(employeeName)) { + // エラー内容を追加 + error.add(EMPLOYEE_NAME_NULL_BLANK); + } - // null or 空文字判定 - if (isNullOrBlank(employeeKana)) { - // エラー内容を追加 - error.add(EMPLOYEE_KANA_NULL_BLANK); - } + // null or 空文字判定 + if (isNullOrBlank(employeeKana)) { + // エラー内容を追加 + error.add(EMPLOYEE_KANA_NULL_BLANK); + } - // null or 空文字判定 - if (isNullOrBlank(mailAddress)) { - // エラー内容を追加 - error.add(MAIL_ADDRESS_NULL_BLANK); - } + // null or 空文字判定 + if (isNullOrBlank(mailAddress)) { + // エラー内容を追加 + error.add(MAIL_ADDRESS_NULL_BLANK); + } - // null or 空文字判定 - if (isNullOrBlank(password)) { - // エラー内容を追加 - error.add(PASSWORD_NULL_BLANK); - } + // null or 空文字判定 + 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; - } + } - /** - * 仮引数を null or 空 判定する - * - * @param str 判定対象の文字列 - * @return true:null or 空 false:null or 空 では無い - */ - private static boolean isNullOrBlank(String str) { - if (null == str) { - return true; - } + /** + * 仮引数を 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(); - } + return str.isBlank(); + } } - - - diff --git a/src/main/java/com/example/rhizome/app/presentation/controller/SelectDepatmentController.java b/src/main/java/com/example/rhizome/app/presentation/controller/SelectDepatmentController.java new file mode 100644 index 0000000..60f2bc3 --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/controller/SelectDepatmentController.java @@ -0,0 +1,81 @@ +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 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.presentation.controller.pageproperty.PageReturnAttributeKeyword; +import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword; +import com.example.rhizome.app.presentation.form.DepartmentForm; +import com.example.rhizome.app.presentation.form.SearchConditionDepartmentForm; + +@Controller +public class SelectDepatmentController { + + // ログ出力用インスタンス + private final static Logger LOGGER = Logger.getLogger(SelectDepatmentController.class.getName()); + // エラーメッセージ用の定数フィールド + private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; + + HttpSession httpSession; + SearchDepartment searchDepartment; + + @Autowired + public SelectDepatmentController(HttpSession httpSession, SearchDepartment searchDepartment) { + this.httpSession = httpSession; + this.searchDepartment = searchDepartment; + } + + @ModelAttribute + public SearchConditionDepartmentForm searchConditionDepartmentForm() { + return new SearchConditionDepartmentForm(); + } + + @PermissionCheck + @SessionCheck + @RequestMapping(value = "/selectDepartment", method = RequestMethod.POST) + public String select(@ModelAttribute("searchConditionDepartmentForm") SearchConditionDepartmentForm searchConditionDepartmentForm, Model model) { + + try { + + SearchConditionDepartment searchCondition = SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm); + + + List departmentList = searchDepartment.searchBy(searchCondition); + + + model.addAttribute( + PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, + DepartmentForm.convertFrom(departmentList) + ); + + + return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML; + + } catch (Exception e) { + // ログイン情報の破棄 + httpSession.invalidate(); + + e.printStackTrace(); + + // エラーログ出力 + LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); + // エラー画面遷移 + return TransitionTargetPageNameKeyword.ERROR_HTML; + } + } +} diff --git a/src/main/java/com/example/rhizome/app/presentation/controller/UpdateDepartmentController.java b/src/main/java/com/example/rhizome/app/presentation/controller/UpdateDepartmentController.java new file mode 100644 index 0000000..c4e6ae8 --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/controller/UpdateDepartmentController.java @@ -0,0 +1,73 @@ +//package com.example.rhizome.app.presentation.controller; +// +//import java.util.List; +//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.SearchDepartmentInfo; +//import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword; +//import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword; +//import com.example.rhizome.app.presentation.form.DepartmentForm; +//import com.example.rhizome.app.presentation.form.MessageForm; +//import com.example.rhizome.app.presentation.form.SearchConditionDepartmentForm; +//import com.example.rhizome.app.presentation.form.UpdateEmployeeInfoForm; +// +//@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; +// +// @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) { +// final String UPDATE_TARGET_ID_NOT_FOUND = "更新対象のデータが見つかりません。"; +// +// try { +// +// model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(searchDepartment.selectAll())); +// +// List departmentInfoList = SearchDepartmentInfo.seachBy( +// new SearchConditionDepartment(idDepartment, +// null)); +// +// if (departmentInfoList.isEmpty()) { +// model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(UPDATE_TARGET_ID_NOT_FOUND)); +// return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO; +// +// model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_INFO_FORM, UpdateDepartmentInfoForm.convertFrom(departmentInfoList.get(0))); +// } +// } +// } +//} diff --git a/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/PageReturnAttributeKeyword.java b/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/PageReturnAttributeKeyword.java index 5e9ec04..0d55527 100644 --- a/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/PageReturnAttributeKeyword.java +++ b/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/PageReturnAttributeKeyword.java @@ -10,6 +10,7 @@ public class PageReturnAttributeKeyword { public static final String DEPARTMENT_FORM_LIST = "departmentFormList"; public static final String UPDATE_EMPLOYEE_INFO_FORM = "updateEmployeeInfoForm"; + public static final String UPDATE_DEPARTMENT_INFO_FORM = "updateDepartmentInfoForm"; public static final String INSERT_EMPLOYEE_FORM = "insertEmployeeForm"; public static final String LOGIN_INFO_FORM = "loginInfoForm"; public static final String UPDATE_PERSONAL_EMPLOYEE_USER_FORM = "updatePersonalEmployeeUserForm"; diff --git a/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/TransitionTargetPageNameKeyword.java b/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/TransitionTargetPageNameKeyword.java index 90ded96..a109883 100644 --- a/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/TransitionTargetPageNameKeyword.java +++ b/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/TransitionTargetPageNameKeyword.java @@ -17,9 +17,13 @@ public class TransitionTargetPageNameKeyword { // 管理者向け public static final String MENU_HTML = "menu"; public static final String SELECT_EMPLOYEE_HTML = "selectEmployee"; + public static final String SELECT_DEPARTMENT_HTML = "selectDepartment"; public static final String INSERT_EMPLOYEE_INPUT_HTML = "insertEmployeeInput"; + public static final String INSERT_DEPARTMENT_INPUT_HTML = "insertDepartmentInput"; public static final String INSERT_EMPLOYEE_CONFIRM_HTML = "insertEmployeeConfirm"; + public static final String INSERT_DEPARTMENT_CONFIRM_HTML = "insertDepartmentConfirm"; public static final String INSERT_EMPLOYEE_RESULT_HTML = "insertEmployeeResult"; + public static final String INSERT_DEPARTMENT_RESULT_HTML = "insertDepartmentResult"; public static final String UPDATE_EMPLOYEE_INPUT_HTML = "updateEmployeeInput"; public static final String ERROR_HTML = "error"; @@ -46,6 +50,15 @@ public class TransitionTargetPageNameKeyword { public static final String UPDATE_EMPLOYEE_RESULT = "/updateEmployeeResult"; // Department + public static final String DELETE_DEPARTMENT = "/deleteDepartment"; + public static final String INSERT_DEPARTMENT_INPUT = "/insertDepartmentInput"; + public static final String INSERT_DEPARTMENT_CONFIRM = "/insertDepartmentConfirm"; + public static final String INSERT_DEPARTMENT = "/insertDepartment"; + public static final String SELECT_DEPARTMENT_INFO = "/selectDepartment"; + public static final String SELECT_DEPARTMENT_INFO_FORM_EMPTY = "/selectAll"; + public static final String SHOW_UPDATE_DEPARTMENT = "/showUpdateDepartment"; + public static final String UPDATE_DEPARTMENT_RESULT = "/updateDepartmentResult"; + // HTML // Controller @@ -70,7 +83,15 @@ public class TransitionTargetPageNameKeyword { SELECT_EMPLOYEE_INFO, SELECT_EMPLOYEE_INFO_FORM_EMPTY, SHOW_UPDATE_EMPLOYEE, - UPDATE_EMPLOYEE_RESULT + UPDATE_EMPLOYEE_RESULT, + + DELETE_DEPARTMENT, + INSERT_DEPARTMENT_INPUT, + INSERT_DEPARTMENT, + INSERT_DEPARTMENT_CONFIRM, + SELECT_DEPARTMENT_INFO, + SHOW_UPDATE_DEPARTMENT, + UPDATE_DEPARTMENT_RESULT ); } diff --git a/src/main/java/com/example/rhizome/app/presentation/form/InsertDepartmentForm.java b/src/main/java/com/example/rhizome/app/presentation/form/InsertDepartmentForm.java new file mode 100644 index 0000000..4230d5d --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/form/InsertDepartmentForm.java @@ -0,0 +1,42 @@ +package com.example.rhizome.app.presentation.form; + +import java.util.ArrayList; +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 InsertDepartmentForm { + + private String nmDepartment; + + public static Department convertTo(InsertDepartmentForm insertDepartmentForm) { + return new Department( + null, + insertDepartmentForm.getNmDepartment()); + } + + private static boolean isNullOrBlank(String str) { + if (null == str) { + return true; + } + + return str.isBlank(); + } + + public List validateParameter() { + final String DEPARTMENT_NAME_NULL_BLANK = "部署名"; + + List error = new ArrayList<>(); + if (isNullOrBlank(nmDepartment)) { + error.add(DEPARTMENT_NAME_NULL_BLANK); + } + return error; + } +} diff --git a/src/main/java/com/example/rhizome/app/presentation/form/SearchConditionDepartmentForm.java b/src/main/java/com/example/rhizome/app/presentation/form/SearchConditionDepartmentForm.java new file mode 100644 index 0000000..8bc347e --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/form/SearchConditionDepartmentForm.java @@ -0,0 +1,30 @@ +// 画面から渡ってきた検索条件をまとめ、再度画面に表示する為のクラス +package com.example.rhizome.app.presentation.form; + +import com.example.rhizome.app.domain.model.SearchConditionDepartment; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class SearchConditionDepartmentForm { + + private Integer idDepartment; + + private String nmDepartment; + + public static SearchConditionDepartmentForm convertFrom(SearchConditionDepartment searchConditionDepartment) { + return new SearchConditionDepartmentForm( + searchConditionDepartment.getIdDepartment(), + searchConditionDepartment.getNmDepartment()); + } + + public static SearchConditionDepartment convertTo(SearchConditionDepartmentForm searchConditionDepartmentForm) { + return new SearchConditionDepartment( + searchConditionDepartmentForm.getIdDepartment(), + searchConditionDepartmentForm.getNmDepartment()); + } +} diff --git a/src/main/java/com/example/rhizome/app/presentation/form/UpdateDepartmentInfoForm.java b/src/main/java/com/example/rhizome/app/presentation/form/UpdateDepartmentInfoForm.java new file mode 100644 index 0000000..ec4192d --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/form/UpdateDepartmentInfoForm.java @@ -0,0 +1,54 @@ +//package com.example.rhizome.app.presentation.form; +// +//import java.util.List; +// +//import com.example.rhizome.app.domain.model.Department; +// +//import lombok.AllArgsConstructor; +//import lombok.Data; +//import lombok.NoArgsConstructor; +// +//@Data +//@AllArgsConstructor +//@NoArgsConstructor +//public class UpdateDepartmentInfoForm { +// +// private Integer idDepartment; +// +// private String nmDepartment; +// +// public static UpdateDepartmentInfoForm convertForm(Department department) { +// return new UpdateDepartmentInfoForm( +// department.getIdDepartment(), +// department.getNmDepartment()); +// +// } +// +// public static List convertForm(List departmentList) { +// return departmentList.stream().map(UpdateDepartmentInfoForm::convertFrom).toList(); +// } +// +// public static Department convertTo(UpdateDepartmentInfoForm updateDepartmentInfoForm) { +// return new Department( +// updateDepartmentInfoForm.getIdDepartment(), +// updateDepartmentInfoForm.getNmDepartment()); +// } +// +// public static boolean hasErrorParameter(UpdateDepartmentInfoForm updateDepartmentInfoForm) { +// +// boolean errorFlag = !isNullOrBlank(updateDepartmentInfoForm.getNmDepartment()); +// +// if (!isNullOrBlank(updateDepartmentInfoForm.getNmDepartment())) { +// errorFlag = true; +// } +// +// return errorFlag; +// } +// +// private static boolean isNullOrBlank(String str) { +// if (null == str) { +// return true; +// } +// return str.isBlank(); +// } +//} diff --git a/src/main/resources/templates/insertDepartmentConfilm.html b/src/main/resources/templates/insertDepartmentConfilm.html new file mode 100644 index 0000000..7777def --- /dev/null +++ b/src/main/resources/templates/insertDepartmentConfilm.html @@ -0,0 +1,73 @@ + + + + + + + + + + + 登録内容確認 + + + +

登録内容確認    +
+ ログイン者名: + +
+

+
+ +
+ +
+ + + + + + + + + + + + +
部署ID + +
部署名 + +
+ +
+ 登録内容の編集 | メニューに戻る +
+ + + + \ No newline at end of file diff --git a/src/main/resources/templates/insertDepartmentInput.html b/src/main/resources/templates/insertDepartmentInput.html new file mode 100644 index 0000000..99a3d7b --- /dev/null +++ b/src/main/resources/templates/insertDepartmentInput.html @@ -0,0 +1,56 @@ + + + + + + + + + + + 部署登録 + + + +

+ 部署登録    +
+ ログイン者名: + +
+

+
+ +
+ +
+ + + + + + + + + + + + + +
部署ID + +
部署名 + +
+ +
+ メニューに戻る +
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/menu.html b/src/main/resources/templates/menu.html index 6d0ee4a..03cab3b 100644 --- a/src/main/resources/templates/menu.html +++ b/src/main/resources/templates/menu.html @@ -26,11 +26,19 @@ 社員検索 登録済みのユーザ一覧表示と
更新、削除を行います。 + + 部署検索 + 登録済みの部署一覧表示と
更新、削除を行います。 + + - - - 社員登録 - 新規でユーザ追加を行います。 + + 社員登録 + 新規でユーザ追加を行います。 + + 部署登録 + 新規で部署を追加します。 + diff --git a/src/main/resources/templates/selectDepartment.html b/src/main/resources/templates/selectDepartment.html new file mode 100644 index 0000000..47aa19c --- /dev/null +++ b/src/main/resources/templates/selectDepartment.html @@ -0,0 +1,112 @@ + + + + + + + + + + + 検索 + + + +

+ 検索条件入力    +
+ ログイン者名: + +
+

+
+ +
+ +
+ + + + + + + + + + + + + +
部署ID + + +
部署名 + + +
+ + + + +
+
+
+ メニューに戻る +
+

検索結果

+
+ + + +
+ + + + + + + + + + + + + + + + + + +
部署ID部署名操作
+ +
+ + + +
+ +
+ + +
+
+
+ + + + 検索結果はありません。 + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/updateDepartmentInput.html b/src/main/resources/templates/updateDepartmentInput.html new file mode 100644 index 0000000..1c241dd --- /dev/null +++ b/src/main/resources/templates/updateDepartmentInput.html @@ -0,0 +1,76 @@ + + + + + + + + + + + 部署情報更新 + + + +

+ 部署情報更新    +
+ ログイン者名: + +
+

+
+
+ +
+ + + + + + + + + + + + +
部署ID + +
部署名 + +
+ +
+
+ + + + + \ No newline at end of file