Skip to content

Commit 1ecbcdf

Browse files
committed
Only treat field name as FixPath when actually given a path. (#170, 8c42874)
IOW, don't split field names received from metadata stream (`Metafix.addValue()`).
1 parent 15e2237 commit 1ecbcdf

File tree

3 files changed

+50
-13
lines changed

3 files changed

+50
-13
lines changed

metafix/src/main/java/org/metafacture/metafix/FixMethod.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void apply(final Metafix metafix, final Record record, final List<String>
9999
add_field {
100100
@Override
101101
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
102-
record.add(params.get(0), new Value(params.get(1)));
102+
record.addNested(params.get(0), new Value(params.get(1)));
103103
}
104104
},
105105
array { // array-from-hash
@@ -111,8 +111,8 @@ public void apply(final Metafix metafix, final Record record, final List<String>
111111
record.remove(field);
112112

113113
h.forEach((subField, value) -> {
114-
record.add(field, new Value(subField));
115-
record.add(field, value);
114+
record.addNested(field, new Value(subField));
115+
record.addNested(field, value);
116116
});
117117
})));
118118
}
@@ -123,7 +123,7 @@ public void apply(final Metafix metafix, final Record record, final List<String>
123123
final String oldName = params.get(0);
124124
final String newName = params.get(1);
125125
Value.asList(record.get(oldName), a -> a.forEach(newValue -> {
126-
record.add(newName, newValue);
126+
record.addNested(newName, newValue);
127127
newValue.updatePathRename(newName);
128128
}));
129129
}
@@ -185,11 +185,11 @@ public void apply(final Metafix metafix, final Record record, final List<String>
185185
});
186186

187187
if (!value.asHash().isEmpty()) {
188-
record.add(field, value);
188+
record.addNested(field, value);
189189
}
190190
else {
191191
for (int i = 1; i <= m.groupCount(); i = i + 1) {
192-
record.add(field, new Value(m.group(i)));
192+
record.addNested(field, new Value(m.group(i)));
193193
}
194194
}
195195
}

metafix/src/main/java/org/metafacture/metafix/Record.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,14 @@ public void add(final String field, final Value newValue) {
150150
super.add(field, newValue);
151151
}
152152
else {
153-
final FixPath fixPath = new FixPath(field);
154-
if (fixPath.size() > 1) {
155-
fixPath.insertInto(this, InsertMode.APPEND, newValue);
156-
}
157-
else {
158-
put(field, newValue);
159-
}
153+
put(field, newValue);
160154
}
161155
}
162156

157+
public void addNested(final String field, final Value newValue) {
158+
new FixPath(field).insertInto(this, InsertMode.APPEND, newValue);
159+
}
160+
163161
/**
164162
* Sets a field/value pair to this record, replacing
165163
* any previous association of the field with a value.

metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,4 +2694,43 @@ public void shouldRenameArrayFieldWithAsterisk() {
26942694
);
26952695
}
26962696

2697+
@Test
2698+
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/pull/170")
2699+
public void shouldNotSplitLiteralName() {
2700+
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
2701+
"nothing()"
2702+
),
2703+
i -> {
2704+
i.startRecord("1");
2705+
i.literal("123. ", "foo");
2706+
i.endRecord();
2707+
},
2708+
o -> {
2709+
o.get().startRecord("1");
2710+
o.get().literal("123. ", "foo");
2711+
o.get().endRecord();
2712+
}
2713+
);
2714+
}
2715+
2716+
@Test
2717+
public void shouldNotSplitEntityName() {
2718+
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
2719+
"nothing()"
2720+
),
2721+
i -> {
2722+
i.startRecord("1");
2723+
i.startEntity("123. ");
2724+
i.endEntity();
2725+
i.endRecord();
2726+
},
2727+
o -> {
2728+
o.get().startRecord("1");
2729+
o.get().startEntity("123. ");
2730+
o.get().endEntity();
2731+
o.get().endRecord();
2732+
}
2733+
);
2734+
}
2735+
26972736
}

0 commit comments

Comments
 (0)