use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class JSONStreamsTest method testFlattenWithAttributes.
@Test
public void testFlattenWithAttributes() throws Exception {
final Topology t = new Topology();
JSONObject e1 = new JSONObject();
e1.put("val", "hello");
JSONObject e2 = new JSONObject();
e2.put("val", "goodbye");
e2.put("a", "def");
final JSONObject value = new JSONObject();
{
value.put("a", "abc");
final JSONArray array = new JSONArray();
array.add(e1);
array.add(e2);
value.put("greetings", array);
}
List<JSONObject> inputs = new ArrayList<>();
inputs.add(value);
final JSONObject value2 = new JSONObject();
{
final JSONArray array2 = new JSONArray();
array2.add(e1.clone());
array2.add(e2.clone());
value2.put("greetings", array2);
}
inputs.add(value2);
TStream<JSONObject> s = t.constants(inputs);
TStream<JSONObject> jsonm = JSONStreams.flattenArray(s, "greetings", "a");
;
TStream<String> output = JSONStreams.serialize(jsonm);
JSONObject e1r = (JSONObject) e1.clone();
e1r.put("a", "abc");
assertFalse(e1.containsKey("a"));
completeAndValidate(output, 10, e1r.toString(), e2.toString(), e1.toString(), e2.toString());
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class SPL method addToolkit.
/**
* Add a dependency on an SPL toolkit.
* @param te Element within the topology.
* @param toolkitRoot Root directory of the toolkit.
* @throws IOException {@code toolkitRoot} is not a valid path.
*/
public static void addToolkit(TopologyElement te, File toolkitRoot) throws IOException {
JSONObject tkinfo = newToolkitDepInfo(te);
tkinfo.put("root", toolkitRoot.getCanonicalPath());
ToolkitInfoModelType infoModel;
try {
infoModel = TkInfo.getToolkitInfo(toolkitRoot);
} catch (JAXBException e) {
throw new IOException(e);
}
if (infoModel != null) {
IdentityType tkIdentity = infoModel.getIdentity();
tkinfo.put("name", tkIdentity.getName());
tkinfo.put("version", tkIdentity.getVersion());
}
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class SPL method addToolkitDependency.
/**
* Add a logical dependency on an SPL toolkit.
* @param te Element within the topology.
* @param name Name of the toolkit.
* @param version Version dependency string.
*/
public static void addToolkitDependency(TopologyElement te, String name, String version) {
JSONObject tkinfo = newToolkitDepInfo(te);
tkinfo.put("name", name);
tkinfo.put("version", version);
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class SPL method newToolkitDepInfo.
private static JSONObject newToolkitDepInfo(TopologyElement te) {
JSONArray tks = (JSONArray) te.topology().getConfig().get(TOOLKITS);
if (tks == null) {
te.topology().getConfig().put(TOOLKITS, tks = new JSONArray());
}
JSONObject tkinfo = new JSONObject();
tks.add(tkinfo);
return tkinfo;
}
use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.
the class BeaconTuple method toJSON.
/**
* Creates a JSON object with two attributes:
* <UL>
* <li>{@code sequence} Value of {@link #getSequence()}</li>
* <li>{@code time} Value of {@link #getTime()}</li>
* </UL>
* @return JSON representation of this tuple.
*/
@Override
public JSONObject toJSON() {
JSONObject btjson = new JSONObject();
btjson.put("sequence", getSequence());
btjson.put("time", getTime());
return btjson;
}
Aggregations