-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from nenadjakic/improvement/security-config-ent…
…ity-model Security configuration etc.
- Loading branch information
Showing
11 changed files
with
127 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/com/github/nenadjakic/ocr/studio/config/SecurityConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.github.nenadjakic.ocr.studio.config | ||
|
||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
import org.springframework.security.config.annotation.web.builders.HttpSecurity | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity | ||
import org.springframework.security.web.SecurityFilterChain | ||
import org.springframework.web.cors.CorsConfiguration | ||
import org.springframework.web.cors.CorsConfigurationSource | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource | ||
|
||
|
||
@Configuration | ||
@EnableWebSecurity | ||
class SecurityConfig { | ||
|
||
@Bean | ||
fun filterChain(httpSecurity: HttpSecurity): SecurityFilterChain { | ||
httpSecurity.cors { it.configurationSource(corsConfigurationSource()) } | ||
httpSecurity.authorizeHttpRequests { it.anyRequest().permitAll() } | ||
return httpSecurity.build() | ||
} | ||
|
||
fun corsConfigurationSource(): CorsConfigurationSource { | ||
val configuration = CorsConfiguration() | ||
configuration.allowedOrigins = listOf("*") | ||
configuration.allowedMethods = listOf("*") | ||
configuration.allowedHeaders = listOf("*") | ||
val source = UrlBasedCorsConfigurationSource() | ||
source.registerCorsConfiguration("/**", configuration) | ||
return source | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/com/github/nenadjakic/ocr/studio/controller/AnalyticsController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.github.nenadjakic.ocr.studio.controller | ||
|
||
import com.github.nenadjakic.ocr.studio.dto.StatusCount | ||
import com.github.nenadjakic.ocr.studio.service.AnalyticsService | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@Tag(name = "Analytics controller", description = "API endpoints for analytics.") | ||
@RestController | ||
@RequestMapping("/analytics") | ||
class AnalyticsController(private val analyticsService: AnalyticsService) { | ||
|
||
@Operation( | ||
operationId = "getCountByStatus", | ||
summary = "Get count by status.", | ||
description = "Returns count by status information.") | ||
@ApiResponses( | ||
value = [ | ||
ApiResponse(responseCode = "200", description = "Successfully retrieved count by status.") | ||
] | ||
) | ||
@GetMapping(value = ["/count-by-status"], produces = [org.springframework.http.MediaType.APPLICATION_JSON_VALUE]) | ||
fun getCountByStatus(): ResponseEntity<List<StatusCount>> = ResponseEntity.ok(analyticsService.getCountByStatus()) | ||
|
||
@Operation( | ||
operationId = "getAverageInDocuments", | ||
summary = "Get average count across inDocuments.", | ||
description = "Returns average count across inDocuments.") | ||
@ApiResponses( | ||
value = [ | ||
ApiResponse(responseCode = "200", description = "Successfully retrieved average count across inDocuments.") | ||
] | ||
) | ||
@GetMapping(value = ["/average-in-documents"], produces = [org.springframework.http.MediaType.APPLICATION_JSON_VALUE]) | ||
fun getAverageInDocuments(): ResponseEntity<Long> = ResponseEntity.ok(analyticsService.getAverageInDocuments()) | ||
} |
4 changes: 2 additions & 2 deletions
4
src/main/kotlin/com/github/nenadjakic/ocr/studio/dto/SchedulerConfigRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.github.nenadjakic.ocr.studio.dto | ||
|
||
import java.time.ZonedDateTime | ||
import java.time.LocalDateTime | ||
|
||
data class SchedulerConfigRequest(var startDateTime: ZonedDateTime? = null) | ||
data class SchedulerConfigRequest(var startDateTime: LocalDateTime? = null) |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/github/nenadjakic/ocr/studio/dto/StatusCount.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.github.nenadjakic.ocr.studio.dto | ||
|
||
import com.github.nenadjakic.ocr.studio.entity.Status | ||
|
||
data class StatusCount( | ||
val status: Status, | ||
val count: Long | ||
) |
4 changes: 2 additions & 2 deletions
4
src/main/kotlin/com/github/nenadjakic/ocr/studio/entity/SchedulerConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package com.github.nenadjakic.ocr.studio.entity | ||
|
||
import java.time.ZonedDateTime | ||
import java.time.LocalDateTime | ||
|
||
class SchedulerConfig( | ||
var startDateTime: ZonedDateTime? = null | ||
var startDateTime: LocalDateTime? = null | ||
) |
4 changes: 2 additions & 2 deletions
4
src/main/kotlin/com/github/nenadjakic/ocr/studio/executor/Executor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package com.github.nenadjakic.ocr.studio.executor | ||
|
||
import java.time.ZonedDateTime | ||
import java.time.LocalDateTime | ||
import java.util.UUID | ||
|
||
interface Executor : Runnable { | ||
val id: UUID | ||
val startDateTime: ZonedDateTime? | ||
val startDateTime: LocalDateTime? | ||
val progressInfo: ProgressInfo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/github/nenadjakic/ocr/studio/service/AnalyticsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.github.nenadjakic.ocr.studio.service | ||
|
||
import com.github.nenadjakic.ocr.studio.dto.StatusCount | ||
import com.github.nenadjakic.ocr.studio.repository.TaskRepository | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class AnalyticsService( | ||
private val taskRepository: TaskRepository | ||
) { | ||
fun getCountByStatus(): List<StatusCount> = taskRepository.countTasksByStatus() | ||
|
||
fun getAverageInDocuments(): Long = taskRepository.averageInDocuments() | ||
} |