Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dprzybyl committed Sep 24, 2023
1 parent baf922f commit 10cc3b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package com.cognifide.apm.core.endpoints.params

import com.cognifide.apm.core.Property
import com.google.common.primitives.Ints
import org.apache.commons.lang3.StringUtils
import org.apache.sling.api.SlingHttpServletRequest
import org.apache.sling.models.spi.DisposalCallbackRegistry
Expand Down Expand Up @@ -69,7 +68,7 @@ class RequestParameterInjector : Injector, StaticInjectAnnotationProcessorFactor
val parameterValue = request.getRequestParameter(fieldName) ?: return null
return when {
annotatedElement.isAnnotationPresent(FileName::class.java) -> parameterValue.fileName
fieldClass.name in listOf("java.lang.Integer", "int") -> Ints.tryParse(parameterValue.string)
fieldClass.name in listOf("java.lang.Integer", "int") -> parameterValue.string.toIntOrNull()
fieldClass.name in listOf("java.lang.Boolean", "boolean") -> "true" == parameterValue.string
fieldClass == InputStream::class.java -> parameterValue.inputStream
fieldClass == LocalDateTime::class.java -> toLocalDateTime(annotatedElement, parameterValue)
Expand Down Expand Up @@ -106,6 +105,7 @@ class RequestParameterInjector : Injector, StaticInjectAnnotationProcessorFactor
return annotation.value
}

@Deprecated("")
override fun isOptional(): Boolean {
return annotation.optional
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.cognifide.apm.core.grammar.common.getIdentifier
import com.cognifide.apm.core.grammar.common.getKey
import com.cognifide.apm.core.grammar.common.getPath
import com.cognifide.apm.core.grammar.executioncontext.VariableHolder
import com.google.common.primitives.Ints
import org.apache.commons.lang.text.StrSubstitutor
import org.apache.commons.lang3.StringUtils

Expand Down Expand Up @@ -147,15 +146,15 @@ class ArgumentResolver(private val variableHolder: VariableHolder) {

override fun visitNumberValue(ctx: NumberValueContext): ApmType {
val value = ctx.NUMBER_LITERAL().toString()
val number = Ints.tryParse(value)
val number = value.toIntOrNull()
?: throw ArgumentResolverException("Found invalid number value $value")
return ApmInteger(number)
}

private fun determineStringValue(value: String): ApmString {
val tokens = StringUtils.substringsBetween(value, "\${", "}")
.orEmpty()
.associateWith { variableHolder[it]!!.string }
.associateWith { variableHolder[it].string }
val strSubstitutor = StrSubstitutor(tokens, "\${", "}")
return ApmString(if (tokens.isEmpty()) value else strSubstitutor.replace(value))
}
Expand Down

0 comments on commit 10cc3b8

Please sign in to comment.