diff --git a/app/uk/gov/hmrc/cataloguefrontend/DependencyExplorerController.scala b/app/uk/gov/hmrc/cataloguefrontend/DependencyExplorerController.scala index bd6b3d7d2..6f4ef1929 100644 --- a/app/uk/gov/hmrc/cataloguefrontend/DependencyExplorerController.scala +++ b/app/uk/gov/hmrc/cataloguefrontend/DependencyExplorerController.scala @@ -52,7 +52,15 @@ class DependencyExplorerController @Inject()( teams <- trConnector.allTeams.map(_.map(_.name).sorted) flags = SlugInfoFlag.values groupArtefacts <- service.getGroupArtefacts - } yield Ok(page(form.fill(SearchForm("", SlugInfoFlag.Latest.s, "", "", "")), teams, flags, groupArtefacts, versionRange = BobbyVersionRange(None, None, None, ""), searchResults = None, pieData = None)) + } yield Ok(page( + form.fill(SearchForm("", SlugInfoFlag.Latest.s, "", "", "")) + , teams + , flags + , groupArtefacts + , versionRange = BobbyVersionRange(None, None, None, "") + , searchResults = None + , pieData = None + )) } @@ -94,7 +102,15 @@ class DependencyExplorerController @Inject()( flags = SlugInfoFlag.values groupArtefacts <- service.getGroupArtefacts res <- { - def pageWithError(msg: String) = page(form.bindFromRequest().withGlobalError(msg), teams, flags, groupArtefacts, versionRange = BobbyVersionRange(None, None, None, ""), searchResults = None, pieData = None) + def pageWithError(msg: String) = page( + form.bindFromRequest().withGlobalError(msg) + , teams + , flags + , groupArtefacts + , versionRange = BobbyVersionRange(None, None, None, "") + , searchResults = None + , pieData = None + ) form .bindFromRequest() .fold( diff --git a/app/uk/gov/hmrc/cataloguefrontend/connector/ServiceDependenciesConnector.scala b/app/uk/gov/hmrc/cataloguefrontend/connector/ServiceDependenciesConnector.scala index 2d5e503a8..b1b605c4c 100644 --- a/app/uk/gov/hmrc/cataloguefrontend/connector/ServiceDependenciesConnector.scala +++ b/app/uk/gov/hmrc/cataloguefrontend/connector/ServiceDependenciesConnector.scala @@ -90,17 +90,19 @@ class ServiceDependenciesConnector @Inject()( } def getServicesWithDependency( - flag : SlugInfoFlag, - group : String, - artefact: String)(implicit hc: HeaderCarrier): Future[Seq[ServiceWithDependency]] = { + flag : SlugInfoFlag, + group : String, + artefact : String, + versionRange: BobbyVersionRange)(implicit hc: HeaderCarrier): Future[Seq[ServiceWithDependency]] = { implicit val r = ServiceWithDependency.reads http .GET[Seq[ServiceWithDependency]]( s"$servicesDependenciesBaseUrl/serviceDeps", queryParams = Seq( - "flag" -> flag.s, - "group" -> group, - "artefact" -> artefact)) + "flag" -> flag.s, + "group" -> group, + "artefact" -> artefact, + "versionRange" -> versionRange.range)) } def getGroupArtefacts(implicit hc: HeaderCarrier): Future[List[GroupArtefacts]] = { diff --git a/app/uk/gov/hmrc/cataloguefrontend/connector/model/Dependencies.scala b/app/uk/gov/hmrc/cataloguefrontend/connector/model/Dependencies.scala index c5b17bd1a..b2beae917 100644 --- a/app/uk/gov/hmrc/cataloguefrontend/connector/model/Dependencies.scala +++ b/app/uk/gov/hmrc/cataloguefrontend/connector/model/Dependencies.scala @@ -89,24 +89,6 @@ case class BobbyVersionRange( } else None } - def includes(v: Version): Boolean = { - val qualFilter: Function1[Version, Boolean] = qualifier match { - case Some(qual) => _.toString.contains(qual) - case None => _ => true - } - val lbFilter: Function1[Version, Boolean] = lowerBound match { - case Some(BobbyVersion(version, true)) => _ >= version - case Some(BobbyVersion(version, false)) => _ > version - case None => _ => true - } - val ubFilter: Function1[Version, Boolean] = upperBound match { - case Some(BobbyVersion(version, true)) => _ <= version - case Some(BobbyVersion(version, false)) => _ < version - case None => _ => true - } - qualFilter(v) && lbFilter(v) && ubFilter(v) - } - override def toString: String = range } diff --git a/app/uk/gov/hmrc/cataloguefrontend/service/DependenciesService.scala b/app/uk/gov/hmrc/cataloguefrontend/service/DependenciesService.scala index dffc4d19d..5166f0af1 100644 --- a/app/uk/gov/hmrc/cataloguefrontend/service/DependenciesService.scala +++ b/app/uk/gov/hmrc/cataloguefrontend/service/DependenciesService.scala @@ -54,16 +54,13 @@ class DependenciesService @Inject()( artefact : String, versionRange: BobbyVersionRange)(implicit hc: HeaderCarrier): Future[Seq[ServiceWithDependency]] = serviceDependenciesConnector - .getServicesWithDependency(flag, group, artefact) + .getServicesWithDependency(flag, group, artefact, versionRange) .map { l => optTeam match { case None => l case Some(team) => l.filter(_.teams.contains(team)) } } - .map { l => - l.filter(_.depSemanticVersion.map(versionRange.includes).getOrElse(true)) // include invalid semanticVersion in results - } .map(_ .sortBy(_.slugName) .sorted(Ordering.by((_: ServiceWithDependency).depSemanticVersion).reverse)) diff --git a/test/uk/gov/hmrc/cataloguefrontend/service/DependenciesServiceSpec.scala b/test/uk/gov/hmrc/cataloguefrontend/service/DependenciesServiceSpec.scala index 00ffdcf76..d60ad14c1 100644 --- a/test/uk/gov/hmrc/cataloguefrontend/service/DependenciesServiceSpec.scala +++ b/test/uk/gov/hmrc/cataloguefrontend/service/DependenciesServiceSpec.scala @@ -32,8 +32,9 @@ class SlugInfoServiceSpec implicit val hc = mock[HeaderCarrier] - val group = "group" - val artefact = "artefact" + val group = "group" + val artefact = "artefact" + val versionRange = BobbyVersionRange("[1.0.1,)") val v100 = ServiceWithDependency( @@ -66,40 +67,15 @@ class SlugInfoServiceSpec depSemanticVersion = Version.parse("2.0.5")) "DependenciesService.getServicesWithDependency" should { - "filter results by version" in { - - val boot = Boot.init - - when(boot.mockedServiceDependenciesConnector.getServicesWithDependency(SlugInfoFlag.Latest, group, artefact)) - .thenReturn(Future(Seq(v100, v200, v205))) - - await(boot.service.getServicesWithDependency(optTeam = None, SlugInfoFlag.Latest, group, artefact, BobbyVersionRange("[1.0.1,)"))) shouldBe Seq(v205, v200) - await(boot.service.getServicesWithDependency(optTeam = None, SlugInfoFlag.Latest, group, artefact, BobbyVersionRange("(,1.0.1]"))) shouldBe Seq(v100) - await(boot.service.getServicesWithDependency(optTeam = None, SlugInfoFlag.Latest, group, artefact, BobbyVersionRange("[2.0.0]"))) shouldBe Seq(v200) - } - - "include non-parseable versions" in { - - val boot = Boot.init - - val bad = v100.copy(depVersion = "r938", depSemanticVersion = None) - - when(boot.mockedServiceDependenciesConnector.getServicesWithDependency(SlugInfoFlag.Latest, group, artefact)) - .thenReturn(Future(Seq(v100, v200, v205, bad))) - - await(boot.service.getServicesWithDependency(optTeam = None, SlugInfoFlag.Latest, group, artefact, BobbyVersionRange("[1.0.1,)"))) shouldBe Seq(v205, v200, bad) - await(boot.service.getServicesWithDependency(optTeam = None, SlugInfoFlag.Latest, group, artefact, BobbyVersionRange("(,1.0.1]"))) shouldBe Seq(v100, bad) - } - "filter results by team" in { val boot = Boot.init - when(boot.mockedServiceDependenciesConnector.getServicesWithDependency(SlugInfoFlag.Latest, group, artefact)) + when(boot.mockedServiceDependenciesConnector.getServicesWithDependency(SlugInfoFlag.Latest, group, artefact, versionRange)) .thenReturn(Future(Seq(v100, v200, v205))) - await(boot.service.getServicesWithDependency(optTeam = Some("T1"), SlugInfoFlag.Latest, group, artefact, BobbyVersionRange("[1.0.1,)"))) shouldBe Seq(v200) - await(boot.service.getServicesWithDependency(optTeam = Some("T2"), SlugInfoFlag.Latest, group, artefact, BobbyVersionRange("[1.0.1,)"))) shouldBe Seq(v205, v200) + await(boot.service.getServicesWithDependency(optTeam = Some("T1"), SlugInfoFlag.Latest, group, artefact, versionRange)) shouldBe Seq(v200, v100) + await(boot.service.getServicesWithDependency(optTeam = Some("T2"), SlugInfoFlag.Latest, group, artefact, versionRange)) shouldBe Seq(v205, v200) } }