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(version): fix displayed versions #2026

Merged
merged 3 commits into from Mar 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 12 additions & 36 deletions webapi/src/main/scala/org/knora/webapi/routing/VersionRoute.scala
Expand Up @@ -15,15 +15,6 @@ import spray.json.{JsObject, JsString}

import scala.concurrent.duration._

case class VersionCheckResult(
name: String,
webapi: String,
scala: String,
akkaHttp: String,
sipi: String,
fuseki: String
)

/**
* Provides version check logic
*/
Expand All @@ -32,39 +23,24 @@ trait VersionCheck {

override implicit val timeout: Timeout = 1.second

protected def createResponse(result: VersionCheckResult): HttpResponse =
protected def createResponse(): HttpResponse = {
val sipiVersion: String = BuildInfo.sipi.split(":").apply(1)
val fusekiVersion: String = BuildInfo.fuseki.split(":").apply(1)

HttpResponse(
status = StatusCodes.OK,
entity = HttpEntity(
ContentTypes.`application/json`,
JsObject(
"name" -> JsString(result.name),
"webapi" -> JsString(result.webapi),
"scala" -> JsString(result.scala),
"akkaHttp" -> JsString(result.akkaHttp),
"sipi" -> JsString(result.sipi),
"fuseki" -> JsString(result.fuseki)
).compactPrint
"name" -> JsString("version"),
subotic marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need this line?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not, but then it is a breaking change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. but instead of improvements to this route I just fixed it with small refactoring to avoid breaking changes...

"webapi" -> JsString(BuildInfo.version),
"scala" -> JsString(BuildInfo.scalaVersion),
"akkaHttp" -> JsString(BuildInfo.akkaHttp),
"sipi" -> JsString(sipiVersion),
"fuseki" -> JsString(fusekiVersion)
).prettyPrint
)
)

protected def getVersion: VersionCheckResult = {
var sipiVersion = BuildInfo.sipi
val sipiIndex = sipiVersion.indexOf(':')
sipiVersion = if (sipiIndex > 0) sipiVersion.substring(sipiIndex + 1) else sipiVersion

var fusekiVersion = BuildInfo.fuseki
val fusekiIndex = fusekiVersion.indexOf(':')
fusekiVersion = if (fusekiIndex > 0) fusekiVersion.substring(fusekiIndex + 1) else fusekiVersion

VersionCheckResult(
name = "version",
webapi = BuildInfo.version,
scala = BuildInfo.version,
akkaHttp = BuildInfo.akkaHttp,
sipi = sipiVersion,
fuseki = fusekiVersion
)
}
}

Expand All @@ -79,7 +55,7 @@ class VersionRoute(routeData: KnoraRouteData) extends KnoraRoute(routeData) with
override def makeRoute(featureFactoryConfig: FeatureFactoryConfig): Route =
path("version") {
get { requestContext =>
requestContext.complete(createResponse(getVersion))
requestContext.complete(createResponse())
}
}
}
Expand Up @@ -17,10 +17,11 @@ import scala.concurrent.duration._
import scala.languageFeature.postfixOps

object VersionRouteITSpec {
val config: Config = ConfigFactory.parseString("""
|akka.loglevel = "DEBUG"
|akka.stdout-loglevel = "DEBUG"
""".stripMargin)
val config: Config = ConfigFactory.parseString(
"""
|akka.loglevel = "DEBUG"
|akka.stdout-loglevel = "DEBUG"
""".stripMargin)
}

/**
Expand Down