improve solution for issue #719

Sun, 14 Sep 2025 16:37:47 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 14 Sep 2025 16:37:47 +0200
changeset 388
698541f09380
parent 387
a0c4d4038f21
child 389
9d7f34e06d8d

improve solution for issue #719

It is no longer necessary to work with placeholder strings just to fill the gaps (=empty rows) between the fields.

src/main/kotlin/de/uapcore/lightpit/Constants.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt file | annotate | diff | comparison | revisions
--- a/src/main/kotlin/de/uapcore/lightpit/Constants.kt	Sun Sep 14 15:58:27 2025 +0200
+++ b/src/main/kotlin/de/uapcore/lightpit/Constants.kt	Sun Sep 14 16:37:47 2025 +0200
@@ -29,7 +29,7 @@
     /**
      * A data in yyyy-mm-dd format to identify the release.
      */
-    const val VERSION_DATE = "2025-09-06"
+    const val VERSION_DATE = "2025-09-14"
 
     /**
      * The path where the JSP files reside.
--- a/src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt	Sun Sep 14 15:58:27 2025 +0200
+++ b/src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt	Sun Sep 14 16:37:47 2025 +0200
@@ -59,17 +59,16 @@
         .build()
     )
 
-    /**
-     * Fixes the incompetence of Java DiffUtils.
-     * Only the CHANGE and EQUAL cases are presented correctly out of the box.
-     * For DELETE and INSERT we need to add the tags ourselves.
-     */
-    fun presentDiff(row: DiffRow): String {
-        return when (row.tag) {
-            DiffRow.Tag.CHANGE -> row.oldLine
-            DiffRow.Tag.DELETE -> "<strike style=\"color:red\">${row.oldLine}</strike>"
-            DiffRow.Tag.INSERT -> "<i style=\"color: green\">${row.newLine}</i>"
-            DiffRow.Tag.EQUAL -> row.oldLine
+    fun calculateDiff(earlier: String, later: String): String {
+        val diff = diffGenerator.generateDiffRows(
+            listOf(earlier.replace("\r", "")),
+            listOf(later.replace("\r", ""))
+        )[0]
+        return when (diff.tag) {
+            DiffRow.Tag.CHANGE -> diff.oldLine
+            DiffRow.Tag.DELETE -> "<strike style=\"color:red\">${diff.oldLine}</strike>"
+            DiffRow.Tag.INSERT -> "<i style=\"color: green\">${diff.newLine}</i>"
+            DiffRow.Tag.EQUAL -> diff.oldLine
         }
     }
 
@@ -88,56 +87,38 @@
             id = cur.commentid,
             project = cur.project,
             currentSubject = cur.subject,
-            comment = diffGenerator.generateDiffRows(
-                listOf(next.comment.replace("\r", "")),
-                listOf(cur.comment.replace("\r", ""))
-            ).joinToString("\n", transform = this::presentDiff)
+            comment = calculateDiff(next.comment, cur.comment)
         )
 
     private fun fullContent(http: HttpRequest, issue: IssueHistoryEntry) = IssueDiff(
-        // Note: we must make sure that every entry is non-empty, otherwise the diff generator will produce wrong results
         id = issue.issueid,
         project = issue.project,
-        component = issue.component.ifBlank { http.i18n("placeholder.null-component") },
+        component = issue.component,
         status = http.i18n("issue.status."+issue.status.name),
         category = http.i18n("issue.category."+issue.category.name),
         subject = issue.subject,
-        description = issue.description.replace("\r", ""),
-        assignee = issue.assignee.ifBlank { http.i18n("placeholder.null-assignee") },
-        eta = issue.eta?.let { SimpleDateFormat("dd.MM.yyyy").format(it) } ?: http.i18n("placeholder.null-eta"),
-        affected = issue.affected.ifBlank { http.i18n("placeholder.null-version") },
-        resolved = issue.resolved.ifBlank { http.i18n("placeholder.null-version") }
+        description = issue.description,
+        assignee = issue.assignee,
+        eta = issue.eta?.let { SimpleDateFormat("dd.MM.yyyy").format(it) } ?: "",
+        affected = issue.affected,
+        resolved = issue.resolved
     )
 
     private fun diffContent(http: HttpRequest, cur: IssueHistoryEntry, next: IssueHistoryEntry): IssueDiff {
-        val nextContent = fullContent(http, next)
-        val curContent = fullContent(http, cur)
-        val result = diffGenerator.generateDiffRows(
-            listOf(
-                nextContent.subject, nextContent.component, nextContent.status,
-                nextContent.category, nextContent.assignee, nextContent.eta, nextContent.affected, nextContent.resolved
-            ),
-            listOf(
-                curContent.subject, curContent.component, curContent.status,
-                curContent.category, curContent.assignee, curContent.eta, curContent.affected, curContent.resolved
-            )
-        )
-
+        val earlier = fullContent(http, next)
+        val later = fullContent(http, cur)
         return IssueDiff(
-            id = curContent.id,
-            project = curContent.project,
-            subject = presentDiff(result[0]),
-            component = presentDiff(result[1]),
-            status = presentDiff(result[2]),
-            category = presentDiff(result[3]),
-            assignee = presentDiff(result[4]),
-            eta = presentDiff(result[5]),
-            affected = presentDiff(result[6]),
-            resolved = presentDiff(result[7]),
-            description = diffGenerator.generateDiffRows(
-                nextContent.description.split('\n'),
-                curContent.description.split('\n')
-            ).joinToString("\n", transform = this::presentDiff)
+            id = later.id,
+            project = later.project,
+            subject = calculateDiff(earlier.subject, later.subject),
+            component = calculateDiff(earlier.component, later.component),
+            status = calculateDiff(earlier.status, later.status),
+            category = calculateDiff(earlier.category, later.category),
+            assignee = calculateDiff(earlier.assignee, later.assignee),
+            eta = calculateDiff(earlier.eta, later.eta),
+            affected = calculateDiff(earlier.affected, later.affected),
+            resolved = calculateDiff(earlier.resolved, later.resolved),
+            description = calculateDiff(earlier.description, later.description)
         )
     }
 

mercurial