Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler warnings and a minor bug #69

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,46 @@ package fi.hsl.jore4.mapmatching.config

import fi.hsl.jore4.mapmatching.api.MapMatchingController
import fi.hsl.jore4.mapmatching.api.RouteController
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpMethod
import org.springframework.security.config.Customizer.withDefaults
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
import org.springframework.security.config.http.SessionCreationPolicy
import org.springframework.security.web.SecurityFilterChain

@Configuration
@EnableWebSecurity
class WebSecurityConfig : WebSecurityConfigurerAdapter() {
class WebSecurityConfig {

override fun configure(httpSec: HttpSecurity) {
httpSec
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.NEVER)
@Bean
@Throws(Exception::class)
fun configure(httpSecurity: HttpSecurity): SecurityFilterChain {
return httpSecurity
.sessionManagement { it.sessionCreationPolicy(SessionCreationPolicy.NEVER) }

.and()
// CSRF is not needed.
.csrf().disable()

.authorizeRequests()

.antMatchers(HttpMethod.GET,
RouteController.URL_PREFIX + "/**",
"/actuator/health",
"/*" // matches static landing page for examining results from route API
).permitAll()

.antMatchers(HttpMethod.POST,
MapMatchingController.URL_PREFIX + "/**",
RouteController.URL_PREFIX + "/**"
).permitAll()

.anyRequest().denyAll()
/** A CORS mapping is defined in [WebConfig] within "development" Spring profile. */
.cors(withDefaults())

.authorizeHttpRequests {
it
.antMatchers(HttpMethod.GET,
RouteController.URL_PREFIX + "/**",
"/actuator/health",
"/*" // matches static landing page for examining results from route API
).permitAll()

.antMatchers(HttpMethod.POST,
MapMatchingController.URL_PREFIX + "/**",
RouteController.URL_PREFIX + "/**"
).permitAll()

.anyRequest().denyAll()
}
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class RoutingRepositoryImpl @Autowired constructor(val jdbcTemplate: NamedParame

var paramIndex = firstParameterIndex

bufferAreaRestriction?.run {
bufferAreaRestriction.run {
explicitLinkReferences?.run {
idsOfCandidatesForTerminusLinks.forEach {
pstmt.setLong(paramIndex++, it.value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package fi.hsl.jore4.mapmatching.util

object CollectionUtils {
fun <T> filterOutConsecutiveDuplicates(coll: Collection<out T>): List<T> {

fun <T> filterOutConsecutiveDuplicates(coll: Collection<T>): List<T> {
val list = mutableListOf<T>()
var prev: T? = null

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package fi.hsl.jore4.mapmatching.util

import org.springframework.stereotype.Component
import java.lang.annotation.ElementType
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
import java.lang.annotation.Target

/**
* A meta-annotation for Spring's [Component] annotation. Marks a Spring-managed
Expand All @@ -17,7 +13,7 @@ import java.lang.annotation.Target
* methods that open database transactions are enabled to recover from an
* exception thrown from an internal service method.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
@Component
annotation class InternalService()
annotation class InternalService
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ class MultilingualString(@JsonValue val values: Map<String, String?>) {
companion object {
@JsonCreator
@JvmStatic
fun of(mapOrNull: Map<String?, String?>?): MultilingualString {
val mapWithNonNullKeys: Map<String, String?> = mapOrNull?.let { map ->
map.filterKeys { it != null } as Map<String, String?>
} ?: emptyMap()
fun of(mapOrNull: Map<String, String?>?): MultilingualString {
val mapWithNonNullKeys: Map<String, String?> = mapOrNull ?: emptyMap()

return MultilingualString(mapWithNonNullKeys)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package fi.hsl.jore4.mapmatching.test.generators

import fi.hsl.jore4.mapmatching.model.TrafficFlowDirectionType
import fi.hsl.jore4.mapmatching.test.util.Quadruple
import org.quicktheories.core.Gen
import org.quicktheories.generators.Generate
import org.quicktheories.generators.Generate.constant
import org.quicktheories.generators.Generate.enumValues

object CommonGenerators {

Expand All @@ -14,7 +12,7 @@ object CommonGenerators {
fun <T> pair(source: Gen<T>): Gen<Pair<T, T>> = source.zip(source, ::Pair)

// pair of discrete values (non-equal within single generated tuple)
fun <T> discretePair(source: Gen<T>): Gen<Pair<T, T>> {
fun <T : Any> discretePair(source: Gen<T>): Gen<Pair<T, T>> {
return source.flatMap { value1 ->
val getAnotherUniqueValue = Retry(source) { it != value1 }

Expand All @@ -36,7 +34,7 @@ object CommonGenerators {
fun <T> duplicate(source: Gen<T>): Gen<Pair<T, T>> = source.map { value -> value to value }

// triple consisting of three discrete values (unique within single generated tuple)
fun <T> discreteTriple(source: Gen<T>): Gen<Triple<T, T, T>> {
fun <T : Any> discreteTriple(source: Gen<T>): Gen<Triple<T, T, T>> {
return discretePair(source)
.flatMap { (value1, value2) ->
val getAnotherUniqueValue = Retry(source) { it != value1 && it != value2 }
Expand All @@ -46,7 +44,7 @@ object CommonGenerators {
}

// quadruple consisting of four discrete values (unique within single generated tuple)
fun <T> discreteQuadruple(source: Gen<T>): Gen<Quadruple<T, T, T, T>> {
fun <T : Any> discreteQuadruple(source: Gen<T>): Gen<Quadruple<T, T, T, T>> {
return discreteTriple(source)
.flatMap { (value1, value2, value3) ->
val getAnotherUniqueValue = Retry(source) { it != value1 && it != value2 && it != value3 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import java.util.function.Predicate
* The original source code file (https://github.com/quicktheories/QuickTheories/blob/master/core/src/main/java/org/quicktheories/generators/CodePoints.java)
* is licensed by https://github.com/quicktheories/QuickTheories under Apace License V2.0.
*/
class Retry<T>(private val child: Gen<T>, private val assumption: Predicate<T>) : Gen<T> {
class Retry<T : Any>(private val child: Gen<T>, private val assumption: Predicate<T>) : Gen<T> {

override fun generate(randomnessSource: RandomnessSource): T {
// danger of infinite loop if used incorrectly
Expand Down