| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- package com.tsystems.inwo.vgl.service;
- import com.fasterxml.jackson.databind.JsonNode;
- import org.springframework.stereotype.Service;
- import java.util.Objects;
- import java.util.function.Function;
- @Service
- public class HtmlRenderingService {
- public String buildPersonFieldHtml(JsonNode rightPerson, JsonNode leftPerson, Function<JsonNode, String> extractor, boolean hasChanges) {
- if (!hasChanges || rightPerson == null) {
- JsonNode primary = rightPerson != null ? rightPerson : leftPerson;
- return primary != null ? escape(extractor.apply(primary)) : "";
- }
-
- String rightVal = rightPerson != null ? extractor.apply(rightPerson) : "";
- String leftVal = leftPerson != null ? extractor.apply(leftPerson) : "";
-
- if (!Objects.equals(rightVal, leftVal)) {
- return cellHtml(rightVal, leftVal, true);
- } else {
- return escape(rightVal);
- }
- }
-
- public String buildItemFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
- if (!hasChanges || rightItem == null) {
- JsonNode primary = rightItem != null ? rightItem : leftItem;
- return primary != null ? escape(extractor.apply(primary)) : "";
- }
-
- String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
- String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
-
- if (!Objects.equals(rightVal, leftVal)) {
- return cellHtml(rightVal, leftVal, true);
- } else {
- return escape(rightVal);
- }
- }
- public String buildEinkommenFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
- if (!hasChanges || rightItem == null) {
- JsonNode primary = rightItem != null ? rightItem : leftItem;
- return primary != null ? escape(extractor.apply(primary)) : "";
- }
-
- String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
- String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
-
- if (!Objects.equals(rightVal, leftVal)) {
- return cellHtml(rightVal, leftVal, true);
- } else {
- return escape(rightVal);
- }
- }
- public String buildFreibetragFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
- if (!hasChanges || rightItem == null) {
- JsonNode primary = rightItem != null ? rightItem : leftItem;
- return primary != null ? escape(extractor.apply(primary)) : "";
- }
-
- String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
- String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
-
- if (!Objects.equals(rightVal, leftVal)) {
- return cellHtml(rightVal, leftVal, true);
- } else {
- return escape(rightVal);
- }
- }
- public String buildKitaFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
- if (!hasChanges || rightItem == null) {
- JsonNode primary = rightItem != null ? rightItem : leftItem;
- return primary != null ? escape(extractor.apply(primary)) : "";
- }
-
- String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
- String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
-
- if (!Objects.equals(rightVal, leftVal)) {
- return cellHtml(rightVal, leftVal, true);
- } else {
- return escape(rightVal);
- }
- }
- public String cellHtml(String newVal, String oldVal, boolean changed) {
- if (!changed) {
- return escape(newVal);
- }
-
- // Handle empty old values
- String displayOldVal = (oldVal == null || oldVal.trim().isEmpty()) ? "leer" : oldVal;
-
- // Return with cell-changed class and proper old value display
- return "<span class='cell-changed'>" + escape(newVal) +
- "<div class='old'>Alt: " + escape(displayOldVal) + "</div></span>";
- }
-
- public String escape(String s) {
- if (s == null) return "";
- return s.replace("&", "&")
- .replace("<", "<")
- .replace(">", ">");
- }
- }
|