diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/repository/controller/RepositoryController.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/repository/controller/RepositoryController.kt index 090afd4d2e4a81d4e0090deaa60a7eca8ad57e4c..09da2fba1e540c94f8b0a6a999483e2479727379 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/repository/controller/RepositoryController.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/repository/controller/RepositoryController.kt @@ -13,6 +13,8 @@ import de.fraunhofer.iem.dataprovider.repository.service.RepositoryService import de.fraunhofer.iem.dataprovider.toolRun.service.ToolRunService import de.fraunhofer.iem.dataprovider.user.dto.ValidateUserDto import de.fraunhofer.iem.dataprovider.user.service.UserService +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import org.springframework.http.HttpHeaders import org.springframework.http.HttpStatus import org.springframework.http.ResponseCookie @@ -37,7 +39,9 @@ class RepositoryController( @GetMapping(ApiPaths.REPOSITORY) suspend fun getAllRepositories(): List<RepositoryResponseDto> { logger.info("Get all repositories") - return repositoryService.getAllRepositoriesWithConsent() + return withContext(Dispatchers.IO) { + repositoryService.getAllRepositoriesWithConsent() + } .map { repositoryEntity: RepositoryEntity -> RepositoryResponseDto( id = repositoryEntity.id!!, @@ -51,7 +55,9 @@ class RepositoryController( @GetMapping(ApiPaths.REPOSITORY_SCORE_CARD) suspend fun getAllScoreCards(): List<ScoreCardResponseDto> { logger.info("Get all repositories as score cards") - return repositoryService.getAllRepositoriesWithConsent().map { repositoryEntity: RepositoryEntity -> + return withContext(Dispatchers.IO) { + repositoryService.getAllRepositoriesWithConsent() + }.map { repositoryEntity: RepositoryEntity -> val rawKpis = repositoryEntity.getLastToolRun().kpiEntities.map { it.toCalculationDto() } val rootKpi = kpiService.removeKPIChildrenLowerThanSecondLevel( this.kpiService.getKpiTreeForRawKpis(rawKpis).toViewModel() @@ -73,7 +79,9 @@ class RepositoryController( suspend fun getScoreCardByRepositoryId(@PathVariable id: Long): ScoreCardResponseDto { logger.info("Get repository score card with id $id") val repositoryEntity = - repositoryService.findByProjectIdAndVisualizationConsentTrue(id) ?: throw ResponseStatusException( + withContext(Dispatchers.IO) { + repositoryService.findByProjectIdAndVisualizationConsentTrue(id) + } ?: throw ResponseStatusException( HttpStatus.NOT_FOUND, "repository not found" ) @@ -98,7 +106,9 @@ class RepositoryController( suspend fun getRepositoryById(@PathVariable id: Long): RepositoryResponseDto { logger.info("Get repository with id $id") val repositoryEntity = - repositoryService.findByProjectIdAndVisualizationConsentTrue(id) ?: throw ResponseStatusException( + withContext(Dispatchers.IO) { + repositoryService.findByProjectIdAndVisualizationConsentTrue(id) + } ?: throw ResponseStatusException( HttpStatus.NOT_FOUND, "repository not found" ) @@ -117,7 +127,9 @@ class RepositoryController( suspend fun getRawKPIByRepositoryId(@PathVariable id: Long): RawKpiDto { logger.info("Get raw KPIs for repository id $id") val repositoryEntity = - repositoryService.findByProjectIdAndVisualizationConsentTrue(id) ?: throw ResponseStatusException( + withContext(Dispatchers.IO) { + repositoryService.findByProjectIdAndVisualizationConsentTrue(id) + } ?: throw ResponseStatusException( HttpStatus.NOT_FOUND, "repository not found" ) @@ -133,7 +145,9 @@ class RepositoryController( suspend fun getKPIByRepositoryId(@PathVariable id: Long): KPITreeResponseDto { logger.info("Get KPI tree for repository id $id") val repositoryEntity = - repositoryService.findByProjectIdAndVisualizationConsentTrue(id) ?: throw ResponseStatusException( + withContext(Dispatchers.IO) { + repositoryService.findByProjectIdAndVisualizationConsentTrue(id) + } ?: throw ResponseStatusException( HttpStatus.NOT_FOUND, "repository not found" ) @@ -171,7 +185,9 @@ class RepositoryController( @PathVariable id: Long, @RequestBody repositoryConsentDto: RepositoryConsentDto ) { - repositoryService.updateVisualizationConsent(id, repositoryConsentDto) + withContext(Dispatchers.IO) { + repositoryService.updateVisualizationConsent(id, repositoryConsentDto) + } } @PostMapping(ApiPaths.REPOSITORY_VALIDATE_USER) diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/repository/service/RepositoryService.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/repository/service/RepositoryService.kt index 67df98b2bd65a15e0f94927879a20252d5a1e7c4..e5e39e18be146c2679348abd06e61d6f51637873 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/repository/service/RepositoryService.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/repository/service/RepositoryService.kt @@ -82,6 +82,7 @@ class RepositoryService( return openCodeGitlabApi.getRepositoryInfo(projectId) } + @Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW) fun findByProjectIdAndVisualizationConsentTrue(projectId: Long): RepositoryEntity? { return repositoryRepository.findByProjectIdAndVisualizationConsentTrue(projectId) }