use of org.apache.sling.commons.json.JSONArray in project flink by apache.
the class JSONGenerator method visitIteration.
private void visitIteration(JSONArray jsonArray, List<Integer> toVisit, int headId, Map<Integer, Integer> edgeRemapings, JSONArray iterationInEdges) throws JSONException {
Integer vertexID = toVisit.get(0);
StreamNode vertex = streamGraph.getStreamNode(vertexID);
toVisit.remove(vertexID);
// Ignoring head and tail to avoid redundancy
if (!streamGraph.vertexIDtoLoopTimeout.containsKey(vertexID)) {
JSONObject obj = new JSONObject();
jsonArray.put(obj);
decorateNode(vertexID, obj);
JSONArray inEdges = new JSONArray();
obj.put(PREDECESSORS, inEdges);
for (StreamEdge inEdge : vertex.getInEdges()) {
int inputID = inEdge.getSourceId();
if (edgeRemapings.keySet().contains(inputID)) {
decorateEdge(inEdges, inEdge, inputID);
} else if (!streamGraph.vertexIDtoLoopTimeout.containsKey(inputID)) {
decorateEdge(iterationInEdges, inEdge, inputID);
}
}
edgeRemapings.put(vertexID, headId);
visitIteration(jsonArray, toVisit, headId, edgeRemapings, iterationInEdges);
}
}
use of org.apache.sling.commons.json.JSONArray in project flink by apache.
the class JSONGenerator method visit.
private void visit(JSONArray jsonArray, List<Integer> toVisit, Map<Integer, Integer> edgeRemapings) throws JSONException {
Integer vertexID = toVisit.get(0);
StreamNode vertex = streamGraph.getStreamNode(vertexID);
if (streamGraph.getSourceIDs().contains(vertexID) || Collections.disjoint(vertex.getInEdges(), toVisit)) {
JSONObject node = new JSONObject();
decorateNode(vertexID, node);
if (!streamGraph.getSourceIDs().contains(vertexID)) {
JSONArray inputs = new JSONArray();
node.put(PREDECESSORS, inputs);
for (StreamEdge inEdge : vertex.getInEdges()) {
int inputID = inEdge.getSourceId();
Integer mappedID = (edgeRemapings.keySet().contains(inputID)) ? edgeRemapings.get(inputID) : inputID;
decorateEdge(inputs, inEdge, mappedID);
}
}
jsonArray.put(node);
toVisit.remove(vertexID);
} else {
Integer iterationHead = -1;
for (StreamEdge inEdge : vertex.getInEdges()) {
int operator = inEdge.getSourceId();
if (streamGraph.vertexIDtoLoopTimeout.containsKey(operator)) {
iterationHead = operator;
}
}
JSONObject obj = new JSONObject();
JSONArray iterationSteps = new JSONArray();
obj.put(STEPS, iterationSteps);
obj.put(ID, iterationHead);
obj.put(PACT, "IterativeDataStream");
obj.put(PARALLELISM, streamGraph.getStreamNode(iterationHead).getParallelism());
obj.put(CONTENTS, "Stream Iteration");
JSONArray iterationInputs = new JSONArray();
obj.put(PREDECESSORS, iterationInputs);
toVisit.remove(iterationHead);
visitIteration(iterationSteps, toVisit, iterationHead, edgeRemapings, iterationInputs);
jsonArray.put(obj);
}
if (!toVisit.isEmpty()) {
visit(jsonArray, toVisit, edgeRemapings);
}
}
use of org.apache.sling.commons.json.JSONArray in project acs-aem-commons by Adobe-Consulting-Services.
the class PackageHelperImplTest method testGetPathFilterSetPreviewJSON.
@Test
public void testGetPathFilterSetPreviewJSON() throws Exception {
final List<PathFilterSet> pathFilterSets = new ArrayList<PathFilterSet>();
pathFilterSets.add(new PathFilterSet("/a/b/c"));
pathFilterSets.add(new PathFilterSet("/d/e/f"));
pathFilterSets.add(new PathFilterSet("/g/h/i"));
final String actual = packageHelper.getPathFilterSetPreviewJSON(pathFilterSets);
final JSONObject json = new JSONObject(actual);
assertEquals("preview", json.getString("status"));
assertEquals("Not applicable (Preview)", json.getString("path"));
final String[] expectedFilterSets = new String[] { "/a/b/c", "/d/e/f", "/g/h/i" };
JSONArray actualArray = json.getJSONArray("filterSets");
for (int i = 0; i < actualArray.length(); i++) {
JSONObject tmp = actualArray.getJSONObject(i);
assertTrue(ArrayUtils.contains(expectedFilterSets, tmp.get("rootPath")));
}
assertEquals(expectedFilterSets.length, actualArray.length());
}
use of org.apache.sling.commons.json.JSONArray in project acs-aem-commons by Adobe-Consulting-Services.
the class PackageHelperImplTest method testGetSuccessJSON.
@Test
public void testGetSuccessJSON() throws Exception {
final String actual = packageHelper.getSuccessJSON(packageOne);
final JSONObject json = new JSONObject(actual);
assertEquals("success", json.getString("status"));
assertEquals("/etc/packages/testGroup/testPackageName-1.0.0.zip", json.getString("path"));
final String[] expectedFilterSets = new String[] { "/a/b/c", "/d/e/f", "/g/h/i" };
JSONArray actualArray = json.getJSONArray("filterSets");
for (int i = 0; i < actualArray.length(); i++) {
JSONObject tmp = actualArray.getJSONObject(i);
assertTrue(ArrayUtils.contains(expectedFilterSets, tmp.get("rootPath")));
}
assertEquals(expectedFilterSets.length, actualArray.length());
}
use of org.apache.sling.commons.json.JSONArray in project acs-aem-commons by Adobe-Consulting-Services.
the class PackageHelperImpl method getSuccessJSON.
/**
* {@inheritDoc}
*/
public String getSuccessJSON(final JcrPackage jcrPackage) throws JSONException, RepositoryException {
final JSONObject json = new JSONObject();
json.put(KEY_STATUS, "success");
json.put(KEY_PATH, jcrPackage.getNode().getPath());
json.put(KEY_FILTER_SETS, new JSONArray());
final List<PathFilterSet> filterSets = jcrPackage.getDefinition().getMetaInf().getFilter().getFilterSets();
for (final PathFilterSet filterSet : filterSets) {
final JSONObject jsonFilterSet = new JSONObject();
jsonFilterSet.put(KEY_IMPORT_MODE, filterSet.getImportMode().name());
jsonFilterSet.put(KEY_ROOT_PATH, filterSet.getRoot());
json.accumulate(KEY_FILTER_SETS, jsonFilterSet);
}
return json.toString();
}
Aggregations