Search in sources :

Example 41 with JSONObject

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());
}
Also used : JSONObject(com.ibm.json.java.JSONObject) JSONArray(com.ibm.json.java.JSONArray) ArrayList(java.util.ArrayList) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 42 with JSONObject

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());
    }
}
Also used : IdentityType(com.ibm.streamsx.topology.internal.toolkit.info.IdentityType) JSONObject(com.ibm.json.java.JSONObject) JAXBException(javax.xml.bind.JAXBException) ToolkitInfoModelType(com.ibm.streamsx.topology.internal.toolkit.info.ToolkitInfoModelType) IOException(java.io.IOException)

Example 43 with JSONObject

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);
}
Also used : JSONObject(com.ibm.json.java.JSONObject)

Example 44 with JSONObject

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;
}
Also used : JSONObject(com.ibm.json.java.JSONObject) JSONArray(com.ibm.json.java.JSONArray)

Example 45 with JSONObject

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;
}
Also used : JSONObject(com.ibm.json.java.JSONObject)

Aggregations

JSONObject (com.ibm.json.java.JSONObject)56 JSONArray (com.ibm.json.java.JSONArray)19 Topology (com.ibm.streamsx.topology.Topology)18 Test (org.junit.Test)18 TestTopology (com.ibm.streamsx.topology.test.TestTopology)14 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)6 Tester (com.ibm.streamsx.topology.tester.Tester)5 JsonObject (com.google.gson.JsonObject)4 HashMap (java.util.HashMap)4 Random (java.util.Random)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 OrderedJSONObject (com.ibm.json.java.OrderedJSONObject)2 StreamConnection (com.ibm.streams.flow.declare.StreamConnection)2 StreamSchema (com.ibm.streams.operator.StreamSchema)2 BOperatorInvocation (com.ibm.streamsx.topology.builder.BOperatorInvocation)2 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 Attribute (com.ibm.streams.operator.Attribute)1