List of usage examples for com.fasterxml.jackson.databind JsonNode textValue
public String textValue()
From source file:controllers.TestApplication.java
public static Result createTestNodes() { String callBackUrl = GoogleComputeEngineAuthImpl.getCallBackURL(request()); try {//from w ww . j av a 2 s. c om boolean option_chosen; String result = GoogleAuthenticationService.authenticate(callBackUrl, null); if (result != null) { return redirect(result); } Map<String, Boolean> machineTypes = new TreeMap<>(Comparator.<String>naturalOrder()), images = new TreeMap<>(Comparator.<String>reverseOrder()); TestNodeCreationForm nodeCreation = new TestNodeCreationForm(); Form<TestNodeCreationForm> formData = Form.form(TestNodeCreationForm.class).fill(nodeCreation); for (JsonNode n : GoogleComputeEngineService.listMachineTypes().findValues("name")) { machineTypes.put(n.textValue(), "n1-standard-4".equals(n.textValue())); } option_chosen = false; for (JsonNode n : GoogleComputeEngineService.listImages().findValues("name")) { if (!option_chosen && n.textValue().startsWith("debian-")) { images.put(n.textValue(), true); option_chosen = true; } else { images.put(n.textValue(), false); } } option_chosen = false; return ok(views.html.test_nodes_creation.render(formData, machineTypes, images)); } catch (GoogleComputeEngineException e) { return ok(views.html.error.render(e.getMessage())); } }
From source file:com.github.fge.jsonschema.core.tree.BaseSchemaTree.java
private static JsonRef extractDollarSchema(final JsonNode schema) { final JsonNode node = schema.path("$schema"); if (!node.isTextual()) return JsonRef.emptyRef(); try {/*from ww w . j ava 2s. c o m*/ final JsonRef ref = JsonRef.fromString(node.textValue()); return ref.isAbsolute() ? ref : JsonRef.emptyRef(); } catch (JsonReferenceException ignored) { return JsonRef.emptyRef(); } }
From source file:controllers.TestApplication.java
public static Result createTestNodesPost() { String callBackUrl = GoogleComputeEngineAuthImpl.getCallBackURL(request()); try {/* www . j av a2 s . com*/ String result = GoogleAuthenticationService.authenticate(callBackUrl, null); if (result != null) { return redirect(result); } Map<String, Boolean> machineTypes = new TreeMap<>(Comparator.<String>naturalOrder()), images = new TreeMap<>(Comparator.<String>reverseOrder()); Form<TestNodeCreationForm> formData = new BugWorkaroundForm<>(TestNodeCreationForm.class) .bindFromRequest(); TestNodeCreationForm nodeCreationForm = formData.get(); for (JsonNode n : GoogleComputeEngineService.listMachineTypes().findValues("name")) { machineTypes.put(n.textValue(), (nodeCreationForm.getMachineType() != null && n.textValue().equals(nodeCreationForm.getMachineType()))); } for (JsonNode n : GoogleComputeEngineService.listImages().findValues("name")) { images.put(n.textValue(), (nodeCreationForm.getImage() != null && n.textValue().equals(nodeCreationForm.getImage()))); } if (formData.hasErrors()) { flash("error", "Please correct errors above."); return ok(views.html.test_nodes_creation.render(formData, machineTypes, images)); } else { try { googleService.createTestNodes(nodeCreationForm.getTestNodes(), nodeCreationForm.getMachineType(), nodeCreationForm.getImage(), nodeCreationForm.getRootDiskSizeGb()); flash("success", "Test nodes creation launched! Please check the running operations in the cluster status page."); return ok(views.html.test_nodes_creation.render(formData, null, null)); } catch (GoogleComputeEngineException e) { return ok(views.html.error.render(e.getMessage())); } catch (GoogleCloudStorageException e) { return ok(views.html.error.render(e.getMessage())); } } } catch (GoogleComputeEngineException e) { return ok(views.html.error.render(e.getMessage())); } }
From source file:org.primaldev.ppm.util.ChartTypeGenerator.java
protected static Component createChart(JsonNode dataNode, String[] names, Number[] values) { String type = dataNode.get("type").textValue(); JsonNode xAxisNode = dataNode.get("xaxis"); String xAxis = null;/*from w w w. jav a 2 s . com*/ if (xAxisNode != null) { xAxis = xAxisNode.textValue(); } JsonNode yAxisNode = dataNode.get("yaxis"); String yAxis = null; if (yAxisNode != null) { yAxis = yAxisNode.textValue(); } Component chart = null; if (CHART_TYPE_BAR_CHART.equals(type)) { DataSeries dataSeries = new DataSeries().add((Object[]) values); SeriesDefaults seriesDefaults = new SeriesDefaults().setRenderer(SeriesRenderers.BAR); Axes axes = new Axes().addAxis( new XYaxis().setRenderer(AxisRenderers.CATEGORY).setTicks(new Ticks().add((Object[]) names))); Highlighter highlighter = new Highlighter().setShow(false); Options options = new Options().setSeriesDefaults(seriesDefaults).setAxes(axes) .setHighlighter(highlighter); options.setAnimate(true); options.setAnimateReplot(true); chart = new DCharts().setDataSeries(dataSeries).setOptions(options); } else if (CHART_TYPE_PIE_CHART.equals(type)) { DataSeries dataSeries = new DataSeries().newSeries(); for (int i = 0; i < names.length; i++) { dataSeries.add(names[i], values[i]); } SeriesDefaults seriesDefaults = new SeriesDefaults().setRenderer(SeriesRenderers.PIE); Options options = new Options().setSeriesDefaults(seriesDefaults); options.setAnimate(true); options.setAnimateReplot(true); Legend legend = new Legend().setShow(true).setPlacement(LegendPlacements.INSIDE); options.setLegend(legend); Highlighter highlighter = new Highlighter().setShow(true); options.setHighlighter(highlighter); chart = new DCharts().setDataSeries(dataSeries).setOptions(options); } else if (CHART_TYPE_LINE_CHART.equals(type)) { AxesDefaults axesDefaults = new AxesDefaults().setLabelRenderer(LabelRenderers.CANVAS); Axes axes = new Axes() .addAxis(new XYaxis().setLabel(xAxis != null ? xAxis : "").setMin(names[0]) .setMax(names[values.length - 1]).setDrawMajorTickMarks(true)) .addAxis(new XYaxis(XYaxes.Y).setLabel(yAxis != null ? yAxis : "").setDrawMajorTickMarks(true)); Options options = new Options().setAxesDefaults(axesDefaults).setAxes(axes); DataSeries dataSeries = new DataSeries().newSeries(); for (int i = 0; i < names.length; i++) { // if (parseLong(names[i]) != null) { // dataSeries.add(parseLong(names[i]), values[i]); // } else if (parseDouble(names[i]) != null) { // dataSeries.add(parseDouble(names[i]), values[i]); // } else { // dataSeries.add(names[i], values[i]); // } dataSeries.add(names[i], values[i]); } Series series = new Series().addSeries(new XYseries().setShowLine(true).setMarkerOptions( new MarkerRenderer().setShadow(true).setSize(7).setStyle(MarkerStyles.CIRCLE))); options.setSeries(series); options.setAnimate(true); options.setAnimateReplot(true); Highlighter highlighter = new Highlighter().setShow(true); options.setHighlighter(highlighter); chart = new DCharts().setDataSeries(dataSeries).setOptions(options); } else if (CHART_TYPE_LIST.equals(type)) { GridLayout grid = new GridLayout(2, names.length); grid.setSpacing(true); for (int i = 0; i < names.length; i++) { String name = names[i]; Label nameLabel = new Label(name); nameLabel.addStyleName(Reindeer.LABEL_H2); grid.addComponent(nameLabel, 0, i); Number value = values[i]; Label valueLabel = new Label(value + ""); grid.addComponent(valueLabel, 1, i); } chart = grid; } if (chart instanceof DCharts) { // Needed, otherwise the chart will not be shown ((DCharts) chart).show(); } return chart; }
From source file:controllers.GoogleComputeEngineApplication.java
public static Result createClusterWizard() { String callBackUrl = GoogleComputeEngineAuthImpl.getCallBackURL(request()); try {/*from w ww. ja v a 2s . c o m*/ boolean option_chosen; String result = GoogleAuthenticationService.authenticate(callBackUrl, null); if (result != null) { return redirect(result); } Map<String, Boolean> machineTypes = new TreeMap<>(Comparator.<String>naturalOrder()), images = new TreeMap<>(Comparator.<String>reverseOrder()), networks = new TreeMap<>(Comparator.<String>reverseOrder()), dataDiskTypes = new TreeMap<>(Comparator.<String>reverseOrder()), dataDiskRaids = new TreeMap<>(Comparator.<String>naturalOrder()), filesystems = new HashMap<>(); ClusterCreationForm clusterCreation = new ClusterCreationForm(); Form<ClusterCreationForm> formData = Form.form(ClusterCreationForm.class).fill(clusterCreation); for (PuppetDiskConfiguration diskConfig : PuppetConfiguration.getSupportedDiskConfigurations()) { dataDiskRaids.put(diskConfig.getName(), "raid0".equals(diskConfig.getName())); } for (JsonNode n : GoogleComputeEngineService.listDiskTypes().findValues("name")) { dataDiskTypes.put(n.textValue(), "pd-ssd".equals(n.textValue())); } for (String fs : PuppetConfiguration.getSupportedDiskFileSystems()) { filesystems.put(fs, "ext4".equals(fs)); } for (JsonNode n : GoogleComputeEngineService.listMachineTypes().findValues("name")) { machineTypes.put(n.textValue(), "n1-standard-4".equals(n.textValue())); } option_chosen = false; for (JsonNode n : GoogleComputeEngineService.listImages().findValues("name")) { if (!option_chosen && n.textValue().startsWith("debian-")) { images.put(n.textValue(), true); option_chosen = true; } else { images.put(n.textValue(), false); } } option_chosen = false; for (JsonNode n : GoogleComputeEngineService.listNetworks().findValues("name")) { if (!option_chosen) { networks.put(n.textValue(), true); option_chosen = true; } else { networks.put(n.textValue(), false); } } return ok(views.html.cluster_creation.render(formData, machineTypes, images, networks, dataDiskTypes, dataDiskRaids, filesystems, Boolean.valueOf(clusterCreation.isCgroups()))); } catch (GoogleComputeEngineException e) { return ok(views.html.error.render(e.getMessage())); } }
From source file:com.msopentech.odatajclient.testservice.utils.JSONUtilities.java
public static Map.Entry<String, List<String>> extractLinkURIs(final InputStream is) throws Exception { final ObjectMapper mapper = new ObjectMapper(); final ObjectNode srcNode = (ObjectNode) mapper.readTree(is); IOUtils.closeQuietly(is);/*from w w w.j a v a 2s .c o m*/ final List<String> links = new ArrayList<String>(); JsonNode uris = srcNode.get("value"); if (uris == null) { final JsonNode url = srcNode.get("url"); if (url != null) { links.add(url.textValue()); } } else { final Iterator<JsonNode> iter = ((ArrayNode) uris).iterator(); while (iter.hasNext()) { links.add(iter.next().get("url").textValue()); } } final JsonNode next = srcNode.get(JSON_NEXTLINK_NAME); return new SimpleEntry<String, List<String>>(next == null ? null : next.asText(), links); }
From source file:de.dfki.kiara.jsonrpc.JsonRpcProtocol.java
public static Object parseMessageId(JsonNode messageNode) throws MessageDeserializationException { JsonNode idNode = messageNode.get("id"); Object id = null;/*from www .j ava 2 s . c o m*/ if (idNode != null) { if (!idNode.isTextual() && !idNode.isNumber() && !idNode.isNull()) { throw new MessageDeserializationException("Invalid 'id' member"); } if (idNode.isTextual()) { id = idNode.textValue(); } else if (idNode.isNumber()) { id = idNode.numberValue(); } } return id; }
From source file:com.gsma.mobileconnect.utils.JsonUtils.java
/** * Return the string value of an optional child node. * <p>//from w w w.j a v a 2 s . com * Check the parent node for the named child, if found return the string contents of the child node, return null otherwise. * * @param parentNode The node to check. * @param name Name of the optional child node. * @return Text value of child node, if found, null otherwise. */ static String getOptionalStringValue(JsonNode parentNode, String name) { JsonNode childNode = parentNode.get(name); if (null == childNode) { return null; } else { return childNode.textValue(); } }
From source file:controllers.GoogleComputeEngineApplication.java
public static Result createClusterWizardPost() { String callBackUrl = GoogleComputeEngineAuthImpl.getCallBackURL(request()); try {/*from w w w .j av a2 s .c o m*/ String result = GoogleAuthenticationService.authenticate(callBackUrl, null); if (result != null) { return redirect(result); } } catch (GoogleComputeEngineException e) { return ok(views.html.error.render(e.getMessage())); } Form<ClusterCreationForm> formData = new BugWorkaroundForm<>(ClusterCreationForm.class).bindFromRequest(); ClusterCreationForm clusterForm = formData.get(); if (formData.hasErrors()) { Map<String, Boolean> machineTypes = new TreeMap<>(Comparator.<String>naturalOrder()), images = new TreeMap<>(Comparator.<String>reverseOrder()), networks = new TreeMap<>(Comparator.<String>reverseOrder()), dataDiskTypes = new TreeMap<>(Comparator.<String>reverseOrder()), dataDiskRaids = new TreeMap<>(Comparator.<String>naturalOrder()), filesystems = new HashMap<>(); flash("error", "Please correct errors above."); try { for (PuppetDiskConfiguration diskConfig : PuppetConfiguration.getSupportedDiskConfigurations()) { dataDiskRaids.put(diskConfig.getName(), (clusterForm.getDiskRaid() != null && diskConfig.getName().equals(clusterForm.getDiskRaid()))); } for (JsonNode n : GoogleComputeEngineService.listDiskTypes().findValues("name")) { dataDiskTypes.put(n.textValue(), clusterForm.getDataDiskType() != null && n.textValue().equals(clusterForm.getDataDiskType())); } for (String fs : PuppetConfiguration.getSupportedDiskFileSystems()) { filesystems.put(fs, (clusterForm.getFileSystem() != null && fs.equals(clusterForm.getFileSystem()))); } for (JsonNode n : GoogleComputeEngineService.listMachineTypes().findValues("name")) { machineTypes.put(n.textValue(), (clusterForm.getMachineType() != null && n.textValue().equals(clusterForm.getMachineType()))); } for (JsonNode n : GoogleComputeEngineService.listImages().findValues("name")) { images.put(n.textValue(), (clusterForm.getImage() != null && n.textValue().equals(clusterForm.getImage()))); } for (JsonNode n : GoogleComputeEngineService.listNetworks().findValues("name")) { networks.put(n.textValue(), (clusterForm.getNetwork() != null && n.textValue().equals(clusterForm.getNetwork()))); } return ok(views.html.cluster_creation.render(formData, machineTypes, images, networks, dataDiskTypes, dataDiskRaids, filesystems, Boolean.valueOf(clusterForm.isCgroups()))); } catch (GoogleComputeEngineException e) { return ok(views.html.error.render(e.getMessage())); } } else { try { googleService.createCluster(clusterForm.getClusterName(), clusterForm.getShardNodes(), clusterForm.getProcesses(), clusterForm.getNodeDisks(), clusterForm.getMachineType(), Arrays.asList(clusterForm.getNetwork()), clusterForm.getImage(), clusterForm.getDataDiskType(), clusterForm.getDiskRaid(), clusterForm.getFileSystem(), clusterForm.getDataDiskSizeGb(), clusterForm.getRootDiskSizeGb()); } catch (GoogleComputeEngineException e) { return ok(views.html.error.render(e.getMessage())); } catch (GoogleCloudStorageException e) { return ok(views.html.error.render(e.getMessage())); } flash("success", "Cluster creation launched! Please check the running operations in the cluster status page."); return ok(views.html.cluster_creation.render(formData, null, null, null, null, null, null, null)); } }
From source file:com.gsma.mobileconnect.utils.JsonUtils.java
/** * Query the parent node for the named child node and return the text value of the child node * * @param parentNode Node to check./*from w w w . j a v a2 s . c o m*/ * @param name Name of the child node. * @return The text value of the child node. * @throws NoFieldException Thrown if field not found. */ static private String getExpectedStringValue(JsonNode parentNode, String name) throws NoFieldException { JsonNode childNode = parentNode.get(name); if (null == childNode) { throw new NoFieldException(name); } return childNode.textValue(); }