From 4767f009bb4c3a7e229458e6bf3d4a2d1c7fc83d Mon Sep 17 00:00:00 2001
From: Jan-Niclas Struewer <j.n.struewer@gmail.com>
Date: Wed, 25 Oct 2023 10:56:03 +0200
Subject: [PATCH] Added new OCCMD check

---
 .../dataprovider/kpi/enumeration/KpiKind.kt   | 20 ++++++++++++++++
 .../dataprovider/kpi/service/KPIService.kt    | 23 +++++++++++++++----
 .../tools/occmd/enumeration/Checks.kt         |  3 ++-
 3 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/kpi/enumeration/KpiKind.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/kpi/enumeration/KpiKind.kt
index a8ac3aeb..5f843c29 100644
--- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/kpi/enumeration/KpiKind.kt
+++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/kpi/enumeration/KpiKind.kt
@@ -165,6 +165,26 @@ enum class KpiKind {
             return "Comments in Code"
         }
     },
+    DOCUMENTATION_INFRASTRUCTURE {
+        override fun toViewModel(
+            value: Int,
+            children: List<KPITreeChildResponseDto>,
+            isEmpty: Boolean
+        ): KPITreeResponseDto {
+            return KPITreeResponseDto(
+                value = value,
+                name = this.getName(),
+                description = "Used to approximate the the availability of documentation " +
+                    "based upon the availability of, e.g., a wiki, and/or a docs folder.",
+                children = children,
+                isEmpty = isEmpty
+            )
+        }
+
+        override fun getName(): String {
+            return "Documentation Infrastructure"
+        }
+    },
 
     // Calculated KPIs
     SIGNED_COMMITS_RATIO {
diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/kpi/service/KPIService.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/kpi/service/KPIService.kt
index 4cc9c002..6ca4f6ee 100644
--- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/kpi/service/KPIService.kt
+++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/kpi/service/KPIService.kt
@@ -59,8 +59,7 @@ class KPIService(
         val kpis = mutableListOf<RawValueKpiCreateDto>()
 
         rawOccmdResults.forEach {
-            val check = Checks.fromString(it.check)
-            when (check) {
+            when (val check = Checks.fromString(it.check)) {
                 Checks.CheckedInBinaries ->
                     kpis.add(
                         RawValueKpiCreateDto(
@@ -93,8 +92,16 @@ class KPIService(
                         )
                     )
 
+                Checks.DocumentationInfrastructure ->
+                    kpis.add(
+                        RawValueKpiCreateDto(
+                            kind = KpiKind.DOCUMENTATION_INFRASTRUCTURE,
+                            score = (it.score * 100).toInt()
+                        )
+                    )
+
                 else ->
-                    logger.warn("Unknown result")
+                    logger.warn("Unknown OCCMD result. $check")
             }
         }
 
@@ -194,12 +201,20 @@ class KPIService(
             calculationStrategy = AggregationKPICalculationStrategy()
         )
 
+        documentationKpi.addChildKPI(
+            rawValueKpis.getOrDefault(
+                KpiKind.DOCUMENTATION_INFRASTRUCTURE,
+                KpiCalculationDto(kind = KpiKind.DOCUMENTATION_INFRASTRUCTURE)
+            ),
+            0.6
+        )
+
         documentationKpi.addChildKPI(
             rawValueKpis.getOrDefault(
                 KpiKind.COMMENTS_IN_CODE,
                 KpiCalculationDto(kind = KpiKind.COMMENTS_IN_CODE)
             ),
-            1.0
+            0.4
         )
 
         val processTransparencyKPI = KpiCalculationDto(
diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/tools/occmd/enumeration/Checks.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/tools/occmd/enumeration/Checks.kt
index 159333e5..736c0c2f 100644
--- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/tools/occmd/enumeration/Checks.kt
+++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/tools/occmd/enumeration/Checks.kt
@@ -4,7 +4,8 @@ enum class Checks(val checkName: String) {
     SastUsageBasic("SastUsageBasic"),
     Secrets("Secrets"),
     CheckedInBinaries("CheckedInBinaries"),
-    CommentsInCode("CommentsInCode");
+    CommentsInCode("CommentsInCode"),
+    DocumentationInfrastructure("ExistenceOfDocumentationInfrastructure");
 
     companion object {
         fun fromString(value: String): Checks? {
-- 
GitLab