Skip to content

Commit bf03f39

Browse files
committed
Tighten VFBqueryJsonProcessor generic path for Shape-A queries
Adds per-cell type coercion to buildGenericRows() so non-connectivity VFBquery responses (neuron-neuron, neuron-region, and the upcoming Shape-A migrations) render correctly without per-query bespoke code: - java.util.List values render pipe-joined ("Adult|Nervous_system|...") matching the v2 SOLRQueryProcessor convention for tag columns (row.grossTypes()). - java.lang.Number values that are integer-valued render as ints, avoiding "2.0" / "31.0" in counter columns like Outputs / Inputs / Presynaptic Terminals. - Everything else passes through .toString(): markdown links, ids, short_forms, free text. The connectivity Shape-C path (buildClassConnectivityRows) is unaffected and continues to do its bespoke column synthesis.
1 parent 5107acc commit bf03f39

1 file changed

Lines changed: 53 additions & 5 deletions

File tree

src/main/java/uk/ac/vfb/geppetto/VFBqueryJsonProcessor.java

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package uk.ac.vfb.geppetto;
22

33
import java.util.HashMap;
4+
import java.util.List;
45
import java.util.Map;
56

67
import org.geppetto.core.datasources.GeppettoDataSourceException;
@@ -167,9 +168,22 @@ private void buildClassConnectivityRows(Variable variable, QueryResults in, Quer
167168
}
168169

169170
/**
170-
* Generic Object-to-String stringification for non-connectivity VFBquery
171-
* responses. Used by Shape-A migrations (single-step Cypher queries) once
172-
* those land. Header titles are passed through unchanged.
171+
* Generic value-to-String pass for non-connectivity VFBquery responses.
172+
* Used by Shape-A migrations (single-step Cypher queries like neuron-
173+
* neuron and neuron-region connectivity). Header titles are passed through
174+
* unchanged.
175+
*
176+
* Per-cell formatting rules (duck-typed against the parsed JSON value):
177+
* - null -> ""
178+
* - java.util.List -> pipe-joined elements ("Adult|Nervous_system|...")
179+
* matching the v2 SOLRQueryProcessor convention
180+
* for tag columns (see SOLRQueryProcessor.java
181+
* row.grossTypes()).
182+
* - java.lang.Number -> integer string if the value is whole; else
183+
* a plain Double.toString(). Avoids "2.0" /
184+
* "31.0" in counter columns.
185+
* - anything else -> Object.toString() pass-through (markdown,
186+
* short_form ids, etc.).
173187
*/
174188
private void buildGenericRows(QueryResults in, QueryResults out)
175189
{
@@ -180,13 +194,47 @@ private void buildGenericRows(QueryResults in, QueryResults out)
180194
SerializableQueryResult r = DatasourcesFactory.eINSTANCE.createSerializableQueryResult();
181195
for (String col : in.getHeader())
182196
{
183-
Object v = safeGetValue(in, col, i);
184-
r.getValues().add(v == null ? "" : v.toString());
197+
r.getValues().add(formatGenericCell(safeGetValue(in, col, i)));
185198
}
186199
out.getResults().add(r);
187200
}
188201
}
189202

203+
private static String formatGenericCell(Object v)
204+
{
205+
if (v == null)
206+
{
207+
return "";
208+
}
209+
if (v instanceof List)
210+
{
211+
StringBuilder sb = new StringBuilder();
212+
for (Object e : (List<?>) v)
213+
{
214+
if (e == null)
215+
{
216+
continue;
217+
}
218+
if (sb.length() > 0)
219+
{
220+
sb.append('|');
221+
}
222+
sb.append(e.toString());
223+
}
224+
return sb.toString();
225+
}
226+
if (v instanceof Number)
227+
{
228+
double d = ((Number) v).doubleValue();
229+
if (d == Math.floor(d) && !Double.isInfinite(d))
230+
{
231+
return Long.toString((long) d);
232+
}
233+
return v.toString();
234+
}
235+
return v.toString();
236+
}
237+
190238
private static Object safeGetValue(QueryResults in, String col, int rowIdx)
191239
{
192240
try

0 commit comments

Comments
 (0)