Skip to content

Commit

Permalink
BDOG-175 move filtering service by version range from catalogue-front…
Browse files Browse the repository at this point in the history
…end into service-dependencies
  • Loading branch information
colin-lamed committed May 10, 2019
1 parent a8d7560 commit 2c076a8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
))
}


Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 2c076a8

Please sign in to comment.