|  | @@ -3,6 +3,7 @@ package com.swagger.rest.controllers
 | 
	
		
			
				|  |  |  import com.swagger.rest.models.*
 | 
	
		
			
				|  |  |  import com.swagger.rest.models.Enum
 | 
	
		
			
				|  |  |  import com.swagger.rest.repositories.*
 | 
	
		
			
				|  |  | +import com.swagger.rest.services.BugService
 | 
	
		
			
				|  |  |  import jakarta.persistence.criteria.Predicate
 | 
	
		
			
				|  |  |  import org.springframework.data.domain.PageRequest
 | 
	
		
			
				|  |  |  import org.springframework.data.domain.Pageable
 | 
	
	
		
			
				|  | @@ -14,7 +15,6 @@ import org.springframework.security.core.context.SecurityContextHolder
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.*
 | 
	
		
			
				|  |  |  import java.text.SimpleDateFormat
 | 
	
		
			
				|  |  |  import java.util.*
 | 
	
		
			
				|  |  | -import java.util.regex.Pattern
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @RestController
 | 
	
		
			
				|  |  |  @RequestMapping("/api/v1")
 | 
	
	
		
			
				|  | @@ -23,27 +23,10 @@ class BugController(
 | 
	
		
			
				|  |  |      private val userRepository: UserRepository,
 | 
	
		
			
				|  |  |      private val platformRepository: PlatformRepository,
 | 
	
		
			
				|  |  |      private val commentRepository: CommentRepository,
 | 
	
		
			
				|  |  | -    private val memberRepository: MemberRepository
 | 
	
		
			
				|  |  | +    private val memberRepository: MemberRepository,
 | 
	
		
			
				|  |  | +    private val bugService: BugService
 | 
	
		
			
				|  |  |  ) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private fun regex(input: String): Boolean {
 | 
	
		
			
				|  |  | -//      "(http:\\/\\/|https:\\/\\/)?(www.)?([a-zA-Z0-9]+).[a-zA-Z0-9]*.[a-z]{3}.?([a-z]+)?"
 | 
	
		
			
				|  |  | -//      "^(http:\\/\\/|https:\\/\\/)?(www.)?([a-zA-Z0-9]+).[a-zA-Z0-9]*.[a-z]{3}.?([a-z]+)?\$"
 | 
	
		
			
				|  |  | -//      "(https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z0-9]{2,}(\.[a-zA-Z0-9]{2,})(\.[a-zA-Z0-9]{2,})?"
 | 
	
		
			
				|  |  | -//      "(https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z0-9]{2,}(\.[a-zA-Z0-9]{2,})(\.[a-zA-Z0-9]{2,})?\/[a-zA-Z0-9]{2,}"
 | 
	
		
			
				|  |  | -//      "(https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}(\.[a-zA-Z0-9]{2,})?"
 | 
	
		
			
				|  |  | -//      "(https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?\/[a-zA-Z0-9]{2,}|((https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z]{2,}(\.[a-zA-Z]{2,})(\.[a-zA-Z]{2,})?)|(https:\/\/www\.|http:\/\/www\.|https:\/\/|http:\/\/)?[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}\.[a-zA-Z0-9]{2,}(\.[a-zA-Z0-9]{2,})?"
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        val regex = "(http://|https://)?(www.)?([a-zA-Z0-9]+).[a-zA-Z0-9]*.[a-z]{3}.?([a-z]+)?"
 | 
	
		
			
				|  |  | -        val pattern = Pattern.compile(regex, Pattern.MULTILINE)
 | 
	
		
			
				|  |  | -        val matcher = pattern.matcher(input)
 | 
	
		
			
				|  |  | -        var ret = false
 | 
	
		
			
				|  |  | -        while (matcher.find()) {
 | 
	
		
			
				|  |  | -            ret = true
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        return ret
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      private fun getSortDirection(direction: String): Sort.Direction {
 | 
	
		
			
				|  |  |          if (direction == "asc") {
 | 
	
		
			
				|  |  |              return Sort.Direction.ASC
 | 
	
	
		
			
				|  | @@ -311,76 +294,30 @@ class BugController(
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @PostMapping("/bugs")
 | 
	
		
			
				|  |  | -    fun addBug(@RequestBody bugInput: BugInput): Any {
 | 
	
		
			
				|  |  | -        return try {
 | 
	
		
			
				|  |  | -            val specBug = Specification<Bug> { root, _, builder ->
 | 
	
		
			
				|  |  | -                val list: MutableList<Predicate> = mutableListOf()
 | 
	
		
			
				|  |  | -                list.add(builder.equal(root.get<Bug>("description"), bugInput.description.trim()))
 | 
	
		
			
				|  |  | -                builder.and(*list.toTypedArray())
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            val found = bugRepository.count(specBug)
 | 
	
		
			
				|  |  | -            val userId = userRepository.getUserByUsername(SecurityContextHolder.getContext().authentication.name)
 | 
	
		
			
				|  |  | -            val countPlat = platformRepository.findPlatform2(userId.id.toString(), bugInput.platform)
 | 
	
		
			
				|  |  | -            val countQc = memberRepository.validRoleByPlatform(bugInput.qc.toString(), bugInput.platform, 0.toString())
 | 
	
		
			
				|  |  | -            val countDev = memberRepository.validRoleByPlatform(bugInput.dev.toString(), bugInput.platform, 1.toString())
 | 
	
		
			
				|  |  | -            if (!enumValues<Enum.Level>().any {
 | 
	
		
			
				|  |  | -                    it.name == bugInput.level.uppercase()
 | 
	
		
			
				|  |  | -                } || !enumValues<Enum.Status>().any {
 | 
	
		
			
				|  |  | -                    it.name == bugInput.status.uppercase()
 | 
	
		
			
				|  |  | -                } || !enumValues<Enum.Dev_Status>().any { it.name == bugInput.dev_status.uppercase() }) {
 | 
	
		
			
				|  |  | -                ResponseEntity(HttpStatus.BAD_REQUEST)
 | 
	
		
			
				|  |  | -            } else if (!regex(bugInput.goodday_url.trim()) || (bugInput.image_url.isNotEmpty() && !regex(bugInput.image_url.trim()))) {
 | 
	
		
			
				|  |  | -                ResponseEntity(HttpStatus.BAD_REQUEST)
 | 
	
		
			
				|  |  | -            } else if (countPlat == 0) {
 | 
	
		
			
				|  |  | -                ResponseEntity(HttpStatus.NOT_FOUND)
 | 
	
		
			
				|  |  | -            } else if (countQc == 0 || countDev == 0) {
 | 
	
		
			
				|  |  | -                ResponseEntity(HttpStatus.FORBIDDEN)
 | 
	
		
			
				|  |  | -            } else if (bugInput.description.isNotBlank()) {
 | 
	
		
			
				|  |  | -                val foundPlat = platformRepository.findPlatform(userId.id.toString(), bugInput.platform)
 | 
	
		
			
				|  |  | -                val qc = userRepository.findById(bugInput.qc).get()
 | 
	
		
			
				|  |  | -                val dev = userRepository.findById(bugInput.dev).get()
 | 
	
		
			
				|  |  | -                if (bugInput.description.length > 500) {//too long
 | 
	
		
			
				|  |  | -                    ResponseEntity(HttpStatus.PAYLOAD_TOO_LARGE)
 | 
	
		
			
				|  |  | -                } else if (found > 0) {//duplicate
 | 
	
		
			
				|  |  | -                    ResponseEntity(HttpStatus.CONFLICT)
 | 
	
		
			
				|  |  | -                } else {
 | 
	
		
			
				|  |  | -                    val saveBug = Bug()
 | 
	
		
			
				|  |  | -                    saveBug.created = Date()
 | 
	
		
			
				|  |  | -                    saveBug.description = bugInput.description.trim()
 | 
	
		
			
				|  |  | -                    saveBug.qc = qc
 | 
	
		
			
				|  |  | -                    saveBug.dev = dev
 | 
	
		
			
				|  |  | -                    saveBug.platform = foundPlat
 | 
	
		
			
				|  |  | -                    saveBug.goodday_url = bugInput.goodday_url.trim()
 | 
	
		
			
				|  |  | -                    saveBug.image_url = bugInput.image_url.trim()
 | 
	
		
			
				|  |  | -                    saveBug.level = Enum.Level.valueOf(bugInput.level.uppercase()).ordinal
 | 
	
		
			
				|  |  | -                    saveBug.status = Enum.Status.valueOf(bugInput.status.uppercase()).ordinal
 | 
	
		
			
				|  |  | -                    saveBug.dev_status = Enum.Dev_Status.valueOf(bugInput.dev_status.uppercase()).ordinal
 | 
	
		
			
				|  |  | -                    val save = bugRepository.save(saveBug)
 | 
	
		
			
				|  |  | -                    if (listOf(save).isNotEmpty()) {
 | 
	
		
			
				|  |  | -                        val output = BugOutput(
 | 
	
		
			
				|  |  | -                            id = save.id,
 | 
	
		
			
				|  |  | -                            created = SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(save.created),
 | 
	
		
			
				|  |  | -                            description = save.description,
 | 
	
		
			
				|  |  | -                            qc = save.qc!!.name,
 | 
	
		
			
				|  |  | -                            dev = save.dev!!.name,
 | 
	
		
			
				|  |  | -                            platform = save.platform!!.name,
 | 
	
		
			
				|  |  | -                            goodday_url = save.goodday_url,
 | 
	
		
			
				|  |  | -                            image_url = save.image_url,
 | 
	
		
			
				|  |  | -                            level = Enum.Level.values()[save.level].name,
 | 
	
		
			
				|  |  | -                            status = Enum.Status.values()[save.status].name,
 | 
	
		
			
				|  |  | -                            dev_status = Enum.Dev_Status.values()[save.dev_status].name
 | 
	
		
			
				|  |  | -                        )
 | 
	
		
			
				|  |  | -                        ResponseEntity(output, HttpStatus.CREATED)
 | 
	
		
			
				|  |  | -                    } else {
 | 
	
		
			
				|  |  | -                        ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR)
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            } else {//invalid
 | 
	
		
			
				|  |  | -                ResponseEntity(HttpStatus.BAD_REQUEST)
 | 
	
		
			
				|  |  | +    fun addBug(@RequestBody bugInput: BugInput): ResponseEntity<Any> {
 | 
	
		
			
				|  |  | +        val validate = bugService.validate(bugInput)
 | 
	
		
			
				|  |  | +        return if (validate !== HttpStatus.OK) {
 | 
	
		
			
				|  |  | +            ResponseEntity(validate!!)
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            val saveBug = bugService.saveBug(bugInput)
 | 
	
		
			
				|  |  | +            if (listOf(saveBug).isNotEmpty()) {
 | 
	
		
			
				|  |  | +                val output = BugOutput(
 | 
	
		
			
				|  |  | +                    id = saveBug!!.id,
 | 
	
		
			
				|  |  | +                    created = SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(saveBug.created),
 | 
	
		
			
				|  |  | +                    description = saveBug.description,
 | 
	
		
			
				|  |  | +                    qc = saveBug.qc!!.name,
 | 
	
		
			
				|  |  | +                    dev = saveBug.dev!!.name,
 | 
	
		
			
				|  |  | +                    platform = saveBug.platform!!.name,
 | 
	
		
			
				|  |  | +                    goodday_url = saveBug.goodday_url,
 | 
	
		
			
				|  |  | +                    image_url = saveBug.image_url,
 | 
	
		
			
				|  |  | +                    level = Enum.Level.values()[saveBug.level].name,
 | 
	
		
			
				|  |  | +                    status = Enum.Status.values()[saveBug.status].name,
 | 
	
		
			
				|  |  | +                    dev_status = Enum.Dev_Status.values()[saveBug.dev_status].name
 | 
	
		
			
				|  |  | +                )
 | 
	
		
			
				|  |  | +                ResponseEntity(output, HttpStatus.CREATED)
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR)
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -        } catch (e: Exception) {
 | 
	
		
			
				|  |  | -            e.printStackTrace()
 | 
	
		
			
				|  |  | -            ResponseEntity(e, HttpStatus.INTERNAL_SERVER_ERROR)
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -433,7 +370,10 @@ class BugController(
 | 
	
		
			
				|  |  |              ret = true
 | 
	
		
			
				|  |  |          } else if (validAdmin > 0 || validOwner > 0) {
 | 
	
		
			
				|  |  |              ret = true
 | 
	
		
			
				|  |  | -        } else if (validQc > 0 && !col.contains(1) && !col.contains(2) && !col.contains(3) && !col.contains(4)&& !col.contains(5)&& !col.contains(9)) {
 | 
	
		
			
				|  |  | +        } else if (validQc > 0 && !col.contains(1) && !col.contains(2) && !col.contains(3) && !col.contains(4) && !col.contains(
 | 
	
		
			
				|  |  | +                5
 | 
	
		
			
				|  |  | +            ) && !col.contains(9)
 | 
	
		
			
				|  |  | +        ) {
 | 
	
		
			
				|  |  |              ret = true
 | 
	
		
			
				|  |  |          } else if (validPro > 0 && col.contains(9) && col.count() == 1) {
 | 
	
		
			
				|  |  |              ret = true
 |