diff --git a/metafix/src/main/java/org/metafacture/metafix/RecordTransformer.java b/metafix/src/main/java/org/metafacture/metafix/RecordTransformer.java index 2ced5c0a..a219ae95 100644 --- a/metafix/src/main/java/org/metafacture/metafix/RecordTransformer.java +++ b/metafix/src/main/java/org/metafacture/metafix/RecordTransformer.java @@ -92,21 +92,11 @@ else if (sub instanceof Unless) { private void processBind(final Do theDo, final EList params) { if (theDo.getName().equals("list")) { // TODO impl multiple binds via FixBind enum final Map options = options(theDo.getOptions()); - final Record fullRecord = record.shallowClone(); - record.findList(options.get("path"), a -> a.forEach(value -> { - // for each value, bind the current record/scope/context to the given var name: - record = new Record(); record.put(options.get("var"), value); - processSubexpressions(theDo.getElements()); record.remove(options.get("var")); - - // and remember the things we added while bound (this probably needs some tweaking): - fullRecord.addAll(record); })); - - record = fullRecord; } else { LOG.warn("Unprocessed bind: {}", theDo); diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java index 6d15db98..24db98f8 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixBindTest.java @@ -70,6 +70,36 @@ public void doList() { }); } + @Test + public void doListFullRecordInScope() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "do list('path': 'name', 'var': 'n')", + " if any_equal('type','book')", + " paste('title','~Book:','n')", + " else", + " paste('title','~Journal:','n')", + " end", + "end", + "retain('title')"), + i -> { + i.startRecord("1"); + i.literal("type", "book"); + i.literal("name", "A book"); + i.endRecord(); + i.startRecord("2"); + i.literal("type", "journal"); + i.literal("name", "A journal"); + i.endRecord(); + }, o -> { + o.get().startRecord("1"); + o.get().literal("title", "Book: A book"); + o.get().endRecord(); + o.get().startRecord("2"); + o.get().literal("title", "Journal: A journal"); + o.get().endRecord(); + }); + } + @Test public void doListPathWithDots() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( @@ -99,8 +129,8 @@ public void doListPathWithDots() { @Test public void doListWithAppendAndLast() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "set_array('author[]')", "do list('path': 'creator', 'var': 'c')", - " set_array('author[]')", " copy_field('c.name', 'author[].$append.name')", " add_field('author[].$last.type', 'Default')", "end",