1010import com .fasterxml .jackson .databind .ObjectMapper ;
1111import com .fasterxml .jackson .databind .node .ArrayNode ;
1212import static com .fasterxml .jackson .databind .node .JsonNodeType .OBJECT ;
13- import com .fasterxml .jackson .databind .node .MissingNode ;
1413import com .fasterxml .jackson .databind .node .ObjectNode ;
1514import com .fasterxml .jackson .databind .node .TextNode ;
1615import io .clownfish .clownfish .jsonator .conditions .ConditionsWrapper ;
3231import java .util .Optional ;
3332import java .util .logging .Level ;
3433import java .util .logging .Logger ;
34+ import java .util .regex .Matcher ;
35+ import java .util .regex .Pattern ;
3536
3637/**
3738 *
@@ -202,7 +203,8 @@ public String map(String mappingcontent, boolean refresh) {
202203 String format = jn .at (mapping .getListcondition ()).asText ();
203204 switch (format ) {
204205 case "string" -> {
205- listentry .put (mapping .getTag (), jn .at (mapping .getContentfield ()));
206+ putVal (listentry , jn , mapping );
207+ //listentry.put(mapping.getTag(), getVal(jn, mapping));
206208 if (listentry .get (mapping .getTag ()).isMissingNode ()) {
207209 listentry .put (mapping .getTag (), mapping .getNullval ());
208210 }
@@ -224,20 +226,23 @@ public String map(String mappingcontent, boolean refresh) {
224226 }
225227 }
226228 } else {
227- listentry .put (mapping .getTag (), jn .at (mapping .getContentfield ()));
229+ putVal (listentry , jn , mapping );
230+ //listentry.put(mapping.getTag(), getVal(jn, mapping));
228231 if (listentry .get (mapping .getTag ()).isMissingNode ()) {
229232 listentry .put (mapping .getTag (), mapping .getNullval ());
230233 }
231234 }
232235 listNode .set (i , listentry );
233236 } else {
234237 listentry = objectMapper .createObjectNode ();
235- listentry .put (mapping .getTag (), jn .at (mapping .getContentfield ()));
238+ putVal (listentry , jn , mapping );
239+ //listentry.put(mapping.getTag(), getVal(jn, mapping));
236240 listNode .add (listentry );
237241 }
238242 } else {
239243 ObjectNode listentry = objectMapper .createObjectNode ();
240- listentry .put (mapping .getTag (), jn .at (mapping .getContentfield ()));
244+ putVal (listentry , jn , mapping );
245+ //listentry.put(mapping.getTag(), getVal(jn, mapping));
241246 listNode .add (listentry );
242247 }
243248 i ++;
@@ -298,16 +303,19 @@ public String map(String mappingcontent, boolean refresh) {
298303 if (listNode .size ()>0 ) {
299304 ObjectNode listentry = (ObjectNode )listNode .get (i );
300305 if (null != listentry ) {
301- listentry .put (mapping .getTag (), jn .at (mapping .getContentfield ()));
306+ //listentry.put(mapping.getTag(), getVal(jn, mapping));
307+ putVal (listentry , jn , mapping );
302308 listNode .set (i , listentry );
303309 } else {
304310 listentry = objectMapper .createObjectNode ();
305- listentry .put (mapping .getTag (), jn .at (mapping .getContentfield ()));
311+ //listentry.put(mapping.getTag(), getVal(jn, mapping));
312+ putVal (listentry , jn , mapping );
306313 listNode .add (listentry );
307314 }
308315 } else {
309316 ObjectNode listentry = objectMapper .createObjectNode ();
310- listentry .put (mapping .getTag (), jn .at (mapping .getContentfield ()));
317+ //listentry.put(mapping.getTag(), getVal(jn, mapping));
318+ putVal (listentry , jn , mapping );
311319 listNode .add (listentry );
312320 }
313321 i ++;
@@ -536,6 +544,69 @@ private JsonNode getJsonNodeVal(IMetaJson mapping, Optional<IDatasource> result,
536544 }
537545 }
538546
547+ private void putVal (ObjectNode listentry , JsonNode jn , IMetaJson mapping ) {
548+ if (mapping .getContentfield ().startsWith ("#" )) {
549+ Pattern pattern = Pattern .compile ("\\ #CONCAT\\ {(.*?)\\ }" );
550+ Matcher matcher = pattern .matcher (mapping .getContentfield ());
551+
552+ if (matcher .find ()) {
553+ // Der gesamte Inhalt zwischen den Klammern (z.B. "#,/test/name")
554+ String content = matcher .group (1 );
555+
556+ // 2. Zerlege den Inhalt anhand des Kommas (,)
557+ // Die Methode split() gibt ein Array von Strings zurück
558+ String [] parts = content .split ("," );
559+
560+ // StringBuilder ist effizienter zum Zusammenfügen von Strings
561+ StringBuilder resultBuilder = new StringBuilder ();
562+
563+ // 3. Füge die Teile zusammen und ignoriere leere Strings (vom führenden Komma)
564+ for (String part : parts ) {
565+ String trimmedPart = part .trim ();
566+ if (!trimmedPart .isEmpty ()) {
567+ if (trimmedPart .startsWith ("/" )) {
568+ resultBuilder .append (jn .at (trimmedPart ).asText ());
569+ } else {
570+ resultBuilder .append (trimmedPart );
571+ }
572+ }
573+ }
574+ if (resultBuilder .length ()>1 ) {
575+ //return resultBuilder.toString();
576+ listentry .put (mapping .getTag (), resultBuilder .toString ());
577+ } else {
578+ listentry .put (mapping .getTag (), "" );
579+ //return "";
580+ }
581+ } else {
582+ // Gib den ursprünglichen String zurück oder eine Fehlermeldung,
583+ // wenn das Muster nicht gefunden wurde
584+ listentry .put (mapping .getTag (), mapping .getContentfield ());
585+ //return mapping.getContentfield();
586+ }
587+ } else {
588+ String retval = jn .at (mapping .getContentfield ()).asText ();
589+ switch (mapping .getContenttype ()) {
590+ case "string" -> {
591+ listentry .put (mapping .getTag (), (String ) retval );
592+ //return (String) retval;
593+ }
594+ case "boolean" -> {
595+ listentry .put (mapping .getTag (), Boolean .valueOf (retval ));
596+ //return Boolean.valueOf(retval);
597+ }
598+ case "number" -> {
599+ listentry .put (mapping .getTag (), Integer .valueOf (retval ));
600+ //return Integer.valueOf(retval);
601+ }
602+ default -> {
603+ listentry .put (mapping .getTag (), (String ) retval );
604+ //return (String) retval;
605+ }
606+ }
607+ }
608+ }
609+
539610 /*
540611 private String nullcheck(JsonNode jn, IMetaJson mapping) {
541612 if (null != jn.at(mapping.getContentfield()) {
0 commit comments