| 
					
				 | 
			
			
				@@ -2,6 +2,7 @@ package com.swagger.rest.controllers 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.swagger.rest.models.Platform 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.swagger.rest.models.PlatformInput 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.swagger.rest.models.Project 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.swagger.rest.repositories.PlatformRepository 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.swagger.rest.repositories.ProjectRepository 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.aspectj.asm.internal.ProgramElement.trim 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -18,7 +19,7 @@ class PlatformController( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @GetMapping("/platforms") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    fun getPlatformByProjectId(@RequestParam(required = false) project: String?): ResponseEntity<List<Platform>?> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fun getPlatformByProjectId(@RequestParam(required = false) project: String?): Any? { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             val platforms: List<Platform> = 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (project == null) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -26,9 +27,11 @@ class PlatformController( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     platformRepository.findByProject(project) as List<Platform> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (platforms.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ResponseEntity<List<Platform>?>(HttpStatus.NO_CONTENT) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else ResponseEntity<List<Platform>?>(platforms, HttpStatus.OK) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (platforms.isNotEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ResponseEntity<List<Platform>?>(platforms, HttpStatus.OK) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                arrayOf<String>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } catch (e: Exception) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ResponseEntity<List<Platform>?>(null, HttpStatus.INTERNAL_SERVER_ERROR) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -46,23 +49,23 @@ class PlatformController( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @PostMapping("/platforms") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     fun addPlatformByProjectId( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        @RequestBody platform: Platform, @RequestParam project: String 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        @RequestBody platform: PlatformInput 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ): ResponseEntity<Platform> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            val found = platformRepository.findByName(platform.name, project)!!.size 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            val foundProject = projectRepository.findById(project.toLong()).isPresent 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (platform.name.isNotBlank()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            val found = platformRepository.findByName(platform.name, platform.project_id.toString())!!.size 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            val foundProject = projectRepository.findById(platform.project_id!!.toLong()).isPresent 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (platform.name!!.isNotBlank()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (!foundProject) {//project not found 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ResponseEntity<Platform>(HttpStatus.NOT_FOUND) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } else if (platform.name.length > 100) {//too long 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } else if (platform.name!!.length > 100) {//too long 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ResponseEntity<Platform>(HttpStatus.PAYLOAD_TOO_LARGE) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } else if (found > 0) {//duplicate 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ResponseEntity<Platform>(HttpStatus.CONFLICT) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    platform.project_id = projectRepository.findById(project.toLong()).get() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    platform.name = trim(platform.name) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    val savePlatform: Platform = platformRepository.save(platform) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    ResponseEntity<Platform>(savePlatform, HttpStatus.CREATED) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    val newPlatform = Platform() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    newPlatform.name = trim(platform.name) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    newPlatform.project_id = projectRepository.findById(platform.project_id!!).get() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    ResponseEntity<Platform>(platformRepository.save(newPlatform), HttpStatus.CREATED) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } else {//invalid name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 ResponseEntity<Platform>(HttpStatus.BAD_REQUEST) 
			 |