Skip to content

Commit

Permalink
Merge pull request #84 from hmrc/BDOG-302
Browse files Browse the repository at this point in the history
BDOG-302 fixes service dependencies page, adds jdk vendor, kind to page
  • Loading branch information
christopherjturner authored Aug 13, 2019
2 parents 19a92bb + 6200eac commit 8d67158
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DependenciesService @Inject()(
_.map { serviceDependency =>
val environmentMappingName =
deployments
.find(deploymentVO => serviceDependency.version.map(_ == deploymentVO.version).getOrElse(false))
.find(deploymentVO => serviceDependency.version.contains(deploymentVO.version))
.map(_.environmentMapping.name)

environmentMappingName match {
Expand Down Expand Up @@ -90,6 +90,9 @@ object DependenciesService {
dependencies.sortBy(serviceDependency => (serviceDependency.group, serviceDependency.artifact))
}


case class ServiceJDKVersion(version: String, vendor: String, kind:String)

case class ServiceDependency(
path : String
, group : String
Expand All @@ -103,7 +106,7 @@ case class ServiceDependencies(
, name : String
, version : Option[String]
, runnerVersion: String
, jdkVersion : String
, java : ServiceJDKVersion
, classpath : String
, dependencies : Seq[ServiceDependency]
, environment : Option[String] = None
Expand All @@ -117,8 +120,25 @@ case class ServiceDependencies(
}

object ServiceDependencies {
import play.api.libs.json.__
import play.api.libs.functional.syntax._

implicit val jdkr = (
(__ \ "version").read[String]
~ (__ \ "vendor" ).read[String]
~ (__ \ "kind" ).read[String]
)(ServiceJDKVersion)

implicit val dependencyReads: Reads[ServiceDependency] = Json.using[Json.WithDefaultValues].reads[ServiceDependency]
implicit val serviceDependenciesReads: Reads[ServiceDependencies] = Json.using[Json.WithDefaultValues].reads[ServiceDependencies]
implicit val serviceDependenciesReads: Reads[ServiceDependencies] = (
(__ \ "uri" ).read[String]
~ (__ \ "name" ).read[String]
~ (__ \ "version" ).readNullable[String]
~ (__ \ "runnerVersion").read[String]
~ (__ \ "java" ).read[ServiceJDKVersion]
~ (__ \ "classpath" ).read[String]
~ (__ \ "dependencies" ).read[Seq[ServiceDependency]]
~ (__ \ "environment" ).readNullable[String]
)(ServiceDependencies.apply _)

}
2 changes: 1 addition & 1 deletion app/views/DependenciesPage.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h1 id="dependencies-header">Dependencies: @serviceName</h1>
}</label>
</div>
<div id="collapsible-area-@index" class="@if(collapsable) {collapse}">
<span class="jdk-version">JDK: @{serviceDependency.jdkVersion}</span>
<span class="jdk-version">@{serviceDependency.java.kind}: @{serviceDependency.java.version} @{serviceDependency.java.vendor}</span>
<table id="dependencies-list" class="table table-condensed table-striped">
<thead>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import org.scalatest.mockito.MockitoSugar
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.json.Json
import uk.gov.hmrc.cataloguefrontend.WireMockEndpoints
import uk.gov.hmrc.cataloguefrontend.connector.model.{Dependency, Version}
import uk.gov.hmrc.cataloguefrontend.service.{DependenciesService, ServiceDependencies}
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.play.bootstrap.config.ServicesConfig
import uk.gov.hmrc.play.bootstrap.http.HttpClient
Expand Down Expand Up @@ -348,6 +350,51 @@ class ServiceDependenciesConnectorSpec
}
}

"JSON Reader" - {
"read json with java section" in {
import uk.gov.hmrc.cataloguefrontend.service.ServiceDependencies.serviceDependenciesReads
val json =""" {
"uri" : "https://artefactory/slugs/mobile-stub/mobile-stub_0.12.0_0.5.2.tgz",
"name" : "mobile-auth-stub",
"version" : "0.12.0",
"semanticVersion" : {
"major" : 0,
"minor" : 12,
"patch" : 0
},
"versionLong" : 12000,
"runnerVersion" : "0.5.2",
"classpath" : "",
"jdkVersion" : "1.8.0_191",
"dependencies" : [
{
"path" : "./mobile-auth-stub-0.12.0/lib/org.slf4j.slf4j-api-1.7.25.jar",
"version" : "1.7.25",
"group" : "org.slf4j",
"artifact" : "slf4j-api",
"meta" : "fromPom"
}
],
"latest" : false,
"qa" : false,
"production" : false,
"development" : false,
"external test" : false,
"staging" : false,
"java" : {
"version" : "1.8.0_191",
"kind" : "JDK",
"vendor" : "OpenJDK"
}
} """
val res = Json.fromJson[ServiceDependencies](Json.parse(json)).get

res.java.version shouldBe "1.8.0_191"
res.java.vendor shouldBe "OpenJDK"
res.java.kind shouldBe "JDK"
}

}
private trait Setup {
implicit val headerCarrier: HeaderCarrier = HeaderCarrier()
}
Expand Down

0 comments on commit 8d67158

Please sign in to comment.