Search in sources :

Example 41 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project visualee by Thomas-S-B.

the class GraphCreator method generateGraph.

public static Graph generateGraph(String fileName, String title, DependencyFilter filter, File outputdirectory) {
    id = 0;
    Graph graph = new Graph();
    graph.setName(fileName);
    File jsonFile = new File(outputdirectory.toString() + File.separatorChar + fileName + ".json");
    graph.setJsonFile(jsonFile);
    File htmlFile = new File(outputdirectory.toString() + File.separatorChar + fileName + ".html");
    graph.setHtmlFile(htmlFile);
    graph.setTitle(title);
    GraphConfigurator.configGraph(graph);
    JsonObjectBuilder builder = Json.createObjectBuilder();
    // Nodes
    JsonArrayBuilder nodesArray = buildJSONNodes(filter);
    builder.add("nodes", nodesArray);
    // Links
    JsonArrayBuilder linksArray = buildJSONLinks(filter);
    builder.add("links", linksArray);
    JsonObject json = builder.build();
    try (PrintStream ps = new PrintStream(graph.getJsonFile())) {
        ps.println(json.toString());
    } catch (FileNotFoundException ex) {
        LogProvider.getInstance().error("Didn't found file " + graph.getJsonFile().getName(), ex);
    }
    return graph;
}
Also used : PrintStream(java.io.PrintStream) Graph(de.strullerbaumann.visualee.ui.graph.entity.Graph) FileNotFoundException(java.io.FileNotFoundException) JsonObject(javax.json.JsonObject) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) File(java.io.File)

Example 42 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project visualee by Thomas-S-B.

the class GraphCreator method buildJSONLinks.

static JsonArrayBuilder buildJSONLinks(DependencyFilter filter) {
    JsonArrayBuilder linksArray = Json.createArrayBuilder();
    int value = 1;
    Set<JavaSource> relevantClasses = DependencyContainer.getInstance().getFilteredJavaSources(filter);
    for (JavaSource javaSource : relevantClasses) {
        for (Dependency d : DependencyContainer.getInstance().getDependencies(javaSource)) {
            DependencyType type = d.getDependencyType();
            if (filter == null || (relevantClasses.contains(d.getJavaSourceTo()) && filter.contains(type))) {
                int source = d.getJavaSourceFrom().getId();
                int target = d.getJavaSourceTo().getId();
                JsonObjectBuilder linksBuilder = Json.createObjectBuilder();
                if (DependencyType.isInverseDirection(type)) {
                    linksBuilder.add("source", source);
                    linksBuilder.add("target", target);
                } else {
                    linksBuilder.add("source", target);
                    linksBuilder.add("target", source);
                }
                linksBuilder.add("value", value);
                linksBuilder.add("type", type.toString());
                linksArray.add(linksBuilder);
            }
        }
    }
    return linksArray;
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) DependencyType(de.strullerbaumann.visualee.dependency.entity.DependencyType) JsonArrayBuilder(javax.json.JsonArrayBuilder) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 43 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project sling by apache.

the class AbstractGetAclServlet method addTo.

private JsonObjectBuilder addTo(JsonObjectBuilder builder, String key, Object value) {
    if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
        builder.add(key, ((Number) value).longValue());
    } else if (value instanceof Float || value instanceof Double) {
        builder.add(key, ((Number) value).doubleValue());
    } else if (value instanceof Privilege) {
        JsonObjectBuilder privilegeBuilder = Json.createObjectBuilder();
        privilegeBuilder.add("name", ((Privilege) value).getName());
        builder.add(key, privilegeBuilder);
    } else if (value instanceof String) {
        builder.add(key, (String) value);
    } else {
        builder.add(key, value.toString());
    }
    return builder;
}
Also used : Privilege(javax.jcr.security.Privilege) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 44 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project sling by apache.

the class Announcement method asJSONObject.

/** Convert this announcement into a json object **/
private JsonObject asJSONObject(boolean filterTimes) {
    JsonObjectBuilder announcement = Json.createObjectBuilder();
    announcement.add("ownerId", ownerId);
    announcement.add("protocolVersion", protocolVersion);
    // for backwards compatibility!
    if (!filterTimes) {
        announcement.add("created", System.currentTimeMillis());
    }
    announcement.add("inherited", inherited);
    if (loop) {
        announcement.add("loop", loop);
    }
    if (serverInfo != null) {
        announcement.add("serverInfo", serverInfo);
    }
    if (localCluster != null) {
        announcement.add("localClusterView", asJSON(localCluster));
    }
    if (!filterTimes && backoffInterval > 0) {
        announcement.add("backoffInterval", backoffInterval);
    }
    if (resetBackoff) {
        announcement.add("resetBackoff", resetBackoff);
    }
    JsonArrayBuilder incomingAnnouncements = Json.createArrayBuilder();
    for (Iterator<Announcement> it = incomings.iterator(); it.hasNext(); ) {
        Announcement incoming = it.next();
        incomingAnnouncements.add(incoming.asJSONObject(filterTimes));
    }
    announcement.add("topologyAnnouncements", incomingAnnouncements);
    return announcement.build();
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 45 with JsonObjectBuilder

use of javax.json.JsonObjectBuilder in project sling by apache.

the class Announcement method asJSON.

/** convert an instance description into a json object **/
private static JsonObject asJSON(final InstanceDescription instanceDescription) {
    JsonObjectBuilder obj = Json.createObjectBuilder();
    obj.add("slingId", instanceDescription.getSlingId());
    obj.add("isLeader", instanceDescription.isLeader());
    ClusterView cluster = instanceDescription.getClusterView();
    if (cluster != null) {
        obj.add("cluster", cluster.getId());
    }
    JsonObjectBuilder propertiesObj = Json.createObjectBuilder();
    Map<String, String> propertiesMap = instanceDescription.getProperties();
    for (Iterator<Entry<String, String>> it = propertiesMap.entrySet().iterator(); it.hasNext(); ) {
        Entry<String, String> entry = it.next();
        propertiesObj.add(entry.getKey(), entry.getValue());
    }
    obj.add("properties", propertiesObj);
    return obj.build();
}
Also used : ClusterView(org.apache.sling.discovery.ClusterView) DefaultClusterView(org.apache.sling.discovery.commons.providers.DefaultClusterView) Entry(java.util.Map.Entry) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Aggregations

JsonObjectBuilder (javax.json.JsonObjectBuilder)76 JsonArrayBuilder (javax.json.JsonArrayBuilder)31 Map (java.util.Map)19 JsonObject (javax.json.JsonObject)19 JsonException (javax.json.JsonException)14 HashMap (java.util.HashMap)9 StringWriter (java.io.StringWriter)8 ArrayList (java.util.ArrayList)6 JsonValue (javax.json.JsonValue)6 List (java.util.List)5 JsonString (javax.json.JsonString)5 PrintWriter (java.io.PrintWriter)3 Entry (java.util.Map.Entry)3 JsonArray (javax.json.JsonArray)3 ActionReporter (com.sun.enterprise.v3.common.ActionReporter)2 JavaSource (de.strullerbaumann.visualee.source.entity.JavaSource)2 File (java.io.File)2 JsonWriter (javax.json.JsonWriter)2 Resource (org.apache.sling.api.resource.Resource)2 ValueMap (org.apache.sling.api.resource.ValueMap)2