Skip to content

Commit

Permalink
Fixed bug in client js. Added search functionality for generic collec…
Browse files Browse the repository at this point in the history
…tion routes (Home, Dependencies and Licenses).
  • Loading branch information
PsychoSnake committed Jun 4, 2018
1 parent 9840456 commit 49230f3
Show file tree
Hide file tree
Showing 15 changed files with 243 additions and 151 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ repositories {
}

configurations {
all*.exclude module : 'spring-boot-starter-logging'
all*.exclude module : 'slf4j-simple'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import javax.persistence.ManyToOne

@Embeddable
class ReportPk(
val timestamp: String,
val timestamp: String, // TODO Edit to a human readable DateTime

@ManyToOne
@JoinColumn(name = "name")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.github.ptosda.projectvalidationmanager.uiController
package com.github.ptosda.projectvalidationmanager.webapp.controller

import com.github.ptosda.projectvalidationmanager.database.entities.*
import com.github.ptosda.projectvalidationmanager.database.repositories.*
import com.github.ptosda.projectvalidationmanager.webapp.service.ReportService
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import kotlin.collections.set

/**
* Controller for the UI
* Controller for the WebApp
*/
@Controller
@RequestMapping("/")
Expand All @@ -36,7 +37,6 @@ class ReportController(val reportService: ReportService,

/**
* Gets the view for the collection of dependencies
* TODO need to show generic dependencies when any is clicked and not specific
*/
@GetMapping("deps")
fun getDependencies(model: HashMap<String, Any?>) : String
Expand All @@ -56,6 +56,7 @@ class ReportController(val reportService: ReportService,
* Gets the view of a dependency
* @param dependencyId the id of the dependency to show
* @param dependencyVersion the version of the dependency to show
* TODO differentiate projects and detail of dependency
*/
@GetMapping("deps/{dep-id}/version/{dep-version}")
fun getDependencyGeneric(@PathVariable("dep-id") dependencyId : String,
Expand Down Expand Up @@ -134,7 +135,7 @@ class ReportController(val reportService: ReportService,
model["report_id"] = reportId
model["report_tag"] = report.tag

model.putAll(reportService.getBuildDependencies(report))
model.putAll(reportService.getReportDependencies(report))

return "report"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.github.ptosda.projectvalidationmanager.webapp.controller

import com.github.ptosda.projectvalidationmanager.database.entities.Project
import com.github.ptosda.projectvalidationmanager.database.repositories.DependencyRepository
import com.github.ptosda.projectvalidationmanager.database.repositories.LicenseRepository
import com.github.ptosda.projectvalidationmanager.database.repositories.ProjectRepository
import com.github.ptosda.projectvalidationmanager.webapp.service.ReportFilterService
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam

@Controller
@RequestMapping("/")
class ReportFilterController(val reportFilterService: ReportFilterService,
val projectRepo: ProjectRepository,
val dependencyRepo: DependencyRepository,
val licenseRepo: LicenseRepository)
{

/**
* HashMap with all project filter types and corresponding functions
*/
val projectFilterFunctions = hashMapOf<String, (Project) -> HashMap<String, Any?>>(
"detail" to { project -> reportFilterService.getProjectDetailView(project) },
"licenses" to { project -> reportFilterService.getProjectLicensesView(project) },
"vulnerabilities" to { project -> reportFilterService.getProjectVulnerabilitiesView(project) }
)

/**
* HashMap with all report filter types and corresponding functions
*/
val buildFilterFunctions = hashMapOf<String, (String, String) -> HashMap<String, Any?>>(
"detail" to { projectId, buildId -> reportFilterService.getReportDetailView(projectId, buildId) },
"licenses" to { projectId, buildId -> reportFilterService.getReportLicensesView(projectId, buildId) },
"vulnerabilities" to { projectId, buildId -> reportFilterService.getReportVulnerabilitiesView(projectId, buildId) }
)

/**
* HashMap with all report search functions
*/
val searchFilterFunctions = hashMapOf<String, (String) -> HashMap<String, Any?>>(
"projs" to { searchText ->
hashMapOf( "projects" to projectRepo.findAll().filter { it.name.startsWith(searchText, true) },
"view_name" to "projects"
)
},
"dependencies" to { searchText ->
hashMapOf("dependencies" to dependencyRepo.findAll()
.groupBy { it.pk.id + it.pk.mainVersion }
.values
.map { it.last() }
.sortedBy{ it.pk.id }
.filter { it.pk.id.startsWith(searchText, true) },
"view_name" to "dependencies"
)
},
"licenses" to { searchText ->
hashMapOf( "licenses" to licenseRepo.findAll().filter { it.spdxId.trimStart('(').startsWith(searchText, true) },
"view_name" to "generic-licenses"
)
}
)

/**
* Gets the view for either of three elements of a Project. These are its detail, licenses or vulnerabilities
* @param projectId the if of the project to filter
* @param filterType the type of filtering to be done (detail, licenses or vulnerabilities)
* @param model hash map to store all view related information
*/
@GetMapping("projs/{project-id}/filter/{filter-type}")
fun filterProject(@PathVariable("project-id") projectId: String,
@PathVariable("filter-type") filterType: String,
model: HashMap<String, Any?>) : String
{

val projectInfo = projectRepo.findById(projectId)

if(!projectInfo.isPresent) {
throw Exception("Project doesn't exist")
}

val project = projectInfo.get()


model.putAll(projectFilterFunctions[filterType]!!.invoke(project))

return model["view_name"].toString()
}

/**
* Gets the view for any of the three possible elements of a Report. These are its detail, licenses or vulnerabilities
* @param projectId the if of the project that the report belongs
* @param buildId the if of the report to filter
* @param filterType the type of filtering to be done (detail, licenses or vulnerabilities)
* @param model hash map to store all view related information
*/
@GetMapping("projs/{project-id}/report/{report-id}/filter/{filter-type}")
fun filterBuild(@PathVariable("project-id") projectId: String,
@PathVariable("report-id") buildId: String,
@PathVariable("filter-type") filterType: String,
model: HashMap<String, Any?>) : String
{

model.putAll(buildFilterFunctions[filterType]!!.invoke(projectId, buildId))

return model["view_name"].toString()
}

/**
* Gets the view for a search request
* @param searchType the type of search to be done
* @param searchValue the value used in the search
* @param model hash map to store all view related information
*/
@GetMapping("search/{search-type}")
fun search(@PathVariable("search-type") searchType: String,
@RequestParam("value") searchValue: String,
model: HashMap<String, Any?>) : String
{

model.putAll(searchFilterFunctions[searchType]!!.invoke(searchValue))

return model["view_name"].toString()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.ptosda.projectvalidationmanager.uiController
package com.github.ptosda.projectvalidationmanager.webapp.service

import com.github.ptosda.projectvalidationmanager.database.entities.*
import com.github.ptosda.projectvalidationmanager.database.repositories.ReportRepository
Expand Down Expand Up @@ -30,23 +30,23 @@ class ReportFilterService(private val reportService: ReportService,
* @param projectId the id of the project
* @param reportId the id of the report to filter
*/
fun getBuildDetailView(projectId: String, reportId: String) : HashMap<String, Any?> {
fun getReportDetailView(projectId: String, reportId: String) : HashMap<String, Any?> {
val model = hashMapOf<String, Any?>()

val buildInfo = reportRepo.findById(ReportPk(reportId, Project(projectId, null, null)))
val reportInfo = reportRepo.findById(ReportPk(reportId, Project(projectId, null, null)))

if(!buildInfo.isPresent) {
if(!reportInfo.isPresent) {
throw Exception("Report was not found")
}

val build = buildInfo.get()
val report = reportInfo.get()

model["project_id"] = projectId

model["report_id"] = reportId
model["report_tag"] = build.tag
model["report_tag"] = report.tag

model.putAll(reportService.getBuildDependencies(build))
model.putAll(reportService.getReportDependencies(report))

model["view_name"] = "report-detail"

Expand Down Expand Up @@ -80,9 +80,9 @@ class ReportFilterService(private val reportService: ReportService,
val model = hashMapOf<String, Any?>()
val licenses = ArrayList<DependencyLicense>()

val build = getProjectLatestBuild(project)
val report = getProjectLatestBuild(project)

build.dependency?.forEach {
report.dependency?.forEach {
licenses.addAll(it.license)
}

Expand All @@ -97,20 +97,20 @@ class ReportFilterService(private val reportService: ReportService,
* @param projectId the id of the project
* @param reportId the id of the report to filter
*/
fun getBuildLicensesView(projectId: String, reportId: String) : HashMap<String, Any?> {
fun getReportLicensesView(projectId: String, reportId: String) : HashMap<String, Any?> {
val model = hashMapOf<String, Any?>()

val buildInfo = reportRepo.findById(ReportPk(reportId, Project(projectId, null, null)))
val reportInfo = reportRepo.findById(ReportPk(reportId, Project(projectId, null, null)))

if(!buildInfo.isPresent) {
if(!reportInfo.isPresent) {
throw Exception("Report was not found")
}

val build = buildInfo.get()
val report = reportInfo.get()

val licenses = ArrayList<DependencyLicense>()

build.dependency!!.forEach {
report.dependency!!.forEach {
licenses.addAll(it.license)
}

Expand All @@ -129,9 +129,9 @@ class ReportFilterService(private val reportService: ReportService,
val model = hashMapOf<String, Any?>()
val vulnerabilities = ArrayList<DependencyVulnerability>()

val build = getProjectLatestBuild(project)
val report = getProjectLatestBuild(project)

build.dependency?.forEach {
report.dependency?.forEach {
vulnerabilities.addAll(it.vulnerabilities)
}

Expand All @@ -146,20 +146,20 @@ class ReportFilterService(private val reportService: ReportService,
* @param projectId the id of the project
* @param reportId the id of the report to filter
*/
fun getBuildVulnerabilitiesView(projectId: String, reportId: String) : HashMap<String, Any?> {
fun getReportVulnerabilitiesView(projectId: String, reportId: String) : HashMap<String, Any?> {
val model = hashMapOf<String, Any?>()

val buildInfo = reportRepo.findById(ReportPk(reportId, Project(projectId, null, null)))
val reportInfo = reportRepo.findById(ReportPk(reportId, Project(projectId, null, null)))

if(!buildInfo.isPresent) {
if(!reportInfo.isPresent) {
throw Exception("Report was not found")
}

val build = buildInfo.get()
val report = reportInfo.get()

val vulnerabilities = ArrayList<DependencyVulnerability>()

build.dependency!!.forEach {
report.dependency!!.forEach {
vulnerabilities.addAll(it.vulnerabilities)
}

Expand Down
Loading

0 comments on commit 49230f3

Please sign in to comment.