@@ -126,16 +126,17 @@ public static void main(String[] args) throws IOException {
126126
127127 if (Settings .getKafka ().getUrl () == null || Settings .getKafka ().getUrl ().isEmpty ()) {
128128 Logger .debug ("Kafka URL not set, loading local file" );
129- File [] files = new File ("testData/zvd" ).listFiles ();
129+ File [] files = new File (Settings . getTestDataDir () ).listFiles ();
130130 for (File f : files ) {
131131 if (f .isDirectory ()) {
132132 continue ;
133133 }
134134 Map <String , Object > entries = mapper .readValue (f , new TypeReference <LinkedHashMap <String , Object >>() {
135135 });
136136 Map <String , Object > map = new LinkedHashMap <>();
137+ Map <String , Object > cache = new LinkedHashMap <>();
137138 map .put ("datalake_id" , entries .get ("datalake_id" ));
138- walkTree (entries .entrySet (), 1 , "" , map );
139+ walkTree (entries .entrySet (), 1 , "" , map , cache );
139140 SPEED .put (UUID .randomUUID ().toString (), "success" );
140141 }
141142 System .exit (0 );
@@ -173,8 +174,9 @@ public static void main(String[] args) throws IOException {
173174 new TypeReference <LinkedHashMap <String , Object >>() {
174175 });
175176 Map <String , Object > map = new LinkedHashMap <>();
177+ Map <String , Object > cache = new LinkedHashMap <>();
176178 map .put ("datalake_id" , entries .get ("datalake_id" ));
177- walkTree (entries .entrySet (), 1 , "" , map );
179+ walkTree (entries .entrySet (), 1 , "" , map , cache );
178180 } catch (ProcessingException e ) {
179181 Logger .error ("ProcessingException occured, writing to error topic!" );
180182 producer .send (new ProducerRecord <>(Settings .getKafka ().getErrorTopic (), record .value ()));
@@ -267,7 +269,8 @@ private static void initializeAttribute(Mapping m, ObjectMapper mapper) {
267269 }
268270
269271 @ SuppressWarnings ({ "unchecked" , "IllegalCatch" })
270- public static Object localMap (Set <Entry <String , Object >> xmlSet , String templateId , String path ) {
272+ public static Object localMap (Set <Entry <String , Object >> xmlSet , String templateId , String path ,
273+ Map <String , Object > cache ) {
271274 Binding b = new Binding ();
272275 GroovyShell s = new GroovyShell (b );
273276 b .setVariable ("xmlSet" , xmlSet );
@@ -276,9 +279,10 @@ public static Object localMap(Set<Entry<String, Object>> xmlSet, String template
276279 b .setVariable ("fhirResolver" , fr );
277280 b .setVariable ("openEhrClient" , openEhrClient );
278281 b .setVariable ("utils" , um );
282+ b .setVariable ("cache" , cache );
279283
280284 if (Settings .getDev ()) {
281- return javaMap (xmlSet , path , fc , fr , openEhrClient , um );
285+ return javaMap (xmlSet , path , fc , fr , openEhrClient , um , cache );
282286 } else {
283287 try {
284288 File groovyFile = new File ("scripts" , templateId + ".groovy" );
@@ -295,13 +299,13 @@ public static Object localMap(Set<Entry<String, Object>> xmlSet, String template
295299
296300 @ SuppressWarnings ({ "HiddenField" })
297301 public static Object javaMap (Set <Entry <String , Object >> xmlSet , String path , IGenericClient fhirClient ,
298- FhirResolver fhirResolver , DefaultRestClient openEhrClient , UtilMethods utils ) {
302+ FhirResolver fhirResolver , DefaultRestClient openEhrClient , UtilMethods utils , Map < String , Object > cache ) {
299303 return null ;
300304 }
301305
302306 @ SuppressWarnings ({ "unchecked" })
303307 public static void walkTree (Set <Entry <String , Object >> xmlSet , int depth , String path ,
304- Map <String , Object > resMap ) {
308+ Map <String , Object > resMap , Map < String , Object > cache ) {
305309 if (depth > Settings .getDepthLimit ()) {
306310 return ;
307311 }
@@ -321,7 +325,7 @@ public static void walkTree(Set<Entry<String, Object>> xmlSet, int depth, String
321325 boolean global = m .getGlobal ();
322326 boolean update = m .isUpdate ();
323327
324- List <Object > mappedList = switch (localMap (xmlSet , m .getTemplateId (), path )) {
328+ List <Object > mappedList = switch (localMap (xmlSet , m .getTemplateId (), path , cache )) {
325329 case List l -> l ;
326330 case Map ml -> List .of (ml );
327331 case null -> new ArrayList <>();
@@ -388,21 +392,21 @@ public static void walkTree(Set<Entry<String, Object>> xmlSet, int depth, String
388392 && Settings .getMapping ().get (newPath ).get (0 ).isList ()) {
389393 Map <String , Object > tmpList = new HashMap <>();
390394 tmpList .put ("list" , List .of (h ));
391- walkTree (tmpList .entrySet (), newDepth , newPath , theMap );
395+ walkTree (tmpList .entrySet (), newDepth , newPath , theMap , cache );
392396 } else {
393- walkTree (h .entrySet (), newDepth , newPath , theMap );
397+ walkTree (h .entrySet (), newDepth , newPath , theMap , cache );
394398 }
395399 }
396400 case @ SuppressWarnings ("rawtypes" ) List a -> {
397401 if (Settings .getMapping ().containsKey (newPath ) && Settings .getMapping ().get (newPath ).size () == 1
398402 && Settings .getMapping ().get (newPath ).get (0 ).isList ()) {
399403 Map <String , Object > tmpList = new HashMap <>();
400404 tmpList .put ("list" , a );
401- walkTree (tmpList .entrySet (), newDepth , newPath , theMap );
405+ walkTree (tmpList .entrySet (), newDepth , newPath , theMap , cache );
402406 } else {
403407 for (Object b : a ) {
404408 if (b instanceof Map ) {
405- walkTree (((Map <String , Object >) b ).entrySet (), newDepth , newPath , theMap );
409+ walkTree (((Map <String , Object >) b ).entrySet (), newDepth , newPath , theMap , cache );
406410 }
407411 }
408412 }
0 commit comments