Skip to content
Snippets Groups Projects
Verified Commit d9310671 authored by Jan-Niclas Strüwer's avatar Jan-Niclas Strüwer
Browse files

If a MaximumKPICalculationStrategy or AggregationKPICalculationStrategy has...

If a MaximumKPICalculationStrategy or AggregationKPICalculationStrategy has only empty children we set the KPI itself to empty.  This is done by throwing an error which should be caught when calculating the KPI
parent 6ab4f36e
No related branches found
No related tags found
No related merge requests found
Pipeline #23086 passed
......@@ -2,6 +2,7 @@ package de.fraunhofer.iem.dataprovider.kpi.dto
import de.fraunhofer.iem.dataprovider.kpi.enumeration.KpiKind
import de.fraunhofer.iem.dataprovider.kpi.strategy.KPICalculationStrategy
import de.fraunhofer.iem.dataprovider.logger.getLogger
class KpiCalculationDto(
val kind: KpiKind,
......@@ -10,6 +11,7 @@ class KpiCalculationDto(
private var value: Int? = null
) {
private val hierarchyEdges: MutableList<KPIHierarchyEdgeDto> = mutableListOf()
private val logger = getLogger(javaClass)
fun hasChildren(): Boolean {
return hierarchyEdges.isNotEmpty()
......@@ -29,6 +31,7 @@ class KpiCalculationDto(
this.value = calculationStrategy.calculateKPI(this.hierarchyEdges)
this.isEmpty = false
} catch (exception: Exception) {
logger.error("Exception during KPI calculation for $kind with $calculationStrategy")
this.isEmpty = true
this.value = null
}
......
......@@ -11,6 +11,10 @@ class AggregationKPICalculationStrategy : KPICalculationStrategy {
* remaining children.
*/
override fun calculateKPI(children: List<KPIHierarchyEdgeDto>): Int {
if (children.none { !it.to.isEmpty() } || children.isEmpty()) {
throw Exception("KPI aggregation of empty children can't be calculated.")
}
val emptyChildren: List<KPIHierarchyEdgeDto> = children.filter { it.to.isEmpty() }
val notEmptyChildren = children.toMutableList()
notEmptyChildren.removeAll(emptyChildren)
......
......@@ -6,6 +6,9 @@ class MaximumKPICalculationStrategy : KPICalculationStrategy {
// TODO: Currently it's tailored to the maximum dependency vulnerability score, this should change in the future
@Suppress("MagicNumber")
override fun calculateKPI(children: List<KPIHierarchyEdgeDto>): Int {
if (children.none { !it.to.isEmpty() } || children.isEmpty()) {
throw Exception("KPI maximum of empty children can't be calculated")
}
var maximum = 0
for (child in children) {
if (!child.to.isEmpty()) {
......
......@@ -30,7 +30,7 @@ spring.main.web-application-type=REACTIVE
spring.jpa.generate-ddl=true
spring.jpa.show-sql=false
# This setting should only be used in dev. In prod we want to switch to update
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.jpa.properties.hibernate.bytecode.use_reflection_optimizer=false
......
......@@ -5,6 +5,7 @@ opencode.host=https://gitlab.opencode.de/
opencode.access-token=${OC_GL_APIKEY:}
# Tool APIs
opencode.api.base-path=https://sl.dev.o4oe.de/api/v1/project/
# https://software.opencode.de as soon as it is live
opencode.api.ort=/cve-result
# API key to access this server's API
# The api key is needed for all routes.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.