From 138deffc719af6da17dd44216491a063afd43eee Mon Sep 17 00:00:00 2001 From: Jan-Niclas Struewer <j.n.struewer@gmail.com> Date: Tue, 24 Oct 2023 16:28:50 +0200 Subject: [PATCH] Added new tool endpoint for easier debugging --- .../iem/dataprovider/configuration/ApiPaths.kt | 2 ++ .../security/WebSecurityConfiguration.kt | 2 +- .../tool/controller/ToolController.kt | 16 ++++++++++++++++ .../tool/dto/ToolEntityResponseDto.kt | 5 +++++ .../iem/dataprovider/tool/entity/ToolEntity.kt | 5 +++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/de/fraunhofer/iem/dataprovider/tool/controller/ToolController.kt create mode 100644 src/main/kotlin/de/fraunhofer/iem/dataprovider/tool/dto/ToolEntityResponseDto.kt diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/configuration/ApiPaths.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/configuration/ApiPaths.kt index 7d28d954..6e9f2403 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/configuration/ApiPaths.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/configuration/ApiPaths.kt @@ -14,6 +14,8 @@ object ApiPaths { const val RAW_KPI_BY_REPOSITORY_ID = "$BASE/repository/{id}/rawkpi" const val KPI_BY_REPOSITORY_ID = "$BASE/repository/{id}/kpi" + const val GET_ALL_TOOLS = "$BASE/tools" + const val REPOSITORY_ID = "$REPOSITORY/{id}" const val REPOSITORY_TOOLS = "$REPOSITORY/{id}/tools" } diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/configuration/security/WebSecurityConfiguration.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/configuration/security/WebSecurityConfiguration.kt index 72027ec2..68673951 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/configuration/security/WebSecurityConfiguration.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/configuration/security/WebSecurityConfiguration.kt @@ -17,7 +17,6 @@ import org.springframework.web.cors.CorsConfiguration import org.springframework.web.cors.reactive.CorsWebFilter import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource - const val ADMIN_ROLE: String = "ADMIN" @Configuration @@ -67,6 +66,7 @@ class SecurityConfiguration(val apiKeyFilter: ApiKeyFilter, private val security addFilterAt(apiKeyFilter, SecurityWebFiltersOrder.FIRST) authorizeExchange { authorize(ApiPaths.ACTUATOR, permitAll) + authorize(ApiPaths.GET_ALL_TOOLS, hasRole(ADMIN_ROLE)) authorize(ApiPaths.REPOSITORY, permitAll) authorize(ApiPaths.REPOSITORY_ID, permitAll) authorize(ApiPaths.REPOSITORY_SCORE_CARD, permitAll) diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/tool/controller/ToolController.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/tool/controller/ToolController.kt new file mode 100644 index 00000000..806527c8 --- /dev/null +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/tool/controller/ToolController.kt @@ -0,0 +1,16 @@ +package de.fraunhofer.iem.dataprovider.tool.controller + +import de.fraunhofer.iem.dataprovider.configuration.ApiPaths +import de.fraunhofer.iem.dataprovider.tool.dto.ToolEntityResponseDto +import de.fraunhofer.iem.dataprovider.tool.repository.ToolRepository +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +class ToolController(val toolRepository: ToolRepository) { + + @GetMapping(ApiPaths.GET_ALL_TOOLS) + fun getAllTools(): List<ToolEntityResponseDto> { + return toolRepository.findAll().map { it.toDto() } + } +} diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/tool/dto/ToolEntityResponseDto.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/tool/dto/ToolEntityResponseDto.kt new file mode 100644 index 00000000..4d9e4d14 --- /dev/null +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/tool/dto/ToolEntityResponseDto.kt @@ -0,0 +1,5 @@ +package de.fraunhofer.iem.dataprovider.tool.dto + +import java.util.* + +data class ToolEntityResponseDto(val id: UUID, val name: String, val toolType: String) diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/tool/entity/ToolEntity.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/tool/entity/ToolEntity.kt index e6bf25d1..ac6008cd 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/tool/entity/ToolEntity.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/tool/entity/ToolEntity.kt @@ -1,5 +1,6 @@ package de.fraunhofer.iem.dataprovider.tool.entity +import de.fraunhofer.iem.dataprovider.tool.dto.ToolEntityResponseDto import de.fraunhofer.iem.dataprovider.tool.enumeration.ToolType import jakarta.persistence.* import org.hibernate.Hibernate @@ -20,6 +21,10 @@ class ToolEntity( var toolType: ToolType, ) { + fun toDto(): ToolEntityResponseDto { + return ToolEntityResponseDto(this.id!!, this.name, this.toolType.getName()) + } + override fun equals(other: Any?): Boolean { if (this === other) return true if (other == null || Hibernate.getClass(this) != Hibernate.getClass(other)) return false -- GitLab