List of usage examples for com.fasterxml.jackson.databind.node ArrayNode size
public int size()
From source file:org.gitana.platform.client.principal.AbstractDomainPrincipalImpl.java
@Override public List<String> getAuthorities() { List<String> authorities = new ArrayList<String>(); ArrayNode array = this.getArray(FIELD_AUTHORITIES); if (array != null) { for (int i = 0; i < array.size(); i++) { String authorityId = array.get(i).textValue(); authorities.add(authorityId); }// www. j ava2 s .c o m } return authorities; }
From source file:org.envirocar.server.rest.util.GeoJSON.java
protected Coordinate[] decodeCoordinates(ArrayNode list) throws GeometryConverterException { Coordinate[] coordinates = new Coordinate[list.size()]; for (int i = 0; i < list.size(); ++i) { coordinates[i] = decodeCoordinate(toList(list.get(i))); }//from w w w . j a v a 2 s . co m return coordinates; }
From source file:org.envirocar.server.rest.util.GeoJSON.java
@Override public GeometryCollection decodeGeometryCollection(JsonNode json) throws GeometryConverterException { if (!json.has(GEOMETRIES_KEY)) { throw new GeometryConverterException("missing 'geometries' field"); }//from w ww . ja v a2s. c o m ArrayNode geometries = toList(json.get(GEOMETRIES_KEY)); Geometry[] geoms = new Geometry[geometries.size()]; for (int i = 0; i < geometries.size(); ++i) { geoms[i] = decodeGeometry(geometries.get(i)); } return getGeometryFactory().createGeometryCollection(geoms); }
From source file:org.envirocar.server.rest.util.GeoJSON.java
@Override public MultiLineString decodeMultiLineString(JsonNode json) throws GeometryConverterException { ArrayNode coordinates = requireCoordinates(json); LineString[] lineStrings = new LineString[coordinates.size()]; for (int i = 0; i < coordinates.size(); ++i) { Object coords = coordinates.get(i); lineStrings[i] = getGeometryFactory().createLineString(decodeCoordinates(toList(coords))); }/*from w ww .j ava 2 s . com*/ return getGeometryFactory().createMultiLineString(lineStrings); }
From source file:org.pentaho.metaverse.impl.model.kettle.json.TransMetaJsonDeserializer.java
protected void deserializeSteps(TransMeta transMeta, JsonNode node, ObjectMapper mapper) throws IOException { ArrayNode stepsArrayNode = (ArrayNode) node.get(TransMetaJsonSerializer.JSON_PROPERTY_STEPS); String stepName = null;/*from w w w . j a va 2 s . co m*/ for (int i = 0; i < stepsArrayNode.size(); i++) { JsonNode stepNode = stepsArrayNode.get(i); String className = stepNode.get(IInfo.JSON_PROPERTY_CLASS).asText(); stepName = stepNode.get(IInfo.JSON_PROPERTY_NAME).asText(); ObjectId stepId = new StringObjectId(stepName); // add the step attributes to the repo so they can be found when they are looked up by the readRep impl JsonNode attributes = stepNode.get(AbstractStepMetaJsonSerializer.JSON_PROPERTY_ATTRIBUTES); writeJsonAttributes(attributes, mapper, stepId); JsonNode fields = stepNode.get(AbstractStepMetaJsonSerializer.JSON_PROPERTY_FIELDS); writeJsonFields(fields, mapper, stepId); try { Class clazz = this.getClass().getClassLoader().loadClass(className); BaseStepMeta meta = (BaseStepMeta) clazz.newInstance(); meta.readRep(getRepository(), null, stepId, transMeta.getDatabases()); StepMetaInterface smi = (StepMetaInterface) meta; StepMeta step = new StepMeta(stepName, smi); transMeta.addStep(step); } catch (Exception e) { LOGGER.warn(Messages.getString("WARNING.Deserialization.Trans.Steps", stepName), e); } } }
From source file:org.apache.flink.test.web.WebFrontendITCase.java
@Test public void getNumberOfTaskManagers() { try {//from w w w .j a va 2 s . co m String json = TestBaseUtils.getFromHTTP("http://localhost:" + port + "/taskmanagers/"); ObjectMapper mapper = new ObjectMapper(); JsonNode response = mapper.readTree(json); ArrayNode taskManagers = (ArrayNode) response.get("taskmanagers"); assertNotNull(taskManagers); assertEquals(cluster.numTaskManagers(), taskManagers.size()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
From source file:org.apache.flink.test.web.WebFrontendITCase.java
@Test public void getTaskmanagers() { try {// w w w .j a v a 2s . c o m String json = getFromHTTP("http://localhost:" + port + "/taskmanagers/"); ObjectMapper mapper = new ObjectMapper(); JsonNode parsed = mapper.readTree(json); ArrayNode taskManagers = (ArrayNode) parsed.get("taskmanagers"); assertNotNull(taskManagers); assertEquals(cluster.numTaskManagers(), taskManagers.size()); JsonNode taskManager = taskManagers.get(0); assertNotNull(taskManager); assertEquals(NUM_SLOTS, taskManager.get("slotsNumber").asInt()); assertTrue(taskManager.get("freeSlots").asInt() <= NUM_SLOTS); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
From source file:org.gitana.platform.client.api.ClientImpl.java
@Override public Collection<String> getScope() { List<String> scopeList = new ArrayList<String>(); ArrayNode array = getArray(FIELD_SCOPE); if (array != null) { for (int i = 0; i < array.size(); i++) { String scope = array.get(i).textValue(); scopeList.add(scope);/* w w w .ja v a 2 s.c o m*/ } } return scopeList; }
From source file:au.org.ands.vocabs.toolkit.tasks.TaskRunner.java
/** Run the task. *//* ww w . j a v a 2s .c o m*/ public final void runTask() { status = TaskStatus.SUCCESS; task = taskInfo.getTask(); results.put("task_id", task.getId().toString()); ArrayNode subtasks = TaskUtils.getSubtasks(task.getParams()); if (subtasks == null || subtasks.size() == 0) { status = TaskStatus.ERROR; results.put("runTask", "No subtasks specified, or invalid" + " format."); addTimestamp(results); TaskUtils.updateMessageAndTaskStatus(logger, task, results, status, "No subtasks specified. Nothing to do."); return; } boolean success = false; for (JsonNode subtask : subtasks) { logger.debug("Got subtask: " + subtask.toString()); if (!(subtask instanceof ObjectNode)) { logger.error("runTask() didn't get an object:" + subtask.toString()); status = TaskStatus.ERROR; addTimestamp(results); TaskUtils.updateMessageAndTaskStatus(logger, task, results, status, "Bad subtask specification."); return; } logger.debug("subtask type: " + subtask.get("type")); String thisTask = subtask.get("type").textValue(); switch (thisTask) { case "HARVEST": case "UNHARVEST": success = runHarvest(subtask, thisTask); break; case "TRANSFORM": case "UNTRANSFORM": success = runTransform(subtask, thisTask); break; case "IMPORT": case "UNIMPORT": success = runImport(subtask, thisTask); break; case "PUBLISH": case "UNPUBLISH": success = runPublish(subtask, thisTask); break; // case "DELETE": // success = runDelete(subtask); // break; default: status = TaskStatus.ERROR; results.put("invalid_sub_task", thisTask); TaskUtils.updateMessageAndTaskStatus(logger, task, results, status, "Invalid subtask specification."); break; } if (!success) { logger.error("ERROR while running task: " + thisTask); results.put("error_subtask", thisTask); status = TaskStatus.ERROR; addTimestamp(results); TaskUtils.updateMessageAndTaskStatus(logger, task, results, status, "Error in subtask."); return; } } status = TaskStatus.SUCCESS; results.put("output_path", ToolkitFileUtils.getTaskOutputPath(taskInfo, null)); addTimestamp(results); TaskUtils.updateMessageAndTaskStatus(logger, task, results, status, "All tasks completed."); }
From source file:de.thomaskrille.dropwizard.environment_configuration.EnvironmentConfigurationFactory.java
private void replaceEnvironmentVariablesForArray(final Queue<JsonNode> q, final ArrayNode node) { for (int i = 0; i < node.size(); i++) { JsonNode element = node.get(i);/*w w w . j a v a 2s .co m*/ if (element.isContainerNode()) { q.offer(element); continue; } if (!element.isValueNode()) { continue; } String replacement = getReplacementForValue(element); if (replacement == null) { continue; } node.set(i, TextNode.valueOf(replacement)); } }