Search in sources :

Example 1 with JSONArray

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);
    }
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) JSONArray(org.apache.sling.commons.json.JSONArray)

Example 2 with JSONArray

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);
    }
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) JSONArray(org.apache.sling.commons.json.JSONArray)

Example 3 with JSONArray

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());
}
Also used : PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) JSONObject(org.apache.sling.commons.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.apache.sling.commons.json.JSONArray) Test(org.junit.Test)

Example 4 with JSONArray

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());
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) JSONArray(org.apache.sling.commons.json.JSONArray) Test(org.junit.Test)

Example 5 with JSONArray

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();
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) JSONArray(org.apache.sling.commons.json.JSONArray)

Aggregations

JSONArray (org.apache.sling.commons.json.JSONArray)23 JSONObject (org.apache.sling.commons.json.JSONObject)22 Map (java.util.Map)4 ValueMap (org.apache.sling.api.resource.ValueMap)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 PathFilterSet (org.apache.jackrabbit.vault.fs.api.PathFilterSet)3 Resource (org.apache.sling.api.resource.Resource)3 Page (com.day.cq.wcm.api.Page)2 Calendar (java.util.Calendar)2 HashSet (java.util.HashSet)2 Session (javax.jcr.Session)2 ServletException (javax.servlet.ServletException)2 RequestParameter (org.apache.sling.api.request.RequestParameter)2 RequestParameterMap (org.apache.sling.api.request.RequestParameterMap)2 JSONException (org.apache.sling.commons.json.JSONException)2 Result (com.adobe.acs.commons.quickly.results.Result)1 WorkflowRemovalForceQuitException (com.adobe.acs.commons.workflow.bulk.removal.WorkflowRemovalForceQuitException)1 ClientLibrary (com.adobe.granite.ui.clientlibs.ClientLibrary)1