Search in sources :

Example 1 with JsonJrdsItem

use of eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsItem in project selenium_java by sergueik.

the class JrdsDataAdapter method attachNode.

private void attachNode(TreeItem<TimeSeriesBinding<Double>> tree, String id, Map<String, JsonJrdsItem> nodes) throws DataAdapterException {
    JsonJrdsItem n = nodes.get(id);
    String currentPath = normalizeId(n.id);
    TreeItem<TimeSeriesBinding<Double>> newBranch = new TreeItem<>(bindingFactory.of(tree.getValue().getTreeHierarchy(), n.name, currentPath, this));
    if (JRDS_FILTER.equals(n.type)) {
        // add a dummy node so that the branch can be expanded
        newBranch.getChildren().add(new TreeItem<>(null));
        // add a listener that will get the treeview filtered according to the selected filter/tag
        newBranch.expandedProperty().addListener(new FilteredViewListener(n, newBranch));
    } else {
        if (n.children != null) {
            for (JsonJrdsItem.JsonTreeRef ref : n.children) {
                attachNode(newBranch, ref._reference, nodes);
            }
        } else {
            // add a dummy node so that the branch can be expanded
            newBranch.getChildren().add(new TreeItem<>(null));
            // add a listener so that bindings for individual datastore are added lazily to avoid
            // dozens of individual call to "graphdesc" when the tree is built.
            newBranch.expandedProperty().addListener(new GraphDescListener(currentPath, newBranch, tree));
        }
    }
    tree.getChildren().add(newBranch);
}
Also used : TimeSeriesBinding(eu.fthevenet.binjr.data.adapters.TimeSeriesBinding) TreeItem(javafx.scene.control.TreeItem) JsonJrdsItem(eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsItem)

Example 2 with JsonJrdsItem

use of eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsItem in project selenium_java by sergueik.

the class JrdsDataAdapter method getBindingTree.

// region [DataAdapter Members]
@Override
public TreeItem<TimeSeriesBinding<Double>> getBindingTree() throws DataAdapterException {
    Gson gson = new Gson();
    try {
        JsonJrdsTree t = gson.fromJson(getJsonTree(treeViewTab.getCommand(), treeViewTab.getArgument(), filter), JsonJrdsTree.class);
        Map<String, JsonJrdsItem> m = Arrays.stream(t.items).collect(Collectors.toMap(o -> o.id, (o -> o)));
        TreeItem<TimeSeriesBinding<Double>> tree = new TreeItem<>(bindingFactory.of("", getSourceName(), "/", this));
        for (JsonJrdsItem branch : Arrays.stream(t.items).filter(jsonJrdsItem -> JRDS_TREE.equals(jsonJrdsItem.type) || JRDS_FILTER.equals(jsonJrdsItem.type)).collect(Collectors.toList())) {
            attachNode(tree, branch.id, m);
        }
        return tree;
    } catch (JsonParseException e) {
        throw new DataAdapterException("An error occurred while parsing the json response to getBindingTree request", e);
    } catch (URISyntaxException e) {
        throw new SourceCommunicationException("Error building URI for request", e);
    }
}
Also used : JsonParseException(com.google.gson.JsonParseException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) java.util(java.util) JsonJrdsTree(eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsTree) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Dialogs(eu.fthevenet.binjr.dialogs.Dialogs) TreeItem(javafx.scene.control.TreeItem) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) ZonedDateTime(java.time.ZonedDateTime) JsonJrdsItem(eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsItem) StatusLine(org.apache.http.StatusLine) EntityUtils(org.apache.http.util.EntityUtils) Gson(com.google.gson.Gson) HttpDataAdapterBase(eu.fthevenet.binjr.data.adapters.HttpDataAdapterBase) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) AbstractResponseHandler(org.apache.http.impl.client.AbstractResponseHandler) URI(java.net.URI) JAXB(javax.xml.bind.JAXB) CsvDecoder(eu.fthevenet.binjr.data.codec.CsvDecoder) XmlAccessorType(javax.xml.bind.annotation.XmlAccessorType) MalformedURLException(java.net.MalformedURLException) XmlUtils(eu.fthevenet.util.xml.XmlUtils) HttpEntity(org.apache.http.HttpEntity) HttpResponseException(org.apache.http.client.HttpResponseException) eu.fthevenet.binjr.data.exceptions(eu.fthevenet.binjr.data.exceptions) IOException(java.io.IOException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) DataAdapter(eu.fthevenet.binjr.data.adapters.DataAdapter) Logger(org.apache.logging.log4j.Logger) TimeSeriesBinding(eu.fthevenet.binjr.data.adapters.TimeSeriesBinding) DateTimeFormatter(java.time.format.DateTimeFormatter) ObservableValue(javafx.beans.value.ObservableValue) Pattern(java.util.regex.Pattern) ChangeListener(javafx.beans.value.ChangeListener) NameValuePair(org.apache.http.NameValuePair) LogManager(org.apache.logging.log4j.LogManager) DoubleTimeSeriesProcessor(eu.fthevenet.binjr.data.timeseries.DoubleTimeSeriesProcessor) InputStream(java.io.InputStream) TreeItem(javafx.scene.control.TreeItem) Gson(com.google.gson.Gson) JsonJrdsTree(eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsTree) URISyntaxException(java.net.URISyntaxException) JsonParseException(com.google.gson.JsonParseException) TimeSeriesBinding(eu.fthevenet.binjr.data.adapters.TimeSeriesBinding) JsonJrdsItem(eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsItem)

Aggregations

TimeSeriesBinding (eu.fthevenet.binjr.data.adapters.TimeSeriesBinding)2 JsonJrdsItem (eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsItem)2 TreeItem (javafx.scene.control.TreeItem)2 Gson (com.google.gson.Gson)1 JsonParseException (com.google.gson.JsonParseException)1 DataAdapter (eu.fthevenet.binjr.data.adapters.DataAdapter)1 HttpDataAdapterBase (eu.fthevenet.binjr.data.adapters.HttpDataAdapterBase)1 CsvDecoder (eu.fthevenet.binjr.data.codec.CsvDecoder)1 eu.fthevenet.binjr.data.exceptions (eu.fthevenet.binjr.data.exceptions)1 DoubleTimeSeriesProcessor (eu.fthevenet.binjr.data.timeseries.DoubleTimeSeriesProcessor)1 Dialogs (eu.fthevenet.binjr.dialogs.Dialogs)1 JsonJrdsTree (eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsTree)1 XmlUtils (eu.fthevenet.util.xml.XmlUtils)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1