|
@@ -1,19 +1,19 @@
|
|
|
package com.server.alb.controllers
|
|
|
|
|
|
import com.server.alb.models.*
|
|
|
-import com.server.alb.repositories.ListBugRepository
|
|
|
-import com.server.alb.repositories.PlatformRepository
|
|
|
-import com.server.alb.repositories.ProjectRepository
|
|
|
-import com.server.alb.repositories.UserRepository
|
|
|
+import com.server.alb.repositories.*
|
|
|
import com.server.alb.services.BugService
|
|
|
import com.server.alb.services.BugValidationService.Companion.isValid
|
|
|
-import com.server.alb.services.PlatformService
|
|
|
+import com.server.alb.services.ProjectService
|
|
|
import com.server.alb.services.UserService
|
|
|
import jakarta.servlet.http.HttpServletRequest
|
|
|
+import jakarta.validation.ConstraintViolation
|
|
|
import jakarta.validation.Valid
|
|
|
+import jakarta.validation.Validator
|
|
|
import org.springframework.security.authentication.AnonymousAuthenticationToken
|
|
|
import org.springframework.security.core.Authentication
|
|
|
import org.springframework.security.core.context.SecurityContextHolder
|
|
|
+import org.springframework.security.crypto.password.PasswordEncoder
|
|
|
import org.springframework.stereotype.Controller
|
|
|
import org.springframework.ui.Model
|
|
|
import org.springframework.validation.BindingResult
|
|
@@ -29,53 +29,159 @@ class BugController(
|
|
|
private val listBugRepository: ListBugRepository,
|
|
|
private val projectRepository: ProjectRepository,
|
|
|
private val platformRepository: PlatformRepository,
|
|
|
- private val service: BugService,
|
|
|
- private val serUser: UserService,
|
|
|
- private val serPlatform: PlatformService
|
|
|
+ private val roleRepository: RoleRepository,
|
|
|
+ private val bugService: BugService,
|
|
|
+ private val userService: UserService,
|
|
|
+ private val projectService: ProjectService,
|
|
|
+ private val passwordEncoder: PasswordEncoder,
|
|
|
+ private val validator: Validator
|
|
|
) {
|
|
|
val qcResultType = Status.QCResultType.values()
|
|
|
val worList = Status.WorkedType.values()
|
|
|
val wStList = Status.WorkedStatusType.values()
|
|
|
val dStList = Status.DevStatusType.values()
|
|
|
- val project: MutableIterable<Project> = this.projectRepository.findAll()
|
|
|
- var proj1: String = "1"
|
|
|
- var platform: MutableIterable<Platform> = this.platformRepository.findAll()
|
|
|
- val user: MutableIterable<User> = this.userRepository.findAll()
|
|
|
+
|
|
|
+ private fun getProject(): MutableList<Project> {
|
|
|
+ return this.projectRepository.findAll()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getPlatform(): MutableList<Platform> {
|
|
|
+ return this.platformRepository.findAll()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getUser(): MutableList<User> {
|
|
|
+ return this.userRepository.findAll()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getRole(): MutableList<Role> {
|
|
|
+ return this.roleRepository.findAll()
|
|
|
+ }
|
|
|
|
|
|
@GetMapping(value = ["/login"])
|
|
|
fun showLoginForm(model: Model): String {
|
|
|
val authentication: Authentication? = SecurityContextHolder.getContext().authentication
|
|
|
return if (authentication == null || authentication is AnonymousAuthenticationToken) {
|
|
|
"login"
|
|
|
- } else "redirect:/inPro"
|
|
|
+ } else "redirect:/proj"
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping(value = ["/reg"])
|
|
|
+ fun showRegister(model: Model): String {
|
|
|
+ val userRole = UserRole()
|
|
|
+ model.addAttribute("userRole", userRole)
|
|
|
+ model.addAttribute("role", getRole())
|
|
|
+ //println(1)
|
|
|
+ return "reg"
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = ["/"])
|
|
|
- fun viewHomePage(model: Model, pForm: String? = "", programmer: String? = "", proj: String? = proj1): String {
|
|
|
- val listBugs = this.listBugRepository.done(pForm ?: "", programmer ?: "", proj ?: proj1).sortedBy { it.date }
|
|
|
+ @PostMapping(value = ["/reg"])
|
|
|
+ fun saveRegister(
|
|
|
+ @Valid @ModelAttribute("userRole") userRole: UserRole, model: Model, bindingResult: BindingResult,
|
|
|
+ redirectAttributes: RedirectAttributes,
|
|
|
+ ): String {//println(2)
|
|
|
+ //todo validasi user kosong
|
|
|
+ val newUser = User()
|
|
|
+ newUser.username = userRole.username
|
|
|
+ newUser.password = passwordEncoder.encode(userRole.password)
|
|
|
+ newUser.roles = userRole.role
|
|
|
+ newUser.isEnabled = true
|
|
|
+ println(newUser)
|
|
|
+ val result: Set<ConstraintViolation<UserRole>> = validator.validate(userRole)
|
|
|
+ return if (result.isNotEmpty()) {
|
|
|
+ model.addAttribute("role", getRole())
|
|
|
+ "reg"
|
|
|
+ } else {
|
|
|
+ userRepository.save(newUser)
|
|
|
+ redirectAttributes.addFlashAttribute("successMessage", "Success save user")
|
|
|
+ return "redirect:/login"
|
|
|
+ }
|
|
|
+// return if (bindingResult.hasErrors()) {
|
|
|
+// model.addAttribute("role", getRole())
|
|
|
+// "reg"
|
|
|
+// } else {
|
|
|
+// userRepository.save(newUser)
|
|
|
+// redirectAttributes.addFlashAttribute("successMessage", "Success save User")
|
|
|
+// "redirect:/login"
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = ["/userList"])
|
|
|
+ fun viewUser(model: Model): String {
|
|
|
+ model.addAttribute("user", getUser())
|
|
|
+ return "userList"
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = ["/proj"])
|
|
|
+ fun viewProject(model: Model): String {
|
|
|
+ model.addAttribute("project", getProject())
|
|
|
+ return "projList"
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping(value = ["/projNew"])
|
|
|
+ fun addProject(model: Model): String {
|
|
|
+ val project = Project()
|
|
|
model.addAttribute("project", project)
|
|
|
- model.addAttribute("platform", platform)
|
|
|
- model.addAttribute("user", user)
|
|
|
+ return "add_proj"
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping(value = ["/projNew"])
|
|
|
+ fun saveProject(
|
|
|
+ @Valid @ModelAttribute("project") project: Project, model: Model, bindingResult: BindingResult,
|
|
|
+ redirectAttributes: RedirectAttributes,
|
|
|
+ ): String {
|
|
|
+ //todo validasi save project
|
|
|
+ println(bindingResult)
|
|
|
+ return if (bindingResult.hasErrors()) {
|
|
|
+ model.addAttribute("project", project)
|
|
|
+ println(project)
|
|
|
+ "add_proj"
|
|
|
+ } else {
|
|
|
+ projectRepository.save(project)
|
|
|
+ redirectAttributes.addFlashAttribute("successMessage", "Success save project")
|
|
|
+ return "redirect:/proj"
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = ["/index/{proj}"])
|
|
|
+ fun viewHomePage(
|
|
|
+ model: Model,
|
|
|
+ pForm: String? = "",
|
|
|
+ programmer: String? = "",
|
|
|
+ @PathVariable(name = "proj") proj: String,
|
|
|
+ request: HttpServletRequest
|
|
|
+ ): String {
|
|
|
+ val listBugs = this.listBugRepository.done(pForm ?: "", programmer ?: "", proj).sortedBy { it.date }
|
|
|
+ val url = request.requestURL.split("/")
|
|
|
+ model.addAttribute("project", url.last())
|
|
|
+ model.addAttribute("platform", getPlatform())
|
|
|
+ model.addAttribute("user", getUser())
|
|
|
model.addAttribute("listBugs", listBugs)
|
|
|
return "index"
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = ["/inPro"])
|
|
|
- fun viewInProgress(model: Model, pForm: String? = "", programmer: String? = "", proj: String? = proj1): String {
|
|
|
- val listBugs = this.listBugRepository.inPro(pForm ?: "", programmer ?: "", proj ?: proj1).sortedBy { it.date }
|
|
|
- model.addAttribute("project", project)
|
|
|
- model.addAttribute("platform", platform)
|
|
|
- model.addAttribute("user", user)
|
|
|
+ @RequestMapping(value = ["/inPro/{proj}"])
|
|
|
+ fun viewInProgress(
|
|
|
+ model: Model,
|
|
|
+ pForm: String? = "",
|
|
|
+ programmer: String? = "",
|
|
|
+ @PathVariable(name = "proj") proj: String,
|
|
|
+ request: HttpServletRequest
|
|
|
+ ): String {
|
|
|
+ val listBugs = this.listBugRepository.inPro(pForm ?: "", programmer ?: "", proj).sortedBy { it.date }
|
|
|
+ val url = request.requestURL.split("/")
|
|
|
+ model.addAttribute("project", url.last())
|
|
|
+ model.addAttribute("platform", getPlatform())
|
|
|
+ model.addAttribute("user", getUser())
|
|
|
model.addAttribute("listBugs", listBugs)
|
|
|
return "inPro"
|
|
|
}
|
|
|
|
|
|
@GetMapping(value = ["/new"])
|
|
|
- fun showNewBugForm(model: Model, proj: String? = proj1): String {
|
|
|
+ fun showNewBugForm(model: Model): String {
|
|
|
val bug = ListBug()
|
|
|
model.addAttribute("bug", bug)
|
|
|
- model.addAttribute("user", user)
|
|
|
- model.addAttribute("platform", platform)
|
|
|
+ model.addAttribute("user", getUser())
|
|
|
+ model.addAttribute("platform", getPlatform())
|
|
|
model.addAttribute("qcResultType", qcResultType)
|
|
|
return "add_bug"
|
|
|
}
|
|
@@ -85,8 +191,7 @@ class BugController(
|
|
|
@Valid @ModelAttribute("bug") bug: ListBug,
|
|
|
bindingResult: BindingResult,
|
|
|
redirectAttributes: RedirectAttributes,
|
|
|
- model: Model,
|
|
|
- proj: String? = proj1
|
|
|
+ model: Model
|
|
|
): String {
|
|
|
if (bug.qcId == null) {
|
|
|
val myUserDetails = SecurityContextHolder.getContext().authentication.name
|
|
@@ -96,15 +201,17 @@ class BugController(
|
|
|
}
|
|
|
}
|
|
|
println(bug)
|
|
|
+ println(bindingResult)
|
|
|
return if (bindingResult.hasErrors()) {
|
|
|
- model.addAttribute("user", user)
|
|
|
- model.addAttribute("platform", platform)
|
|
|
+ model.addAttribute("user", getUser())
|
|
|
+ model.addAttribute("platform", getPlatform())
|
|
|
model.addAttribute("qcResultType", qcResultType)
|
|
|
"add_bug"
|
|
|
} else {
|
|
|
- service.save(bug)
|
|
|
+ bugService.save(bug)
|
|
|
+ val project = this.projectRepository.findProjectById(bug.id.toString())
|
|
|
redirectAttributes.addFlashAttribute("successMessage", "Success save bug")
|
|
|
- "redirect:/inPro"
|
|
|
+ "redirect:/inPro/$project"
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -113,9 +220,10 @@ class BugController(
|
|
|
@Valid @ModelAttribute("bug") bug: ListBug,
|
|
|
redirectAttributes: RedirectAttributes,
|
|
|
result: BindingResult,
|
|
|
- request: HttpServletRequest
|
|
|
+ request: HttpServletRequest,
|
|
|
): String {
|
|
|
val referer: String = request.getHeader("Referer")
|
|
|
+ val url = referer.split("=")
|
|
|
if (bug.qcId == null) {
|
|
|
val myUserDetails = SecurityContextHolder.getContext().authentication.name
|
|
|
val userLogin = userRepository.findByUsername(myUserDetails)
|
|
@@ -124,25 +232,46 @@ class BugController(
|
|
|
}
|
|
|
}
|
|
|
val successMessage: String = if (isValid(bug)) {
|
|
|
- service.save(bug)
|
|
|
+ bugService.save(bug)
|
|
|
"Success save bug"
|
|
|
} else {
|
|
|
"Failed ! Please try again"
|
|
|
}
|
|
|
redirectAttributes.addFlashAttribute("successMessage", successMessage)
|
|
|
- return if (referer.endsWith("=index")) "redirect:/" else "redirect:/inPro"
|
|
|
+ return if (referer.endsWith("=index")) "redirect:/" + url.last() else "redirect:/" + url.last()
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = ["/saveUser"], method = [RequestMethod.POST])
|
|
|
+ fun saveUserEdit(@Valid @ModelAttribute("userRole") userRole: UserRole): String {
|
|
|
+ val existUser = userService[userRole.id]
|
|
|
+ val editUser = User()
|
|
|
+ editUser.id = userRole.id
|
|
|
+ editUser.username = userRole.username
|
|
|
+ editUser.password = passwordEncoder.encode(userRole.password)
|
|
|
+ editUser.roles = userRole.role
|
|
|
+ editUser.isEnabled = true
|
|
|
+ if (userService.checkIfValidOldPassword(userRole.oldPass, existUser.password)) {
|
|
|
+ userService.save(editUser)
|
|
|
+ }
|
|
|
+ return "redirect:/userList"
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = ["/saveProj"], method = [RequestMethod.POST])
|
|
|
+ fun saveProjEdit(@Valid @ModelAttribute("project") project: Project): String {
|
|
|
+ projectService.save(project)
|
|
|
+ return "redirect:/proj"
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/edit/{id}")
|
|
|
- fun showEditBugForm(@PathVariable(name = "id") id: Long, @RequestParam page: String): ModelAndView {
|
|
|
+ fun showEditBugForm(
|
|
|
+ @PathVariable(name = "id") id: Long,
|
|
|
+ @RequestParam page: String,
|
|
|
+ ): ModelAndView {
|
|
|
val mav = ModelAndView("edit_bug")
|
|
|
- val bug: ListBug = service[id]
|
|
|
- val userQc: User = serUser[bug.qcId?.id]
|
|
|
- val userPro: User = serUser[bug.proId?.id]
|
|
|
- val plat: Platform = serPlatform[bug.platform!!.id]
|
|
|
- mav.addObject("listQc", userQc)
|
|
|
- mav.addObject("listPro", userPro)
|
|
|
- mav.addObject("platform", plat)
|
|
|
+ val bug: ListBug = bugService[id]
|
|
|
+ mav.addObject("listQc", getUser())
|
|
|
+ mav.addObject("listPro", getUser())
|
|
|
+ mav.addObject("platform", getPlatform())
|
|
|
mav.addObject("bug", bug)
|
|
|
mav.addObject("worList", worList)
|
|
|
mav.addObject("wStList", wStList)
|
|
@@ -151,18 +280,61 @@ class BugController(
|
|
|
return mav
|
|
|
}
|
|
|
|
|
|
+ @RequestMapping("/userList/edit/{id}")
|
|
|
+ fun editUser(@PathVariable(name = "id") id: Long): ModelAndView {
|
|
|
+ val mav = ModelAndView("edit_user")
|
|
|
+ val user: User = userService[id]
|
|
|
+ val userRole = UserRole()
|
|
|
+ userRole.id = user.id
|
|
|
+ userRole.username = user.username
|
|
|
+ userRole.password = user.password
|
|
|
+ userRole.role = user.roles
|
|
|
+ mav.addObject("userRole", userRole)
|
|
|
+ mav.addObject("role", getRole())
|
|
|
+ return mav
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/proj/edit/{id}")
|
|
|
+ fun editProject(@PathVariable(name = "id") id: Long): ModelAndView {
|
|
|
+ val mav = ModelAndView("edit_proj")
|
|
|
+ val project: Project = projectService[id]
|
|
|
+ mav.addObject("project", project)
|
|
|
+ return mav
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/userList/delete/{id}")
|
|
|
+ fun deleteUser(@PathVariable(name = "id") id: Long): String {
|
|
|
+ val user = userService[id]
|
|
|
+ userService.delete(user)
|
|
|
+ return "redirect:/userList"
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/proj/delete/{id}")
|
|
|
+ fun deleteProj(@PathVariable(name = "id") id: Long): String {
|
|
|
+ projectService[id]
|
|
|
+ projectService.delete(id)
|
|
|
+ return "redirect:/proj"
|
|
|
+ }
|
|
|
+
|
|
|
@RequestMapping("/delete/{id}")
|
|
|
fun deleteBug(@PathVariable(name = "id") id: Long): String {
|
|
|
- service[id]
|
|
|
- service.delete(id)
|
|
|
- return "redirect:/"
|
|
|
+ val project = this.projectRepository.findProjectById(id.toString())
|
|
|
+ bugService[id]
|
|
|
+ bugService.delete(id)
|
|
|
+ return "redirect:/index/$project"
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/delete2/{id}")
|
|
|
fun delete2Bug(@PathVariable(name = "id") id: Long): String {
|
|
|
- service[id]
|
|
|
- service.delete(id)
|
|
|
- return "redirect:/inPro"
|
|
|
+ val project = this.projectRepository.findProjectById(id.toString())
|
|
|
+ bugService[id]
|
|
|
+ bugService.delete(id)
|
|
|
+ return "redirect:/inPro/$project"
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping("/")
|
|
|
+ fun redirect(): String {
|
|
|
+ return "redirect:/proj"
|
|
|
}
|
|
|
|
|
|
}
|