Report proper error messages when filter is wrong project or wrong team

This commit is contained in:
Šesták Vít
2018-03-21 10:45:11 +01:00
parent e6e9d4c940
commit a2a4ee01c7
2 changed files with 9 additions and 4 deletions

View File

@@ -139,10 +139,14 @@ object DependencyCheckReportsParser{
private val ProjectSelectorPattern = """^project:(.*)$""".r private val ProjectSelectorPattern = """^project:(.*)$""".r
private val TeamSelectorPattern = """^team:(.*)$""".r private val TeamSelectorPattern = """^team:(.*)$""".r
private def parseFilter(filter: String): Filter = filter match { private def parseFilter(filter: String): Filter = {
case ProjectSelectorPattern(project) => ProjectFilter(projectsReportInfo.reportIdToReportInfo(project)) def mapToFilter[T](dataOption: Option[T], filterCreator: T => Filter): Filter =
case TeamSelectorPattern(team) => TeamFilter(projects.teamById(team)) dataOption.fold[Filter](BadFilter(filter))(filterCreator)
case other => BadFilter(other) filter match {
case ProjectSelectorPattern(project) => mapToFilter(projectsReportInfo.reportIdToReportInfo.get(project), ProjectFilter)
case TeamSelectorPattern(team) => mapToFilter(projects.getTeamById(team), TeamFilter)
case other => BadFilter(other)
}
} }
def selection(selectorOption: Option[String]): Option[ResultWithSelection] = { def selection(selectorOption: Option[String]): Option[ResultWithSelection] = {

View File

@@ -21,6 +21,7 @@ class Projects (
) )
def teamById(id: String): Team = teamsById(id) def teamById(id: String): Team = teamsById(id)
def getTeamById(id: String): Option[Team] = teamsById.get(id)
def teamSet: Set[Team] = teamsById.values.toSet def teamSet: Set[Team] = teamsById.values.toSet