-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from hmrc/BDOG-182
BDOG-182 Bobby Explorer
- Loading branch information
Showing
13 changed files
with
408 additions
and
5 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
app/uk/gov/hmrc/cataloguefrontend/BobbyExplorerController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2019 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.cataloguefrontend | ||
|
||
import javax.inject.Inject | ||
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} | ||
import uk.gov.hmrc.cataloguefrontend.service.BobbyService | ||
import uk.gov.hmrc.play.bootstrap.controller.FrontendController | ||
import views.html.BobbyExplorerPage | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
class BobbyExplorerController @Inject() (mcc : MessagesControllerComponents, | ||
page : BobbyExplorerPage, | ||
bobbyService: BobbyService | ||
)( implicit val ec: ExecutionContext) extends FrontendController(mcc) { | ||
def list(): Action[AnyContent] = Action.async { implicit request => | ||
bobbyService.getRules().map(r => Ok(page(r))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/uk/gov/hmrc/cataloguefrontend/connector/model/BobbyRule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2019 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.cataloguefrontend.connector.model | ||
|
||
import java.time.LocalDate | ||
|
||
import play.api.libs.json.{Json, Reads} | ||
|
||
case class BobbyRule(organisation: String, name: String, range: String, reason: String, from: LocalDate) { | ||
val groupArtifactName: String = { | ||
val wildcard = "*" | ||
if (organisation == wildcard && name == wildcard) "*" else s"$organisation:$name" | ||
} | ||
} | ||
object BobbyRule { | ||
implicit val reader: Reads[BobbyRule] = Json.reads[BobbyRule] | ||
} | ||
|
||
case class BobbyRuleSet(libraries: Seq[BobbyRule], plugins: Seq[BobbyRule]) | ||
object BobbyRuleSet { | ||
implicit val reader: Reads[BobbyRuleSet] = Json.reads[BobbyRuleSet] | ||
} |
46 changes: 46 additions & 0 deletions
46
app/uk/gov/hmrc/cataloguefrontend/service/BobbyService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2019 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.cataloguefrontend.service | ||
|
||
import java.time.{Clock, LocalDate} | ||
|
||
import javax.inject.Inject | ||
import uk.gov.hmrc.cataloguefrontend.connector.ConfigConnector | ||
import uk.gov.hmrc.cataloguefrontend.connector.model.{BobbyRule, BobbyRuleSet} | ||
import uk.gov.hmrc.cataloguefrontend.service.model.BobbyRulesView | ||
import uk.gov.hmrc.http.HeaderCarrier | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class BobbyService @Inject()(configConnector: ConfigConnector, clock: Clock)(implicit val ec: ExecutionContext) { | ||
|
||
def getRules()(implicit hc: HeaderCarrier) : Future[BobbyRulesView] = { | ||
val today = LocalDate.now(clock) | ||
def filterUpcoming(rule: BobbyRule) = rule.from.isAfter(today) | ||
def filterActive(rule: BobbyRule) = rule.from.isBefore(today) || rule.from.isEqual(today) | ||
def compareUpcoming(rule1: BobbyRule, rule2: BobbyRule) = compareRules(rule1, rule2)(_ isBefore _) | ||
def compareActive(rule1: BobbyRule, rule2: BobbyRule) = compareRules(rule1, rule2)(_ isAfter _) | ||
def compareRules(x: BobbyRule, y: BobbyRule)(sortDirection: (LocalDate, LocalDate) => Boolean) = | ||
if (x.from == y.from) x.groupArtifactName < y.groupArtifactName else sortDirection(x.from, y.from) | ||
|
||
configConnector.bobbyRules().map(r => BobbyRulesView( | ||
upcoming = BobbyRuleSet(libraries = r.libraries.filter(filterUpcoming).sortWith(compareUpcoming), plugins = r.plugins.filter(filterUpcoming).sortWith(compareUpcoming)), | ||
active = BobbyRuleSet(libraries = r.libraries.filter(filterActive).sortWith(compareActive), plugins = r.plugins.filter(filterActive).sortWith(compareActive))) | ||
) | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
app/uk/gov/hmrc/cataloguefrontend/service/model/BobbyRulesView.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2019 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.cataloguefrontend.service.model | ||
|
||
import uk.gov.hmrc.cataloguefrontend.connector.model.BobbyRuleSet | ||
|
||
case class BobbyRulesView (upcoming: BobbyRuleSet, active: BobbyRuleSet) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
@* | ||
* Copyright 2019 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*@ | ||
|
||
@import uk.gov.hmrc.cataloguefrontend.ViewMessages | ||
@import uk.gov.hmrc.cataloguefrontend.connector.model.{BobbyRule, BobbyRuleSet} | ||
@import uk.gov.hmrc.cataloguefrontend.service.model.BobbyRulesView | ||
|
||
@this(viewMessages: ViewMessages) | ||
|
||
@(rules: BobbyRulesView)(implicit request: Request[_]) | ||
|
||
@standard_layout(s"Bobby rules") { | ||
<header> | ||
<h1>Bobby Rules</h1> | ||
</header> | ||
@bobbyRulesTimeSection(rules.upcoming, "Upcoming", "table table-striped") | ||
@bobbyRulesTimeSection(rules.active, "Active", "table table-striped-warning") | ||
} | ||
|
||
@bobbyRulesTimeSection(rulesByTime: BobbyRuleSet, heading: String, cssClass: String) = { | ||
@if(rulesByTime.libraries.nonEmpty || rulesByTime.plugins.nonEmpty) { | ||
<div><h2>@heading</h2></div> | ||
@bobbyRulesArtifactTypeSection(rulesByTime.libraries, "Library", cssClass) | ||
@bobbyRulesArtifactTypeSection(rulesByTime.plugins, "Plugin", cssClass) | ||
} | ||
} | ||
|
||
@bobbyRulesArtifactTypeSection(rulesByArtifactType: Seq[BobbyRule], artifactType: String, cssClass: String) = { | ||
@if(rulesByArtifactType.nonEmpty) { | ||
<div> | ||
<table class="@{artifactType.toLowerCase}-rules @cssClass"> | ||
<thead> | ||
<tr> | ||
<th>@artifactType</th> | ||
<th>Version</th> | ||
<th>Reason</th> | ||
<th>Active from</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@rulesByArtifactType.map(bobbyRuleRow) | ||
</tbody> | ||
</table> | ||
</div> | ||
} | ||
} | ||
|
||
@bobbyRuleRow(rule: BobbyRule) = { | ||
<tr class="bobby-rule"> | ||
<td>@rule.groupArtifactName</td> | ||
<td>@rule.range</td> | ||
<td>@rule.reason</td> | ||
<td>@rule.from</td> | ||
</tr> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
test/uk/gov/hmrc/cataloguefrontend/connector/model/BobbyRuleFactory.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2019 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.cataloguefrontend.connector.model | ||
|
||
import java.time.LocalDate | ||
|
||
object BobbyRuleFactory { | ||
def aBobbyRule(organisation: String = "uk.gov.hmrc", name: String = "play-frontend", range: String = "[*-SNAPSHOT]", reason: String = "No snapshot dependencies permitted", from: LocalDate = LocalDate.of(2015, 3, 16)) = | ||
BobbyRule(organisation, name, range, reason, from) | ||
} |
35 changes: 35 additions & 0 deletions
35
test/uk/gov/hmrc/cataloguefrontend/connector/model/BobbyRuleSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2019 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.cataloguefrontend.connector.model | ||
|
||
import org.scalatest.{Matchers, WordSpec} | ||
import uk.gov.hmrc.cataloguefrontend.connector.model.BobbyRuleFactory.aBobbyRule | ||
|
||
class BobbyRuleSpec extends WordSpec with Matchers { | ||
|
||
"groupArtifactName" should { | ||
|
||
"return group ID and artifact ID" in { | ||
aBobbyRule(organisation = "a", name = "b").groupArtifactName should be("a:b") | ||
} | ||
|
||
"return * for matching all" in { | ||
aBobbyRule(organisation = "*", name = "*").groupArtifactName should be("*") | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.